I'm trying to flip an image which has its pixels stored in a vector. For some reason, when I try to flip it, the image gets distorted and gray/fuzzy. Any idea why?
My code is as follows:
void JNIData::FlipBytes(void*& Result, bool TopDown)
{
unsigned char* Pixels = &BufferPixels[0]; //vector of pixels/unsigned chars.
unsigned char* BuffPos = static_cast<unsigned char*>(Result);
for (int I = 0; I < height; ++I)
{
for (int J = 0; J < width; ++J)
{
int Offset = TopDown ? (height - 1 - I) * width + J : I * width + J;
*(BuffPos++) = *(Pixels++ + Offset);
*(BuffPos++) = *(Pixels++ + Offset);
*(BuffPos++) = *(Pixels++ + Offset);
if (Bpp > 24)
*(BuffPos++) = *(Pixels++ + Offset);
}
if (Bpp == 24)
{
BuffPos += width % 4;
Pixels += width % 4;
}
}
}