I tried to copy an image in OpenCL, however the final result end up with the red and blue channels inverted.
Any clues why this happened?
I use the following code:
const cl::ImageFormat format(CL_RGBA, CL_UNSIGNED_INT8);
cl::Image2D in(ocl->context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, format, image_width, image_height, 0, image->pixels);
cl::Image2D out(ocl->context, CL_MEM_WRITE_ONLY, format, image_width, image_height, 0, NULL);
constant sampler_t smp = CLK_NORMALIZED_COORDS_TRUE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR;
void kernel copy(__read_only image2d_t in, __write_only image2d_t out)
{
int x = get_global_id(0);
int y = get_global_id(1);
int2 pos = (int2)(x, y);
uint4 pixel = read_imageui(in, smp, pos);
write_imageui(out, pos, pixel);
}
Naturally if I invert the format of the output image, I get the right colors. However, I wonder why this happens?