Advertisement

How to load BMP correctly.....?

Started by July 19, 2001 07:59 AM
6 comments, last by HalfLucifer 23 years, 7 months ago
I took the BMP loading code in GameTut#4 to test the bitmap loading. After testing with a lot of bitmaps, I found that while loading a few of them, it would directly CRASH whole program! I am sure those bitmaps are okay because they can be loaded with AUX correctly. But I do not like to use AUX and I would like to code a safe and complete BMP loading function. Could someone help me out? Thanks a lot.
are the bitmaps you''re loading powers of four in width and height? 16x16,256x256, etc?

HHSDrum@yahoo.com
Polarisoft Home Page
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Advertisement
Yeah, I''ve checked that for sure.
For example, while I try to load "NeHe.bmp" in lesson29.zip and "BG.bmp" in lesson24.zip using that code,
it DID crashed my program.
Anyone knows why?.....
You may need to post your code... it could be something as simple as pointer misuse. That was my problem when I took the bitmap loading code from the Superbible (very nice bitmap loading code imo).

-Blackstream

Will you, won''t you, will you, won''t you, won''t you take my virus?

-The Mad Hacker

Blackstream''s Webpage
-Blackstream Will you, won't you, will you, won't you, won't you take my virus?-The Mad HackerBlackstream's Webpage
I had problems with the bmp code aswell.

info_header.biSizeImage does not return the correct size
(sometimes) if you are using uncompressed format.

To quote microsoft:-

"Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps. "

So I used:-

t_width = info_header.biWidth;
t_height= info_header.biHeight;
t_bpp = info_header.biBitCount;

t_data = new unsigned char [t_width*t_height*3];

to calculate the image size. This prevented my code from crashing.
Hope this helps.



quote:
Original post by Heater To quote microsoft:-

"Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps. "


Some guy at Microsoft obviously had a brainfart when he designed the .bmp file.



-Blackstream

Will you, won''t you, will you, won''t you, won''t you take my virus?

-The Mad Hacker

Blackstream''s Webpage
-Blackstream Will you, won't you, will you, won't you, won't you take my virus?-The Mad HackerBlackstream's Webpage
Advertisement

You''re the man ~~~!! :D
I change the code with:

image->width = InfoHeader.biWidth;
image->height = InfoHeader.biHeight;
image->bpp = InfoHeader.biBitCount;
ImageSize = image->width * image->height * image->bpp;
image->data = new unsigned char [ImageSize];

// using ImageSize=image->width*image->height*3 not necessarily safe, still got crashed in some bitmaps.

Now loading any bitmaps would not crash my program, though,
while loading "BG.bmp" in lesson24.zip, still it would load in a bag image (but would not crash).
I think the code may not be 100% perfect though, I''ll keep testing loading other bitmaps.

I think I''d send ShiningKnight an email to report this.
Thanks a lot lot lot!
You could always write your own loader as the bmp spec is about as simple as you can get. I wrote my own, for a java program then later in c++, some time ago and have never had a problem with it.

The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson

This topic is closed to new replies.

Advertisement