src/video/SDL_blit_1.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 23 Jan 2020 01:00:52 -0800
changeset 13440 ac297b67f6d9
parent 13422 fd6a12de91c7
permissions -rw-r--r--
Added a single SDL_LEAN_AND_MEAN define to turn on minimal SDL builds
Protected more code with #ifdefs to reduce the size of minimal shared library builds
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@13422
     3
  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
icculus@8093
    21
#include "../SDL_internal.h"
slouken@0
    22
slouken@13440
    23
#if SDL_HAVE_BLIT_1
slouken@13440
    24
slouken@0
    25
#include "SDL_video.h"
slouken@0
    26
#include "SDL_blit.h"
slouken@0
    27
#include "SDL_sysvideo.h"
slouken@0
    28
#include "SDL_endian.h"
slouken@0
    29
slouken@0
    30
/* Functions to blit from 8-bit surfaces to other surfaces */
slouken@0
    31
slouken@1895
    32
static void
slouken@1895
    33
Blit1to1(SDL_BlitInfo * info)
slouken@0
    34
{
slouken@0
    35
#ifndef USE_DUFFS_LOOP
slouken@1895
    36
    int c;
slouken@0
    37
#endif
slouken@1895
    38
    int width, height;
slouken@1895
    39
    Uint8 *src, *map, *dst;
slouken@1895
    40
    int srcskip, dstskip;
slouken@0
    41
slouken@1895
    42
    /* Set up some basic variables */
slouken@2262
    43
    width = info->dst_w;
slouken@2262
    44
    height = info->dst_h;
slouken@2262
    45
    src = info->src;
slouken@2267
    46
    srcskip = info->src_skip;
slouken@2262
    47
    dst = info->dst;
slouken@2267
    48
    dstskip = info->dst_skip;
slouken@1895
    49
    map = info->table;
slouken@0
    50
slouken@1895
    51
    while (height--) {
slouken@0
    52
#ifdef USE_DUFFS_LOOP
slouken@1895
    53
        /* *INDENT-OFF* */
slouken@12201
    54
        DUFFS_LOOP(
slouken@12201
    55
            {
slouken@12201
    56
              *dst = map[*src];
slouken@12201
    57
            }
slouken@12201
    58
            dst++;
slouken@12201
    59
            src++;
slouken@12201
    60
        , width);
slouken@1895
    61
        /* *INDENT-ON* */
slouken@0
    62
#else
slouken@1895
    63
        for (c = width; c; --c) {
slouken@1895
    64
            *dst = map[*src];
slouken@1895
    65
            dst++;
slouken@1895
    66
            src++;
slouken@1895
    67
        }
slouken@0
    68
#endif
slouken@1895
    69
        src += srcskip;
slouken@1895
    70
        dst += dstskip;
slouken@1895
    71
    }
slouken@0
    72
}
slouken@1895
    73
slouken@0
    74
/* This is now endian dependent */
slouken@10609
    75
#ifndef USE_DUFFS_LOOP
slouken@10609
    76
# if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
slouken@12201
    77
#  define HI    1
slouken@12201
    78
#  define LO    0
slouken@10609
    79
# else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
slouken@12201
    80
#  define HI    0
slouken@12201
    81
#  define LO    1
slouken@10609
    82
# endif
slouken@0
    83
#endif
slouken@1895
    84
static void
slouken@1895
    85
Blit1to2(SDL_BlitInfo * info)
slouken@0
    86
{
slouken@0
    87
#ifndef USE_DUFFS_LOOP
slouken@1895
    88
    int c;
slouken@0
    89
#endif
slouken@1895
    90
    int width, height;
slouken@1895
    91
    Uint8 *src, *dst;
slouken@1895
    92
    Uint16 *map;
slouken@1895
    93
    int srcskip, dstskip;
slouken@0
    94
slouken@1895
    95
    /* Set up some basic variables */
slouken@2262
    96
    width = info->dst_w;
slouken@2262
    97
    height = info->dst_h;
slouken@2262
    98
    src = info->src;
slouken@2267
    99
    srcskip = info->src_skip;
slouken@2262
   100
    dst = info->dst;
slouken@2267
   101
    dstskip = info->dst_skip;
slouken@1895
   102
    map = (Uint16 *) info->table;
slouken@0
   103
slouken@0
   104
#ifdef USE_DUFFS_LOOP
slouken@1895
   105
    while (height--) {
slouken@12201
   106
        /* *INDENT-OFF* */
slouken@12201
   107
        DUFFS_LOOP(
slouken@12201
   108
        {
slouken@12201
   109
            *(Uint16 *)dst = map[*src++];
slouken@12201
   110
            dst += 2;
slouken@12201
   111
        },
slouken@12201
   112
        width);
slouken@12201
   113
        /* *INDENT-ON* */
slouken@1895
   114
        src += srcskip;
slouken@1895
   115
        dst += dstskip;
slouken@1895
   116
    }
slouken@0
   117
#else
slouken@1895
   118
    /* Memory align at 4-byte boundary, if necessary */
slouken@1895
   119
    if ((long) dst & 0x03) {
slouken@1895
   120
        /* Don't do anything if width is 0 */
slouken@1895
   121
        if (width == 0) {
slouken@1895
   122
            return;
slouken@1895
   123
        }
slouken@1895
   124
        --width;
slouken@0
   125
slouken@1895
   126
        while (height--) {
slouken@1895
   127
            /* Perform copy alignment */
slouken@1895
   128
            *(Uint16 *) dst = map[*src++];
slouken@1895
   129
            dst += 2;
slouken@0
   130
slouken@1895
   131
            /* Copy in 4 pixel chunks */
slouken@1895
   132
            for (c = width / 4; c; --c) {
slouken@1895
   133
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1895
   134
                src += 2;
slouken@1895
   135
                dst += 4;
slouken@1895
   136
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1895
   137
                src += 2;
slouken@1895
   138
                dst += 4;
slouken@1895
   139
            }
slouken@1895
   140
            /* Get any leftovers */
slouken@1895
   141
            switch (width & 3) {
slouken@1895
   142
            case 3:
slouken@1895
   143
                *(Uint16 *) dst = map[*src++];
slouken@1895
   144
                dst += 2;
slouken@1895
   145
            case 2:
slouken@1895
   146
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1895
   147
                src += 2;
slouken@1895
   148
                dst += 4;
slouken@1895
   149
                break;
slouken@1895
   150
            case 1:
slouken@1895
   151
                *(Uint16 *) dst = map[*src++];
slouken@1895
   152
                dst += 2;
slouken@1895
   153
                break;
slouken@1895
   154
            }
slouken@1895
   155
            src += srcskip;
slouken@1895
   156
            dst += dstskip;
slouken@1895
   157
        }
slouken@1895
   158
    } else {
slouken@1895
   159
        while (height--) {
slouken@1895
   160
            /* Copy in 4 pixel chunks */
slouken@1895
   161
            for (c = width / 4; c; --c) {
slouken@1895
   162
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1895
   163
                src += 2;
slouken@1895
   164
                dst += 4;
slouken@1895
   165
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1895
   166
                src += 2;
slouken@1895
   167
                dst += 4;
slouken@1895
   168
            }
slouken@1895
   169
            /* Get any leftovers */
slouken@1895
   170
            switch (width & 3) {
slouken@1895
   171
            case 3:
slouken@1895
   172
                *(Uint16 *) dst = map[*src++];
slouken@1895
   173
                dst += 2;
slouken@1895
   174
            case 2:
slouken@1895
   175
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1895
   176
                src += 2;
slouken@1895
   177
                dst += 4;
slouken@1895
   178
                break;
slouken@1895
   179
            case 1:
slouken@1895
   180
                *(Uint16 *) dst = map[*src++];
slouken@1895
   181
                dst += 2;
slouken@1895
   182
                break;
slouken@1895
   183
            }
slouken@1895
   184
            src += srcskip;
slouken@1895
   185
            dst += dstskip;
slouken@1895
   186
        }
slouken@1895
   187
    }
slouken@0
   188
#endif /* USE_DUFFS_LOOP */
slouken@0
   189
}
slouken@2735
   190
slouken@1895
   191
static void
slouken@1895
   192
Blit1to3(SDL_BlitInfo * info)
slouken@0
   193
{
slouken@0
   194
#ifndef USE_DUFFS_LOOP
slouken@1895
   195
    int c;
slouken@0
   196
#endif
slouken@1895
   197
    int o;
slouken@1895
   198
    int width, height;
slouken@1895
   199
    Uint8 *src, *map, *dst;
slouken@1895
   200
    int srcskip, dstskip;
slouken@0
   201
slouken@1895
   202
    /* Set up some basic variables */
slouken@2262
   203
    width = info->dst_w;
slouken@2262
   204
    height = info->dst_h;
slouken@2262
   205
    src = info->src;
slouken@2267
   206
    srcskip = info->src_skip;
slouken@2262
   207
    dst = info->dst;
slouken@2267
   208
    dstskip = info->dst_skip;
slouken@1895
   209
    map = info->table;
slouken@0
   210
slouken@1895
   211
    while (height--) {
slouken@0
   212
#ifdef USE_DUFFS_LOOP
slouken@12201
   213
        /* *INDENT-OFF* */
slouken@12201
   214
        DUFFS_LOOP(
slouken@12201
   215
            {
slouken@12201
   216
                o = *src * 4;
slouken@12201
   217
                dst[0] = map[o++];
slouken@12201
   218
                dst[1] = map[o++];
slouken@12201
   219
                dst[2] = map[o++];
slouken@12201
   220
            }
slouken@12201
   221
            src++;
slouken@12201
   222
            dst += 3;
slouken@12201
   223
        , width);
slouken@12201
   224
        /* *INDENT-ON* */
slouken@0
   225
#else
slouken@1895
   226
        for (c = width; c; --c) {
slouken@1895
   227
            o = *src * 4;
slouken@1895
   228
            dst[0] = map[o++];
slouken@1895
   229
            dst[1] = map[o++];
slouken@1895
   230
            dst[2] = map[o++];
slouken@1895
   231
            src++;
slouken@1895
   232
            dst += 3;
slouken@1895
   233
        }
slouken@0
   234
#endif /* USE_DUFFS_LOOP */
slouken@1895
   235
        src += srcskip;
slouken@1895
   236
        dst += dstskip;
slouken@1895
   237
    }
slouken@0
   238
}
slouken@2735
   239
slouken@1895
   240
static void
slouken@1895
   241
Blit1to4(SDL_BlitInfo * info)
slouken@0
   242
{
slouken@0
   243
#ifndef USE_DUFFS_LOOP
slouken@1895
   244
    int c;
slouken@0
   245
#endif
slouken@1895
   246
    int width, height;
slouken@1895
   247
    Uint8 *src;
slouken@1895
   248
    Uint32 *map, *dst;
slouken@1895
   249
    int srcskip, dstskip;
slouken@0
   250
slouken@1895
   251
    /* Set up some basic variables */
slouken@2262
   252
    width = info->dst_w;
slouken@2262
   253
    height = info->dst_h;
slouken@2262
   254
    src = info->src;
slouken@2267
   255
    srcskip = info->src_skip;
slouken@2262
   256
    dst = (Uint32 *) info->dst;
slouken@2267
   257
    dstskip = info->dst_skip / 4;
slouken@1895
   258
    map = (Uint32 *) info->table;
slouken@0
   259
slouken@1895
   260
    while (height--) {
slouken@0
   261
#ifdef USE_DUFFS_LOOP
slouken@12201
   262
        /* *INDENT-OFF* */
slouken@12201
   263
        DUFFS_LOOP(
slouken@12201
   264
            *dst++ = map[*src++];
slouken@12201
   265
        , width);
slouken@12201
   266
        /* *INDENT-ON* */
slouken@0
   267
#else
slouken@1895
   268
        for (c = width / 4; c; --c) {
slouken@1895
   269
            *dst++ = map[*src++];
slouken@1895
   270
            *dst++ = map[*src++];
slouken@1895
   271
            *dst++ = map[*src++];
slouken@1895
   272
            *dst++ = map[*src++];
slouken@1895
   273
        }
slouken@1895
   274
        switch (width & 3) {
slouken@1895
   275
        case 3:
slouken@1895
   276
            *dst++ = map[*src++];
slouken@1895
   277
        case 2:
slouken@1895
   278
            *dst++ = map[*src++];
slouken@1895
   279
        case 1:
slouken@1895
   280
            *dst++ = map[*src++];
slouken@1895
   281
        }
slouken@0
   282
#endif /* USE_DUFFS_LOOP */
slouken@1895
   283
        src += srcskip;
slouken@1895
   284
        dst += dstskip;
slouken@1895
   285
    }
slouken@0
   286
}
slouken@0
   287
slouken@1895
   288
static void
slouken@1895
   289
Blit1to1Key(SDL_BlitInfo * info)
slouken@0
   290
{
slouken@2262
   291
    int width = info->dst_w;
slouken@2262
   292
    int height = info->dst_h;
slouken@2262
   293
    Uint8 *src = info->src;
slouken@2267
   294
    int srcskip = info->src_skip;
slouken@2262
   295
    Uint8 *dst = info->dst;
slouken@2267
   296
    int dstskip = info->dst_skip;
slouken@1895
   297
    Uint8 *palmap = info->table;
slouken@2267
   298
    Uint32 ckey = info->colorkey;
slouken@1895
   299
slouken@1895
   300
    if (palmap) {
slouken@1895
   301
        while (height--) {
slouken@12201
   302
            /* *INDENT-OFF* */
slouken@12201
   303
            DUFFS_LOOP(
slouken@12201
   304
            {
slouken@12201
   305
                if ( *src != ckey ) {
slouken@12201
   306
                  *dst = palmap[*src];
slouken@12201
   307
                }
slouken@12201
   308
                dst++;
slouken@12201
   309
                src++;
slouken@12201
   310
            },
slouken@12201
   311
            width);
slouken@12201
   312
            /* *INDENT-ON* */
slouken@1895
   313
            src += srcskip;
slouken@1895
   314
            dst += dstskip;
slouken@1895
   315
        }
slouken@1895
   316
    } else {
slouken@1895
   317
        while (height--) {
slouken@12201
   318
            /* *INDENT-OFF* */
slouken@12201
   319
            DUFFS_LOOP(
slouken@12201
   320
            {
slouken@12201
   321
                if ( *src != ckey ) {
slouken@12201
   322
                  *dst = *src;
slouken@12201
   323
                }
slouken@12201
   324
                dst++;
slouken@12201
   325
                src++;
slouken@12201
   326
            },
slouken@12201
   327
            width);
slouken@12201
   328
            /* *INDENT-ON* */
slouken@1895
   329
            src += srcskip;
slouken@1895
   330
            dst += dstskip;
slouken@1895
   331
        }
slouken@1895
   332
    }
slouken@0
   333
}
slouken@0
   334
slouken@1895
   335
static void
slouken@1895
   336
Blit1to2Key(SDL_BlitInfo * info)
slouken@0
   337
{
slouken@2262
   338
    int width = info->dst_w;
slouken@2262
   339
    int height = info->dst_h;
slouken@2262
   340
    Uint8 *src = info->src;
slouken@2267
   341
    int srcskip = info->src_skip;
slouken@2262
   342
    Uint16 *dstp = (Uint16 *) info->dst;
slouken@2267
   343
    int dstskip = info->dst_skip;
slouken@1895
   344
    Uint16 *palmap = (Uint16 *) info->table;
slouken@2267
   345
    Uint32 ckey = info->colorkey;
slouken@0
   346
slouken@1895
   347
    /* Set up some basic variables */
slouken@1895
   348
    dstskip /= 2;
slouken@0
   349
slouken@1895
   350
    while (height--) {
slouken@12201
   351
        /* *INDENT-OFF* */
slouken@12201
   352
        DUFFS_LOOP(
slouken@12201
   353
        {
slouken@12201
   354
            if ( *src != ckey ) {
slouken@12201
   355
                *dstp=palmap[*src];
slouken@12201
   356
            }
slouken@12201
   357
            src++;
slouken@12201
   358
            dstp++;
slouken@12201
   359
        },
slouken@12201
   360
        width);
slouken@12201
   361
        /* *INDENT-ON* */
slouken@1895
   362
        src += srcskip;
slouken@1895
   363
        dstp += dstskip;
slouken@1895
   364
    }
slouken@0
   365
}
slouken@0
   366
slouken@1895
   367
static void
slouken@1895
   368
Blit1to3Key(SDL_BlitInfo * info)
slouken@0
   369
{
slouken@2262
   370
    int width = info->dst_w;
slouken@2262
   371
    int height = info->dst_h;
slouken@2262
   372
    Uint8 *src = info->src;
slouken@2267
   373
    int srcskip = info->src_skip;
slouken@2262
   374
    Uint8 *dst = info->dst;
slouken@2267
   375
    int dstskip = info->dst_skip;
slouken@1895
   376
    Uint8 *palmap = info->table;
slouken@2267
   377
    Uint32 ckey = info->colorkey;
slouken@1895
   378
    int o;
slouken@0
   379
slouken@1895
   380
    while (height--) {
slouken@12201
   381
        /* *INDENT-OFF* */
slouken@12201
   382
        DUFFS_LOOP(
slouken@12201
   383
        {
slouken@12201
   384
            if ( *src != ckey ) {
slouken@12201
   385
                o = *src * 4;
slouken@12201
   386
                dst[0] = palmap[o++];
slouken@12201
   387
                dst[1] = palmap[o++];
slouken@12201
   388
                dst[2] = palmap[o++];
slouken@12201
   389
            }
slouken@12201
   390
            src++;
slouken@12201
   391
            dst += 3;
slouken@12201
   392
        },
slouken@12201
   393
        width);
slouken@12201
   394
        /* *INDENT-ON* */
slouken@1895
   395
        src += srcskip;
slouken@1895
   396
        dst += dstskip;
slouken@1895
   397
    }
slouken@0
   398
}
slouken@0
   399
slouken@1895
   400
static void
slouken@1895
   401
Blit1to4Key(SDL_BlitInfo * info)
slouken@0
   402
{
slouken@2262
   403
    int width = info->dst_w;
slouken@2262
   404
    int height = info->dst_h;
slouken@2262
   405
    Uint8 *src = info->src;
slouken@2267
   406
    int srcskip = info->src_skip;
slouken@2262
   407
    Uint32 *dstp = (Uint32 *) info->dst;
slouken@2267
   408
    int dstskip = info->dst_skip;
slouken@1895
   409
    Uint32 *palmap = (Uint32 *) info->table;
slouken@2267
   410
    Uint32 ckey = info->colorkey;
slouken@0
   411
slouken@1895
   412
    /* Set up some basic variables */
slouken@1895
   413
    dstskip /= 4;
slouken@0
   414
slouken@1895
   415
    while (height--) {
slouken@12201
   416
        /* *INDENT-OFF* */
slouken@12201
   417
        DUFFS_LOOP(
slouken@12201
   418
        {
slouken@12201
   419
            if ( *src != ckey ) {
slouken@12201
   420
                *dstp = palmap[*src];
slouken@12201
   421
            }
slouken@12201
   422
            src++;
slouken@12201
   423
            dstp++;
slouken@12201
   424
        },
slouken@12201
   425
        width);
slouken@12201
   426
        /* *INDENT-ON* */
slouken@1895
   427
        src += srcskip;
slouken@1895
   428
        dstp += dstskip;
slouken@1895
   429
    }
slouken@0
   430
}
slouken@0
   431
slouken@1895
   432
static void
slouken@1895
   433
Blit1toNAlpha(SDL_BlitInfo * info)
slouken@0
   434
{
slouken@2262
   435
    int width = info->dst_w;
slouken@2262
   436
    int height = info->dst_h;
slouken@2262
   437
    Uint8 *src = info->src;
slouken@2267
   438
    int srcskip = info->src_skip;
slouken@2262
   439
    Uint8 *dst = info->dst;
slouken@2267
   440
    int dstskip = info->dst_skip;
slouken@2267
   441
    SDL_PixelFormat *dstfmt = info->dst_fmt;
slouken@2267
   442
    const SDL_Color *srcpal = info->src_fmt->palette->colors;
slouken@1895
   443
    int dstbpp;
slouken@7502
   444
    Uint32 pixel;
slouken@7502
   445
    unsigned sR, sG, sB;
slouken@7502
   446
    unsigned dR, dG, dB, dA;
slouken@7502
   447
    const unsigned A = info->a;
slouken@0
   448
slouken@1895
   449
    /* Set up some basic variables */
slouken@1895
   450
    dstbpp = dstfmt->BytesPerPixel;
slouken@0
   451
slouken@1895
   452
    while (height--) {
slouken@7502
   453
        /* *INDENT-OFF* */
slouken@7502
   454
        DUFFS_LOOP4(
slouken@7502
   455
        {
slouken@7502
   456
            sR = srcpal[*src].r;
slouken@7502
   457
            sG = srcpal[*src].g;
slouken@7502
   458
            sB = srcpal[*src].b;
slouken@7502
   459
            DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
slouken@7502
   460
            ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
slouken@7502
   461
            ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
slouken@7502
   462
            src++;
slouken@7502
   463
            dst += dstbpp;
slouken@7502
   464
        },
slouken@7502
   465
        width);
slouken@7502
   466
        /* *INDENT-ON* */
slouken@1895
   467
        src += srcskip;
slouken@1895
   468
        dst += dstskip;
slouken@1895
   469
    }
slouken@0
   470
}
slouken@0
   471
slouken@1895
   472
static void
slouken@1895
   473
Blit1toNAlphaKey(SDL_BlitInfo * info)
slouken@0
   474
{
slouken@2262
   475
    int width = info->dst_w;
slouken@2262
   476
    int height = info->dst_h;
slouken@2262
   477
    Uint8 *src = info->src;
slouken@2267
   478
    int srcskip = info->src_skip;
slouken@2262
   479
    Uint8 *dst = info->dst;
slouken@2267
   480
    int dstskip = info->dst_skip;
slouken@2267
   481
    SDL_PixelFormat *dstfmt = info->dst_fmt;
slouken@2267
   482
    const SDL_Color *srcpal = info->src_fmt->palette->colors;
slouken@2267
   483
    Uint32 ckey = info->colorkey;
slouken@1895
   484
    int dstbpp;
slouken@7502
   485
    Uint32 pixel;
slouken@7502
   486
    unsigned sR, sG, sB;
slouken@7502
   487
    unsigned dR, dG, dB, dA;
slouken@7502
   488
    const unsigned A = info->a;
slouken@0
   489
slouken@1895
   490
    /* Set up some basic variables */
slouken@1895
   491
    dstbpp = dstfmt->BytesPerPixel;
slouken@0
   492
slouken@1895
   493
    while (height--) {
slouken@12201
   494
        /* *INDENT-OFF* */
slouken@12201
   495
        DUFFS_LOOP(
slouken@12201
   496
        {
slouken@12201
   497
            if ( *src != ckey ) {
slouken@12201
   498
                sR = srcpal[*src].r;
slouken@12201
   499
                sG = srcpal[*src].g;
slouken@12201
   500
                sB = srcpal[*src].b;
slouken@12201
   501
                DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
slouken@12201
   502
                ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
slouken@12201
   503
                  ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
slouken@12201
   504
            }
slouken@12201
   505
            src++;
slouken@12201
   506
            dst += dstbpp;
slouken@12201
   507
        },
slouken@12201
   508
        width);
slouken@12201
   509
        /* *INDENT-ON* */
slouken@1895
   510
        src += srcskip;
slouken@1895
   511
        dst += dstskip;
slouken@1895
   512
    }
slouken@0
   513
}
slouken@0
   514
slouken@3162
   515
static const SDL_BlitFunc one_blit[] = {
eviltypeguy@6967
   516
    (SDL_BlitFunc) NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4
slouken@0
   517
};
slouken@0
   518
slouken@3162
   519
static const SDL_BlitFunc one_blitkey[] = {
eviltypeguy@6967
   520
    (SDL_BlitFunc) NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key
slouken@0
   521
};
slouken@0
   522
slouken@2267
   523
SDL_BlitFunc
slouken@2267
   524
SDL_CalculateBlit1(SDL_Surface * surface)
slouken@0
   525
{
slouken@1895
   526
    int which;
slouken@1895
   527
    SDL_PixelFormat *dstfmt;
slouken@0
   528
slouken@1895
   529
    dstfmt = surface->map->dst->format;
slouken@1895
   530
    if (dstfmt->BitsPerPixel < 8) {
slouken@1895
   531
        which = 0;
slouken@1895
   532
    } else {
slouken@1895
   533
        which = dstfmt->BytesPerPixel;
slouken@1895
   534
    }
slouken@2853
   535
    switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
slouken@2267
   536
    case 0:
slouken@1895
   537
        return one_blit[which];
slouken@0
   538
slouken@2267
   539
    case SDL_COPY_COLORKEY:
slouken@1895
   540
        return one_blitkey[which];
slouken@0
   541
slouken@2267
   542
    case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
slouken@1895
   543
        /* Supporting 8bpp->8bpp alpha is doable but requires lots of
slouken@1895
   544
           tables which consume space and takes time to precompute,
slouken@1895
   545
           so is better left to the user */
eviltypeguy@6967
   546
        return which >= 2 ? Blit1toNAlpha : (SDL_BlitFunc) NULL;
slouken@0
   547
slouken@2267
   548
    case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
eviltypeguy@6967
   549
        return which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc) NULL;
slouken@1895
   550
    }
eviltypeguy@6967
   551
    return (SDL_BlitFunc) NULL;
slouken@0
   552
}
slouken@1895
   553
slouken@13440
   554
#endif /* SDL_HAVE_BLIT_1 */
slouken@13440
   555
slouken@1895
   556
/* vi: set ts=4 sw=4 expandtab: */