Why is OpenCL Inverting Red and Blue Channels?

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);


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?

The first thing which I would do would be to have a closer look at your host image (“image->pixels”), to check that it meets the expectations of the OpenCL API. Are you sure, for example, that its pixels are in RGBA format and not BGRA?

Thank you for fast reply.
The real pixel format is ABGR. However, there is no support for that (no CL_ABGR). So I tried a couple of formats without any change.

I just solved it.
It seems that OpenCL had little to do with the problem.
The bug was in the part of creating the Texture, because it seems SDL2 does not keep the format of the surface.
I had to use SDL_CreateTexture and explicitly set the format for it to work as expected.