Wednesday 15 April 2015

c++ - Flip an image vertically -



c++ - Flip an image vertically -

i'm trying flip image vertically, after retrieving buffer opengl. seems outputting wrong image next code:

const int width = 100; const int height = width; const int components = 3; unsigned char pixels[width * height * components]; glreadpixels(0, 0, width, height, gl_rgb, gl_unsigned_byte, pixels); unsigned char flippixels[width * height * components]; (int = 0; < width; ++i) { (int j = 0; j < height; ++j) { (int k = 0; k < components; ++k) { flippixels[i + j * width + k] = pixels[(height) * (width) - ((j+1) * width) + + k]; } } }

i know can iterate half height , accomplish same, want implement going through finish height of image. can't seem figure out what's wrong code. help appreciated.

i'm not sure how image stored indices i , k given same stride suspicious. maybe want i * components , j * width * components. after that, inverting vertically should have alter j (height - j - 1).

flippixels[(i + j * width) * components + k] = pixels[(i + (height - 1 - j) * width) * components + k];

c++ image-processing

No comments:

Post a Comment