16bits per channel RGB Image


I’m trying to process Image in OpenCl…

Only problem : my Images are 16-bits per channel images…

Is there anyone that has an idea or an example…of let’s say an opencl example which from an unsigned short * which contains the pixels values ( unsigned short Tab_Pixels[WH3]) ) and proceeds it in an program…to for example add some contrast…

Thanks if anyone can put some light in there :frowning:

An example of AMD for image convolution :
http://developer.amd.com/GPU/ATISTREAMS … penCL.aspx

It does not use unsigned short *, but anyway in OpenCL 1.0 (not in 1.1) you can’t write in an unsigned short buffer without the “Byte adressable store” extension. So perhaps you’ll have to put them as integer.

Does section of the 1.0 Specification Revision 48, “Image Format Descriptor,” help you?

Host Code:
If you have an image, you should also have a image format descriptor.
Set the image_channel_data_type to be CL_UNSIGNED_INT16, inside this descriptor.

cl_image_format img2Dformat = {CL_RGBA, CL_UNSIGNED_INT16};

Copy this image to the GPU.

Kernel Code:
The pixel/texel you’re reading inside the image can then be read into an appropriate data type inside the kernel.

I imagine something like this should do the trick:


ushort4 myPixel;
int2 coord;

coord[0] = i; // width index
coord[1] = j; // height index

myPixel = read_image(pInImage, sampler, coord);

Each pixel will then have 4 values corresponding to each image channel (RGBA etc…).

If you have a 16-bit / channel RGBA image and want to process these pixel values as floating-point values in your OpenCL kernel then create the image with

cl_image_format image_format;

image_format.image_channel_order = CL_RGBA
image_format.image_channel_data_type = CL_UNORM_INT16

In your CL kernel, you call read_imagef to read from this image. The implementation will read 16-bit/channel pixel values and convert them to float. Similarly write_imagef will take a float4 color value and convert them to the appropriate channel format which in this case will be 16-bits/channel.

If you want to read the data as integer values instead then

image_format.image_channel_data_type = CL_UNSIGNED_INT16 or CL_SIGNED_INT16 depending on whether the data you want to read is an unsigned or signed 16-bit integer.

In the CL kernel you call read_imageui or read_imagei which will return a 4-component integer vector. Similarly write_imageui or write_imagei will take a 4-component integer vector and convert them to the appropriate channel format.