SDL_Loadbmp fail

Hi Guys,

First time poster so any help or advise would be greatly appreciated…

I’m having a problem loading a bmp image. I’m basically passing the
filename to a function that does an SDL_LoadBMP. Most of the code is
from examples. I’ve been trawling through this for ages and cannot
figure out what is going on. Basically if I pass it an image that is
320x480 .bmp, it’s fine. An image of 704x16 .bmp crashes.

Tony.

Code included below…

SDL_TextureID load_image (char *image_name) {

SDL_Surface *bmp_surface;
 	SDL_Surface *bmp_surface_rgba;
int format = SDL_PIXELFORMAT_ABGR8888;      // desired texture format
Uint32 Rmask, Gmask, Bmask, Amask;  /* masks for desired format */
	int bpp;                    /* bits per pixel for desired format */

 // load the image onto a temp background
 bmp_surface = SDL_LoadBMP( image_name );
 if ( bmp_surface == NULL ) {
	fatalError( "could not load image" );    // <<<---Crashes here--->>>
}

/* set white to transparent */
 SDL_SetColorKey(bmp_surface, 1, SDL_MapRGB(bmp_surface->format,  

255, 0, 255));
SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask,
&Amask);

//	create a new RGBA surface and blit the bmp to it

 bmp_surface_rgba = SDL_CreateRGBSurface(0, bmp_surface->w,  

bmp_surface->h, bpp, Rmask, Gmask, Bmask, Amask);
SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba, NULL);

// create new texture from loaded image
 SDL_TextureID texture_id = SDL_CreateTextureFromSurface( format,  

bmp_surface_rgba );
if ( texture_id == 0 ) {
fatalError( “could not create new texture” );
}

// free up all allocated memory
 SDL_FreeSurface( bmp_surface );
SDL_FreeSurface( bmp_surface_rgba );

return ( texture_id );

}

Hi Guys,

First time poster so any help or advise would be greatly
appreciated…

I’m having a problem loading a bmp image. I’m basically passing the
filename to a function that does an SDL_LoadBMP. Most of the code is
from examples. I’ve been trawling through this for ages and cannot
figure out what is going on. Basically if I pass it an image that is
320x480 .bmp, it’s fine. An image of 704x16 .bmp crashes.

Hi,

Are you really sure that file is a bmp? (Check on console with
"file …".)

Another reason could be that the size of the image is to big for your
SDL graphics backend.

Check SDL_GetError() to get some more helpfull information.

  • AlbertAm 24.02.2009 um 05:38 schrieb Tony Parkes:

The error is an ‘out of memory’ error. The image I’m trying to load is
704x16, so I didn’t think this would be an issue with memory. Is there
a limit to the size of images that SDL_LoadBMP can handle?On 24/02/2009, at 4:21 PM, Albert Zeyer wrote:

Am 24.02.2009 um 05:38 schrieb Tony Parkes:

Hi Guys,

First time poster so any help or advise would be greatly
appreciated…

I’m having a problem loading a bmp image. I’m basically passing the
filename to a function that does an SDL_LoadBMP. Most of the code
is from examples. I’ve been trawling through this for ages and
cannot figure out what is going on. Basically if I pass it an image
that is 320x480 .bmp, it’s fine. An image of 704x16 .bmp crashes.

Hi,

Are you really sure that file is a bmp? (Check on console with
"file …".)

Another reason could be that the size of the image is to big for
your SDL graphics backend.

Check SDL_GetError() to get some more helpfull information.

  • Albert

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

If it is some exotic image format (such as one of the various "raw"
image formats) perhaps it is being incorrectly misinterpreted as a BMP
by coincidence: but being misinterpreted as a bitmap with very large
dimensions?

Please post an example program and your BMP file (or one that also
causes the problem) so that it can be debugged! Thanks!On Tue, Feb 24, 2009 at 12:41 AM, Tony Parkes wrote:

On 24/02/2009, at 4:21 PM, Albert Zeyer wrote:

Are you really sure that file is a bmp? (Check on console with “file
…”.)

The error is an ‘out of memory’ error. The image I’m trying to load is
704x16, so I didn’t think this would be an issue with memory. Is there a
limit to the size of images that SDL_LoadBMP can handle?


http://codebad.com/

I tracked this problem down. Thanks for the advise, implying it could
be mis-interpreting the file dimensions made me take a closer look. It
seems that if I create an image of say 100 x 100 in pixelmator or save
an image in preview on a mac, it saves the image with the dimensions
as 100 x -100. Gimp fixed the issue.On 24/02/2009, at 4:52 PM, Donny Viszneki wrote:

On Tue, Feb 24, 2009 at 12:41 AM, Tony Parkes <@Tony_Parkes> wrote:

On 24/02/2009, at 4:21 PM, Albert Zeyer wrote:

Are you really sure that file is a bmp? (Check on console with “file
…”.)

The error is an ‘out of memory’ error. The image I’m trying to load
is
704x16, so I didn’t think this would be an issue with memory. Is
there a
limit to the size of images that SDL_LoadBMP can handle?

If it is some exotic image format (such as one of the various "raw"
image formats) perhaps it is being incorrectly misinterpreted as a BMP
by coincidence: but being misinterpreted as a bitmap with very large
dimensions?

Please post an example program and your BMP file (or one that also
causes the problem) so that it can be debugged! Thanks!


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I tracked this problem down. Thanks for the advise, implying it could
be mis-interpreting the file dimensions made me take a closer look. It
seems that if I create an image of say 100 x 100 in pixelmator or
save
an image in preview on a mac, it saves the image with the
dimensions
as 100 x -100. Gimp fixed the issue.

Actually, that probably is a bug in SDL. A negative height value in a
windows bitmap file indicates that the pixel data is stored top down
instead of bottom up. If SDL is reading that -100 as a height of
0x100000000-100, that’s an error.On Tuesday 24 Feb 2009 01:58:02 Tony Parkes wrote:

Excellent work Tony! Kenneth, I don’t really know the BMP file format,
perhaps you’d like to submit a patch for this?On Tue, Feb 24, 2009 at 3:32 AM, Kenneth Bull wrote:

On Tuesday 24 Feb 2009 01:58:02 Tony Parkes wrote:

I tracked this problem down. Thanks for the advise, implying it could
be mis-interpreting the file dimensions made me take a closer look. It
seems that if I create an image of say 100 x 100 in pixelmator or
save
an image in preview on a mac, it saves the image with the
dimensions
as 100 x -100. Gimp fixed the issue.

Actually, that probably is a bug in SDL. ?A negative height value in a
windows bitmap file indicates that the pixel data is stored top down
instead of bottom up. ?If SDL is reading that -100 as a height of
0x100000000-100, that’s an error.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/

Try the attached file (not thoroughly tested, but compiles without warnings
with gcc -c SDL_bmp2.c pkg-config sdl --cflags).

I renamed SDL_LoadBMP_RW and SDL_SaveBMP_RW so you can test it without
recompiling SDL. This is for 1.2, not 1.3.

This should also work better for BITMAPV4HEADER and BITMAPV5HEADER bitmaps.

-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDL_bmp2.c
Type: text/x-csrc
Size: 14668 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090224/c086dfa7/attachment.cOn Tuesday 24 Feb 2009 06:52:59 Donny Viszneki wrote:

Excellent work Tony! Kenneth, I don’t really know the BMP file format,
perhaps you’d like to submit a patch for this?

This has been reported before… I guess a patch didn’t result?

Jonny DOn Tue, Feb 24, 2009 at 10:41 AM, Kenneth Bull wrote:

On Tuesday 24 Feb 2009 06:52:59 Donny Viszneki wrote:

Excellent work Tony! Kenneth, I don’t really know the BMP file format,
perhaps you’d like to submit a patch for this?

Try the attached file (not thoroughly tested, but compiles without warnings
with gcc -c SDL_bmp2.c pkg-config sdl --cflags).

I renamed SDL_LoadBMP_RW and SDL_SaveBMP_RW so you can test it without
recompiling SDL. This is for 1.2, not 1.3.

This should also work better for BITMAPV4HEADER and BITMAPV5HEADER bitmaps.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org