Jump to content
  • Advertisement

Archived

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

HalfLucifer

How to load BMP correctly.....?

This topic is 6237 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

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.

Share this post


Link to post
Share on other sites
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?.....

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.



Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!