Correct flip/mirror of pixels of an image?

Posted by igor on Stack Overflow See other posts from Stack Overflow or by igor
Published on 2010-04-15T17:04:10Z Indexed on 2010/04/15 17:13 UTC
Read the original article Hit count: 702

Filed under:
|

http://tinypic.com/r/fwubzc/5

That shows what a flip should be and what a mirror should be.

Code for both types of mirrors:

void mirrorLeftRight()
{
    for (int x = 0; x < width/2; x++) {
            for (int y = 0; y < height; y++) {
                int temp = pixelData[x][y];
                pixelData[x][y]=pixelData[width-x][y]
                pixelData[width-x][y]=temp;
            }
    }
}

void mirrorUpDown()
{
    for (int x = 0; x < width; x++) {
            for (int y = 0; y < height/2; y++) {
                int temp = pixelData[x][y];
                pixelData[x][y]=pixelData[x][height-y]
                pixelData[x][height-y]=temp;
            }
    }
}

Does this seem right for mirrors?

And for flip, just a matter of using width and height w/o dividing by 2?

© Stack Overflow or respective owner

Related posts about c++

Related posts about homework