src/video/SDL_pixels.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 15 Dec 2009 08:11:06 +0000
changeset 3565 f43c8f688f77
parent 3557 7184580ab756
child 3597 7dec3fe9b580
permissions -rw-r--r--
Fixed bug #906

Added better error reporting for OpenGL context creation failing.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
/* General (mostly internal) pixel/color manipulation routines for SDL */
slouken@0
    25
slouken@0
    26
#include "SDL_endian.h"
slouken@0
    27
#include "SDL_video.h"
slouken@0
    28
#include "SDL_sysvideo.h"
slouken@0
    29
#include "SDL_blit.h"
slouken@0
    30
#include "SDL_pixels_c.h"
slouken@0
    31
#include "SDL_RLEaccel_c.h"
slouken@0
    32
slouken@3555
    33
struct SDL_PaletteWatch
slouken@3555
    34
{
slouken@3555
    35
    SDL_PaletteChangedFunc callback;
slouken@3555
    36
    void *userdata;
slouken@3555
    37
    struct SDL_PaletteWatch *next;
slouken@3555
    38
};
slouken@3555
    39
slouken@0
    40
/* Helper functions */
slouken@1895
    41
slouken@1895
    42
SDL_bool
slouken@1895
    43
SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask,
slouken@1895
    44
                           Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
slouken@1895
    45
{
slouken@1895
    46
    Uint32 masks[4];
slouken@1895
    47
slouken@1895
    48
    /* Initialize the values here */
slouken@3284
    49
    if (SDL_BYTESPERPIXEL(format) <= 2) {
slouken@3284
    50
        *bpp = SDL_BITSPERPIXEL(format);
slouken@3284
    51
    } else {
slouken@1895
    52
        *bpp = SDL_BYTESPERPIXEL(format) * 8;
slouken@1895
    53
    }
slouken@1895
    54
    *Rmask = *Gmask = *Bmask = *Amask = 0;
slouken@1895
    55
slouken@3557
    56
    if (format == SDL_PIXELFORMAT_RGB24) {
slouken@3557
    57
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
slouken@3557
    58
        *Rmask = 0x00FF0000;
slouken@3557
    59
        *Gmask = 0x0000FF00;
slouken@3557
    60
        *Bmask = 0x000000FF;
slouken@3557
    61
#else
slouken@3557
    62
        *Rmask = 0x000000FF;
slouken@3557
    63
        *Gmask = 0x0000FF00;
slouken@3557
    64
        *Bmask = 0x00FF0000;
slouken@3557
    65
#endif
slouken@3557
    66
        return SDL_TRUE;
slouken@3557
    67
    }
slouken@3557
    68
slouken@3557
    69
    if (format == SDL_PIXELFORMAT_BGR24) {
slouken@3557
    70
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
slouken@3557
    71
        *Rmask = 0x000000FF;
slouken@3557
    72
        *Gmask = 0x0000FF00;
slouken@3557
    73
        *Bmask = 0x00FF0000;
slouken@3557
    74
#else
slouken@3557
    75
        *Rmask = 0x00FF0000;
slouken@3557
    76
        *Gmask = 0x0000FF00;
slouken@3557
    77
        *Bmask = 0x000000FF;
slouken@3557
    78
#endif
slouken@3557
    79
        return SDL_TRUE;
slouken@3557
    80
    }
slouken@3557
    81
slouken@1965
    82
    if (SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED8 &&
slouken@1965
    83
        SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED16 &&
slouken@1965
    84
        SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED32) {
slouken@1895
    85
        /* Not a format that uses masks */
slouken@1895
    86
        return SDL_TRUE;
slouken@1895
    87
    }
slouken@1895
    88
slouken@1895
    89
    switch (SDL_PIXELLAYOUT(format)) {
slouken@1965
    90
    case SDL_PACKEDLAYOUT_332:
slouken@1895
    91
        masks[0] = 0x00000000;
slouken@1895
    92
        masks[1] = 0x000000E0;
slouken@1895
    93
        masks[2] = 0x0000001C;
slouken@1895
    94
        masks[3] = 0x00000003;
slouken@1895
    95
        break;
slouken@1965
    96
    case SDL_PACKEDLAYOUT_4444:
slouken@1895
    97
        masks[0] = 0x0000F000;
slouken@1895
    98
        masks[1] = 0x00000F00;
slouken@1895
    99
        masks[2] = 0x000000F0;
slouken@1895
   100
        masks[3] = 0x0000000F;
slouken@1895
   101
        break;
slouken@1965
   102
    case SDL_PACKEDLAYOUT_1555:
slouken@1895
   103
        masks[0] = 0x00008000;
slouken@1895
   104
        masks[1] = 0x00007C00;
slouken@1895
   105
        masks[2] = 0x000003E0;
slouken@1895
   106
        masks[3] = 0x0000001F;
slouken@1895
   107
        break;
lestat@3163
   108
    case SDL_PACKEDLAYOUT_5551:
lestat@3163
   109
        masks[0] = 0x0000F800;
lestat@3163
   110
        masks[1] = 0x000007C0;
lestat@3163
   111
        masks[2] = 0x0000003E;
lestat@3163
   112
        masks[3] = 0x00000001;
lestat@3163
   113
        break;
slouken@1965
   114
    case SDL_PACKEDLAYOUT_565:
slouken@1895
   115
        masks[0] = 0x00000000;
slouken@1895
   116
        masks[1] = 0x0000F800;
slouken@1895
   117
        masks[2] = 0x000007E0;
slouken@1895
   118
        masks[3] = 0x0000001F;
slouken@1895
   119
        break;
slouken@1965
   120
    case SDL_PACKEDLAYOUT_8888:
slouken@1895
   121
        masks[0] = 0xFF000000;
slouken@1895
   122
        masks[1] = 0x00FF0000;
slouken@1895
   123
        masks[2] = 0x0000FF00;
slouken@1895
   124
        masks[3] = 0x000000FF;
slouken@1895
   125
        break;
slouken@1965
   126
    case SDL_PACKEDLAYOUT_2101010:
slouken@1895
   127
        masks[0] = 0xC0000000;
slouken@1895
   128
        masks[1] = 0x3FF00000;
slouken@1895
   129
        masks[2] = 0x000FFC00;
slouken@1895
   130
        masks[3] = 0x000003FF;
slouken@1895
   131
        break;
lestat@3163
   132
    case SDL_PACKEDLAYOUT_1010102:
lestat@3163
   133
        masks[0] = 0xFFC00000;
lestat@3163
   134
        masks[1] = 0x003FF000;
lestat@3163
   135
        masks[2] = 0x00000FFC;
lestat@3163
   136
        masks[3] = 0x00000003;
lestat@3163
   137
        break;
slouken@1895
   138
    default:
slouken@3484
   139
        SDL_SetError("Unknown pixel format");
slouken@1895
   140
        return SDL_FALSE;
slouken@1895
   141
    }
slouken@1895
   142
slouken@1895
   143
    switch (SDL_PIXELORDER(format)) {
slouken@1965
   144
    case SDL_PACKEDORDER_XRGB:
slouken@1895
   145
        *Rmask = masks[1];
slouken@1895
   146
        *Gmask = masks[2];
slouken@1895
   147
        *Bmask = masks[3];
slouken@1895
   148
        break;
slouken@1965
   149
    case SDL_PACKEDORDER_RGBX:
slouken@1895
   150
        *Rmask = masks[0];
slouken@1895
   151
        *Gmask = masks[1];
slouken@1895
   152
        *Bmask = masks[2];
slouken@1895
   153
        break;
slouken@1965
   154
    case SDL_PACKEDORDER_ARGB:
slouken@1895
   155
        *Amask = masks[0];
slouken@1895
   156
        *Rmask = masks[1];
slouken@1895
   157
        *Gmask = masks[2];
slouken@1895
   158
        *Bmask = masks[3];
slouken@1895
   159
        break;
slouken@1965
   160
    case SDL_PACKEDORDER_RGBA:
slouken@1895
   161
        *Rmask = masks[0];
slouken@1895
   162
        *Gmask = masks[1];
slouken@1895
   163
        *Bmask = masks[2];
slouken@1895
   164
        *Amask = masks[3];
slouken@1895
   165
        break;
slouken@1965
   166
    case SDL_PACKEDORDER_XBGR:
slouken@1895
   167
        *Bmask = masks[1];
slouken@1895
   168
        *Gmask = masks[2];
slouken@1895
   169
        *Rmask = masks[3];
slouken@1895
   170
        break;
slouken@1965
   171
    case SDL_PACKEDORDER_BGRX:
slouken@1895
   172
        *Bmask = masks[0];
slouken@1895
   173
        *Gmask = masks[1];
slouken@1895
   174
        *Rmask = masks[2];
slouken@1895
   175
        break;
slouken@1965
   176
    case SDL_PACKEDORDER_BGRA:
slouken@1895
   177
        *Bmask = masks[0];
slouken@1895
   178
        *Gmask = masks[1];
slouken@1895
   179
        *Rmask = masks[2];
slouken@1895
   180
        *Amask = masks[3];
slouken@1895
   181
        break;
slouken@1965
   182
    case SDL_PACKEDORDER_ABGR:
slouken@1895
   183
        *Amask = masks[0];
slouken@1895
   184
        *Bmask = masks[1];
slouken@1895
   185
        *Gmask = masks[2];
slouken@1895
   186
        *Rmask = masks[3];
slouken@1895
   187
        break;
slouken@1895
   188
    default:
slouken@3484
   189
        SDL_SetError("Unknown pixel format");
slouken@1895
   190
        return SDL_FALSE;
slouken@1895
   191
    }
slouken@1895
   192
    return SDL_TRUE;
slouken@1895
   193
}
slouken@1895
   194
slouken@1895
   195
Uint32
slouken@1895
   196
SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
slouken@1895
   197
                           Uint32 Amask)
slouken@1895
   198
{
slouken@1895
   199
    switch (bpp) {
slouken@1895
   200
    case 8:
slouken@1895
   201
        switch (Rmask) {
slouken@1895
   202
        case 0:
slouken@1965
   203
            return SDL_PIXELFORMAT_INDEX8;
slouken@1895
   204
        case 0xE0:
slouken@1965
   205
            return SDL_PIXELFORMAT_RGB332;
slouken@1895
   206
        }
slouken@1895
   207
        break;
slouken@1895
   208
    case 12:
slouken@1895
   209
        switch (Rmask) {
slouken@1895
   210
        case 0x0F00:
slouken@1965
   211
            return SDL_PIXELFORMAT_RGB444;
slouken@1895
   212
        }
slouken@1895
   213
        break;
slouken@1895
   214
    case 15:
slouken@1895
   215
        switch (Rmask) {
slouken@2735
   216
        case 0x001F:
slouken@2735
   217
            return SDL_PIXELFORMAT_BGR555;
slouken@1895
   218
        case 0x7C00:
slouken@1965
   219
            return SDL_PIXELFORMAT_RGB555;
slouken@1895
   220
        }
slouken@1895
   221
        break;
slouken@1895
   222
    case 16:
slouken@1895
   223
        switch (Rmask) {
lestat@3163
   224
        case 0x000F:
lestat@3163
   225
            return SDL_PIXELFORMAT_ABGR4444;
slouken@2735
   226
        case 0x001F:
lestat@3163
   227
            if (Gmask == 0x07E0) {
lestat@3163
   228
                return SDL_PIXELFORMAT_BGR565;
lestat@3163
   229
            }
slouken@2735
   230
            return SDL_PIXELFORMAT_ABGR1555;
slouken@1895
   231
        case 0x0F00:
slouken@1965
   232
            return SDL_PIXELFORMAT_ARGB4444;
slouken@1895
   233
        case 0x7C00:
slouken@1965
   234
            return SDL_PIXELFORMAT_ARGB1555;
slouken@1895
   235
        case 0xF800:
slouken@1965
   236
            return SDL_PIXELFORMAT_RGB565;
slouken@1895
   237
        }
slouken@1895
   238
        break;
lestat@3182
   239
    case 24:
lestat@3182
   240
        switch (Rmask) {
lestat@3182
   241
        case 0x00FF0000:
lestat@3182
   242
            return SDL_PIXELFORMAT_RGB888;
lestat@3182
   243
        case 0x000000FF:
lestat@3182
   244
            return SDL_PIXELFORMAT_BGR888;
lestat@3182
   245
        case 0x00000000:
lestat@3182
   246
            /* FIXME: At this point we can't distinguish */
lestat@3182
   247
            /* if this format is RGB24 or BGR24          */
lestat@3182
   248
            return SDL_PIXELFORMAT_RGB24;
lestat@3182
   249
        }
slouken@1895
   250
    case 32:
slouken@1895
   251
        switch (Rmask) {
slouken@1895
   252
        case 0xFF000000:
slouken@1895
   253
            if (Amask == 0x000000FF) {
slouken@1965
   254
                return SDL_PIXELFORMAT_RGBA8888;
slouken@1895
   255
            }
slouken@1895
   256
            break;
slouken@1895
   257
        case 0x00FF0000:
slouken@1895
   258
            if (Amask == 0xFF000000) {
slouken@1965
   259
                return SDL_PIXELFORMAT_ARGB8888;
slouken@1895
   260
            } else {
slouken@1965
   261
                return SDL_PIXELFORMAT_RGB888;
slouken@1895
   262
            }
slouken@1895
   263
            break;
slouken@1895
   264
        case 0x0000FF00:
slouken@1895
   265
            if (Amask == 0x000000FF) {
slouken@1965
   266
                return SDL_PIXELFORMAT_BGRA8888;
slouken@1895
   267
            }
slouken@1895
   268
            break;
slouken@1895
   269
        case 0x000000FF:
slouken@1895
   270
            if (Amask == 0xFF000000) {
slouken@1965
   271
                return SDL_PIXELFORMAT_ABGR8888;
slouken@1895
   272
            } else {
slouken@1965
   273
                return SDL_PIXELFORMAT_BGR888;
slouken@1895
   274
            }
slouken@1895
   275
            break;
slouken@1895
   276
        case 0x3FF00000:
slouken@1965
   277
            return SDL_PIXELFORMAT_ARGB2101010;
slouken@1895
   278
        }
slouken@1895
   279
    }
slouken@1965
   280
    return SDL_PIXELFORMAT_UNKNOWN;
slouken@1895
   281
}
slouken@1895
   282
slouken@1895
   283
slouken@1895
   284
SDL_Palette *
slouken@1895
   285
SDL_AllocPalette(int ncolors)
slouken@1895
   286
{
slouken@1895
   287
    SDL_Palette *palette;
slouken@1895
   288
slouken@1895
   289
    palette = (SDL_Palette *) SDL_malloc(sizeof(*palette));
slouken@1895
   290
    if (!palette) {
slouken@1895
   291
        SDL_OutOfMemory();
slouken@1895
   292
        return NULL;
slouken@1895
   293
    }
slouken@1895
   294
    palette->colors =
slouken@1895
   295
        (SDL_Color *) SDL_malloc(ncolors * sizeof(*palette->colors));
slouken@1895
   296
    if (!palette->colors) {
slouken@1895
   297
        SDL_free(palette);
slouken@1895
   298
        return NULL;
slouken@1895
   299
    }
slouken@1895
   300
    palette->ncolors = ncolors;
slouken@1895
   301
    palette->watch = NULL;
slouken@1895
   302
    palette->refcount = 1;
slouken@1895
   303
slouken@1895
   304
    SDL_memset(palette->colors, 0xFF, ncolors * sizeof(*palette->colors));
slouken@1895
   305
slouken@1895
   306
    return palette;
slouken@1895
   307
}
slouken@1895
   308
slouken@1895
   309
int
slouken@1895
   310
SDL_AddPaletteWatch(SDL_Palette * palette, SDL_PaletteChangedFunc callback,
slouken@1895
   311
                    void *userdata)
slouken@1895
   312
{
slouken@1895
   313
    SDL_PaletteWatch *watch;
slouken@1895
   314
slouken@1895
   315
    if (!palette) {
slouken@1895
   316
        return -1;
slouken@1895
   317
    }
slouken@1895
   318
slouken@1895
   319
    watch = (SDL_PaletteWatch *) SDL_malloc(sizeof(*watch));
slouken@1895
   320
    if (!watch) {
slouken@1895
   321
        SDL_OutOfMemory();
slouken@1895
   322
        return -1;
slouken@1895
   323
    }
slouken@1895
   324
slouken@1895
   325
    watch->callback = callback;
slouken@1895
   326
    watch->userdata = userdata;
slouken@1895
   327
    watch->next = palette->watch;
slouken@1895
   328
    palette->watch = watch;
slouken@1895
   329
    ++palette->refcount;
slouken@1895
   330
    return 0;
slouken@1895
   331
}
slouken@1895
   332
slouken@1895
   333
void
slouken@1895
   334
SDL_DelPaletteWatch(SDL_Palette * palette, SDL_PaletteChangedFunc callback,
slouken@1895
   335
                    void *userdata)
slouken@1895
   336
{
slouken@1895
   337
    SDL_PaletteWatch *prev, *watch;
slouken@1895
   338
slouken@1895
   339
    if (!palette) {
slouken@1895
   340
        return;
slouken@1895
   341
    }
slouken@1895
   342
slouken@1895
   343
    for (prev = NULL, watch = palette->watch; watch;
slouken@1895
   344
         prev = watch, watch = watch->next) {
slouken@1895
   345
        if (watch->callback == callback && watch->userdata == userdata) {
slouken@1895
   346
            if (prev) {
slouken@1895
   347
                prev->next = watch->next;
slouken@1895
   348
            } else {
slouken@1895
   349
                palette->watch = watch->next;
slouken@1895
   350
            }
slouken@1895
   351
            SDL_free(watch);
slouken@1895
   352
            SDL_FreePalette(palette);
slouken@1895
   353
            return;
slouken@1895
   354
        }
slouken@1895
   355
    }
slouken@1895
   356
}
slouken@1895
   357
slouken@1895
   358
int
slouken@1895
   359
SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors,
slouken@1895
   360
                     int firstcolor, int ncolors)
slouken@1895
   361
{
slouken@1895
   362
    SDL_PaletteWatch *watch;
slouken@1895
   363
    int status = 0;
slouken@1895
   364
slouken@1895
   365
    /* Verify the parameters */
slouken@1895
   366
    if (!palette) {
slouken@1895
   367
        return -1;
slouken@1895
   368
    }
slouken@1895
   369
    if (ncolors > (palette->ncolors - firstcolor)) {
slouken@1895
   370
        ncolors = (palette->ncolors - firstcolor);
slouken@1895
   371
        status = -1;
slouken@1895
   372
    }
slouken@1895
   373
slouken@1895
   374
    if (colors != (palette->colors + firstcolor)) {
slouken@1895
   375
        SDL_memcpy(palette->colors + firstcolor, colors,
slouken@1895
   376
                   ncolors * sizeof(*colors));
slouken@1895
   377
    }
slouken@1895
   378
slouken@1895
   379
    for (watch = palette->watch; watch; watch = watch->next) {
slouken@1895
   380
        if (watch->callback(watch->userdata, palette) < 0) {
slouken@1895
   381
            status = -1;
slouken@1895
   382
        }
slouken@1895
   383
    }
slouken@1895
   384
slouken@1895
   385
    return status;
slouken@1895
   386
}
slouken@1895
   387
slouken@1895
   388
void
slouken@1895
   389
SDL_FreePalette(SDL_Palette * palette)
slouken@1895
   390
{
slouken@1895
   391
    if (!palette) {
slouken@1895
   392
        return;
slouken@1895
   393
    }
slouken@1895
   394
    if (--palette->refcount > 0) {
slouken@1895
   395
        return;
slouken@1895
   396
    }
slouken@1895
   397
    if (palette->colors) {
slouken@1895
   398
        SDL_free(palette->colors);
slouken@1895
   399
    }
slouken@1895
   400
    SDL_free(palette);
slouken@1895
   401
}
slouken@1895
   402
slouken@0
   403
/*
slouken@0
   404
 * Allocate a pixel format structure and fill it according to the given info.
slouken@0
   405
 */
slouken@1895
   406
SDL_PixelFormat *
slouken@1895
   407
SDL_AllocFormat(int bpp,
slouken@1895
   408
                Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
slouken@0
   409
{
slouken@1895
   410
    SDL_PixelFormat *format;
slouken@0
   411
slouken@1895
   412
    /* Allocate an empty pixel format structure */
slouken@2967
   413
    format = SDL_malloc(sizeof(*format));
slouken@1895
   414
    if (format == NULL) {
slouken@1895
   415
        SDL_OutOfMemory();
slouken@1895
   416
        return (NULL);
slouken@1895
   417
    }
slouken@0
   418
slouken@1895
   419
    /* Set up the format */
slouken@2967
   420
    return SDL_InitFormat(format, bpp, Rmask, Gmask, Bmask, Amask);
slouken@2967
   421
}
slouken@2967
   422
slouken@2967
   423
SDL_PixelFormat *
slouken@2990
   424
SDL_InitFormat(SDL_PixelFormat * format, int bpp, Uint32 Rmask, Uint32 Gmask,
slouken@2990
   425
               Uint32 Bmask, Uint32 Amask)
slouken@2967
   426
{
slouken@2967
   427
    Uint32 mask;
slouken@2967
   428
slouken@2967
   429
    /* Set up the format */
slouken@2967
   430
    SDL_zerop(format);
slouken@1895
   431
    format->BitsPerPixel = bpp;
slouken@1895
   432
    format->BytesPerPixel = (bpp + 7) / 8;
slouken@1895
   433
    if (Rmask || Bmask || Gmask) {      /* Packed pixels with custom mask */
slouken@1895
   434
        format->Rshift = 0;
slouken@1895
   435
        format->Rloss = 8;
slouken@1895
   436
        if (Rmask) {
slouken@1895
   437
            for (mask = Rmask; !(mask & 0x01); mask >>= 1)
slouken@1895
   438
                ++format->Rshift;
slouken@1895
   439
            for (; (mask & 0x01); mask >>= 1)
slouken@1895
   440
                --format->Rloss;
slouken@1895
   441
        }
slouken@1895
   442
        format->Gshift = 0;
slouken@1895
   443
        format->Gloss = 8;
slouken@1895
   444
        if (Gmask) {
slouken@1895
   445
            for (mask = Gmask; !(mask & 0x01); mask >>= 1)
slouken@1895
   446
                ++format->Gshift;
slouken@1895
   447
            for (; (mask & 0x01); mask >>= 1)
slouken@1895
   448
                --format->Gloss;
slouken@1895
   449
        }
slouken@1895
   450
        format->Bshift = 0;
slouken@1895
   451
        format->Bloss = 8;
slouken@1895
   452
        if (Bmask) {
slouken@1895
   453
            for (mask = Bmask; !(mask & 0x01); mask >>= 1)
slouken@1895
   454
                ++format->Bshift;
slouken@1895
   455
            for (; (mask & 0x01); mask >>= 1)
slouken@1895
   456
                --format->Bloss;
slouken@1895
   457
        }
slouken@1895
   458
        format->Ashift = 0;
slouken@1895
   459
        format->Aloss = 8;
slouken@1895
   460
        if (Amask) {
slouken@1895
   461
            for (mask = Amask; !(mask & 0x01); mask >>= 1)
slouken@1895
   462
                ++format->Ashift;
slouken@1895
   463
            for (; (mask & 0x01); mask >>= 1)
slouken@1895
   464
                --format->Aloss;
slouken@1895
   465
        }
slouken@1895
   466
        format->Rmask = Rmask;
slouken@1895
   467
        format->Gmask = Gmask;
slouken@1895
   468
        format->Bmask = Bmask;
slouken@1895
   469
        format->Amask = Amask;
slouken@1895
   470
    } else if (bpp > 8) {       /* Packed pixels with standard mask */
slouken@1895
   471
        /* R-G-B */
slouken@1895
   472
        if (bpp > 24)
slouken@1895
   473
            bpp = 24;
slouken@1895
   474
        format->Rloss = 8 - (bpp / 3);
slouken@1895
   475
        format->Gloss = 8 - (bpp / 3) - (bpp % 3);
slouken@1895
   476
        format->Bloss = 8 - (bpp / 3);
slouken@1895
   477
        format->Rshift = ((bpp / 3) + (bpp % 3)) + (bpp / 3);
slouken@1895
   478
        format->Gshift = (bpp / 3);
slouken@1895
   479
        format->Bshift = 0;
slouken@1895
   480
        format->Rmask = ((0xFF >> format->Rloss) << format->Rshift);
slouken@1895
   481
        format->Gmask = ((0xFF >> format->Gloss) << format->Gshift);
slouken@1895
   482
        format->Bmask = ((0xFF >> format->Bloss) << format->Bshift);
slouken@1895
   483
    } else {
slouken@1895
   484
        /* Palettized formats have no mask info */
slouken@1895
   485
        format->Rloss = 8;
slouken@1895
   486
        format->Gloss = 8;
slouken@1895
   487
        format->Bloss = 8;
slouken@1895
   488
        format->Aloss = 8;
slouken@1895
   489
        format->Rshift = 0;
slouken@1895
   490
        format->Gshift = 0;
slouken@1895
   491
        format->Bshift = 0;
slouken@1895
   492
        format->Ashift = 0;
slouken@1895
   493
        format->Rmask = 0;
slouken@1895
   494
        format->Gmask = 0;
slouken@1895
   495
        format->Bmask = 0;
slouken@1895
   496
        format->Amask = 0;
slouken@1895
   497
    }
slouken@1895
   498
    format->palette = NULL;
slouken@1057
   499
slouken@2967
   500
    return format;
slouken@0
   501
}
slouken@0
   502
slouken@0
   503
/*
slouken@0
   504
 * Change any previous mappings from/to the new surface format
slouken@0
   505
 */
slouken@1895
   506
void
slouken@1895
   507
SDL_FormatChanged(SDL_Surface * surface)
slouken@0
   508
{
slouken@1895
   509
    static int format_version = 0;
slouken@1895
   510
    ++format_version;
slouken@1895
   511
    if (format_version < 0) {   /* It wrapped... */
slouken@1895
   512
        format_version = 1;
slouken@1895
   513
    }
slouken@1895
   514
    surface->format_version = format_version;
slouken@1895
   515
    SDL_InvalidateMap(surface->map);
slouken@0
   516
}
slouken@1895
   517
slouken@0
   518
/*
slouken@0
   519
 * Free a previously allocated format structure
slouken@0
   520
 */
slouken@1895
   521
void
slouken@1895
   522
SDL_FreeFormat(SDL_PixelFormat * format)
slouken@0
   523
{
slouken@1895
   524
    if (!format) {
slouken@1895
   525
        return;
slouken@1895
   526
    }
slouken@1895
   527
    SDL_free(format);
slouken@0
   528
}
slouken@1895
   529
slouken@0
   530
/*
slouken@0
   531
 * Calculate an 8-bit (3 red, 3 green, 2 blue) dithered palette of colors
slouken@0
   532
 */
slouken@1895
   533
void
slouken@1895
   534
SDL_DitherColors(SDL_Color * colors, int bpp)
slouken@0
   535
{
slouken@1895
   536
    int i;
slouken@1895
   537
    if (bpp != 8)
slouken@1895
   538
        return;                 /* only 8bpp supported right now */
slouken@0
   539
slouken@1895
   540
    for (i = 0; i < 256; i++) {
slouken@1895
   541
        int r, g, b;
slouken@1895
   542
        /* map each bit field to the full [0, 255] interval,
slouken@1895
   543
           so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */
slouken@1895
   544
        r = i & 0xe0;
slouken@1895
   545
        r |= r >> 3 | r >> 6;
slouken@1895
   546
        colors[i].r = r;
slouken@1895
   547
        g = (i << 3) & 0xe0;
slouken@1895
   548
        g |= g >> 3 | g >> 6;
slouken@1895
   549
        colors[i].g = g;
slouken@1895
   550
        b = i & 0x3;
slouken@1895
   551
        b |= b << 2;
slouken@1895
   552
        b |= b << 4;
slouken@1895
   553
        colors[i].b = b;
slouken@1895
   554
        colors[i].unused = SDL_ALPHA_OPAQUE;
slouken@1895
   555
    }
slouken@0
   556
}
slouken@1895
   557
slouken@0
   558
/* 
slouken@0
   559
 * Calculate the pad-aligned scanline width of a surface
slouken@0
   560
 */
slouken@1895
   561
int
slouken@1895
   562
SDL_CalculatePitch(SDL_Surface * surface)
slouken@0
   563
{
slouken@1895
   564
    int pitch;
slouken@0
   565
slouken@1895
   566
    /* Surface should be 4-byte aligned for speed */
slouken@1895
   567
    pitch = surface->w * surface->format->BytesPerPixel;
slouken@1895
   568
    switch (surface->format->BitsPerPixel) {
slouken@1895
   569
    case 1:
slouken@1895
   570
        pitch = (pitch + 7) / 8;
slouken@1895
   571
        break;
slouken@1895
   572
    case 4:
slouken@1895
   573
        pitch = (pitch + 1) / 2;
slouken@1895
   574
        break;
slouken@1895
   575
    default:
slouken@1895
   576
        break;
slouken@1895
   577
    }
slouken@1895
   578
    pitch = (pitch + 3) & ~3;   /* 4-byte aligning */
slouken@1895
   579
    return (pitch);
slouken@0
   580
}
slouken@1895
   581
slouken@0
   582
/*
slouken@0
   583
 * Match an RGB value to a particular palette index
slouken@0
   584
 */
slouken@1895
   585
Uint8
slouken@1895
   586
SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b)
slouken@0
   587
{
slouken@1895
   588
    /* Do colorspace distance matching */
slouken@1895
   589
    unsigned int smallest;
slouken@1895
   590
    unsigned int distance;
slouken@1895
   591
    int rd, gd, bd;
slouken@1895
   592
    int i;
slouken@1895
   593
    Uint8 pixel = 0;
slouken@1895
   594
slouken@1895
   595
    smallest = ~0;
slouken@1895
   596
    for (i = 0; i < pal->ncolors; ++i) {
slouken@1895
   597
        rd = pal->colors[i].r - r;
slouken@1895
   598
        gd = pal->colors[i].g - g;
slouken@1895
   599
        bd = pal->colors[i].b - b;
slouken@1895
   600
        distance = (rd * rd) + (gd * gd) + (bd * bd);
slouken@1895
   601
        if (distance < smallest) {
slouken@1895
   602
            pixel = i;
slouken@1895
   603
            if (distance == 0) {        /* Perfect match! */
slouken@1895
   604
                break;
slouken@1895
   605
            }
slouken@1895
   606
            smallest = distance;
slouken@1895
   607
        }
slouken@1895
   608
    }
slouken@1895
   609
    return (pixel);
slouken@0
   610
}
slouken@0
   611
slouken@0
   612
/* Find the opaque pixel value corresponding to an RGB triple */
slouken@1895
   613
Uint32
slouken@2275
   614
SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b)
slouken@0
   615
{
slouken@1895
   616
    if (format->palette == NULL) {
slouken@1895
   617
        return (r >> format->Rloss) << format->Rshift
slouken@1895
   618
            | (g >> format->Gloss) << format->Gshift
slouken@1895
   619
            | (b >> format->Bloss) << format->Bshift | format->Amask;
slouken@1895
   620
    } else {
slouken@1895
   621
        return SDL_FindColor(format->palette, r, g, b);
slouken@1895
   622
    }
slouken@0
   623
}
slouken@0
   624
slouken@0
   625
/* Find the pixel value corresponding to an RGBA quadruple */
slouken@1895
   626
Uint32
slouken@2275
   627
SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b,
slouken@2275
   628
            Uint8 a)
slouken@0
   629
{
slouken@1895
   630
    if (format->palette == NULL) {
slouken@1895
   631
        return (r >> format->Rloss) << format->Rshift
slouken@1895
   632
            | (g >> format->Gloss) << format->Gshift
slouken@1895
   633
            | (b >> format->Bloss) << format->Bshift
slouken@1895
   634
            | ((a >> format->Aloss) << format->Ashift & format->Amask);
slouken@1895
   635
    } else {
slouken@1895
   636
        return SDL_FindColor(format->palette, r, g, b);
slouken@1895
   637
    }
slouken@0
   638
}
slouken@0
   639
slouken@1895
   640
void
slouken@2275
   641
SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g,
slouken@2275
   642
           Uint8 * b)
slouken@2275
   643
{
slouken@2275
   644
    if (format->palette == NULL) {
slouken@2275
   645
        /*
slouken@2275
   646
         * This makes sure that the result is mapped to the
slouken@2275
   647
         * interval [0..255], and the maximum value for each
slouken@2275
   648
         * component is 255. This is important to make sure
slouken@2275
   649
         * that white is indeed reported as (255, 255, 255).
slouken@2275
   650
         * This only works for RGB bit fields at least 4 bit
slouken@2275
   651
         * wide, which is almost always the case.
slouken@2275
   652
         */
slouken@2275
   653
        unsigned v;
slouken@2275
   654
        v = (pixel & format->Rmask) >> format->Rshift;
slouken@2275
   655
        *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1)));
slouken@2275
   656
        v = (pixel & format->Gmask) >> format->Gshift;
slouken@2275
   657
        *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1)));
slouken@2275
   658
        v = (pixel & format->Bmask) >> format->Bshift;
slouken@2275
   659
        *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1)));
slouken@2275
   660
    } else {
slouken@2275
   661
        *r = format->palette->colors[pixel].r;
slouken@2275
   662
        *g = format->palette->colors[pixel].g;
slouken@2275
   663
        *b = format->palette->colors[pixel].b;
slouken@2275
   664
    }
slouken@2275
   665
}
slouken@2275
   666
slouken@2275
   667
void
slouken@2275
   668
SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
slouken@1895
   669
            Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
slouken@0
   670
{
slouken@2275
   671
    if (format->palette == NULL) {
slouken@1895
   672
        /*
slouken@1895
   673
         * This makes sure that the result is mapped to the
slouken@1895
   674
         * interval [0..255], and the maximum value for each
slouken@1895
   675
         * component is 255. This is important to make sure
slouken@1895
   676
         * that white is indeed reported as (255, 255, 255),
slouken@1895
   677
         * and that opaque alpha is 255.
slouken@1895
   678
         * This only works for RGB bit fields at least 4 bit
slouken@1895
   679
         * wide, which is almost always the case.
slouken@1895
   680
         */
slouken@1895
   681
        unsigned v;
slouken@2275
   682
        v = (pixel & format->Rmask) >> format->Rshift;
slouken@2275
   683
        *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1)));
slouken@2275
   684
        v = (pixel & format->Gmask) >> format->Gshift;
slouken@2275
   685
        *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1)));
slouken@2275
   686
        v = (pixel & format->Bmask) >> format->Bshift;
slouken@2275
   687
        *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1)));
slouken@2275
   688
        if (format->Amask) {
slouken@2275
   689
            v = (pixel & format->Amask) >> format->Ashift;
slouken@2275
   690
            *a = (v << format->Aloss) + (v >> (8 - (format->Aloss << 1)));
slouken@1895
   691
        } else {
slouken@1895
   692
            *a = SDL_ALPHA_OPAQUE;
slouken@1895
   693
        }
slouken@1895
   694
    } else {
slouken@2275
   695
        *r = format->palette->colors[pixel].r;
slouken@2275
   696
        *g = format->palette->colors[pixel].g;
slouken@2275
   697
        *b = format->palette->colors[pixel].b;
slouken@1895
   698
        *a = SDL_ALPHA_OPAQUE;
slouken@1895
   699
    }
slouken@0
   700
}
slouken@0
   701
slouken@0
   702
/* Apply gamma to a set of colors - this is easy. :) */
slouken@1895
   703
void
slouken@1895
   704
SDL_ApplyGamma(Uint16 * gamma, SDL_Color * colors, SDL_Color * output,
slouken@1895
   705
               int ncolors)
slouken@0
   706
{
slouken@1895
   707
    int i;
slouken@0
   708
slouken@1895
   709
    for (i = 0; i < ncolors; ++i) {
slouken@1895
   710
        output[i].r = gamma[0 * 256 + colors[i].r] >> 8;
slouken@1895
   711
        output[i].g = gamma[1 * 256 + colors[i].g] >> 8;
slouken@1895
   712
        output[i].b = gamma[2 * 256 + colors[i].b] >> 8;
slouken@1895
   713
    }
slouken@0
   714
}
slouken@0
   715
slouken@0
   716
/* Map from Palette to Palette */
slouken@1895
   717
static Uint8 *
slouken@1895
   718
Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical)
slouken@0
   719
{
slouken@1895
   720
    Uint8 *map;
slouken@1895
   721
    int i;
slouken@0
   722
slouken@1895
   723
    if (identical) {
slouken@1895
   724
        if (src->ncolors <= dst->ncolors) {
slouken@1895
   725
            /* If an identical palette, no need to map */
slouken@1895
   726
            if (src == dst
slouken@1895
   727
                ||
slouken@1895
   728
                (SDL_memcmp
slouken@1895
   729
                 (src->colors, dst->colors,
slouken@1895
   730
                  src->ncolors * sizeof(SDL_Color)) == 0)) {
slouken@1895
   731
                *identical = 1;
slouken@1895
   732
                return (NULL);
slouken@1895
   733
            }
slouken@1895
   734
        }
slouken@1895
   735
        *identical = 0;
slouken@1895
   736
    }
slouken@1895
   737
    map = (Uint8 *) SDL_malloc(src->ncolors);
slouken@1895
   738
    if (map == NULL) {
slouken@1895
   739
        SDL_OutOfMemory();
slouken@1895
   740
        return (NULL);
slouken@1895
   741
    }
slouken@1895
   742
    for (i = 0; i < src->ncolors; ++i) {
slouken@1895
   743
        map[i] = SDL_FindColor(dst,
slouken@1895
   744
                               src->colors[i].r, src->colors[i].g,
slouken@1895
   745
                               src->colors[i].b);
slouken@1895
   746
    }
slouken@1895
   747
    return (map);
slouken@0
   748
}
slouken@0
   749
slouken@1895
   750
/* Map from Palette to BitField */
slouken@1895
   751
static Uint8 *
slouken@2267
   752
Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod,
slouken@2267
   753
        SDL_PixelFormat * dst)
slouken@0
   754
{
slouken@1895
   755
    Uint8 *map;
slouken@1895
   756
    int i;
slouken@1895
   757
    int bpp;
slouken@1895
   758
    SDL_Palette *pal = src->palette;
slouken@0
   759
slouken@1895
   760
    bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
slouken@1895
   761
    map = (Uint8 *) SDL_malloc(pal->ncolors * bpp);
slouken@1895
   762
    if (map == NULL) {
slouken@1895
   763
        SDL_OutOfMemory();
slouken@1895
   764
        return (NULL);
slouken@1895
   765
    }
slouken@0
   766
slouken@1895
   767
    /* We memory copy to the pixel map so the endianness is preserved */
slouken@1895
   768
    for (i = 0; i < pal->ncolors; ++i) {
slouken@2257
   769
        Uint8 A = Amod;
slouken@2267
   770
        Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255);
slouken@2267
   771
        Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255);
slouken@2267
   772
        Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255);
slouken@2257
   773
        ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A);
slouken@1895
   774
    }
slouken@1895
   775
    return (map);
slouken@1895
   776
}
slouken@0
   777
slouken@1895
   778
/* Map from BitField to Dithered-Palette to Palette */
slouken@1895
   779
static Uint8 *
slouken@1895
   780
MapNto1(SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical)
slouken@1895
   781
{
slouken@1895
   782
    /* Generate a 256 color dither palette */
slouken@1895
   783
    SDL_Palette dithered;
slouken@1895
   784
    SDL_Color colors[256];
slouken@1895
   785
    SDL_Palette *pal = dst->palette;
slouken@1895
   786
slouken@1895
   787
    dithered.ncolors = 256;
slouken@1895
   788
    SDL_DitherColors(colors, 8);
slouken@1895
   789
    dithered.colors = colors;
slouken@1895
   790
    return (Map1to1(&dithered, pal, identical));
slouken@0
   791
}
slouken@1895
   792
slouken@1895
   793
SDL_BlitMap *
slouken@1895
   794
SDL_AllocBlitMap(void)
slouken@0
   795
{
slouken@1895
   796
    SDL_BlitMap *map;
slouken@1895
   797
slouken@1895
   798
    /* Allocate the empty map */
slouken@1920
   799
    map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map));
slouken@1895
   800
    if (map == NULL) {
slouken@1895
   801
        SDL_OutOfMemory();
slouken@1895
   802
        return (NULL);
slouken@1895
   803
    }
slouken@2267
   804
    map->info.r = 0xFF;
slouken@2267
   805
    map->info.g = 0xFF;
slouken@2267
   806
    map->info.b = 0xFF;
slouken@2267
   807
    map->info.a = 0xFF;
slouken@1895
   808
slouken@1895
   809
    /* It's ready to go */
slouken@1895
   810
    return (map);
slouken@0
   811
}
slouken@1895
   812
slouken@1895
   813
void
slouken@1895
   814
SDL_InvalidateMap(SDL_BlitMap * map)
slouken@0
   815
{
slouken@1895
   816
    if (!map) {
slouken@1895
   817
        return;
slouken@1895
   818
    }
slouken@1895
   819
    map->dst = NULL;
slouken@1895
   820
    map->format_version = (unsigned int) -1;
slouken@2267
   821
    if (map->info.table) {
slouken@2267
   822
        SDL_free(map->info.table);
slouken@2267
   823
        map->info.table = NULL;
slouken@1895
   824
    }
slouken@1895
   825
}
slouken@2735
   826
slouken@1895
   827
int
slouken@1895
   828
SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
slouken@1895
   829
{
slouken@1895
   830
    SDL_PixelFormat *srcfmt;
slouken@1895
   831
    SDL_PixelFormat *dstfmt;
slouken@1895
   832
    SDL_BlitMap *map;
slouken@0
   833
slouken@1895
   834
    /* Clear out any previous mapping */
slouken@1895
   835
    map = src->map;
slouken@1895
   836
    if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
slouken@1895
   837
        SDL_UnRLESurface(src, 1);
slouken@1895
   838
    }
slouken@1895
   839
    SDL_InvalidateMap(map);
slouken@0
   840
slouken@1895
   841
    /* Figure out what kind of mapping we're doing */
slouken@1895
   842
    map->identity = 0;
slouken@1895
   843
    srcfmt = src->format;
slouken@1895
   844
    dstfmt = dst->format;
slouken@1895
   845
    switch (srcfmt->BytesPerPixel) {
slouken@1895
   846
    case 1:
slouken@1895
   847
        switch (dstfmt->BytesPerPixel) {
slouken@1895
   848
        case 1:
slouken@1895
   849
            /* Palette --> Palette */
slouken@2267
   850
            map->info.table =
slouken@1895
   851
                Map1to1(srcfmt->palette, dstfmt->palette, &map->identity);
slouken@1895
   852
            if (!map->identity) {
slouken@2267
   853
                if (map->info.table == NULL) {
slouken@1895
   854
                    return (-1);
slouken@1895
   855
                }
slouken@1895
   856
            }
slouken@1895
   857
            if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel)
slouken@1895
   858
                map->identity = 0;
slouken@1895
   859
            break;
slouken@0
   860
slouken@1895
   861
        default:
slouken@1895
   862
            /* Palette --> BitField */
slouken@2267
   863
            map->info.table =
slouken@2267
   864
                Map1toN(srcfmt, src->map->info.r, src->map->info.g,
slouken@2267
   865
                        src->map->info.b, src->map->info.a, dstfmt);
slouken@2267
   866
            if (map->info.table == NULL) {
slouken@1895
   867
                return (-1);
slouken@1895
   868
            }
slouken@1895
   869
            break;
slouken@1895
   870
        }
slouken@1895
   871
        break;
slouken@1895
   872
    default:
slouken@1895
   873
        switch (dstfmt->BytesPerPixel) {
slouken@1895
   874
        case 1:
slouken@1895
   875
            /* BitField --> Palette */
slouken@2267
   876
            map->info.table = MapNto1(srcfmt, dstfmt, &map->identity);
slouken@1895
   877
            if (!map->identity) {
slouken@2267
   878
                if (map->info.table == NULL) {
slouken@1895
   879
                    return (-1);
slouken@1895
   880
                }
slouken@1895
   881
            }
slouken@1895
   882
            map->identity = 0;  /* Don't optimize to copy */
slouken@1895
   883
            break;
slouken@1895
   884
        default:
slouken@1895
   885
            /* BitField --> BitField */
slouken@1895
   886
            if (FORMAT_EQUAL(srcfmt, dstfmt))
slouken@1895
   887
                map->identity = 1;
slouken@1895
   888
            break;
slouken@1895
   889
        }
slouken@1895
   890
        break;
slouken@1895
   891
    }
slouken@0
   892
slouken@1895
   893
    map->dst = dst;
slouken@1895
   894
    map->format_version = dst->format_version;
slouken@0
   895
slouken@1895
   896
    /* Choose your blitters wisely */
slouken@1895
   897
    return (SDL_CalculateBlit(src));
slouken@0
   898
}
slouken@1895
   899
slouken@1895
   900
void
slouken@1895
   901
SDL_FreeBlitMap(SDL_BlitMap * map)
slouken@0
   902
{
slouken@1895
   903
    if (map) {
slouken@1895
   904
        SDL_InvalidateMap(map);
slouken@1895
   905
        SDL_free(map);
slouken@1895
   906
    }
slouken@0
   907
}
slouken@1895
   908
slouken@1895
   909
/* vi: set ts=4 sw=4 expandtab: */