Mattias Engdeg�rd - Tue Nov 20 08:08:53 PST 2001
authorSam Lantinga <slouken@libsdl.org>
Tue, 20 Nov 2001 16:09:46 +0000
changeset 50754bff7e03aa
parent 49 99f6bec11df8
child 51 1c08334b3753
Mattias Engdeg�rd - Tue Nov 20 08:08:53 PST 2001
* Fixed transparency in the GIF loading code
CHANGES
IMG.c
IMG_gif.c
IMG_lbm.c
SDL_image.h
     1.1 --- a/CHANGES	Fri Nov 02 20:40:32 2001 +0000
     1.2 +++ b/CHANGES	Tue Nov 20 16:09:46 2001 +0000
     1.3 @@ -1,5 +1,7 @@
     1.4  
     1.5  1.2.1:
     1.6 +Mattias Engdegrd - Tue Nov 20 08:08:53 PST 2001
     1.7 + * Fixed transparency in the GIF loading code
     1.8  Daniel Morais - Sun Sep 23 16:32:13 PDT 2001
     1.9   * Added support for the IFF (LBM) image format
    1.10  Sam Lantinga - Sun Aug 19 01:51:44 PDT 2001
     2.1 --- a/IMG.c	Fri Nov 02 20:40:32 2001 +0000
     2.2 +++ b/IMG.c	Tue Nov 20 16:09:46 2001 +0000
     2.3 @@ -69,7 +69,7 @@
     2.4  }
     2.5  
     2.6  /* Portable case-insensitive string compare function */
     2.7 -int IMG_string_equals(const char *str1, const char *str2)
     2.8 +static int IMG_string_equals(const char *str1, const char *str2)
     2.9  {
    2.10  	while ( *str1 && *str2 ) {
    2.11  		if ( toupper((unsigned char)*str1) !=
     3.1 --- a/IMG_gif.c	Fri Nov 02 20:40:32 2001 +0000
     3.2 +++ b/IMG_gif.c	Tue Nov 20 16:09:46 2001 +0000
     3.3 @@ -253,7 +253,7 @@
     3.4      } while (image == NULL);
     3.5  
     3.6  #ifdef USED_BY_SDL
     3.7 -    if ( Gif89.transparent > 0 ) {
     3.8 +    if ( Gif89.transparent >= 0 ) {
     3.9          SDL_SetColorKey(image, SDL_SRCCOLORKEY, Gif89.transparent);
    3.10      }
    3.11  #endif
     4.1 --- a/IMG_lbm.c	Fri Nov 02 20:40:32 2001 +0000
     4.2 +++ b/IMG_lbm.c	Tue Nov 20 16:09:46 2001 +0000
     4.3 @@ -36,37 +36,25 @@
     4.4  #ifdef LOAD_LBM
     4.5  
     4.6  
     4.7 -//===========================================================================
     4.8 -// DEFINES
     4.9 -//===========================================================================
    4.10 -
    4.11  #define MAXCOLORS 256
    4.12  
    4.13 -//===========================================================================
    4.14 -// STRUCTURES
    4.15 -//===========================================================================
    4.16 -
    4.17 -// Structure for an IFF picture ( BMHD = Bitmap Header )
    4.18 +/* Structure for an IFF picture ( BMHD = Bitmap Header ) */
    4.19  
    4.20  typedef struct
    4.21  {
    4.22 -   Uint16 w, h;		// width & height of the bitmap in pixels
    4.23 -   Sint16 x, y;      // screen coordinates of the bitmap
    4.24 -   Uint8 planes;     // number of planes of the bitmap
    4.25 -   Uint8 mask;       // mask type ( 0 => no mask )
    4.26 -   Uint8 tcomp;      // compression type
    4.27 -   Uint8 pad1;       // dummy value, for padding
    4.28 -   Uint16 tcolor;    // transparent color
    4.29 -   Uint8 xAspect,    // pixel aspect ratio
    4.30 +    Uint16 w, h;		/* width & height of the bitmap in pixels */
    4.31 +    Sint16 x, y;		/* screen coordinates of the bitmap */
    4.32 +    Uint8 planes;		/* number of planes of the bitmap */
    4.33 +    Uint8 mask;			/* mask type ( 0 => no mask ) */
    4.34 +    Uint8 tcomp;		/* compression type */
    4.35 +    Uint8 pad1;			/* dummy value, for padding */
    4.36 +    Uint16 tcolor;		/* transparent color */
    4.37 +    Uint8 xAspect,		/* pixel aspect ratio */
    4.38           yAspect;
    4.39 -   Sint16  Lpage;		// width of the screen in pixels
    4.40 -   Sint16  Hpage;		// height of the screen in pixels
    4.41 -
    4.42 +    Sint16  Lpage;		/* width of the screen in pixels */
    4.43 +    Sint16  Hpage;		/* height of the screen in pixels */
    4.44  } BMHD;
    4.45  
    4.46 -//===========================================================================
    4.47 -// See if an image is contained in a data source
    4.48 -
    4.49  int IMG_isLBM( SDL_RWops *src )
    4.50  {
    4.51  	int   is_LBM;
    4.52 @@ -85,9 +73,6 @@
    4.53  	return( is_LBM );
    4.54  }
    4.55  
    4.56 -//===========================================================================
    4.57 -// Load a IFF type image from an SDL datasource
    4.58 -
    4.59  SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
    4.60  {
    4.61  	SDL_Surface *Image;
    4.62 @@ -111,13 +96,14 @@
    4.63  		goto done;
    4.64  	}
    4.65  
    4.66 -	if ( !SDL_RWread( src, &size, 4, 1 ) ) // Should be the size of the file minus 4+4 ( 'FORM'+size )
    4.67 +	/* Should be the size of the file minus 4+4 ( 'FORM'+size ) */
    4.68 +	if ( !SDL_RWread( src, &size, 4, 1 ) )
    4.69  	{
    4.70  	   error="error reading IFF chunk size";
    4.71  		goto done;
    4.72  	}
    4.73  
    4.74 -	// As size is not used here, no need to swap it
    4.75 +	/* As size is not used here, no need to swap it */
    4.76  	
    4.77  	if ( memcmp( id, "FORM", 4 ) != 0 ) 
    4.78  	{
    4.79 @@ -133,7 +119,8 @@
    4.80  
    4.81  	pbm = 0;
    4.82  
    4.83 -	if ( !memcmp( id, "PBM ", 4 ) ) pbm = 1; // File format : PBM=Packed Bitmap, ILBM=Interleaved Bitmap
    4.84 +	/* File format : PBM=Packed Bitmap, ILBM=Interleaved Bitmap */
    4.85 +	if ( !memcmp( id, "PBM ", 4 ) ) pbm = 1;
    4.86  	else if ( memcmp( id, "ILBM", 4 ) )
    4.87  	{
    4.88  	   error="not a IFF picture";
    4.89 @@ -162,7 +149,7 @@
    4.90  
    4.91  		size = SDL_SwapBE32( size );
    4.92  		
    4.93 -		if ( !memcmp( id, "BMHD", 4 ) ) // Bitmap header
    4.94 +		if ( !memcmp( id, "BMHD", 4 ) ) /* Bitmap header */
    4.95  		{
    4.96  			if ( !SDL_RWread( src, &bmhd, sizeof( BMHD ), 1 ) )
    4.97  			{
    4.98 @@ -181,7 +168,7 @@
    4.99  			bmhd.Hpage 	= SDL_SwapBE16( bmhd.Hpage );
   4.100  		}
   4.101  
   4.102 -		if ( !memcmp( id, "CMAP", 4 ) ) // palette ( Color Map )
   4.103 +		if ( !memcmp( id, "CMAP", 4 ) ) /* palette ( Color Map ) */
   4.104  		{
   4.105  			if ( !SDL_RWread( src, &colormap, size, 1 ) )
   4.106  			{
   4.107 @@ -195,29 +182,31 @@
   4.108  
   4.109  		if ( memcmp( id, "BODY", 4 ) )
   4.110  		{
   4.111 -		   if ( size & 1 )	++size;  	// padding !
   4.112 +		    if ( size & 1 )	++size;  	/* padding ! */
   4.113  			size -= bytesloaded;
   4.114 -			if ( size )	SDL_RWseek( src, size, SEEK_CUR ); // skip the remaining bytes of this chunk
   4.115 +			/* skip the remaining bytes of this chunk */
   4.116 +			if ( size )	SDL_RWseek( src, size, SEEK_CUR );
   4.117  		}
   4.118  	}
   4.119  
   4.120 -	// compute some usefull values, based on the bitmap header
   4.121 +	/* compute some usefull values, based on the bitmap header */
   4.122  
   4.123 -	width = ( bmhd.w + 15 ) & 0xFFFFFFF0;        // Width in pixels modulo 16
   4.124 +	width = ( bmhd.w + 15 ) & 0xFFFFFFF0;  /* Width in pixels modulo 16 */
   4.125  
   4.126 -	bytesperline = ( ( bmhd.w + 15 ) / 16 ) * 2;	// Number of bytes per line
   4.127 +	bytesperline = ( ( bmhd.w + 15 ) / 16 ) * 2;
   4.128  
   4.129 -	nbplanes = bmhd.planes;                      // Number of planes
   4.130 +	nbplanes = bmhd.planes;
   4.131  
   4.132 -	if ( pbm )                                   // File format : 'Packed Bitmap'
   4.133 +	if ( pbm )                         /* File format : 'Packed Bitmap' */
   4.134  	{
   4.135  	   bytesperline *= 8;
   4.136  		nbplanes = 1;
   4.137  	}
   4.138  
   4.139 -	if ( bmhd.mask ) ++nbplanes;                 // There is a mask ( 'stencil' )
   4.140 +	if ( bmhd.mask ) ++nbplanes;       /* There is a mask ( 'stencil' ) */
   4.141  
   4.142 -	// Allocate memory for a temporary buffer ( used for decompression/deinterleaving )
   4.143 +	/* Allocate memory for a temporary buffer ( used for
   4.144 +           decompression/deinterleaving ) */
   4.145  
   4.146  	if ( ( MiniBuf = (void *)malloc( bytesperline * nbplanes ) ) == NULL )
   4.147  	{
   4.148 @@ -225,12 +214,10 @@
   4.149  		goto done;
   4.150  	}
   4.151  
   4.152 -	// Create the surface
   4.153 -
   4.154  	if ( ( Image = SDL_CreateRGBSurface( SDL_SWSURFACE, width, bmhd.h, 8, 0, 0, 0, 0 ) ) == NULL )
   4.155  	   goto done;
   4.156  
   4.157 -	// Update palette informations
   4.158 +	/* Update palette informations */
   4.159  
   4.160  	Image->format->palette->ncolors = nbcolors;
   4.161  
   4.162 @@ -243,11 +230,11 @@
   4.163  	   Image->format->palette->colors[i].b = *ptr++;
   4.164  	}
   4.165  
   4.166 -	// Get the bitmap
   4.167 +	/* Get the bitmap */
   4.168  
   4.169  	for ( h=0; h < bmhd.h; h++ )
   4.170  	{
   4.171 -		// uncompress the datas of each planes
   4.172 +	    /* uncompress the datas of each planes */
   4.173  			  
   4.174  	   for ( plane=0; plane < nbplanes; plane++ )
   4.175  		{
   4.176 @@ -255,7 +242,7 @@
   4.177  	
   4.178  			remainingbytes = bytesperline;
   4.179  	
   4.180 -			if ( bmhd.tcomp == 1 )			// Datas are compressed
   4.181 +			if ( bmhd.tcomp == 1 )	    /* Datas are compressed */
   4.182  			{
   4.183  			   do
   4.184  				{
   4.185 @@ -268,7 +255,7 @@
   4.186  					if ( count & 0x80 )
   4.187  					{
   4.188  					   count ^= 0xFF;
   4.189 -						count += 2; // now it
   4.190 +					   count += 2; /* now it */
   4.191  						
   4.192  						if ( !SDL_RWread( src, &color, 1, 1 ) )
   4.193  						{
   4.194 @@ -303,16 +290,16 @@
   4.195  			}
   4.196  		}
   4.197  	
   4.198 -		// One line has been read, store it !
   4.199 +	   /* One line has been read, store it ! */
   4.200  
   4.201  		ptr = Image->pixels;
   4.202  		ptr += h * width;
   4.203  	
   4.204 -		if ( pbm )                 // File format : 'Packed Bitmap'
   4.205 +		if ( pbm )                 /* File format : 'Packed Bitmap' */
   4.206  		{
   4.207  		   memcpy( ptr, MiniBuf, width );
   4.208  		}
   4.209 -		else							   // We have to un-interlace the bits !
   4.210 +		else		/* We have to un-interlace the bits ! */
   4.211  		{
   4.212  		   size = ( width + 7 ) / 8;
   4.213  	
     5.1 --- a/SDL_image.h	Fri Nov 02 20:40:32 2001 +0000
     5.2 +++ b/SDL_image.h	Tue Nov 20 16:09:46 2001 +0000
     5.3 @@ -85,9 +85,6 @@
     5.4  #define IMG_SetError	SDL_SetError
     5.5  #define IMG_GetError	SDL_GetError
     5.6  
     5.7 -/* used internally, NOT an exported function */
     5.8 -extern int IMG_string_equals(const char *str1, const char *str2);
     5.9 -
    5.10  /* Ends C function definitions when using C++ */
    5.11  #ifdef __cplusplus
    5.12  }