src/video/SDL_blit_N.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 04 Jan 2006 20:53:55 +0000
changeset 1224 f033d9589ca1
parent 1175 867f521591e5
child 1232 0aa0000081d5
permissions -rw-r--r--
Debug code should check right function names.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
     3
    Copyright (C) 1997-2004 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     6
    modify it under the terms of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
    version 2 of the License, or (at your option) any later version.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    13
    Library General Public License for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    15
    You should have received a copy of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    19
    Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 91
diff changeset
    20
    slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    21
*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
#ifdef SAVE_RCSID
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
static char rcsid =
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
 "@(#) $Id$";
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
#include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    30
#include "SDL_types.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    31
#include "SDL_video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    32
#include "SDL_blit.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    33
#include "SDL_byteorder.h"
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 431
diff changeset
    34
#include "SDL_cpuinfo.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    35
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    36
/* Functions to blit from N-bit surfaces to other surfaces */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    37
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    38
#ifdef USE_ALTIVEC_BLITTERS
1175
867f521591e5 Fixed Altivec support on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1162
diff changeset
    39
#ifdef HAVE_ALTIVEC_H
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    40
#include <altivec.h>
1175
867f521591e5 Fixed Altivec support on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1162
diff changeset
    41
#endif
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    42
#include <assert.h>
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    43
#include <stdlib.h>
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    44
#ifdef MACOSX
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    45
#include <sys/sysctl.h>
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    46
static size_t GetL3CacheSize( void )
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    47
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    48
    const char key[] = "hw.l3cachesize";
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    49
    u_int64_t result = 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    50
    size_t typeSize = sizeof( result );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    51
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    52
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    53
    int err = sysctlbyname( key, &result, &typeSize, NULL, 0 );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    54
    if( 0 != err ) return 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    55
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    56
    return result;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    57
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    58
#else
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    59
static size_t GetL3CacheSize( void )
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    60
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    61
    /* XXX: Just guess G4 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    62
    return 2097152;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    63
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    64
#endif /* MACOSX */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    65
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    66
#if ((defined MACOSX) && (__GNUC__ < 4))
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    67
    #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    68
        (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    69
    #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    70
        (vector unsigned short) ( a,b,c,d,e,f,g,h )
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    71
#else
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    72
    #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    73
        (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    74
    #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    75
        (vector unsigned short) { a,b,c,d,e,f,g,h }
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    76
#endif
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    77
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    78
#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    79
#define VSWIZZLE32(a,b,c,d) (vector unsigned char) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    80
                               ( 0x00+a, 0x00+b, 0x00+c, 0x00+d, \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    81
                                 0x04+a, 0x04+b, 0x04+c, 0x04+d, \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    82
                                 0x08+a, 0x08+b, 0x08+c, 0x08+d, \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    83
                                 0x0C+a, 0x0C+b, 0x0C+c, 0x0C+d )
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    84
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    85
#define MAKE8888(dstfmt, r, g, b, a)  \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    86
    ( ((r<<dstfmt->Rshift)&dstfmt->Rmask) | \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    87
      ((g<<dstfmt->Gshift)&dstfmt->Gmask) | \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    88
      ((b<<dstfmt->Bshift)&dstfmt->Bmask) | \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    89
      ((a<<dstfmt->Ashift)&dstfmt->Amask) )
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    90
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    91
/*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    92
 * Data Stream Touch...Altivec cache prefetching.
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    93
 *
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    94
 *  Don't use this on a G5...however, the speed boost is very significant
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    95
 *   on a G4.
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    96
 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    97
#define DST_CHAN_SRC 1
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    98
#define DST_CHAN_DEST 2
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    99
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   100
/* macro to set DST control word value... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   101
#define DST_CTRL(size, count, stride) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   102
    (((size) << 24) | ((count) << 16) | (stride))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   103
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   104
#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   105
    ? vec_lvsl(0, src) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   106
    : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   107
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   108
/* Calculate the permute vector used for 32->32 swizzling */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   109
static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   110
                                  const SDL_PixelFormat *dstfmt)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   111
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   112
    /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   113
    * We have to assume that the bits that aren't used by other
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   114
     *  colors is alpha, and it's one complete byte, since some formats
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   115
     *  leave alpha with a zero mask, but we should still swizzle the bits.
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   116
     */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   117
    /* ARGB */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   118
    const static struct SDL_PixelFormat default_pixel_format = {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   119
        NULL, 0, 0,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   120
        0, 0, 0, 0,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   121
        16, 8, 0, 24,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   122
        0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   123
        0, 0};
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   124
    if (!srcfmt) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   125
        srcfmt = &default_pixel_format;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   126
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   127
    if (!dstfmt) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   128
        dstfmt = &default_pixel_format;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   129
    }
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   130
    vector unsigned char plus = VECUINT8_LITERAL(
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   131
                                      0x00, 0x00, 0x00, 0x00,
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   132
                                      0x04, 0x04, 0x04, 0x04,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   133
                                      0x08, 0x08, 0x08, 0x08,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   134
                                      0x0C, 0x0C, 0x0C, 0x0C );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   135
    vector unsigned char vswiz;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   136
    vector unsigned int srcvec;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   137
#define RESHIFT(X) (3 - ((X) >> 3))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   138
    Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   139
    Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   140
    Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   141
    Uint32 amask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   142
    /* Use zero for alpha if either surface doesn't have alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   143
    if (dstfmt->Amask) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   144
        amask = ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   145
    } else {    
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   146
        amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   147
    }           
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   148
#undef RESHIFT  
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   149
    ((unsigned int *)(char*)&srcvec)[0] = (rmask | gmask | bmask | amask);
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   150
    vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   151
    return(vswiz);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   152
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   153
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   154
static void Blit_RGB888_RGB565(SDL_BlitInfo *info);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   155
static void Blit_RGB888_RGB565Altivec(SDL_BlitInfo *info) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   156
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   157
    Uint8 *src = (Uint8 *) info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   158
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   159
    Uint8 *dst = (Uint8 *) info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   160
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   161
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   162
    vector unsigned char valpha = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   163
    vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   164
    vector unsigned char vgmerge = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   165
        0x00, 0x02, 0x00, 0x06,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   166
        0x00, 0x0a, 0x00, 0x0e,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   167
        0x00, 0x12, 0x00, 0x16,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   168
        0x00, 0x1a, 0x00, 0x1e);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   169
    vector unsigned short v1 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   170
    vector unsigned short v3 = vec_splat_u16(3);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   171
    vector unsigned short v3f = VECUINT16_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   172
        0x003f, 0x003f, 0x003f, 0x003f,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   173
        0x003f, 0x003f, 0x003f, 0x003f);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   174
    vector unsigned short vfc = VECUINT16_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   175
        0x00fc, 0x00fc, 0x00fc, 0x00fc,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   176
        0x00fc, 0x00fc, 0x00fc, 0x00fc);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   177
    vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   178
    vf800 = vec_sl(vf800, vec_splat_u16(8));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   179
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   180
    while (height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   181
        vector unsigned char valigner;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   182
        vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   183
        vector unsigned char vsrc;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   184
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   185
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   186
        int extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   187
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   188
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   189
#define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   190
        while (condition) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   191
            Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   192
            unsigned sR, sG, sB, sA; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   193
            DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, Pixel, \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   194
                          sR, sG, sB, sA); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   195
            *(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   196
                                ((sG << 3) & 0x000007E0) | \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   197
                                ((sB >> 3) & 0x0000001F)); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   198
            dst += 2; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   199
            src += 4; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   200
            widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   201
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   202
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   203
        ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   204
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   205
        /* After all that work, here's the vector part! */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   206
        extrawidth = (width % 8);  /* trailing unaligned stores */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   207
        width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   208
        vsrc = vec_ld(0, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   209
        valigner = VEC_ALIGNER(src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   210
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   211
        while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   212
            vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   213
            vector unsigned int vsrc1, vsrc2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   214
            vector unsigned char vdst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   215
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   216
            voverflow = vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   217
            vsrc = vec_perm(vsrc, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   218
            vsrc1 = (vector unsigned int)vec_perm(vsrc, valpha, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   219
            src += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   220
            vsrc = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   221
            voverflow = vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   222
            vsrc = vec_perm(vsrc, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   223
            vsrc2 = (vector unsigned int)vec_perm(vsrc, valpha, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   224
            /* 1555 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   225
            vpixel = (vector unsigned short)vec_packpx(vsrc1, vsrc2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   226
            vgpixel = (vector unsigned short)vec_perm(vsrc1, vsrc2, vgmerge);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   227
            vgpixel = vec_and(vgpixel, vfc);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   228
            vgpixel = vec_sl(vgpixel, v3);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   229
            vrpixel = vec_sl(vpixel, v1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   230
            vrpixel = vec_and(vrpixel, vf800);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   231
            vbpixel = vec_and(vpixel, v3f);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   232
            vdst = vec_or((vector unsigned char)vrpixel, (vector unsigned char)vgpixel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   233
            /* 565 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   234
            vdst = vec_or(vdst, (vector unsigned char)vbpixel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   235
            vec_st(vdst, 0, dst);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   236
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   237
            width -= 8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   238
            src += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   239
            dst += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   240
            vsrc = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   241
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   242
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   243
        assert(width == 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   244
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   245
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   246
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   247
        ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   248
#undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   249
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   250
        src += srcskip;  /* move to next row, accounting for pitch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   251
        dst += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   252
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   253
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   254
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   255
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   256
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   257
static void Blit_RGB565_32Altivec(SDL_BlitInfo *info) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   258
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   259
    Uint8 *src = (Uint8 *) info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   260
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   261
    Uint8 *dst = (Uint8 *) info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   262
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   263
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   264
    SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   265
    unsigned alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   266
    vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   267
    vector unsigned char vpermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   268
    vector unsigned short vf800;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   269
    vector unsigned int v8 = vec_splat_u32(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   270
    vector unsigned int v16 = vec_add(v8, v8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   271
    vector unsigned short v2 = vec_splat_u16(2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   272
    vector unsigned short v3 = vec_splat_u16(3);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   273
    /* 
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   274
        0x10 - 0x1f is the alpha
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   275
        0x00 - 0x0e evens are the red
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   276
        0x01 - 0x0f odds are zero
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   277
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   278
    vector unsigned char vredalpha1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   279
        0x10, 0x00, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   280
        0x10, 0x02, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   281
        0x10, 0x04, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   282
        0x10, 0x06, 0x01, 0x01
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   283
    );
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   284
    vector unsigned char vredalpha2 = (vector unsigned char) (
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   285
        vec_add((vector unsigned int)vredalpha1, vec_sl(v8, v16))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   286
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   287
    /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   288
        0x00 - 0x0f is ARxx ARxx ARxx ARxx
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   289
        0x11 - 0x0f odds are blue
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   290
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   291
    vector unsigned char vblue1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   292
        0x00, 0x01, 0x02, 0x11,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   293
        0x04, 0x05, 0x06, 0x13,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   294
        0x08, 0x09, 0x0a, 0x15,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   295
        0x0c, 0x0d, 0x0e, 0x17
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   296
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   297
    vector unsigned char vblue2 = (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   298
        vec_add((vector unsigned int)vblue1, v8)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   299
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   300
    /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   301
        0x00 - 0x0f is ARxB ARxB ARxB ARxB
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   302
        0x10 - 0x0e evens are green
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   303
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   304
    vector unsigned char vgreen1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   305
        0x00, 0x01, 0x10, 0x03,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   306
        0x04, 0x05, 0x12, 0x07,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   307
        0x08, 0x09, 0x14, 0x0b,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   308
        0x0c, 0x0d, 0x16, 0x0f
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   309
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   310
    vector unsigned char vgreen2 = (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   311
        vec_add((vector unsigned int)vgreen1, vec_sl(v8, v8))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   312
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   313
    
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   314
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   315
    assert(srcfmt->BytesPerPixel == 2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   316
    assert(dstfmt->BytesPerPixel == 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   317
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   318
    vf800 = (vector unsigned short)vec_splat_u8(-7);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   319
    vf800 = vec_sl(vf800, vec_splat_u16(8));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   320
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   321
    if (dstfmt->Amask && srcfmt->alpha) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   322
        ((unsigned char *)&valpha)[0] = alpha = srcfmt->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   323
        valpha = vec_splat(valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   324
    } else {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   325
        alpha = 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   326
        valpha = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   327
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   328
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   329
    vpermute = calc_swizzle32(NULL, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   330
    while (height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   331
        vector unsigned char valigner;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   332
        vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   333
        vector unsigned char vsrc;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   334
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   335
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   336
        int extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   337
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   338
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   339
#define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   340
        while (condition) { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   341
            unsigned sR, sG, sB; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   342
            unsigned short Pixel = *((unsigned short *)src); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   343
            sR = (Pixel >> 8) & 0xf8; \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   344
            sG = (Pixel >> 3) & 0xfc; \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   345
            sB = (Pixel << 3) & 0xf8; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   346
            ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   347
            src += 2; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   348
            dst += 4; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   349
            widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   350
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   351
        ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   352
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   353
        /* After all that work, here's the vector part! */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   354
        extrawidth = (width % 8);  /* trailing unaligned stores */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   355
        width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   356
        vsrc = vec_ld(0, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   357
        valigner = VEC_ALIGNER(src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   358
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   359
        while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   360
            vector unsigned short vR, vG, vB;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   361
            vector unsigned char vdst1, vdst2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   362
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   363
            voverflow = vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   364
            vsrc = vec_perm(vsrc, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   365
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   366
            vR = vec_and((vector unsigned short)vsrc, vf800);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   367
            vB = vec_sl((vector unsigned short)vsrc, v3);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   368
            vG = vec_sl(vB, v2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   369
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   370
            vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   371
            vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   372
            vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   373
            vdst1 = vec_perm(vdst1, valpha, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   374
            vec_st(vdst1, 0, dst);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   375
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   376
            vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   377
            vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   378
            vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   379
            vdst2 = vec_perm(vdst2, valpha, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   380
            vec_st(vdst2, 16, dst);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   381
            
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   382
            width -= 8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   383
            dst += 32;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   384
            src += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   385
            vsrc = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   386
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   387
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   388
        assert(width == 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   389
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   390
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   391
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   392
        ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   393
#undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   394
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   395
        src += srcskip;  /* move to next row, accounting for pitch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   396
        dst += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   397
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   398
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   399
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   400
1139
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   401
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   402
static void Blit_RGB555_32Altivec(SDL_BlitInfo *info) {
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   403
    int height = info->d_height;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   404
    Uint8 *src = (Uint8 *) info->s_pixels;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   405
    int srcskip = info->s_skip;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   406
    Uint8 *dst = (Uint8 *) info->d_pixels;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   407
    int dstskip = info->d_skip;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   408
    SDL_PixelFormat *srcfmt = info->src;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   409
    SDL_PixelFormat *dstfmt = info->dst;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   410
    unsigned alpha;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   411
    vector unsigned char valpha;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   412
    vector unsigned char vpermute;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   413
    vector unsigned short vf800;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   414
    vector unsigned int v8 = vec_splat_u32(8);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   415
    vector unsigned int v16 = vec_add(v8, v8);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   416
    vector unsigned short v1 = vec_splat_u16(1);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   417
    vector unsigned short v3 = vec_splat_u16(3);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   418
    /* 
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   419
        0x10 - 0x1f is the alpha
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   420
        0x00 - 0x0e evens are the red
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   421
        0x01 - 0x0f odds are zero
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   422
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   423
    vector unsigned char vredalpha1 = VECUINT8_LITERAL(
1139
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   424
        0x10, 0x00, 0x01, 0x01,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   425
        0x10, 0x02, 0x01, 0x01,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   426
        0x10, 0x04, 0x01, 0x01,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   427
        0x10, 0x06, 0x01, 0x01
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   428
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   429
    vector unsigned char vredalpha2 = (vector unsigned char)(
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   430
        vec_add((vector unsigned int)vredalpha1, vec_sl(v8, v16))
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   431
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   432
    /*
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   433
        0x00 - 0x0f is ARxx ARxx ARxx ARxx
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   434
        0x11 - 0x0f odds are blue
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   435
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   436
    vector unsigned char vblue1 = VECUINT8_LITERAL(
1139
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   437
        0x00, 0x01, 0x02, 0x11,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   438
        0x04, 0x05, 0x06, 0x13,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   439
        0x08, 0x09, 0x0a, 0x15,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   440
        0x0c, 0x0d, 0x0e, 0x17
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   441
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   442
    vector unsigned char vblue2 = (vector unsigned char)(
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   443
        vec_add((vector unsigned int)vblue1, v8)
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   444
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   445
    /*
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   446
        0x00 - 0x0f is ARxB ARxB ARxB ARxB
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   447
        0x10 - 0x0e evens are green
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   448
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   449
    vector unsigned char vgreen1 = VECUINT8_LITERAL(
1139
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   450
        0x00, 0x01, 0x10, 0x03,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   451
        0x04, 0x05, 0x12, 0x07,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   452
        0x08, 0x09, 0x14, 0x0b,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   453
        0x0c, 0x0d, 0x16, 0x0f
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   454
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   455
    vector unsigned char vgreen2 = (vector unsigned char)(
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   456
        vec_add((vector unsigned int)vgreen1, vec_sl(v8, v8))
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   457
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   458
    
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   459
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   460
    assert(srcfmt->BytesPerPixel == 2);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   461
    assert(dstfmt->BytesPerPixel == 4);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   462
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   463
    vf800 = (vector unsigned short)vec_splat_u8(-7);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   464
    vf800 = vec_sl(vf800, vec_splat_u16(8));
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   465
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   466
    if (dstfmt->Amask && srcfmt->alpha) {
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   467
        ((unsigned char *)&valpha)[0] = alpha = srcfmt->alpha;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   468
        valpha = vec_splat(valpha, 0);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   469
    } else {
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   470
        alpha = 0;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   471
        valpha = vec_splat_u8(0);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   472
    }
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   473
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   474
    vpermute = calc_swizzle32(NULL, dstfmt);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   475
    while (height--) {
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   476
        vector unsigned char valigner;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   477
        vector unsigned char voverflow;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   478
        vector unsigned char vsrc;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   479
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   480
        int width = info->d_width;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   481
        int extrawidth;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   482
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   483
        /* do scalar until we can align... */
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   484
#define ONE_PIXEL_BLEND(condition, widthvar) \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   485
        while (condition) { \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   486
            unsigned sR, sG, sB; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   487
            unsigned short Pixel = *((unsigned short *)src); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   488
            sR = (Pixel >> 7) & 0xf8; \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   489
            sG = (Pixel >> 2) & 0xf8; \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   490
            sB = (Pixel << 3) & 0xf8; \
1139
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   491
            ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   492
            src += 2; \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   493
            dst += 4; \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   494
            widthvar--; \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   495
        }
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   496
        ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   497
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   498
        /* After all that work, here's the vector part! */
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   499
        extrawidth = (width % 8);  /* trailing unaligned stores */
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   500
        width -= extrawidth;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   501
        vsrc = vec_ld(0, src);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   502
        valigner = VEC_ALIGNER(src);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   503
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   504
        while (width) {
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   505
            vector unsigned short vR, vG, vB;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   506
            vector unsigned char vdst1, vdst2;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   507
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   508
            voverflow = vec_ld(15, src);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   509
            vsrc = vec_perm(vsrc, voverflow, valigner);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   510
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   511
            vR = vec_and(vec_sl((vector unsigned short)vsrc,v1), vf800);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   512
            vB = vec_sl((vector unsigned short)vsrc, v3);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   513
            vG = vec_sl(vB, v3);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   514
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   515
            vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha1);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   516
            vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   517
            vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   518
            vdst1 = vec_perm(vdst1, valpha, vpermute);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   519
            vec_st(vdst1, 0, dst);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   520
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   521
            vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha2);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   522
            vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   523
            vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   524
            vdst2 = vec_perm(vdst2, valpha, vpermute);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   525
            vec_st(vdst2, 16, dst);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   526
            
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   527
            width -= 8;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   528
            dst += 32;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   529
            src += 16;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   530
            vsrc = voverflow;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   531
        }
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   532
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   533
        assert(width == 0);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   534
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   535
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   536
        /* do scalar until we can align... */
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   537
        ONE_PIXEL_BLEND((extrawidth), extrawidth);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   538
#undef ONE_PIXEL_BLEND
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   539
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   540
        src += srcskip;  /* move to next row, accounting for pitch. */
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   541
        dst += dstskip;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   542
    }
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   543
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   544
}
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   545
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   546
static void BlitNtoNKey(SDL_BlitInfo *info);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   547
static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo *info);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   548
static void Blit32to32KeyAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   549
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   550
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   551
    Uint32 *srcp = (Uint32 *) info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   552
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   553
    Uint32 *dstp = (Uint32 *) info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   554
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   555
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   556
    int srcbpp = srcfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   557
    SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   558
    int dstbpp = dstfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   559
    int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   560
	unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   561
    Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   562
	Uint32 ckey = info->src->colorkey;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   563
    vector unsigned int valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   564
    vector unsigned char vpermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   565
    vector unsigned char vzero;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   566
    vector unsigned int vckey;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   567
    vector unsigned int vrgbmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   568
    vpermute = calc_swizzle32(srcfmt, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   569
    if (info->d_width < 16) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   570
        if(copy_alpha) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   571
            return BlitNtoNKeyCopyAlpha(info);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   572
        } else {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   573
            return BlitNtoNKey(info);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   574
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   575
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   576
    vzero = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   577
    if (alpha) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   578
        ((unsigned char *)&valpha)[0] = (unsigned char)alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   579
        valpha = (vector unsigned int)vec_splat((vector unsigned char)valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   580
    } else {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   581
        valpha = (vector unsigned int)vzero;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   582
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   583
    ckey &= rgbmask;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   584
    ((unsigned int *)(char*)&vckey)[0] = ckey;
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   585
    vckey = vec_splat(vckey, 0);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   586
    ((unsigned int *)(char*)&vrgbmask)[0] = rgbmask;
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   587
    vrgbmask = vec_splat(vrgbmask, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   588
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   589
    while (height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   590
#define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   591
        if (copy_alpha) { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   592
            while (condition) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   593
                Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   594
                unsigned sR, sG, sB, sA; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   595
                DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, Pixel, \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   596
                          sR, sG, sB, sA); \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   597
                if ( (Pixel & rgbmask) != ckey ) { \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   598
                      ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   599
                            sR, sG, sB, sA); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   600
                } \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   601
                dstp = (Uint32 *) (((Uint8 *) dstp) + dstbpp); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   602
                srcp = (Uint32 *) (((Uint8 *) srcp) + srcbpp); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   603
                widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   604
            } \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   605
        } else { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   606
            while (condition) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   607
                Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   608
                unsigned sR, sG, sB; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   609
                RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, Pixel); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   610
                if ( Pixel != ckey ) { \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   611
                    RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   612
                    ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   613
                              sR, sG, sB, alpha); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   614
                } \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   615
                dstp = (Uint32 *) (((Uint8 *)dstp) + dstbpp); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   616
                srcp = (Uint32 *) (((Uint8 *)srcp) + srcbpp); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   617
                widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   618
            } \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   619
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   620
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   621
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   622
        assert(width > 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   623
        if (width > 0) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   624
            int extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   625
            vector unsigned char valigner = VEC_ALIGNER(srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   626
            vector unsigned int vs = vec_ld(0, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   627
            width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   628
            assert(width >= 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   629
            while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   630
                vector unsigned char vsel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   631
                vector unsigned int vd;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   632
                vector unsigned int voverflow = vec_ld(15, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   633
                /* load the source vec */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   634
                vs = vec_perm(vs, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   635
                /* vsel is set for items that match the key */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   636
                vsel = (vector unsigned char)vec_and(vs, vrgbmask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   637
                vsel = (vector unsigned char)vec_cmpeq(vs, vckey);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   638
                /* permute the src vec to the dest format */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   639
                vs = vec_perm(vs, valpha, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   640
                /* load the destination vec */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   641
                vd = vec_ld(0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   642
                /* select the source and dest into vs */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   643
                vd = (vector unsigned int)vec_sel((vector unsigned char)vs, (vector unsigned char)vd, vsel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   644
                
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   645
                vec_st(vd, 0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   646
                srcp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   647
                width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   648
                dstp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   649
                vs = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   650
            }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   651
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   652
#undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   653
            srcp += srcskip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   654
            dstp += dstskip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   655
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   656
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   657
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   658
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   659
/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   660
/* Use this on a G5 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   661
static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   662
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   663
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   664
    Uint32 *src = (Uint32 *) info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   665
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   666
    Uint32 *dst = (Uint32 *) info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   667
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   668
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   669
    int srcbpp = srcfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   670
    SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   671
    int dstbpp = dstfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   672
    vector unsigned int vzero = vec_splat_u32(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   673
    vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   674
    if (dstfmt->Amask && !srcfmt->Amask) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   675
        if (srcfmt->alpha) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   676
            vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   677
            ((unsigned char *)&valpha)[0] = srcfmt->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   678
            vzero = (vector unsigned int)vec_splat(valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   679
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   680
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   681
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   682
    assert(srcbpp == 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   683
    assert(dstbpp == 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   684
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   685
    while (height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   686
        vector unsigned char valigner;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   687
        vector unsigned int vbits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   688
        vector unsigned int voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   689
        Uint32 bits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   690
        Uint8 r, g, b, a;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   691
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   692
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   693
        int extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   694
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   695
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   696
        while ((UNALIGNED_PTR(dst)) && (width)) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   697
            bits = *(src++);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   698
            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   699
            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   700
            width--;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   701
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   702
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   703
        /* After all that work, here's the vector part! */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   704
        extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   705
        width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   706
        valigner = VEC_ALIGNER(src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   707
        vbits = vec_ld(0, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   708
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   709
       while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   710
            voverflow = vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   711
            src += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   712
            width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   713
            vbits = vec_perm(vbits, voverflow, valigner);  /* src is ready. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   714
            vbits = vec_perm(vbits, vzero, vpermute);  /* swizzle it. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   715
            vec_st(vbits, 0, dst);  /* store it back out. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   716
            dst += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   717
            vbits = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   718
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   719
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   720
        assert(width == 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   721
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   722
        /* cover pixels at the end of the row that didn't fit in 16 bytes. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   723
        while (extrawidth) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   724
            bits = *(src++);  /* max 7 pixels, don't bother with prefetch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   725
            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   726
            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   727
            extrawidth--;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   728
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   729
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   730
        src += srcskip >> 2;  /* move to next row, accounting for pitch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   731
        dst += dstskip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   732
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   733
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   734
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   735
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   736
/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   737
/* Use this on a G4 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   738
static void ConvertAltivec32to32_prefetch(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   739
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   740
    const int scalar_dst_lead = sizeof (Uint32) * 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   741
    const int vector_dst_lead = sizeof (Uint32) * 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   742
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   743
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   744
    Uint32 *src = (Uint32 *) info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   745
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   746
    Uint32 *dst = (Uint32 *) info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   747
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   748
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   749
    int srcbpp = srcfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   750
    SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   751
    int dstbpp = dstfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   752
    vector unsigned int vzero = vec_splat_u32(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   753
    vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   754
    if (dstfmt->Amask && !srcfmt->Amask) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   755
        if (srcfmt->alpha) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   756
            vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   757
            ((unsigned char *)&valpha)[0] = srcfmt->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   758
            vzero = (vector unsigned int)vec_splat(valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   759
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   760
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   761
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   762
    assert(srcbpp == 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   763
    assert(dstbpp == 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   764
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   765
    while (height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   766
        vector unsigned char valigner;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   767
        vector unsigned int vbits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   768
        vector unsigned int voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   769
        Uint32 bits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   770
        Uint8 r, g, b, a;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   771
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   772
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   773
        int extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   774
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   775
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   776
        while ((UNALIGNED_PTR(dst)) && (width)) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   777
            vec_dstt(src+scalar_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_SRC);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   778
            vec_dstst(dst+scalar_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_DEST);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   779
            bits = *(src++);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   780
            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   781
            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   782
            width--;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   783
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   784
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   785
        /* After all that work, here's the vector part! */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   786
        extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   787
        width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   788
        valigner = VEC_ALIGNER(src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   789
        vbits = vec_ld(0, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   790
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   791
        while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   792
            vec_dstt(src+vector_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_SRC);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   793
            vec_dstst(dst+vector_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_DEST);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   794
            voverflow = vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   795
            src += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   796
            width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   797
            vbits = vec_perm(vbits, voverflow, valigner);  /* src is ready. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   798
            vbits = vec_perm(vbits, vzero, vpermute);  /* swizzle it. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   799
            vec_st(vbits, 0, dst);  /* store it back out. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   800
            dst += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   801
            vbits = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   802
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   803
        
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   804
        assert(width == 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   805
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   806
        /* cover pixels at the end of the row that didn't fit in 16 bytes. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   807
        while (extrawidth) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   808
            bits = *(src++);  /* max 7 pixels, don't bother with prefetch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   809
            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   810
            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   811
            extrawidth--;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   812
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   813
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   814
        src += srcskip >> 2;  /* move to next row, accounting for pitch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   815
        dst += dstskip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   816
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   817
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   818
    vec_dss(DST_CHAN_SRC);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   819
    vec_dss(DST_CHAN_DEST);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   820
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   821
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   822
static Uint32 GetBlitFeatures( void )
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   823
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   824
    static Uint32 features = 0xffffffff;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   825
    if (features == 0xffffffff) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   826
        /* Provide an override for testing .. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   827
        char *override = getenv("SDL_ALTIVEC_BLIT_FEATURES");
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   828
        if (override) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   829
            features = 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   830
            sscanf(override, "%u", &features);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   831
        } else {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   832
            features = ( 0
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   833
                /* Feature 1 is has-MMX */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   834
                | ((SDL_HasMMX()) ? 1 : 0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   835
                /* Feature 2 is has-AltiVec */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   836
                | ((SDL_HasAltiVec()) ? 2 : 0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   837
                /* Feature 4 is dont-use-prefetch */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   838
                /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   839
                | ((GetL3CacheSize() == 0) ? 4 : 0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   840
            );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   841
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   842
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   843
    return features;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   844
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   845
#else
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   846
/* Feature 1 is has-MMX */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   847
#define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   848
#endif
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   849
1053
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   850
/* This is now endian dependent */
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   851
#if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   852
#define HI	1
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   853
#define LO	0
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   854
#else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   855
#define HI	0
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   856
#define LO	1
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   857
#endif
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   858
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   859
#ifdef USE_ASMBLIT
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   860
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   861
/* Heheheh, we coerce Hermes into using SDL blit information */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   862
#define X86_ASSEMBLER
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   863
#define HermesConverterInterface	SDL_BlitInfo
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   864
#define HermesClearInterface		void
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   865
#define STACKCALL
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   866
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   867
#include "HeadMMX.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   868
#include "HeadX86.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   869
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   870
#else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   871
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   872
/* Special optimized blit for RGB 8-8-8 --> RGB 3-3-2 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   873
#define RGB888_RGB332(dst, src) { \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   874
	dst = (((src)&0x00E00000)>>16)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   875
	      (((src)&0x0000E000)>>11)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   876
	      (((src)&0x000000C0)>>6); \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   877
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   878
static void Blit_RGB888_index8(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   879
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   880
#ifndef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   881
	int c;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   882
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   883
	int width, height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   884
	Uint32 *src;
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   885
	const Uint8 *map;
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   886
	Uint8 *dst;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   887
	int srcskip, dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   888
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   889
	/* Set up some basic variables */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   890
	width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   891
	height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   892
	src = (Uint32 *)info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   893
	srcskip = info->s_skip/4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   894
	dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   895
	dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   896
	map = info->table;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   897
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   898
	if ( map == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   899
		while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   900
#ifdef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   901
			DUFFS_LOOP(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   902
				RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   903
			, width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   904
#else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   905
			for ( c=width/4; c; --c ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   906
				/* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   907
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   908
				RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   909
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   910
				RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   911
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   912
				RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   913
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   914
			}
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   915
			switch ( width & 3 ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   916
				case 3:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   917
					RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   918
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   919
				case 2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   920
					RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   921
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   922
				case 1:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   923
					RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   924
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   925
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   926
#endif /* USE_DUFFS_LOOP */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   927
			src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   928
			dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   929
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   930
	} else {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   931
		int Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   932
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   933
		while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   934
#ifdef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   935
			DUFFS_LOOP(
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   936
				RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   937
				*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   938
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   939
			, width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   940
#else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   941
			for ( c=width/4; c; --c ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   942
				/* Pack RGB into 8bit pixel */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   943
				RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   944
				*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   945
				++src;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   946
				RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   947
				*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   948
				++src;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   949
				RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   950
				*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   951
				++src;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   952
				RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   953
				*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   954
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   955
			}
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   956
			switch ( width & 3 ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   957
				case 3:
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   958
					RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   959
					*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   960
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   961
				case 2:
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   962
					RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   963
					*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   964
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   965
				case 1:
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   966
					RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   967
					*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   968
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   969
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   970
#endif /* USE_DUFFS_LOOP */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   971
			src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   972
			dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   973
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   974
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   975
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   976
/* Special optimized blit for RGB 8-8-8 --> RGB 5-5-5 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   977
#define RGB888_RGB555(dst, src) { \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   978
	*(Uint16 *)(dst) = (((*src)&0x00F80000)>>9)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   979
	                   (((*src)&0x0000F800)>>6)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   980
	                   (((*src)&0x000000F8)>>3); \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   981
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   982
#define RGB888_RGB555_TWO(dst, src) { \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   983
	*(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>9)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   984
	                     (((src[HI])&0x0000F800)>>6)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   985
	                     (((src[HI])&0x000000F8)>>3))<<16)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   986
	                     (((src[LO])&0x00F80000)>>9)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   987
	                     (((src[LO])&0x0000F800)>>6)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   988
	                     (((src[LO])&0x000000F8)>>3); \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   989
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   990
static void Blit_RGB888_RGB555(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   991
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   992
#ifndef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   993
	int c;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   994
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   995
	int width, height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   996
	Uint32 *src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   997
	Uint16 *dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   998
	int srcskip, dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   999
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1000
	/* Set up some basic variables */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1001
	width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1002
	height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1003
	src = (Uint32 *)info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1004
	srcskip = info->s_skip/4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1005
	dst = (Uint16 *)info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1006
	dstskip = info->d_skip/2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1007
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1008
#ifdef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1009
	while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1010
		DUFFS_LOOP(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1011
			RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1012
			++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1013
			++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1014
		, width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1015
		src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1016
		dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1017
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1018
#else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1019
	/* Memory align at 4-byte boundary, if necessary */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1020
	if ( (long)dst & 0x03 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1021
		/* Don't do anything if width is 0 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1022
		if ( width == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1023
			return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1024
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1025
		--width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1026
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1027
		while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1028
			/* Perform copy alignment */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1029
			RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1030
			++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1031
			++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1032
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1033
			/* Copy in 4 pixel chunks */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1034
			for ( c=width/4; c; --c ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1035
				RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1036
				src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1037
				dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1038
				RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1039
				src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1040
				dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1041
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1042
			/* Get any leftovers */
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
  1043
			switch (width & 3) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1044
				case 3:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1045
					RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1046
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1047
					++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1048
				case 2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1049
					RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1050
					src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1051
					dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1052
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1053
				case 1:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1054
					RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1055
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1056
					++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1057
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1058
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1059
			src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1060
			dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1061
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1062
	} else { 
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1063
		while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1064
			/* Copy in 4 pixel chunks */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1065
			for ( c=width/4; c; --c ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1066
				RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1067
				src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1068
				dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1069
				RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1070
				src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1071
				dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1072
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1073
			/* Get any leftovers */
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
  1074
			switch (width & 3) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1075
				case 3:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1076
					RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1077
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1078
					++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1079
				case 2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1080
					RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1081
					src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1082
					dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1083
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1084
				case 1:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1085
					RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1086
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1087
					++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1088
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1089
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1090
			src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1091
			dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1092
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1093
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1094
#endif /* USE_DUFFS_LOOP */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1095
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1096
/* Special optimized blit for RGB 8-8-8 --> RGB 5-6-5 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1097
#define RGB888_RGB565(dst, src) { \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1098
	*(Uint16 *)(dst) = (((*src)&0x00F80000)>>8)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1099
	                   (((*src)&0x0000FC00)>>5)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1100
	                   (((*src)&0x000000F8)>>3); \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1101
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1102
#define RGB888_RGB565_TWO(dst, src) { \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1103
	*(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>8)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1104
	                     (((src[HI])&0x0000FC00)>>5)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset