25 #include <Base/Common/BIASpragma.hh>
26 #include <OpenCLFramework/clfImage3D.hh>
27 #include <OpenCLFramework/clfException.hh>
28 #include <Base/Debug/Error.hh>
32 std::vector<cl::ImageFormat> clfImage3D::imageFormatsReadable_;
33 std::vector<cl::ImageFormat> clfImage3D::imageFormatsWritable_;
34 std::vector<cl::ImageFormat> clfImage3D::imageFormatsReadWrite_;
38 BIASWARN(
"clfImage3D is untested, use with care");
46 if (imageFormatsReadable_.empty()) {
47 context_->getSupportedImageFormats(CL_MEM_READ_ONLY, CL_MEM_OBJECT_IMAGE3D, &imageFormatsReadable_);
49 if (imageFormatsWritable_.empty()) {
50 context_->getSupportedImageFormats(CL_MEM_READ_ONLY, CL_MEM_OBJECT_IMAGE3D, &imageFormatsWritable_);
52 if (imageFormatsReadWrite_.empty()) {
53 context_->getSupportedImageFormats(CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE3D, &imageFormatsReadWrite_);
62 unsigned int width,
unsigned int height,
unsigned int levels,
unsigned int stride,
63 bool readonly,
bool writeonly,
const void *hostptr,
bool copy) {
67 BIASWARN(
"RGB not supported, interpreting as Grey, width*3");
71 cl::ImageFormat format = DetermineImageFormat_(st,cm);
72 if (!GetFormatSupported_(format, readonly, writeonly)) {
73 THROW_CL_EXCEPTION(cl::Error(-100,
"requested image format is not supported by device."));
86 THROW_CL_EXCEPTION(cl::Error(-100,
"please provide stride for your data type or extend code for automatic support."));
98 slideStride_ = stride*height;
99 size_ = slideStride_*depth_;
102 buffer_ = cl::Image3D(*
context_, cl_mem_flags, format, width_, height_, depth_, 0, 0, (
void*)hostptr);
104 }
catch(cl::Error &err) {
105 THROW_CL_EXCEPTION(err);
115 readonly, writeonly);
119 Allocate(src.st_, src.cm_, src.width_, src.height_, src.depth_, src.stride_, readonly, writeonly);
125 #ifdef CL_VERSION_1_2
131 buffer_.getInfo(CL_MEM_SIZE, &memsize);
133 }
catch(cl::Error &err) {
134 THROW_CL_EXCEPTION(err);
145 unsigned int originX,
unsigned int originY,
unsigned int originZ,
146 unsigned int regionX,
unsigned int regionY,
unsigned int regionZ)
157 cl::size_t<3> origin, region;
158 MakeDim_(origin, originX, originY, originZ);
159 MakeDim_(region, regionX, regionY, regionZ);
162 queue_->enqueueWriteImage(
image(), CL_TRUE, origin, region, 0, 0, (
void*)data);
163 }
catch (cl::Error &error) {
164 THROW_CL_EXCEPTION(error);
169 unsigned int originX,
unsigned int originY,
unsigned int originZ,
170 unsigned int regionX,
unsigned int regionY,
unsigned int regionZ)
181 cl::size_t<3> origin, region;
182 MakeDim_(origin, originX, originY, originZ);
183 MakeDim_(region, regionX, regionY, regionZ);
185 queue_->enqueueReadImage(
image(), CL_TRUE, origin, region, 0, 0, data);
186 }
catch (cl::Error &error) {
187 THROW_CL_EXCEPTION(error);
192 unsigned int srcoriginX,
unsigned int srcoriginY,
unsigned int srcoriginZ,
193 unsigned int dstoriginX,
unsigned int dstoriginY,
unsigned int dstoriginZ,
194 unsigned int regionX,
unsigned int regionY,
unsigned int regionZ)
205 cl::size_t<3> srcorigin, dstorigin, region;
206 MakeDim_(srcorigin, srcoriginX, srcoriginY, srcoriginZ);
207 MakeDim_(dstorigin, dstoriginX, dstoriginY, dstoriginZ);
208 MakeDim_(region, regionX, regionY, regionZ);
211 queue_->enqueueCopyImage(
image(), outputimage.
image(), srcorigin, dstorigin, region, NULL, &event);
213 }
catch (cl::Error &error) {
214 THROW_CL_EXCEPTION(error);
219 unsigned int originX,
unsigned int originY,
unsigned int originZ,
220 unsigned int regionX,
unsigned int regionY,
unsigned int regionZ)
223 cl_map_flags mapflags = 0;
225 mapflags = CL_MAP_WRITE;
227 mapflags = CL_MAP_READ;
238 cl::size_t<3> origin, region;
239 MakeDim_(origin, originX, originY, originZ);
240 MakeDim_(region, regionX, regionY, regionZ);
241 return queue_->enqueueMapImage(
image(), CL_TRUE, mapflags, origin, region, 0, NULL);
242 }
catch (cl::Error &error) {
243 THROW_CL_EXCEPTION(error);
249 unsigned int originX,
unsigned int originY,
250 unsigned int regionX,
unsigned int regionY)
258 int sx = regionX - originX;
259 int sy = regionY - originY;
274 std::vector<cl::ImageFormat> *dat = NULL;
276 dat = &clfImage3D::imageFormatsReadable_;
277 }
else if (writeonly) {
278 dat = &clfImage3D::imageFormatsWritable_;
280 dat = &clfImage3D::imageFormatsReadWrite_;
282 std::vector<std::string> result( dat->size() );
283 for (
unsigned int i=0;i<dat->size();i++) {
284 switch ((*dat)[i].image_channel_order) {
286 result[i] =
"one channel (R) \t";
289 result[i] =
"one channel (A) \t";
292 result[i] =
"one channel (Intensity)\t";
295 result[i] =
"one channel (Luminance)\t";
298 result[i] =
"two channels (RG) \t";
301 result[i] =
"two channels (RA) \t";
304 result[i] =
"two channels (Rx) \t";
307 result[i] =
"three channels (RGB) \t";
310 result[i] =
"three channels (RGx) \t";
313 result[i] =
"four channels (RGBA) \t";
316 result[i] =
"four channels (BGRA) \t";
319 result[i] =
"four channels (ARGB) \t";
322 result[i] =
"four channels (RGBx) \t";
325 switch ((*dat)[i].image_channel_data_type) {
327 result[i] +=
"signed normalized char";
330 result[i] +=
"signed normalized short";
333 result[i] +=
"unsigned normalized char";
336 result[i] +=
"unsigned normalized short";
338 case CL_UNORM_SHORT_565:
339 result[i] +=
"unsigned normalized short 565";
341 case CL_UNORM_SHORT_555:
342 result[i] +=
"unsigned normalized short 555";
344 case CL_UNORM_INT_101010:
345 result[i] +=
"unsigned normalized int 101010";
348 result[i] +=
"signed char";
350 case CL_SIGNED_INT16:
351 result[i] +=
"signed short";
353 case CL_SIGNED_INT32:
354 result[i] +=
"signed int";
356 case CL_UNSIGNED_INT8:
357 result[i] +=
"unsigned char";
359 case CL_UNSIGNED_INT16:
360 result[i] +=
"unsigned short";
362 case CL_UNSIGNED_INT32:
363 result[i] +=
"unsigned int";
366 result[i] +=
"half float";
369 result[i] +=
"float";
377 cl::ImageFormat format;
380 format.image_channel_data_type = CL_SIGNED_INT8;
383 format.image_channel_data_type = CL_UNSIGNED_INT16;
386 format.image_channel_data_type = CL_SIGNED_INT16;
389 format.image_channel_data_type = CL_UNSIGNED_INT32;
392 format.image_channel_data_type = CL_SIGNED_INT32;
395 format.image_channel_data_type = CL_FLOAT;
398 format.image_channel_data_type = CL_UNSIGNED_INT8;
403 THROW_CL_EXCEPTION(cl::Error(-100,
"image storage type not supported!"));
414 format.image_channel_order = CL_R;
418 format.image_channel_order = CL_INTENSITY;
424 format.image_channel_order = CL_RA;
435 format.image_channel_order = CL_RGB;
441 format.image_channel_order = CL_RGBA;
444 THROW_CL_EXCEPTION(cl::Error(-100,
"color model not supported!"));
450 bool clfImage3D::GetFormatSupported_(cl::ImageFormat test,
bool readonly,
bool writeonly) {
451 std::vector<cl::ImageFormat> *dat = NULL;
453 dat = &clfImage3D::imageFormatsReadable_;
454 }
else if (writeonly) {
455 dat = &clfImage3D::imageFormatsWritable_;
457 dat = &clfImage3D::imageFormatsReadWrite_;
459 for (
unsigned int i=0;i<dat->size();i++) {
460 if (test.image_channel_data_type == (*dat)[i].image_channel_data_type) {
461 if (test.image_channel_order == (*dat)[i].image_channel_order) {
469 void clfImage3D::MakeDim_(cl::size_t<3> &dest,
int x,
int y,
int z) {
EColorModel
These are the most often used color models.
void CopyToImage(clfImage3D &outputimage, unsigned int srcoriginX=0, unsigned int srcoriginY=0, unsigned int srcoriginZ=0, unsigned int dstoriginX=0, unsigned int dstoriginY=0, unsigned int dstoriginZ=0, unsigned int regionX=0, unsigned int regionY=0, unsigned int regionZ=0)
YUYV422, 2 channels, full luminance Y, subsampled half U,V.
Bayer_GRBG, 1 channel RGB image Bayer tile.
hsl, similar to HSL but euclidean (h,s) for CNCC
LAB, 3 channels, http://en.wikipedia.org/wiki/Lab_color_space.
(16bit) unsigned integer image storage type
HSL, similar to HSV but space is a double tipped cone.
void CopyToBiasImage(BIAS::ImageBase &image, unsigned int level, unsigned int originX=0, unsigned int originY=0, unsigned int regionX=0, unsigned int regionY=0)
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
(8bit) signed char image storage type
Bayer_RGGB, 1 channel RGB image Bayer tile.
void * MapImage(bool write=false, unsigned int originX=0, unsigned int originY=0, unsigned int originZ=0, unsigned int regionX=0, unsigned int regionY=0, unsigned int regionZ=0)
static int GetChannelcount(const enum BIAS::ImageBase::EColorModel &colormodel)
get the number of channels corresponding to the enum ColorModel Determines the number of (packed) dat...
double image storage type
XYZ, 3 channels, http://en.wikipedia.org/wiki/Xyz_color_space.
unsigned int GetWidth() const
void AllocateFromTemplate(const clfImage3D &src, bool readonly=false, bool writeonly=false)
void AllocateFromBiasTemplate(const BIAS::ImageBase &image, unsigned int levels, bool readonly=false, bool writeonly=false)
Allocation of a memory buffer as 3D image (2d+level), biasimage is used as template for one level...
int DetermineMemFlags_(bool readonly, bool writeonly, const void *hostptr=NULL, bool copy=false)
invalid not set image storage type
GLuint GetTextureID() const
Returns the OpenGL texture id.
(16bit) signed integer image storage type
color values, 3 channels, order: blue,green,red
Bayer_BGGR, 1 channel RGB image Bayer tile.
const void * GetImageData() const
Disparity images Q: should disp and depth be treated separately, if not what would be a good name to ...
Bayer_GBRG, 1 channel RGB image Bayer tile.
cl::CommandQueue * queue_
color values, 3 channels, order: red,green,blue
CIELUV color space, 3 channels, http://en.wikipedia.org/wiki/CIELUV_color_space.
unsigned int GetHeight() const
RGBA, 4 channels, order: red,green,blue,alpha.
void Release(const bool reset_storage_type=false)
Free the allocated data structures Hands off: Do !!NOT!! change the default of reset_storage_type: Im...
clfImage3D(cl::Context *context, cl::CommandQueue *queue)
enum EColorModel GetColorModel() const
(32bit) signed integer image storage type
RGBE color values, 4 channels, RADIANCE hdr format, four low dynamic channels meaning: 3x mantissa (r...
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
void Allocate(BIAS::ImageBase::EStorageType st, BIAS::ImageBase::EColorModel cm, unsigned int width, unsigned int height, unsigned int levels, unsigned int stride=0, bool readonly=false, bool writeonly=false, const void *hostptr=NULL, bool copy=false)
Allocation of a memory buffer as 3D image, either call directly or use wrapper for BIAS::ImageBase...
void AllocateFromTexture3D(BIAS::glfTexture3D &tex, bool readonly=false, bool writeonly=false)
Allocation of a memory buffer from a GL Texture3D (works only on shared context!) ...
invalid (not set) image format
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
HSV, 3 channels, order: hue, sat , value.
GLenum GetTextureTarget() const
Returns the OpenGL texture target.
std::vector< std::string > GetSupportedImageFormats(bool readonly=false, bool writeonly=false)
Todo: Unclear, I think one channel float, why isn't grey used for that?
GreyA, 2 channels, grey plus Alpha.
This is the base class for images in BIAS.
void WriteToImage(const void *data, unsigned int originX=0, unsigned int originY=0, unsigned int originZ=0, unsigned int regionX=0, unsigned int regionY=0, unsigned int regionZ=0)
write from host memory to image
Depth images A: separated for now.
void ReadFromImage(void *data, unsigned int originX=0, unsigned int originY=0, unsigned int originZ=0, unsigned int regionX=0, unsigned int regionY=0, unsigned int regionZ=0)
read from image to host memory
BGRA color values, 4 channels, order: blue,green,red,alpha.
(32bit) unsigned integer image storage type