Skip to content

Commit

Permalink
Date: Sat, 7 Feb 2004 13:26:01 +0100
Browse files Browse the repository at this point in the history
From: delq
Subject: Re: [SDL] better ILBM support for SDL_Image

- fixed reading of colorkeyed images (they were previously assumed to
have a stencil bitplane, but since the body didn't have it, the decoding
failed).  Added a missing call to SDL_SetColorKey() too.

- fixed colormap for images with a stencil (mask) bitplane. Those images
can have say 7+1 bitplanes but only 128 colors defined. In that case,
the end of the SDL_Image colormap was uninitialized, resulting in
garbled surfaces.
  • Loading branch information
slouken committed Feb 9, 2004
1 parent b04e82b commit f5ce018
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions IMG_lbm.c
Expand Up @@ -29,6 +29,7 @@
POINT fr) 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.
*/

#include <stdio.h>
Expand Down Expand Up @@ -230,7 +231,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
nbplanes = 1;
}

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

/* Allocate memory for a temporary buffer ( used for
decompression/deinterleaving ) */
Expand All @@ -244,13 +245,14 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
if ( ( Image = SDL_CreateRGBSurface( SDL_SWSURFACE, width, bmhd.h, (bmhd.planes==24 || flagHAM==1)?24:8, 0, 0, 0, 0 ) ) == NULL )
goto done;

if ( bmhd.mask & 2 ) /* There is a transparent color */
SDL_SetColorKey( Image, SDL_SRCCOLORKEY, bmhd.tcolor );

/* Update palette informations */

/* There is no palette in 24 bits ILBM file */
if ( nbcolors>0 && flagHAM==0 )
{
Image->format->palette->ncolors = nbcolors;

ptr = &colormap[0];

for ( i=0; i<nbcolors; i++ )
Expand All @@ -263,11 +265,11 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
/* Amiga EHB mode (Extra-Half-Bright) */
/* 6 bitplanes mode with a 32 colors palette */
/* The 32 last colors are the same but divided by 2 */
/* Some Amiga pictures save 64 colors with 32 last wrong colors,
/* Some Amiga pictures save 64 colors with 32 last wrong colors, */
/* they shouldn't !, and here we overwrite these 32 bad colors. */
if ( (nbcolors==32 || flagEHB ) && (1<<bmhd.planes)==64 )
{
Image->format->palette->ncolors = 64;
nbcolors = 64;
ptr = &colormap[0];
for ( i=32; i<64; i++ )
{
Expand All @@ -276,6 +278,17 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
Image->format->palette->colors[i].b = (*ptr++)/2;
}
}

/* If nbcolors < 2^nbplanes, repeat the colormap */
/* This happens when pictures have a stencil mask */
for ( i=nbcolors; i < (1 << nbplanes); 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;
}

/* Get the bitmap */
Expand Down

0 comments on commit f5ce018

Please sign in to comment.