Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
clfImage2D.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef CLFIMAGE2D_HH_
26 #define CLFIMAGE2D_HH_
27 
28 #include <bias_config.h>
29 #include <Base/Common/BIASpragmaStart.hh>
30 #include <Base/Image/MetaData.hh>
31 #include <OpenCLFramework/clfOpenCL.hh>
32 #include <OpenCLFramework/clfMemory.hh>
33 #include <OpenGLFramework/Base/glfTexture2D.hh>
34 
35 namespace BIAS {
36 
37  /**
38  *
39  * @brief OpenCL Image2D wrapper
40  *
41  * An clfImage2D is used for both cl::Images, host and GL objects.
42  * All buffers are created from a valid clfContext, hence the constructor is protected.
43  *
44  * @author fkellner 06/11
45  */
46  class BIASOpenCLFramework_EXPORT clfImage2D : public clfMemory {
47  public:
48 
49  virtual ~clfImage2D();
50 
51  /**
52  * @brief Allocation of a memory buffer as 2D image, either call directly or use wrapper for BIAS::ImageBase
53  */
54  void Allocate(
56  unsigned int width, unsigned int height, unsigned int stride=0,
57  bool readonly=false, bool writeonly=false, const void *hostptr = NULL, bool copy = false);
58 
59  /**
60  * @brief Allocation of a memory buffer as 2D image, either call directly or use wrapper for BIAS::ImageBase
61  */
62  void AllocateFromBiasImage(const BIAS::ImageBase &image, bool readonly=false, bool writeonly=false, bool copy = false);
63 
64  void AllocateFromBiasTemplate(const BIAS::ImageBase &image, bool readonly=false, bool writeonly=false);
65 
66  void AllocateFromTemplate(const clfImage2D &src, bool readonly=false, bool writeonly=false);
67 
68  /**
69  * @brief Allocation of a memory buffer from a GL Texture2D (works only on shared context!)
70  */
71  void AllocateFromTexture2D(BIAS::glfTexture2D &tex, bool readonly=false, bool writeonly=false);
72 
73  inline unsigned int Width() const { return width_; }
74  inline unsigned int Height() const { return height_; }
75  inline unsigned int Stride() const { return stride_; }
76  inline BIAS::ImageBase::EColorModel ColorModel() const { return cm_; }
77  inline BIAS::ImageBase::EStorageType StorageType() const { return st_; }
78 
79  /// @brief write from host memory to image
80  void WriteToImage(const void *data,
81  unsigned int originX=0, unsigned int originY=0,
82  unsigned int regionX=0, unsigned int regionY=0,
83  bool blocking = true);
84 
85  /// @brief read from image to host memory
86  void ReadFromImage(void *data,
87  unsigned int originX=0, unsigned int originY=0,
88  unsigned int regionX=0, unsigned int regionY=0);
89 
90  void CopyToImage(clfImage2D &outputimage,
91  unsigned int srcoriginX=0, unsigned int srcoriginY=0,
92  unsigned int dstoriginX=0, unsigned int dstoriginY=0,
93  unsigned int regionX=0, unsigned int regionY=0,
94  bool blocking = true);
95 
96  void* MapImage(bool write = false,
97  unsigned int originX=0, unsigned int originY=0,
98  unsigned int regionX=0, unsigned int regionY=0
99  );
100 
101  void CopyToBiasImage(BIAS::ImageBase &image,
102  unsigned int originX=0, unsigned int originY=0,
103  unsigned int regionX=0, unsigned int regionY=0);
104 
105  void CopyToBiasImageUncheckedRGBAToRGB(BIAS::ImageBase &image);
106 
107  std::vector<std::string> GetSupportedImageFormats(bool readonly=false,
108  bool writeonly=false);
109 
110  void GetImageDim(unsigned int &width, unsigned int &height) const {
111  width = width_;
112  height = height_;
113  }
114 
115  void SetStorageAndColorModelInfo(const BIAS::ImageBase::EStorageType &st,
116  const BIAS::ImageBase::EColorModel &cm);
117 
119  return cm_;
120  }
121 
123  return st_;
124  }
125 
126  unsigned int GetBitDepth() const {
127  return bitdepth_;
128  }
129 
130  void SetBitDepth(unsigned int bitdepth) {
131  bitdepth_ = bitdepth;
132  }
133 
135  return &MetaData_;
136  }
137 
138  void SetMetaData(const BIAS::MetaData &m) {
139  MetaData_ = m;
140  }
141 
143  return tex_;
144  }
145 
146  void SetIsSpare(bool spare);
147 
148  void LockSpare();
149  void UnLockSpare();
150 
151  bool IsSpare();
152  bool IsSpareInUse();
153 
154  protected:
155  clfImage2D(cl::Context *context, cl::CommandQueue *queue);
156  cl::Image2D& image() const;
157 
158  private:
159  friend class clfContext;
160  friend class clfProgram;
161 
162  cl::ImageFormat DetermineImageFormat_(BIAS::ImageBase::EStorageType st, BIAS::ImageBase::EColorModel cm);
163  void DetermineBIASFormat_(cl::ImageFormat format, BIAS::ImageBase::EStorageType &st, BIAS::ImageBase::EColorModel &cm);
164  bool GetFormatSupported_(cl::ImageFormat test, bool readonly, bool writeonly);
165  void MakeDim_(cl::size_t<3> &dest, int x, int y, int z);
166 
167  unsigned int width_, height_, stride_;
168 
171  unsigned int bitdepth_;
172 
173  BIAS::MetaData MetaData_;
174 
175  BIAS::glfTexture2D *tex_;
176 
177  bool isSpare_, isInUse_;
178 
179  static std::vector<cl::ImageFormat> imageFormatsReadable_;
180  static std::vector<cl::ImageFormat> imageFormatsWritable_;
181  static std::vector<cl::ImageFormat> imageFormatsReadWrite_;
182 
183  };
184 }
185 #include <Base/Common/BIASpragmaEnd.hh>
186 #endif /* CLFIMAGE2D_HH_ */
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
BIAS::ImageBase::EStorageType GetStorageType() const
Definition: clfImage2D.hh:122
OpenCL Program wrapper.
Definition: clfProgram.hh:53
void GetImageDim(unsigned int &width, unsigned int &height) const
Definition: clfImage2D.hh:110
unsigned int GetBitDepth() const
Definition: clfImage2D.hh:126
A 2D texture.
Definition: glfTexture2D.hh:40
OpenCL Image2D wrapper.
Definition: clfImage2D.hh:46
void SetMetaData(const BIAS::MetaData &m)
Definition: clfImage2D.hh:138
BIAS::ImageBase::EColorModel ColorModel() const
Definition: clfImage2D.hh:76
BIAS::ImageBase::EStorageType StorageType() const
Definition: clfImage2D.hh:77
BIAS::ImageBase::EColorModel GetColorModel() const
Definition: clfImage2D.hh:118
OpenCL Context wrapper.
Definition: clfContext.hh:49
BIAS::glfTexture2D * GetTexture()
Definition: clfImage2D.hh:142
this class collects all additional data chunks of type AppData to be written into/read from an image ...
Definition: MetaData.hh:121
unsigned int Width() const
Definition: clfImage2D.hh:73
void SetBitDepth(unsigned int bitdepth)
Definition: clfImage2D.hh:130
BIAS::MetaData * GetMetaData()
Definition: clfImage2D.hh:134
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
unsigned int Stride() const
Definition: clfImage2D.hh:75
unsigned int Height() const
Definition: clfImage2D.hh:74