Image flipping

I’m trying to flip an image horizontally but It’s only the blue colors that are flipped.
Here’s an example:

I want the whole image flipped.
Here’s the code that is supposed to flip the image:

//Copy the image to a temporary place
memcpy(TempImage, ImageData, ImageSize);

//Flip image horizontally
for (UINT y = 0; y < ImageHeight; y++)
{
for (UINT x = 0; x < ImageWidth; x++)
{
ImageData[y * BytesPerLine + (x*3)] = TempImage[y * BytesPerLine + ((ImageWidth-x)*3)];
}
}

//Release the temporary image
free(TempImage);

Help would really be apreciated!

I assume three channels, and 8 bits per channel.

You loop through each pixel in the image, and for each pixel, you move the first byte from TempImage to ImageData (I assume they are both byte pointers). Since you have three channels, you need to move three bytes, one byte per channel.

In the innermost loop, add these two lines.

ImageData[y * BytesPerLine + (x*3) + 1] = TempImage[y * BytesPerLine + ((ImageWidth-x)3) + 1]; // second channel
ImageData[y * BytesPerLine + (x
3) + 2] = TempImage[y * BytesPerLine + ((ImageWidth-x)*3) + 2]; // third channel

Thanks!