LPDIRECTDRAWSURFACE7 LoadBitmap(char *filename, int palette)
{
BitmapFile bitmap;
FILE *filepointer;
UCHAR *surfacebuffer;
LPDIRECTDRAWSURFACE7 bitmapsurface;
if(!(filepointer = fopen(filename, "r")))
ErrorBox("Could not open bitmap file");
if(!(fread(&bitmap.bitmapfileheader, sizeof(BITMAPFILEHEADER), 1, filepointer)))
ErrorBox("Could not read bitmapfileheader");
if(bitmap.bitmapfileheader.bfType != 0x4D42)
ErrorBox("File is not a bitmap file");
if(!(fread(&bitmap.bitmapinfoheader, sizeof(BITMAPINFOHEADER), 1, filepointer)))
ErrorBox("Could not read bitmapinfoheader");
if(bitmap.bitmapinfoheader.biBitCount == 8)
if(!(fread(&bitmap.palette, sizeof(PALETTEENTRY), 256, filepointer)))
ErrorBox("Could not read palette");
if(!(bitmap.buffer = new BYTE[bitmap.bitmapinfoheader.biSizeImage]))
ErrorBox("Could not allocate memory");
if(!(fread(bitmap.buffer, sizeof(BYTE), bitmap.bitmapinfoheader.biSizeImage, filepointer)))
ErrorBox("Could not read bitmap image data");
bitmapsurface = CreateOffScreenPlain(bitmap.bitmapinfoheader.biWidth, bitmap.bitmapinfoheader.biHeight);
bitmapsurface->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
surfacebuffer = (UCHAR *)ddsd.lpSurface;
for(int index=0; index < bitmap.bitmapinfoheader.biHeight; index++)
memcpy(&surfacebuffer[index * bitmap.bitmapinfoheader.biWidth],
&bitmap.buffer[(bitmap.bitmapinfoheader.biHeight - (index + 1)) * bitmap.bitmapinfoheader.biWidth],
bitmap.bitmapinfoheader.biWidth + ddsd.lPitch);
bitmapsurface->Unlock(NULL);
delete [] bitmap.buffer;
if(fclose(filepointer) != 0)
ErrorBox("Could not close bitmap file");
if(palette == YES)
AttachPalette(bitmap.palette);
return(bitmapsurface);
}
Bitmap funkiness
Im having trouble with displaying any bitmaps that are not ^2 x ^2. I want to display a 24x24 bitmap but something is going wrong and i have a black bar across the bottom. The bitmap looks fine in LView and paint but try as I might I haven''t been able to figure why this happens. Could it be my bitmap loader?
There's always something smaller and something bigger. Don't sweat the small stuff and don't piss off the big stuff :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement