Jump to content
• Advertisement

#### Archived

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

##### Share on other sites
Advertisement
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...
"Diddy"
P.Diddy

#### Share this post

##### Share on other sites
  const int WIDTH = 640;const int HEIGHT = 480;struct RGB{ char r; char g; char b;};RGB image1[WIDTH][HEIGHT];RGB image2[WIDTH][HEIGHT];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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5
• Advertisement

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632591
• Total Posts
3007250

×

## 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!