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