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