Flipping an image on the y-axis
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!
If you have a vertical axis about the horizontal middle, then your transformation is essentially
Since both x and -x are defined relative to the axis (x = 0), then your required horizontal flip is
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement