Archived

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

PSioNiC

I HATE BITMAP LOADING

Recommended Posts

i made my own bitmap loader to load in a height map. im not using any API calls im doing it from scratch with fread()''s when i load in the bitmap, it looks as though fread is adding 0''s to the bitmap in weird places. my test bitmap is has only one color on it (r=150, g=150, b=150). when i output all of the data to a file, it should look like this: (assume that each line is a new pixel, the first column is for red, the next green and the next blue): 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 but it doesn''t it looks like this: 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 0 0 150 i have no idea where these 0''s are coming from. I am using fread to load the data straight out of the bmp file and the outputting it on the next line and these zeros that always seem to be traveling in pairs of two are coming out of no where. Again my test bitmap has only one color on it, so these are not supposed to be there. The bitmaps color format is R8B8G8. here is the code:

	int			x, y;
	V3DCOLOR	Color;
	FILE		*File = fopen(filename, "rb");

	fread(&BitmapType,			sizeof(BitmapType),			1, File);
	fread(&BitmapFileSize,		sizeof(BitmapFileSize),		1, File);
	fread(&BitmapReserved1,		sizeof(BitmapReserved1),	1, File);
	fread(&BitmapReserved2,		sizeof(BitmapReserved2),	1, File);
	fread(&BitmapOffBits,		sizeof(BitmapOffBits),		1, File);

	fread(&BitmapSize,			sizeof(BitmapSize),			1, File);
	fread(&BitmapWidth,			sizeof(BitmapWidth),		1, File);
	fread(&BitmapHeight,		sizeof(BitmapHeight),		1, File);
	fread(&BitmapPlanes,		sizeof(BitmapPlanes),		1, File);
	fread(&BitmapBitCount,		sizeof(BitmapBitCount),		1, File);
	fread(&BitmapCompression,	sizeof(BitmapCompression),	1, File);
	fread(&BitmapSizeImage,		sizeof(BitmapSizeImage),	1, File);
	fread(&BitmapXPelsPerMeter, sizeof(BitmapXPelsPerMeter),1, File);
	fread(&BitmapYPelsPerMeter, sizeof(BitmapYPelsPerMeter),1, File);
	fread(&BitmapClrUsed,		sizeof(BitmapClrUsed),		1, File);
	fread(&BitmapClrImportant,	sizeof(BitmapClrImportant), 1, File);

	BitmapData = new V3DCOLOR[BitmapWidth * BitmapHeight];

	if (!BitmapData) 
		return false;


	for (x = 0; x < BitmapWidth; x++) {
		for (y = 0; y < BitmapHeight; y++) {
			
			fread(&Color, sizeof(Color), 1, File);
			
			BitmapData[y + x * BitmapWidth].r = Color.r;
			BitmapData[y + x * BitmapWidth].g = Color.g;
			BitmapData[y + x * BitmapWidth].b = Color.b;		
		}
	}

	fclose(File);


 
right after that final fread

fread(&Color, sizeof(Color), 1, File);

 
i added a line that would output what came from it and it was the 150''s polluted with 0''s anybody know ?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Haha... silly coder (j/k). If the width isn''t evenly divisible by 4.. it pads it with 0''s.

Billy

BillyB@mrsnj.com -> Email me, and I can give you my bitmap loader (source code).

Share this post


Link to post
Share on other sites
hey if either one of you would offer your loader,
i''d appreciate it. i''m trying to do mine through
GDI calls and i swear i can''t get the bitmap data
at all... 2 days of work on a pathetically simple
problem.

you can mail me at chisholm@cs.utk.edu


thanks
dan

Share this post


Link to post
Share on other sites