Archived

This topic is now archived and is closed to further replies.

Image flipping

This topic is 5776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! In my application I use this code to flip a 24-bit image vertical(upside-down): int BytesPerLine = ImageWidth*3; //Copy the data to a temporary place memcpy(TempImage, ImageData, ImageSize); //Flip the image for (UINT y = 0; y < ImageHeight; y++) memcpy(&ImageData[((ImageHeight - 1) - y) * BytesPerLine], &TempImage[y * BytesPerLine], BytesPerLine); //Free the temporary image free(TempImage); Now, if I want to flip the image horizontal instead of vertical, how would I do that? Thanks in advance.

Share this post


Link to post
Share on other sites
Hmmmm, I don''t seem to get it right... I don''t think I understood what you meant. Maybe you could you post the modified code? That''d be great!

Share this post


Link to post
Share on other sites
To lazy to read and then mod the code so...

You get the number of pixels on the x axis in the image as your starting point for coping. Begin to copy from that starting point on the original and place the pixel at 0,0 on the copy, increment the position on the x axis you copy to as you pull pixels from the original and repeat the process for each line of the image top to bottom.

Share this post


Link to post
Share on other sites
He means you copy the data a pixel at a time.

  
//Copy the data to a temporary place

memcpy(TempImage, ImageData, ImageSize);

//Flip the 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)];

//Free the temporary image

free(TempImage);



Thar.

Share this post


Link to post
Share on other sites
Ummm, I tried the code, and it almost works. It seems like only the blue colors are flipped.
Here''s an example:
wallsoft.form08.com/original.jpg --- Original image
wallsoft.form08.com/flipped.jpg --- Flipped image

Any suggestions would be apreciated, I''m killing myself over here... =)

Share this post


Link to post
Share on other sites
HEHEH whoops, hehe yeah I was only flipping one byte of colour.

for a 24 bit image:
  
//Copy the data to a temporary place

memcpy(TempImage, ImageData, ImageSize);

//Flip the image HORIZONTALLY

for (UINT y = 0; y < ImageHeight; y++)
for (UINT x = 0; x < ImageWidth; x++)
memcpy(ImageData + y*BytesPerLine + (x*3), TempImage + y*BytesPerLine + ((ImageWidth - x)*3),3);

//Free the temporary imagefree(TempImage);



if you were using a 32 bit image, you would change all the 3''s
to 4''s, a 16 bit image you would change teh 3''s to 2''s etc.

PS. I think the effect you got is WAY cool anyway

Share this post


Link to post
Share on other sites