src/video/SDL_blit_1.c
author Sam Lantinga <slouken@lokigames.com>
Sat, 07 Jul 2001 20:20:17 +0000
changeset 91 e85e03f195b4
parent 0 74212992fb08
child 252 e8157fcb3114
permissions -rw-r--r--
From: "Markus F.X.J. Oberhumer"
Subject: SDL CVS patches

below you will find some small patches against the
current SDL CVS.

It adresses these things:

1) Use "&" instead of "%" in some cases. For negative
signed integers (x % 8) is not always (x & 7),
and the compiler can produce slightly faster
code when using "&" here.

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