Fixed decoding HAM6 image with masking
authorSam Lantinga <slouken@libsdl.org>
Mon, 10 May 2010 22:40:18 -0700
changeset 251a6565b353095
parent 250 692379215a48
child 252 59a9fcacf8fc
Fixed decoding HAM6 image with masking
IMG_lbm.c
     1.1 --- a/IMG_lbm.c	Mon May 10 21:26:13 2010 -0700
     1.2 +++ b/IMG_lbm.c	Mon May 10 22:40:18 2010 -0700
     1.3 @@ -55,7 +55,7 @@
     1.4      Uint8 pad1;			/* dummy value, for padding */
     1.5      Uint16 tcolor;		/* transparent color */
     1.6      Uint8 xAspect,		/* pixel aspect ratio */
     1.7 -         yAspect;
     1.8 +          yAspect;
     1.9      Sint16  Lpage;		/* width of the screen in pixels */
    1.10      Sint16  Hpage;		/* height of the screen in pixels */
    1.11  } BMHD;
    1.12 @@ -89,7 +89,7 @@
    1.13  	SDL_Surface *Image;
    1.14  	Uint8       id[4], pbm, colormap[MAXCOLORS*3], *MiniBuf, *ptr, count, color, msk;
    1.15  	Uint32      size, bytesloaded, nbcolors;
    1.16 -	Uint32      i, j, bytesperline, nbplanes, plane, h;
    1.17 +	Uint32      i, j, bytesperline, nbplanes, stencil, plane, h;
    1.18  	Uint32      remainingbytes;
    1.19  	Uint32      width;
    1.20  	BMHD	      bmhd;
    1.21 @@ -238,12 +238,13 @@
    1.22  		nbplanes = 1;
    1.23  	}
    1.24  
    1.25 -	if ( bmhd.mask & 1 ) ++nbplanes;   /* There is a mask ( 'stencil' ) */
    1.26 +	stencil = (bmhd.mask & 1);   /* There is a mask ( 'stencil' ) */
    1.27  
    1.28  	/* Allocate memory for a temporary buffer ( used for
    1.29             decompression/deinterleaving ) */
    1.30  
    1.31 -	if ( ( MiniBuf = (void *)malloc( bytesperline * nbplanes ) ) == NULL )
    1.32 +	MiniBuf = (void *)malloc( bytesperline * (nbplanes + stencil) );
    1.33 +	if ( MiniBuf == NULL )
    1.34  	{
    1.35  		error="no enough memory for temporary buffer";
    1.36  		goto done;
    1.37 @@ -260,7 +261,8 @@
    1.38  	/* There is no palette in 24 bits ILBM file */
    1.39  	if ( nbcolors>0 && flagHAM==0 )
    1.40  	{
    1.41 -		int nbrcolorsfinal = 1 << nbplanes;
    1.42 +		/* FIXME: Should this include the stencil? See comment below */
    1.43 +		int nbrcolorsfinal = 1 << (nbplanes + stencil);
    1.44  		ptr = &colormap[0];
    1.45  
    1.46  		for ( i=0; i<nbcolors; i++ )
    1.47 @@ -308,7 +310,7 @@
    1.48  	{
    1.49  		/* uncompress the datas of each planes */
    1.50  
    1.51 -		for ( plane=0; plane < nbplanes; plane++ )
    1.52 +		for ( plane=0; plane < (nbplanes+stencil); plane++ )
    1.53  		{
    1.54  			ptr = MiniBuf + ( plane * bytesperline );
    1.55  
    1.56 @@ -331,7 +333,7 @@
    1.57  
    1.58  						if ( ( count > remainingbytes ) || !SDL_RWread( src, &color, 1, 1 ) )
    1.59  						{
    1.60 -						   error="error reading BODY chunk";
    1.61 +							error="error reading BODY chunk";
    1.62  							goto done;
    1.63  						}
    1.64  						memset( ptr, color, count );
    1.65 @@ -384,7 +386,7 @@
    1.66  				{
    1.67  					memset( ptr, 0, 8 );
    1.68  
    1.69 -					for ( plane=0; plane < nbplanes; plane++ )
    1.70 +					for ( plane=0; plane < (nbplanes + stencil); plane++ )
    1.71  					{
    1.72  						color = *( MiniBuf + i + ( plane * bytesperline ) );
    1.73  						msk = 0x80;