Skip to content

Commit

Permalink
Mattias Engdeg?rd - Tue Nov 20 08:08:53 PST 2001
Browse files Browse the repository at this point in the history
 * Fixed transparency in the GIF loading code
  • Loading branch information
slouken committed Nov 20, 2001
1 parent 9402a6c commit a6e97b8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 55 deletions.
2 changes: 2 additions & 0 deletions CHANGES
@@ -1,5 +1,7 @@

1.2.1:
Mattias Engdeg�rd - Tue Nov 20 08:08:53 PST 2001
* Fixed transparency in the GIF loading code
Daniel Morais - Sun Sep 23 16:32:13 PDT 2001
* Added support for the IFF (LBM) image format
Sam Lantinga - Sun Aug 19 01:51:44 PDT 2001
Expand Down
2 changes: 1 addition & 1 deletion IMG.c
Expand Up @@ -69,7 +69,7 @@ SDL_Surface *IMG_Load_RW(SDL_RWops *src, int freesrc)
}

/* Portable case-insensitive string compare function */
int IMG_string_equals(const char *str1, const char *str2)
static int IMG_string_equals(const char *str1, const char *str2)
{
while ( *str1 && *str2 ) {
if ( toupper((unsigned char)*str1) !=
Expand Down
2 changes: 1 addition & 1 deletion IMG_gif.c
Expand Up @@ -253,7 +253,7 @@ IMG_LoadGIF_RW(SDL_RWops *src)
} while (image == NULL);

#ifdef USED_BY_SDL
if ( Gif89.transparent > 0 ) {
if ( Gif89.transparent >= 0 ) {
SDL_SetColorKey(image, SDL_SRCCOLORKEY, Gif89.transparent);
}
#endif
Expand Down
87 changes: 37 additions & 50 deletions IMG_lbm.c
Expand Up @@ -36,37 +36,25 @@
#ifdef LOAD_LBM


//===========================================================================
// DEFINES
//===========================================================================

#define MAXCOLORS 256

//===========================================================================
// STRUCTURES
//===========================================================================

// Structure for an IFF picture ( BMHD = Bitmap Header )
/* Structure for an IFF picture ( BMHD = Bitmap Header ) */

typedef struct
{
Uint16 w, h; // width & height of the bitmap in pixels
Sint16 x, y; // screen coordinates of the bitmap
Uint8 planes; // number of planes of the bitmap
Uint8 mask; // mask type ( 0 => no mask )
Uint8 tcomp; // compression type
Uint8 pad1; // dummy value, for padding
Uint16 tcolor; // transparent color
Uint8 xAspect, // pixel aspect ratio
Uint16 w, h; /* width & height of the bitmap in pixels */
Sint16 x, y; /* screen coordinates of the bitmap */
Uint8 planes; /* number of planes of the bitmap */
Uint8 mask; /* mask type ( 0 => no mask ) */
Uint8 tcomp; /* compression type */
Uint8 pad1; /* dummy value, for padding */
Uint16 tcolor; /* transparent color */
Uint8 xAspect, /* pixel aspect ratio */
yAspect;
Sint16 Lpage; // width of the screen in pixels
Sint16 Hpage; // height of the screen in pixels

Sint16 Lpage; /* width of the screen in pixels */
Sint16 Hpage; /* height of the screen in pixels */
} BMHD;

//===========================================================================
// See if an image is contained in a data source

int IMG_isLBM( SDL_RWops *src )
{
int is_LBM;
Expand All @@ -85,9 +73,6 @@ int IMG_isLBM( SDL_RWops *src )
return( is_LBM );
}

//===========================================================================
// Load a IFF type image from an SDL datasource

SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
{
SDL_Surface *Image;
Expand All @@ -111,13 +96,14 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
goto done;
}

if ( !SDL_RWread( src, &size, 4, 1 ) ) // Should be the size of the file minus 4+4 ( 'FORM'+size )
/* Should be the size of the file minus 4+4 ( 'FORM'+size ) */
if ( !SDL_RWread( src, &size, 4, 1 ) )
{
error="error reading IFF chunk size";
goto done;
}

// As size is not used here, no need to swap it
/* As size is not used here, no need to swap it */

if ( memcmp( id, "FORM", 4 ) != 0 )
{
Expand All @@ -133,7 +119,8 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )

pbm = 0;

if ( !memcmp( id, "PBM ", 4 ) ) pbm = 1; // File format : PBM=Packed Bitmap, ILBM=Interleaved Bitmap
/* File format : PBM=Packed Bitmap, ILBM=Interleaved Bitmap */
if ( !memcmp( id, "PBM ", 4 ) ) pbm = 1;
else if ( memcmp( id, "ILBM", 4 ) )
{
error="not a IFF picture";
Expand Down Expand Up @@ -162,7 +149,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )

size = SDL_SwapBE32( size );

if ( !memcmp( id, "BMHD", 4 ) ) // Bitmap header
if ( !memcmp( id, "BMHD", 4 ) ) /* Bitmap header */
{
if ( !SDL_RWread( src, &bmhd, sizeof( BMHD ), 1 ) )
{
Expand All @@ -181,7 +168,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
bmhd.Hpage = SDL_SwapBE16( bmhd.Hpage );
}

if ( !memcmp( id, "CMAP", 4 ) ) // palette ( Color Map )
if ( !memcmp( id, "CMAP", 4 ) ) /* palette ( Color Map ) */
{
if ( !SDL_RWread( src, &colormap, size, 1 ) )
{
Expand All @@ -195,42 +182,42 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )

if ( memcmp( id, "BODY", 4 ) )
{
if ( size & 1 ) ++size; // padding !
if ( size & 1 ) ++size; /* padding ! */
size -= bytesloaded;
if ( size ) SDL_RWseek( src, size, SEEK_CUR ); // skip the remaining bytes of this chunk
/* skip the remaining bytes of this chunk */
if ( size ) SDL_RWseek( src, size, SEEK_CUR );
}
}

// compute some usefull values, based on the bitmap header
/* compute some usefull values, based on the bitmap header */

width = ( bmhd.w + 15 ) & 0xFFFFFFF0; // Width in pixels modulo 16
width = ( bmhd.w + 15 ) & 0xFFFFFFF0; /* Width in pixels modulo 16 */

bytesperline = ( ( bmhd.w + 15 ) / 16 ) * 2; // Number of bytes per line
bytesperline = ( ( bmhd.w + 15 ) / 16 ) * 2;

nbplanes = bmhd.planes; // Number of planes
nbplanes = bmhd.planes;

if ( pbm ) // File format : 'Packed Bitmap'
if ( pbm ) /* File format : 'Packed Bitmap' */
{
bytesperline *= 8;
nbplanes = 1;
}

if ( bmhd.mask ) ++nbplanes; // There is a mask ( 'stencil' )
if ( bmhd.mask ) ++nbplanes; /* There is a mask ( 'stencil' ) */

// Allocate memory for a temporary buffer ( used for decompression/deinterleaving )
/* Allocate memory for a temporary buffer ( used for
decompression/deinterleaving ) */

if ( ( MiniBuf = (void *)malloc( bytesperline * nbplanes ) ) == NULL )
{
error="no enough memory for temporary buffer";
goto done;
}

// Create the surface

if ( ( Image = SDL_CreateRGBSurface( SDL_SWSURFACE, width, bmhd.h, 8, 0, 0, 0, 0 ) ) == NULL )
goto done;

// Update palette informations
/* Update palette informations */

Image->format->palette->ncolors = nbcolors;

Expand All @@ -243,19 +230,19 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
Image->format->palette->colors[i].b = *ptr++;
}

// Get the bitmap
/* Get the bitmap */

for ( h=0; h < bmhd.h; h++ )
{
// uncompress the datas of each planes
/* uncompress the datas of each planes */

for ( plane=0; plane < nbplanes; plane++ )
{
ptr = MiniBuf + ( plane * bytesperline );

remainingbytes = bytesperline;

if ( bmhd.tcomp == 1 ) // Datas are compressed
if ( bmhd.tcomp == 1 ) /* Datas are compressed */
{
do
{
Expand All @@ -268,7 +255,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
if ( count & 0x80 )
{
count ^= 0xFF;
count += 2; // now it
count += 2; /* now it */

if ( !SDL_RWread( src, &color, 1, 1 ) )
{
Expand Down Expand Up @@ -303,16 +290,16 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
}
}

// One line has been read, store it !
/* One line has been read, store it ! */

ptr = Image->pixels;
ptr += h * width;

if ( pbm ) // File format : 'Packed Bitmap'
if ( pbm ) /* File format : 'Packed Bitmap' */
{
memcpy( ptr, MiniBuf, width );
}
else // We have to un-interlace the bits !
else /* We have to un-interlace the bits ! */
{
size = ( width + 7 ) / 8;

Expand Down
3 changes: 0 additions & 3 deletions SDL_image.h
Expand Up @@ -85,9 +85,6 @@ extern DECLSPEC SDL_Surface *IMG_ReadXPMFromArray(char **xpm);
#define IMG_SetError SDL_SetError
#define IMG_GetError SDL_GetError

/* used internally, NOT an exported function */
extern int IMG_string_equals(const char *str1, const char *str2);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
Expand Down

0 comments on commit a6e97b8

Please sign in to comment.