src/video/SDL_blit_1.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
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@0
    25
#include "SDL_blit.h"
slouken@0
    26
#include "SDL_sysvideo.h"
slouken@0
    27
#include "SDL_endian.h"
slouken@0
    28
slouken@0
    29
/* Functions to blit from 8-bit surfaces to other surfaces */
slouken@0
    30
slouken@1662
    31
static void
slouken@1668
    32
Blit1to1(SDL_BlitInfo * info)
slouken@0
    33
{
slouken@0
    34
#ifndef USE_DUFFS_LOOP
slouken@1662
    35
    int c;
slouken@0
    36
#endif
slouken@1662
    37
    int width, height;
slouken@1662
    38
    Uint8 *src, *map, *dst;
slouken@1662
    39
    int srcskip, dstskip;
slouken@0
    40
slouken@1662
    41
    /* Set up some basic variables */
slouken@1662
    42
    width = info->d_width;
slouken@1662
    43
    height = info->d_height;
slouken@1662
    44
    src = info->s_pixels;
slouken@1662
    45
    srcskip = info->s_skip;
slouken@1662
    46
    dst = info->d_pixels;
slouken@1662
    47
    dstskip = info->d_skip;
slouken@1662
    48
    map = info->table;
slouken@0
    49
slouken@1662
    50
    while (height--) {
slouken@0
    51
#ifdef USE_DUFFS_LOOP
slouken@1662
    52
        /* *INDENT-OFF* */
slouken@0
    53
		DUFFS_LOOP(
slouken@0
    54
			{
slouken@0
    55
			  *dst = map[*src];
slouken@0
    56
			}
slouken@0
    57
			dst++;
slouken@0
    58
			src++;
slouken@0
    59
		, width);
slouken@1662
    60
        /* *INDENT-ON* */
slouken@0
    61
#else
slouken@1662
    62
        for (c = width; c; --c) {
slouken@1662
    63
            *dst = map[*src];
slouken@1662
    64
            dst++;
slouken@1662
    65
            src++;
slouken@1662
    66
        }
slouken@0
    67
#endif
slouken@1662
    68
        src += srcskip;
slouken@1662
    69
        dst += dstskip;
slouken@1662
    70
    }
slouken@0
    71
}
slouken@1662
    72
slouken@0
    73
/* This is now endian dependent */
slouken@0
    74
#if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
slouken@0
    75
#define HI	1
slouken@0
    76
#define LO	0
slouken@0
    77
#else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
slouken@0
    78
#define HI	0
slouken@0
    79
#define LO	1
slouken@0
    80
#endif
slouken@1662
    81
static void
slouken@1668
    82
Blit1to2(SDL_BlitInfo * info)
slouken@0
    83
{
slouken@0
    84
#ifndef USE_DUFFS_LOOP
slouken@1662
    85
    int c;
slouken@0
    86
#endif
slouken@1662
    87
    int width, height;
slouken@1662
    88
    Uint8 *src, *dst;
slouken@1662
    89
    Uint16 *map;
slouken@1662
    90
    int srcskip, dstskip;
slouken@0
    91
slouken@1662
    92
    /* Set up some basic variables */
slouken@1662
    93
    width = info->d_width;
slouken@1662
    94
    height = info->d_height;
slouken@1662
    95
    src = info->s_pixels;
slouken@1662
    96
    srcskip = info->s_skip;
slouken@1662
    97
    dst = info->d_pixels;
slouken@1662
    98
    dstskip = info->d_skip;
slouken@1662
    99
    map = (Uint16 *) info->table;
slouken@0
   100
slouken@0
   101
#ifdef USE_DUFFS_LOOP
slouken@1662
   102
    while (height--) {
slouken@1662
   103
		/* *INDENT-OFF* */
slouken@0
   104
		DUFFS_LOOP(
slouken@0
   105
		{
slouken@0
   106
			*(Uint16 *)dst = map[*src++];
slouken@0
   107
			dst += 2;
slouken@0
   108
		},
slouken@0
   109
		width);
slouken@1662
   110
		/* *INDENT-ON* */
slouken@1662
   111
        src += srcskip;
slouken@1662
   112
        dst += dstskip;
slouken@1662
   113
    }
slouken@0
   114
#else
slouken@1662
   115
    /* Memory align at 4-byte boundary, if necessary */
slouken@1662
   116
    if ((long) dst & 0x03) {
slouken@1662
   117
        /* Don't do anything if width is 0 */
slouken@1662
   118
        if (width == 0) {
slouken@1662
   119
            return;
slouken@1662
   120
        }
slouken@1662
   121
        --width;
slouken@0
   122
slouken@1662
   123
        while (height--) {
slouken@1662
   124
            /* Perform copy alignment */
slouken@1662
   125
            *(Uint16 *) dst = map[*src++];
slouken@1662
   126
            dst += 2;
slouken@0
   127
slouken@1662
   128
            /* Copy in 4 pixel chunks */
slouken@1662
   129
            for (c = width / 4; c; --c) {
slouken@1662
   130
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1662
   131
                src += 2;
slouken@1662
   132
                dst += 4;
slouken@1662
   133
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1662
   134
                src += 2;
slouken@1662
   135
                dst += 4;
slouken@1662
   136
            }
slouken@1662
   137
            /* Get any leftovers */
slouken@1662
   138
            switch (width & 3) {
slouken@1662
   139
            case 3:
slouken@1662
   140
                *(Uint16 *) dst = map[*src++];
slouken@1662
   141
                dst += 2;
slouken@1662
   142
            case 2:
slouken@1662
   143
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1662
   144
                src += 2;
slouken@1662
   145
                dst += 4;
slouken@1662
   146
                break;
slouken@1662
   147
            case 1:
slouken@1662
   148
                *(Uint16 *) dst = map[*src++];
slouken@1662
   149
                dst += 2;
slouken@1662
   150
                break;
slouken@1662
   151
            }
slouken@1662
   152
            src += srcskip;
slouken@1662
   153
            dst += dstskip;
slouken@1662
   154
        }
slouken@1662
   155
    } else {
slouken@1662
   156
        while (height--) {
slouken@1662
   157
            /* Copy in 4 pixel chunks */
slouken@1662
   158
            for (c = width / 4; c; --c) {
slouken@1662
   159
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1662
   160
                src += 2;
slouken@1662
   161
                dst += 4;
slouken@1662
   162
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1662
   163
                src += 2;
slouken@1662
   164
                dst += 4;
slouken@1662
   165
            }
slouken@1662
   166
            /* Get any leftovers */
slouken@1662
   167
            switch (width & 3) {
slouken@1662
   168
            case 3:
slouken@1662
   169
                *(Uint16 *) dst = map[*src++];
slouken@1662
   170
                dst += 2;
slouken@1662
   171
            case 2:
slouken@1662
   172
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1662
   173
                src += 2;
slouken@1662
   174
                dst += 4;
slouken@1662
   175
                break;
slouken@1662
   176
            case 1:
slouken@1662
   177
                *(Uint16 *) dst = map[*src++];
slouken@1662
   178
                dst += 2;
slouken@1662
   179
                break;
slouken@1662
   180
            }
slouken@1662
   181
            src += srcskip;
slouken@1662
   182
            dst += dstskip;
slouken@1662
   183
        }
slouken@1662
   184
    }
slouken@0
   185
#endif /* USE_DUFFS_LOOP */
slouken@0
   186
}
slouken@1662
   187
static void
slouken@1668
   188
Blit1to3(SDL_BlitInfo * info)
slouken@0
   189
{
slouken@0
   190
#ifndef USE_DUFFS_LOOP
slouken@1662
   191
    int c;
slouken@0
   192
#endif
slouken@1662
   193
    int o;
slouken@1662
   194
    int width, height;
slouken@1662
   195
    Uint8 *src, *map, *dst;
slouken@1662
   196
    int srcskip, dstskip;
slouken@0
   197
slouken@1662
   198
    /* Set up some basic variables */
slouken@1662
   199
    width = info->d_width;
slouken@1662
   200
    height = info->d_height;
slouken@1662
   201
    src = info->s_pixels;
slouken@1662
   202
    srcskip = info->s_skip;
slouken@1662
   203
    dst = info->d_pixels;
slouken@1662
   204
    dstskip = info->d_skip;
slouken@1662
   205
    map = info->table;
slouken@0
   206
slouken@1662
   207
    while (height--) {
slouken@0
   208
#ifdef USE_DUFFS_LOOP
slouken@1662
   209
		/* *INDENT-OFF* */
slouken@0
   210
		DUFFS_LOOP(
slouken@0
   211
			{
slouken@0
   212
				o = *src * 4;
slouken@0
   213
				dst[0] = map[o++];
slouken@0
   214
				dst[1] = map[o++];
slouken@0
   215
				dst[2] = map[o++];
slouken@0
   216
			}
slouken@0
   217
			src++;
slouken@0
   218
			dst += 3;
slouken@0
   219
		, width);
slouken@1662
   220
		/* *INDENT-ON* */
slouken@0
   221
#else
slouken@1662
   222
        for (c = width; c; --c) {
slouken@1662
   223
            o = *src * 4;
slouken@1662
   224
            dst[0] = map[o++];
slouken@1662
   225
            dst[1] = map[o++];
slouken@1662
   226
            dst[2] = map[o++];
slouken@1662
   227
            src++;
slouken@1662
   228
            dst += 3;
slouken@1662
   229
        }
slouken@0
   230
#endif /* USE_DUFFS_LOOP */
slouken@1662
   231
        src += srcskip;
slouken@1662
   232
        dst += dstskip;
slouken@1662
   233
    }
slouken@0
   234
}
slouken@1662
   235
static void
slouken@1668
   236
Blit1to4(SDL_BlitInfo * info)
slouken@0
   237
{
slouken@0
   238
#ifndef USE_DUFFS_LOOP
slouken@1662
   239
    int c;
slouken@0
   240
#endif
slouken@1662
   241
    int width, height;
slouken@1662
   242
    Uint8 *src;
slouken@1662
   243
    Uint32 *map, *dst;
slouken@1662
   244
    int srcskip, dstskip;
slouken@0
   245
slouken@1662
   246
    /* Set up some basic variables */
slouken@1662
   247
    width = info->d_width;
slouken@1662
   248
    height = info->d_height;
slouken@1662
   249
    src = info->s_pixels;
slouken@1662
   250
    srcskip = info->s_skip;
slouken@1662
   251
    dst = (Uint32 *) info->d_pixels;
slouken@1662
   252
    dstskip = info->d_skip / 4;
slouken@1662
   253
    map = (Uint32 *) info->table;
slouken@0
   254
slouken@1662
   255
    while (height--) {
slouken@0
   256
#ifdef USE_DUFFS_LOOP
slouken@1662
   257
		/* *INDENT-OFF* */
slouken@0
   258
		DUFFS_LOOP(
slouken@0
   259
			*dst++ = map[*src++];
slouken@0
   260
		, width);
slouken@1662
   261
		/* *INDENT-ON* */
slouken@0
   262
#else
slouken@1662
   263
        for (c = width / 4; c; --c) {
slouken@1662
   264
            *dst++ = map[*src++];
slouken@1662
   265
            *dst++ = map[*src++];
slouken@1662
   266
            *dst++ = map[*src++];
slouken@1662
   267
            *dst++ = map[*src++];
slouken@1662
   268
        }
slouken@1662
   269
        switch (width & 3) {
slouken@1662
   270
        case 3:
slouken@1662
   271
            *dst++ = map[*src++];
slouken@1662
   272
        case 2:
slouken@1662
   273
            *dst++ = map[*src++];
slouken@1662
   274
        case 1:
slouken@1662
   275
            *dst++ = map[*src++];
slouken@1662
   276
        }
slouken@0
   277
#endif /* USE_DUFFS_LOOP */
slouken@1662
   278
        src += srcskip;
slouken@1662
   279
        dst += dstskip;
slouken@1662
   280
    }
slouken@0
   281
}
slouken@0
   282
slouken@1662
   283
static void
slouken@1668
   284
Blit1to1Key(SDL_BlitInfo * info)
slouken@0
   285
{
slouken@1662
   286
    int width = info->d_width;
slouken@1662
   287
    int height = info->d_height;
slouken@1662
   288
    Uint8 *src = info->s_pixels;
slouken@1662
   289
    int srcskip = info->s_skip;
slouken@1662
   290
    Uint8 *dst = info->d_pixels;
slouken@1662
   291
    int dstskip = info->d_skip;
slouken@1662
   292
    Uint8 *palmap = info->table;
slouken@1662
   293
    Uint32 ckey = info->src->colorkey;
slouken@1662
   294
slouken@1662
   295
    if (palmap) {
slouken@1662
   296
        while (height--) {
slouken@1662
   297
			/* *INDENT-OFF* */
slouken@0
   298
			DUFFS_LOOP(
slouken@0
   299
			{
slouken@0
   300
				if ( *src != ckey ) {
slouken@0
   301
				  *dst = palmap[*src];
slouken@0
   302
				}
slouken@0
   303
				dst++;
slouken@0
   304
				src++;
slouken@0
   305
			},
slouken@0
   306
			width);
slouken@1662
   307
			/* *INDENT-ON* */
slouken@1662
   308
            src += srcskip;
slouken@1662
   309
            dst += dstskip;
slouken@1662
   310
        }
slouken@1662
   311
    } else {
slouken@1662
   312
        while (height--) {
slouken@1662
   313
			/* *INDENT-OFF* */
slouken@0
   314
			DUFFS_LOOP(
slouken@0
   315
			{
slouken@0
   316
				if ( *src != ckey ) {
slouken@0
   317
				  *dst = *src;
slouken@0
   318
				}
slouken@0
   319
				dst++;
slouken@0
   320
				src++;
slouken@0
   321
			},
slouken@0
   322
			width);
slouken@1662
   323
			/* *INDENT-ON* */
slouken@1662
   324
            src += srcskip;
slouken@1662
   325
            dst += dstskip;
slouken@1662
   326
        }
slouken@1662
   327
    }
slouken@0
   328
}
slouken@0
   329
slouken@1662
   330
static void
slouken@1668
   331
Blit1to2Key(SDL_BlitInfo * info)
slouken@0
   332
{
slouken@1662
   333
    int width = info->d_width;
slouken@1662
   334
    int height = info->d_height;
slouken@1662
   335
    Uint8 *src = info->s_pixels;
slouken@1662
   336
    int srcskip = info->s_skip;
slouken@1662
   337
    Uint16 *dstp = (Uint16 *) info->d_pixels;
slouken@1662
   338
    int dstskip = info->d_skip;
slouken@1662
   339
    Uint16 *palmap = (Uint16 *) info->table;
slouken@1662
   340
    Uint32 ckey = info->src->colorkey;
slouken@0
   341
slouken@1662
   342
    /* Set up some basic variables */
slouken@1662
   343
    dstskip /= 2;
slouken@0
   344
slouken@1662
   345
    while (height--) {
slouken@1662
   346
		/* *INDENT-OFF* */
slouken@0
   347
		DUFFS_LOOP(
slouken@0
   348
		{
slouken@0
   349
			if ( *src != ckey ) {
slouken@0
   350
				*dstp=palmap[*src];
slouken@0
   351
			}
slouken@0
   352
			src++;
slouken@0
   353
			dstp++;
slouken@0
   354
		},
slouken@0
   355
		width);
slouken@1662
   356
		/* *INDENT-ON* */
slouken@1662
   357
        src += srcskip;
slouken@1662
   358
        dstp += dstskip;
slouken@1662
   359
    }
slouken@0
   360
}
slouken@0
   361
slouken@1662
   362
static void
slouken@1668
   363
Blit1to3Key(SDL_BlitInfo * info)
slouken@0
   364
{
slouken@1662
   365
    int width = info->d_width;
slouken@1662
   366
    int height = info->d_height;
slouken@1662
   367
    Uint8 *src = info->s_pixels;
slouken@1662
   368
    int srcskip = info->s_skip;
slouken@1662
   369
    Uint8 *dst = info->d_pixels;
slouken@1662
   370
    int dstskip = info->d_skip;
slouken@1662
   371
    Uint8 *palmap = info->table;
slouken@1662
   372
    Uint32 ckey = info->src->colorkey;
slouken@1662
   373
    int o;
slouken@0
   374
slouken@1662
   375
    while (height--) {
slouken@1662
   376
		/* *INDENT-OFF* */
slouken@0
   377
		DUFFS_LOOP(
slouken@0
   378
		{
slouken@0
   379
			if ( *src != ckey ) {
slouken@0
   380
				o = *src * 4;
slouken@0
   381
				dst[0] = palmap[o++];
slouken@0
   382
				dst[1] = palmap[o++];
slouken@0
   383
				dst[2] = palmap[o++];
slouken@0
   384
			}
slouken@0
   385
			src++;
slouken@0
   386
			dst += 3;
slouken@0
   387
		},
slouken@0
   388
		width);
slouken@1662
   389
		/* *INDENT-ON* */
slouken@1662
   390
        src += srcskip;
slouken@1662
   391
        dst += dstskip;
slouken@1662
   392
    }
slouken@0
   393
}
slouken@0
   394
slouken@1662
   395
static void
slouken@1668
   396
Blit1to4Key(SDL_BlitInfo * info)
slouken@0
   397
{
slouken@1662
   398
    int width = info->d_width;
slouken@1662
   399
    int height = info->d_height;
slouken@1662
   400
    Uint8 *src = info->s_pixels;
slouken@1662
   401
    int srcskip = info->s_skip;
slouken@1662
   402
    Uint32 *dstp = (Uint32 *) info->d_pixels;
slouken@1662
   403
    int dstskip = info->d_skip;
slouken@1662
   404
    Uint32 *palmap = (Uint32 *) info->table;
slouken@1662
   405
    Uint32 ckey = info->src->colorkey;
slouken@0
   406
slouken@1662
   407
    /* Set up some basic variables */
slouken@1662
   408
    dstskip /= 4;
slouken@0
   409
slouken@1662
   410
    while (height--) {
slouken@1662
   411
		/* *INDENT-OFF* */
slouken@0
   412
		DUFFS_LOOP(
slouken@0
   413
		{
slouken@0
   414
			if ( *src != ckey ) {
slouken@0
   415
				*dstp = palmap[*src];
slouken@0
   416
			}
slouken@0
   417
			src++;
slouken@0
   418
			dstp++;
slouken@0
   419
		},
slouken@0
   420
		width);
slouken@1662
   421
		/* *INDENT-ON* */
slouken@1662
   422
        src += srcskip;
slouken@1662
   423
        dstp += dstskip;
slouken@1662
   424
    }
slouken@0
   425
}
slouken@0
   426
slouken@1662
   427
static void
slouken@1668
   428
Blit1toNAlpha(SDL_BlitInfo * info)
slouken@0
   429
{
slouken@1662
   430
    int width = info->d_width;
slouken@1662
   431
    int height = info->d_height;
slouken@1662
   432
    Uint8 *src = info->s_pixels;
slouken@1662
   433
    int srcskip = info->s_skip;
slouken@1662
   434
    Uint8 *dst = info->d_pixels;
slouken@1662
   435
    int dstskip = info->d_skip;
slouken@1662
   436
    SDL_PixelFormat *dstfmt = info->dst;
slouken@1662
   437
    const SDL_Color *srcpal = info->src->palette->colors;
slouken@1662
   438
    int dstbpp;
slouken@1662
   439
    const int A = info->src->alpha;
slouken@0
   440
slouken@1662
   441
    /* Set up some basic variables */
slouken@1662
   442
    dstbpp = dstfmt->BytesPerPixel;
slouken@0
   443
slouken@1662
   444
    while (height--) {
slouken@1662
   445
        int sR, sG, sB;
slouken@1662
   446
        int dR, dG, dB;
slouken@1662
   447
	    	/* *INDENT-OFF* */
slouken@0
   448
	    	DUFFS_LOOP4(
slouken@0
   449
			{
slouken@0
   450
			        Uint32 pixel;
slouken@0
   451
				sR = srcpal[*src].r;
slouken@0
   452
				sG = srcpal[*src].g;
slouken@0
   453
				sB = srcpal[*src].b;
slouken@0
   454
				DISEMBLE_RGB(dst, dstbpp, dstfmt,
slouken@0
   455
					     pixel, dR, dG, dB);
slouken@0
   456
				ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
slouken@0
   457
			  	ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
slouken@0
   458
				src++;
slouken@0
   459
				dst += dstbpp;
slouken@0
   460
			},
slouken@0
   461
			width);
slouken@1662
   462
	    	/* *INDENT-ON* */
slouken@1662
   463
        src += srcskip;
slouken@1662
   464
        dst += dstskip;
slouken@1662
   465
    }
slouken@0
   466
}
slouken@0
   467
slouken@1662
   468
static void
slouken@1668
   469
Blit1toNAlphaKey(SDL_BlitInfo * info)
slouken@0
   470
{
slouken@1662
   471
    int width = info->d_width;
slouken@1662
   472
    int height = info->d_height;
slouken@1662
   473
    Uint8 *src = info->s_pixels;
slouken@1662
   474
    int srcskip = info->s_skip;
slouken@1662
   475
    Uint8 *dst = info->d_pixels;
slouken@1662
   476
    int dstskip = info->d_skip;
slouken@1662
   477
    SDL_PixelFormat *srcfmt = info->src;
slouken@1662
   478
    SDL_PixelFormat *dstfmt = info->dst;
slouken@1662
   479
    const SDL_Color *srcpal = info->src->palette->colors;
slouken@1662
   480
    Uint32 ckey = srcfmt->colorkey;
slouken@1662
   481
    int dstbpp;
slouken@1662
   482
    const int A = srcfmt->alpha;
slouken@0
   483
slouken@1662
   484
    /* Set up some basic variables */
slouken@1662
   485
    dstbpp = dstfmt->BytesPerPixel;
slouken@0
   486
slouken@1662
   487
    while (height--) {
slouken@1662
   488
        int sR, sG, sB;
slouken@1662
   489
        int dR, dG, dB;
slouken@1662
   490
		/* *INDENT-OFF* */
slouken@0
   491
		DUFFS_LOOP(
slouken@0
   492
		{
slouken@0
   493
			if ( *src != ckey ) {
slouken@0
   494
			        Uint32 pixel;
slouken@0
   495
				sR = srcpal[*src].r;
slouken@0
   496
				sG = srcpal[*src].g;
slouken@0
   497
				sB = srcpal[*src].b;
slouken@0
   498
				DISEMBLE_RGB(dst, dstbpp, dstfmt,
slouken@0
   499
							pixel, dR, dG, dB);
slouken@0
   500
				ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
slouken@0
   501
			  	ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
slouken@0
   502
			}
slouken@0
   503
			src++;
slouken@0
   504
			dst += dstbpp;
slouken@0
   505
		},
slouken@0
   506
		width);
slouken@1662
   507
		/* *INDENT-ON* */
slouken@1662
   508
        src += srcskip;
slouken@1662
   509
        dst += dstskip;
slouken@1662
   510
    }
slouken@0
   511
}
slouken@0
   512
slouken@0
   513
static SDL_loblit one_blit[] = {
slouken@1662
   514
    NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4
slouken@0
   515
};
slouken@0
   516
slouken@0
   517
static SDL_loblit one_blitkey[] = {
slouken@1662
   518
    NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key
slouken@0
   519
};
slouken@0
   520
slouken@1662
   521
SDL_loblit
slouken@1668
   522
SDL_CalculateBlit1(SDL_Surface * surface, int blit_index)
slouken@0
   523
{
slouken@1662
   524
    int which;
slouken@1662
   525
    SDL_PixelFormat *dstfmt;
slouken@0
   526
slouken@1662
   527
    dstfmt = surface->map->dst->format;
slouken@1662
   528
    if (dstfmt->BitsPerPixel < 8) {
slouken@1662
   529
        which = 0;
slouken@1662
   530
    } else {
slouken@1662
   531
        which = dstfmt->BytesPerPixel;
slouken@1662
   532
    }
slouken@1662
   533
    switch (blit_index) {
slouken@1662
   534
    case 0:                    /* copy */
slouken@1662
   535
        return one_blit[which];
slouken@0
   536
slouken@1662
   537
    case 1:                    /* colorkey */
slouken@1662
   538
        return one_blitkey[which];
slouken@0
   539
slouken@1662
   540
    case 2:                    /* alpha */
slouken@1662
   541
        /* Supporting 8bpp->8bpp alpha is doable but requires lots of
slouken@1662
   542
           tables which consume space and takes time to precompute,
slouken@1662
   543
           so is better left to the user */
slouken@1662
   544
        return which >= 2 ? Blit1toNAlpha : NULL;
slouken@0
   545
slouken@1662
   546
    case 3:                    /* alpha + colorkey */
slouken@1662
   547
        return which >= 2 ? Blit1toNAlphaKey : NULL;
slouken@0
   548
slouken@1662
   549
    }
slouken@1662
   550
    return NULL;
slouken@0
   551
}
slouken@1662
   552
slouken@1662
   553
/* vi: set ts=4 sw=4 expandtab: */