How to load BMP correctly.....?
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
HHSDrum@yahoo.com
Polarisoft Home Page
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?.....
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 Hacker
Blackstream''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.
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement