IMG_bmp.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 01 Jan 2017 18:50:51 -0800
changeset 496 6332f9425dcc
parent 486 7bb8af91e887
child 528 7f9e88f4b45e
permissions -rw-r--r--
Updated copyright for 2017
slouken@0
     1
/*
slouken@280
     2
  SDL_image:  An example image loading library for use with SDL
slouken@496
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@0
     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@0
     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@0
    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@0
    20
*/
slouken@0
    21
slouken@332
    22
#if (!defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND)) || !defined(BMP_USES_IMAGEIO)
slouken@237
    23
slouken@413
    24
/* This is a BMP image file loading framework
slouken@413
    25
 *
slouken@413
    26
 * ICO/CUR file support is here as well since it uses similar internal
slouken@413
    27
 * representation
slouken@413
    28
 *
slouken@413
    29
 * A good test suite of BMP images is available at:
slouken@413
    30
 * http://entropymine.com/jason/bmpsuite/bmpsuite/html/bmpsuite.html
slouken@413
    31
 */
slouken@0
    32
slouken@0
    33
#include <stdio.h>
slouken@0
    34
#include <string.h>
slouken@0
    35
slouken@0
    36
#include "SDL_image.h"
slouken@0
    37
slouken@0
    38
#ifdef LOAD_BMP
slouken@0
    39
slouken@0
    40
/* See if an image is contained in a data source */
slouken@0
    41
int IMG_isBMP(SDL_RWops *src)
slouken@0
    42
{
slouken@368
    43
    Sint64 start;
slouken@368
    44
    int is_BMP;
slouken@368
    45
    char magic[2];
slouken@0
    46
slouken@368
    47
    if ( !src )
slouken@368
    48
        return 0;
slouken@368
    49
    start = SDL_RWtell(src);
slouken@368
    50
    is_BMP = 0;
slouken@368
    51
    if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
slouken@368
    52
        if ( SDL_strncmp(magic, "BM", 2) == 0 ) {
slouken@368
    53
            is_BMP = 1;
slouken@368
    54
        }
slouken@368
    55
    }
slouken@368
    56
    SDL_RWseek(src, start, RW_SEEK_SET);
slouken@368
    57
    return(is_BMP);
slouken@0
    58
}
slouken@0
    59
couriersud@189
    60
static int IMG_isICOCUR(SDL_RWops *src, int type)
couriersud@189
    61
{
slouken@368
    62
    Sint64 start;
slouken@368
    63
    int is_ICOCUR;
couriersud@189
    64
slouken@368
    65
    /* The Win32 ICO file header (14 bytes) */
couriersud@189
    66
    Uint16 bfReserved;
couriersud@189
    67
    Uint16 bfType;
couriersud@189
    68
    Uint16 bfCount;
couriersud@189
    69
slouken@368
    70
    if ( !src )
slouken@368
    71
        return 0;
slouken@368
    72
    start = SDL_RWtell(src);
slouken@368
    73
    is_ICOCUR = 0;
couriersud@189
    74
    bfReserved = SDL_ReadLE16(src);
couriersud@189
    75
    bfType = SDL_ReadLE16(src);
couriersud@189
    76
    bfCount = SDL_ReadLE16(src);
slouken@368
    77
    if ((bfReserved == 0) && (bfType == type) && (bfCount != 0))
slouken@368
    78
        is_ICOCUR = 1;
slouken@368
    79
    SDL_RWseek(src, start, RW_SEEK_SET);
couriersud@189
    80
slouken@368
    81
    return (is_ICOCUR);
couriersud@189
    82
}
couriersud@189
    83
couriersud@189
    84
int IMG_isICO(SDL_RWops *src)
couriersud@189
    85
{
slouken@368
    86
    return IMG_isICOCUR(src, 1);
couriersud@189
    87
}
couriersud@189
    88
couriersud@189
    89
int IMG_isCUR(SDL_RWops *src)
couriersud@189
    90
{
slouken@368
    91
    return IMG_isICOCUR(src, 2);
couriersud@189
    92
}
couriersud@189
    93
slouken@101
    94
#include "SDL_error.h"
slouken@101
    95
#include "SDL_video.h"
slouken@101
    96
#include "SDL_endian.h"
slouken@101
    97
slouken@101
    98
/* Compression encodings for BMP files */
slouken@101
    99
#ifndef BI_RGB
slouken@368
   100
#define BI_RGB      0
slouken@368
   101
#define BI_RLE8     1
slouken@368
   102
#define BI_RLE4     2
slouken@368
   103
#define BI_BITFIELDS    3
slouken@101
   104
#endif
slouken@101
   105
slouken@101
   106
static int readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
slouken@101
   107
{
slouken@368
   108
    /*
slouken@368
   109
    | Sets the surface pixels from src.  A bmp image is upside down.
slouken@368
   110
    */
slouken@368
   111
    int pitch = surface->pitch;
slouken@368
   112
    int height = surface->h;
slouken@368
   113
    Uint8 *start = (Uint8 *)surface->pixels;
slouken@368
   114
    Uint8 *end = start + (height*pitch);
slouken@368
   115
    Uint8 *bits = end-pitch, *spot;
slouken@368
   116
    int ofs = 0;
slouken@368
   117
    Uint8 ch;
slouken@368
   118
    Uint8 needsPad;
slouken@101
   119
slouken@368
   120
#define COPY_PIXEL(x)   spot = &bits[ofs++]; if(spot >= start && spot < end) *spot = (x)
slouken@184
   121
slouken@368
   122
    for (;;) {
slouken@368
   123
        if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
slouken@368
   124
        /*
slouken@368
   125
        | encoded mode starts with a run length, and then a byte
slouken@368
   126
        | with two colour indexes to alternate between for the run
slouken@368
   127
        */
slouken@368
   128
        if ( ch ) {
slouken@368
   129
            Uint8 pixel;
slouken@368
   130
            if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
slouken@368
   131
            if ( isRle8 ) {                 /* 256-color bitmap, compressed */
slouken@368
   132
                do {
slouken@368
   133
                    COPY_PIXEL(pixel);
slouken@368
   134
                } while (--ch);
slouken@368
   135
            } else {                         /* 16-color bitmap, compressed */
slouken@368
   136
                Uint8 pixel0 = pixel >> 4;
slouken@368
   137
                Uint8 pixel1 = pixel & 0x0F;
slouken@368
   138
                for (;;) {
slouken@368
   139
                    COPY_PIXEL(pixel0); /* even count, high nibble */
slouken@368
   140
                    if (!--ch) break;
slouken@368
   141
                    COPY_PIXEL(pixel1); /* odd count, low nibble */
slouken@368
   142
                    if (!--ch) break;
slouken@368
   143
                }
slouken@368
   144
            }
slouken@368
   145
        } else {
slouken@368
   146
            /*
slouken@368
   147
            | A leading zero is an escape; it may signal the end of the bitmap,
slouken@368
   148
            | a cursor move, or some absolute data.
slouken@368
   149
            | zero tag may be absolute mode or an escape
slouken@368
   150
            */
slouken@368
   151
            if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
slouken@368
   152
            switch (ch) {
slouken@368
   153
            case 0:                         /* end of line */
slouken@368
   154
                ofs = 0;
slouken@368
   155
                bits -= pitch;               /* go to previous */
slouken@368
   156
                break;
slouken@368
   157
            case 1:                         /* end of bitmap */
slouken@368
   158
                return 0;                    /* success! */
slouken@368
   159
            case 2:                         /* delta */
slouken@368
   160
                if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
slouken@368
   161
                ofs += ch;
slouken@368
   162
                if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
slouken@368
   163
                bits -= (ch * pitch);
slouken@368
   164
                break;
slouken@368
   165
            default:                        /* no compression */
slouken@368
   166
                if (isRle8) {
slouken@368
   167
                    needsPad = ( ch & 1 );
slouken@368
   168
                    do {
slouken@368
   169
                        Uint8 pixel;
slouken@368
   170
                        if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
slouken@368
   171
                        COPY_PIXEL(pixel);
slouken@368
   172
                    } while (--ch);
slouken@368
   173
                } else {
slouken@368
   174
                    needsPad = ( ((ch+1)>>1) & 1 ); /* (ch+1)>>1: bytes size */
slouken@368
   175
                    for (;;) {
slouken@368
   176
                        Uint8 pixel;
slouken@368
   177
                        if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
slouken@368
   178
                        COPY_PIXEL(pixel >> 4);
slouken@368
   179
                        if (!--ch) break;
slouken@368
   180
                        COPY_PIXEL(pixel & 0x0F);
slouken@368
   181
                        if (!--ch) break;
slouken@368
   182
                    }
slouken@368
   183
                }
slouken@368
   184
                /* pad at even boundary */
slouken@368
   185
                if ( needsPad && !SDL_RWread(src, &ch, 1, 1) ) return 1;
slouken@368
   186
                break;
slouken@368
   187
            }
slouken@368
   188
        }
slouken@368
   189
    }
slouken@101
   190
}
slouken@101
   191
slouken@413
   192
static void CorrectAlphaChannel(SDL_Surface *surface)
slouken@413
   193
{
slouken@413
   194
    /* Check to see if there is any alpha channel data */
slouken@413
   195
    SDL_bool hasAlpha = SDL_FALSE;
slouken@413
   196
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
slouken@413
   197
    int alphaChannelOffset = 0;
slouken@413
   198
#else
slouken@413
   199
    int alphaChannelOffset = 3;
slouken@413
   200
#endif
slouken@413
   201
    Uint8 *alpha = ((Uint8*)surface->pixels) + alphaChannelOffset;
slouken@413
   202
    Uint8 *end = alpha + surface->h * surface->pitch;
slouken@413
   203
slouken@413
   204
    while (alpha < end) {
slouken@413
   205
        if (*alpha != 0) {
slouken@413
   206
            hasAlpha = SDL_TRUE;
slouken@413
   207
            break;
slouken@413
   208
        }
slouken@413
   209
        alpha += 4;
slouken@413
   210
    }
slouken@413
   211
slouken@413
   212
    if (!hasAlpha) {
slouken@413
   213
        alpha = ((Uint8*)surface->pixels) + alphaChannelOffset;
slouken@413
   214
        while (alpha < end) {
slouken@413
   215
            *alpha = SDL_ALPHA_OPAQUE;
slouken@413
   216
            alpha += 4;
slouken@413
   217
        }
slouken@413
   218
    }
slouken@413
   219
}
slouken@413
   220
slouken@101
   221
static SDL_Surface *LoadBMP_RW (SDL_RWops *src, int freesrc)
slouken@101
   222
{
slouken@368
   223
    SDL_bool was_error;
slouken@368
   224
    Sint64 fp_offset;
slouken@368
   225
    int bmpPitch;
slouken@368
   226
    int i, pad;
slouken@368
   227
    SDL_Surface *surface;
slouken@477
   228
    Uint32 Rmask = 0;
slouken@477
   229
    Uint32 Gmask = 0;
slouken@477
   230
    Uint32 Bmask = 0;
slouken@477
   231
    Uint32 Amask = 0;
slouken@368
   232
    SDL_Palette *palette;
slouken@368
   233
    Uint8 *bits;
slouken@368
   234
    Uint8 *top, *end;
slouken@368
   235
    SDL_bool topDown;
slouken@368
   236
    int ExpandBMP;
slouken@477
   237
    SDL_bool haveRGBMasks = SDL_FALSE;
slouken@477
   238
    SDL_bool haveAlphaMask = SDL_FALSE;
slouken@413
   239
    SDL_bool correctAlpha = SDL_FALSE;
slouken@101
   240
slouken@368
   241
    /* The Win32 BMP file header (14 bytes) */
slouken@368
   242
    char   magic[2];
slouken@368
   243
    Uint32 bfSize;
slouken@368
   244
    Uint16 bfReserved1;
slouken@368
   245
    Uint16 bfReserved2;
slouken@368
   246
    Uint32 bfOffBits;
slouken@101
   247
slouken@368
   248
    /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
slouken@368
   249
    Uint32 biSize;
slouken@368
   250
    Sint32 biWidth;
slouken@368
   251
    Sint32 biHeight;
slouken@368
   252
    Uint16 biPlanes;
slouken@368
   253
    Uint16 biBitCount;
slouken@368
   254
    Uint32 biCompression;
slouken@368
   255
    Uint32 biSizeImage;
slouken@368
   256
    Sint32 biXPelsPerMeter;
slouken@368
   257
    Sint32 biYPelsPerMeter;
slouken@368
   258
    Uint32 biClrUsed;
slouken@368
   259
    Uint32 biClrImportant;
slouken@101
   260
slouken@368
   261
    /* Make sure we are passed a valid data source */
slouken@368
   262
    surface = NULL;
slouken@368
   263
    was_error = SDL_FALSE;
slouken@368
   264
    if ( src == NULL ) {
slouken@368
   265
        was_error = SDL_TRUE;
slouken@368
   266
        goto done;
slouken@368
   267
    }
slouken@101
   268
slouken@368
   269
    /* Read in the BMP file header */
slouken@368
   270
    fp_offset = SDL_RWtell(src);
slouken@368
   271
    SDL_ClearError();
slouken@368
   272
    if ( SDL_RWread(src, magic, 1, 2) != 2 ) {
slouken@368
   273
        SDL_Error(SDL_EFREAD);
slouken@368
   274
        was_error = SDL_TRUE;
slouken@368
   275
        goto done;
slouken@368
   276
    }
slouken@368
   277
    if ( SDL_strncmp(magic, "BM", 2) != 0 ) {
slouken@368
   278
        IMG_SetError("File is not a Windows BMP file");
slouken@368
   279
        was_error = SDL_TRUE;
slouken@368
   280
        goto done;
slouken@368
   281
    }
slouken@368
   282
    bfSize      = SDL_ReadLE32(src);
slouken@368
   283
    bfReserved1 = SDL_ReadLE16(src);
slouken@368
   284
    bfReserved2 = SDL_ReadLE16(src);
slouken@368
   285
    bfOffBits   = SDL_ReadLE32(src);
slouken@101
   286
slouken@368
   287
    /* Read the Win32 BITMAPINFOHEADER */
slouken@368
   288
    biSize      = SDL_ReadLE32(src);
slouken@477
   289
    if ( biSize == 12 ) {   /* really old BITMAPCOREHEADER */
slouken@368
   290
        biWidth     = (Uint32)SDL_ReadLE16(src);
slouken@368
   291
        biHeight    = (Uint32)SDL_ReadLE16(src);
slouken@368
   292
        biPlanes    = SDL_ReadLE16(src);
slouken@368
   293
        biBitCount  = SDL_ReadLE16(src);
slouken@368
   294
        biCompression   = BI_RGB;
slouken@368
   295
        biSizeImage = 0;
slouken@368
   296
        biXPelsPerMeter = 0;
slouken@368
   297
        biYPelsPerMeter = 0;
slouken@368
   298
        biClrUsed   = 0;
slouken@368
   299
        biClrImportant  = 0;
slouken@477
   300
    } else if (biSize >= 40) {  /* some version of BITMAPINFOHEADER */
slouken@477
   301
        Uint32 headerSize;
slouken@368
   302
        biWidth     = SDL_ReadLE32(src);
slouken@368
   303
        biHeight    = SDL_ReadLE32(src);
slouken@368
   304
        biPlanes    = SDL_ReadLE16(src);
slouken@368
   305
        biBitCount  = SDL_ReadLE16(src);
slouken@368
   306
        biCompression   = SDL_ReadLE32(src);
slouken@368
   307
        biSizeImage = SDL_ReadLE32(src);
slouken@368
   308
        biXPelsPerMeter = SDL_ReadLE32(src);
slouken@368
   309
        biYPelsPerMeter = SDL_ReadLE32(src);
slouken@368
   310
        biClrUsed   = SDL_ReadLE32(src);
slouken@368
   311
        biClrImportant  = SDL_ReadLE32(src);
slouken@433
   312
slouken@477
   313
        /* 64 == BITMAPCOREHEADER2, an incompatible OS/2 2.x extension. Skip this stuff for now. */
slouken@477
   314
        if (biSize != 64) {
slouken@477
   315
            /* This is complicated. If compression is BI_BITFIELDS, then
slouken@477
   316
               we have 3 DWORDS that specify the RGB masks. This is either
slouken@477
   317
               stored here in an BITMAPV2INFOHEADER (which only differs in
slouken@477
   318
               that it adds these RGB masks) and biSize >= 52, or we've got
slouken@477
   319
               these masks stored in the exact same place, but strictly
slouken@477
   320
               speaking, this is the bmiColors field in BITMAPINFO immediately
slouken@477
   321
               following the legacy v1 info header, just past biSize. */
slouken@477
   322
            if (biCompression == BI_BITFIELDS) {
slouken@477
   323
                haveRGBMasks = SDL_TRUE;
slouken@477
   324
                Rmask = SDL_ReadLE32(src);
slouken@477
   325
                Gmask = SDL_ReadLE32(src);
slouken@477
   326
                Bmask = SDL_ReadLE32(src);
slouken@477
   327
slouken@477
   328
                /* ...v3 adds an alpha mask. */
slouken@477
   329
                if (biSize >= 56) {  /* BITMAPV3INFOHEADER; adds alpha mask */
slouken@477
   330
                    haveAlphaMask = SDL_TRUE;
slouken@477
   331
                    Amask = SDL_ReadLE32(src);
slouken@477
   332
                }
slouken@477
   333
            } else {
slouken@477
   334
                /* the mask fields are ignored for v2+ headers if not BI_BITFIELD. */
slouken@477
   335
                if (biSize >= 52) {  /* BITMAPV2INFOHEADER; adds RGB masks */
slouken@477
   336
                    /*Rmask = */ SDL_ReadLE32(src);
slouken@477
   337
                    /*Gmask = */ SDL_ReadLE32(src);
slouken@477
   338
                    /*Bmask = */ SDL_ReadLE32(src);
slouken@477
   339
                }
slouken@477
   340
                if (biSize >= 56) {  /* BITMAPV3INFOHEADER; adds alpha mask */
slouken@477
   341
                    /*Amask = */ SDL_ReadLE32(src);
slouken@477
   342
                }
slouken@477
   343
            }
slouken@477
   344
slouken@477
   345
            /* Insert other fields here; Wikipedia and MSDN say we're up to
slouken@477
   346
               v5 of this header, but we ignore those for now (they add gamma,
slouken@477
   347
               color spaces, etc). Ignoring the weird OS/2 2.x format, we
slouken@477
   348
               currently parse up to v3 correctly (hopefully!). */
slouken@477
   349
        }
slouken@477
   350
slouken@477
   351
        /* skip any header bytes we didn't handle... */
slouken@477
   352
        headerSize = (Uint32) (SDL_RWtell(src) - (fp_offset + 14));
slouken@433
   353
        if (biSize > headerSize) {
slouken@433
   354
            SDL_RWseek(src, (biSize - headerSize), RW_SEEK_CUR);
slouken@433
   355
        }
slouken@368
   356
    }
slouken@368
   357
    if (biHeight < 0) {
slouken@368
   358
        topDown = SDL_TRUE;
slouken@368
   359
        biHeight = -biHeight;
slouken@368
   360
    } else {
slouken@368
   361
        topDown = SDL_FALSE;
slouken@368
   362
    }
slouken@101
   363
slouken@368
   364
    /* Check for read error */
slouken@477
   365
    if (SDL_strcmp(SDL_GetError(), "") != 0) {
slouken@368
   366
        was_error = SDL_TRUE;
slouken@368
   367
        goto done;
slouken@368
   368
    }
slouken@101
   369
slouken@368
   370
    /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */
slouken@368
   371
    switch (biBitCount) {
slouken@368
   372
        case 1:
slouken@368
   373
        case 4:
slouken@368
   374
            ExpandBMP = biBitCount;
slouken@368
   375
            biBitCount = 8;
slouken@368
   376
            break;
slouken@368
   377
        default:
slouken@368
   378
            ExpandBMP = 0;
slouken@368
   379
            break;
slouken@368
   380
    }
slouken@101
   381
slouken@368
   382
    /* RLE4 and RLE8 BMP compression is supported */
slouken@368
   383
    switch (biCompression) {
slouken@368
   384
        case BI_RGB:
slouken@368
   385
            /* If there are no masks, use the defaults */
slouken@477
   386
            SDL_assert(!haveRGBMasks);
slouken@477
   387
            SDL_assert(!haveAlphaMask);
slouken@477
   388
            /* Default values for the BMP format */
slouken@477
   389
            switch (biBitCount) {
slouken@477
   390
            case 15:
slouken@477
   391
            case 16:
slouken@477
   392
                Rmask = 0x7C00;
slouken@477
   393
                Gmask = 0x03E0;
slouken@477
   394
                Bmask = 0x001F;
slouken@477
   395
                break;
slouken@477
   396
            case 24:
slouken@101
   397
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
slouken@477
   398
                Rmask = 0x000000FF;
slouken@477
   399
                Gmask = 0x0000FF00;
slouken@477
   400
                Bmask = 0x00FF0000;
slouken@106
   401
#else
slouken@477
   402
                Rmask = 0x00FF0000;
slouken@477
   403
                Gmask = 0x0000FF00;
slouken@477
   404
                Bmask = 0x000000FF;
slouken@106
   405
#endif
slouken@477
   406
                break;
slouken@477
   407
            case 32:
slouken@477
   408
                /* We don't know if this has alpha channel or not */
slouken@477
   409
                correctAlpha = SDL_TRUE;
slouken@477
   410
                Amask = 0xFF000000;
slouken@477
   411
                Rmask = 0x00FF0000;
slouken@477
   412
                Gmask = 0x0000FF00;
slouken@477
   413
                Bmask = 0x000000FF;
slouken@477
   414
                break;
slouken@477
   415
            default:
slouken@368
   416
                break;
slouken@368
   417
            }
slouken@477
   418
            break;
slouken@477
   419
slouken@477
   420
        case BI_BITFIELDS:
slouken@477
   421
            break;  /* we handled this in the info header. */
slouken@101
   422
slouken@368
   423
        default:
slouken@368
   424
            break;
slouken@368
   425
    }
slouken@101
   426
slouken@368
   427
    /* Create a compatible surface, note that the colors are RGB ordered */
slouken@368
   428
    surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
slouken@368
   429
            biWidth, biHeight, biBitCount, Rmask, Gmask, Bmask, Amask);
slouken@368
   430
    if ( surface == NULL ) {
slouken@368
   431
        was_error = SDL_TRUE;
slouken@368
   432
        goto done;
slouken@368
   433
    }
slouken@101
   434
slouken@368
   435
    /* Load the palette, if any */
slouken@368
   436
    palette = (surface->format)->palette;
slouken@368
   437
    if ( palette ) {
slouken@368
   438
        if ( SDL_RWseek(src, fp_offset+14+biSize, RW_SEEK_SET) < 0 ) {
slouken@368
   439
            SDL_Error(SDL_EFSEEK);
slouken@368
   440
            was_error = SDL_TRUE;
slouken@368
   441
            goto done;
slouken@368
   442
        }
slouken@151
   443
slouken@368
   444
        /*
slouken@368
   445
        | guich: always use 1<<bpp b/c some bitmaps can bring wrong information
slouken@368
   446
        | for colorsUsed
slouken@368
   447
        */
slouken@368
   448
        /* if ( biClrUsed == 0 ) {  */
slouken@368
   449
        biClrUsed = 1 << biBitCount;
slouken@368
   450
        /* } */
slouken@368
   451
        if ( biSize == 12 ) {
slouken@368
   452
            for ( i = 0; i < (int)biClrUsed; ++i ) {
slouken@368
   453
                SDL_RWread(src, &palette->colors[i].b, 1, 1);
slouken@368
   454
                SDL_RWread(src, &palette->colors[i].g, 1, 1);
slouken@368
   455
                SDL_RWread(src, &palette->colors[i].r, 1, 1);
slouken@368
   456
                palette->colors[i].a = SDL_ALPHA_OPAQUE;
slouken@368
   457
            }
slouken@368
   458
        } else {
slouken@368
   459
            for ( i = 0; i < (int)biClrUsed; ++i ) {
slouken@368
   460
                SDL_RWread(src, &palette->colors[i].b, 1, 1);
slouken@368
   461
                SDL_RWread(src, &palette->colors[i].g, 1, 1);
slouken@368
   462
                SDL_RWread(src, &palette->colors[i].r, 1, 1);
slouken@368
   463
                SDL_RWread(src, &palette->colors[i].a, 1, 1);
slouken@364
   464
slouken@368
   465
                /* According to Microsoft documentation, the fourth element
slouken@368
   466
                   is reserved and must be zero, so we shouldn't treat it as
slouken@368
   467
                   alpha.
slouken@368
   468
                */
slouken@368
   469
                palette->colors[i].a = SDL_ALPHA_OPAQUE;
slouken@368
   470
            }
slouken@368
   471
        }
slouken@368
   472
        palette->ncolors = biClrUsed;
slouken@368
   473
    }
slouken@101
   474
slouken@368
   475
    /* Read the surface pixels.  Note that the bmp image is upside down */
slouken@368
   476
    if ( SDL_RWseek(src, fp_offset+bfOffBits, RW_SEEK_SET) < 0 ) {
slouken@368
   477
        SDL_Error(SDL_EFSEEK);
slouken@368
   478
        was_error = SDL_TRUE;
slouken@368
   479
        goto done;
slouken@368
   480
    }
slouken@368
   481
    if ((biCompression == BI_RLE4) || (biCompression == BI_RLE8)) {
slouken@368
   482
        was_error = (SDL_bool)readRlePixels(surface, src, biCompression == BI_RLE8);
slouken@368
   483
        if (was_error) IMG_SetError("Error reading from BMP");
slouken@368
   484
        goto done;
slouken@368
   485
    }
slouken@368
   486
    top = (Uint8 *)surface->pixels;
slouken@368
   487
    end = (Uint8 *)surface->pixels+(surface->h*surface->pitch);
slouken@368
   488
    switch (ExpandBMP) {
slouken@368
   489
        case 1:
slouken@368
   490
            bmpPitch = (biWidth + 7) >> 3;
slouken@368
   491
            pad  = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0);
slouken@368
   492
            break;
slouken@368
   493
        case 4:
slouken@368
   494
            bmpPitch = (biWidth + 1) >> 1;
slouken@368
   495
            pad  = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0);
slouken@368
   496
            break;
slouken@368
   497
        default:
slouken@368
   498
            pad  = ((surface->pitch%4) ?
slouken@368
   499
                    (4-(surface->pitch%4)) : 0);
slouken@368
   500
            break;
slouken@368
   501
    }
slouken@368
   502
    if ( topDown ) {
slouken@368
   503
        bits = top;
slouken@368
   504
    } else {
slouken@368
   505
        bits = end - surface->pitch;
slouken@368
   506
    }
slouken@368
   507
    while ( bits >= top && bits < end ) {
slouken@368
   508
        switch (ExpandBMP) {
slouken@368
   509
            case 1:
slouken@368
   510
            case 4: {
slouken@368
   511
            Uint8 pixel = 0;
slouken@368
   512
            int   shift = (8-ExpandBMP);
slouken@368
   513
            for ( i=0; i<surface->w; ++i ) {
slouken@368
   514
                if ( i%(8/ExpandBMP) == 0 ) {
slouken@368
   515
                    if ( !SDL_RWread(src, &pixel, 1, 1) ) {
slouken@413
   516
                        IMG_SetError("Error reading from BMP");
slouken@368
   517
                        was_error = SDL_TRUE;
slouken@368
   518
                        goto done;
slouken@368
   519
                    }
slouken@368
   520
                }
slouken@368
   521
                *(bits+i) = (pixel>>shift);
slouken@368
   522
                pixel <<= ExpandBMP;
slouken@368
   523
            } }
slouken@368
   524
            break;
slouken@101
   525
slouken@368
   526
            default:
slouken@413
   527
            if ( SDL_RWread(src, bits, 1, surface->pitch) != surface->pitch ) {
slouken@368
   528
                SDL_Error(SDL_EFREAD);
slouken@368
   529
                was_error = SDL_TRUE;
slouken@368
   530
                goto done;
slouken@368
   531
            }
slouken@101
   532
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
slouken@368
   533
            /* Byte-swap the pixels if needed. Note that the 24bpp
slouken@368
   534
               case has already been taken care of above. */
slouken@368
   535
            switch(biBitCount) {
slouken@368
   536
                case 15:
slouken@368
   537
                case 16: {
slouken@413
   538
                    Uint16 *pix = (Uint16 *)bits;
slouken@368
   539
                    for(i = 0; i < surface->w; i++)
slouken@413
   540
                        pix[i] = SDL_Swap16(pix[i]);
slouken@368
   541
                    break;
slouken@368
   542
                }
slouken@101
   543
slouken@368
   544
                case 32: {
slouken@413
   545
                    Uint32 *pix = (Uint32 *)bits;
slouken@368
   546
                    for(i = 0; i < surface->w; i++)
slouken@413
   547
                        pix[i] = SDL_Swap32(pix[i]);
slouken@368
   548
                    break;
slouken@368
   549
                }
slouken@368
   550
            }
slouken@101
   551
#endif
slouken@368
   552
            break;
slouken@368
   553
        }
slouken@368
   554
        /* Skip padding bytes, ugh */
slouken@368
   555
        if ( pad ) {
slouken@368
   556
            Uint8 padbyte;
slouken@368
   557
            for ( i=0; i<pad; ++i ) {
slouken@368
   558
                SDL_RWread(src, &padbyte, 1, 1);
slouken@368
   559
            }
slouken@368
   560
        }
slouken@368
   561
        if ( topDown ) {
slouken@368
   562
            bits += surface->pitch;
slouken@368
   563
        } else {
slouken@368
   564
            bits -= surface->pitch;
slouken@368
   565
        }
slouken@368
   566
    }
slouken@413
   567
    if (correctAlpha) {
slouken@413
   568
        CorrectAlphaChannel(surface);
slouken@413
   569
    }
slouken@101
   570
done:
slouken@368
   571
    if ( was_error ) {
slouken@368
   572
        if ( src ) {
slouken@368
   573
            SDL_RWseek(src, fp_offset, RW_SEEK_SET);
slouken@368
   574
        }
slouken@368
   575
        if ( surface ) {
slouken@368
   576
            SDL_FreeSurface(surface);
slouken@368
   577
        }
slouken@368
   578
        surface = NULL;
slouken@368
   579
    }
slouken@368
   580
    if ( freesrc && src ) {
slouken@368
   581
        SDL_RWclose(src);
slouken@368
   582
    }
slouken@368
   583
    return(surface);
slouken@101
   584
}
slouken@101
   585
couriersud@189
   586
static Uint8
couriersud@189
   587
SDL_Read8(SDL_RWops * src)
couriersud@189
   588
{
couriersud@189
   589
    Uint8 value;
couriersud@189
   590
couriersud@189
   591
    SDL_RWread(src, &value, 1, 1);
couriersud@189
   592
    return (value);
couriersud@189
   593
}
couriersud@189
   594
couriersud@189
   595
static SDL_Surface *
couriersud@189
   596
LoadICOCUR_RW(SDL_RWops * src, int type, int freesrc)
couriersud@189
   597
{
slouken@202
   598
    SDL_bool was_error;
aschiffler@343
   599
    Sint64 fp_offset;
couriersud@189
   600
    int bmpPitch;
couriersud@189
   601
    int i, pad;
couriersud@189
   602
    SDL_Surface *surface;
couriersud@189
   603
    Uint32 Rmask;
couriersud@189
   604
    Uint32 Gmask;
couriersud@189
   605
    Uint32 Bmask;
couriersud@189
   606
    Uint8 *bits;
couriersud@189
   607
    int ExpandBMP;
couriersud@189
   608
    int maxCol = 0;
couriersud@189
   609
    int icoOfs = 0;
couriersud@189
   610
    Uint32 palette[256];
couriersud@189
   611
couriersud@189
   612
    /* The Win32 ICO file header (14 bytes) */
couriersud@189
   613
    Uint16 bfReserved;
couriersud@189
   614
    Uint16 bfType;
couriersud@189
   615
    Uint16 bfCount;
couriersud@189
   616
couriersud@189
   617
    /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
couriersud@189
   618
    Uint32 biSize;
couriersud@189
   619
    Sint32 biWidth;
couriersud@189
   620
    Sint32 biHeight;
couriersud@189
   621
    Uint16 biPlanes;
couriersud@189
   622
    Uint16 biBitCount;
couriersud@189
   623
    Uint32 biCompression;
couriersud@189
   624
    Uint32 biSizeImage;
couriersud@189
   625
    Sint32 biXPelsPerMeter;
couriersud@189
   626
    Sint32 biYPelsPerMeter;
couriersud@189
   627
    Uint32 biClrUsed;
couriersud@189
   628
    Uint32 biClrImportant;
couriersud@189
   629
couriersud@189
   630
    /* Make sure we are passed a valid data source */
couriersud@189
   631
    surface = NULL;
slouken@202
   632
    was_error = SDL_FALSE;
couriersud@189
   633
    if (src == NULL) {
slouken@202
   634
        was_error = SDL_TRUE;
couriersud@189
   635
        goto done;
couriersud@189
   636
    }
couriersud@189
   637
couriersud@189
   638
    /* Read in the ICO file header */
couriersud@189
   639
    fp_offset = SDL_RWtell(src);
couriersud@189
   640
    SDL_ClearError();
couriersud@189
   641
couriersud@189
   642
    bfReserved = SDL_ReadLE16(src);
couriersud@189
   643
    bfType = SDL_ReadLE16(src);
couriersud@189
   644
    bfCount = SDL_ReadLE16(src);
couriersud@189
   645
    if ((bfReserved != 0) || (bfType != type) || (bfCount == 0)) {
slouken@253
   646
        IMG_SetError("File is not a Windows %s file", type == 1 ? "ICO" : "CUR");
slouken@202
   647
        was_error = SDL_TRUE;
couriersud@189
   648
        goto done;
couriersud@189
   649
    }
couriersud@189
   650
couriersud@189
   651
    /* Read the Win32 Icon Directory */
couriersud@189
   652
    for (i = 0; i < bfCount; i++) {
couriersud@189
   653
        /* Icon Directory Entries */
couriersud@189
   654
        int bWidth = SDL_Read8(src);    /* Uint8, but 0 = 256 ! */
couriersud@189
   655
        int bHeight = SDL_Read8(src);   /* Uint8, but 0 = 256 ! */
couriersud@189
   656
        int bColorCount = SDL_Read8(src);       /* Uint8, but 0 = 256 ! */
couriersud@189
   657
        Uint8 bReserved = SDL_Read8(src);
couriersud@189
   658
        Uint16 wPlanes = SDL_ReadLE16(src);
couriersud@189
   659
        Uint16 wBitCount = SDL_ReadLE16(src);
couriersud@189
   660
        Uint32 dwBytesInRes = SDL_ReadLE32(src);
couriersud@189
   661
        Uint32 dwImageOffset = SDL_ReadLE32(src);
couriersud@189
   662
couriersud@189
   663
        if (!bWidth)
couriersud@189
   664
            bWidth = 256;
couriersud@189
   665
        if (!bHeight)
couriersud@189
   666
            bHeight = 256;
couriersud@189
   667
        if (!bColorCount)
couriersud@189
   668
            bColorCount = 256;
couriersud@189
   669
couriersud@189
   670
        //printf("%dx%d@%d - %08x\n", bWidth, bHeight, bColorCount, dwImageOffset);
couriersud@189
   671
        if (bColorCount > maxCol) {
couriersud@189
   672
            maxCol = bColorCount;
couriersud@189
   673
            icoOfs = dwImageOffset;
couriersud@189
   674
            //printf("marked\n");
couriersud@189
   675
        }
couriersud@189
   676
    }
couriersud@189
   677
couriersud@189
   678
    /* Advance to the DIB Data */
couriersud@189
   679
    if (SDL_RWseek(src, icoOfs, RW_SEEK_SET) < 0) {
couriersud@189
   680
        SDL_Error(SDL_EFSEEK);
slouken@202
   681
        was_error = SDL_TRUE;
couriersud@189
   682
        goto done;
couriersud@189
   683
    }
couriersud@189
   684
couriersud@189
   685
    /* Read the Win32 BITMAPINFOHEADER */
couriersud@189
   686
    biSize = SDL_ReadLE32(src);
couriersud@189
   687
    if (biSize == 40) {
couriersud@189
   688
        biWidth = SDL_ReadLE32(src);
couriersud@189
   689
        biHeight = SDL_ReadLE32(src);
couriersud@189
   690
        biPlanes = SDL_ReadLE16(src);
couriersud@189
   691
        biBitCount = SDL_ReadLE16(src);
couriersud@189
   692
        biCompression = SDL_ReadLE32(src);
couriersud@189
   693
        biSizeImage = SDL_ReadLE32(src);
couriersud@189
   694
        biXPelsPerMeter = SDL_ReadLE32(src);
couriersud@189
   695
        biYPelsPerMeter = SDL_ReadLE32(src);
couriersud@189
   696
        biClrUsed = SDL_ReadLE32(src);
couriersud@189
   697
        biClrImportant = SDL_ReadLE32(src);
couriersud@189
   698
    } else {
slouken@253
   699
        IMG_SetError("Unsupported ICO bitmap format");
slouken@202
   700
        was_error = SDL_TRUE;
couriersud@189
   701
        goto done;
couriersud@189
   702
    }
couriersud@189
   703
couriersud@189
   704
    /* Check for read error */
couriersud@189
   705
    if (SDL_strcmp(SDL_GetError(), "") != 0) {
slouken@202
   706
        was_error = SDL_TRUE;
couriersud@189
   707
        goto done;
couriersud@189
   708
    }
couriersud@189
   709
couriersud@189
   710
    /* We don't support any BMP compression right now */
couriersud@189
   711
    switch (biCompression) {
couriersud@189
   712
    case BI_RGB:
couriersud@189
   713
        /* Default values for the BMP format */
couriersud@189
   714
        switch (biBitCount) {
couriersud@189
   715
        case 1:
couriersud@189
   716
        case 4:
couriersud@189
   717
            ExpandBMP = biBitCount;
couriersud@189
   718
            biBitCount = 8;
couriersud@189
   719
            break;
couriersud@189
   720
        case 8:
couriersud@189
   721
            ExpandBMP = 8;
couriersud@189
   722
            break;
couriersud@189
   723
        case 32:
couriersud@189
   724
            Rmask = 0x00FF0000;
couriersud@189
   725
            Gmask = 0x0000FF00;
couriersud@189
   726
            Bmask = 0x000000FF;
couriersud@189
   727
            ExpandBMP = 0;
couriersud@189
   728
            break;
couriersud@189
   729
        default:
slouken@253
   730
            IMG_SetError("ICO file with unsupported bit count");
slouken@202
   731
            was_error = SDL_TRUE;
couriersud@189
   732
            goto done;
couriersud@189
   733
        }
couriersud@189
   734
        break;
couriersud@189
   735
    default:
slouken@253
   736
        IMG_SetError("Compressed ICO files not supported");
slouken@202
   737
        was_error = SDL_TRUE;
couriersud@189
   738
        goto done;
couriersud@189
   739
    }
couriersud@189
   740
couriersud@189
   741
    /* Create a RGBA surface */
couriersud@189
   742
    biHeight = biHeight >> 1;
couriersud@189
   743
    //printf("%d x %d\n", biWidth, biHeight);
couriersud@189
   744
    surface =
couriersud@189
   745
        SDL_CreateRGBSurface(0, biWidth, biHeight, 32, 0x00FF0000,
couriersud@189
   746
                             0x0000FF00, 0x000000FF, 0xFF000000);
couriersud@189
   747
    if (surface == NULL) {
slouken@202
   748
        was_error = SDL_TRUE;
couriersud@189
   749
        goto done;
couriersud@189
   750
    }
couriersud@189
   751
couriersud@189
   752
    /* Load the palette, if any */
couriersud@189
   753
    //printf("bc %d bused %d\n", biBitCount, biClrUsed);
couriersud@189
   754
    if (biBitCount <= 8) {
couriersud@189
   755
        if (biClrUsed == 0) {
couriersud@189
   756
            biClrUsed = 1 << biBitCount;
couriersud@189
   757
        }
couriersud@189
   758
        for (i = 0; i < (int) biClrUsed; ++i) {
couriersud@189
   759
            SDL_RWread(src, &palette[i], 4, 1);
couriersud@189
   760
        }
couriersud@189
   761
    }
couriersud@189
   762
couriersud@189
   763
    /* Read the surface pixels.  Note that the bmp image is upside down */
couriersud@189
   764
    bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch);
couriersud@189
   765
    switch (ExpandBMP) {
couriersud@189
   766
    case 1:
couriersud@189
   767
        bmpPitch = (biWidth + 7) >> 3;
couriersud@189
   768
        pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
couriersud@189
   769
        break;
couriersud@189
   770
    case 4:
couriersud@189
   771
        bmpPitch = (biWidth + 1) >> 1;
couriersud@189
   772
        pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
couriersud@189
   773
        break;
couriersud@189
   774
    case 8:
couriersud@189
   775
        bmpPitch = biWidth;
couriersud@189
   776
        pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
couriersud@189
   777
        break;
couriersud@189
   778
    default:
couriersud@189
   779
        bmpPitch = biWidth * 4;
couriersud@189
   780
        pad = 0;
couriersud@189
   781
        break;
couriersud@189
   782
    }
couriersud@189
   783
    while (bits > (Uint8 *) surface->pixels) {
couriersud@189
   784
        bits -= surface->pitch;
couriersud@189
   785
        switch (ExpandBMP) {
couriersud@189
   786
        case 1:
couriersud@189
   787
        case 4:
couriersud@189
   788
        case 8:
couriersud@189
   789
            {
couriersud@189
   790
                Uint8 pixel = 0;
couriersud@189
   791
                int shift = (8 - ExpandBMP);
couriersud@189
   792
                for (i = 0; i < surface->w; ++i) {
couriersud@189
   793
                    if (i % (8 / ExpandBMP) == 0) {
couriersud@189
   794
                        if (!SDL_RWread(src, &pixel, 1, 1)) {
slouken@253
   795
                            IMG_SetError("Error reading from ICO");
slouken@202
   796
                            was_error = SDL_TRUE;
couriersud@189
   797
                            goto done;
couriersud@189
   798
                        }
couriersud@189
   799
                    }
couriersud@189
   800
                    *((Uint32 *) bits + i) = (palette[pixel >> shift]);
couriersud@189
   801
                    pixel <<= ExpandBMP;
couriersud@189
   802
                }
couriersud@189
   803
            }
couriersud@189
   804
            break;
couriersud@189
   805
couriersud@189
   806
        default:
couriersud@189
   807
            if (SDL_RWread(src, bits, 1, surface->pitch)
couriersud@189
   808
                != surface->pitch) {
couriersud@189
   809
                SDL_Error(SDL_EFREAD);
slouken@202
   810
                was_error = SDL_TRUE;
couriersud@189
   811
                goto done;
couriersud@189
   812
            }
couriersud@189
   813
            break;
couriersud@189
   814
        }
couriersud@189
   815
        /* Skip padding bytes, ugh */
couriersud@189
   816
        if (pad) {
couriersud@189
   817
            Uint8 padbyte;
couriersud@189
   818
            for (i = 0; i < pad; ++i) {
couriersud@189
   819
                SDL_RWread(src, &padbyte, 1, 1);
couriersud@189
   820
            }
couriersud@189
   821
        }
couriersud@189
   822
    }
couriersud@189
   823
    /* Read the mask pixels.  Note that the bmp image is upside down */
couriersud@189
   824
    bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch);
couriersud@189
   825
    ExpandBMP = 1;
couriersud@189
   826
    bmpPitch = (biWidth + 7) >> 3;
couriersud@189
   827
    pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
couriersud@189
   828
    while (bits > (Uint8 *) surface->pixels) {
couriersud@189
   829
        Uint8 pixel = 0;
couriersud@189
   830
        int shift = (8 - ExpandBMP);
couriersud@189
   831
couriersud@189
   832
        bits -= surface->pitch;
couriersud@189
   833
        for (i = 0; i < surface->w; ++i) {
couriersud@189
   834
            if (i % (8 / ExpandBMP) == 0) {
couriersud@189
   835
                if (!SDL_RWread(src, &pixel, 1, 1)) {
slouken@253
   836
                    IMG_SetError("Error reading from ICO");
slouken@202
   837
                    was_error = SDL_TRUE;
couriersud@189
   838
                    goto done;
couriersud@189
   839
                }
couriersud@189
   840
            }
couriersud@189
   841
            *((Uint32 *) bits + i) |= ((pixel >> shift) ? 0 : 0xFF000000);
couriersud@189
   842
            pixel <<= ExpandBMP;
couriersud@189
   843
        }
couriersud@189
   844
        /* Skip padding bytes, ugh */
couriersud@189
   845
        if (pad) {
couriersud@189
   846
            Uint8 padbyte;
couriersud@189
   847
            for (i = 0; i < pad; ++i) {
couriersud@189
   848
                SDL_RWread(src, &padbyte, 1, 1);
couriersud@189
   849
            }
couriersud@189
   850
        }
couriersud@189
   851
    }
couriersud@189
   852
  done:
couriersud@189
   853
    if (was_error) {
couriersud@189
   854
        if (src) {
couriersud@189
   855
            SDL_RWseek(src, fp_offset, RW_SEEK_SET);
couriersud@189
   856
        }
couriersud@189
   857
        if (surface) {
couriersud@189
   858
            SDL_FreeSurface(surface);
couriersud@189
   859
        }
couriersud@189
   860
        surface = NULL;
couriersud@189
   861
    }
couriersud@189
   862
    if (freesrc && src) {
couriersud@189
   863
        SDL_RWclose(src);
couriersud@189
   864
    }
couriersud@189
   865
    return (surface);
couriersud@189
   866
}
couriersud@189
   867
slouken@0
   868
/* Load a BMP type image from an SDL datasource */
slouken@0
   869
SDL_Surface *IMG_LoadBMP_RW(SDL_RWops *src)
slouken@0
   870
{
slouken@368
   871
    return(LoadBMP_RW(src, 0));
slouken@0
   872
}
slouken@0
   873
couriersud@189
   874
/* Load a ICO type image from an SDL datasource */
couriersud@189
   875
SDL_Surface *IMG_LoadICO_RW(SDL_RWops *src)
couriersud@189
   876
{
slouken@368
   877
    return(LoadICOCUR_RW(src, 1, 0));
couriersud@189
   878
}
couriersud@189
   879
couriersud@189
   880
/* Load a CUR type image from an SDL datasource */
couriersud@189
   881
SDL_Surface *IMG_LoadCUR_RW(SDL_RWops *src)
couriersud@189
   882
{
slouken@368
   883
    return(LoadICOCUR_RW(src, 2, 0));
couriersud@189
   884
}
couriersud@189
   885
slouken@0
   886
#else
slouken@0
   887
slouken@0
   888
/* See if an image is contained in a data source */
slouken@0
   889
int IMG_isBMP(SDL_RWops *src)
slouken@0
   890
{
slouken@368
   891
    return(0);
slouken@0
   892
}
slouken@0
   893
couriersud@189
   894
int IMG_isICO(SDL_RWops *src)
couriersud@189
   895
{
slouken@368
   896
    return(0);
couriersud@189
   897
}
couriersud@189
   898
couriersud@189
   899
int IMG_isCUR(SDL_RWops *src)
couriersud@189
   900
{
slouken@368
   901
    return(0);
couriersud@189
   902
}
couriersud@189
   903
slouken@0
   904
/* Load a BMP type image from an SDL datasource */
slouken@0
   905
SDL_Surface *IMG_LoadBMP_RW(SDL_RWops *src)
slouken@0
   906
{
slouken@368
   907
    return(NULL);
slouken@0
   908
}
slouken@0
   909
couriersud@189
   910
/* Load a BMP type image from an SDL datasource */
couriersud@189
   911
SDL_Surface *IMG_LoadCUR_RW(SDL_RWops *src)
couriersud@189
   912
{
slouken@368
   913
    return(NULL);
couriersud@189
   914
}
couriersud@189
   915
couriersud@189
   916
/* Load a BMP type image from an SDL datasource */
couriersud@189
   917
SDL_Surface *IMG_LoadICO_RW(SDL_RWops *src)
couriersud@189
   918
{
slouken@368
   919
    return(NULL);
couriersud@189
   920
}
couriersud@189
   921
slouken@0
   922
#endif /* LOAD_BMP */
slouken@237
   923
slouken@237
   924
#endif /* !defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND) */