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


Flipping Bitmaps

Recommended Posts

monkey-poop    122
Hello, I have created a function for my bitmap loader that flips the bitmap vertically, since most bitmaps are bottom-up. It works fine for 8-, 16- and 24-bit modes, but it shuts down my game rather nicely when I try to do it in 32-bit mode. Here is my code: /////////////// // Get the image UCHAR *image = bitmap->buffer; // Get the size of each line of the bitmap int bytesPerLine = bitmap->bitmapInfoHeader.biWidth * (bitmap->bitmapInfoHeader.biBitCount / 8); // Get the number of lines in the bitmap int height = bitmap->bitmapInfoHeader.biHeight; // Allocate the temporary buffer UCHAR *tempBuffer = (UCHAR *)malloc (bytesPerLine * height); if (!(tempBuffer)) { App->ReportError (true, "Bitmap error", "Unable to allocate bitmap buffer: %s!", filename); return FALSE; } // Copy image to work area // ******FAILS HERE****** memcpy (tempBuffer, image, bytesPerLine * height); // Flip vertically for (index = 0; index < height; index++) memcpy (&image[((height - 1) - index) * bytesPerLine], &tempBuffer[index * bytesPerLine], bytesPerLine); // Release the memory free (tempBuffer); //////////////// Does anyone know why? Thanks! Jon

Share this post

Link to post
Share on other sites