src/video/SDL_blit_1.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 17 Aug 2007 06:21:58 +0000
changeset 2262 bee005ace1bf
parent 2257 340942cfda48
child 2267 c785543d1843
permissions -rw-r--r--
Work in progress: merging new texture features into SDL blit system
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@1895
    31
static void
slouken@1895
    32
Blit1to1(SDL_BlitInfo * info)
slouken@0
    33
{
slouken@0
    34
#ifndef USE_DUFFS_LOOP
slouken@1895
    35
    int c;
slouken@0
    36
#endif
slouken@1895
    37
    int width, height;
slouken@1895
    38
    Uint8 *src, *map, *dst;
slouken@1895
    39
    int srcskip, dstskip;
slouken@0
    40
slouken@1895
    41
    /* Set up some basic variables */
slouken@2262
    42
    width = info->dst_w;
slouken@2262
    43
    height = info->dst_h;
slouken@2262
    44
    src = info->src;
slouken@1895
    45
    srcskip = info->s_skip;
slouken@2262
    46
    dst = info->dst;
slouken@2262
    47
    dstskip = info->dst_pitch;
slouken@1895
    48
    map = info->table;
slouken@0
    49
slouken@1895
    50
    while (height--) {
slouken@0
    51
#ifdef USE_DUFFS_LOOP
slouken@1895
    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@1895
    60
        /* *INDENT-ON* */
slouken@0
    61
#else
slouken@1895
    62
        for (c = width; c; --c) {
slouken@1895
    63
            *dst = map[*src];
slouken@1895
    64
            dst++;
slouken@1895
    65
            src++;
slouken@1895
    66
        }
slouken@0
    67
#endif
slouken@1895
    68
        src += srcskip;
slouken@1895
    69
        dst += dstskip;
slouken@1895
    70
    }
slouken@0
    71
}
slouken@1895
    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@1895
    81
static void
slouken@1895
    82
Blit1to2(SDL_BlitInfo * info)
slouken@0
    83
{
slouken@0
    84
#ifndef USE_DUFFS_LOOP
slouken@1895
    85
    int c;
slouken@0
    86
#endif
slouken@1895
    87
    int width, height;
slouken@1895
    88
    Uint8 *src, *dst;
slouken@1895
    89
    Uint16 *map;
slouken@1895
    90
    int srcskip, dstskip;
slouken@0
    91
slouken@1895
    92
    /* Set up some basic variables */
slouken@2262
    93
    width = info->dst_w;
slouken@2262
    94
    height = info->dst_h;
slouken@2262
    95
    src = info->src;
slouken@1895
    96
    srcskip = info->s_skip;
slouken@2262
    97
    dst = info->dst;
slouken@2262
    98
    dstskip = info->dst_pitch;
slouken@1895
    99
    map = (Uint16 *) info->table;
slouken@0
   100
slouken@0
   101
#ifdef USE_DUFFS_LOOP
slouken@1895
   102
    while (height--) {
slouken@1895
   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@1895
   110
		/* *INDENT-ON* */
slouken@1895
   111
        src += srcskip;
slouken@1895
   112
        dst += dstskip;
slouken@1895
   113
    }
slouken@0
   114
#else
slouken@1895
   115
    /* Memory align at 4-byte boundary, if necessary */
slouken@1895
   116
    if ((long) dst & 0x03) {
slouken@1895
   117
        /* Don't do anything if width is 0 */
slouken@1895
   118
        if (width == 0) {
slouken@1895
   119
            return;
slouken@1895
   120
        }
slouken@1895
   121
        --width;
slouken@0
   122
slouken@1895
   123
        while (height--) {
slouken@1895
   124
            /* Perform copy alignment */
slouken@1895
   125
            *(Uint16 *) dst = map[*src++];
slouken@1895
   126
            dst += 2;
slouken@0
   127
slouken@1895
   128
            /* Copy in 4 pixel chunks */
slouken@1895
   129
            for (c = width / 4; c; --c) {
slouken@1895
   130
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1895
   131
                src += 2;
slouken@1895
   132
                dst += 4;
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
            }
slouken@1895
   137
            /* Get any leftovers */
slouken@1895
   138
            switch (width & 3) {
slouken@1895
   139
            case 3:
slouken@1895
   140
                *(Uint16 *) dst = map[*src++];
slouken@1895
   141
                dst += 2;
slouken@1895
   142
            case 2:
slouken@1895
   143
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1895
   144
                src += 2;
slouken@1895
   145
                dst += 4;
slouken@1895
   146
                break;
slouken@1895
   147
            case 1:
slouken@1895
   148
                *(Uint16 *) dst = map[*src++];
slouken@1895
   149
                dst += 2;
slouken@1895
   150
                break;
slouken@1895
   151
            }
slouken@1895
   152
            src += srcskip;
slouken@1895
   153
            dst += dstskip;
slouken@1895
   154
        }
slouken@1895
   155
    } else {
slouken@1895
   156
        while (height--) {
slouken@1895
   157
            /* Copy in 4 pixel chunks */
slouken@1895
   158
            for (c = width / 4; c; --c) {
slouken@1895
   159
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1895
   160
                src += 2;
slouken@1895
   161
                dst += 4;
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
            }
slouken@1895
   166
            /* Get any leftovers */
slouken@1895
   167
            switch (width & 3) {
slouken@1895
   168
            case 3:
slouken@1895
   169
                *(Uint16 *) dst = map[*src++];
slouken@1895
   170
                dst += 2;
slouken@1895
   171
            case 2:
slouken@1895
   172
                *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
slouken@1895
   173
                src += 2;
slouken@1895
   174
                dst += 4;
slouken@1895
   175
                break;
slouken@1895
   176
            case 1:
slouken@1895
   177
                *(Uint16 *) dst = map[*src++];
slouken@1895
   178
                dst += 2;
slouken@1895
   179
                break;
slouken@1895
   180
            }
slouken@1895
   181
            src += srcskip;
slouken@1895
   182
            dst += dstskip;
slouken@1895
   183
        }
slouken@1895
   184
    }
slouken@0
   185
#endif /* USE_DUFFS_LOOP */
slouken@0
   186
}
slouken@1895
   187
static void
slouken@1895
   188
Blit1to3(SDL_BlitInfo * info)
slouken@0
   189
{
slouken@0
   190
#ifndef USE_DUFFS_LOOP
slouken@1895
   191
    int c;
slouken@0
   192
#endif
slouken@1895
   193
    int o;
slouken@1895
   194
    int width, height;
slouken@1895
   195
    Uint8 *src, *map, *dst;
slouken@1895
   196
    int srcskip, dstskip;
slouken@0
   197
slouken@1895
   198
    /* Set up some basic variables */
slouken@2262
   199
    width = info->dst_w;
slouken@2262
   200
    height = info->dst_h;
slouken@2262
   201
    src = info->src;
slouken@1895
   202
    srcskip = info->s_skip;
slouken@2262
   203
    dst = info->dst;
slouken@2262
   204
    dstskip = info->dst_pitch;
slouken@1895
   205
    map = info->table;
slouken@0
   206
slouken@1895
   207
    while (height--) {
slouken@0
   208
#ifdef USE_DUFFS_LOOP
slouken@1895
   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@1895
   220
		/* *INDENT-ON* */
slouken@0
   221
#else
slouken@1895
   222
        for (c = width; c; --c) {
slouken@1895
   223
            o = *src * 4;
slouken@1895
   224
            dst[0] = map[o++];
slouken@1895
   225
            dst[1] = map[o++];
slouken@1895
   226
            dst[2] = map[o++];
slouken@1895
   227
            src++;
slouken@1895
   228
            dst += 3;
slouken@1895
   229
        }
slouken@0
   230
#endif /* USE_DUFFS_LOOP */
slouken@1895
   231
        src += srcskip;
slouken@1895
   232
        dst += dstskip;
slouken@1895
   233
    }
slouken@0
   234
}
slouken@1895
   235
static void
slouken@1895
   236
Blit1to4(SDL_BlitInfo * info)
slouken@0
   237
{
slouken@0
   238
#ifndef USE_DUFFS_LOOP
slouken@1895
   239
    int c;
slouken@0
   240
#endif
slouken@1895
   241
    int width, height;
slouken@1895
   242
    Uint8 *src;
slouken@1895
   243
    Uint32 *map, *dst;
slouken@1895
   244
    int srcskip, dstskip;
slouken@0
   245
slouken@1895
   246
    /* Set up some basic variables */
slouken@2262
   247
    width = info->dst_w;
slouken@2262
   248
    height = info->dst_h;
slouken@2262
   249
    src = info->src;
slouken@1895
   250
    srcskip = info->s_skip;
slouken@2262
   251
    dst = (Uint32 *) info->dst;
slouken@2262
   252
    dstskip = info->dst_pitch / 4;
slouken@1895
   253
    map = (Uint32 *) info->table;
slouken@0
   254
slouken@1895
   255
    while (height--) {
slouken@0
   256
#ifdef USE_DUFFS_LOOP
slouken@1895
   257
		/* *INDENT-OFF* */
slouken@0
   258
		DUFFS_LOOP(
slouken@0
   259
			*dst++ = map[*src++];
slouken@0
   260
		, width);
slouken@1895
   261
		/* *INDENT-ON* */
slouken@0
   262
#else
slouken@1895
   263
        for (c = width / 4; c; --c) {
slouken@1895
   264
            *dst++ = map[*src++];
slouken@1895
   265
            *dst++ = map[*src++];
slouken@1895
   266
            *dst++ = map[*src++];
slouken@1895
   267
            *dst++ = map[*src++];
slouken@1895
   268
        }
slouken@1895
   269
        switch (width & 3) {
slouken@1895
   270
        case 3:
slouken@1895
   271
            *dst++ = map[*src++];
slouken@1895
   272
        case 2:
slouken@1895
   273
            *dst++ = map[*src++];
slouken@1895
   274
        case 1:
slouken@1895
   275
            *dst++ = map[*src++];
slouken@1895
   276
        }
slouken@0
   277
#endif /* USE_DUFFS_LOOP */
slouken@1895
   278
        src += srcskip;
slouken@1895
   279
        dst += dstskip;
slouken@1895
   280
    }
slouken@0
   281
}
slouken@0
   282
slouken@1895
   283
static void
slouken@1895
   284
Blit1to1Key(SDL_BlitInfo * info)
slouken@0
   285
{
slouken@2262
   286
    int width = info->dst_w;
slouken@2262
   287
    int height = info->dst_h;
slouken@2262
   288
    Uint8 *src = info->src;
slouken@1895
   289
    int srcskip = info->s_skip;
slouken@2262
   290
    Uint8 *dst = info->dst;
slouken@2262
   291
    int dstskip = info->dst_pitch;
slouken@1895
   292
    Uint8 *palmap = info->table;
slouken@2257
   293
    Uint32 ckey = info->ckey;
slouken@1895
   294
slouken@1895
   295
    if (palmap) {
slouken@1895
   296
        while (height--) {
slouken@1895
   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@1895
   307
			/* *INDENT-ON* */
slouken@1895
   308
            src += srcskip;
slouken@1895
   309
            dst += dstskip;
slouken@1895
   310
        }
slouken@1895
   311
    } else {
slouken@1895
   312
        while (height--) {
slouken@1895
   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@1895
   323
			/* *INDENT-ON* */
slouken@1895
   324
            src += srcskip;
slouken@1895
   325
            dst += dstskip;
slouken@1895
   326
        }
slouken@1895
   327
    }
slouken@0
   328
}
slouken@0
   329
slouken@1895
   330
static void
slouken@1895
   331
Blit1to2Key(SDL_BlitInfo * info)
slouken@0
   332
{
slouken@2262
   333
    int width = info->dst_w;
slouken@2262
   334
    int height = info->dst_h;
slouken@2262
   335
    Uint8 *src = info->src;
slouken@1895
   336
    int srcskip = info->s_skip;
slouken@2262
   337
    Uint16 *dstp = (Uint16 *) info->dst;
slouken@2262
   338
    int dstskip = info->dst_pitch;
slouken@1895
   339
    Uint16 *palmap = (Uint16 *) info->table;
slouken@2257
   340
    Uint32 ckey = info->ckey;
slouken@0
   341
slouken@1895
   342
    /* Set up some basic variables */
slouken@1895
   343
    dstskip /= 2;
slouken@0
   344
slouken@1895
   345
    while (height--) {
slouken@1895
   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@1895
   356
		/* *INDENT-ON* */
slouken@1895
   357
        src += srcskip;
slouken@1895
   358
        dstp += dstskip;
slouken@1895
   359
    }
slouken@0
   360
}
slouken@0
   361
slouken@1895
   362
static void
slouken@1895
   363
Blit1to3Key(SDL_BlitInfo * info)
slouken@0
   364
{
slouken@2262
   365
    int width = info->dst_w;
slouken@2262
   366
    int height = info->dst_h;
slouken@2262
   367
    Uint8 *src = info->src;
slouken@1895
   368
    int srcskip = info->s_skip;
slouken@2262
   369
    Uint8 *dst = info->dst;
slouken@2262
   370
    int dstskip = info->dst_pitch;
slouken@1895
   371
    Uint8 *palmap = info->table;
slouken@2257
   372
    Uint32 ckey = info->ckey;
slouken@1895
   373
    int o;
slouken@0
   374
slouken@1895
   375
    while (height--) {
slouken@1895
   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@1895
   389
		/* *INDENT-ON* */
slouken@1895
   390
        src += srcskip;
slouken@1895
   391
        dst += dstskip;
slouken@1895
   392
    }
slouken@0
   393
}
slouken@0
   394
slouken@1895
   395
static void
slouken@1895
   396
Blit1to4Key(SDL_BlitInfo * info)
slouken@0
   397
{
slouken@2262
   398
    int width = info->dst_w;
slouken@2262
   399
    int height = info->dst_h;
slouken@2262
   400
    Uint8 *src = info->src;
slouken@1895
   401
    int srcskip = info->s_skip;
slouken@2262
   402
    Uint32 *dstp = (Uint32 *) info->dst;
slouken@2262
   403
    int dstskip = info->dst_pitch;
slouken@1895
   404
    Uint32 *palmap = (Uint32 *) info->table;
slouken@2257
   405
    Uint32 ckey = info->ckey;
slouken@0
   406
slouken@1895
   407
    /* Set up some basic variables */
slouken@1895
   408
    dstskip /= 4;
slouken@0
   409
slouken@1895
   410
    while (height--) {
slouken@1895
   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@1895
   421
		/* *INDENT-ON* */
slouken@1895
   422
        src += srcskip;
slouken@1895
   423
        dstp += dstskip;
slouken@1895
   424
    }
slouken@0
   425
}
slouken@0
   426
slouken@1895
   427
static void
slouken@1895
   428
Blit1toNAlpha(SDL_BlitInfo * info)
slouken@0
   429
{
slouken@2262
   430
    int width = info->dst_w;
slouken@2262
   431
    int height = info->dst_h;
slouken@2262
   432
    Uint8 *src = info->src;
slouken@1895
   433
    int srcskip = info->s_skip;
slouken@2262
   434
    Uint8 *dst = info->dst;
slouken@2262
   435
    int dstskip = info->dst_pitch;
slouken@1895
   436
    SDL_PixelFormat *dstfmt = info->dst;
slouken@1895
   437
    const SDL_Color *srcpal = info->src->palette->colors;
slouken@1895
   438
    int dstbpp;
slouken@2257
   439
    const int A = (info->cmod >> 24);
slouken@0
   440
slouken@1895
   441
    /* Set up some basic variables */
slouken@1895
   442
    dstbpp = dstfmt->BytesPerPixel;
slouken@0
   443
slouken@1895
   444
    while (height--) {
slouken@1895
   445
        int sR, sG, sB;
slouken@1895
   446
        int dR, dG, dB;
slouken@1895
   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@1895
   462
	    	/* *INDENT-ON* */
slouken@1895
   463
        src += srcskip;
slouken@1895
   464
        dst += dstskip;
slouken@1895
   465
    }
slouken@0
   466
}
slouken@0
   467
slouken@1895
   468
static void
slouken@1895
   469
Blit1toNAlphaKey(SDL_BlitInfo * info)
slouken@0
   470
{
slouken@2262
   471
    int width = info->dst_w;
slouken@2262
   472
    int height = info->dst_h;
slouken@2262
   473
    Uint8 *src = info->src;
slouken@1895
   474
    int srcskip = info->s_skip;
slouken@2262
   475
    Uint8 *dst = info->dst;
slouken@2262
   476
    int dstskip = info->dst_pitch;
slouken@1895
   477
    SDL_PixelFormat *srcfmt = info->src;
slouken@1895
   478
    SDL_PixelFormat *dstfmt = info->dst;
slouken@1895
   479
    const SDL_Color *srcpal = info->src->palette->colors;
slouken@2257
   480
    Uint32 ckey = info->ckey;
slouken@1895
   481
    int dstbpp;
slouken@2257
   482
    const int A = (info->cmod >> 24);
slouken@0
   483
slouken@1895
   484
    /* Set up some basic variables */
slouken@1895
   485
    dstbpp = dstfmt->BytesPerPixel;
slouken@0
   486
slouken@1895
   487
    while (height--) {
slouken@1895
   488
        int sR, sG, sB;
slouken@1895
   489
        int dR, dG, dB;
slouken@1895
   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@1895
   507
		/* *INDENT-ON* */
slouken@1895
   508
        src += srcskip;
slouken@1895
   509
        dst += dstskip;
slouken@1895
   510
    }
slouken@0
   511
}
slouken@0
   512
slouken@0
   513
static SDL_loblit one_blit[] = {
slouken@1895
   514
    NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4
slouken@0
   515
};
slouken@0
   516
slouken@0
   517
static SDL_loblit one_blitkey[] = {
slouken@1895
   518
    NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key
slouken@0
   519
};
slouken@0
   520
slouken@1895
   521
SDL_loblit
slouken@1895
   522
SDL_CalculateBlit1(SDL_Surface * surface, int blit_index)
slouken@0
   523
{
slouken@1895
   524
    int which;
slouken@1895
   525
    SDL_PixelFormat *dstfmt;
slouken@0
   526
slouken@1895
   527
    dstfmt = surface->map->dst->format;
slouken@1895
   528
    if (dstfmt->BitsPerPixel < 8) {
slouken@1895
   529
        which = 0;
slouken@1895
   530
    } else {
slouken@1895
   531
        which = dstfmt->BytesPerPixel;
slouken@1895
   532
    }
slouken@1895
   533
    switch (blit_index) {
slouken@1895
   534
    case 0:                    /* copy */
slouken@1895
   535
        return one_blit[which];
slouken@0
   536
slouken@1895
   537
    case 1:                    /* colorkey */
slouken@1895
   538
        return one_blitkey[which];
slouken@0
   539
slouken@1895
   540
    case 2:                    /* alpha */
slouken@1895
   541
        /* Supporting 8bpp->8bpp alpha is doable but requires lots of
slouken@1895
   542
           tables which consume space and takes time to precompute,
slouken@1895
   543
           so is better left to the user */
slouken@1895
   544
        return which >= 2 ? Blit1toNAlpha : NULL;
slouken@0
   545
slouken@1895
   546
    case 3:                    /* alpha + colorkey */
slouken@1895
   547
        return which >= 2 ? Blit1toNAlphaKey : NULL;
slouken@0
   548
slouken@1895
   549
    }
slouken@1895
   550
    return NULL;
slouken@0
   551
}
slouken@1895
   552
slouken@1895
   553
/* vi: set ts=4 sw=4 expandtab: */