src/video/SDL_blit_A.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 Apr 2005 10:19:22 +0000
changeset 1047 ffaaf7ecf685
parent 880 9ef41050100c
child 1162 2651158f59b8
permissions -rw-r--r--
Altivec-optimized blitters!

Vast majority of this work is compliments of Bob Ippolito.

http://www.devolution.com/pipermail/sdl/2005-February/067466.html and many
other posts.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 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@252
    20
    slouken@libsdl.org
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
slouken@880
    34
#if (defined(i386) || defined(__x86_64__)) && defined(__GNUC__) && defined(USE_ASMBLIT)
slouken@880
    35
#define MMX_ASMBLIT
slouken@880
    36
#endif
slouken@880
    37
slouken@739
    38
/* Function to check the CPU flags */
slouken@739
    39
#include "SDL_cpuinfo.h"
icculus@1047
    40
#ifdef MMX_ASMBLIT
slouken@689
    41
#include "mmx.h"
slouken@689
    42
#endif
slouken@689
    43
slouken@0
    44
/* Functions to perform alpha blended blitting */
slouken@0
    45
slouken@0
    46
/* N->1 blending with per-surface alpha */
slouken@0
    47
static void BlitNto1SurfaceAlpha(SDL_BlitInfo *info)
slouken@0
    48
{
slouken@0
    49
	int width = info->d_width;
slouken@0
    50
	int height = info->d_height;
slouken@0
    51
	Uint8 *src = info->s_pixels;
slouken@0
    52
	int srcskip = info->s_skip;
slouken@0
    53
	Uint8 *dst = info->d_pixels;
slouken@0
    54
	int dstskip = info->d_skip;
slouken@0
    55
	Uint8 *palmap = info->table;
slouken@0
    56
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
    57
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
    58
	int srcbpp = srcfmt->BytesPerPixel;
slouken@0
    59
slouken@0
    60
	const unsigned A = srcfmt->alpha;
slouken@0
    61
slouken@0
    62
	while ( height-- ) {
slouken@0
    63
	    DUFFS_LOOP4(
slouken@0
    64
	    {
slouken@0
    65
		Uint32 pixel;
slouken@0
    66
		unsigned sR;
slouken@0
    67
		unsigned sG;
slouken@0
    68
		unsigned sB;
slouken@0
    69
		unsigned dR;
slouken@0
    70
		unsigned dG;
slouken@0
    71
		unsigned dB;
slouken@0
    72
		DISEMBLE_RGB(src, srcbpp, srcfmt, pixel, sR, sG, sB);
slouken@0
    73
		dR = dstfmt->palette->colors[*dst].r;
slouken@0
    74
		dG = dstfmt->palette->colors[*dst].g;
slouken@0
    75
		dB = dstfmt->palette->colors[*dst].b;
slouken@0
    76
		ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
slouken@0
    77
		dR &= 0xff;
slouken@0
    78
		dG &= 0xff;
slouken@0
    79
		dB &= 0xff;
slouken@0
    80
		/* Pack RGB into 8bit pixel */
slouken@0
    81
		if ( palmap == NULL ) {
slouken@0
    82
		    *dst =((dR>>5)<<(3+2))|
slouken@0
    83
			  ((dG>>5)<<(2))|
slouken@0
    84
			  ((dB>>6)<<(0));
slouken@0
    85
		} else {
slouken@0
    86
		    *dst = palmap[((dR>>5)<<(3+2))|
slouken@0
    87
				  ((dG>>5)<<(2))  |
slouken@0
    88
				  ((dB>>6)<<(0))];
slouken@0
    89
		}
slouken@0
    90
		dst++;
slouken@0
    91
		src += srcbpp;
slouken@0
    92
	    },
slouken@0
    93
	    width);
slouken@0
    94
	    src += srcskip;
slouken@0
    95
	    dst += dstskip;
slouken@0
    96
	}
slouken@0
    97
}
slouken@0
    98
slouken@0
    99
/* N->1 blending with pixel alpha */
slouken@0
   100
static void BlitNto1PixelAlpha(SDL_BlitInfo *info)
slouken@0
   101
{
slouken@0
   102
	int width = info->d_width;
slouken@0
   103
	int height = info->d_height;
slouken@0
   104
	Uint8 *src = info->s_pixels;
slouken@0
   105
	int srcskip = info->s_skip;
slouken@0
   106
	Uint8 *dst = info->d_pixels;
slouken@0
   107
	int dstskip = info->d_skip;
slouken@0
   108
	Uint8 *palmap = info->table;
slouken@0
   109
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
   110
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
   111
	int srcbpp = srcfmt->BytesPerPixel;
slouken@0
   112
slouken@0
   113
	/* FIXME: fix alpha bit field expansion here too? */
slouken@0
   114
	while ( height-- ) {
slouken@0
   115
	    DUFFS_LOOP4(
slouken@0
   116
	    {
slouken@0
   117
		Uint32 pixel;
slouken@0
   118
		unsigned sR;
slouken@0
   119
		unsigned sG;
slouken@0
   120
		unsigned sB;
slouken@0
   121
		unsigned sA;
slouken@0
   122
		unsigned dR;
slouken@0
   123
		unsigned dG;
slouken@0
   124
		unsigned dB;
slouken@0
   125
		DISEMBLE_RGBA(src,srcbpp,srcfmt,pixel,sR,sG,sB,sA);
slouken@0
   126
		dR = dstfmt->palette->colors[*dst].r;
slouken@0
   127
		dG = dstfmt->palette->colors[*dst].g;
slouken@0
   128
		dB = dstfmt->palette->colors[*dst].b;
slouken@0
   129
		ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
slouken@0
   130
		dR &= 0xff;
slouken@0
   131
		dG &= 0xff;
slouken@0
   132
		dB &= 0xff;
slouken@0
   133
		/* Pack RGB into 8bit pixel */
slouken@0
   134
		if ( palmap == NULL ) {
slouken@0
   135
		    *dst =((dR>>5)<<(3+2))|
slouken@0
   136
			  ((dG>>5)<<(2))|
slouken@0
   137
			  ((dB>>6)<<(0));
slouken@0
   138
		} else {
slouken@0
   139
		    *dst = palmap[((dR>>5)<<(3+2))|
slouken@0
   140
				  ((dG>>5)<<(2))  |
slouken@0
   141
				  ((dB>>6)<<(0))  ];
slouken@0
   142
		}
slouken@0
   143
		dst++;
slouken@0
   144
		src += srcbpp;
slouken@0
   145
	    },
slouken@0
   146
	    width);
slouken@0
   147
	    src += srcskip;
slouken@0
   148
	    dst += dstskip;
slouken@0
   149
	}
slouken@0
   150
}
slouken@0
   151
slouken@0
   152
/* colorkeyed N->1 blending with per-surface alpha */
slouken@0
   153
static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info)
slouken@0
   154
{
slouken@0
   155
	int width = info->d_width;
slouken@0
   156
	int height = info->d_height;
slouken@0
   157
	Uint8 *src = info->s_pixels;
slouken@0
   158
	int srcskip = info->s_skip;
slouken@0
   159
	Uint8 *dst = info->d_pixels;
slouken@0
   160
	int dstskip = info->d_skip;
slouken@0
   161
	Uint8 *palmap = info->table;
slouken@0
   162
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
   163
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
   164
	int srcbpp = srcfmt->BytesPerPixel;
slouken@0
   165
	Uint32 ckey = srcfmt->colorkey;
slouken@0
   166
slouken@0
   167
	const int A = srcfmt->alpha;
slouken@0
   168
slouken@0
   169
	while ( height-- ) {
slouken@0
   170
	    DUFFS_LOOP(
slouken@0
   171
	    {
slouken@0
   172
		Uint32 pixel;
slouken@0
   173
		unsigned sR;
slouken@0
   174
		unsigned sG;
slouken@0
   175
		unsigned sB;
slouken@0
   176
		unsigned dR;
slouken@0
   177
		unsigned dG;
slouken@0
   178
		unsigned dB;
slouken@0
   179
		DISEMBLE_RGB(src, srcbpp, srcfmt, pixel, sR, sG, sB);
slouken@0
   180
		if ( pixel != ckey ) {
slouken@0
   181
		    dR = dstfmt->palette->colors[*dst].r;
slouken@0
   182
		    dG = dstfmt->palette->colors[*dst].g;
slouken@0
   183
		    dB = dstfmt->palette->colors[*dst].b;
slouken@0
   184
		    ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
slouken@0
   185
		    dR &= 0xff;
slouken@0
   186
		    dG &= 0xff;
slouken@0
   187
		    dB &= 0xff;
slouken@0
   188
		    /* Pack RGB into 8bit pixel */
slouken@0
   189
		    if ( palmap == NULL ) {
slouken@0
   190
			*dst =((dR>>5)<<(3+2))|
slouken@0
   191
			      ((dG>>5)<<(2)) |
slouken@0
   192
			      ((dB>>6)<<(0));
slouken@0
   193
		    } else {
slouken@0
   194
			*dst = palmap[((dR>>5)<<(3+2))|
slouken@0
   195
				      ((dG>>5)<<(2))  |
slouken@0
   196
				      ((dB>>6)<<(0))  ];
slouken@0
   197
		    }
slouken@0
   198
		}
slouken@0
   199
		dst++;
slouken@0
   200
		src += srcbpp;
slouken@0
   201
	    },
slouken@0
   202
	    width);
slouken@0
   203
	    src += srcskip;
slouken@0
   204
	    dst += dstskip;
slouken@0
   205
	}
slouken@0
   206
}
slouken@0
   207
slouken@880
   208
#ifdef MMX_ASMBLIT
slouken@689
   209
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
slouken@689
   210
static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info)
slouken@689
   211
{
slouken@689
   212
	int width = info->d_width;
slouken@689
   213
	int height = info->d_height;
slouken@689
   214
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@689
   215
	int srcskip = info->s_skip >> 2;
slouken@689
   216
	Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@689
   217
	int dstskip = info->d_skip >> 2;
slouken@689
   218
        Uint8 load[8];
slouken@689
   219
  
slouken@720
   220
        *(Uint64 *)load = 0x00fefefe00fefefeULL;/* alpha128 mask */
slouken@689
   221
        movq_m2r(*load, mm4); /* alpha128 mask -> mm4 */
slouken@720
   222
        *(Uint64 *)load = 0x0001010100010101ULL;/* !alpha128 mask */
slouken@689
   223
        movq_m2r(*load, mm3); /* !alpha128 mask -> mm3 */
slouken@720
   224
        *(Uint64 *)load = 0xFF000000FF000000ULL;/* dst alpha mask */
slouken@689
   225
        movq_m2r(*load, mm7); /* dst alpha mask -> mm7 */
slouken@689
   226
	while(height--) {
slouken@689
   227
            DUFFS_LOOP_DOUBLE2(
slouken@689
   228
            {
slouken@689
   229
		    Uint32 s = *srcp++;
slouken@689
   230
		    Uint32 d = *dstp;
slouken@689
   231
		    *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
slouken@689
   232
			       + (s & d & 0x00010101)) | 0xff000000;
slouken@689
   233
            },{
slouken@689
   234
	            movq_m2r((*dstp), mm2);/* 2 x dst -> mm2(ARGBARGB) */
slouken@689
   235
	            movq_r2r(mm2, mm6); /* 2 x dst -> mm6(ARGBARGB) */
slouken@689
   236
	      
slouken@689
   237
	            movq_m2r((*srcp), mm1);/* 2 x src -> mm1(ARGBARGB) */
slouken@689
   238
	            movq_r2r(mm1, mm5); /* 2 x src -> mm5(ARGBARGB) */
slouken@689
   239
		
slouken@689
   240
	            pand_r2r(mm4, mm6); /* dst & mask -> mm6 */
slouken@689
   241
	            pand_r2r(mm4, mm5); /* src & mask -> mm5 */
slouken@689
   242
	            paddd_r2r(mm6, mm5); /* mm6 + mm5 -> mm5 */
slouken@689
   243
	            psrld_i2r(1, mm5); /* mm5 >> 1 -> mm5 */
slouken@689
   244
	
slouken@689
   245
	            pand_r2r(mm1, mm2); /* src & dst -> mm2 */
slouken@689
   246
	            pand_r2r(mm3, mm2); /* mm2 & !mask -> mm2 */
slouken@689
   247
	            paddd_r2r(mm5, mm2); /* mm5 + mm2 -> mm2 */
slouken@689
   248
	            por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
slouken@689
   249
	            movq_r2m(mm2, (*dstp));/* mm2 -> 2 x dst pixels */
slouken@689
   250
	            dstp += 2;
slouken@689
   251
	            srcp += 2;
slouken@689
   252
            }, width);
slouken@689
   253
	    srcp += srcskip;
slouken@689
   254
	    dstp += dstskip;
slouken@689
   255
	}
slouken@689
   256
	emms();
slouken@689
   257
}
slouken@689
   258
slouken@689
   259
/* fast RGB888->(A)RGB888 blending with surface alpha */
slouken@689
   260
static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info)
slouken@689
   261
{
slouken@689
   262
	unsigned alpha = info->src->alpha;
slouken@689
   263
	if(alpha == 128) {
slouken@689
   264
		BlitRGBtoRGBSurfaceAlpha128MMX(info);
slouken@689
   265
	} else {
slouken@689
   266
		int width = info->d_width;
slouken@689
   267
		int height = info->d_height;
slouken@689
   268
		Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@689
   269
		int srcskip = info->s_skip >> 2;
slouken@689
   270
		Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@689
   271
		int dstskip = info->d_skip >> 2;
slouken@689
   272
                Uint8 load[8] = {alpha, alpha, alpha, alpha,
slouken@689
   273
    					alpha, alpha, alpha, alpha};
slouken@689
   274
					
slouken@689
   275
                movq_m2r(*load, mm4); /* alpha -> mm4 */
slouken@720
   276
		*(Uint64 *)load = 0x00FF00FF00FF00FFULL;
slouken@689
   277
                movq_m2r(*load, mm3); /* mask -> mm3 */
slouken@689
   278
		pand_r2r(mm3, mm4); /* mm4 & mask -> 0A0A0A0A -> mm4 */
slouken@720
   279
		*(Uint64 *)load = 0xFF000000FF000000ULL;/* dst alpha mask */
slouken@689
   280
		movq_m2r(*load, mm7); /* dst alpha mask -> mm7 */
slouken@689
   281
		
slouken@689
   282
		while(height--) {
slouken@689
   283
			DUFFS_LOOP_DOUBLE2({
slouken@689
   284
				/* One Pixel Blend */
slouken@689
   285
	                        movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
slouken@689
   286
                                punpcklbw_r2r(mm1, mm1); /* AARRGGBB -> mm1 */
slouken@689
   287
                                pand_r2r(mm3, mm1); /* 0A0R0G0B -> mm1 */
slouken@689
   288
			  
slouken@689
   289
	                        movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
slouken@689
   290
			        movq_r2r(mm2, mm6);/* dst(ARGB) -> mm6 (0000ARGB)*/
slouken@689
   291
                                punpcklbw_r2r(mm2, mm2); /* AARRGGBB -> mm2 */
slouken@689
   292
                                pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
slouken@689
   293
			  
slouken@689
   294
                                psubw_r2r(mm2, mm1);/* src - dst -> mm1 */
slouken@689
   295
	                        pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
slouken@689
   296
	                        psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1 */
slouken@689
   297
	                        paddw_r2r(mm1, mm2); /* mm1 + mm2(dst) -> mm2 */
slouken@689
   298
	                        pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
slouken@689
   299
	                        packuswb_r2r(mm2, mm2);  /* ARGBARGB -> mm2 */
slouken@689
   300
	                        por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
slouken@689
   301
			        movd_r2m(mm2, *dstp);/* mm2 -> pixel */
slouken@689
   302
				++srcp;
slouken@689
   303
				++dstp;
slouken@689
   304
			},{
slouken@689
   305
			        /* Two Pixels Blend */
slouken@689
   306
				movq_m2r((*srcp), mm0);/* 2 x src -> mm0(ARGBARGB)*/
slouken@689
   307
			        movq_r2r(mm0, mm1); /* 2 x src -> mm1(ARGBARGB) */
slouken@689
   308
                                punpcklbw_r2r(mm0, mm0); /* low - AARRGGBB -> mm0 */
slouken@689
   309
			        pand_r2r(mm3, mm0); /* 0A0R0G0B -> mm0(src1) */
slouken@689
   310
			        punpckhbw_r2r(mm1, mm1); /* high - AARRGGBB -> mm1 */
slouken@689
   311
	                        pand_r2r(mm3, mm1); /* 0A0R0G0B -> mm1(src2) */
slouken@689
   312
	
slouken@689
   313
	                        movq_m2r((*dstp), mm2);/* 2 x dst -> mm2(ARGBARGB) */
slouken@689
   314
	                        movq_r2r(mm2, mm5); /* 2 x dst -> mm5(ARGBARGB) */
slouken@689
   315
			        movq_r2r(mm2, mm6); /* 2 x dst -> mm6(ARGBARGB) */
slouken@689
   316
                                punpcklbw_r2r(mm2, mm2); /* low - AARRGGBB -> mm2 */
slouken@689
   317
	                        punpckhbw_r2r(mm6, mm6); /* high - AARRGGBB -> mm6 */
slouken@689
   318
                                pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2(dst1) */
slouken@689
   319
	                  
slouken@689
   320
                                psubw_r2r(mm2, mm0);/* src1 - dst1 -> mm0 */
slouken@689
   321
	                        pmullw_r2r(mm4, mm0); /* mm0 * alpha -> mm0 */
slouken@689
   322
			        pand_r2r(mm3, mm6); /* 0A0R0G0B -> mm6(dst2) */
slouken@689
   323
			        psrlw_i2r(8, mm0); /* mm0 >> 8 -> mm1 */
slouken@689
   324
			        psubw_r2r(mm6, mm1);/* src2 - dst2 -> mm1 */
slouken@689
   325
	                        pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
slouken@689
   326
				paddw_r2r(mm0, mm2); /* mm0 + mm2(dst1) -> mm2 */
slouken@689
   327
	                        psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm0 */
slouken@689
   328
				pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
slouken@689
   329
	                        paddw_r2r(mm1, mm6); /* mm1 + mm6(dst2) -> mm6 */
slouken@689
   330
	                        pand_r2r(mm3, mm6); /* 0A0R0G0B -> mm6 */
slouken@689
   331
	                        packuswb_r2r(mm2, mm2);  /* ARGBARGB -> mm2 */
slouken@689
   332
	                        packuswb_r2r(mm6, mm6);  /* ARGBARGB -> mm6 */
slouken@689
   333
	                        psrlq_i2r(32, mm2); /* mm2 >> 32 -> mm2 */
slouken@689
   334
	                        psllq_i2r(32, mm6); /* mm6 << 32 -> mm6 */
slouken@689
   335
	                        por_r2r(mm6, mm2); /* mm6 | mm2 -> mm2 */				
slouken@689
   336
				por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
slouken@689
   337
                                movq_r2m(mm2, *dstp);/* mm2 -> 2 x pixel */
slouken@689
   338
				srcp += 2;
slouken@689
   339
				dstp += 2;
slouken@689
   340
			}, width);
slouken@689
   341
			srcp += srcskip;
slouken@689
   342
			dstp += dstskip;
slouken@689
   343
		}
slouken@689
   344
		emms();
slouken@689
   345
	}
slouken@689
   346
}
slouken@689
   347
slouken@689
   348
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
slouken@689
   349
static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info)
slouken@689
   350
{
slouken@689
   351
	int width = info->d_width;
slouken@689
   352
	int height = info->d_height;
slouken@689
   353
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@689
   354
	int srcskip = info->s_skip >> 2;
slouken@689
   355
	Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@689
   356
	int dstskip = info->d_skip >> 2;
slouken@689
   357
        Uint32 alpha = 0;
slouken@689
   358
        Uint8 load[8];
slouken@689
   359
	                
slouken@720
   360
	*(Uint64 *)load = 0x00FF00FF00FF00FFULL;
slouken@689
   361
        movq_m2r(*load, mm3); /* mask -> mm2 */
slouken@720
   362
	*(Uint64 *)load = 0x00FF000000000000ULL;
slouken@689
   363
        movq_m2r(*load, mm7); /* dst alpha mask -> mm2 */
slouken@720
   364
        *(Uint64 *)load = 0x00FFFFFF00FFFFFFULL;
slouken@689
   365
        movq_m2r(*load, mm0); /* alpha 255 mask -> mm0 */
slouken@720
   366
        *(Uint64 *)load = 0xFF000000FF000000ULL;
slouken@689
   367
        movq_m2r(*load, mm6); /* alpha 255 !mask -> mm6 */
slouken@689
   368
	while(height--) {
slouken@689
   369
	    DUFFS_LOOP4({
slouken@689
   370
	        alpha = *srcp;
slouken@689
   371
	        alpha >>= 24;
slouken@689
   372
		/* FIXME: Here we special-case opaque alpha since the
slouken@689
   373
		   compositioning used (>>8 instead of /255) doesn't handle
slouken@689
   374
		   it correctly. Also special-case alpha=0 for speed?
slouken@689
   375
		   Benchmark this! */
slouken@689
   376
		if(alpha) {   
slouken@689
   377
		  if(alpha == SDL_ALPHA_OPAQUE) {
slouken@689
   378
		    movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
slouken@689
   379
		    movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
slouken@689
   380
		    pand_r2r(mm0, mm1);
slouken@689
   381
		    pand_r2r(mm6, mm2);
slouken@689
   382
		    por_r2r(mm1, mm2);
slouken@689
   383
		    movd_r2m(mm2, (*dstp));
slouken@689
   384
		  } else {
slouken@689
   385
		    movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
slouken@689
   386
                    punpcklbw_r2r(mm1, mm1); /* AARRGGBB -> mm1 */
slouken@689
   387
                    pand_r2r(mm3, mm1); /* 0A0R0G0B -> mm1 */
slouken@689
   388
			  
slouken@689
   389
	            movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
slouken@689
   390
                    punpcklbw_r2r(mm2, mm2); /* AARRGGBB -> mm2 */
slouken@689
   391
                    pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
slouken@689
   392
		
slouken@689
   393
		    movq_r2r(mm2, mm5);/* mm2(0A0R0G0B) -> mm5 */
slouken@689
   394
		    pand_r2r(mm7, mm5); /* mm5 & dst alpha mask -> mm5(0A000000) */
slouken@689
   395
		    psrlq_i2r(24, mm5); /* mm5 >> 24 -> mm5 (0000A000)*/
slouken@689
   396
		    
slouken@689
   397
		    movq_r2r(mm1, mm4);/* mm1(0A0R0G0B) -> mm4 */
slouken@689
   398
		    psrlq_i2r(48, mm4); /* mm4 >> 48 -> mm4(0000000A) */
slouken@689
   399
		    punpcklwd_r2r(mm4, mm4); /* 00000A0A -> mm4 */
slouken@689
   400
                    punpcklwd_r2r(mm4, mm4); /* 0A0A0A0A -> mm4 */
slouken@689
   401
		                        		    
slouken@689
   402
                    /* blend */		    
slouken@689
   403
                    psubw_r2r(mm2, mm1);/* src - dst -> mm1 */
slouken@689
   404
	            pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
slouken@689
   405
	            psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1 */
slouken@689
   406
	            paddw_r2r(mm1, mm2); /* mm1 + mm2(dst) -> mm2 */
slouken@689
   407
	            pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
slouken@689
   408
		    packuswb_r2r(mm2, mm2);  /* ARGBARGB -> mm2 */
slouken@689
   409
		    pand_r2r(mm0, mm2); /* 0RGB0RGB -> mm2 */
slouken@689
   410
		    por_r2r(mm5, mm2); /* dst alpha | mm2 -> mm2 */
slouken@689
   411
		    movd_r2m(mm2, *dstp);/* mm2 -> dst */
slouken@689
   412
		  }
slouken@689
   413
		}
slouken@689
   414
		++srcp;
slouken@689
   415
		++dstp;
slouken@689
   416
	    }, width);
slouken@689
   417
	    srcp += srcskip;
slouken@689
   418
	    dstp += dstskip;
slouken@689
   419
	}
slouken@689
   420
	emms();
slouken@689
   421
}
slouken@689
   422
#endif
slouken@689
   423
icculus@1047
   424
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
   425
#include <assert.h>
icculus@1047
   426
#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
icculus@1047
   427
#define VECPRINT(msg, v) do { \
icculus@1047
   428
    vector unsigned int tmpvec = (vector unsigned int)(v); \
icculus@1047
   429
    unsigned int *vp = (unsigned int *)&tmpvec; \
icculus@1047
   430
    printf("%s = %08X %08X %08X %08X\n", msg, vp[0], vp[1], vp[2], vp[3]); \
icculus@1047
   431
} while (0)
icculus@1047
   432
icculus@1047
   433
/* the permuation vector that takes the high bytes out of all the appropriate shorts 
icculus@1047
   434
    (vector unsigned char)(
icculus@1047
   435
        0x00, 0x10, 0x02, 0x12,
icculus@1047
   436
        0x04, 0x14, 0x06, 0x16,
icculus@1047
   437
        0x08, 0x18, 0x0A, 0x1A,
icculus@1047
   438
        0x0C, 0x1C, 0x0E, 0x1E );
icculus@1047
   439
*/
icculus@1047
   440
#define VEC_MERGE_PERMUTE() (vec_add(vec_lvsl(0, (int*)NULL), (vector unsigned char)vec_splat_u16(0x0F)))
icculus@1047
   441
#define VEC_U32_24() (vec_add(vec_splat_u32(12), vec_splat_u32(12)))
icculus@1047
   442
#define VEC_ALPHA_MASK() ((vector unsigned char)vec_sl((vector unsigned int)vec_splat_s8(-1), VEC_U32_24()))
icculus@1047
   443
#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
icculus@1047
   444
    ? vec_lvsl(0, src) \
icculus@1047
   445
    : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
icculus@1047
   446
icculus@1047
   447
   
icculus@1047
   448
#define VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1_16, v8_16) do { \
icculus@1047
   449
    /* vtemp1 contains source AAGGAAGGAAGGAAGG */ \
icculus@1047
   450
    vector unsigned short vtemp1 = vec_mule(vs, valpha); \
icculus@1047
   451
    /* vtemp2 contains source RRBBRRBBRRBBRRBB */ \
icculus@1047
   452
    vector unsigned short vtemp2 = vec_mulo(vs, valpha); \
icculus@1047
   453
    /* valpha2 is 255-alpha */ \
icculus@1047
   454
    vector unsigned char valpha2 = vec_nor(valpha, valpha); \
icculus@1047
   455
    /* vtemp3 contains dest AAGGAAGGAAGGAAGG */ \
icculus@1047
   456
    vector unsigned short vtemp3 = vec_mule(vd, valpha2); \
icculus@1047
   457
    /* vtemp4 contains dest RRBBRRBBRRBBRRBB */ \
icculus@1047
   458
    vector unsigned short vtemp4 = vec_mulo(vd, valpha2); \
icculus@1047
   459
    /* add source and dest */ \
icculus@1047
   460
    vtemp1 = vec_add(vtemp1, vtemp3); \
icculus@1047
   461
    vtemp2 = vec_add(vtemp2, vtemp4); \
icculus@1047
   462
    /* vtemp1 = (vtemp1 + 1) + ((vtemp1 + 1) >> 8) */ \
icculus@1047
   463
    vtemp1 = vec_add(vtemp1, v1_16); \
icculus@1047
   464
    vtemp3 = vec_sr(vtemp1, v8_16); \
icculus@1047
   465
    vtemp1 = vec_add(vtemp1, vtemp3); \
icculus@1047
   466
    /* vtemp2 = (vtemp2 + 1) + ((vtemp2 + 1) >> 8) */ \
icculus@1047
   467
    vtemp2 = vec_add(vtemp2, v1_16); \
icculus@1047
   468
    vtemp4 = vec_sr(vtemp2, v8_16); \
icculus@1047
   469
    vtemp2 = vec_add(vtemp2, vtemp4); \
icculus@1047
   470
    /* (>>8) and get ARGBARGBARGBARGB */ \
icculus@1047
   471
    vd = (vector unsigned char)vec_perm(vtemp1, vtemp2, mergePermute); \
icculus@1047
   472
} while (0)
icculus@1047
   473
 
icculus@1047
   474
/* Calculate the permute vector used for 32->32 swizzling */
icculus@1047
   475
static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt,
icculus@1047
   476
                                  const SDL_PixelFormat *dstfmt)
icculus@1047
   477
{
icculus@1047
   478
    /*
icculus@1047
   479
     * We have to assume that the bits that aren't used by other
icculus@1047
   480
     *  colors is alpha, and it's one complete byte, since some formats
icculus@1047
   481
     *  leave alpha with a zero mask, but we should still swizzle the bits.
icculus@1047
   482
     */
icculus@1047
   483
    /* ARGB */
icculus@1047
   484
    const static struct SDL_PixelFormat default_pixel_format = {
icculus@1047
   485
        NULL, 0, 0,
icculus@1047
   486
        0, 0, 0, 0,
icculus@1047
   487
        16, 8, 0, 24,
icculus@1047
   488
        0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
icculus@1047
   489
        0, 0};
icculus@1047
   490
    if (!srcfmt) {
icculus@1047
   491
        srcfmt = &default_pixel_format;
icculus@1047
   492
    }
icculus@1047
   493
    if (!dstfmt) {
icculus@1047
   494
        dstfmt = &default_pixel_format;
icculus@1047
   495
    }
icculus@1047
   496
    vector unsigned char plus = (vector unsigned char)
icculus@1047
   497
                                            ( 0x00, 0x00, 0x00, 0x00,
icculus@1047
   498
                                              0x04, 0x04, 0x04, 0x04,
icculus@1047
   499
                                              0x08, 0x08, 0x08, 0x08,
icculus@1047
   500
                                              0x0C, 0x0C, 0x0C, 0x0C );
icculus@1047
   501
    vector unsigned char vswiz;
icculus@1047
   502
    vector unsigned int srcvec;
icculus@1047
   503
#define RESHIFT(X) (3 - ((X) >> 3))
icculus@1047
   504
    Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
icculus@1047
   505
    Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
icculus@1047
   506
    Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
icculus@1047
   507
    Uint32 amask;
icculus@1047
   508
    /* Use zero for alpha if either surface doesn't have alpha */
icculus@1047
   509
    if (dstfmt->Amask) {
icculus@1047
   510
        amask = ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift);
icculus@1047
   511
    } else {
icculus@1047
   512
        amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF);
icculus@1047
   513
    }
icculus@1047
   514
#undef RESHIFT  
icculus@1047
   515
    ((unsigned int *)&srcvec)[0] = (rmask | gmask | bmask | amask);
icculus@1047
   516
    vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0));
icculus@1047
   517
    return(vswiz);
icculus@1047
   518
}
icculus@1047
   519
icculus@1047
   520
static void Blit32to565PixelAlphaAltivec(SDL_BlitInfo *info)
icculus@1047
   521
{
icculus@1047
   522
    int height = info->d_height;
icculus@1047
   523
    Uint8 *src = (Uint8 *)info->s_pixels;
icculus@1047
   524
    int srcskip = info->s_skip;
icculus@1047
   525
    Uint8 *dst = (Uint8 *)info->d_pixels;
icculus@1047
   526
    int dstskip = info->d_skip;
icculus@1047
   527
    SDL_PixelFormat *srcfmt = info->src;
icculus@1047
   528
icculus@1047
   529
    vector unsigned char v0 = vec_splat_u8(0);
icculus@1047
   530
    vector unsigned short v8_16 = vec_splat_u16(8);
icculus@1047
   531
    vector unsigned short v1_16 = vec_splat_u16(1);
icculus@1047
   532
    vector unsigned short v2_16 = vec_splat_u16(2);
icculus@1047
   533
    vector unsigned short v3_16 = vec_splat_u16(3);
icculus@1047
   534
    vector unsigned int v8_32 = vec_splat_u32(8);
icculus@1047
   535
    vector unsigned int v16_32 = vec_add(v8_32, v8_32);
icculus@1047
   536
    vector unsigned short v3f = (vector unsigned short)(
icculus@1047
   537
        0x003f, 0x003f, 0x003f, 0x003f,
icculus@1047
   538
        0x003f, 0x003f, 0x003f, 0x003f);
icculus@1047
   539
    vector unsigned short vfc = (vector unsigned short)(
icculus@1047
   540
        0x00fc, 0x00fc, 0x00fc, 0x00fc,
icculus@1047
   541
        0x00fc, 0x00fc, 0x00fc, 0x00fc);
icculus@1047
   542
icculus@1047
   543
    /* 
icculus@1047
   544
        0x10 - 0x1f is the alpha
icculus@1047
   545
        0x00 - 0x0e evens are the red
icculus@1047
   546
        0x01 - 0x0f odds are zero
icculus@1047
   547
    */
icculus@1047
   548
    vector unsigned char vredalpha1 = (vector unsigned char)(
icculus@1047
   549
        0x10, 0x00, 0x01, 0x01,
icculus@1047
   550
        0x10, 0x02, 0x01, 0x01,
icculus@1047
   551
        0x10, 0x04, 0x01, 0x01,
icculus@1047
   552
        0x10, 0x06, 0x01, 0x01
icculus@1047
   553
    );
icculus@1047
   554
    vector unsigned char vredalpha2 = (vector unsigned char)(
icculus@1047
   555
        vec_add((vector unsigned int)vredalpha1, vec_sl(v8_32, v16_32))
icculus@1047
   556
    );
icculus@1047
   557
    /*
icculus@1047
   558
        0x00 - 0x0f is ARxx ARxx ARxx ARxx
icculus@1047
   559
        0x11 - 0x0f odds are blue
icculus@1047
   560
    */
icculus@1047
   561
    vector unsigned char vblue1 = (vector unsigned char)(
icculus@1047
   562
        0x00, 0x01, 0x02, 0x11,
icculus@1047
   563
        0x04, 0x05, 0x06, 0x13,
icculus@1047
   564
        0x08, 0x09, 0x0a, 0x15,
icculus@1047
   565
        0x0c, 0x0d, 0x0e, 0x17
icculus@1047
   566
    );
icculus@1047
   567
    vector unsigned char vblue2 = (vector unsigned char)(
icculus@1047
   568
        vec_add((vector unsigned int)vblue1, v8_32)
icculus@1047
   569
    );
icculus@1047
   570
    /*
icculus@1047
   571
        0x00 - 0x0f is ARxB ARxB ARxB ARxB
icculus@1047
   572
        0x10 - 0x0e evens are green
icculus@1047
   573
    */
icculus@1047
   574
    vector unsigned char vgreen1 = (vector unsigned char)(
icculus@1047
   575
        0x00, 0x01, 0x10, 0x03,
icculus@1047
   576
        0x04, 0x05, 0x12, 0x07,
icculus@1047
   577
        0x08, 0x09, 0x14, 0x0b,
icculus@1047
   578
        0x0c, 0x0d, 0x16, 0x0f
icculus@1047
   579
    );
icculus@1047
   580
    vector unsigned char vgreen2 = (vector unsigned char)(
icculus@1047
   581
        vec_add((vector unsigned int)vgreen1, vec_sl(v8_32, v8_32))
icculus@1047
   582
    );
icculus@1047
   583
    vector unsigned char vgmerge = (vector unsigned char)(
icculus@1047
   584
        0x00, 0x02, 0x00, 0x06,
icculus@1047
   585
        0x00, 0x0a, 0x00, 0x0e,
icculus@1047
   586
        0x00, 0x12, 0x00, 0x16,
icculus@1047
   587
        0x00, 0x1a, 0x00, 0x1e);
icculus@1047
   588
    vector unsigned char mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
   589
    vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
icculus@1047
   590
    vector unsigned char valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
icculus@1047
   591
icculus@1047
   592
    vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7);
icculus@1047
   593
    vf800 = vec_sl(vf800, vec_splat_u16(8));
icculus@1047
   594
icculus@1047
   595
    while(height--) {
icculus@1047
   596
        int extrawidth;
icculus@1047
   597
        vector unsigned char valigner;
icculus@1047
   598
        vector unsigned char vsrc;
icculus@1047
   599
        vector unsigned char voverflow;
icculus@1047
   600
        int width = info->d_width;
icculus@1047
   601
icculus@1047
   602
#define ONE_PIXEL_BLEND(condition, widthvar) \
icculus@1047
   603
        while (condition) { \
icculus@1047
   604
            Uint32 pixel; \
icculus@1047
   605
            unsigned sR, sG, sB, dR, dG, dB, sA; \
icculus@1047
   606
            DISEMBLE_RGBA(src, 4, srcfmt, pixel, sR, sG, sB, sA); \
icculus@1047
   607
            if(sA) { \
icculus@1047
   608
                unsigned short dstpixel = *((unsigned short *)dst); \
icculus@1047
   609
                dR = (dstpixel >> 8) & 0xf8; \
icculus@1047
   610
                dG = (dstpixel >> 3) & 0xfc; \
icculus@1047
   611
                dB = (dstpixel << 3) & 0xf8; \
icculus@1047
   612
                ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
icculus@1047
   613
                *((unsigned short *)dst) = ( \
icculus@1047
   614
                    ((dR & 0xf8) << 8) | ((dG & 0xfc) << 3) | (dB >> 3) \
icculus@1047
   615
                ); \
icculus@1047
   616
            } \
icculus@1047
   617
            src += 4; \
icculus@1047
   618
            dst += 2; \
icculus@1047
   619
            widthvar--; \
icculus@1047
   620
        }
icculus@1047
   621
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dst)) && (width), width);
icculus@1047
   622
        extrawidth = (width % 8);
icculus@1047
   623
        valigner = VEC_ALIGNER(src);
icculus@1047
   624
        vsrc = (vector unsigned char)vec_ld(0, src);
icculus@1047
   625
        width -= extrawidth;
icculus@1047
   626
        while (width) {
icculus@1047
   627
            vector unsigned char valpha;
icculus@1047
   628
            vector unsigned char vsrc1, vsrc2;
icculus@1047
   629
            vector unsigned char vdst1, vdst2;
icculus@1047
   630
            vector unsigned short vR, vG, vB;
icculus@1047
   631
            vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
icculus@1047
   632
icculus@1047
   633
            /* Load 8 pixels from src as ARGB */
icculus@1047
   634
            voverflow = (vector unsigned char)vec_ld(15, src);
icculus@1047
   635
            vsrc = vec_perm(vsrc, voverflow, valigner);
icculus@1047
   636
            vsrc1 = vec_perm(vsrc, vsrc, vpermute);
icculus@1047
   637
            src += 16;
icculus@1047
   638
            vsrc = (vector unsigned char)vec_ld(15, src);
icculus@1047
   639
            voverflow = vec_perm(voverflow, vsrc, valigner);
icculus@1047
   640
            vsrc2 = vec_perm(voverflow, voverflow, vpermute);
icculus@1047
   641
            src += 16;
icculus@1047
   642
icculus@1047
   643
            /* Load 8 pixels from dst as XRGB */
icculus@1047
   644
            voverflow = vec_ld(0, dst);
icculus@1047
   645
            vR = vec_and((vector unsigned short)voverflow, vf800);
icculus@1047
   646
            vB = vec_sl((vector unsigned short)voverflow, v3_16);
icculus@1047
   647
            vG = vec_sl(vB, v2_16);
icculus@1047
   648
            vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, (vector unsigned char)vR, vredalpha1);
icculus@1047
   649
            vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1);
icculus@1047
   650
            vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1);
icculus@1047
   651
            vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, (vector unsigned char)vR, vredalpha2);
icculus@1047
   652
            vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2);
icculus@1047
   653
            vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2);
icculus@1047
   654
icculus@1047
   655
            /* Alpha blend 8 pixels as ARGB */
icculus@1047
   656
            valpha = vec_perm(vsrc1, v0, valphaPermute);
icculus@1047
   657
            VEC_MULTIPLY_ALPHA(vsrc1, vdst1, valpha, mergePermute, v1_16, v8_16);
icculus@1047
   658
            valpha = vec_perm(vsrc2, v0, valphaPermute);
icculus@1047
   659
            VEC_MULTIPLY_ALPHA(vsrc2, vdst2, valpha, mergePermute, v1_16, v8_16);
icculus@1047
   660
icculus@1047
   661
            /* Convert 8 pixels to 565 */
icculus@1047
   662
            vpixel = (vector unsigned short)vec_packpx((vector unsigned int)vdst1, (vector unsigned int)vdst2);
icculus@1047
   663
            vgpixel = (vector unsigned short)vec_perm(vdst1, vdst2, vgmerge);
icculus@1047
   664
            vgpixel = vec_and(vgpixel, vfc);
icculus@1047
   665
            vgpixel = vec_sl(vgpixel, v3_16);
icculus@1047
   666
            vrpixel = vec_sl(vpixel, v1_16);
icculus@1047
   667
            vrpixel = vec_and(vrpixel, vf800);
icculus@1047
   668
            vbpixel = vec_and(vpixel, v3f);
icculus@1047
   669
            vdst1 = vec_or((vector unsigned char)vrpixel, (vector unsigned char)vgpixel);
icculus@1047
   670
            vdst1 = vec_or(vdst1, (vector unsigned char)vbpixel);
icculus@1047
   671
            
icculus@1047
   672
            /* Store 8 pixels */
icculus@1047
   673
            vec_st(vdst1, 0, dst);
icculus@1047
   674
icculus@1047
   675
            width -= 8;
icculus@1047
   676
            dst += 16;
icculus@1047
   677
        }
icculus@1047
   678
        ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
   679
#undef ONE_PIXEL_BLEND
icculus@1047
   680
        src += srcskip;
icculus@1047
   681
        dst += dstskip;
icculus@1047
   682
    }
icculus@1047
   683
}
icculus@1047
   684
icculus@1047
   685
static void Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo *info)
icculus@1047
   686
{
icculus@1047
   687
    unsigned alpha = info->src->alpha;
icculus@1047
   688
    int height = info->d_height;
icculus@1047
   689
    Uint32 *srcp = (Uint32 *)info->s_pixels;
icculus@1047
   690
    int srcskip = info->s_skip >> 2;
icculus@1047
   691
    Uint32 *dstp = (Uint32 *)info->d_pixels;
icculus@1047
   692
    int dstskip = info->d_skip >> 2;
icculus@1047
   693
    SDL_PixelFormat *srcfmt = info->src;
icculus@1047
   694
    SDL_PixelFormat *dstfmt = info->dst;
icculus@1047
   695
    unsigned sA = srcfmt->alpha;
icculus@1047
   696
    unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
icculus@1047
   697
    Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
icculus@1047
   698
    Uint32 ckey = info->src->colorkey;
icculus@1047
   699
    vector unsigned char mergePermute;
icculus@1047
   700
    vector unsigned char vsrcPermute;
icculus@1047
   701
    vector unsigned char vdstPermute;
icculus@1047
   702
    vector unsigned char vsdstPermute;
icculus@1047
   703
    vector unsigned char valpha;
icculus@1047
   704
    vector unsigned char valphamask;
icculus@1047
   705
    vector unsigned char vbits;
icculus@1047
   706
    vector unsigned char v0;
icculus@1047
   707
    vector unsigned short v1;
icculus@1047
   708
    vector unsigned short v8;
icculus@1047
   709
    vector unsigned int vckey;
icculus@1047
   710
    vector unsigned int vrgbmask;
icculus@1047
   711
icculus@1047
   712
    mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
   713
    v0 = vec_splat_u8(0);
icculus@1047
   714
    v1 = vec_splat_u16(1);
icculus@1047
   715
    v8 = vec_splat_u16(8);
icculus@1047
   716
icculus@1047
   717
    /* set the alpha to 255 on the destination surf */
icculus@1047
   718
    valphamask = VEC_ALPHA_MASK();
icculus@1047
   719
icculus@1047
   720
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
icculus@1047
   721
    vdstPermute = calc_swizzle32(NULL, dstfmt);
icculus@1047
   722
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
icculus@1047
   723
icculus@1047
   724
    /* set a vector full of alpha and 255-alpha */
icculus@1047
   725
    ((unsigned char *)&valpha)[0] = alpha;
icculus@1047
   726
    valpha = vec_splat(valpha, 0);
icculus@1047
   727
    vbits = (vector unsigned char)vec_splat_s8(-1);
icculus@1047
   728
icculus@1047
   729
    ckey &= rgbmask;
icculus@1047
   730
    ((unsigned int *)&vckey)[0] = ckey;
icculus@1047
   731
    vckey = vec_splat(vckey, 0);
icculus@1047
   732
    ((unsigned int *)&vrgbmask)[0] = rgbmask;
icculus@1047
   733
    vrgbmask = vec_splat(vrgbmask, 0);
icculus@1047
   734
icculus@1047
   735
    while(height--) {
icculus@1047
   736
        int width = info->d_width;
icculus@1047
   737
#define ONE_PIXEL_BLEND(condition, widthvar) \
icculus@1047
   738
        while (condition) { \
icculus@1047
   739
            Uint32 pixel; \
icculus@1047
   740
            unsigned sR, sG, sB, dR, dG, dB; \
icculus@1047
   741
            RETRIEVE_RGB_PIXEL(((Uint8 *)srcp), 4, pixel); \
icculus@1047
   742
            if(sA && pixel != ckey) { \
icculus@1047
   743
                RGB_FROM_PIXEL(pixel, srcfmt, sR, sG, sB); \
icculus@1047
   744
                DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, pixel, dR, dG, dB); \
icculus@1047
   745
                ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
icculus@1047
   746
                ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
icculus@1047
   747
            } \
icculus@1047
   748
            ((Uint8 *)dstp) += 4; \
icculus@1047
   749
            ((Uint8 *)srcp) += 4; \
icculus@1047
   750
            widthvar--; \
icculus@1047
   751
        }
icculus@1047
   752
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
icculus@1047
   753
        if (width > 0) {
icculus@1047
   754
            int extrawidth = (width % 4);
icculus@1047
   755
            vector unsigned char valigner = VEC_ALIGNER(srcp);
icculus@1047
   756
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
icculus@1047
   757
            width -= extrawidth;
icculus@1047
   758
            while (width) {
icculus@1047
   759
                vector unsigned char vsel;
icculus@1047
   760
                vector unsigned char voverflow;
icculus@1047
   761
                vector unsigned char vd;
icculus@1047
   762
                vector unsigned char vd_orig;
icculus@1047
   763
icculus@1047
   764
                /* s = *srcp */
icculus@1047
   765
                voverflow = (vector unsigned char)vec_ld(15, srcp);
icculus@1047
   766
                vs = vec_perm(vs, voverflow, valigner);
icculus@1047
   767
                
icculus@1047
   768
                /* vsel is set for items that match the key */
icculus@1047
   769
                vsel = (vector unsigned char)vec_and((vector unsigned int)vs, vrgbmask);
icculus@1047
   770
                vsel = (vector unsigned char)vec_cmpeq((vector unsigned int)vsel, vckey);
icculus@1047
   771
icculus@1047
   772
                /* permute to source format */
icculus@1047
   773
                vs = vec_perm(vs, valpha, vsrcPermute);
icculus@1047
   774
icculus@1047
   775
                /* d = *dstp */
icculus@1047
   776
                vd = (vector unsigned char)vec_ld(0, dstp);
icculus@1047
   777
                vd_orig = vd = vec_perm(vd, v0, vsdstPermute);
icculus@1047
   778
icculus@1047
   779
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
icculus@1047
   780
icculus@1047
   781
                /* set the alpha channel to full on */
icculus@1047
   782
                vd = vec_or(vd, valphamask);
icculus@1047
   783
icculus@1047
   784
                /* mask out color key */
icculus@1047
   785
                vd = vec_sel(vd, vd_orig, vsel);
icculus@1047
   786
                
icculus@1047
   787
                /* permute to dest format */
icculus@1047
   788
                vd = vec_perm(vd, vbits, vdstPermute);
icculus@1047
   789
icculus@1047
   790
                /* *dstp = res */
icculus@1047
   791
                vec_st((vector unsigned int)vd, 0, dstp);
icculus@1047
   792
                
icculus@1047
   793
                srcp += 4;
icculus@1047
   794
                dstp += 4;
icculus@1047
   795
                width -= 4;
icculus@1047
   796
                vs = voverflow;
icculus@1047
   797
            }
icculus@1047
   798
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
   799
        }
icculus@1047
   800
#undef ONE_PIXEL_BLEND
icculus@1047
   801
 
icculus@1047
   802
        srcp += srcskip;
icculus@1047
   803
        dstp += dstskip;
icculus@1047
   804
    }
icculus@1047
   805
}
icculus@1047
   806
icculus@1047
   807
icculus@1047
   808
static void Blit32to32PixelAlphaAltivec(SDL_BlitInfo *info)
icculus@1047
   809
{
icculus@1047
   810
    int width = info->d_width;
icculus@1047
   811
    int height = info->d_height;
icculus@1047
   812
    Uint32 *srcp = (Uint32 *)info->s_pixels;
icculus@1047
   813
    int srcskip = info->s_skip >> 2;
icculus@1047
   814
    Uint32 *dstp = (Uint32 *)info->d_pixels;
icculus@1047
   815
    int dstskip = info->d_skip >> 2;
icculus@1047
   816
    SDL_PixelFormat *srcfmt = info->src;
icculus@1047
   817
    SDL_PixelFormat *dstfmt = info->dst;
icculus@1047
   818
    vector unsigned char mergePermute;
icculus@1047
   819
    vector unsigned char valphaPermute;
icculus@1047
   820
    vector unsigned char vsrcPermute;
icculus@1047
   821
    vector unsigned char vdstPermute;
icculus@1047
   822
    vector unsigned char vsdstPermute;
icculus@1047
   823
    vector unsigned char valphamask;
icculus@1047
   824
    vector unsigned char vpixelmask;
icculus@1047
   825
    vector unsigned char v0;
icculus@1047
   826
    vector unsigned short v1;
icculus@1047
   827
    vector unsigned short v8;
icculus@1047
   828
icculus@1047
   829
    v0 = vec_splat_u8(0);
icculus@1047
   830
    v1 = vec_splat_u16(1);
icculus@1047
   831
    v8 = vec_splat_u16(8);
icculus@1047
   832
    mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
   833
    valphamask = VEC_ALPHA_MASK();
icculus@1047
   834
    valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
icculus@1047
   835
    vpixelmask = vec_nor(valphamask, v0);
icculus@1047
   836
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
icculus@1047
   837
    vdstPermute = calc_swizzle32(NULL, dstfmt);
icculus@1047
   838
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
icculus@1047
   839
icculus@1047
   840
	while ( height-- ) {
icculus@1047
   841
        width = info->d_width;
icculus@1047
   842
#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
icculus@1047
   843
            Uint32 pixel; \
icculus@1047
   844
            unsigned sR, sG, sB, dR, dG, dB, sA, dA; \
icculus@1047
   845
            DISEMBLE_RGBA((Uint8 *)srcp, 4, srcfmt, pixel, sR, sG, sB, sA); \
icculus@1047
   846
            if(sA) { \
icculus@1047
   847
              DISEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, pixel, dR, dG, dB, dA); \
icculus@1047
   848
              ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
icculus@1047
   849
              ASSEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, dR, dG, dB, dA); \
icculus@1047
   850
            } \
icculus@1047
   851
            ++srcp; \
icculus@1047
   852
            ++dstp; \
icculus@1047
   853
            widthvar--; \
icculus@1047
   854
        }
icculus@1047
   855
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
icculus@1047
   856
        if (width > 0) {
icculus@1047
   857
            // vsrcPermute
icculus@1047
   858
            // vdstPermute
icculus@1047
   859
            int extrawidth = (width % 4);
icculus@1047
   860
            vector unsigned char valigner = VEC_ALIGNER(srcp);
icculus@1047
   861
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
icculus@1047
   862
            width -= extrawidth;
icculus@1047
   863
            while (width) {
icculus@1047
   864
                vector unsigned char voverflow;
icculus@1047
   865
                vector unsigned char vd;
icculus@1047
   866
                vector unsigned char valpha;
icculus@1047
   867
                vector unsigned char vdstalpha;
icculus@1047
   868
                /* s = *srcp */
icculus@1047
   869
                voverflow = (vector unsigned char)vec_ld(15, srcp);
icculus@1047
   870
                vs = vec_perm(vs, voverflow, valigner);
icculus@1047
   871
                vs = vec_perm(vs, v0, vsrcPermute);
icculus@1047
   872
icculus@1047
   873
                valpha = vec_perm(vs, v0, valphaPermute);
icculus@1047
   874
                
icculus@1047
   875
                /* d = *dstp */
icculus@1047
   876
                vd = (vector unsigned char)vec_ld(0, dstp);
icculus@1047
   877
                vd = vec_perm(vd, v0, vsdstPermute);
icculus@1047
   878
                vdstalpha = vec_and(vd, valphamask);
icculus@1047
   879
icculus@1047
   880
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
icculus@1047
   881
icculus@1047
   882
                /* set the alpha to the dest alpha */
icculus@1047
   883
                vd = vec_and(vd, vpixelmask);
icculus@1047
   884
                vd = vec_or(vd, vdstalpha);
icculus@1047
   885
                vd = vec_perm(vd, v0, vdstPermute);
icculus@1047
   886
icculus@1047
   887
                /* *dstp = res */
icculus@1047
   888
                vec_st((vector unsigned int)vd, 0, dstp);
icculus@1047
   889
                
icculus@1047
   890
                srcp += 4;
icculus@1047
   891
                dstp += 4;
icculus@1047
   892
                width -= 4;
icculus@1047
   893
                vs = voverflow;
icculus@1047
   894
icculus@1047
   895
            }
icculus@1047
   896
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
   897
        }
icculus@1047
   898
	    srcp += srcskip;
icculus@1047
   899
	    dstp += dstskip;
icculus@1047
   900
#undef ONE_PIXEL_BLEND
icculus@1047
   901
	}
icculus@1047
   902
}
icculus@1047
   903
icculus@1047
   904
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
icculus@1047
   905
static void BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo *info)
icculus@1047
   906
{
icculus@1047
   907
	int width = info->d_width;
icculus@1047
   908
	int height = info->d_height;
icculus@1047
   909
	Uint32 *srcp = (Uint32 *)info->s_pixels;
icculus@1047
   910
	int srcskip = info->s_skip >> 2;
icculus@1047
   911
	Uint32 *dstp = (Uint32 *)info->d_pixels;
icculus@1047
   912
	int dstskip = info->d_skip >> 2;
icculus@1047
   913
    vector unsigned char mergePermute;
icculus@1047
   914
    vector unsigned char valphaPermute;
icculus@1047
   915
    vector unsigned char valphamask;
icculus@1047
   916
    vector unsigned char vpixelmask;
icculus@1047
   917
    vector unsigned char v0;
icculus@1047
   918
    vector unsigned short v1;
icculus@1047
   919
    vector unsigned short v8;
icculus@1047
   920
    v0 = vec_splat_u8(0);
icculus@1047
   921
    v1 = vec_splat_u16(1);
icculus@1047
   922
    v8 = vec_splat_u16(8);
icculus@1047
   923
    mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
   924
    valphamask = VEC_ALPHA_MASK();
icculus@1047
   925
    valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
icculus@1047
   926
    
icculus@1047
   927
 
icculus@1047
   928
    vpixelmask = vec_nor(valphamask, v0);
icculus@1047
   929
	while(height--) {
icculus@1047
   930
        width = info->d_width;
icculus@1047
   931
#define ONE_PIXEL_BLEND(condition, widthvar) \
icculus@1047
   932
        while ((condition)) { \
icculus@1047
   933
            Uint32 dalpha; \
icculus@1047
   934
            Uint32 d; \
icculus@1047
   935
            Uint32 s1; \
icculus@1047
   936
            Uint32 d1; \
icculus@1047
   937
            Uint32 s = *srcp; \
icculus@1047
   938
            Uint32 alpha = s >> 24; \
icculus@1047
   939
            if(alpha) { \
icculus@1047
   940
              if(alpha == SDL_ALPHA_OPAQUE) { \
icculus@1047
   941
                *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000); \
icculus@1047
   942
              } else { \
icculus@1047
   943
                d = *dstp; \
icculus@1047
   944
                dalpha = d & 0xff000000; \
icculus@1047
   945
                s1 = s & 0xff00ff; \
icculus@1047
   946
                d1 = d & 0xff00ff; \
icculus@1047
   947
                d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
icculus@1047
   948
                s &= 0xff00; \
icculus@1047
   949
                d &= 0xff00; \
icculus@1047
   950
                d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
icculus@1047
   951
                *dstp = d1 | d | dalpha; \
icculus@1047
   952
              } \
icculus@1047
   953
            } \
icculus@1047
   954
            ++srcp; \
icculus@1047
   955
            ++dstp; \
icculus@1047
   956
            widthvar--; \
icculus@1047
   957
	    }
icculus@1047
   958
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
icculus@1047
   959
        if (width > 0) {
icculus@1047
   960
            int extrawidth = (width % 4);
icculus@1047
   961
            vector unsigned char valigner = VEC_ALIGNER(srcp);
icculus@1047
   962
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
icculus@1047
   963
            width -= extrawidth;
icculus@1047
   964
            while (width) {
icculus@1047
   965
                vector unsigned char voverflow;
icculus@1047
   966
                vector unsigned char vd;
icculus@1047
   967
                vector unsigned char valpha;
icculus@1047
   968
                vector unsigned char vdstalpha;
icculus@1047
   969
                /* s = *srcp */
icculus@1047
   970
                voverflow = (vector unsigned char)vec_ld(15, srcp);
icculus@1047
   971
                vs = vec_perm(vs, voverflow, valigner);
icculus@1047
   972
icculus@1047
   973
                valpha = vec_perm(vs, v0, valphaPermute);
icculus@1047
   974
                
icculus@1047
   975
                /* d = *dstp */
icculus@1047
   976
                vd = (vector unsigned char)vec_ld(0, dstp);
icculus@1047
   977
                vdstalpha = vec_and(vd, valphamask);
icculus@1047
   978
icculus@1047
   979
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
icculus@1047
   980
icculus@1047
   981
                /* set the alpha to the dest alpha */
icculus@1047
   982
                vd = vec_and(vd, vpixelmask);
icculus@1047
   983
                vd = vec_or(vd, vdstalpha);
icculus@1047
   984
icculus@1047
   985
                /* *dstp = res */
icculus@1047
   986
                vec_st((vector unsigned int)vd, 0, dstp);
icculus@1047
   987
                
icculus@1047
   988
                srcp += 4;
icculus@1047
   989
                dstp += 4;
icculus@1047
   990
                width -= 4;
icculus@1047
   991
                vs = voverflow;
icculus@1047
   992
            }
icculus@1047
   993
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
   994
        }
icculus@1047
   995
	    srcp += srcskip;
icculus@1047
   996
	    dstp += dstskip;
icculus@1047
   997
	}
icculus@1047
   998
#undef ONE_PIXEL_BLEND
icculus@1047
   999
}
icculus@1047
  1000
icculus@1047
  1001
static void Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo *info)
icculus@1047
  1002
{
icculus@1047
  1003
    /* XXX : 6 */
icculus@1047
  1004
	unsigned alpha = info->src->alpha;
icculus@1047
  1005
    int height = info->d_height;
icculus@1047
  1006
    Uint32 *srcp = (Uint32 *)info->s_pixels;
icculus@1047
  1007
    int srcskip = info->s_skip >> 2;
icculus@1047
  1008
    Uint32 *dstp = (Uint32 *)info->d_pixels;
icculus@1047
  1009
    int dstskip = info->d_skip >> 2;
icculus@1047
  1010
    SDL_PixelFormat *srcfmt = info->src;
icculus@1047
  1011
    SDL_PixelFormat *dstfmt = info->dst;
icculus@1047
  1012
	unsigned sA = srcfmt->alpha;
icculus@1047
  1013
	unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
icculus@1047
  1014
    vector unsigned char mergePermute;
icculus@1047
  1015
    vector unsigned char vsrcPermute;
icculus@1047
  1016
    vector unsigned char vdstPermute;
icculus@1047
  1017
    vector unsigned char vsdstPermute;
icculus@1047
  1018
    vector unsigned char valpha;
icculus@1047
  1019
    vector unsigned char valphamask;
icculus@1047
  1020
    vector unsigned char vbits;
icculus@1047
  1021
    vector unsigned short v1;
icculus@1047
  1022
    vector unsigned short v8;
icculus@1047
  1023
icculus@1047
  1024
    mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
  1025
    v1 = vec_splat_u16(1);
icculus@1047
  1026
    v8 = vec_splat_u16(8);
icculus@1047
  1027
icculus@1047
  1028
    /* set the alpha to 255 on the destination surf */
icculus@1047
  1029
    valphamask = VEC_ALPHA_MASK();
icculus@1047
  1030
icculus@1047
  1031
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
icculus@1047
  1032
    vdstPermute = calc_swizzle32(NULL, dstfmt);
icculus@1047
  1033
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
icculus@1047
  1034
icculus@1047
  1035
    /* set a vector full of alpha and 255-alpha */
icculus@1047
  1036
    ((unsigned char *)&valpha)[0] = alpha;
icculus@1047
  1037
    valpha = vec_splat(valpha, 0);
icculus@1047
  1038
    vbits = (vector unsigned char)vec_splat_s8(-1);
icculus@1047
  1039
icculus@1047
  1040
    while(height--) {
icculus@1047
  1041
        int width = info->d_width;
icculus@1047
  1042
#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
icculus@1047
  1043
            Uint32 pixel; \
icculus@1047
  1044
            unsigned sR, sG, sB, dR, dG, dB; \
icculus@1047
  1045
            DISEMBLE_RGB(((Uint8 *)srcp), 4, srcfmt, pixel, sR, sG, sB); \
icculus@1047
  1046
            DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, pixel, dR, dG, dB); \
icculus@1047
  1047
            ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
icculus@1047
  1048
            ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
icculus@1047
  1049
            ++srcp; \
icculus@1047
  1050
            ++dstp; \
icculus@1047
  1051
            widthvar--; \
icculus@1047
  1052
        }
icculus@1047
  1053
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
icculus@1047
  1054
        if (width > 0) {
icculus@1047
  1055
            int extrawidth = (width % 4);
icculus@1047
  1056
            vector unsigned char valigner = vec_lvsl(0, srcp);
icculus@1047
  1057
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
icculus@1047
  1058
            width -= extrawidth;
icculus@1047
  1059
            while (width) {
icculus@1047
  1060
                vector unsigned char voverflow;
icculus@1047
  1061
                vector unsigned char vd;
icculus@1047
  1062
icculus@1047
  1063
                /* s = *srcp */
icculus@1047
  1064
                voverflow = (vector unsigned char)vec_ld(15, srcp);
icculus@1047
  1065
                vs = vec_perm(vs, voverflow, valigner);
icculus@1047
  1066
                vs = vec_perm(vs, valpha, vsrcPermute);
icculus@1047
  1067
                
icculus@1047
  1068
                /* d = *dstp */
icculus@1047
  1069
                vd = (vector unsigned char)vec_ld(0, dstp);
icculus@1047
  1070
                vd = vec_perm(vd, vd, vsdstPermute);
icculus@1047
  1071
icculus@1047
  1072
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
icculus@1047
  1073
icculus@1047
  1074
                /* set the alpha channel to full on */
icculus@1047
  1075
                vd = vec_or(vd, valphamask);
icculus@1047
  1076
                vd = vec_perm(vd, vbits, vdstPermute);
icculus@1047
  1077
icculus@1047
  1078
                /* *dstp = res */
icculus@1047
  1079
                vec_st((vector unsigned int)vd, 0, dstp);
icculus@1047
  1080
                
icculus@1047
  1081
                srcp += 4;
icculus@1047
  1082
                dstp += 4;
icculus@1047
  1083
                width -= 4;
icculus@1047
  1084
                vs = voverflow;
icculus@1047
  1085
            }
icculus@1047
  1086
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
  1087
        }
icculus@1047
  1088
#undef ONE_PIXEL_BLEND
icculus@1047
  1089
 
icculus@1047
  1090
        srcp += srcskip;
icculus@1047
  1091
        dstp += dstskip;
icculus@1047
  1092
    }
icculus@1047
  1093
icculus@1047
  1094
}
icculus@1047
  1095
icculus@1047
  1096
icculus@1047
  1097
/* fast RGB888->(A)RGB888 blending */
icculus@1047
  1098
static void BlitRGBtoRGBSurfaceAlphaAltivec(SDL_BlitInfo *info)
icculus@1047
  1099
{
icculus@1047
  1100
	unsigned alpha = info->src->alpha;
icculus@1047
  1101
    int height = info->d_height;
icculus@1047
  1102
    Uint32 *srcp = (Uint32 *)info->s_pixels;
icculus@1047
  1103
    int srcskip = info->s_skip >> 2;
icculus@1047
  1104
    Uint32 *dstp = (Uint32 *)info->d_pixels;
icculus@1047
  1105
    int dstskip = info->d_skip >> 2;
icculus@1047
  1106
    vector unsigned char mergePermute;
icculus@1047
  1107
    vector unsigned char valpha;
icculus@1047
  1108
    vector unsigned char valphamask;
icculus@1047
  1109
    vector unsigned short v1;
icculus@1047
  1110
    vector unsigned short v8;
icculus@1047
  1111
icculus@1047
  1112
    mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
  1113
    v1 = vec_splat_u16(1);
icculus@1047
  1114
    v8 = vec_splat_u16(8);
icculus@1047
  1115
icculus@1047
  1116
    /* set the alpha to 255 on the destination surf */
icculus@1047
  1117
    valphamask = VEC_ALPHA_MASK();
icculus@1047
  1118
icculus@1047
  1119
    /* set a vector full of alpha and 255-alpha */
icculus@1047
  1120
    ((unsigned char *)&valpha)[0] = alpha;
icculus@1047
  1121
    valpha = vec_splat(valpha, 0);
icculus@1047
  1122
icculus@1047
  1123
    while(height--) {
icculus@1047
  1124
        int width = info->d_width;
icculus@1047
  1125
#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
icculus@1047
  1126
            Uint32 s = *srcp; \
icculus@1047
  1127
            Uint32 d = *dstp; \
icculus@1047
  1128
            Uint32 s1 = s & 0xff00ff; \
icculus@1047
  1129
            Uint32 d1 = d & 0xff00ff; \
icculus@1047
  1130
            d1 = (d1 + ((s1 - d1) * alpha >> 8)) \
icculus@1047
  1131
                 & 0xff00ff; \
icculus@1047
  1132
            s &= 0xff00; \
icculus@1047
  1133
            d &= 0xff00; \
icculus@1047
  1134
            d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
icculus@1047
  1135
            *dstp = d1 | d | 0xff000000; \
icculus@1047
  1136
            ++srcp; \
icculus@1047
  1137
            ++dstp; \
icculus@1047
  1138
            widthvar--; \
icculus@1047
  1139
        }
icculus@1047
  1140
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
icculus@1047
  1141
        if (width > 0) {
icculus@1047
  1142
            int extrawidth = (width % 4);
icculus@1047
  1143
            vector unsigned char valigner = VEC_ALIGNER(srcp);
icculus@1047
  1144
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
icculus@1047
  1145
            width -= extrawidth;
icculus@1047
  1146
            while (width) {
icculus@1047
  1147
                vector unsigned char voverflow;
icculus@1047
  1148
                vector unsigned char vd;
icculus@1047
  1149
icculus@1047
  1150
                /* s = *srcp */
icculus@1047
  1151
                voverflow = (vector unsigned char)vec_ld(15, srcp);
icculus@1047
  1152
                vs = vec_perm(vs, voverflow, valigner);
icculus@1047
  1153
                
icculus@1047
  1154
                /* d = *dstp */
icculus@1047
  1155
                vd = (vector unsigned char)vec_ld(0, dstp);
icculus@1047
  1156
icculus@1047
  1157
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
icculus@1047
  1158
icculus@1047
  1159
                /* set the alpha channel to full on */
icculus@1047
  1160
                vd = vec_or(vd, valphamask);
icculus@1047
  1161
icculus@1047
  1162
                /* *dstp = res */
icculus@1047
  1163
                vec_st((vector unsigned int)vd, 0, dstp);
icculus@1047
  1164
                
icculus@1047
  1165
                srcp += 4;
icculus@1047
  1166
                dstp += 4;
icculus@1047
  1167
                width -= 4;
icculus@1047
  1168
                vs = voverflow;
icculus@1047
  1169
            }
icculus@1047
  1170
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
  1171
        }
icculus@1047
  1172
#undef ONE_PIXEL_BLEND
icculus@1047
  1173
 
icculus@1047
  1174
        srcp += srcskip;
icculus@1047
  1175
        dstp += dstskip;
icculus@1047
  1176
    }
icculus@1047
  1177
}
icculus@1047
  1178
#endif /* USE_ALTIVEC_BLITTERS */
icculus@1047
  1179
slouken@1
  1180
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
slouken@1
  1181
static void BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo *info)
slouken@0
  1182
{
slouken@0
  1183
	int width = info->d_width;
slouken@0
  1184
	int height = info->d_height;
slouken@0
  1185
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@0
  1186
	int srcskip = info->s_skip >> 2;
slouken@0
  1187
	Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@0
  1188
	int dstskip = info->d_skip >> 2;
slouken@0
  1189
slouken@0
  1190
	while(height--) {
slouken@0
  1191
	    DUFFS_LOOP4({
slouken@1
  1192
		    Uint32 s = *srcp++;
slouken@1
  1193
		    Uint32 d = *dstp;
slouken@1
  1194
		    *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
slouken@1
  1195
			       + (s & d & 0x00010101)) | 0xff000000;
slouken@0
  1196
	    }, width);
slouken@0
  1197
	    srcp += srcskip;
slouken@0
  1198
	    dstp += dstskip;
slouken@0
  1199
	}
slouken@0
  1200
}
slouken@0
  1201
slouken@1
  1202
/* fast RGB888->(A)RGB888 blending with surface alpha */
slouken@1
  1203
static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo *info)
slouken@1
  1204
{
slouken@1
  1205
	unsigned alpha = info->src->alpha;
slouken@1
  1206
	if(alpha == 128) {
slouken@1
  1207
		BlitRGBtoRGBSurfaceAlpha128(info);
slouken@1
  1208
	} else {
slouken@1
  1209
		int width = info->d_width;
slouken@1
  1210
		int height = info->d_height;
slouken@1
  1211
		Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@1
  1212
		int srcskip = info->s_skip >> 2;
slouken@1
  1213
		Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@1
  1214
		int dstskip = info->d_skip >> 2;
slouken@689
  1215
		Uint32 s;
slouken@689
  1216
		Uint32 d;
slouken@689
  1217
		Uint32 s1;
slouken@689
  1218
		Uint32 d1;
slouken@1
  1219
slouken@1
  1220
		while(height--) {
slouken@689
  1221
			DUFFS_LOOP_DOUBLE2({
slouken@689
  1222
				/* One Pixel Blend */
slouken@1
  1223
				s = *srcp;
slouken@1
  1224
				d = *dstp;
slouken@1
  1225
				s1 = s & 0xff00ff;
slouken@1
  1226
				d1 = d & 0xff00ff;
slouken@1
  1227
				d1 = (d1 + ((s1 - d1) * alpha >> 8))
slouken@1
  1228
				     & 0xff00ff;
slouken@1
  1229
				s &= 0xff00;
slouken@1
  1230
				d &= 0xff00;
slouken@1
  1231
				d = (d + ((s - d) * alpha >> 8)) & 0xff00;
slouken@1
  1232
				*dstp = d1 | d | 0xff000000;
slouken@1
  1233
				++srcp;
slouken@1
  1234
				++dstp;
slouken@689
  1235
			},{
slouken@689
  1236
			        /* Two Pixels Blend */
slouken@689
  1237
				s = *srcp;
slouken@689
  1238
				d = *dstp;
slouken@689
  1239
				s1 = s & 0xff00ff;
slouken@689
  1240
				d1 = d & 0xff00ff;
slouken@689
  1241
				d1 += (s1 - d1) * alpha >> 8;
slouken@689
  1242
				d1 &= 0xff00ff;
slouken@689
  1243
				     
slouken@689
  1244
				s = ((s & 0xff00) >> 8) | 
slouken@689
  1245
					((srcp[1] & 0xff00) << 8);
slouken@689
  1246
				d = ((d & 0xff00) >> 8) |
slouken@689
  1247
					((dstp[1] & 0xff00) << 8);
slouken@689
  1248
				d += (s - d) * alpha >> 8;
slouken@689
  1249
				d &= 0x00ff00ff;
slouken@689
  1250
				
slouken@689
  1251
				*dstp++ = d1 | ((d << 8) & 0xff00) | 0xff000000;
slouken@689
  1252
				++srcp;
slouken@689
  1253
				
slouken@689
  1254
			        s1 = *srcp;
slouken@689
  1255
				d1 = *dstp;
slouken@689
  1256
				s1 &= 0xff00ff;
slouken@689
  1257
				d1 &= 0xff00ff;
slouken@689
  1258
				d1 += (s1 - d1) * alpha >> 8;
slouken@689
  1259
				d1 &= 0xff00ff;
slouken@689
  1260
				
slouken@689
  1261
				*dstp = d1 | ((d >> 8) & 0xff00) | 0xff000000;
slouken@689
  1262
				++srcp;
slouken@689
  1263
				++dstp;
slouken@1
  1264
			}, width);
slouken@1
  1265
			srcp += srcskip;
slouken@1
  1266
			dstp += dstskip;
slouken@1
  1267
		}
slouken@1
  1268
	}
slouken@1
  1269
}
slouken@1
  1270
slouken@0
  1271
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
slouken@0
  1272
static void BlitRGBtoRGBPixelAlpha(SDL_BlitInfo *info)
slouken@0
  1273
{
slouken@0
  1274
	int width = info->d_width;
slouken@0
  1275
	int height = info->d_height;
slouken@0
  1276
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@0
  1277
	int srcskip = info->s_skip >> 2;
slouken@0
  1278
	Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@0
  1279
	int dstskip = info->d_skip >> 2;
slouken@0
  1280
slouken@0
  1281
	while(height--) {
slouken@0
  1282
	    DUFFS_LOOP4({
slouken@0
  1283
		Uint32 dalpha;
slouken@0
  1284
		Uint32 d;
slouken@0
  1285
		Uint32 s1;
slouken@0
  1286
		Uint32 d1;
slouken@0
  1287
		Uint32 s = *srcp;
slouken@0
  1288
		Uint32 alpha = s >> 24;
slouken@0
  1289
		/* FIXME: Here we special-case opaque alpha since the
slouken@0
  1290
		   compositioning used (>>8 instead of /255) doesn't handle
slouken@0
  1291
		   it correctly. Also special-case alpha=0 for speed?
slouken@0
  1292
		   Benchmark this! */
slouken@689
  1293
		if(alpha) {   
slouken@689
  1294
		  if(alpha == SDL_ALPHA_OPAQUE) {
slouken@0
  1295
		    *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000);
slouken@689
  1296
		  } else {
slouken@0
  1297
		    /*
slouken@0
  1298
		     * take out the middle component (green), and process
slouken@0
  1299
		     * the other two in parallel. One multiply less.
slouken@0
  1300
		     */
slouken@0
  1301
		    d = *dstp;
slouken@0
  1302
		    dalpha = d & 0xff000000;
slouken@0
  1303
		    s1 = s & 0xff00ff;
slouken@0
  1304
		    d1 = d & 0xff00ff;
slouken@0
  1305
		    d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff;
slouken@0
  1306
		    s &= 0xff00;
slouken@0
  1307
		    d &= 0xff00;
slouken@0
  1308
		    d = (d + ((s - d) * alpha >> 8)) & 0xff00;
slouken@0
  1309
		    *dstp = d1 | d | dalpha;
slouken@689
  1310
		  }
slouken@0
  1311
		}
slouken@0
  1312
		++srcp;
slouken@0
  1313
		++dstp;
slouken@0
  1314
	    }, width);
slouken@0
  1315
	    srcp += srcskip;
slouken@0
  1316
	    dstp += dstskip;
slouken@0
  1317
	}
slouken@0
  1318
}
slouken@0
  1319
slouken@880
  1320
#ifdef MMX_ASMBLIT
slouken@689
  1321
/* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */
slouken@689
  1322
inline static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info)
slouken@689
  1323
{
slouken@689
  1324
	int width = info->d_width;
slouken@689
  1325
	int height = info->d_height;
slouken@689
  1326
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@689
  1327
	int srcskip = info->s_skip >> 2;
slouken@689
  1328
	Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@689
  1329
	int dstskip = info->d_skip >> 2;
slouken@689
  1330
slouken@689
  1331
	Uint32 s;
slouken@689
  1332
	Uint32 alpha;
slouken@689
  1333
slouken@689
  1334
	__asm__ (
slouken@689
  1335
	/* make mm6 all zeros. */
slouken@689
  1336
	"pxor       %%mm6, %%mm6\n"
slouken@689
  1337
	
slouken@689
  1338
	/* Make a mask to preserve the alpha. */
slouken@689
  1339
	"pcmpeqb   %%mm7, %%mm7\n\t"            /* mm7(s) = FF FF FF FF | FF FF FF FF */
slouken@689
  1340
	"psrlq     $16, %%mm7\n\t"		    /* mm7(s) = 00 00 FF FF | FF FF FF FF */
slouken@689
  1341
slouken@689
  1342
		: );
slouken@689
  1343
slouken@689
  1344
	while(height--) {
slouken@689
  1345
slouken@689
  1346
	    DUFFS_LOOP4({
slouken@689
  1347
slouken@689
  1348
		__asm__ (
slouken@689
  1349
		"prefetch 64(%0)\n"
slouken@689
  1350
		"prefetch 64(%1)\n"
slouken@689
  1351
			: : "r" (srcp), "r" (dstp) );
slouken@689
  1352
slouken@689
  1353
		s = *srcp;
slouken@689
  1354
		alpha = s >> 24;
slouken@689
  1355
		/* FIXME: Here we special-case opaque alpha since the
slouken@689
  1356
		   compositioning used (>>8 instead of /255) doesn't handle
slouken@689
  1357
		   it correctly. Also special-case alpha=0 for speed?
slouken@689
  1358
		   Benchmark this! */
slouken@689
  1359
		
slouken@689
  1360
		if(alpha == SDL_ALPHA_OPAQUE) {
slouken@689
  1361
		    *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000);
slouken@689
  1362
		} 
slouken@689
  1363
slouken@689
  1364
		else {
slouken@689
  1365
			    __asm__ (
slouken@689
  1366
		    /* load in the source, and dst. */
slouken@689
  1367
		    "movd      (%0), %%mm0\n"		    /* mm0(s) = 0 0 0 0 | As Rs Gs Bs */
slouken@689
  1368
		    "movd      (%1), %%mm1\n"		    /* mm1(d) = 0 0 0 0 | Ad Rd Gd Bd */
slouken@689
  1369
slouken@689
  1370
		    /* Move the src alpha into mm2 */
slouken@689
  1371
slouken@689
  1372
		    /* if supporting pshufw */
slouken@689
  1373
		    /*"pshufw     $0x55, %%mm0, %%mm2\n" */ /* mm2 = 0 As 0 As |  0 As  0  As */
slouken@689
  1374
		    /*"psrlw     $8, %%mm2\n" */
slouken@689
  1375
		    
slouken@689
  1376
		    /* else: */
slouken@689
  1377
		    "movq      %%mm0, %%mm2\n"
slouken@689
  1378
		    "psrld     $24, %%mm2\n"                /* mm2 = 0 0 0 0 | 0  0  0  As */
slouken@689
  1379
		    "punpcklwd	%%mm2, %%mm2\n"	            /* mm2 = 0 0 0 0 |  0 As  0  As */
slouken@689
  1380
		    "punpckldq	%%mm2, %%mm2\n"             /* mm2 = 0 As 0 As |  0 As  0  As */
slouken@689
  1381
slouken@689
  1382
		    /* move the colors into words. */
slouken@689
  1383
		    "punpcklbw %%mm6, %%mm0\n"		    /* mm0 = 0 As 0 Rs | 0 Gs 0 Bs */
slouken@689
  1384
		    "punpcklbw %%mm6, %%mm1\n"              /* mm0 = 0 Ad 0 Rd | 0 Gd 0 Bd */
slouken@689
  1385
slouken@689
  1386
		    /* src - dst */
slouken@689
  1387
		    "psubw    %%mm1, %%mm0\n"		    /* mm0 = As-Ad Rs-Rd | Gs-Gd  Bs-Bd */
slouken@689
  1388
slouken@689
  1389
		    /* A * (src-dst) */
slouken@689
  1390
		    "pmullw    %%mm2, %%mm0\n"		    /* mm0 = As*As-d As*Rs-d | As*Gs-d  As*Bs-d */
slouken@689
  1391
		    "pand      %%mm7, %%mm0\n"              /* to preserve dest alpha */
slouken@689
  1392
		    "psrlw     $8,    %%mm0\n"		    /* mm0 = Ac>>8 Rc>>8 | Gc>>8  Bc>>8 */
slouken@689
  1393
		    "paddb     %%mm1, %%mm0\n"		    /* mm0 = Ac+Ad Rc+Rd | Gc+Gd  Bc+Bd */
slouken@689
  1394
slouken@689
  1395
		    "packuswb  %%mm0, %%mm0\n"              /* mm0 =             | Ac Rc Gc Bc */
slouken@689
  1396
		    
slouken@689
  1397
		    "movd      %%mm0, (%1)\n"               /* result in mm0 */
slouken@689
  1398
slouken@689
  1399
		     : : "r" (srcp), "r" (dstp) );
slouken@689
  1400
slouken@689
  1401
		}
slouken@689
  1402
		++srcp;
slouken@689
  1403
		++dstp;
slouken@689
  1404
	    }, width);
slouken@689
  1405
	    srcp += srcskip;
slouken@689
  1406
	    dstp += dstskip;
slouken@689
  1407
	}
slouken@689
  1408
slouken@689
  1409
	__asm__ (
slouken@689
  1410
	"emms\n"
slouken@689
  1411
		:   );
slouken@689
  1412
}
slouken@689
  1413
#endif
slouken@689
  1414
slouken@1
  1415
/* 16bpp special case for per-surface alpha=50%: blend 2 pixels in parallel */
slouken@1
  1416
slouken@1
  1417
/* blend a single 16 bit pixel at 50% */
slouken@1
  1418
#define BLEND16_50(d, s, mask)						\
slouken@1
  1419
	((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff)))
slouken@1
  1420
slouken@1
  1421
/* blend two 16 bit pixels at 50% */
slouken@1
  1422
#define BLEND2x16_50(d, s, mask)					     \
slouken@1
  1423
	(((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \
slouken@1
  1424
	 + (s & d & (~(mask | mask << 16))))
slouken@1
  1425
slouken@1
  1426
static void Blit16to16SurfaceAlpha128(SDL_BlitInfo *info, Uint16 mask)
slouken@0
  1427
{
slouken@0
  1428
	int width = info->d_width;
slouken@0
  1429
	int height = info->d_height;
slouken@0
  1430
	Uint16 *srcp = (Uint16 *)info->s_pixels;
slouken@0
  1431
	int srcskip = info->s_skip >> 1;
slouken@0
  1432
	Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@0
  1433
	int dstskip = info->d_skip >> 1;
slouken@0
  1434
slouken@0
  1435
	while(height--) {
slouken@1
  1436
		if(((unsigned long)srcp ^ (unsigned long)dstp) & 2) {
slouken@1
  1437
			/*
slouken@1
  1438
			 * Source and destination not aligned, pipeline it.
slouken@1
  1439
			 * This is mostly a win for big blits but no loss for
slouken@1
  1440
			 * small ones
slouken@1
  1441
			 */
slouken@1
  1442
			Uint32 prev_sw;
slouken@1
  1443
			int w = width;
slouken@1
  1444
slouken@1
  1445
			/* handle odd destination */
slouken@1
  1446
			if((unsigned long)dstp & 2) {
slouken@1
  1447
				Uint16 d = *dstp, s = *srcp;
slouken@1
  1448
				*dstp = BLEND16_50(d, s, mask);
slouken@1
  1449
				dstp++;
slouken@1
  1450
				srcp++;
slouken@1
  1451
				w--;
slouken@1
  1452
			}
slouken@1
  1453
			srcp++;	/* srcp is now 32-bit aligned */
slouken@1
  1454
slouken@1
  1455
			/* bootstrap pipeline with first halfword */
slouken@1
  1456
			prev_sw = ((Uint32 *)srcp)[-1];
slouken@1
  1457
slouken@1
  1458
			while(w > 1) {
slouken@1
  1459
				Uint32 sw, dw, s;
slouken@1
  1460
				sw = *(Uint32 *)srcp;
slouken@1
  1461
				dw = *(Uint32 *)dstp;
slouken@1
  1462
				if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
slouken@1
  1463
					s = (prev_sw << 16) + (sw >> 16);
slouken@1
  1464
				else
slouken@1
  1465
					s = (prev_sw >> 16) + (sw << 16);
slouken@1
  1466
				prev_sw = sw;
slouken@1
  1467
				*(Uint32 *)dstp = BLEND2x16_50(dw, s, mask);
slouken@1
  1468
				dstp += 2;
slouken@1
  1469
				srcp += 2;
slouken@1
  1470
				w -= 2;
slouken@1
  1471
			}
slouken@1
  1472
slouken@1
  1473
			/* final pixel if any */
slouken@1
  1474
			if(w) {
slouken@1
  1475
				Uint16 d = *dstp, s;
slouken@1
  1476
				if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
slouken@1
  1477
					s = prev_sw;
slouken@1
  1478
				else
slouken@1
  1479
					s = prev_sw >> 16;
slouken@1
  1480
				*dstp = BLEND16_50(d, s, mask);
slouken@1
  1481
				srcp++;
slouken@1
  1482
				dstp++;
slouken@1
  1483
			}
slouken@1
  1484
			srcp += srcskip - 1;
slouken@1
  1485
			dstp += dstskip;
slouken@1
  1486
		} else {
slouken@1
  1487
			/* source and destination are aligned */
slouken@1
  1488
			int w = width;
slouken@1
  1489
slouken@1
  1490
			/* first odd pixel? */
slouken@1
  1491
			if((unsigned long)srcp & 2) {
slouken@1
  1492
				Uint16 d = *dstp, s = *srcp;
slouken@1
  1493
				*dstp = BLEND16_50(d, s, mask);
slouken@1
  1494
				srcp++;
slouken@1
  1495
				dstp++;
slouken@1
  1496
				w--;
slouken@1
  1497
			}
slouken@1
  1498
			/* srcp and dstp are now 32-bit aligned */
slouken@1
  1499
slouken@1
  1500
			while(w > 1) {
slouken@1
  1501
				Uint32 sw = *(Uint32 *)srcp;
slouken@1
  1502
				Uint32 dw = *(Uint32 *)dstp;
slouken@1
  1503
				*(Uint32 *)dstp = BLEND2x16_50(dw, sw, mask);
slouken@1
  1504
				srcp += 2;
slouken@1
  1505
				dstp += 2;
slouken@1
  1506
				w -= 2;
slouken@1
  1507
			}
slouken@1
  1508
slouken@1
  1509
			/* last odd pixel? */
slouken@1
  1510
			if(w) {
slouken@1
  1511
				Uint16 d = *dstp, s = *srcp;
slouken@1
  1512
				*dstp = BLEND16_50(d, s, mask);
slouken@1
  1513
				srcp++;
slouken@1
  1514
				dstp++;
slouken@1
  1515
			}
slouken@1
  1516
			srcp += srcskip;
slouken@1
  1517
			dstp += dstskip;
slouken@1
  1518
		}
slouken@1
  1519
	}
slouken@1
  1520
}
slouken@1
  1521
slouken@880
  1522
#ifdef MMX_ASMBLIT
slouken@689
  1523
/* fast RGB565->RGB565 blending with surface alpha */
slouken@689
  1524
static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo *info)
slouken@689
  1525
{
slouken@689
  1526
	unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
slouken@689
  1527
	if(alpha == 128) {
slouken@689
  1528
		Blit16to16SurfaceAlpha128(info, 0xf7de);
slouken@689
  1529
	} else {
slouken@689
  1530
		int width = info->d_width;
slouken@689
  1531
		int height = info->d_height;
slouken@689
  1532
		Uint16 *srcp = (Uint16 *)info->s_pixels;
slouken@689
  1533
		int srcskip = info->s_skip >> 1;
slouken@689
  1534
		Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@689
  1535
		int dstskip = info->d_skip >> 1;
slouken@689
  1536
	        Uint32 s, d;
slouken@689
  1537
	        Uint8 load[8];
slouken@689
  1538
	  
slouken@689
  1539
		alpha &= ~(1+2+4);		/* cut alpha to get the exact same behaviour */
slouken@689
  1540
	        *(Uint64 *)load = alpha;
slouken@689
  1541
		alpha >>= 3;		/* downscale alpha to 5 bits */
slouken@689
  1542
slouken@689
  1543
                movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */
slouken@689
  1544
                punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */
slouken@689
  1545
                punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */
slouken@689
  1546
	  
slouken@689
  1547
 	        /* Setup the 565 color channel masks */
slouken@720
  1548
	        *(Uint64 *)load = 0xF800F800F800F800ULL;
slouken@689
  1549
		movq_m2r(*load, mm1); /* MASKRED -> mm1 */
slouken@720
  1550
		*(Uint64 *)load = 0x07E007E007E007E0ULL;
slouken@689
  1551
		movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */
slouken@720
  1552
		*(Uint64 *)load = 0x001F001F001F001FULL;
slouken@689
  1553
		movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */
slouken@689
  1554
		while(height--) {
slouken@689
  1555
                        DUFFS_LOOP_QUATRO2(
slouken@689
  1556
                        {
slouken@689
  1557
	                        s = *srcp++;
slouken@689
  1558
				d = *dstp;
slouken@689
  1559
				/*
slouken@689
  1560
				 * shift out the middle component (green) to
slouken@689
  1561
				 * the high 16 bits, and process all three RGB
slouken@689
  1562
				 * components at the same time.
slouken@689
  1563
				 */
slouken@689
  1564
				s = (s | s << 16) & 0x07e0f81f;
slouken@689
  1565
				d = (d | d << 16) & 0x07e0f81f;
slouken@689
  1566
				d += (s - d) * alpha >> 5;
slouken@689
  1567
				d &= 0x07e0f81f;
slouken@689
  1568
				*dstp++ = d | d >> 16;
slouken@689
  1569
                        },{
slouken@689
  1570
	                        s = *srcp++;
slouken@689
  1571
				d = *dstp;
slouken@689
  1572
				/*
slouken@689
  1573
				 * shift out the middle component (green) to
slouken@689
  1574
				 * the high 16 bits, and process all three RGB
slouken@689
  1575
				 * components at the same time.
slouken@689
  1576
				 */
slouken@689
  1577
				s = (s | s << 16) & 0x07e0f81f;
slouken@689
  1578
				d = (d | d << 16) & 0x07e0f81f;
slouken@689
  1579
				d += (s - d) * alpha >> 5;
slouken@689
  1580
				d &= 0x07e0f81f;
slouken@689
  1581
				*dstp++ = d | d >> 16;
slouken@689
  1582
			        s = *srcp++;
slouken@689
  1583
				d = *dstp;
slouken@689
  1584
				/*
slouken@689
  1585
				 * shift out the middle component (green) to
slouken@689
  1586
				 * the high 16 bits, and process all three RGB
slouken@689
  1587
				 * components at the same time.
slouken@689
  1588
				 */
slouken@689
  1589
				s = (s | s << 16) & 0x07e0f81f;
slouken@689
  1590
				d = (d | d << 16) & 0x07e0f81f;
slouken@689
  1591
				d += (s - d) * alpha >> 5;
slouken@689
  1592
				d &= 0x07e0f81f;
slouken@689
  1593
				*dstp++ = d | d >> 16;
slouken@689
  1594
                        },{
slouken@689
  1595
	                        movq_m2r((*dstp), mm3);/* 4 dst pixels -> mm3 */
slouken@689
  1596
	                        movq_m2r((*srcp), mm2);/* 4 src pixels -> mm2 */
slouken@689
  1597
			  
slouken@689
  1598
	                        /* RED */
slouken@689
  1599
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1600
	                        pand_r2r(mm1 , mm5); /* src & MASKRED -> mm5 */
slouken@689
  1601
	                        psrlq_i2r(11, mm5); /* mm5 >> 11 -> mm5 [000r 000r 000r 000r] */
slouken@689
  1602
	
slouken@689
  1603
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1604
	                        pand_r2r(mm1 , mm6); /* dst & MASKRED -> mm6 */
slouken@689
  1605
	                        psrlq_i2r(11, mm6); /* mm6 >> 11 -> mm6 [000r 000r 000r 000r] */
slouken@689
  1606
	
slouken@689
  1607
	                        /* blend */
slouken@689
  1608
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1609
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1610
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1611
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1612
	                        psllq_i2r(11, mm6); /* mm6 << 11 -> mm6 */
slouken@689
  1613
	                        pand_r2r(mm1, mm6); /* mm6 & MASKRED -> mm6 */
slouken@689
  1614
	
slouken@689
  1615
	                        movq_r2r(mm4, mm5); /* MASKGREEN -> mm5 */
slouken@689
  1616
	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
slouken@689
  1617
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKRED) -> mm3 */
slouken@689
  1618
	                        por_r2r(mm6, mm3); /* save new reds in dsts */
slouken@689
  1619
	
slouken@689
  1620
	                        /* green */
slouken@689
  1621
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1622
	                        pand_r2r(mm4 , mm5); /* src & MASKGREEN -> mm5 */
slouken@689
  1623
	                        psrlq_i2r(5, mm5); /* mm5 >> 5 -> mm5 [000g 000g 000g 000g] */
slouken@689
  1624
	
slouken@689
  1625
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1626
	                        pand_r2r(mm4 , mm6); /* dst & MASKGREEN -> mm6 */
slouken@689
  1627
	                        psrlq_i2r(5, mm6); /* mm6 >> 5 -> mm6 [000g 000g 000g 000g] */
slouken@689
  1628
	
slouken@689
  1629
	                        /* blend */
slouken@689
  1630
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1631
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1632
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1633
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1634
	                        psllq_i2r(5, mm6); /* mm6 << 5 -> mm6 */
slouken@689
  1635
	                        pand_r2r(mm4, mm6); /* mm6 & MASKGREEN -> mm6 */
slouken@689
  1636
	
slouken@689
  1637
	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
slouken@689
  1638
	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
slouken@689
  1639
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKGREEN) -> mm3 */
slouken@689
  1640
	                        por_r2r(mm6, mm3); /* save new greens in dsts */
slouken@689
  1641
	
slouken@689
  1642
	                        /* blue */
slouken@689
  1643
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1644
	                        pand_r2r(mm7 , mm5); /* src & MASKRED -> mm5[000b 000b 000b 000b] */
slouken@689
  1645
		
slouken@689
  1646
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1647
	                        pand_r2r(mm7 , mm6); /* dst & MASKBLUE -> mm6[000b 000b 000b 000b] */
slouken@689
  1648
	
slouken@689
  1649
	                        /* blend */
slouken@689
  1650
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1651
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1652
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1653
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1654
	                        pand_r2r(mm7, mm6); /* mm6 & MASKBLUE -> mm6 */
slouken@689
  1655
	
slouken@689
  1656
	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
slouken@689
  1657
	                        por_r2r(mm4, mm5);  /* MASKGREEN | mm5 -> mm5 */
slouken@689
  1658
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKBLUE) -> mm3 */
slouken@689
  1659
	                        por_r2r(mm6, mm3); /* save new blues in dsts */
slouken@689
  1660
	
slouken@689
  1661
	                        movq_r2m(mm3, *dstp);/* mm3 -> 4 dst pixels */
slouken@689
  1662
	
slouken@689
  1663
	                        srcp += 4;
slouken@689
  1664
	                        dstp += 4;
slouken@689
  1665
                        }, width);			
slouken@689
  1666
			srcp += srcskip;
slouken@689
  1667
			dstp += dstskip;
slouken@689
  1668
		}
slouken@689
  1669
		emms();
slouken@689
  1670
	}
slouken@689
  1671
}
slouken@689
  1672
slouken@689
  1673
/* fast RGB555->RGB555 blending with surface alpha */
slouken@689
  1674
static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo *info)
slouken@689
  1675
{
slouken@689
  1676
	unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
slouken@689
  1677
	if(alpha == 128) {
slouken@689
  1678
		Blit16to16SurfaceAlpha128(info, 0xfbde);
slouken@689
  1679
	} else {
slouken@689
  1680
		int width = info->d_width;
slouken@689
  1681
		int height = info->d_height;
slouken@689
  1682
		Uint16 *srcp = (Uint16 *)info->s_pixels;
slouken@689
  1683
		int srcskip = info->s_skip >> 1;
slouken@689
  1684
		Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@689
  1685
		int dstskip = info->d_skip >> 1;
slouken@689
  1686
	        Uint32 s, d;
slouken@689
  1687
	        Uint8 load[8];
slouken@689
  1688
	  
slouken@689
  1689
		alpha &= ~(1+2+4);		/* cut alpha to get the exact same behaviour */
slouken@689
  1690
	        *(Uint64 *)load = alpha;
slouken@689
  1691
		alpha >>= 3;		/* downscale alpha to 5 bits */
slouken@689
  1692
slouken@689
  1693
                movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */
slouken@689
  1694
                punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */
slouken@689
  1695
                punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */
slouken@689
  1696
	  
slouken@689
  1697
 	        /* Setup the 555 color channel masks */
slouken@720
  1698
	        *(Uint64 *)load = 0x7C007C007C007C00ULL;
slouken@689
  1699
		movq_m2r(*load, mm1); /* MASKRED -> mm1 */
slouken@720
  1700
		*(Uint64 *)load = 0x03E003E003E003E0ULL;
slouken@689
  1701
		movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */
slouken@720
  1702
		*(Uint64 *)load = 0x001F001F001F001FULL;
slouken@689
  1703
		movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */
slouken@689
  1704
		while(height--) {
slouken@689
  1705
                        DUFFS_LOOP_QUATRO2(
slouken@689
  1706
                        {
slouken@689
  1707
	                        s = *srcp++;
slouken@689
  1708
				d = *dstp;
slouken@689
  1709
				/*
slouken@689
  1710
				 * shift out the middle component (green) to
slouken@689
  1711
				 * the high 16 bits, and process all three RGB
slouken@689
  1712
				 * components at the same time.
slouken@689
  1713
				 */
slouken@689
  1714
				s = (s | s << 16) & 0x03e07c1f;
slouken@689
  1715
				d = (d | d << 16) & 0x03e07c1f;
slouken@689
  1716
				d += (s - d) * alpha >> 5;
slouken@689
  1717
				d &= 0x03e07c1f;
slouken@689
  1718
				*dstp++ = d | d >> 16;
slouken@689
  1719
                        },{
slouken@689
  1720
	                        s = *srcp++;
slouken@689
  1721
				d = *dstp;
slouken@689
  1722
				/*
slouken@689
  1723
				 * shift out the middle component (green) to
slouken@689
  1724
				 * the high 16 bits, and process all three RGB
slouken@689
  1725
				 * components at the same time.
slouken@689
  1726
				 */
slouken@689
  1727
				s = (s | s << 16) & 0x03e07c1f;
slouken@689
  1728
				d = (d | d << 16) & 0x03e07c1f;
slouken@689
  1729
				d += (s - d) * alpha >> 5;
slouken@689
  1730
				d &= 0x03e07c1f;
slouken@689
  1731
				*dstp++ = d | d >> 16;
slouken@689
  1732
			        s = *srcp++;
slouken@689
  1733
				d = *dstp;
slouken@689
  1734
				/*
slouken@689
  1735
				 * shift out the middle component (green) to
slouken@689
  1736
				 * the high 16 bits, and process all three RGB
slouken@689
  1737
				 * components at the same time.
slouken@689
  1738
				 */
slouken@689
  1739
				s = (s | s << 16) & 0x03e07c1f;
slouken@689
  1740
				d = (d | d << 16) & 0x03e07c1f;
slouken@689
  1741
				d += (s - d) * alpha >> 5;
slouken@689
  1742
				d &= 0x03e07c1f;
slouken@689
  1743
				*dstp++ = d | d >> 16;
slouken@689
  1744
                        },{
slouken@689
  1745
	                        movq_m2r((*dstp), mm3);/* 4 dst pixels -> mm3 */
slouken@689
  1746
	                        movq_m2r((*srcp), mm2);/* 4 src pixels -> mm2 */
slouken@689
  1747
			  
slouken@689
  1748
	                        /* RED */
slouken@689
  1749
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1750
	                        pand_r2r(mm1 , mm5); /* src & MASKRED -> mm5 */
slouken@689
  1751
	                        psrlq_i2r(10, mm5); /* mm5 >> 10 -> mm5 [000r 000r 000r 000r] */
slouken@689
  1752
	
slouken@689
  1753
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1754
	                        pand_r2r(mm1 , mm6); /* dst & MASKRED -> mm6 */
slouken@689
  1755
	                        psrlq_i2r(10, mm6); /* mm6 >> 10 -> mm6 [000r 000r 000r 000r] */
slouken@689
  1756
	
slouken@689
  1757
	                        /* blend */
slouken@689
  1758
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1759
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1760
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1761
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1762
	                        psllq_i2r(10, mm6); /* mm6 << 10 -> mm6 */
slouken@689
  1763
	                        pand_r2r(mm1, mm6); /* mm6 & MASKRED -> mm6 */
slouken@689
  1764
	
slouken@689
  1765
	                        movq_r2r(mm4, mm5); /* MASKGREEN -> mm5 */
slouken@689
  1766
	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
slouken@689
  1767
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKRED) -> mm3 */
slouken@689
  1768
	                        por_r2r(mm6, mm3); /* save new reds in dsts */
slouken@689
  1769
	
slouken@689
  1770
	                        /* green */
slouken@689
  1771
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1772
	                        pand_r2r(mm4 , mm5); /* src & MASKGREEN -> mm5 */
slouken@689
  1773
	                        psrlq_i2r(5, mm5); /* mm5 >> 5 -> mm5 [000g 000g 000g 000g] */
slouken@689
  1774
	
slouken@689
  1775
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1776
	                        pand_r2r(mm4 , mm6); /* dst & MASKGREEN -> mm6 */
slouken@689
  1777
	                        psrlq_i2r(5, mm6); /* mm6 >> 5 -> mm6 [000g 000g 000g 000g] */
slouken@689
  1778
	
slouken@689
  1779
	                        /* blend */
slouken@689
  1780
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1781
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1782
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1783
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1784
	                        psllq_i2r(5, mm6); /* mm6 << 5 -> mm6 */
slouken@689
  1785
	                        pand_r2r(mm4, mm6); /* mm6 & MASKGREEN -> mm6 */
slouken@689
  1786
	
slouken@689
  1787
	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
slouken@689
  1788
	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
slouken@689
  1789
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKGREEN) -> mm3 */
slouken@689
  1790
	                        por_r2r(mm6, mm3); /* save new greens in dsts */
slouken@689
  1791
	
slouken@689
  1792
	                        /* blue */
slouken@689
  1793
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1794
	                        pand_r2r(mm7 , mm5); /* src & MASKRED -> mm5[000b 000b 000b 000b] */
slouken@689
  1795
		
slouken@689
  1796
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1797
	                        pand_r2r(mm7 , mm6); /* dst & MASKBLUE -> mm6[000b 000b 000b 000b] */
slouken@689
  1798
	
slouken@689
  1799
	                        /* blend */
slouken@689
  1800
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1801
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1802
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1803
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1804
	                        pand_r2r(mm7, mm6); /* mm6 & MASKBLUE -> mm6 */
slouken@689
  1805
	
slouken@689
  1806
	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
slouken@689
  1807
	                        por_r2r(mm4, mm5);  /* MASKGREEN | mm5 -> mm5 */
slouken@689
  1808
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKBLUE) -> mm3 */
slouken@689
  1809
	                        por_r2r(mm6, mm3); /* save new blues in dsts */
slouken@689
  1810
	
slouken@689
  1811
	                        movq_r2m(mm3, *dstp);/* mm3 -> 4 dst pixels */
slouken@689
  1812
	
slouken@689
  1813
	                        srcp += 4;
slouken@689
  1814
	                        dstp += 4;
slouken@689
  1815
                        }, width);			
slouken@689
  1816
			srcp += srcskip;
slouken@689
  1817
			dstp += dstskip;
slouken@689
  1818
		}
slouken@689
  1819
		emms();
slouken@689
  1820
	}
slouken@689
  1821
}
slouken@689
  1822
#endif
slouken@689
  1823
slouken@1
  1824
/* fast RGB565->RGB565 blending with surface alpha */
slouken@1
  1825
static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info)
slouken@1
  1826
{
slouken@1
  1827
	unsigned alpha = info->src->alpha;
slouken@1
  1828
	if(alpha == 128) {
slouken@1
  1829
		Blit16to16SurfaceAlpha128(info, 0xf7de);
slouken@1
  1830
	} else {
slouken@1
  1831
		int width = info->d_width;
slouken@1
  1832
		int height = info->d_height;
slouken@1
  1833
		Uint16 *srcp = (Uint16 *)info->s_pixels;
slouken@1
  1834
		int srcskip = info->s_skip >> 1;
slouken@1
  1835
		Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@1
  1836
		int dstskip = info->d_skip >> 1;
slouken@1
  1837
		alpha >>= 3;	/* downscale alpha to 5 bits */
slouken@1
  1838
slouken@1
  1839
		while(height--) {
slouken@1
  1840
			DUFFS_LOOP4({
slouken@1
  1841
				Uint32 s = *srcp++;
slouken@1
  1842
				Uint32 d = *dstp;
slouken@1
  1843
				/*
slouken@1
  1844
				 * shift out the middle component (green) to
slouken@1
  1845
				 * the high 16 bits, and process all three RGB
slouken@1
  1846
				 * components at the same time.
slouken@1
  1847
				 */
slouken@1
  1848
				s = (s | s << 16) & 0x07e0f81f;
slouken@1
  1849
				d = (d | d << 16) & 0x07e0f81f;
slouken@1
  1850
				d += (s - d) * alpha >> 5;
slouken@1
  1851
				d &= 0x07e0f81f;
slouken@1
  1852
				*dstp++ = d | d >> 16;
slouken@1
  1853
			}, width);
slouken@1
  1854
			srcp += srcskip;
slouken@1
  1855
			dstp += dstskip;
slouken@1
  1856
		}
slouken@0
  1857
	}
slouken@0
  1858
}
slouken@0
  1859
slouken@0
  1860
/* fast RGB555->RGB555 blending with surface alpha */
slouken@0
  1861
static void Blit555to555SurfaceAlpha(SDL_BlitInfo *info)
slouken@0
  1862
{
slouken@1
  1863
	unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
slouken@1
  1864
	if(alpha == 128) {
slouken@1
  1865
		Blit16to16SurfaceAlpha128(info, 0xfbde);
slouken@1
  1866
	} else {
slouken@1
  1867
		int width = info->d_width;
slouken@1
  1868
		int height = info->d_height;
slouken@1
  1869
		Uint16 *srcp = (Uint16 *)info->s_pixels;
slouken@1
  1870
		int srcskip = info->s_skip >> 1;
slouken@1
  1871
		Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@1
  1872
		int dstskip = info->d_skip >> 1;
slouken@1
  1873
		alpha >>= 3;		/* downscale alpha to 5 bits */
slouken@0
  1874
slouken@1
  1875
		while(height--) {
slouken@1
  1876
			DUFFS_LOOP4({
slouken@1
  1877
				Uint32 s = *srcp++;
slouken@1
  1878
				Uint32 d = *dstp;
slouken@1
  1879
				/*
slouken@1
  1880
				 * shift out the middle component (green) to
slouken@1
  1881
				 * the high 16 bits, and process all three RGB
slouken@1
  1882
				 * components at the same time.
slouken@1
  1883
				 */
slouken@1
  1884
				s = (s | s << 16) & 0x03e07c1f;
slouken@1
  1885
				d = (d | d << 16) & 0x03e07c1f;
slouken@1
  1886
				d += (s - d) * alpha >> 5;
slouken@1
  1887
				d &= 0x03e07c1f;
slouken@1
  1888
				*dstp++ = d | d >> 16;
slouken@1
  1889
			}, width);
slouken@1
  1890
			srcp += srcskip;
slouken@1
  1891
			dstp += dstskip;
slouken@1
  1892
		}
slouken@0
  1893
	}
slouken@0
  1894
}
slouken@0
  1895
slouken@0
  1896
/* fast ARGB8888->RGB565 blending with pixel alpha */
slouken@0
  1897
static void BlitARGBto565PixelAlpha(SDL_BlitInfo *info)
slouken@0
  1898
{
slouken@0
  1899
	int width = info->d_width;
slouken@0
  1900
	int height = info->d_height;
slouken@0
  1901
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@0
  1902
	int srcskip = info->s_skip >> 2;
slouken@0
  1903
	Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@0
  1904
	int dstskip = info->d_skip >> 1;
slouken@0
  1905
slouken@0
  1906
	while(height--) {
slouken@0
  1907
	    DUFFS_LOOP4({
slouken@0
  1908
		Uint32 s = *srcp;
slouken@0
  1909
		unsigned alpha = s >> 27; /* downscale alpha to 5 bits */
slouken@0
  1910
		/* FIXME: Here we special-case opaque alpha since the
slouken@0
  1911
		   compositioning used (>>8 instead of /255) doesn't handle
slouken@0
  1912
		   it correctly. Also special-case alpha=0 for speed?
slouken@0
  1913
		   Benchmark this! */
slouken@689
  1914
		if(alpha) {   
slouken@689
  1915
		  if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
slouken@0
  1916
		    *dstp = (s >> 8 & 0xf800) + (s >> 5 & 0x7e0)
slouken@0
  1917
			  + (s >> 3  & 0x1f);
slouken@689
  1918
		  } else {
slouken@0
  1919
		    Uint32 d = *dstp;
slouken@0
  1920
		    /*
slouken@0
  1921
		     * convert source and destination to G0RAB65565
slouken@0
  1922
		     * and blend all components at the same time
slouken@0
  1923
		     */
slouken@0
  1924
		    s = ((s & 0xfc00) << 11) + (s >> 8 & 0xf800)
slouken@0
  1925
		      + (s >> 3 & 0x1f);
slouken@0
  1926
		    d = (d | d << 16) & 0x07e0f81f;
slouken@0
  1927
		    d += (s - d) * alpha >> 5;
slouken@0
  1928
		    d &= 0x07e0f81f;
slouken@0
  1929
		    *dstp = d | d >> 16;
slouken@689
  1930
		  }
slouken@0
  1931
		}
slouken@0
  1932
		srcp++;
slouken@0
  1933
		dstp++;
slouken@0
  1934
	    }, width);
slouken@0
  1935
	    srcp += srcskip;
slouken@0
  1936
	    dstp += dstskip;
slouken@0
  1937
	}
slouken@0
  1938
}
slouken@0
  1939
slouken@0
  1940
/* fast ARGB8888->RGB555 blending with pixel alpha */
slouken@0
  1941
static void BlitARGBto555PixelAlpha(SDL_BlitInfo *info)
slouken@0
  1942
{
slouken@0
  1943
	int width = info->d_width;
slouken@0
  1944
	int height = info->d_height;
slouken@0
  1945
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@0
  1946
	int srcskip = info->s_skip >> 2;
slouken@0
  1947
	Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@0
  1948
	int dstskip = info->d_skip >> 1;
slouken@0
  1949
slouken@0
  1950
	while(height--) {
slouken@0
  1951
	    DUFFS_LOOP4({
slouken@0
  1952
		unsigned alpha;
slouken@0
  1953
		Uint32 s = *srcp;
slouken@0
  1954
		alpha = s >> 27; /* downscale alpha to 5 bits */
slouken@0
  1955
		/* FIXME: Here we special-case opaque alpha since the
slouken@0
  1956
		   compositioning used (>>8 instead of /255) doesn't handle
slouken@0
  1957
		   it correctly. Also special-case alpha=0 for speed?
slouken@0
  1958
		   Benchmark this! */
slouken@689
  1959
		if(alpha) {   
slouken@689
  1960
		  if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
slouken@0
  1961
		    *dstp = (s >> 9 & 0x7c00) + (s >> 6 & 0x3e0)
slouken@0
  1962
			  + (s >> 3  & 0x1f);
slouken@689
  1963
		  } else {
slouken@0
  1964
		    Uint32 d = *dstp;
slouken@0
  1965
		    /*
slouken@0
  1966
		     * convert source and destination to G0RAB65565
slouken@0
  1967
		     * and blend all components at the same time
slouken@0
  1968
		     */
slouken@0
  1969
		    s = ((s & 0xf800) << 10) + (s >> 9 & 0x7c00)
slouken@0
  1970
		      + (s >> 3 & 0x1f);
slouken@0
  1971
		    d = (d | d << 16) & 0x03e07c1f;
slouken@0
  1972
		    d += (s - d) * alpha >> 5;
slouken@0
  1973
		    d &= 0x03e07c1f;
slouken@0
  1974
		    *dstp = d | d >> 16;
slouken@689
  1975
		  }
slouken@0
  1976
		}
slouken@0
  1977
		srcp++;
slouken@0
  1978
		dstp++;
slouken@0
  1979
	    }, width);
slouken@0
  1980
	    srcp += srcskip;
slouken@0
  1981
	    dstp += dstskip;
slouken@0
  1982
	}
slouken@0
  1983
}
slouken@0
  1984
slouken@0
  1985
/* General (slow) N->N blending with per-surface alpha */
slouken@0
  1986
static void BlitNtoNSurfaceAlpha(SDL_BlitInfo *info)
slouken@0
  1987
{
slouken@0
  1988
	int width = info->d_width;
slouken@0
  1989
	int height = info->d_height;
slouken@0
  1990
	Uint8 *src = info->s_pixels;
slouken@0
  1991
	int srcskip = info->s_skip;
slouken@0
  1992
	Uint8 *dst = info->d_pixels;
slouken@0
  1993
	int dstskip = info->d_skip;
slouken@0
  1994
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
  1995
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
  1996
	int srcbpp = srcfmt->BytesPerPixel;
slouken@0
  1997
	int dstbpp = dstfmt->BytesPerPixel;
slouken@0
  1998
	unsigned sA = srcfmt->alpha;
slouken@0
  1999
	unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
slouken@0
  2000
slouken@689
  2001
	if(sA) {
slouken@689
  2002
	  while ( height-- ) {
slouken@0
  2003
	    DUFFS_LOOP4(
slouken@0
  2004
	    {
slouken@0
  2005
		Uint32 pixel;
slouken@0
  2006
		unsigned sR;
slouken@0
  2007
		unsigned sG;
slouken@0
  2008
		unsigned sB;
slouken@0
  2009
		unsigned dR;
slouken@0
  2010
		unsigned dG;
slouken@0
  2011
		unsigned dB;
slouken@0
  2012
		DISEMBLE_RGB(src, srcbpp, srcfmt, pixel, sR, sG, sB);
slouken@0
  2013
		DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB);
slouken@0
  2014
		ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
slouken@0
  2015
		ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
slouken@0
  2016
		src += srcbpp;
slouken@0
  2017
		dst += dstbpp;
slouken@0
  2018
	    },
slouken@0
  2019
	    width);
slouken@0
  2020
	    src += srcskip;
slouken@0
  2021
	    dst += dstskip;
slouken@689
  2022
	  }
slouken@0
  2023
	}
slouken@0
  2024
}
slouken@0
  2025
slouken@0
  2026
/* General (slow) colorkeyed N->N blending with per-surface alpha */
slouken@0
  2027
static void BlitNtoNSurfaceAlphaKey(SDL_BlitInfo *info)
slouken@0
  2028
{
slouken@0
  2029
	int width = info->d_width;
slouken@0
  2030
	int height = info->d_height;
slouken@0
  2031
	Uint8 *src = info->s_pixels;
slouken@0
  2032
	int srcskip = info->s_skip;
slouken@0
  2033
	Uint8 *dst = info->d_pixels;
slouken@0
  2034
	int dstskip = info->d_skip;
slouken@0
  2035
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
  2036
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
  2037
	Uint32 ckey = srcfmt->colorkey;
slouken@0
  2038
	int srcbpp = srcfmt->BytesPerPixel;
slouken@0
  2039
	int dstbpp = dstfmt->BytesPerPixel;
slouken@0
  2040
	unsigned sA = srcfmt->alpha;
slouken@0
  2041
	unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
slouken@0
  2042
slouken@0
  2043
	while ( height-- ) {
slouken@0
  2044
	    DUFFS_LOOP4(
slouken@0
  2045
	    {
slouken@0
  2046
		Uint32 pixel;
slouken@0
  2047
		unsigned sR;
slouken@0
  2048
		unsigned sG;
slouken@0
  2049
		unsigned sB;
slouken@0
  2050
		unsigned dR;
slouken@0
  2051
		unsigned dG;
slouken@0
  2052
		unsigned dB;
slouken@0
  2053
		RETRIEVE_RGB_PIXEL(src, srcbpp, pixel);
slouken@689
  2054
		if(sA && pixel != ckey) {
slouken@0
  2055
		    RGB_FROM_PIXEL(pixel, srcfmt, sR, sG, sB);
slouken@0
  2056
		    DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB);
slouken@0
  2057
		    ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
slouken@0
  2058
		    ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
slouken@0
  2059
		}
slouken@0
  2060
		src += srcbpp;
slouken@0
  2061
		dst += dstbpp;
slouken@0
  2062
	    },
slouken@0
  2063
	    width);
slouken@0
  2064
	    src += srcskip;
slouken@0
  2065
	    dst += dstskip;
slouken@0
  2066
	}
slouken@0
  2067
}
slouken@0
  2068
slouken@0
  2069
/* General (slow) N->N blending with pixel alpha */
slouken@0
  2070
static void BlitNtoNPixelAlpha(SDL_BlitInfo *info)
slouken@0
  2071
{
slouken@0
  2072
	int width = info->d_width;
slouken@0
  2073
	int height = info->d_height;
slouken@0
  2074
	Uint8 *src = info->s_pixels;
slouken@0
  2075
	int srcskip = info->s_skip;
slouken@0
  2076
	Uint8 *dst = info->d_pixels;
slouken@0
  2077
	int dstskip = info->d_skip;
slouken@0
  2078
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
  2079
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
  2080
slouken@0
  2081
	int  srcbpp;
slouken@0
  2082
	int  dstbpp;
slouken@0
  2083
slouken@0
  2084
	/* Set up some basic variables */
slouken@0
  2085
	srcbpp = srcfmt->BytesPerPixel;
slouken@0
  2086
	dstbpp = dstfmt->BytesPerPixel;
slouken@0
  2087
slouken@0
  2088
	/* FIXME: for 8bpp source alpha, this doesn't get opaque values
slouken@0
  2089
	   quite right. for <8bpp source alpha, it gets them very wrong
slouken@0
  2090
	   (check all macros!)
slouken@0
  2091
	   It is unclear whether there is a good general solution that doesn't
slouken@0
  2092
	   need a branch (or a divide). */
slouken@0
  2093
	while ( height-- ) {
slouken@0
  2094
	    DUFFS_LOOP4(
slouken@0
  2095
	    {
slouken@0
  2096
		Uint32 pixel;
slouken@0
  2097
		unsigned sR;
slouken@0
  2098
		unsigned sG;
slouken@0
  2099
		unsigned sB;
slouken@0
  2100
		unsigned dR;
slouken@0
  2101
		unsigned dG;
slouken@0
  2102
		unsigned dB;
slouken@0
  2103
		unsigned sA;
slouken@0
  2104
		unsigned dA;
slouken@0
  2105
		DISEMBLE_RGBA(src, srcbpp, srcfmt, pixel, sR, sG, sB, sA);
slouken@689
  2106
		if(sA) {
slouken@689
  2107
		  DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
slouken@689
  2108
		  ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
slouken@689
  2109
		  ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
slouken@689
  2110
		}
slouken@0
  2111
		src += srcbpp;
slouken@0
  2112
		dst += dstbpp;
slouken@0
  2113
	    },
slouken@0
  2114
	    width);
slouken@0
  2115
	    src += srcskip;
slouken@0
  2116
	    dst += dstskip;
slouken@0
  2117
	}
slouken@0
  2118
}
slouken@0
  2119
slouken@0
  2120
slouken@0
  2121
SDL_loblit SDL_CalculateAlphaBlit(SDL_Surface *surface, int blit_index)
slouken@0
  2122
{
slouken@0
  2123
    SDL_PixelFormat *sf = surface->format;
slouken@0
  2124
    SDL_PixelFormat *df = surface->map->dst->format;
slouken@0
  2125
slouken@0
  2126
    if(sf->Amask == 0) {
slouken@0
  2127
	if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
slouken@0
  2128
	    if(df->BytesPerPixel == 1)
slouken@0
  2129
		return BlitNto1SurfaceAlphaKey;
slouken@0
  2130
	    else
icculus@1047
  2131
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2132
        if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 && SDL_HasAltiVec())
icculus@1047
  2133
            return Blit32to32SurfaceAlphaKeyAltivec;
icculus@1047
  2134
        else
icculus@1047
  2135
#endif
icculus@1047
  2136
            return BlitNtoNSurfaceAlphaKey;
slouken@0
  2137
	} else {
slouken@0
  2138
	    /* Per-surface alpha blits */
slouken@0
  2139
	    switch(df->BytesPerPixel) {
slouken@0
  2140
	    case 1:
slouken@0
  2141
		return BlitNto1SurfaceAlpha;
slouken@0
  2142
slouken@0
  2143
	    case 2:
slouken@0
  2144
		if(surface->map->identity) {
slouken@0
  2145
		    if(df->Gmask == 0x7e0)
slouken@689
  2146
		    {
slouken@880
  2147
#ifdef MMX_ASMBLIT
slouken@739
  2148
		if(SDL_HasMMX())
slouken@689
  2149
			return Blit565to565SurfaceAlphaMMX;
slouken@689
  2150
		else
slouken@689
  2151
#endif
slouken@0
  2152
			return Blit565to565SurfaceAlpha;
slouken@689
  2153
		    }
slouken@0
  2154
		    else if(df->Gmask == 0x3e0)
slouken@689
  2155
		    {
slouken@880
  2156
#ifdef MMX_ASMBLIT
slouken@739
  2157
		if(SDL_HasMMX())
slouken@689
  2158
			return Blit555to555SurfaceAlphaMMX;
slouken@689
  2159
		else
slouken@689
  2160
#endif
slouken@0
  2161
			return Blit555to555SurfaceAlpha;
slouken@689
  2162
		    }
slouken@0
  2163
		}
slouken@0
  2164
		return BlitNtoNSurfaceAlpha;
slouken@0
  2165
slouken@0
  2166
	    case 4:
slouken@0
  2167
		if(sf->Rmask == df->Rmask
slouken@0
  2168
		   && sf->Gmask == df->Gmask
slouken@0
  2169
		   && sf->Bmask == df->Bmask
slouken@0
  2170
		   && (sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff
slouken@0
  2171
		   && sf->BytesPerPixel == 4)
slouken@689
  2172
		{
slouken@880
  2173
#ifdef MMX_ASMBLIT
slouken@739
  2174
		if(SDL_HasMMX())
slouken@689
  2175
		    return BlitRGBtoRGBSurfaceAlphaMMX;
slouken@689
  2176
		else
slouken@689
  2177
#endif
icculus@1047
  2178
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2179
        if(SDL_HasAltiVec())
icculus@1047
  2180
            return BlitRGBtoRGBSurfaceAlphaAltivec;
icculus@1047
  2181
        else
icculus@1047
  2182
#endif
slouken@0
  2183
		    return BlitRGBtoRGBSurfaceAlpha;
slouken@689
  2184
		}
slouken@0
  2185
		else
icculus@1047
  2186
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2187
        if((sf->BytesPerPixel == 4) && SDL_HasAltiVec())
icculus@1047
  2188
            return Blit32to32SurfaceAlphaAltivec;
icculus@1047
  2189
        else
icculus@1047
  2190
#endif
slouken@0
  2191
		    return BlitNtoNSurfaceAlpha;
slouken@0
  2192
slouken@0
  2193
	    case 3:
slouken@0
  2194
	    default:
slouken@0
  2195
		return BlitNtoNSurfaceAlpha;
slouken@0
  2196
	    }
slouken@0
  2197
	}
slouken@0
  2198
    } else {
slouken@0
  2199
	/* Per-pixel alpha blits */
slouken@0
  2200
	switch(df->BytesPerPixel) {
slouken@0
  2201
	case 1:
slouken@0
  2202
	    return BlitNto1PixelAlpha;
slouken@0
  2203
slouken@0
  2204
	case 2:
icculus@1047
  2205
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2206
        if(sf->BytesPerPixel == 4 && 
icculus@1047
  2207
           df->Gmask == 0x7e0 &&
icculus@1047
  2208
           df->Bmask == 0x1f)
icculus@1047
  2209
            return Blit32to565PixelAlphaAltivec;
icculus@1047
  2210
        else
icculus@1047
  2211
#endif
slouken@0
  2212
	    if(sf->BytesPerPixel == 4 && sf->Amask == 0xff000000
slouken@0
  2213
	       && sf->Gmask == 0xff00
slouken@0
  2214
	       && ((sf->Rmask == 0xff && df->Rmask == 0x1f)
slouken@0
  2215
		   || (sf->Bmask == 0xff && df->Bmask == 0x1f))) {
slouken@0
  2216
		if(df->Gmask == 0x7e0)
slouken@0
  2217
		    return BlitARGBto565PixelAlpha;
slouken@0
  2218
		else if(df->Gmask == 0x3e0)
slouken@0
  2219
		    return BlitARGBto555PixelAlpha;
slouken@0
  2220
	    }
slouken@0
  2221
	    return BlitNtoNPixelAlpha;
slouken@0
  2222
slouken@0
  2223
	case 4:
slouken@0
  2224
	    if(sf->Amask == 0xff000000
slouken@0
  2225
	       && sf->Rmask == df->Rmask
slouken@0
  2226
	       && sf->Gmask == df->Gmask
slouken@0
  2227
	       && sf->Bmask == df->Bmask
slouken@0
  2228
	       && sf->BytesPerPixel == 4)
slouken@689
  2229
	    {
slouken@880
  2230
#ifdef MMX_ASMBLIT
slouken@739
  2231
		if(SDL_Has3DNow())
slouken@689
  2232
		    return BlitRGBtoRGBPixelAlphaMMX3DNOW;
slouken@689
  2233
		else
slouken@739
  2234
		if(SDL_HasMMX())
slouken@689
  2235
		    return BlitRGBtoRGBPixelAlphaMMX;
slouken@689
  2236
		else
slouken@689
  2237
#endif
icculus@1047
  2238
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2239
        if(SDL_HasAltiVec())
icculus@1047
  2240
            return BlitRGBtoRGBPixelAlphaAltivec;
icculus@1047
  2241
        else
icculus@1047
  2242
#endif
slouken@689
  2243
		    return BlitRGBtoRGBPixelAlpha;
slouken@689
  2244
	    }
icculus@1047
  2245
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2246
        if (sf->Amask && sf->BytesPerPixel == 4 && SDL_HasAltiVec())
icculus@1047
  2247
            return Blit32to32PixelAlphaAltivec;
icculus@1047
  2248
        else
icculus@1047
  2249
#endif
slouken@0
  2250
	    return BlitNtoNPixelAlpha;
slouken@0
  2251
slouken@0
  2252
	case 3:
slouken@0
  2253
	default:
slouken@0
  2254
	    return BlitNtoNPixelAlpha;
slouken@0
  2255
	}
slouken@0
  2256
    }
slouken@0
  2257
}
slouken@0
  2258