Jump to content
  • Advertisement


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


Flipping an image on the y-axis

This topic is 6177 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

Hello, Does anyone have a good function that will flip an image (i.e. tga, bmp) on the y-axis, so in other words if you had a smiley face for a picture and you wanted the left eye to be on the right side how would you do that? I was able to be able to flip the images upside down, but flipping them sideways hasn''t been a success yet; I can only get inverse colors and 2/3 of its flipped, arg, hehe. I just want to manipulate the image data to get this effect. Any help would be greatly appreciated!

Share this post

Link to post
Share on other sites
If you have a vertical axis about the horizontal middle, then your transformation is essentially
f(x) = -x 

Since both x and -x are defined relative to the axis (x = 0), then your required horizontal flip is

new_x = middle_x + (middle_x - old_x)
= 2 * middle_x - old_x
= width - old_x

Use exactly the same algorithm for the y-axis. I don''t think you need to mess with the pixel depth data.

To you it''s a Bently, to me it''s a blue car...

Share this post

Link to post
Share on other sites

const int WIDTH = 640;
const int HEIGHT = 480;

struct RGB
char r;
char g;
char b;


for(int y=0; y < HEIGHT; y++)
for(int x=0; x < WIDTH; x++)
image2[WIDTH-x-1][y].r = image1[x][y].r;
image2[WIDTH-x-1][y].g = image1[x][y].g;
image2[WIDTH-x-1][y].b = image1[x][y].b;

Edited by - TerranFury on October 22, 2001 3:45:28 PM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!