• Advertisement

Archived

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

Bitmap funkiness

This topic is 6417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?
    
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);
}
    

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement