IMG_lbm.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 15 Sep 2004 15:39:59 +0000
changeset 103 27f1072602da
parent 99 9256da39d67e
child 104 e77df0fdb882
permissions -rw-r--r--
Date: Mon, 13 Sep 2004 09:16:01 +0200
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.
slouken@45
     1
/*
slouken@53
     2
    SDL_image:  An example image loading library for use with SDL
slouken@97
     3
    Copyright (C) 1999-2004 Sam Lantinga
slouken@45
     4
slouken@45
     5
    This library is free software; you can redistribute it and/or
slouken@45
     6
    modify it under the terms of the GNU Library General Public
slouken@45
     7
    License as published by the Free Software Foundation; either
slouken@45
     8
    version 2 of the License, or (at your option) any later version.
slouken@45
     9
slouken@45
    10
    This library is distributed in the hope that it will be useful,
slouken@45
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@45
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@45
    13
    Library General Public License for more details.
slouken@45
    14
slouken@45
    15
    You should have received a copy of the GNU Library General Public
slouken@45
    16
    License along with this library; if not, write to the Free
slouken@45
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@45
    18
slouken@45
    19
    Sam Lantinga
slouken@53
    20
    slouken@libsdl.org
slouken@45
    21
*/
slouken@53
    22
slouken@53
    23
/* $Id$ */
slouken@74
    24
slouken@45
    25
/* This is a ILBM image file loading framework
slouken@45
    26
   Load IFF pictures, PBM & ILBM packing methods, with or without stencil
slouken@103
    27
   Written by Daniel Morais ( Daniel AT Morais DOT com ) in September 2001.
slouken@103
    28
   24 bits ILBM files support added by Marc Le Douarain (http://www.multimania.com/mavati)
slouken@103
    29
   in December 2002.
slouken@96
    30
   EHB and HAM (specific Amiga graphic chip modes) support added by Marc Le Douarain
slouken@103
    31
   (http://www.multimania.com/mavati) in December 2003.
slouken@103
    32
   Stencil and colorkey fixes by David Raulo (david.raulo AT free DOT fr) in February 2004.
slouken@45
    33
*/
slouken@45
    34
slouken@45
    35
#include <stdio.h>
slouken@45
    36
#include <stdlib.h>
slouken@58
    37
#include <string.h>
slouken@45
    38
slouken@45
    39
#include "SDL_endian.h"
slouken@45
    40
#include "SDL_image.h"
slouken@45
    41
slouken@45
    42
#ifdef LOAD_LBM
slouken@45
    43
slouken@45
    44
slouken@45
    45
#define MAXCOLORS 256
slouken@45
    46
slouken@50
    47
/* Structure for an IFF picture ( BMHD = Bitmap Header ) */
slouken@45
    48
slouken@45
    49
typedef struct
slouken@45
    50
{
slouken@50
    51
    Uint16 w, h;		/* width & height of the bitmap in pixels */
slouken@50
    52
    Sint16 x, y;		/* screen coordinates of the bitmap */
slouken@50
    53
    Uint8 planes;		/* number of planes of the bitmap */
slouken@50
    54
    Uint8 mask;			/* mask type ( 0 => no mask ) */
slouken@50
    55
    Uint8 tcomp;		/* compression type */
slouken@50
    56
    Uint8 pad1;			/* dummy value, for padding */
slouken@50
    57
    Uint16 tcolor;		/* transparent color */
slouken@50
    58
    Uint8 xAspect,		/* pixel aspect ratio */
slouken@45
    59
         yAspect;
slouken@50
    60
    Sint16  Lpage;		/* width of the screen in pixels */
slouken@50
    61
    Sint16  Hpage;		/* height of the screen in pixels */
slouken@45
    62
} BMHD;
slouken@45
    63
slouken@45
    64
int IMG_isLBM( SDL_RWops *src )
slouken@45
    65
{
slouken@45
    66
	int   is_LBM;
slouken@45
    67
	Uint8 magic[4+4+4];
slouken@45
    68
slouken@45
    69
	is_LBM = 0;
slouken@74
    70
	if ( SDL_RWread( src, magic, 4+4+4, 1 ) )
slouken@45
    71
	{
slouken@74
    72
		if ( !memcmp( magic, "FORM", 4 ) &&
slouken@74
    73
			( !memcmp( magic + 8, "PBM ", 4 ) ||
slouken@74
    74
			  !memcmp( magic + 8, "ILBM", 4 ) ) )
slouken@45
    75
		{
slouken@45
    76
			is_LBM = 1;
slouken@45
    77
		}
slouken@45
    78
	}
slouken@45
    79
	return( is_LBM );
slouken@45
    80
}
slouken@45
    81
slouken@45
    82
SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
slouken@45
    83
{
slouken@45
    84
	SDL_Surface *Image;
slouken@45
    85
	Uint8       id[4], pbm, colormap[MAXCOLORS*3], *MiniBuf, *ptr, count, color, msk;
slouken@74
    86
	Uint32      size, bytesloaded, nbcolors;
slouken@45
    87
	Uint32      i, j, bytesperline, nbplanes, plane, h;
slouken@45
    88
	Uint32      remainingbytes;
slouken@84
    89
	Uint32      width;
slouken@45
    90
	BMHD	      bmhd;
slouken@45
    91
	char        *error;
slouken@96
    92
	Uint8       flagHAM,flagEHB;
slouken@45
    93
slouken@45
    94
	Image   = NULL;
slouken@45
    95
	error   = NULL;
slouken@45
    96
	MiniBuf = NULL;
slouken@45
    97
slouken@98
    98
	if ( !src ) {
slouken@98
    99
		/* The error message has been set in SDL_RWFromFile */
slouken@98
   100
		return NULL;
slouken@98
   101
	}
slouken@96
   102
	if ( !SDL_RWread( src, id, 4, 1 ) )
slouken@45
   103
	{
slouken@74
   104
		error="error reading IFF chunk";
slouken@45
   105
		goto done;
slouken@45
   106
	}
slouken@45
   107
slouken@50
   108
	/* Should be the size of the file minus 4+4 ( 'FORM'+size ) */
slouken@50
   109
	if ( !SDL_RWread( src, &size, 4, 1 ) )
slouken@45
   110
	{
slouken@74
   111
		error="error reading IFF chunk size";
slouken@45
   112
		goto done;
slouken@45
   113
	}
slouken@45
   114
slouken@50
   115
	/* As size is not used here, no need to swap it */
slouken@74
   116
slouken@74
   117
	if ( memcmp( id, "FORM", 4 ) != 0 )
slouken@45
   118
	{
slouken@74
   119
		error="not a IFF file";
slouken@45
   120
		goto done;
slouken@45
   121
	}
slouken@45
   122
slouken@74
   123
	if ( !SDL_RWread( src, id, 4, 1 ) )
slouken@45
   124
	{
slouken@74
   125
		error="error reading IFF chunk";
slouken@45
   126
		goto done;
slouken@45
   127
	}
slouken@45
   128
slouken@45
   129
	pbm = 0;
slouken@45
   130
slouken@50
   131
	/* File format : PBM=Packed Bitmap, ILBM=Interleaved Bitmap */
slouken@50
   132
	if ( !memcmp( id, "PBM ", 4 ) ) pbm = 1;
slouken@45
   133
	else if ( memcmp( id, "ILBM", 4 ) )
slouken@45
   134
	{
slouken@74
   135
		error="not a IFF picture";
slouken@45
   136
		goto done;
slouken@45
   137
	}
slouken@45
   138
slouken@45
   139
	nbcolors = 0;
slouken@45
   140
slouken@45
   141
	memset( &bmhd, 0, sizeof( BMHD ) );
slouken@96
   142
	flagHAM = 0;
slouken@96
   143
	flagEHB = 0;
slouken@45
   144
slouken@74
   145
	while ( memcmp( id, "BODY", 4 ) != 0 )
slouken@45
   146
	{
slouken@45
   147
		if ( !SDL_RWread( src, id, 4, 1 ) ) 
slouken@45
   148
		{
slouken@74
   149
			error="error reading IFF chunk";
slouken@45
   150
			goto done;
slouken@45
   151
		}
slouken@45
   152
slouken@74
   153
		if ( !SDL_RWread( src, &size, 4, 1 ) )
slouken@45
   154
		{
slouken@74
   155
			error="error reading IFF chunk size";
slouken@45
   156
			goto done;
slouken@45
   157
		}
slouken@45
   158
slouken@45
   159
		bytesloaded = 0;
slouken@45
   160
slouken@45
   161
		size = SDL_SwapBE32( size );
slouken@74
   162
slouken@50
   163
		if ( !memcmp( id, "BMHD", 4 ) ) /* Bitmap header */
slouken@45
   164
		{
slouken@45
   165
			if ( !SDL_RWread( src, &bmhd, sizeof( BMHD ), 1 ) )
slouken@45
   166
			{
slouken@74
   167
				error="error reading BMHD chunk";
slouken@45
   168
				goto done;
slouken@45
   169
			}
slouken@45
   170
slouken@45
   171
			bytesloaded = sizeof( BMHD );
slouken@45
   172
slouken@45
   173
			bmhd.w 		= SDL_SwapBE16( bmhd.w );
slouken@45
   174
			bmhd.h 		= SDL_SwapBE16( bmhd.h );
slouken@45
   175
			bmhd.x 		= SDL_SwapBE16( bmhd.x );
slouken@45
   176
			bmhd.y 		= SDL_SwapBE16( bmhd.y );
slouken@45
   177
			bmhd.tcolor = SDL_SwapBE16( bmhd.tcolor );
slouken@45
   178
			bmhd.Lpage 	= SDL_SwapBE16( bmhd.Lpage );
slouken@45
   179
			bmhd.Hpage 	= SDL_SwapBE16( bmhd.Hpage );
slouken@45
   180
		}
slouken@45
   181
slouken@50
   182
		if ( !memcmp( id, "CMAP", 4 ) ) /* palette ( Color Map ) */
slouken@45
   183
		{
slouken@45
   184
			if ( !SDL_RWread( src, &colormap, size, 1 ) )
slouken@45
   185
			{
slouken@74
   186
				error="error reading CMAP chunk";
slouken@45
   187
				goto done;
slouken@45
   188
			}
slouken@45
   189
slouken@45
   190
			bytesloaded = size;
slouken@45
   191
			nbcolors = size / 3;
slouken@45
   192
		}
slouken@45
   193
slouken@96
   194
		if ( !memcmp( id, "CAMG", 4 ) ) /* Amiga ViewMode  */
slouken@96
   195
		{
slouken@96
   196
			Uint32 viewmodes;
slouken@96
   197
			if ( !SDL_RWread( src, &viewmodes, sizeof(viewmodes), 1 ) )
slouken@96
   198
			{
slouken@96
   199
				error="error reading CAMG chunk";
slouken@96
   200
				goto done;
slouken@96
   201
			}
slouken@96
   202
slouken@96
   203
			bytesloaded = size;
slouken@96
   204
			viewmodes = SDL_SwapBE32( viewmodes );
slouken@96
   205
			if ( viewmodes & 0x0800 )
slouken@96
   206
				flagHAM = 1;
slouken@96
   207
			if ( viewmodes & 0x0080 )
slouken@96
   208
				flagEHB = 1;
slouken@96
   209
		}
slouken@96
   210
slouken@45
   211
		if ( memcmp( id, "BODY", 4 ) )
slouken@45
   212
		{
slouken@74
   213
			if ( size & 1 )	++size;  	/* padding ! */
slouken@45
   214
			size -= bytesloaded;
slouken@50
   215
			/* skip the remaining bytes of this chunk */
slouken@50
   216
			if ( size )	SDL_RWseek( src, size, SEEK_CUR );
slouken@45
   217
		}
slouken@45
   218
	}
slouken@45
   219
slouken@50
   220
	/* compute some usefull values, based on the bitmap header */
slouken@45
   221
slouken@50
   222
	width = ( bmhd.w + 15 ) & 0xFFFFFFF0;  /* Width in pixels modulo 16 */
slouken@45
   223
slouken@50
   224
	bytesperline = ( ( bmhd.w + 15 ) / 16 ) * 2;
slouken@45
   225
slouken@50
   226
	nbplanes = bmhd.planes;
slouken@45
   227
slouken@50
   228
	if ( pbm )                         /* File format : 'Packed Bitmap' */
slouken@45
   229
	{
slouken@74
   230
		bytesperline *= 8;
slouken@45
   231
		nbplanes = 1;
slouken@45
   232
	}
slouken@45
   233
slouken@99
   234
	if ( bmhd.mask & 1 ) ++nbplanes;   /* There is a mask ( 'stencil' ) */
slouken@45
   235
slouken@50
   236
	/* Allocate memory for a temporary buffer ( used for
slouken@50
   237
           decompression/deinterleaving ) */
slouken@45
   238
slouken@45
   239
	if ( ( MiniBuf = (void *)malloc( bytesperline * nbplanes ) ) == NULL )
slouken@45
   240
	{
slouken@74
   241
		error="no enough memory for temporary buffer";
slouken@45
   242
		goto done;
slouken@45
   243
	}
slouken@45
   244
slouken@96
   245
	if ( ( Image = SDL_CreateRGBSurface( SDL_SWSURFACE, width, bmhd.h, (bmhd.planes==24 || flagHAM==1)?24:8, 0, 0, 0, 0 ) ) == NULL )
slouken@45
   246
	   goto done;
slouken@45
   247
slouken@99
   248
	if ( bmhd.mask & 2 )               /* There is a transparent color */
slouken@99
   249
		SDL_SetColorKey( Image, SDL_SRCCOLORKEY, bmhd.tcolor );
slouken@99
   250
slouken@50
   251
	/* Update palette informations */
slouken@45
   252
slouken@74
   253
	/* There is no palette in 24 bits ILBM file */
slouken@96
   254
	if ( nbcolors>0 && flagHAM==0 )
slouken@74
   255
	{
slouken@103
   256
		int nbrcolorsfinal = 1 << nbplanes;
slouken@74
   257
		ptr = &colormap[0];
slouken@45
   258
slouken@74
   259
		for ( i=0; i<nbcolors; i++ )
slouken@74
   260
		{
slouken@74
   261
			Image->format->palette->colors[i].r = *ptr++;
slouken@74
   262
			Image->format->palette->colors[i].g = *ptr++;
slouken@74
   263
			Image->format->palette->colors[i].b = *ptr++;
slouken@74
   264
		}
slouken@96
   265
slouken@96
   266
		/* Amiga EHB mode (Extra-Half-Bright) */
slouken@96
   267
		/* 6 bitplanes mode with a 32 colors palette */
slouken@96
   268
		/* The 32 last colors are the same but divided by 2 */
slouken@99
   269
		/* Some Amiga pictures save 64 colors with 32 last wrong colors, */
slouken@96
   270
		/* they shouldn't !, and here we overwrite these 32 bad colors. */
slouken@96
   271
		if ( (nbcolors==32 || flagEHB ) && (1<<bmhd.planes)==64 )
slouken@96
   272
		{
slouken@99
   273
			nbcolors = 64;
slouken@96
   274
			ptr = &colormap[0];
slouken@96
   275
			for ( i=32; i<64; i++ )
slouken@96
   276
			{
slouken@96
   277
				Image->format->palette->colors[i].r = (*ptr++)/2;
slouken@96
   278
				Image->format->palette->colors[i].g = (*ptr++)/2;
slouken@96
   279
				Image->format->palette->colors[i].b = (*ptr++)/2;
slouken@96
   280
			}
slouken@96
   281
		}
slouken@99
   282
slouken@99
   283
		/* If nbcolors < 2^nbplanes, repeat the colormap */
slouken@99
   284
		/* This happens when pictures have a stencil mask */
slouken@103
   285
		if ( nbrcolorsfinal > (1<<bmhd.planes) ) {
slouken@103
   286
			nbrcolorsfinal = (1<<bmhd.planes);
slouken@103
   287
		}
slouken@103
   288
		for ( i=nbcolors; i < nbrcolorsfinal; i++ )
slouken@99
   289
		{
slouken@99
   290
			Image->format->palette->colors[i].r = Image->format->palette->colors[i%nbcolors].r;
slouken@99
   291
			Image->format->palette->colors[i].g = Image->format->palette->colors[i%nbcolors].g;
slouken@99
   292
			Image->format->palette->colors[i].b = Image->format->palette->colors[i%nbcolors].b;
slouken@99
   293
		}
slouken@103
   294
		Image->format->palette->ncolors = nbrcolorsfinal;
slouken@45
   295
	}
slouken@45
   296
slouken@50
   297
	/* Get the bitmap */
slouken@45
   298
slouken@45
   299
	for ( h=0; h < bmhd.h; h++ )
slouken@45
   300
	{
slouken@74
   301
		/* uncompress the datas of each planes */
slouken@74
   302
slouken@74
   303
		for ( plane=0; plane < nbplanes; plane++ )
slouken@45
   304
		{
slouken@74
   305
			ptr = MiniBuf + ( plane * bytesperline );
slouken@74
   306
slouken@45
   307
			remainingbytes = bytesperline;
slouken@74
   308
slouken@50
   309
			if ( bmhd.tcomp == 1 )	    /* Datas are compressed */
slouken@45
   310
			{
slouken@74
   311
				do
slouken@45
   312
				{
slouken@74
   313
					if ( !SDL_RWread( src, &count, 1, 1 ) )
slouken@45
   314
					{
slouken@74
   315
						error="error reading BODY chunk";
slouken@45
   316
						goto done;
slouken@45
   317
					}
slouken@74
   318
slouken@45
   319
					if ( count & 0x80 )
slouken@45
   320
					{
slouken@74
   321
						count ^= 0xFF;
slouken@74
   322
						count += 2; /* now it */
slouken@74
   323
slouken@45
   324
						if ( !SDL_RWread( src, &color, 1, 1 ) )
slouken@45
   325
						{
slouken@45
   326
						   error="error reading BODY chunk";
slouken@45
   327
							goto done;
slouken@45
   328
						}
slouken@45
   329
						memset( ptr, color, count );
slouken@45
   330
					}
slouken@45
   331
					else
slouken@45
   332
					{
slouken@74
   333
						++count;
slouken@45
   334
slouken@45
   335
						if ( !SDL_RWread( src, ptr, count, 1 ) )
slouken@45
   336
						{
slouken@45
   337
						   error="error reading BODY chunk";
slouken@45
   338
							goto done;
slouken@45
   339
						}
slouken@45
   340
					}
slouken@74
   341
slouken@45
   342
					ptr += count;
slouken@45
   343
					remainingbytes -= count;
slouken@74
   344
slouken@45
   345
				} while ( remainingbytes > 0 );
slouken@45
   346
			}
slouken@74
   347
			else
slouken@45
   348
			{
slouken@74
   349
				if ( !SDL_RWread( src, ptr, bytesperline, 1 ) )
slouken@45
   350
				{
slouken@74
   351
					error="error reading BODY chunk";
slouken@45
   352
					goto done;
slouken@45
   353
				}
slouken@45
   354
			}
slouken@45
   355
		}
slouken@74
   356
slouken@74
   357
		/* One line has been read, store it ! */
slouken@45
   358
slouken@45
   359
		ptr = Image->pixels;
slouken@96
   360
		if ( nbplanes==24 || flagHAM==1 )
slouken@74
   361
			ptr += h * width * 3;
slouken@74
   362
		else
slouken@74
   363
			ptr += h * width;
slouken@74
   364
slouken@50
   365
		if ( pbm )                 /* File format : 'Packed Bitmap' */
slouken@45
   366
		{
slouken@45
   367
		   memcpy( ptr, MiniBuf, width );
slouken@45
   368
		}
slouken@50
   369
		else		/* We have to un-interlace the bits ! */
slouken@45
   370
		{
slouken@96
   371
			if ( nbplanes!=24 && flagHAM==0 )
slouken@45
   372
			{
slouken@74
   373
				size = ( width + 7 ) / 8;
slouken@74
   374
slouken@74
   375
				for ( i=0; i < size; i++ )
slouken@45
   376
				{
slouken@74
   377
					memset( ptr, 0, 8 );
slouken@74
   378
slouken@74
   379
					for ( plane=0; plane < nbplanes; plane++ )
slouken@74
   380
					{
slouken@74
   381
						color = *( MiniBuf + i + ( plane * bytesperline ) );
slouken@74
   382
						msk = 0x80;
slouken@74
   383
slouken@74
   384
						for ( j=0; j<8; j++ )
slouken@74
   385
						{
slouken@74
   386
							if ( ( plane + j ) <= 7 ) ptr[j] |= (Uint8)( color & msk ) >> ( 7 - plane - j );
slouken@74
   387
							else 	                    ptr[j] |= (Uint8)( color & msk ) << ( plane + j - 7 );
slouken@74
   388
slouken@74
   389
							msk >>= 1;
slouken@74
   390
						}
slouken@74
   391
					}
slouken@74
   392
					ptr += 8;
slouken@74
   393
				}
slouken@74
   394
			}
slouken@74
   395
			else
slouken@74
   396
			{
slouken@96
   397
				Uint32 finalcolor = 0;
slouken@74
   398
				size = ( width + 7 ) / 8;
slouken@74
   399
				/* 24 bitplanes ILBM : R0...R7,G0...G7,B0...B7 */
slouken@96
   400
				/* or HAM (6 bitplanes) or HAM8 (8 bitplanes) modes */
slouken@74
   401
				for ( i=0; i<width; i=i+8 )
slouken@74
   402
				{
slouken@74
   403
					Uint8 maskBit = 0x80;
slouken@45
   404
					for ( j=0; j<8; j++ )
slouken@45
   405
					{
slouken@96
   406
						Uint32 pixelcolor = 0;
slouken@96
   407
						Uint32 maskColor = 1;
slouken@74
   408
						Uint8 dataBody;
slouken@74
   409
						for ( plane=0; plane < nbplanes; plane++ )
slouken@74
   410
						{
slouken@74
   411
							dataBody = MiniBuf[ plane*size+i/8 ];
slouken@74
   412
							if ( dataBody&maskBit )
slouken@96
   413
								pixelcolor = pixelcolor | maskColor;
slouken@96
   414
							maskColor = maskColor<<1;
slouken@96
   415
						}
slouken@96
   416
						/* HAM : 12 bits RGB image (4 bits per color component) */
slouken@96
   417
						/* HAM8 : 18 bits RGB image (6 bits per color component) */
slouken@96
   418
						if ( flagHAM )
slouken@96
   419
						{
slouken@96
   420
							switch( pixelcolor>>(nbplanes-2) )
slouken@96
   421
							{
slouken@96
   422
								case 0: /* take direct color from palette */
slouken@96
   423
									finalcolor = colormap[ pixelcolor*3 ] + (colormap[ pixelcolor*3+1 ]<<8) + (colormap[ pixelcolor*3+2 ]<<16);
slouken@96
   424
									break;
slouken@96
   425
								case 1: /* modify only blue component */
slouken@96
   426
									finalcolor = finalcolor&0x00FFFF;
slouken@96
   427
									finalcolor = finalcolor | (pixelcolor<<(16+(10-nbplanes)));
slouken@96
   428
									break;
slouken@96
   429
								case 2: /* modify only red component */
slouken@96
   430
									finalcolor = finalcolor&0xFFFF00;
slouken@96
   431
									finalcolor = finalcolor | pixelcolor<<(10-nbplanes);
slouken@96
   432
									break;
slouken@96
   433
								case 3: /* modify only green component */
slouken@96
   434
									finalcolor = finalcolor&0xFF00FF;
slouken@96
   435
									finalcolor = finalcolor | (pixelcolor<<(8+(10-nbplanes)));
slouken@96
   436
									break;
slouken@96
   437
							}
slouken@96
   438
						}
slouken@96
   439
						else
slouken@96
   440
						{
slouken@96
   441
							finalcolor = pixelcolor;
slouken@74
   442
						}
slouken@74
   443
						if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
slouken@74
   444
						{
slouken@96
   445
							*ptr++ = finalcolor>>16;
slouken@96
   446
							*ptr++ = finalcolor>>8;
slouken@96
   447
							*ptr++ = finalcolor;
slouken@74
   448
						}
slouken@74
   449
						else
slouken@74
   450
						{
slouken@96
   451
							*ptr++ = finalcolor;
slouken@96
   452
							*ptr++ = finalcolor>>8;
slouken@96
   453
							*ptr++ = finalcolor>>16;
slouken@74
   454
						}
slouken@74
   455
slouken@74
   456
						maskBit = maskBit>>1;
slouken@45
   457
					}
slouken@45
   458
				}
slouken@45
   459
			}
slouken@45
   460
		}
slouken@45
   461
	}
slouken@45
   462
slouken@45
   463
done:
slouken@45
   464
slouken@45
   465
	if ( MiniBuf ) free( MiniBuf );
slouken@45
   466
slouken@74
   467
	if ( error )
slouken@45
   468
	{
slouken@45
   469
		IMG_SetError( error );
slouken@74
   470
		SDL_FreeSurface( Image );
slouken@45
   471
		Image = NULL;
slouken@45
   472
	}
slouken@45
   473
slouken@45
   474
	return( Image );
slouken@45
   475
}
slouken@45
   476
slouken@45
   477
#else /* LOAD_LBM */
slouken@45
   478
slouken@45
   479
/* See if an image is contained in a data source */
slouken@45
   480
int IMG_isLBM(SDL_RWops *src)
slouken@45
   481
{
slouken@45
   482
	return(0);
slouken@45
   483
}
slouken@45
   484
slouken@45
   485
/* Load an IFF type image from an SDL datasource */
slouken@45
   486
SDL_Surface *IMG_LoadLBM_RW(SDL_RWops *src)
slouken@45
   487
{
slouken@45
   488
	return(NULL);
slouken@45
   489
}
slouken@45
   490
slouken@45
   491
#endif /* LOAD_LBM */