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