Skip to content

Commit

Permalink
Date: Mon, 13 Sep 2004 09:16:01 +0200
Browse files Browse the repository at this point in the history
From: "Marc Le Douarain"
Subject: SDL_image / ILBM loader fix

With some pictures (mask and 256 colors), the color palette
loop for stencil was trying to access to 512 colors of a 8
bits surface previously defined, and was crashing.
  • Loading branch information
slouken committed Sep 15, 2004
1 parent 1369d4e commit 7a96ced
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions IMG_lbm.c
Expand Up @@ -24,12 +24,12 @@

/* This is a ILBM image file loading framework
Load IFF pictures, PBM & ILBM packing methods, with or without stencil
Written by Daniel Morais ( Daniel@Morais.com ) in September 2001.
24 bits ILBM files support added by Marc Le Douarain (mavati AT club-internet
POINT fr) in December 2002.
Written by Daniel Morais ( Daniel AT Morais DOT com ) in September 2001.
24 bits ILBM files support added by Marc Le Douarain (http://www.multimania.com/mavati)
in December 2002.
EHB and HAM (specific Amiga graphic chip modes) support added by Marc Le Douarain
(mavati AT club-internet POINT fr) in December 2003.
Stencil and colorkey fixes by David Raulo (david.raulo@free.fr) in February 2004.
(http://www.multimania.com/mavati) in December 2003.
Stencil and colorkey fixes by David Raulo (david.raulo AT free DOT fr) in February 2004.
*/

#include <stdio.h>
Expand Down Expand Up @@ -253,6 +253,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
/* There is no palette in 24 bits ILBM file */
if ( nbcolors>0 && flagHAM==0 )
{
int nbrcolorsfinal = 1 << nbplanes;
ptr = &colormap[0];

for ( i=0; i<nbcolors; i++ )
Expand Down Expand Up @@ -281,14 +282,16 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )

/* If nbcolors < 2^nbplanes, repeat the colormap */
/* This happens when pictures have a stencil mask */
for ( i=nbcolors; i < (1 << nbplanes); i++ )
if ( nbrcolorsfinal > (1<<bmhd.planes) ) {
nbrcolorsfinal = (1<<bmhd.planes);
}
for ( i=nbcolors; i < nbrcolorsfinal; i++ )
{
Image->format->palette->colors[i].r = Image->format->palette->colors[i%nbcolors].r;
Image->format->palette->colors[i].g = Image->format->palette->colors[i%nbcolors].g;
Image->format->palette->colors[i].b = Image->format->palette->colors[i%nbcolors].b;
}

Image->format->palette->ncolors = 1 << nbplanes;
Image->format->palette->ncolors = nbrcolorsfinal;
}

/* Get the bitmap */
Expand Down

0 comments on commit 7a96ced

Please sign in to comment.