AnsweredAssumed Answered

OpenCL Image2D Format

Question asked by krinosx on Mar 23, 2014
Latest reply on Mar 25, 2014 by krinosx

Hello Guys,


I am starting with OpenCL to image processing... So I am starting to learn the basics of Image objects and how to upload image data to an OpenCL device.


I read the specification, even bought a book ( OpenCL in Action ) and I am doing fine until now.


But... I am facing a problem, ( I think its a problem ) about image data format.


To make my project some kind of portable I am using ANSI C and OpenCL ( to processing ) + SDL to GUI and image loading functions.


SDL load image functions give me an byte array of pixel data... the format is the same of a simple BMP 3Bytes per pixel data ( 1byte to BLUE, GREEN and RED ).


To create an image2d ( clCreateImage2d ) I got the following method declaration:


cl_mem clCreateImage2D ( cl_context context,
cl_mem_flags flags,
const cl_image_format *image_format,
size_t image_width,
size_t image_height,
size_t image_row_pitch,
void *host_ptr,
cl_int *errcode_ret)


The imageFormat argument is intriguing me... ( cl_image_format ). The docs say I can use a "CL_BGRA" format.. so I must put an extra byte for each pixel in my buffer right? ( today my buffer is [b,g,r][b,g,r]... I will add an extra byte so it will become [b,g,r,1][b,g,r,1] )... its the right approach?


What really intrigues me is the second field of cl_image_format. ( cl_channel_type image_channel_data_type ) the cl_channel_type enumeration says I can use CL_UNSIGNED_INT8 as data type... It is messing with my mind...


The docs says ( about CL_UNSIGNED_INT8 ): Each channel component is an unnormalized unsigned 8-bit integer value.


In my host program, my byte array is made of "unsigned int" ( 4byte each )... so If I send it to a clCreateImage2D using the CL_UNSIGNED_INT8 as a cl_channel_type in my cl_image_format parameter it will work? OpenCL will convert my 4byte info to a 8byte info?

or may I convert my byte buffer from integer to long/double values?


What I am missing? I think it maybe simpler... but I am missing something I cant see... May someone give-me a hand?