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