Archived

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

Viscous-Flow

Flipping an image on the y-axis

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...
"Diddy"
P.Diddy

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;
};

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


Link to post
Share on other sites