Skip to main content
gamedev.net
🔒 Locked

1-bit Bitmap Saving

Started by EepTech Jan 29, 2004 at 12:25 PM 1 replies 700+ views
Original Post
EepTech
EepTech
I am having trouble saving an array of raw data as a 1-bit bitmap. It works with some of the arrays, but not all. I believe my problem is with the padding. Can anyone help? Here is how I am creating the bitmap and I know I need to add the padding code in place of the last two memcpys, but I don''t know how. Thank in Advance! char *Create1BitBmp(UINT uWidth, UINT uHeight, UINT uBpp, char *pImageData) { BITMAPFILEHEADER BmpHeader; // Bitmap header BITMAPINFOHEADER BmpInfo; // Bitmap info memset(&BmpHeader, 0, sizeof(BITMAPFILEHEADER)); memset(&BmpInfo, 0, sizeof(BITMAPINFOHEADER)); // Define the bitmap file header BmpHeader.bfType = 0x4D42; BmpHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + ((uBpp <= 8) ? (int)(4 * pow(2, uBpp)) : 0); // Define the bitmap info BmpInfo.biSize = sizeof(BITMAPINFOHEADER); BmpInfo.biPlanes = 1; BmpInfo.biBitCount = uBpp; BmpInfo.biCompression = BI_RGB; // no compression BmpInfo.biSizeImage = ((((uWidth * uBpp) + 31) & ~31) >> 3) * uHeight; BmpInfo.biWidth = uWidth; BmpInfo.biHeight = uHeight; BmpHeader.bfSize = BmpHeader.bfOffBits + BmpInfo.biSizeImage; char *pImage = new char[BmpHeader.bfSize]; memcpy(pImage, &BmpHeader, sizeof(BITMAPFILEHEADER)); memcpy(pImage + sizeof(BITMAPFILEHEADER), &BmpInfo, sizeof(BITMAPINFOHEADER)); if (uBpp == 1) { RGBQUAD RgbPal[2]; // Create Black and White Palette RgbPal[0].rgbRed = 255; // White RgbPal[0].rgbGreen = 255; RgbPal[0].rgbBlue = 255; RgbPal[0].rgbReserved = 0; // No Alpha RgbPal[1].rgbRed = 0; // Black RgbPal[1].rgbGreen = 0; RgbPal[1].rgbBlue = 0; RgbPal[1].rgbReserved = 0; // No Alpha memcpy(pImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER), RgbPal, (sizeof(RGBQUAD) << 1)); memcpy(pImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (sizeof(RGBQUAD) << 1), pImageData, BmpInfo.biSizeImage); } else { memcpy(pImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER), Pal256Gray, (sizeof(BYTE) << 10)); memcpy(pImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (sizeof(BYTE) << 10), pImageData, BmpInfo.biSizeImage); } return pImage; }
RPGeezus
RPGeezus
I''m not going to read your code, but I will suggest you try the following.

Write out a bitmap with a width of 32.

Write out another bitmap with a width of 33.

Which one looks good? If they''re both broken, then you''re code is generally flawed. If the width 32 works, and the width 33 doesn''t, then your padding isn''t working properly. If you''re padding doesn''t work, step through your code with a debugger.

Cheers,
Will
EepTech
EepTech
I have solved the problem. It was the padding. Thanks for the help though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.