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