src/video/SDL_surface.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 14 Jun 2006 06:14:26 +0000
branchSDL-1.3
changeset 1678 90bf530ced8e
parent 1672 8e754b82cecc
child 1682 7ae8018b2e5d
permissions -rw-r--r--
SDL_SetVideoMode() compiles now...
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 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
#include "SDL_video.h"
slouken@1672
    25
#include "SDL_compat.h"
slouken@0
    26
#include "SDL_sysvideo.h"
slouken@0
    27
#include "SDL_blit.h"
slouken@0
    28
#include "SDL_RLEaccel_c.h"
slouken@0
    29
#include "SDL_pixels_c.h"
slouken@0
    30
#include "SDL_leaks.h"
slouken@0
    31
icculus@1251
    32
slouken@0
    33
/* Public routines */
slouken@0
    34
/*
slouken@0
    35
 * Create an empty RGB surface of the appropriate depth
slouken@0
    36
 */
slouken@1662
    37
SDL_Surface *
slouken@1668
    38
SDL_CreateRGBSurface(Uint32 flags,
slouken@1668
    39
                     int width, int height, int depth,
slouken@1668
    40
                     Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
slouken@0
    41
{
slouken@1668
    42
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1662
    43
    SDL_Surface *screen;
slouken@1662
    44
    SDL_Surface *surface;
slouken@0
    45
slouken@1670
    46
    /* FIXME!! */
slouken@1662
    47
    /* Make sure the size requested doesn't overflow our datatypes */
slouken@1662
    48
    /* Next time I write a library like SDL, I'll use int for size. :) */
slouken@1662
    49
    if (width >= 16384 || height >= 65536) {
slouken@1668
    50
        SDL_SetError("Width or height is too large");
slouken@1662
    51
        return (NULL);
slouken@1662
    52
    }
slouken@940
    53
slouken@1662
    54
    /* Allocate the surface */
slouken@1668
    55
    surface = (SDL_Surface *) SDL_malloc(sizeof(*surface));
slouken@1662
    56
    if (surface == NULL) {
slouken@1668
    57
        SDL_OutOfMemory();
slouken@1662
    58
        return (NULL);
slouken@1662
    59
    }
slouken@1670
    60
    surface->flags = 0;
slouken@1668
    61
    surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask);
slouken@1662
    62
    if (surface->format == NULL) {
slouken@1668
    63
        SDL_free(surface);
slouken@1662
    64
        return (NULL);
slouken@1662
    65
    }
slouken@1662
    66
    if (Amask) {
slouken@1662
    67
        surface->flags |= SDL_SRCALPHA;
slouken@1662
    68
    }
slouken@1662
    69
    surface->w = width;
slouken@1662
    70
    surface->h = height;
slouken@1668
    71
    surface->pitch = SDL_CalculatePitch(surface);
slouken@1662
    72
    surface->pixels = NULL;
slouken@1662
    73
    surface->locked = 0;
slouken@1662
    74
    surface->map = NULL;
slouken@1668
    75
    SDL_SetClipRect(surface, NULL);
slouken@1668
    76
    SDL_FormatChanged(surface);
slouken@0
    77
slouken@1662
    78
    /* Get the pixels */
slouken@1670
    79
    if (surface->w && surface->h) {
slouken@1670
    80
        surface->pixels = SDL_malloc(surface->h * surface->pitch);
slouken@1670
    81
        if (surface->pixels == NULL) {
slouken@1670
    82
            SDL_FreeSurface(surface);
slouken@1670
    83
            SDL_OutOfMemory();
slouken@1670
    84
            return NULL;
slouken@1662
    85
        }
slouken@1670
    86
        /* This is important for bitmaps */
slouken@1670
    87
        SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
slouken@1662
    88
    }
slouken@0
    89
slouken@1662
    90
    /* Allocate an empty mapping */
slouken@1668
    91
    surface->map = SDL_AllocBlitMap();
slouken@1662
    92
    if (surface->map == NULL) {
slouken@1668
    93
        SDL_FreeSurface(surface);
slouken@1662
    94
        return (NULL);
slouken@1662
    95
    }
slouken@0
    96
slouken@1662
    97
    /* The surface is ready to go */
slouken@1662
    98
    surface->refcount = 1;
slouken@0
    99
#ifdef CHECK_LEAKS
slouken@1662
   100
    ++surfaces_allocated;
slouken@0
   101
#endif
slouken@1662
   102
    return (surface);
slouken@0
   103
}
slouken@1662
   104
slouken@0
   105
/*
slouken@0
   106
 * Create an RGB surface from an existing memory buffer
slouken@0
   107
 */
slouken@1662
   108
SDL_Surface *
slouken@1668
   109
SDL_CreateRGBSurfaceFrom(void *pixels,
slouken@1668
   110
                         int width, int height, int depth, int pitch,
slouken@1668
   111
                         Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
slouken@1668
   112
                         Uint32 Amask)
slouken@0
   113
{
slouken@1662
   114
    SDL_Surface *surface;
slouken@0
   115
slouken@1672
   116
    surface =
slouken@1672
   117
        SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask);
slouken@1662
   118
    if (surface != NULL) {
slouken@1662
   119
        surface->flags |= SDL_PREALLOC;
slouken@1662
   120
        surface->pixels = pixels;
slouken@1662
   121
        surface->w = width;
slouken@1662
   122
        surface->h = height;
slouken@1662
   123
        surface->pitch = pitch;
slouken@1668
   124
        SDL_SetClipRect(surface, NULL);
slouken@1662
   125
    }
slouken@1670
   126
    return surface;
slouken@1670
   127
}
slouken@1670
   128
slouken@1670
   129
SDL_Surface *
slouken@1670
   130
SDL_CreateRGBSurfaceFromTexture(SDL_TextureID textureID)
slouken@1670
   131
{
slouken@1670
   132
    SDL_Surface *surface;
slouken@1670
   133
    Uint32 format;
slouken@1670
   134
    int w, h;
slouken@1670
   135
    int bpp;
slouken@1670
   136
    Uint32 Rmask, Gmask, Bmask, Amask;
slouken@1678
   137
    void *pixels;
slouken@1678
   138
    int pitch;
slouken@1670
   139
slouken@1670
   140
    if (SDL_QueryTexture(textureID, &format, NULL, &w, &h) < 0) {
slouken@1670
   141
        return NULL;
slouken@1670
   142
    }
slouken@1670
   143
slouken@1670
   144
    if (!SDL_PixelFormatEnumToMasks
slouken@1670
   145
        (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
slouken@1670
   146
        SDL_SetError("Unknown texture format");
slouken@1670
   147
        return NULL;
slouken@1670
   148
    }
slouken@1670
   149
slouken@1678
   150
    if (SDL_QueryTexturePixels(textureID, &pixels, &pitch) == 0) {
slouken@1678
   151
        surface =
slouken@1678
   152
            SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, Gmask,
slouken@1678
   153
                                     Bmask, Amask);
slouken@1678
   154
    } else {
slouken@1678
   155
        surface =
slouken@1678
   156
            SDL_CreateRGBSurface(0, 0, 0, bpp, Rmask, Gmask, Bmask, Amask);
slouken@1678
   157
        if (surface) {
slouken@1678
   158
            surface->flags |= SDL_HWSURFACE;
slouken@1678
   159
            surface->w = w;
slouken@1678
   160
            surface->h = h;
slouken@1678
   161
            surface->lock_data = (void *) textureID;
slouken@1678
   162
            SDL_SetClipRect(surface, NULL);
slouken@1678
   163
        }
slouken@1670
   164
    }
slouken@1678
   165
slouken@1670
   166
    return surface;
slouken@1670
   167
}
slouken@1670
   168
slouken@1670
   169
/*
slouken@1670
   170
 * Set the palette in a blittable surface
slouken@1670
   171
 */
slouken@1670
   172
int
slouken@1670
   173
SDL_SetColors(SDL_Surface * surface, SDL_Color * colors, int firstcolor,
slouken@1670
   174
              int ncolors)
slouken@1670
   175
{
slouken@1670
   176
    SDL_Palette *pal;
slouken@1670
   177
    int gotall;
slouken@1670
   178
    int palsize;
slouken@1670
   179
slouken@1670
   180
    /* Verify the parameters */
slouken@1670
   181
    pal = surface->format->palette;
slouken@1670
   182
    if (!pal) {
slouken@1670
   183
        return 0;               /* not a palettized surface */
slouken@1670
   184
    }
slouken@1670
   185
    gotall = 1;
slouken@1670
   186
    palsize = 1 << surface->format->BitsPerPixel;
slouken@1670
   187
    if (ncolors > (palsize - firstcolor)) {
slouken@1670
   188
        ncolors = (palsize - firstcolor);
slouken@1670
   189
        gotall = 0;
slouken@1670
   190
    }
slouken@1670
   191
slouken@1670
   192
    if (colors != (pal->colors + firstcolor)) {
slouken@1670
   193
        SDL_memcpy(pal->colors + firstcolor, colors,
slouken@1670
   194
                   ncolors * sizeof(*colors));
slouken@1670
   195
    }
slouken@1670
   196
    SDL_FormatChanged(surface);
slouken@1670
   197
slouken@1670
   198
    if (surface->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) {
slouken@1670
   199
        gotall &= SDL_SetScreenColors(surface, colors, firstcolor, ncolors);
slouken@1670
   200
    }
slouken@1670
   201
    return gotall;
slouken@0
   202
}
slouken@1662
   203
slouken@0
   204
/*
slouken@0
   205
 * Set the color key in a blittable surface
slouken@0
   206
 */
slouken@1662
   207
int
slouken@1668
   208
SDL_SetColorKey(SDL_Surface * surface, Uint32 flag, Uint32 key)
slouken@0
   209
{
slouken@1662
   210
    /* Sanity check the flag as it gets passed in */
slouken@1662
   211
    if (flag & SDL_SRCCOLORKEY) {
slouken@1662
   212
        if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) {
slouken@1662
   213
            flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
slouken@1662
   214
        } else {
slouken@1662
   215
            flag = SDL_SRCCOLORKEY;
slouken@1662
   216
        }
slouken@1662
   217
    } else {
slouken@1662
   218
        flag = 0;
slouken@1662
   219
    }
slouken@0
   220
slouken@1662
   221
    /* Optimize away operations that don't change anything */
slouken@1662
   222
    if ((flag == (surface->flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK))) &&
slouken@1662
   223
        (key == surface->format->colorkey)) {
slouken@1662
   224
        return (0);
slouken@1662
   225
    }
slouken@0
   226
slouken@1662
   227
    /* UnRLE surfaces before we change the colorkey */
slouken@1662
   228
    if (surface->flags & SDL_RLEACCEL) {
slouken@1668
   229
        SDL_UnRLESurface(surface, 1);
slouken@1662
   230
    }
slouken@0
   231
slouken@1662
   232
    if (flag) {
slouken@1662
   233
        surface->flags |= SDL_SRCCOLORKEY;
slouken@1662
   234
        surface->format->colorkey = key;
slouken@1662
   235
        if (flag & SDL_RLEACCELOK) {
slouken@1662
   236
            surface->flags |= SDL_RLEACCELOK;
slouken@1662
   237
        } else {
slouken@1662
   238
            surface->flags &= ~SDL_RLEACCELOK;
slouken@1662
   239
        }
slouken@1662
   240
    } else {
slouken@1662
   241
        surface->flags &= ~(SDL_SRCCOLORKEY | SDL_RLEACCELOK);
slouken@1662
   242
        surface->format->colorkey = 0;
slouken@1662
   243
    }
slouken@1668
   244
    SDL_InvalidateMap(surface->map);
slouken@1662
   245
    return (0);
slouken@1662
   246
}
slouken@0
   247
slouken@1662
   248
/* This function sets the alpha channel of a surface */
slouken@1662
   249
int
slouken@1668
   250
SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
slouken@1662
   251
{
slouken@1662
   252
    Uint32 oldflags = surface->flags;
slouken@1662
   253
    Uint32 oldalpha = surface->format->alpha;
slouken@1662
   254
slouken@1662
   255
    /* Sanity check the flag as it gets passed in */
slouken@1662
   256
    if (flag & SDL_SRCALPHA) {
slouken@1662
   257
        if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) {
slouken@1662
   258
            flag = (SDL_SRCALPHA | SDL_RLEACCELOK);
slouken@1662
   259
        } else {
slouken@1662
   260
            flag = SDL_SRCALPHA;
slouken@1662
   261
        }
slouken@1662
   262
    } else {
slouken@1662
   263
        flag = 0;
slouken@1662
   264
    }
slouken@1662
   265
slouken@1662
   266
    /* Optimize away operations that don't change anything */
slouken@1662
   267
    if ((flag == (surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK))) &&
slouken@1662
   268
        (!flag || value == oldalpha)) {
slouken@1662
   269
        return (0);
slouken@1662
   270
    }
slouken@1662
   271
slouken@1662
   272
    if (!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL))
slouken@1668
   273
        SDL_UnRLESurface(surface, 1);
slouken@1662
   274
slouken@1662
   275
    if (flag) {
slouken@1662
   276
        surface->flags |= SDL_SRCALPHA;
slouken@1662
   277
        surface->format->alpha = value;
slouken@1662
   278
        if (flag & SDL_RLEACCELOK) {
slouken@1662
   279
            surface->flags |= SDL_RLEACCELOK;
slouken@1662
   280
        } else {
slouken@1662
   281
            surface->flags &= ~SDL_RLEACCELOK;
slouken@1662
   282
        }
slouken@1662
   283
    } else {
slouken@1662
   284
        surface->flags &= ~SDL_SRCALPHA;
slouken@1662
   285
        surface->format->alpha = SDL_ALPHA_OPAQUE;
slouken@1662
   286
    }
slouken@1662
   287
    /*
slouken@1662
   288
     * The representation for software surfaces is independent of
slouken@1662
   289
     * per-surface alpha, so no need to invalidate the blit mapping
slouken@1662
   290
     * if just the alpha value was changed. (If either is 255, we still
slouken@1662
   291
     * need to invalidate.)
slouken@1662
   292
     */
slouken@1672
   293
    if (oldflags != surface->flags
slouken@1672
   294
        || (((oldalpha + 1) ^ (value + 1)) & 0x100)) {
slouken@1668
   295
        SDL_InvalidateMap(surface->map);
slouken@1672
   296
    }
slouken@1662
   297
    return (0);
slouken@0
   298
}
slouken@1662
   299
slouken@1662
   300
int
slouken@1668
   301
SDL_SetAlphaChannel(SDL_Surface * surface, Uint8 value)
slouken@0
   302
{
slouken@1662
   303
    int row, col;
slouken@1662
   304
    int offset;
slouken@1662
   305
    Uint8 *buf;
slouken@0
   306
slouken@1662
   307
    if ((surface->format->Amask != 0xFF000000) &&
slouken@1662
   308
        (surface->format->Amask != 0x000000FF)) {
slouken@1668
   309
        SDL_SetError("Unsupported surface alpha mask format");
slouken@1662
   310
        return -1;
slouken@1662
   311
    }
slouken@431
   312
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@1662
   313
    if (surface->format->Amask == 0xFF000000) {
slouken@1662
   314
        offset = 3;
slouken@1662
   315
    } else {
slouken@1662
   316
        offset = 0;
slouken@1662
   317
    }
slouken@431
   318
#else
slouken@1662
   319
    if (surface->format->Amask == 0xFF000000) {
slouken@1662
   320
        offset = 0;
slouken@1662
   321
    } else {
slouken@1662
   322
        offset = 3;
slouken@1662
   323
    }
slouken@431
   324
#endif /* Byte ordering */
slouken@431
   325
slouken@1662
   326
    /* Quickly set the alpha channel of an RGBA or ARGB surface */
slouken@1668
   327
    if (SDL_MUSTLOCK(surface)) {
slouken@1668
   328
        if (SDL_LockSurface(surface) < 0) {
slouken@1662
   329
            return -1;
slouken@1662
   330
        }
slouken@1662
   331
    }
slouken@1662
   332
    row = surface->h;
slouken@1662
   333
    while (row--) {
slouken@1662
   334
        col = surface->w;
slouken@1662
   335
        buf = (Uint8 *) surface->pixels + row * surface->pitch + offset;
slouken@1662
   336
        while (col--) {
slouken@1662
   337
            *buf = value;
slouken@1662
   338
            buf += 4;
slouken@1662
   339
        }
slouken@1662
   340
    }
slouken@1668
   341
    if (SDL_MUSTLOCK(surface)) {
slouken@1668
   342
        SDL_UnlockSurface(surface);
slouken@1662
   343
    }
slouken@1662
   344
    return 0;
slouken@431
   345
}
slouken@0
   346
slouken@0
   347
/*
slouken@0
   348
 * A function to calculate the intersection of two rectangles:
slouken@0
   349
 * return true if the rectangles intersect, false otherwise
slouken@0
   350
 */
slouken@1662
   351
static __inline__ SDL_bool
slouken@1668
   352
SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B,
slouken@1668
   353
                  SDL_Rect * intersection)
slouken@0
   354
{
slouken@1662
   355
    int Amin, Amax, Bmin, Bmax;
slouken@0
   356
slouken@1662
   357
    /* Horizontal intersection */
slouken@1662
   358
    Amin = A->x;
slouken@1662
   359
    Amax = Amin + A->w;
slouken@1662
   360
    Bmin = B->x;
slouken@1662
   361
    Bmax = Bmin + B->w;
slouken@1662
   362
    if (Bmin > Amin)
slouken@1662
   363
        Amin = Bmin;
slouken@1662
   364
    intersection->x = Amin;
slouken@1662
   365
    if (Bmax < Amax)
slouken@1662
   366
        Amax = Bmax;
slouken@1662
   367
    intersection->w = Amax - Amin > 0 ? Amax - Amin : 0;
slouken@0
   368
slouken@1662
   369
    /* Vertical intersection */
slouken@1662
   370
    Amin = A->y;
slouken@1662
   371
    Amax = Amin + A->h;
slouken@1662
   372
    Bmin = B->y;
slouken@1662
   373
    Bmax = Bmin + B->h;
slouken@1662
   374
    if (Bmin > Amin)
slouken@1662
   375
        Amin = Bmin;
slouken@1662
   376
    intersection->y = Amin;
slouken@1662
   377
    if (Bmax < Amax)
slouken@1662
   378
        Amax = Bmax;
slouken@1662
   379
    intersection->h = Amax - Amin > 0 ? Amax - Amin : 0;
slouken@0
   380
slouken@1662
   381
    return (intersection->w && intersection->h);
slouken@0
   382
}
slouken@1662
   383
slouken@0
   384
/*
slouken@0
   385
 * Set the clipping rectangle for a blittable surface
slouken@0
   386
 */
slouken@1662
   387
SDL_bool
slouken@1668
   388
SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect)
slouken@0
   389
{
slouken@1662
   390
    SDL_Rect full_rect;
slouken@0
   391
slouken@1662
   392
    /* Don't do anything if there's no surface to act on */
slouken@1662
   393
    if (!surface) {
slouken@1662
   394
        return SDL_FALSE;
slouken@1662
   395
    }
slouken@0
   396
slouken@1662
   397
    /* Set up the full surface rectangle */
slouken@1662
   398
    full_rect.x = 0;
slouken@1662
   399
    full_rect.y = 0;
slouken@1662
   400
    full_rect.w = surface->w;
slouken@1662
   401
    full_rect.h = surface->h;
slouken@0
   402
slouken@1662
   403
    /* Set the clipping rectangle */
slouken@1662
   404
    if (!rect) {
slouken@1662
   405
        surface->clip_rect = full_rect;
slouken@1662
   406
        return 1;
slouken@1662
   407
    }
slouken@1668
   408
    return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect);
slouken@0
   409
}
slouken@1662
   410
slouken@1662
   411
void
slouken@1668
   412
SDL_GetClipRect(SDL_Surface * surface, SDL_Rect * rect)
slouken@0
   413
{
slouken@1662
   414
    if (surface && rect) {
slouken@1662
   415
        *rect = surface->clip_rect;
slouken@1662
   416
    }
slouken@0
   417
}
slouken@1662
   418
slouken@0
   419
/* 
slouken@0
   420
 * Set up a blit between two surfaces -- split into three parts:
slouken@0
   421
 * The upper part, SDL_UpperBlit(), performs clipping and rectangle 
slouken@0
   422
 * verification.  The lower part is a pointer to a low level
slouken@0
   423
 * accelerated blitting function.
slouken@0
   424
 *
slouken@0
   425
 * These parts are separated out and each used internally by this 
slouken@0
   426
 * library in the optimimum places.  They are exported so that if
slouken@0
   427
 * you know exactly what you are doing, you can optimize your code
slouken@0
   428
 * by calling the one(s) you need.
slouken@0
   429
 */
slouken@1662
   430
int
slouken@1668
   431
SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect,
slouken@1668
   432
              SDL_Surface * dst, SDL_Rect * dstrect)
slouken@0
   433
{
slouken@1662
   434
    /* Check to make sure the blit mapping is valid */
slouken@1662
   435
    if ((src->map->dst != dst) ||
slouken@1662
   436
        (src->map->dst->format_version != src->map->format_version)) {
slouken@1668
   437
        if (SDL_MapSurface(src, dst) < 0) {
slouken@1662
   438
            return (-1);
slouken@1662
   439
        }
slouken@1662
   440
    }
slouken@1672
   441
    return (src->map->sw_blit(src, srcrect, dst, dstrect));
slouken@0
   442
}
slouken@0
   443
slouken@0
   444
slouken@1662
   445
int
slouken@1668
   446
SDL_UpperBlit(SDL_Surface * src, SDL_Rect * srcrect,
slouken@1668
   447
              SDL_Surface * dst, SDL_Rect * dstrect)
slouken@0
   448
{
slouken@1662
   449
    SDL_Rect fulldst;
slouken@1662
   450
    int srcx, srcy, w, h;
slouken@0
   451
slouken@1662
   452
    /* Make sure the surfaces aren't locked */
slouken@1662
   453
    if (!src || !dst) {
slouken@1668
   454
        SDL_SetError("SDL_UpperBlit: passed a NULL surface");
slouken@1662
   455
        return (-1);
slouken@1662
   456
    }
slouken@1662
   457
    if (src->locked || dst->locked) {
slouken@1668
   458
        SDL_SetError("Surfaces must not be locked during blit");
slouken@1662
   459
        return (-1);
slouken@1662
   460
    }
slouken@0
   461
slouken@1662
   462
    /* If the destination rectangle is NULL, use the entire dest surface */
slouken@1662
   463
    if (dstrect == NULL) {
slouken@1662
   464
        fulldst.x = fulldst.y = 0;
slouken@1662
   465
        dstrect = &fulldst;
slouken@1662
   466
    }
slouken@0
   467
slouken@1662
   468
    /* clip the source rectangle to the source surface */
slouken@1662
   469
    if (srcrect) {
slouken@1662
   470
        int maxw, maxh;
slouken@0
   471
slouken@1662
   472
        srcx = srcrect->x;
slouken@1662
   473
        w = srcrect->w;
slouken@1662
   474
        if (srcx < 0) {
slouken@1662
   475
            w += srcx;
slouken@1662
   476
            dstrect->x -= srcx;
slouken@1662
   477
            srcx = 0;
slouken@1662
   478
        }
slouken@1662
   479
        maxw = src->w - srcx;
slouken@1662
   480
        if (maxw < w)
slouken@1662
   481
            w = maxw;
slouken@0
   482
slouken@1662
   483
        srcy = srcrect->y;
slouken@1662
   484
        h = srcrect->h;
slouken@1662
   485
        if (srcy < 0) {
slouken@1662
   486
            h += srcy;
slouken@1662
   487
            dstrect->y -= srcy;
slouken@1662
   488
            srcy = 0;
slouken@1662
   489
        }
slouken@1662
   490
        maxh = src->h - srcy;
slouken@1662
   491
        if (maxh < h)
slouken@1662
   492
            h = maxh;
slouken@0
   493
slouken@1662
   494
    } else {
slouken@1662
   495
        srcx = srcy = 0;
slouken@1662
   496
        w = src->w;
slouken@1662
   497
        h = src->h;
slouken@1662
   498
    }
slouken@0
   499
slouken@1662
   500
    /* clip the destination rectangle against the clip rectangle */
slouken@1662
   501
    {
slouken@1662
   502
        SDL_Rect *clip = &dst->clip_rect;
slouken@1662
   503
        int dx, dy;
slouken@0
   504
slouken@1662
   505
        dx = clip->x - dstrect->x;
slouken@1662
   506
        if (dx > 0) {
slouken@1662
   507
            w -= dx;
slouken@1662
   508
            dstrect->x += dx;
slouken@1662
   509
            srcx += dx;
slouken@1662
   510
        }
slouken@1662
   511
        dx = dstrect->x + w - clip->x - clip->w;
slouken@1662
   512
        if (dx > 0)
slouken@1662
   513
            w -= dx;
slouken@1662
   514
slouken@1662
   515
        dy = clip->y - dstrect->y;
slouken@1662
   516
        if (dy > 0) {
slouken@1662
   517
            h -= dy;
slouken@1662
   518
            dstrect->y += dy;
slouken@1662
   519
            srcy += dy;
slouken@1662
   520
        }
slouken@1662
   521
        dy = dstrect->y + h - clip->y - clip->h;
slouken@1662
   522
        if (dy > 0)
slouken@1662
   523
            h -= dy;
slouken@1662
   524
    }
slouken@1662
   525
slouken@1662
   526
    if (w > 0 && h > 0) {
slouken@1662
   527
        SDL_Rect sr;
slouken@1662
   528
        sr.x = srcx;
slouken@1662
   529
        sr.y = srcy;
slouken@1662
   530
        sr.w = dstrect->w = w;
slouken@1662
   531
        sr.h = dstrect->h = h;
slouken@1668
   532
        return SDL_LowerBlit(src, &sr, dst, dstrect);
slouken@1662
   533
    }
slouken@1662
   534
    dstrect->w = dstrect->h = 0;
slouken@1662
   535
    return 0;
slouken@0
   536
}
slouken@0
   537
slouken@1662
   538
static int
slouken@1668
   539
SDL_FillRect1(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
slouken@532
   540
{
slouken@1662
   541
    /* FIXME: We have to worry about packing order.. *sigh* */
slouken@1668
   542
    SDL_SetError("1-bpp rect fill not yet implemented");
slouken@1662
   543
    return -1;
slouken@532
   544
}
slouken@532
   545
slouken@1662
   546
static int
slouken@1668
   547
SDL_FillRect4(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
slouken@532
   548
{
slouken@1662
   549
    /* FIXME: We have to worry about packing order.. *sigh* */
slouken@1668
   550
    SDL_SetError("4-bpp rect fill not yet implemented");
slouken@1662
   551
    return -1;
slouken@532
   552
}
slouken@532
   553
slouken@0
   554
/* 
slouken@0
   555
 * This function performs a fast fill of the given rectangle with 'color'
slouken@0
   556
 */
slouken@1662
   557
int
slouken@1668
   558
SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
slouken@0
   559
{
slouken@1668
   560
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1662
   561
    int x, y;
slouken@1662
   562
    Uint8 *row;
slouken@0
   563
slouken@1662
   564
    /* This function doesn't work on surfaces < 8 bpp */
slouken@1662
   565
    if (dst->format->BitsPerPixel < 8) {
slouken@1662
   566
        switch (dst->format->BitsPerPixel) {
slouken@1662
   567
        case 1:
slouken@1668
   568
            return SDL_FillRect1(dst, dstrect, color);
slouken@1662
   569
            break;
slouken@1662
   570
        case 4:
slouken@1668
   571
            return SDL_FillRect4(dst, dstrect, color);
slouken@1662
   572
            break;
slouken@1662
   573
        default:
slouken@1668
   574
            SDL_SetError("Fill rect on unsupported surface format");
slouken@1662
   575
            return (-1);
slouken@1662
   576
            break;
slouken@1662
   577
        }
slouken@1662
   578
    }
slouken@532
   579
slouken@1662
   580
    /* If 'dstrect' == NULL, then fill the whole surface */
slouken@1662
   581
    if (dstrect) {
slouken@1662
   582
        /* Perform clipping */
slouken@1668
   583
        if (!SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect)) {
slouken@1662
   584
            return (0);
slouken@1662
   585
        }
slouken@1662
   586
    } else {
slouken@1662
   587
        dstrect = &dst->clip_rect;
slouken@1662
   588
    }
slouken@0
   589
slouken@1662
   590
    /* Perform software fill */
slouken@1668
   591
    if (SDL_LockSurface(dst) != 0) {
slouken@1662
   592
        return (-1);
slouken@1662
   593
    }
slouken@1662
   594
    row = (Uint8 *) dst->pixels + dstrect->y * dst->pitch +
slouken@1662
   595
        dstrect->x * dst->format->BytesPerPixel;
slouken@1662
   596
    if (dst->format->palette || (color == 0)) {
slouken@1662
   597
        x = dstrect->w * dst->format->BytesPerPixel;
slouken@1662
   598
        if (!color && !((uintptr_t) row & 3) && !(x & 3)
slouken@1662
   599
            && !(dst->pitch & 3)) {
slouken@1662
   600
            int n = x >> 2;
slouken@1662
   601
            for (y = dstrect->h; y; --y) {
slouken@1668
   602
                SDL_memset4(row, 0, n);
slouken@1662
   603
                row += dst->pitch;
slouken@1662
   604
            }
slouken@1662
   605
        } else {
slouken@0
   606
#ifdef __powerpc__
slouken@1662
   607
            /*
slouken@1662
   608
             * SDL_memset() on PPC (both glibc and codewarrior) uses
slouken@1662
   609
             * the dcbz (Data Cache Block Zero) instruction, which
slouken@1662
   610
             * causes an alignment exception if the destination is
slouken@1662
   611
             * uncachable, so only use it on software surfaces
slouken@1662
   612
             */
slouken@1672
   613
            if (dst->flags & SDL_HWSURFACE) {
slouken@1662
   614
                if (dstrect->w >= 8) {
slouken@1662
   615
                    /*
slouken@1662
   616
                     * 64-bit stores are probably most
slouken@1662
   617
                     * efficient to uncached video memory
slouken@1662
   618
                     */
slouken@1662
   619
                    double fill;
slouken@1668
   620
                    SDL_memset(&fill, color, (sizeof fill));
slouken@1662
   621
                    for (y = dstrect->h; y; y--) {
slouken@1662
   622
                        Uint8 *d = row;
slouken@1662
   623
                        unsigned n = x;
slouken@1662
   624
                        unsigned nn;
slouken@1662
   625
                        Uint8 c = color;
slouken@1662
   626
                        double f = fill;
slouken@1668
   627
                        while ((unsigned long) d & (sizeof(double) - 1)) {
slouken@1662
   628
                            *d++ = c;
slouken@1662
   629
                            n--;
slouken@1662
   630
                        }
slouken@1668
   631
                        nn = n / (sizeof(double) * 4);
slouken@1662
   632
                        while (nn) {
slouken@1662
   633
                            ((double *) d)[0] = f;
slouken@1662
   634
                            ((double *) d)[1] = f;
slouken@1662
   635
                            ((double *) d)[2] = f;
slouken@1662
   636
                            ((double *) d)[3] = f;
slouken@1668
   637
                            d += 4 * sizeof(double);
slouken@1662
   638
                            nn--;
slouken@1662
   639
                        }
slouken@1668
   640
                        n &= ~(sizeof(double) * 4 - 1);
slouken@1668
   641
                        nn = n / sizeof(double);
slouken@1662
   642
                        while (nn) {
slouken@1662
   643
                            *(double *) d = f;
slouken@1668
   644
                            d += sizeof(double);
slouken@1662
   645
                            nn--;
slouken@1662
   646
                        }
slouken@1668
   647
                        n &= ~(sizeof(double) - 1);
slouken@1662
   648
                        while (n) {
slouken@1662
   649
                            *d++ = c;
slouken@1662
   650
                            n--;
slouken@1662
   651
                        }
slouken@1662
   652
                        row += dst->pitch;
slouken@1662
   653
                    }
slouken@1662
   654
                } else {
slouken@1662
   655
                    /* narrow boxes */
slouken@1662
   656
                    for (y = dstrect->h; y; y--) {
slouken@1662
   657
                        Uint8 *d = row;
slouken@1662
   658
                        Uint8 c = color;
slouken@1662
   659
                        int n = x;
slouken@1662
   660
                        while (n) {
slouken@1662
   661
                            *d++ = c;
slouken@1662
   662
                            n--;
slouken@1662
   663
                        }
slouken@1662
   664
                        row += dst->pitch;
slouken@1662
   665
                    }
slouken@1662
   666
                }
slouken@1662
   667
            } else
slouken@0
   668
#endif /* __powerpc__ */
slouken@1662
   669
            {
slouken@1662
   670
                for (y = dstrect->h; y; y--) {
slouken@1668
   671
                    SDL_memset(row, color, x);
slouken@1662
   672
                    row += dst->pitch;
slouken@1662
   673
                }
slouken@1662
   674
            }
slouken@1662
   675
        }
slouken@1662
   676
    } else {
slouken@1662
   677
        switch (dst->format->BytesPerPixel) {
slouken@1662
   678
        case 2:
slouken@1662
   679
            for (y = dstrect->h; y; --y) {
slouken@1662
   680
                Uint16 *pixels = (Uint16 *) row;
slouken@1662
   681
                Uint16 c = (Uint16) color;
slouken@1662
   682
                Uint32 cc = (Uint32) c << 16 | c;
slouken@1662
   683
                int n = dstrect->w;
slouken@1662
   684
                if ((uintptr_t) pixels & 3) {
slouken@1662
   685
                    *pixels++ = c;
slouken@1662
   686
                    n--;
slouken@1662
   687
                }
slouken@1662
   688
                if (n >> 1)
slouken@1668
   689
                    SDL_memset4(pixels, cc, n >> 1);
slouken@1662
   690
                if (n & 1)
slouken@1662
   691
                    pixels[n - 1] = c;
slouken@1662
   692
                row += dst->pitch;
slouken@1662
   693
            }
slouken@1662
   694
            break;
slouken@0
   695
slouken@1662
   696
        case 3:
slouken@1662
   697
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
slouken@1662
   698
            color <<= 8;
slouken@1662
   699
#endif
slouken@1662
   700
            for (y = dstrect->h; y; --y) {
slouken@1662
   701
                Uint8 *pixels = row;
slouken@1662
   702
                for (x = dstrect->w; x; --x) {
slouken@1668
   703
                    SDL_memcpy(pixels, &color, 3);
slouken@1662
   704
                    pixels += 3;
slouken@1662
   705
                }
slouken@1662
   706
                row += dst->pitch;
slouken@1662
   707
            }
slouken@1662
   708
            break;
slouken@0
   709
slouken@1662
   710
        case 4:
slouken@1662
   711
            for (y = dstrect->h; y; --y) {
slouken@1668
   712
                SDL_memset4(row, color, dstrect->w);
slouken@1662
   713
                row += dst->pitch;
slouken@1662
   714
            }
slouken@1662
   715
            break;
slouken@1662
   716
        }
slouken@1662
   717
    }
slouken@1668
   718
    SDL_UnlockSurface(dst);
slouken@0
   719
slouken@1662
   720
    /* We're done! */
slouken@1662
   721
    return (0);
slouken@0
   722
}
slouken@0
   723
slouken@0
   724
/*
slouken@0
   725
 * Lock a surface to directly access the pixels
slouken@0
   726
 */
slouken@1662
   727
int
slouken@1668
   728
SDL_LockSurface(SDL_Surface * surface)
slouken@0
   729
{
slouken@1662
   730
    if (!surface->locked) {
slouken@1662
   731
        /* Perform the lock */
slouken@1662
   732
        if (surface->flags & SDL_HWSURFACE) {
slouken@1672
   733
            if (SDL_LockTexture
slouken@1672
   734
                ((SDL_TextureID) surface->lock_data, NULL, 1,
slouken@1672
   735
                 &surface->pixels, &surface->pitch) < 0) {
slouken@1662
   736
                return (-1);
slouken@1662
   737
            }
slouken@1662
   738
        }
slouken@1662
   739
        if (surface->flags & SDL_RLEACCEL) {
slouken@1668
   740
            SDL_UnRLESurface(surface, 1);
slouken@1662
   741
            surface->flags |= SDL_RLEACCEL;     /* save accel'd state */
slouken@1662
   742
        }
slouken@1662
   743
    }
slouken@0
   744
slouken@1662
   745
    /* Increment the surface lock count, for recursive locks */
slouken@1662
   746
    ++surface->locked;
slouken@0
   747
slouken@1662
   748
    /* Ready to go.. */
slouken@1662
   749
    return (0);
slouken@0
   750
}
slouken@1662
   751
slouken@0
   752
/*
slouken@0
   753
 * Unlock a previously locked surface
slouken@0
   754
 */
slouken@1662
   755
void
slouken@1668
   756
SDL_UnlockSurface(SDL_Surface * surface)
slouken@0
   757
{
slouken@1662
   758
    /* Only perform an unlock if we are locked */
slouken@1662
   759
    if (!surface->locked || (--surface->locked > 0)) {
slouken@1662
   760
        return;
slouken@1662
   761
    }
slouken@0
   762
slouken@1662
   763
    /* Unlock hardware or accelerated surfaces */
slouken@1662
   764
    if (surface->flags & SDL_HWSURFACE) {
slouken@1672
   765
        SDL_UnlockTexture((SDL_TextureID) surface->lock_data);
slouken@1662
   766
    } else {
slouken@1662
   767
        /* Update RLE encoded surface with new data */
slouken@1662
   768
        if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
slouken@1662
   769
            surface->flags &= ~SDL_RLEACCEL;    /* stop lying */
slouken@1668
   770
            SDL_RLESurface(surface);
slouken@1662
   771
        }
slouken@1662
   772
    }
slouken@0
   773
}
slouken@0
   774
slouken@0
   775
/* 
slouken@0
   776
 * Convert a surface into the specified pixel format.
slouken@0
   777
 */
slouken@1662
   778
SDL_Surface *
slouken@1668
   779
SDL_ConvertSurface(SDL_Surface * surface,
slouken@1668
   780
                   SDL_PixelFormat * format, Uint32 flags)
slouken@0
   781
{
slouken@1662
   782
    SDL_Surface *convert;
slouken@1662
   783
    Uint32 colorkey = 0;
slouken@1662
   784
    Uint8 alpha = 0;
slouken@1662
   785
    Uint32 surface_flags;
slouken@1662
   786
    SDL_Rect bounds;
slouken@0
   787
slouken@1662
   788
    /* Check for empty destination palette! (results in empty image) */
slouken@1662
   789
    if (format->palette != NULL) {
slouken@1662
   790
        int i;
slouken@1662
   791
        for (i = 0; i < format->palette->ncolors; ++i) {
slouken@1662
   792
            if ((format->palette->colors[i].r != 0) ||
slouken@1662
   793
                (format->palette->colors[i].g != 0) ||
slouken@1662
   794
                (format->palette->colors[i].b != 0))
slouken@1662
   795
                break;
slouken@1662
   796
        }
slouken@1662
   797
        if (i == format->palette->ncolors) {
slouken@1668
   798
            SDL_SetError("Empty destination palette");
slouken@1662
   799
            return (NULL);
slouken@1662
   800
        }
slouken@1662
   801
    }
slouken@0
   802
slouken@1662
   803
    /* Create a new surface with the desired format */
slouken@1668
   804
    convert = SDL_CreateRGBSurface(flags,
slouken@1668
   805
                                   surface->w, surface->h,
slouken@1668
   806
                                   format->BitsPerPixel, format->Rmask,
slouken@1668
   807
                                   format->Gmask, format->Bmask,
slouken@1668
   808
                                   format->Amask);
slouken@1662
   809
    if (convert == NULL) {
slouken@1662
   810
        return (NULL);
slouken@1662
   811
    }
slouken@0
   812
slouken@1662
   813
    /* Copy the palette if any */
slouken@1662
   814
    if (format->palette && convert->format->palette) {
slouken@1668
   815
        SDL_memcpy(convert->format->palette->colors,
slouken@1668
   816
                   format->palette->colors,
slouken@1668
   817
                   format->palette->ncolors * sizeof(SDL_Color));
slouken@1662
   818
        convert->format->palette->ncolors = format->palette->ncolors;
slouken@1662
   819
    }
slouken@0
   820
slouken@1662
   821
    /* Save the original surface color key and alpha */
slouken@1662
   822
    surface_flags = surface->flags;
slouken@1662
   823
    if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
slouken@1662
   824
        /* Convert colourkeyed surfaces to RGBA if requested */
slouken@1662
   825
        if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) {
slouken@1662
   826
            surface_flags &= ~SDL_SRCCOLORKEY;
slouken@1662
   827
        } else {
slouken@1662
   828
            colorkey = surface->format->colorkey;
slouken@1668
   829
            SDL_SetColorKey(surface, 0, 0);
slouken@1662
   830
        }
slouken@1662
   831
    }
slouken@1662
   832
    if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
slouken@1662
   833
        /* Copy over the alpha channel to RGBA if requested */
slouken@1662
   834
        if (format->Amask) {
slouken@1662
   835
            surface->flags &= ~SDL_SRCALPHA;
slouken@1662
   836
        } else {
slouken@1662
   837
            alpha = surface->format->alpha;
slouken@1668
   838
            SDL_SetAlpha(surface, 0, 0);
slouken@1662
   839
        }
slouken@1662
   840
    }
slouken@0
   841
slouken@1662
   842
    /* Copy over the image data */
slouken@1662
   843
    bounds.x = 0;
slouken@1662
   844
    bounds.y = 0;
slouken@1662
   845
    bounds.w = surface->w;
slouken@1662
   846
    bounds.h = surface->h;
slouken@1668
   847
    SDL_LowerBlit(surface, &bounds, convert, &bounds);
slouken@0
   848
slouken@1662
   849
    /* Clean up the original surface, and update converted surface */
slouken@1662
   850
    if (convert != NULL) {
slouken@1668
   851
        SDL_SetClipRect(convert, &surface->clip_rect);
slouken@1662
   852
    }
slouken@1662
   853
    if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
slouken@1662
   854
        Uint32 cflags = surface_flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
slouken@1662
   855
        if (convert != NULL) {
slouken@1662
   856
            Uint8 keyR, keyG, keyB;
slouken@0
   857
slouken@1668
   858
            SDL_GetRGB(colorkey, surface->format, &keyR, &keyG, &keyB);
slouken@1668
   859
            SDL_SetColorKey(convert, cflags | (flags & SDL_RLEACCELOK),
slouken@1668
   860
                            SDL_MapRGB(convert->format, keyR, keyG, keyB));
slouken@1662
   861
        }
slouken@1668
   862
        SDL_SetColorKey(surface, cflags, colorkey);
slouken@1662
   863
    }
slouken@1662
   864
    if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
slouken@1662
   865
        Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
slouken@1662
   866
        if (convert != NULL) {
slouken@1668
   867
            SDL_SetAlpha(convert, aflags | (flags & SDL_RLEACCELOK), alpha);
slouken@1662
   868
        }
slouken@1662
   869
        if (format->Amask) {
slouken@1662
   870
            surface->flags |= SDL_SRCALPHA;
slouken@1662
   871
        } else {
slouken@1668
   872
            SDL_SetAlpha(surface, aflags, alpha);
slouken@1662
   873
        }
slouken@1662
   874
    }
slouken@0
   875
slouken@1662
   876
    /* We're ready to go! */
slouken@1662
   877
    return (convert);
slouken@0
   878
}
slouken@0
   879
slouken@0
   880
/*
slouken@0
   881
 * Free a surface created by the above function.
slouken@0
   882
 */
slouken@1662
   883
void
slouken@1668
   884
SDL_FreeSurface(SDL_Surface * surface)
slouken@0
   885
{
slouken@1666
   886
    if (surface == NULL) {
slouken@1662
   887
        return;
slouken@1662
   888
    }
slouken@1662
   889
    if (--surface->refcount > 0) {
slouken@1662
   890
        return;
slouken@1662
   891
    }
slouken@1662
   892
    while (surface->locked > 0) {
slouken@1668
   893
        SDL_UnlockSurface(surface);
slouken@1662
   894
    }
slouken@1672
   895
    if (surface->flags & SDL_RLEACCEL) {
slouken@1668
   896
        SDL_UnRLESurface(surface, 0);
slouken@1662
   897
    }
slouken@1662
   898
    if (surface->format) {
slouken@1668
   899
        SDL_FreeFormat(surface->format);
slouken@1662
   900
        surface->format = NULL;
slouken@1662
   901
    }
slouken@1662
   902
    if (surface->map != NULL) {
slouken@1668
   903
        SDL_FreeBlitMap(surface->map);
slouken@1662
   904
        surface->map = NULL;
slouken@1662
   905
    }
slouken@1672
   906
    /* Should we destroy the texture too?
slouken@1672
   907
       if (surface->flags & SDL_HWSURFACE) {
slouken@1672
   908
       SDL_DestroyTexture((SDL_TextureID)surface->lock_data);
slouken@1672
   909
       }
slouken@1672
   910
     */
slouken@1662
   911
    if (surface->pixels && ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC)) {
slouken@1668
   912
        SDL_free(surface->pixels);
slouken@1662
   913
    }
slouken@1668
   914
    SDL_free(surface);
slouken@0
   915
#ifdef CHECK_LEAKS
slouken@1662
   916
    --surfaces_allocated;
slouken@0
   917
#endif
slouken@0
   918
}
slouken@1662
   919
slouken@1662
   920
/* vi: set ts=4 sw=4 expandtab: */