annotate src/video/SDL_blit_A.c @ 3914:4fd12011d8d6 SDL-1.2

Quartz code should use F13, F14, and F15 keys instead of PrintScreen, ScrollLock, and Pause, since that's what's on the standard Apple keyboards (minus the laptops, which have neither set). Ideally we'll find a better way to distinguish this...the keys being replaced would be correct on a USB keyboard for Windows. Sigh. Fixes Bugzilla #301.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 14 Feb 2007 10:23:23 +0000
parents af4d584e0edb
children d65b4a73c991
rev   line source
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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
3 Copyright (C) 1997-2006 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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
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: 1
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 #include "SDL_video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 #include "SDL_blit.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
27 #if SDL_ASSEMBLY_ROUTINES
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
28 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
29 #define MMX_ASMBLIT 1
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
30 #define GCC_ASMBLIT 1
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
31 #elif defined(_MSC_VER) && (_MSC_VER >= 1200) && defined(_M_IX86)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
32 #define MMX_ASMBLIT 1
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
33 #define MSVC_ASMBLIT 1
880
9ef41050100c Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
34 #endif
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
35 #endif /* SDL_ASSEMBLY_ROUTINES */
880
9ef41050100c Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
36
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 720
diff changeset
37 /* Function to check the CPU flags */
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 720
diff changeset
38 #include "SDL_cpuinfo.h"
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
39 #if GCC_ASMBLIT
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
40 #include "mmx.h"
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
41 #elif MSVC_ASMBLIT
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
42 #include <mmintrin.h>
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
43 #include <mm3dnow.h>
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
44 #endif
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
45
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 /* Functions to perform alpha blended blitting */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 /* N->1 blending with per-surface alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 static void BlitNto1SurfaceAlpha(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 Uint8 *src = info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 int srcskip = info->s_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 Uint8 *dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 int dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 Uint8 *palmap = info->table;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 SDL_PixelFormat *srcfmt = info->src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 SDL_PixelFormat *dstfmt = info->dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 int srcbpp = srcfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62 const unsigned A = srcfmt->alpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 DUFFS_LOOP4(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
67 Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69 unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71 unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73 unsigned dB;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
74 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75 dR = dstfmt->palette->colors[*dst].r;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 dG = dstfmt->palette->colors[*dst].g;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 dB = dstfmt->palette->colors[*dst].b;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78 ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 dR &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 dG &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 dB &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 /* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 if ( palmap == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84 *dst =((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 ((dG>>5)<<(2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86 ((dB>>6)<<(0));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 *dst = palmap[((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 ((dG>>5)<<(2)) |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90 ((dB>>6)<<(0))];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 dst++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 /* N->1 blending with pixel alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102 static void BlitNto1PixelAlpha(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
103 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
104 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
105 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106 Uint8 *src = info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107 int srcskip = info->s_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
108 Uint8 *dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
109 int dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110 Uint8 *palmap = info->table;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111 SDL_PixelFormat *srcfmt = info->src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112 SDL_PixelFormat *dstfmt = info->dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113 int srcbpp = srcfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 /* FIXME: fix alpha bit field expansion here too? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117 DUFFS_LOOP4(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118 {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
119 Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 unsigned sA;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125 unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126 unsigned dB;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
127 DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 dR = dstfmt->palette->colors[*dst].r;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129 dG = dstfmt->palette->colors[*dst].g;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 dB = dstfmt->palette->colors[*dst].b;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131 ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 dR &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 dG &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134 dB &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 /* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 if ( palmap == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 *dst =((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 ((dG>>5)<<(2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 ((dB>>6)<<(0));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
141 *dst = palmap[((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
142 ((dG>>5)<<(2)) |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 ((dB>>6)<<(0)) ];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 dst++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146 src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148 width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 /* colorkeyed N->1 blending with per-surface alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 Uint8 *src = info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 int srcskip = info->s_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 Uint8 *dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162 int dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 Uint8 *palmap = info->table;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 SDL_PixelFormat *srcfmt = info->src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 SDL_PixelFormat *dstfmt = info->dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166 int srcbpp = srcfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167 Uint32 ckey = srcfmt->colorkey;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
168
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169 const int A = srcfmt->alpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
171 while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 DUFFS_LOOP(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
174 Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
175 unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176 unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
177 unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179 unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
180 unsigned dB;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
181 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
182 if ( Pixel != ckey ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183 dR = dstfmt->palette->colors[*dst].r;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184 dG = dstfmt->palette->colors[*dst].g;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185 dB = dstfmt->palette->colors[*dst].b;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 dR &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 dG &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 dB &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190 /* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 if ( palmap == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 *dst =((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 ((dG>>5)<<(2)) |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 ((dB>>6)<<(0));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 *dst = palmap[((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 ((dG>>5)<<(2)) |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 ((dB>>6)<<(0)) ];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
201 dst++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202 src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205 src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
210 #if GCC_ASMBLIT
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
211 /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
212 static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info)
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
213 {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
214 int width = info->d_width;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
215 int height = info->d_height;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
216 Uint32 *srcp = (Uint32 *)info->s_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
217 int srcskip = info->s_skip >> 2;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
218 Uint32 *dstp = (Uint32 *)info->d_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
219 int dstskip = info->d_skip >> 2;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
220 Uint32 dalpha = info->dst->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
221 Uint8 load[8];
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
222
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
223 *(Uint64 *)load = 0x00fefefe00fefefeULL;/* alpha128 mask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
224 movq_m2r(*load, mm4); /* alpha128 mask -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
225 *(Uint64 *)load = 0x0001010100010101ULL;/* !alpha128 mask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
226 movq_m2r(*load, mm3); /* !alpha128 mask -> mm3 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
227 movd_m2r(dalpha, mm7); /* dst alpha mask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
228 punpckldq_r2r(mm7, mm7); /* dst alpha mask | dst alpha mask -> mm7 */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
229 while(height--) {
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
230 DUFFS_LOOP_DOUBLE2(
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
231 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
232 Uint32 s = *srcp++;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
233 Uint32 d = *dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
234 *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
235 + (s & d & 0x00010101)) | dalpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
236 },{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
237 movq_m2r((*dstp), mm2);/* 2 x dst -> mm2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
238 movq_r2r(mm2, mm6); /* 2 x dst -> mm6(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
239
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
240 movq_m2r((*srcp), mm1);/* 2 x src -> mm1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
241 movq_r2r(mm1, mm5); /* 2 x src -> mm5(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
242
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
243 pand_r2r(mm4, mm6); /* dst & mask -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
244 pand_r2r(mm4, mm5); /* src & mask -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
245 paddd_r2r(mm6, mm5); /* mm6 + mm5 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
246 pand_r2r(mm1, mm2); /* src & dst -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
247 psrld_i2r(1, mm5); /* mm5 >> 1 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
248 pand_r2r(mm3, mm2); /* mm2 & !mask -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
249 paddd_r2r(mm5, mm2); /* mm5 + mm2 -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
250
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
251 por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
252 movq_r2m(mm2, (*dstp));/* mm2 -> 2 x dst pixels */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
253 dstp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
254 srcp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
255 }, width);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
256 srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
257 dstp += dstskip;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
258 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
259 emms();
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
260 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
261
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
262 /* fast RGB888->(A)RGB888 blending with surface alpha */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
263 static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info)
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
264 {
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
265 SDL_PixelFormat* df = info->dst;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
266 unsigned alpha = info->src->alpha;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
267
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
268 if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
269 /* only call a128 version when R,G,B occupy lower bits */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
270 BlitRGBtoRGBSurfaceAlpha128MMX(info);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
271 } else {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
272 int width = info->d_width;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
273 int height = info->d_height;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
274 Uint32 *srcp = (Uint32 *)info->s_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
275 int srcskip = info->s_skip >> 2;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
276 Uint32 *dstp = (Uint32 *)info->d_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
277 int dstskip = info->d_skip >> 2;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
278
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
279 pxor_r2r(mm5, mm5); /* 0 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
280 /* form the alpha mult */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
281 movd_m2r(alpha, mm4); /* 0000000A -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
282 punpcklwd_r2r(mm4, mm4); /* 00000A0A -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
283 punpckldq_r2r(mm4, mm4); /* 0A0A0A0A -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
284 alpha = (0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df->Bshift);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
285 movd_m2r(alpha, mm0); /* 00000FFF -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
286 punpcklbw_r2r(mm0, mm0); /* 00FFFFFF -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
287 pand_r2r(mm0, mm4); /* 0A0A0A0A -> mm4, minus 1 chan */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
288 /* at this point mm4 can be 000A0A0A or 0A0A0A00 or another combo */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
289 movd_m2r(df->Amask, mm7); /* dst alpha mask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
290 punpckldq_r2r(mm7, mm7); /* dst alpha mask | dst alpha mask -> mm7 */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
291
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
292 while(height--) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
293 DUFFS_LOOP_DOUBLE2({
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
294 /* One Pixel Blend */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
295 movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
296 movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
297 punpcklbw_r2r(mm5, mm1); /* 0A0R0G0B -> mm1(src) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
298 punpcklbw_r2r(mm5, mm2); /* 0A0R0G0B -> mm2(dst) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
299
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
300 psubw_r2r(mm2, mm1);/* src - dst -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
301 pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
302 psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
303 paddb_r2r(mm1, mm2); /* mm1 + mm2(dst) -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
304
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
305 packuswb_r2r(mm5, mm2); /* ARGBARGB -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
306 por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
307 movd_r2m(mm2, *dstp);/* mm2 -> pixel */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
308 ++srcp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
309 ++dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
310 },{
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
311 /* Two Pixels Blend */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
312 movq_m2r((*srcp), mm0);/* 2 x src -> mm0(ARGBARGB)*/
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
313 movq_m2r((*dstp), mm2);/* 2 x dst -> mm2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
314 movq_r2r(mm0, mm1); /* 2 x src -> mm1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
315 movq_r2r(mm2, mm6); /* 2 x dst -> mm6(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
316
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
317 punpcklbw_r2r(mm5, mm0); /* low - 0A0R0G0B -> mm0(src1) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
318 punpckhbw_r2r(mm5, mm1); /* high - 0A0R0G0B -> mm1(src2) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
319 punpcklbw_r2r(mm5, mm2); /* low - 0A0R0G0B -> mm2(dst1) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
320 punpckhbw_r2r(mm5, mm6); /* high - 0A0R0G0B -> mm6(dst2) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
321
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
322 psubw_r2r(mm2, mm0);/* src1 - dst1 -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
323 pmullw_r2r(mm4, mm0); /* mm0 * alpha -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
324 psrlw_i2r(8, mm0); /* mm0 >> 8 -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
325 paddb_r2r(mm0, mm2); /* mm0 + mm2(dst1) -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
326
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
327 psubw_r2r(mm6, mm1);/* src2 - dst2 -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
328 pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
329 psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
330 paddb_r2r(mm1, mm6); /* mm1 + mm6(dst2) -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
331
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
332 packuswb_r2r(mm6, mm2); /* ARGBARGB -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
333 por_r2r(mm7, mm2); /* mm7(dst alpha) | mm2 -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
334
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
335 movq_r2m(mm2, *dstp);/* mm2 -> 2 x pixel */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
336
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
337 srcp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
338 dstp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
339 }, width);
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
340 srcp += srcskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
341 dstp += dstskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
342 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
343 emms();
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
344 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
345 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
346
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
347 /* fast ARGB888->(A)RGB888 blending with pixel alpha */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
348 static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info)
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
349 {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
350 int width = info->d_width;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
351 int height = info->d_height;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
352 Uint32 *srcp = (Uint32 *)info->s_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
353 int srcskip = info->s_skip >> 2;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
354 Uint32 *dstp = (Uint32 *)info->d_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
355 int dstskip = info->d_skip >> 2;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
356 SDL_PixelFormat* sf = info->src;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
357 Uint32 amask = sf->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
358
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
359 pxor_r2r(mm6, mm6); /* 0 -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
360 /* form multiplication mask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
361 movd_m2r(sf->Amask, mm7); /* 0000F000 -> mm7 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
362 punpcklbw_r2r(mm7, mm7); /* FF000000 -> mm7 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
363 pcmpeqb_r2r(mm0, mm0); /* FFFFFFFF -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
364 movq_r2r(mm0, mm3); /* FFFFFFFF -> mm3 (for later) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
365 pxor_r2r(mm0, mm7); /* 00FFFFFF -> mm7 (mult mask) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
366 /* form channel masks */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
367 movq_r2r(mm7, mm0); /* 00FFFFFF -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
368 packsswb_r2r(mm6, mm0); /* 00000FFF -> mm0 (channel mask) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
369 packsswb_r2r(mm6, mm3); /* 0000FFFF -> mm3 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
370 pxor_r2r(mm0, mm3); /* 0000F000 -> mm3 (~channel mask) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
371 /* get alpha channel shift */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
372 movd_m2r(sf->Ashift, mm5); /* Ashift -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
373
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
374 while(height--) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
375 DUFFS_LOOP4({
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
376 Uint32 alpha = *srcp & amask;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
377 /* FIXME: Here we special-case opaque alpha since the
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
378 compositioning used (>>8 instead of /255) doesn't handle
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
379 it correctly. Also special-case alpha=0 for speed?
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
380 Benchmark this! */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
381 if(alpha == 0) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
382 /* do nothing */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
383 } else if(alpha == amask) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
384 /* opaque alpha -- copy RGB, keep dst alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
385 /* using MMX here to free up regular registers for other things */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
386 movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
387 movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
388 pand_r2r(mm0, mm1); /* src & chanmask -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
389 pand_r2r(mm3, mm2); /* dst & ~chanmask -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
390 por_r2r(mm1, mm2); /* src | dst -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
391 movd_r2m(mm2, (*dstp)); /* mm2 -> dst */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
392 } else {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
393 movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
394 punpcklbw_r2r(mm6, mm1); /* 0A0R0G0B -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
395
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
396 movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
397 punpcklbw_r2r(mm6, mm2); /* 0A0R0G0B -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
398
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
399 __asm__ __volatile__ (
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
400 "movd %0, %%mm4"
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
401 : : "r" (alpha) ); /* 0000A000 -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
402 psrld_r2r(mm5, mm4); /* mm4 >> mm5 -> mm4 (0000000A) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
403 punpcklwd_r2r(mm4, mm4); /* 00000A0A -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
404 punpcklwd_r2r(mm4, mm4); /* 0A0A0A0A -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
405 pand_r2r(mm7, mm4); /* 000A0A0A -> mm4, preserve dst alpha on add */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
406
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
407 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
408 psubw_r2r(mm2, mm1);/* src - dst -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
409 pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
410 psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1(000R0G0B) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
411 paddb_r2r(mm1, mm2); /* mm1 + mm2(dst) -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
412
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
413 packuswb_r2r(mm6, mm2); /* 0000ARGB -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
414 movd_r2m(mm2, *dstp);/* mm2 -> dst */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
415 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
416 ++srcp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
417 ++dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
418 }, width);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
419 srcp += srcskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
420 dstp += dstskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
421 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
422 emms();
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
423 }
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
424 /* End GCC_ASMBLIT */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
425
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
426 #elif MSVC_ASMBLIT
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
427 /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
428 static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
429 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
430 int width = info->d_width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
431 int height = info->d_height;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
432 Uint32 *srcp = (Uint32 *)info->s_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
433 int srcskip = info->s_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
434 Uint32 *dstp = (Uint32 *)info->d_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
435 int dstskip = info->d_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
436 Uint32 dalpha = info->dst->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
437
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
438 __m64 src1, src2, dst1, dst2, lmask, hmask, dsta;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
439
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
440 hmask = _mm_set_pi32(0x00fefefe, 0x00fefefe); /* alpha128 mask -> hmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
441 lmask = _mm_set_pi32(0x00010101, 0x00010101); /* !alpha128 mask -> lmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
442 dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
443
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
444 while (height--) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
445 int n = width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
446 if ( n & 1 ) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
447 Uint32 s = *srcp++;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
448 Uint32 d = *dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
449 *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
450 + (s & d & 0x00010101)) | dalpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
451 n--;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
452 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
453
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
454 for (n >>= 1; n > 0; --n) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
455 dst1 = *(__m64*)dstp; /* 2 x dst -> dst1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
456 dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
457
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
458 src1 = *(__m64*)srcp; /* 2 x src -> src1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
459 src2 = src1; /* 2 x src -> src2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
460
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
461 dst2 = _mm_and_si64(dst2, hmask); /* dst & mask -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
462 src2 = _mm_and_si64(src2, hmask); /* src & mask -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
463 src2 = _mm_add_pi32(src2, dst2); /* dst2 + src2 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
464 src2 = _mm_srli_pi32(src2, 1); /* src2 >> 1 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
465
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
466 dst1 = _mm_and_si64(dst1, src1); /* src & dst -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
467 dst1 = _mm_and_si64(dst1, lmask); /* dst1 & !mask -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
468 dst1 = _mm_add_pi32(dst1, src2); /* src2 + dst1 -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
469 dst1 = _mm_or_si64(dst1, dsta); /* dsta(full alpha) | dst1 -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
470
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
471 *(__m64*)dstp = dst1; /* dst1 -> 2 x dst pixels */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
472 dstp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
473 srcp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
474 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
475
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
476 srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
477 dstp += dstskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
478 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
479 _mm_empty();
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
480 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
481
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
482 /* fast RGB888->(A)RGB888 blending with surface alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
483 static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
484 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
485 SDL_PixelFormat* df = info->dst;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
486 Uint32 chanmask = df->Rmask | df->Gmask | df->Bmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
487 unsigned alpha = info->src->alpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
488
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
489 if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
490 /* only call a128 version when R,G,B occupy lower bits */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
491 BlitRGBtoRGBSurfaceAlpha128MMX(info);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
492 } else {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
493 int width = info->d_width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
494 int height = info->d_height;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
495 Uint32 *srcp = (Uint32 *)info->s_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
496 int srcskip = info->s_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
497 Uint32 *dstp = (Uint32 *)info->d_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
498 int dstskip = info->d_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
499 Uint32 dalpha = df->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
500 Uint32 amult;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
501
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
502 __m64 src1, src2, dst1, dst2, mm_alpha, mm_zero, dsta;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
503
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
504 mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
505 /* form the alpha mult */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
506 amult = alpha | (alpha << 8);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
507 amult = amult | (amult << 16);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
508 chanmask = (0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df->Bshift);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
509 mm_alpha = _mm_set_pi32(0, amult & chanmask); /* 0000AAAA -> mm_alpha, minus 1 chan */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
510 mm_alpha = _mm_unpacklo_pi8(mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
511 /* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
512 dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
513
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
514 while (height--) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
515 int n = width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
516 if (n & 1) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
517 /* One Pixel Blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
518 src2 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src2 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
519 src2 = _mm_unpacklo_pi8(src2, mm_zero); /* 0A0R0G0B -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
520
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
521 dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
522 dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
523
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
524 src2 = _mm_sub_pi16(src2, dst1); /* src2 - dst2 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
525 src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
526 src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
527 dst1 = _mm_add_pi8(src2, dst1); /* src2 + dst1 -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
528
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
529 dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
530 dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
531 *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
532
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
533 ++srcp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
534 ++dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
535
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
536 n--;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
537 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
538
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
539 for (n >>= 1; n > 0; --n) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
540 /* Two Pixels Blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
541 src1 = *(__m64*)srcp; /* 2 x src -> src1(ARGBARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
542 src2 = src1; /* 2 x src -> src2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
543 src1 = _mm_unpacklo_pi8(src1, mm_zero); /* low - 0A0R0G0B -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
544 src2 = _mm_unpackhi_pi8(src2, mm_zero); /* high - 0A0R0G0B -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
545
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
546 dst1 = *(__m64*)dstp;/* 2 x dst -> dst1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
547 dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
548 dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* low - 0A0R0G0B -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
549 dst2 = _mm_unpackhi_pi8(dst2, mm_zero); /* high - 0A0R0G0B -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
550
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
551 src1 = _mm_sub_pi16(src1, dst1);/* src1 - dst1 -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
552 src1 = _mm_mullo_pi16(src1, mm_alpha); /* src1 * alpha -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
553 src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
554 dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst1) -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
555
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
556 src2 = _mm_sub_pi16(src2, dst2);/* src2 - dst2 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
557 src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
558 src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
559 dst2 = _mm_add_pi8(src2, dst2); /* src2 + dst2(dst2) -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
560
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
561 dst1 = _mm_packs_pu16(dst1, dst2); /* 0A0R0G0B(res1), 0A0R0G0B(res2) -> dst1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
562 dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
563
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
564 *(__m64*)dstp = dst1; /* dst1 -> 2 x pixel */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
565
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
566 srcp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
567 dstp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
568 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
569 srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
570 dstp += dstskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
571 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
572 _mm_empty();
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
573 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
574 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
575
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
576 /* fast ARGB888->(A)RGB888 blending with pixel alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
577 static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
578 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
579 int width = info->d_width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
580 int height = info->d_height;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
581 Uint32 *srcp = (Uint32 *)info->s_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
582 int srcskip = info->s_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
583 Uint32 *dstp = (Uint32 *)info->d_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
584 int dstskip = info->d_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
585 SDL_PixelFormat* sf = info->src;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
586 Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
587 Uint32 amask = sf->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
588 Uint32 ashift = sf->Ashift;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
589 Uint64 multmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
590
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
591 __m64 src1, dst1, mm_alpha, mm_zero, dmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
592
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
593 mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
594 multmask = ~(0xFFFFi64 << (ashift * 2));
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
595 dmask = *(__m64*) &multmask; /* dst alpha mask -> dmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
596
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
597 while(height--) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
598 DUFFS_LOOP4({
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
599 Uint32 alpha = *srcp & amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
600 if (alpha == 0) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
601 /* do nothing */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
602 } else if (alpha == amask) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
603 /* opaque alpha -- copy RGB, keep dst alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
604 *dstp = (*srcp & chanmask) | (*dstp & ~chanmask);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
605 } else {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
606 src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
607 src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
608
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
609 dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
610 dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
611
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
612 mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
613 mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
614 mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
615 mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
616 mm_alpha = _mm_and_si64(mm_alpha, dmask); /* 000A0A0A -> mm_alpha, preserve dst alpha on add */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
617
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
618 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
619 src1 = _mm_sub_pi16(src1, dst1);/* src1 - dst1 -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
620 src1 = _mm_mullo_pi16(src1, mm_alpha); /* (src1 - dst1) * alpha -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
621 src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1(000R0G0B) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
622 dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1 -> dst1(0A0R0G0B) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
623 dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
624
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
625 *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
626 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
627 ++srcp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
628 ++dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
629 }, width);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
630 srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
631 dstp += dstskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
632 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
633 _mm_empty();
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
634 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
635 /* End MSVC_ASMBLIT */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
636
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
637 #endif /* GCC_ASMBLIT, MSVC_ASMBLIT */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
638
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
639 #if SDL_ALTIVEC_BLITTERS
1795
398ac0f88e4d Fixed bug #220
Sam Lantinga <slouken@libsdl.org>
parents: 1617
diff changeset
640 #if __MWERKS__
398ac0f88e4d Fixed bug #220
Sam Lantinga <slouken@libsdl.org>
parents: 1617
diff changeset
641 #pragma altivec_model on
398ac0f88e4d Fixed bug #220
Sam Lantinga <slouken@libsdl.org>
parents: 1617
diff changeset
642 #endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
643 #if HAVE_ALTIVEC_H
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
644 #include <altivec.h>
1175
867f521591e5 Fixed Altivec support on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1162
diff changeset
645 #endif
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
646 #include <assert.h>
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
647
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
648 #if (defined(__MACOSX__) && (__GNUC__ < 4))
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
649 #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
650 (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
651 #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
652 (vector unsigned short) ( a,b,c,d,e,f,g,h )
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
653 #else
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
654 #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
655 (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
656 #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
657 (vector unsigned short) { a,b,c,d,e,f,g,h }
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
658 #endif
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
659
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
660 #define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
661 #define VECPRINT(msg, v) do { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
662 vector unsigned int tmpvec = (vector unsigned int)(v); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
663 unsigned int *vp = (unsigned int *)&tmpvec; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
664 printf("%s = %08X %08X %08X %08X\n", msg, vp[0], vp[1], vp[2], vp[3]); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
665 } while (0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
666
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
667 /* the permuation vector that takes the high bytes out of all the appropriate shorts
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
668 (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
669 0x00, 0x10, 0x02, 0x12,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
670 0x04, 0x14, 0x06, 0x16,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
671 0x08, 0x18, 0x0A, 0x1A,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
672 0x0C, 0x1C, 0x0E, 0x1E );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
673 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
674 #define VEC_MERGE_PERMUTE() (vec_add(vec_lvsl(0, (int*)NULL), (vector unsigned char)vec_splat_u16(0x0F)))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
675 #define VEC_U32_24() (vec_add(vec_splat_u32(12), vec_splat_u32(12)))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
676 #define VEC_ALPHA_MASK() ((vector unsigned char)vec_sl((vector unsigned int)vec_splat_s8(-1), VEC_U32_24()))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
677 #define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
678 ? vec_lvsl(0, src) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
679 : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
680
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
681
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
682 #define VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1_16, v8_16) do { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
683 /* vtemp1 contains source AAGGAAGGAAGGAAGG */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
684 vector unsigned short vtemp1 = vec_mule(vs, valpha); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
685 /* vtemp2 contains source RRBBRRBBRRBBRRBB */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
686 vector unsigned short vtemp2 = vec_mulo(vs, valpha); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
687 /* valpha2 is 255-alpha */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
688 vector unsigned char valpha2 = vec_nor(valpha, valpha); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
689 /* vtemp3 contains dest AAGGAAGGAAGGAAGG */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
690 vector unsigned short vtemp3 = vec_mule(vd, valpha2); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
691 /* vtemp4 contains dest RRBBRRBBRRBBRRBB */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
692 vector unsigned short vtemp4 = vec_mulo(vd, valpha2); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
693 /* add source and dest */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
694 vtemp1 = vec_add(vtemp1, vtemp3); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
695 vtemp2 = vec_add(vtemp2, vtemp4); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
696 /* vtemp1 = (vtemp1 + 1) + ((vtemp1 + 1) >> 8) */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
697 vtemp1 = vec_add(vtemp1, v1_16); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
698 vtemp3 = vec_sr(vtemp1, v8_16); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
699 vtemp1 = vec_add(vtemp1, vtemp3); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
700 /* vtemp2 = (vtemp2 + 1) + ((vtemp2 + 1) >> 8) */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
701 vtemp2 = vec_add(vtemp2, v1_16); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
702 vtemp4 = vec_sr(vtemp2, v8_16); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
703 vtemp2 = vec_add(vtemp2, vtemp4); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
704 /* (>>8) and get ARGBARGBARGBARGB */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
705 vd = (vector unsigned char)vec_perm(vtemp1, vtemp2, mergePermute); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
706 } while (0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
707
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
708 /* Calculate the permute vector used for 32->32 swizzling */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
709 static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
710 const SDL_PixelFormat *dstfmt)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
711 {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
712 /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
713 * We have to assume that the bits that aren't used by other
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
714 * colors is alpha, and it's one complete byte, since some formats
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
715 * leave alpha with a zero mask, but we should still swizzle the bits.
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
716 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
717 /* ARGB */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
718 const static struct SDL_PixelFormat default_pixel_format = {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
719 NULL, 0, 0,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
720 0, 0, 0, 0,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
721 16, 8, 0, 24,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
722 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
723 0, 0};
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
724 if (!srcfmt) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
725 srcfmt = &default_pixel_format;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
726 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
727 if (!dstfmt) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
728 dstfmt = &default_pixel_format;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
729 }
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
730 const vector unsigned char plus = VECUINT8_LITERAL
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
731 ( 0x00, 0x00, 0x00, 0x00,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
732 0x04, 0x04, 0x04, 0x04,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
733 0x08, 0x08, 0x08, 0x08,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
734 0x0C, 0x0C, 0x0C, 0x0C );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
735 vector unsigned char vswiz;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
736 vector unsigned int srcvec;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
737 #define RESHIFT(X) (3 - ((X) >> 3))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
738 Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
739 Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
740 Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
741 Uint32 amask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
742 /* Use zero for alpha if either surface doesn't have alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
743 if (dstfmt->Amask) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
744 amask = ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
745 } else {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
746 amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
747 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
748 #undef RESHIFT
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
749 ((unsigned int *)(char*)&srcvec)[0] = (rmask | gmask | bmask | amask);
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
750 vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
751 return(vswiz);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
752 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
753
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
754 static void Blit32to565PixelAlphaAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
755 {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
756 int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
757 Uint8 *src = (Uint8 *)info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
758 int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
759 Uint8 *dst = (Uint8 *)info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
760 int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
761 SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
762
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
763 vector unsigned char v0 = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
764 vector unsigned short v8_16 = vec_splat_u16(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
765 vector unsigned short v1_16 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
766 vector unsigned short v2_16 = vec_splat_u16(2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
767 vector unsigned short v3_16 = vec_splat_u16(3);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
768 vector unsigned int v8_32 = vec_splat_u32(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
769 vector unsigned int v16_32 = vec_add(v8_32, v8_32);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
770 vector unsigned short v3f = VECUINT16_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
771 0x003f, 0x003f, 0x003f, 0x003f,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
772 0x003f, 0x003f, 0x003f, 0x003f);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
773 vector unsigned short vfc = VECUINT16_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
774 0x00fc, 0x00fc, 0x00fc, 0x00fc,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
775 0x00fc, 0x00fc, 0x00fc, 0x00fc);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
776
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
777 /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
778 0x10 - 0x1f is the alpha
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
779 0x00 - 0x0e evens are the red
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
780 0x01 - 0x0f odds are zero
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
781 */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
782 vector unsigned char vredalpha1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
783 0x10, 0x00, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
784 0x10, 0x02, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
785 0x10, 0x04, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
786 0x10, 0x06, 0x01, 0x01
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
787 );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
788 vector unsigned char vredalpha2 = (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
789 vec_add((vector unsigned int)vredalpha1, vec_sl(v8_32, v16_32))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
790 );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
791 /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
792 0x00 - 0x0f is ARxx ARxx ARxx ARxx
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
793 0x11 - 0x0f odds are blue
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
794 */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
795 vector unsigned char vblue1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
796 0x00, 0x01, 0x02, 0x11,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
797 0x04, 0x05, 0x06, 0x13,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
798 0x08, 0x09, 0x0a, 0x15,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
799 0x0c, 0x0d, 0x0e, 0x17
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
800 );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
801 vector unsigned char vblue2 = (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
802 vec_add((vector unsigned int)vblue1, v8_32)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
803 );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
804 /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
805 0x00 - 0x0f is ARxB ARxB ARxB ARxB
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
806 0x10 - 0x0e evens are green
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
807 */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
808 vector unsigned char vgreen1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
809 0x00, 0x01, 0x10, 0x03,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
810 0x04, 0x05, 0x12, 0x07,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
811 0x08, 0x09, 0x14, 0x0b,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
812 0x0c, 0x0d, 0x16, 0x0f
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
813 );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
814 vector unsigned char vgreen2 = (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
815 vec_add((vector unsigned int)vgreen1, vec_sl(v8_32, v8_32))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
816 );
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
817 vector unsigned char vgmerge = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
818 0x00, 0x02, 0x00, 0x06,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
819 0x00, 0x0a, 0x00, 0x0e,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
820 0x00, 0x12, 0x00, 0x16,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
821 0x00, 0x1a, 0x00, 0x1e);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
822 vector unsigned char mergePermute = VEC_MERGE_PERMUTE();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
823 vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
824 vector unsigned char valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
825
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
826 vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
827 vf800 = vec_sl(vf800, vec_splat_u16(8));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
828
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
829 while(height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
830 int extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
831 vector unsigned char valigner;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
832 vector unsigned char vsrc;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
833 vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
834 int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
835
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
836 #define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
837 while (condition) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
838 Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
839 unsigned sR, sG, sB, dR, dG, dB, sA; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
840 DISEMBLE_RGBA(src, 4, srcfmt, Pixel, sR, sG, sB, sA); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
841 if(sA) { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
842 unsigned short dstpixel = *((unsigned short *)dst); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
843 dR = (dstpixel >> 8) & 0xf8; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
844 dG = (dstpixel >> 3) & 0xfc; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
845 dB = (dstpixel << 3) & 0xf8; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
846 ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
847 *((unsigned short *)dst) = ( \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
848 ((dR & 0xf8) << 8) | ((dG & 0xfc) << 3) | (dB >> 3) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
849 ); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
850 } \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
851 src += 4; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
852 dst += 2; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
853 widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
854 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
855 ONE_PIXEL_BLEND((UNALIGNED_PTR(dst)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
856 extrawidth = (width % 8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
857 valigner = VEC_ALIGNER(src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
858 vsrc = (vector unsigned char)vec_ld(0, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
859 width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
860 while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
861 vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
862 vector unsigned char vsrc1, vsrc2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
863 vector unsigned char vdst1, vdst2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
864 vector unsigned short vR, vG, vB;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
865 vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
866
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
867 /* Load 8 pixels from src as ARGB */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
868 voverflow = (vector unsigned char)vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
869 vsrc = vec_perm(vsrc, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
870 vsrc1 = vec_perm(vsrc, vsrc, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
871 src += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
872 vsrc = (vector unsigned char)vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
873 voverflow = vec_perm(voverflow, vsrc, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
874 vsrc2 = vec_perm(voverflow, voverflow, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
875 src += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
876
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
877 /* Load 8 pixels from dst as XRGB */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
878 voverflow = vec_ld(0, dst);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
879 vR = vec_and((vector unsigned short)voverflow, vf800);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
880 vB = vec_sl((vector unsigned short)voverflow, v3_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
881 vG = vec_sl(vB, v2_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
882 vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, (vector unsigned char)vR, vredalpha1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
883 vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
884 vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
885 vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, (vector unsigned char)vR, vredalpha2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
886 vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
887 vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
888
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
889 /* Alpha blend 8 pixels as ARGB */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
890 valpha = vec_perm(vsrc1, v0, valphaPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
891 VEC_MULTIPLY_ALPHA(vsrc1, vdst1, valpha, mergePermute, v1_16, v8_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
892 valpha = vec_perm(vsrc2, v0, valphaPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
893 VEC_MULTIPLY_ALPHA(vsrc2, vdst2, valpha, mergePermute, v1_16, v8_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
894
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
895 /* Convert 8 pixels to 565 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
896 vpixel = (vector unsigned short)vec_packpx((vector unsigned int)vdst1, (vector unsigned int)vdst2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
897 vgpixel = (vector unsigned short)vec_perm(vdst1, vdst2, vgmerge);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
898 vgpixel = vec_and(vgpixel, vfc);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
899 vgpixel = vec_sl(vgpixel, v3_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
900 vrpixel = vec_sl(vpixel, v1_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
901 vrpixel = vec_and(vrpixel, vf800);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
902 vbpixel = vec_and(vpixel, v3f);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
903 vdst1 = vec_or((vector unsigned char)vrpixel, (vector unsigned char)vgpixel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
904 vdst1 = vec_or(vdst1, (vector unsigned char)vbpixel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
905
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
906 /* Store 8 pixels */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
907 vec_st(vdst1, 0, dst);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
908
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
909 width -= 8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
910 dst += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
911 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
912 ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
913 #undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
914 src += srcskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
915 dst += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
916 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
917 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
918
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
919 static void Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
920 {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
921 unsigned alpha = info->src->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
922 int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
923 Uint32 *srcp = (Uint32 *)info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
924 int srcskip = info->s_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
925 Uint32 *dstp = (Uint32 *)info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
926 int dstskip = info->d_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
927 SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
928 SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
929 unsigned sA = srcfmt->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
930 unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
931 Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
932 Uint32 ckey = info->src->colorkey;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
933 vector unsigned char mergePermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
934 vector unsigned char vsrcPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
935 vector unsigned char vdstPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
936 vector unsigned char vsdstPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
937 vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
938 vector unsigned char valphamask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
939 vector unsigned char vbits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
940 vector unsigned char v0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
941 vector unsigned short v1;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
942 vector unsigned short v8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
943 vector unsigned int vckey;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
944 vector unsigned int vrgbmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
945
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
946 mergePermute = VEC_MERGE_PERMUTE();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
947 v0 = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
948 v1 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
949 v8 = vec_splat_u16(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
950
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
951 /* set the alpha to 255 on the destination surf */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
952 valphamask = VEC_ALPHA_MASK();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
953
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
954 vsrcPermute = calc_swizzle32(srcfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
955 vdstPermute = calc_swizzle32(NULL, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
956 vsdstPermute = calc_swizzle32(dstfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
957
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
958 /* set a vector full of alpha and 255-alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
959 ((unsigned char *)&valpha)[0] = alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
960 valpha = vec_splat(valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
961 vbits = (vector unsigned char)vec_splat_s8(-1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
962
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
963 ckey &= rgbmask;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
964 ((unsigned int *)(char*)&vckey)[0] = ckey;
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
965 vckey = vec_splat(vckey, 0);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
966 ((unsigned int *)(char*)&vrgbmask)[0] = rgbmask;
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
967 vrgbmask = vec_splat(vrgbmask, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
968
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
969 while(height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
970 int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
971 #define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
972 while (condition) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
973 Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
974 unsigned sR, sG, sB, dR, dG, dB; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
975 RETRIEVE_RGB_PIXEL(((Uint8 *)srcp), 4, Pixel); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
976 if(sA && Pixel != ckey) { \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
977 RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
978 DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
979 ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
980 ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
981 } \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
982 dstp++; \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
983 srcp++; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
984 widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
985 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
986 ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
987 if (width > 0) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
988 int extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
989 vector unsigned char valigner = VEC_ALIGNER(srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
990 vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
991 width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
992 while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
993 vector unsigned char vsel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
994 vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
995 vector unsigned char vd;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
996 vector unsigned char vd_orig;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
997
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
998 /* s = *srcp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
999 voverflow = (vector unsigned char)vec_ld(15, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1000 vs = vec_perm(vs, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1001
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1002 /* vsel is set for items that match the key */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1003 vsel = (vector unsigned char)vec_and((vector unsigned int)vs, vrgbmask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1004 vsel = (vector unsigned char)vec_cmpeq((vector unsigned int)vsel, vckey);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1005
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1006 /* permute to source format */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1007 vs = vec_perm(vs, valpha, vsrcPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1008
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1009 /* d = *dstp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1010 vd = (vector unsigned char)vec_ld(0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1011 vd_orig = vd = vec_perm(vd, v0, vsdstPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1012
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1013 VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1014
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1015 /* set the alpha channel to full on */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1016 vd = vec_or(vd, valphamask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1017
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1018 /* mask out color key */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1019 vd = vec_sel(vd, vd_orig, vsel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1020
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1021 /* permute to dest format */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1022 vd = vec_perm(vd, vbits, vdstPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1023
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1024 /* *dstp = res */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1025 vec_st((vector unsigned int)vd, 0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1026
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1027 srcp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1028 dstp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1029 width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1030 vs = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1031 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1032 ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1033 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1034 #undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1035
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1036 srcp += srcskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1037 dstp += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1038 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1039 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1040
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1041
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1042 static void Blit32to32PixelAlphaAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1043 {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1044 int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1045 int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1046 Uint32 *srcp = (Uint32 *)info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1047 int srcskip = info->s_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1048 Uint32 *dstp = (Uint32 *)info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1049 int dstskip = info->d_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1050 SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1051 SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1052 vector unsigned char mergePermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1053 vector unsigned char valphaPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1054 vector unsigned char vsrcPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1055 vector unsigned char vdstPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1056 vector unsigned char vsdstPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1057 vector unsigned char valphamask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1058 vector unsigned char vpixelmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1059 vector unsigned char v0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1060 vector unsigned short v1;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1061 vector unsigned short v8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1062
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1063 v0 = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1064 v1 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1065 v8 = vec_splat_u16(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1066 mergePermute = VEC_MERGE_PERMUTE();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1067 valphamask = VEC_ALPHA_MASK();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1068 valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1069 vpixelmask = vec_nor(valphamask, v0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1070 vsrcPermute = calc_swizzle32(srcfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1071 vdstPermute = calc_swizzle32(NULL, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1072 vsdstPermute = calc_swizzle32(dstfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1073
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1074 while ( height-- ) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1075 width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1076 #define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
1077 Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1078 unsigned sR, sG, sB, dR, dG, dB, sA, dA; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
1079 DISEMBLE_RGBA((Uint8 *)srcp, 4, srcfmt, Pixel, sR, sG, sB, sA); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1080 if(sA) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
1081 DISEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, Pixel, dR, dG, dB, dA); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1082 ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1083 ASSEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, dR, dG, dB, dA); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1084 } \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1085 ++srcp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1086 ++dstp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1087 widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1088 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1089 ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1090 if (width > 0) {
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
1091 /* vsrcPermute */
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
1092 /* vdstPermute */
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1093 int extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1094 vector unsigned char valigner = VEC_ALIGNER(srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1095 vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1096 width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1097 while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1098 vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1099 vector unsigned char vd;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1100 vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1101 vector unsigned char vdstalpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1102 /* s = *srcp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1103 voverflow = (vector unsigned char)vec_ld(15, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1104 vs = vec_perm(vs, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1105 vs = vec_perm(vs, v0, vsrcPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1106
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1107 valpha = vec_perm(vs, v0, valphaPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1108
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1109 /* d = *dstp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1110 vd = (vector unsigned char)vec_ld(0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1111 vd = vec_perm(vd, v0, vsdstPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1112 vdstalpha = vec_and(vd, valphamask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1113
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1114 VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1115
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1116 /* set the alpha to the dest alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1117 vd = vec_and(vd, vpixelmask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1118 vd = vec_or(vd, vdstalpha);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1119 vd = vec_perm(vd, v0, vdstPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1120
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1121 /* *dstp = res */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1122 vec_st((vector unsigned int)vd, 0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1123
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1124 srcp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1125 dstp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1126 width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1127 vs = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1128
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1129 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1130 ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1131 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1132 srcp += srcskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1133 dstp += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1134 #undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1135 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1136 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1137
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1138 /* fast ARGB888->(A)RGB888 blending with pixel alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1139 static void BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1140 {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1141 int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1142 int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1143 Uint32 *srcp = (Uint32 *)info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1144 int srcskip = info->s_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1145 Uint32 *dstp = (Uint32 *)info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1146 int dstskip = info->d_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1147 vector unsigned char mergePermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1148 vector unsigned char valphaPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1149 vector unsigned char valphamask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1150 vector unsigned char vpixelmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1151 vector unsigned char v0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1152 vector unsigned short v1;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1153 vector unsigned short v8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1154 v0 = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1155 v1 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1156 v8 = vec_splat_u16(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1157 mergePermute = VEC_MERGE_PERMUTE();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1158 valphamask = VEC_ALPHA_MASK();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1159 valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1160
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1161
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1162 vpixelmask = vec_nor(valphamask, v0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1163 while(height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1164 width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1165 #define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1166 while ((condition)) { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1167 Uint32 dalpha; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1168 Uint32 d; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1169 Uint32 s1; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1170 Uint32 d1; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1171 Uint32 s = *srcp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1172 Uint32 alpha = s >> 24; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1173 if(alpha) { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1174 if(alpha == SDL_ALPHA_OPAQUE) { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1175 *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1176 } else { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1177 d = *dstp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1178 dalpha = d & 0xff000000; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1179 s1 = s & 0xff00ff; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1180 d1 = d & 0xff00ff; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1181 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1182 s &= 0xff00; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1183 d &= 0xff00; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1184 d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1185 *dstp = d1 | d | dalpha; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1186 } \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1187 } \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1188 ++srcp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1189 ++dstp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1190 widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1191 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1192 ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1193 if (width > 0) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1194 int extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1195 vector unsigned char valigner = VEC_ALIGNER(srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1196 vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1197 width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1198 while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1199 vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1200 vector unsigned char vd;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1201 vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1202 vector unsigned char vdstalpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1203 /* s = *srcp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1204 voverflow = (vector unsigned char)vec_ld(15, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1205 vs = vec_perm(vs, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1206
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1207 valpha = vec_perm(vs, v0, valphaPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1208
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1209 /* d = *dstp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1210 vd = (vector unsigned char)vec_ld(0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1211 vdstalpha = vec_and(vd, valphamask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1212
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1213 VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1214
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1215 /* set the alpha to the dest alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1216 vd = vec_and(vd, vpixelmask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1217 vd = vec_or(vd, vdstalpha);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1218
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1219 /* *dstp = res */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1220 vec_st((vector unsigned int)vd, 0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1221
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1222 srcp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1223 dstp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1224 width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1225 vs = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1226 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1227 ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1228 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1229 srcp += srcskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1230 dstp += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1231 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1232 #undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1233 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1234
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1235 static void Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1236 {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1237 /* XXX : 6 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1238 unsigned alpha = info->src->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1239 int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1240 Uint32 *srcp = (Uint32 *)info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1241 int srcskip = info->s_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1242 Uint32 *dstp = (Uint32 *)info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1243 int dstskip = info->d_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1244 SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1245 SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1246 unsigned sA = srcfmt->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1247 unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1248 vector unsigned char mergePermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1249 vector unsigned char vsrcPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1250 vector unsigned char vdstPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1251 vector unsigned char vsdstPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1252 vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1253 vector unsigned char valphamask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1254 vector unsigned char vbits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1255 vector unsigned short v1;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1256 vector unsigned short v8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1257
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1258 mergePermute = VEC_MERGE_PERMUTE();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1259 v1 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1260 v8 = vec_splat_u16(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1261
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1262 /* set the alpha to 255 on the destination surf */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1263 valphamask = VEC_ALPHA_MASK();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1264
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1265 vsrcPermute = calc_swizzle32(srcfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1266 vdstPermute = calc_swizzle32(NULL, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1267 vsdstPermute = calc_swizzle32(dstfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1268
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1269 /* set a vector full of alpha and 255-alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1270 ((unsigned char *)&valpha)[0] = alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1271 valpha = vec_splat(valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1272 vbits = (vector unsigned char)vec_splat_s8(-1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1273
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1274 while(height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1275 int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1276 #define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
1277 Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1278 unsigned sR, sG, sB, dR, dG, dB; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
1279 DISEMBLE_RGB(((Uint8 *)srcp), 4, srcfmt, Pixel, sR, sG, sB); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
1280 DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1281 ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1282 ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1283 ++srcp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1284 ++dstp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1285 widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1286 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1287 ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1288 if (width > 0) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1289 int extrawidth = (width % 4);
3910
af4d584e0edb Handle source data alignment correctly in Blit32to32SurfaceAlphaAltivec().
Ryan C. Gordon <icculus@icculus.org>
parents: 3899
diff changeset
1290 vector unsigned char valigner = VEC_ALIGNER(srcp);
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1291 vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1292 width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1293 while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1294 vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1295 vector unsigned char vd;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1296
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1297 /* s = *srcp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1298 voverflow = (vector unsigned char)vec_ld(15, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1299 vs = vec_perm(vs, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1300 vs = vec_perm(vs, valpha, vsrcPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1301
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1302 /* d = *dstp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1303 vd = (vector unsigned char)vec_ld(0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1304 vd = vec_perm(vd, vd, vsdstPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1305
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1306 VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1307
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1308 /* set the alpha channel to full on */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1309 vd = vec_or(vd, valphamask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1310 vd = vec_perm(vd, vbits, vdstPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1311
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1312 /* *dstp = res */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1313 vec_st((vector unsigned int)vd, 0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1314
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1315 srcp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1316 dstp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1317 width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1318 vs = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1319 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1320 ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1321 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1322 #undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1323
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1324 srcp += srcskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1325 dstp += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1326 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1327
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1328 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1329
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1330
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1331 /* fast RGB888->(A)RGB888 blending */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1332 static void BlitRGBtoRGBSurfaceAlphaAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1333 {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1334 unsigned alpha = info->src->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1335 int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1336 Uint32 *srcp = (Uint32 *)info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1337 int srcskip = info->s_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1338 Uint32 *dstp = (Uint32 *)info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1339 int dstskip = info->d_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1340 vector unsigned char mergePermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1341 vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1342 vector unsigned char valphamask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1343 vector unsigned short v1;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1344 vector unsigned short v8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1345
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1346 mergePermute = VEC_MERGE_PERMUTE();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1347 v1 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1348 v8 = vec_splat_u16(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1349
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1350 /* set the alpha to 255 on the destination surf */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1351 valphamask = VEC_ALPHA_MASK();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1352
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1353 /* set a vector full of alpha and 255-alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1354 ((unsigned char *)&valpha)[0] = alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1355 valpha = vec_splat(valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1356
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1357 while(height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1358 int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1359 #define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1360 Uint32 s = *srcp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1361 Uint32 d = *dstp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1362 Uint32 s1 = s & 0xff00ff; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1363 Uint32 d1 = d & 0xff00ff; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1364 d1 = (d1 + ((s1 - d1) * alpha >> 8)) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1365 & 0xff00ff; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1366 s &= 0xff00; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1367 d &= 0xff00; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1368 d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1369 *dstp = d1 | d | 0xff000000; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1370 ++srcp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1371 ++dstp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1372 widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1373 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1374 ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1375 if (width > 0) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1376 int extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1377 vector unsigned char valigner = VEC_ALIGNER(srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1378 vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1379 width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1380 while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1381 vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1382 vector unsigned char vd;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1383
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1384 /* s = *srcp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1385 voverflow = (vector unsigned char)vec_ld(15, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1386 vs = vec_perm(vs, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1387
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1388 /* d = *dstp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1389 vd = (vector unsigned char)vec_ld(0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1390
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1391 VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1392
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1393 /* set the alpha channel to full on */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1394 vd = vec_or(vd, valphamask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1395
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1396 /* *dstp = res */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1397 vec_st((vector unsigned int)vd, 0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1398
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1399 srcp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1400 dstp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1401 width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1402 vs = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1403 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1404 ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1405 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1406 #undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1407
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1408 srcp += srcskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1409 dstp += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1410 }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1411 }
1795
398ac0f88e4d Fixed bug #220
Sam Lantinga <slouken@libsdl.org>
parents: 1617
diff changeset
1412 #if __MWERKS__
398ac0f88e4d Fixed bug #220
Sam Lantinga <slouken@libsdl.org>
parents: 1617
diff changeset
1413 #pragma altivec_model off
398ac0f88e4d Fixed bug #220
Sam Lantinga <slouken@libsdl.org>
parents: 1617
diff changeset
1414 #endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
1415 #endif /* SDL_ALTIVEC_BLITTERS */
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
1416
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1417 /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1418 static void BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo *info)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1419 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1420 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1421 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1422 Uint32 *srcp = (Uint32 *)info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1423 int srcskip = info->s_skip >> 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1424 Uint32 *dstp = (Uint32 *)info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1425 int dstskip = info->d_skip >> 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1426
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1427 while(height--) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1428 DUFFS_LOOP4({
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1429 Uint32 s = *srcp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1430 Uint32 d = *dstp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1431 *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1432 + (s & d & 0x00010101)) | 0xff000000;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1433 }, width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1434 srcp += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1435 dstp += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1436 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1437 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1438
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1439 /* fast RGB888->(A)RGB888 blending with surface alpha */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1440 static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo *info)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1441 {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1442 unsigned alpha = info->src->alpha;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1443 if(alpha == 128) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1444 BlitRGBtoRGBSurfaceAlpha128(info);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1445 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1446 int width = info->d_width;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1447 int height = info->d_height;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1448 Uint32 *srcp = (Uint32 *)info->s_pixels;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1449 int srcskip = info->s_skip >> 2;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1450 Uint32 *dstp = (Uint32 *)info->d_pixels;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1451 int dstskip = info->d_skip >> 2;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1452 Uint32 s;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1453 Uint32 d;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1454 Uint32 s1;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1455 Uint32 d1;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1456
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1457 while(height--) {
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1458 DUFFS_LOOP_DOUBLE2({
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1459 /* One Pixel Blend */
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1460 s = *srcp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1461 d = *dstp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1462 s1 = s & 0xff00ff;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1463 d1 = d & 0xff00ff;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1464 d1 = (d1 + ((s1 - d1) * alpha >> 8))
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1465 & 0xff00ff;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1466 s &= 0xff00;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1467 d &= 0xff00;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1468 d = (d + ((s - d) * alpha >> 8)) & 0xff00;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1469 *dstp = d1 | d | 0xff000000;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1470 ++srcp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1471 ++dstp;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1472 },{
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1473 /* Two Pixels Blend */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1474 s = *srcp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1475 d = *dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1476 s1 = s & 0xff00ff;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1477 d1 = d & 0xff00ff;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1478 d1 += (s1 - d1) * alpha >> 8;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1479 d1 &= 0xff00ff;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1480
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1481 s = ((s & 0xff00) >> 8) |
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1482 ((srcp[1] & 0xff00) << 8);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1483 d = ((d & 0xff00) >> 8) |
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1484 ((dstp[1] & 0xff00) << 8);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1485 d += (s - d) * alpha >> 8;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1486 d &= 0x00ff00ff;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1487
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1488 *dstp++ = d1 | ((d << 8) & 0xff00) | 0xff000000;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1489 ++srcp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1490
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1491 s1 = *srcp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1492 d1 = *dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1493 s1 &= 0xff00ff;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1494 d1 &= 0xff00ff;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1495 d1 += (s1 - d1) * alpha >> 8;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1496 d1 &= 0xff00ff;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1497
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1498 *dstp = d1 | ((d >> 8) & 0xff00) | 0xff000000;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1499 ++srcp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1500 ++dstp;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1501 }, width);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1502 srcp += srcskip;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1503 dstp += dstskip;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1504 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1505 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1506 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1507
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1508 /* fast ARGB888->(A)RGB888 blending with pixel alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1509 static void BlitRGBtoRGBPixelAlpha(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1510 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1511 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1512 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1513 Uint32 *srcp = (Uint32 *)info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1514 int srcskip = info->s_skip >> 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1515 Uint32 *dstp = (Uint32 *)info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1516 int dstskip = info->d_skip >> 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1517
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1518 while(height--) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1519 DUFFS_LOOP4({
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1520 Uint32 dalpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1521 Uint32 d;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1522 Uint32 s1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1523 Uint32 d1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1524 Uint32 s = *srcp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1525 Uint32 alpha = s >> 24;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1526 /* FIXME: Here we special-case opaque alpha since the
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1527 compositioning used (>>8 instead of /255) doesn't handle
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1528 it correctly. Also special-case alpha=0 for speed?
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1529 Benchmark this! */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1530 if(alpha) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1531 if(alpha == SDL_ALPHA_OPAQUE) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1532 *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000);
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1533 } else {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1534 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1535 * take out the middle component (green), and process
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1536 * the other two in parallel. One multiply less.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1537 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1538 d = *dstp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1539 dalpha = d & 0xff000000;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1540 s1 = s & 0xff00ff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1541 d1 = d & 0xff00ff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1542 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1543 s &= 0xff00;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1544 d &= 0xff00;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1545 d = (d + ((s - d) * alpha >> 8)) & 0xff00;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1546 *dstp = d1 | d | dalpha;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1547 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1548 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1549 ++srcp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1550 ++dstp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1551 }, width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1552 srcp += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1553 dstp += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1554 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1555 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1556
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1557 #if GCC_ASMBLIT
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1558 /* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */
3870
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
1559 static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info)
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1560 {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1561 int width = info->d_width;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1562 int height = info->d_height;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1563 Uint32 *srcp = (Uint32 *)info->s_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1564 int srcskip = info->s_skip >> 2;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1565 Uint32 *dstp = (Uint32 *)info->d_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1566 int dstskip = info->d_skip >> 2;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1567 SDL_PixelFormat* sf = info->src;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1568 Uint32 amask = sf->Amask;
3899
081aecdb0911 From: Gabriel Gambetta
Ryan C. Gordon <icculus@icculus.org>
parents: 3870
diff changeset
1569 Uint32 ashift = sf->Ashift;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1570
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1571 __asm__ (
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1572 /* make mm6 all zeros. */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1573 "pxor %%mm6, %%mm6\n"
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1574
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1575 /* Make a mask to preserve the alpha. */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1576 "movd %0, %%mm7\n\t" /* 0000F000 -> mm7 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1577 "punpcklbw %%mm7, %%mm7\n\t" /* FF000000 -> mm7 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1578 "pcmpeqb %%mm4, %%mm4\n\t" /* FFFFFFFF -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1579 "movq %%mm4, %%mm3\n\t" /* FFFFFFFF -> mm3 (for later) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1580 "pxor %%mm4, %%mm7\n\t" /* 00FFFFFF -> mm7 (mult mask) */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1581
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1582 /* form channel masks */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1583 "movq %%mm7, %%mm4\n\t" /* 00FFFFFF -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1584 "packsswb %%mm6, %%mm4\n\t" /* 00000FFF -> mm4 (channel mask) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1585 "packsswb %%mm6, %%mm3\n\t" /* 0000FFFF -> mm3 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1586 "pxor %%mm4, %%mm3\n\t" /* 0000F000 -> mm3 (~channel mask) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1587
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1588 /* get alpha channel shift */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1589 "movd %1, %%mm5\n\t" /* Ashift -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1590
3899
081aecdb0911 From: Gabriel Gambetta
Ryan C. Gordon <icculus@icculus.org>
parents: 3870
diff changeset
1591 : /* nothing */ : "m" (amask), "m" (ashift) );
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1592
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1593 while(height--) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1594
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1595 DUFFS_LOOP4({
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1596 Uint32 alpha;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1597
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1598 __asm__ (
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1599 "prefetch 64(%0)\n"
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1600 "prefetch 64(%1)\n"
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1601 : : "r" (srcp), "r" (dstp) );
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1602
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1603 alpha = *srcp & amask;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1604 /* FIXME: Here we special-case opaque alpha since the
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1605 compositioning used (>>8 instead of /255) doesn't handle
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1606 it correctly. Also special-case alpha=0 for speed?
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1607 Benchmark this! */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1608 if(alpha == 0) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1609 /* do nothing */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1610 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1611 else if(alpha == amask) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1612 /* opaque alpha -- copy RGB, keep dst alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1613 /* using MMX here to free up regular registers for other things */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1614 __asm__ (
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1615 "movd (%0), %%mm0\n\t" /* src(ARGB) -> mm0 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1616 "movd (%1), %%mm1\n\t" /* dst(ARGB) -> mm1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1617 "pand %%mm4, %%mm0\n\t" /* src & chanmask -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1618 "pand %%mm3, %%mm1\n\t" /* dst & ~chanmask -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1619 "por %%mm0, %%mm1\n\t" /* src | dst -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1620 "movd %%mm1, (%1) \n\t" /* mm1 -> dst */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1621
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1622 : : "r" (srcp), "r" (dstp) );
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1623 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1624
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1625 else {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1626 __asm__ (
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1627 /* load in the source, and dst. */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1628 "movd (%0), %%mm0\n" /* mm0(s) = 0 0 0 0 | As Rs Gs Bs */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1629 "movd (%1), %%mm1\n" /* mm1(d) = 0 0 0 0 | Ad Rd Gd Bd */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1630
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1631 /* Move the src alpha into mm2 */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1632
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1633 /* if supporting pshufw */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1634 /*"pshufw $0x55, %%mm0, %%mm2\n" */ /* mm2 = 0 As 0 As | 0 As 0 As */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1635 /*"psrlw $8, %%mm2\n" */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1636
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1637 /* else: */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1638 "movd %2, %%mm2\n"
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1639 "psrld %%mm5, %%mm2\n" /* mm2 = 0 0 0 0 | 0 0 0 As */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1640 "punpcklwd %%mm2, %%mm2\n" /* mm2 = 0 0 0 0 | 0 As 0 As */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1641 "punpckldq %%mm2, %%mm2\n" /* mm2 = 0 As 0 As | 0 As 0 As */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1642 "pand %%mm7, %%mm2\n" /* to preserve dest alpha */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1643
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1644 /* move the colors into words. */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1645 "punpcklbw %%mm6, %%mm0\n" /* mm0 = 0 As 0 Rs | 0 Gs 0 Bs */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1646 "punpcklbw %%mm6, %%mm1\n" /* mm0 = 0 Ad 0 Rd | 0 Gd 0 Bd */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1647
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1648 /* src - dst */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1649 "psubw %%mm1, %%mm0\n" /* mm0 = As-Ad Rs-Rd | Gs-Gd Bs-Bd */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1650
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1651 /* A * (src-dst) */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1652 "pmullw %%mm2, %%mm0\n" /* mm0 = 0*As-d As*Rs-d | As*Gs-d As*Bs-d */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1653 "psrlw $8, %%mm0\n" /* mm0 = 0>>8 Rc>>8 | Gc>>8 Bc>>8 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1654 "paddb %%mm1, %%mm0\n" /* mm0 = 0+Ad Rc+Rd | Gc+Gd Bc+Bd */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1655
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1656 "packuswb %%mm0, %%mm0\n" /* mm0 = | Ac Rc Gc Bc */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1657
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1658 "movd %%mm0, (%1)\n" /* result in mm0 */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1659
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1660 : : "r" (srcp), "r" (dstp), "r" (alpha) );
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1661
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1662 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1663 ++srcp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1664 ++dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1665 }, width);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1666 srcp += srcskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1667 dstp += dstskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1668 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1669
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1670 __asm__ (
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1671 "emms\n"
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1672 : );
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1673 }
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1674 /* End GCC_ASMBLIT*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1675
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1676 #elif MSVC_ASMBLIT
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1677 /* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1678 static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1679 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1680 int width = info->d_width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1681 int height = info->d_height;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1682 Uint32 *srcp = (Uint32 *)info->s_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1683 int srcskip = info->s_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1684 Uint32 *dstp = (Uint32 *)info->d_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1685 int dstskip = info->d_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1686 SDL_PixelFormat* sf = info->src;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1687 Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1688 Uint32 amask = sf->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1689 Uint32 ashift = sf->Ashift;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1690 Uint64 multmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1691
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1692 __m64 src1, dst1, mm_alpha, mm_zero, dmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1693
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1694 mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1695 multmask = ~(0xFFFFi64 << (ashift * 2));
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1696 dmask = *(__m64*) &multmask; /* dst alpha mask -> dmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1697
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1698 while(height--) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1699 DUFFS_LOOP4({
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1700 Uint32 alpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1701
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1702 _m_prefetch(srcp + 16);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1703 _m_prefetch(dstp + 16);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1704
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1705 alpha = *srcp & amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1706 if (alpha == 0) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1707 /* do nothing */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1708 } else if (alpha == amask) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1709 /* copy RGB, keep dst alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1710 *dstp = (*srcp & chanmask) | (*dstp & ~chanmask);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1711 } else {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1712 src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1713 src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1714
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1715 dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1716 dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1717
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1718 mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1719 mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1720 mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1721 mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1722 mm_alpha = _mm_and_si64(mm_alpha, dmask); /* 000A0A0A -> mm_alpha, preserve dst alpha on add */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1723
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1724 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1725 src1 = _mm_sub_pi16(src1, dst1);/* src - dst -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1726 src1 = _mm_mullo_pi16(src1, mm_alpha); /* (src - dst) * alpha -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1727 src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1(000R0G0B) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1728 dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst) -> dst1(0A0R0G0B) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1729 dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1730
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1731 *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1732 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1733 ++srcp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1734 ++dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1735 }, width);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1736 srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1737 dstp += dstskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1738 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1739 _mm_empty();
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1740 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1741 /* End MSVC_ASMBLIT */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1742
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1743 #endif /* GCC_ASMBLIT, MSVC_ASMBLIT */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1744
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1745 /* 16bpp special case for per-surface alpha=50%: blend 2 pixels in parallel */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1746
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1747 /* blend a single 16 bit pixel at 50% */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1748 #define BLEND16_50(d, s, mask) \
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1749 ((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff)))
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1750
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1751 /* blend two 16 bit pixels at 50% */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1752 #define BLEND2x16_50(d, s, mask) \
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1753 (((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1754 + (s & d & (~(mask | mask << 16))))
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1755
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1756 static void Blit16to16SurfaceAlpha128(SDL_BlitInfo *info, Uint16 mask)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1757 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1758 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1759 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1760 Uint16 *srcp = (Uint16 *)info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1761 int srcskip = info->s_skip >> 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1762 Uint16 *dstp = (Uint16 *)info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1763 int dstskip = info->d_skip >> 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1764
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1765 while(height--) {
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1443
diff changeset
1766 if(((uintptr_t)srcp ^ (uintptr_t)dstp) & 2) {
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1767 /*
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1768 * Source and destination not aligned, pipeline it.
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1769 * This is mostly a win for big blits but no loss for
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1770 * small ones
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1771 */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1772 Uint32 prev_sw;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1773 int w = width;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1774
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1775 /* handle odd destination */
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1443
diff changeset
1776 if((uintptr_t)dstp & 2) {
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1777 Uint16 d = *dstp, s = *srcp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1778 *dstp = BLEND16_50(d, s, mask);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1779 dstp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1780 srcp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1781 w--;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1782 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1783 srcp++; /* srcp is now 32-bit aligned */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1784
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1785 /* bootstrap pipeline with first halfword */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1786 prev_sw = ((Uint32 *)srcp)[-1];
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1787
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1788 while(w > 1) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1789 Uint32 sw, dw, s;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1790 sw = *(Uint32 *)srcp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1791 dw = *(Uint32 *)dstp;
1443
9ebbbb4ae53b Fixed some OpenWatcom warnings
Sam Lantinga <slouken@libsdl.org>
parents: 1428
diff changeset
1792 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
9ebbbb4ae53b Fixed some OpenWatcom warnings
Sam Lantinga <slouken@libsdl.org>
parents: 1428
diff changeset
1793 s = (prev_sw << 16) + (sw >> 16);
9ebbbb4ae53b Fixed some OpenWatcom warnings
Sam Lantinga <slouken@libsdl.org>
parents: 1428
diff changeset
1794 #else
9ebbbb4ae53b Fixed some OpenWatcom warnings
Sam Lantinga <slouken@libsdl.org>
parents: 1428
diff changeset
1795 s = (prev_sw >> 16) + (sw << 16);
9ebbbb4ae53b Fixed some OpenWatcom warnings
Sam Lantinga <slouken@libsdl.org>
parents: 1428
diff changeset
1796 #endif
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1797 prev_sw = sw;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1798 *(Uint32 *)dstp = BLEND2x16_50(dw, s, mask);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1799 dstp += 2;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1800 srcp += 2;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1801 w -= 2;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1802 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1803
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1804 /* final pixel if any */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1805 if(w) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1806 Uint16 d = *dstp, s;
1443
9ebbbb4ae53b Fixed some OpenWatcom warnings
Sam Lantinga <slouken@libsdl.org>
parents: 1428
diff changeset
1807 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
9ebbbb4ae53b Fixed some OpenWatcom warnings
Sam Lantinga <slouken@libsdl.org>
parents: 1428
diff changeset
1808 s = (Uint16)prev_sw;
9ebbbb4ae53b Fixed some OpenWatcom warnings
Sam Lantinga <slouken@libsdl.org>
parents: 1428
diff changeset
1809 #else
9ebbbb4ae53b Fixed some OpenWatcom warnings
Sam Lantinga <slouken@libsdl.org>
parents: 1428
diff changeset
1810 s = (Uint16)(prev_sw >> 16);
9ebbbb4ae53b Fixed some OpenWatcom warnings
Sam Lantinga <slouken@libsdl.org>
parents: 1428
diff changeset
1811 #endif
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1812 *dstp = BLEND16_50(d, s, mask);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1813 srcp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1814 dstp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1815 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1816 srcp += srcskip - 1;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1817 dstp += dstskip;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1818 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1819 /* source and destination are aligned */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1820 int w = width;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1821
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1822 /* first odd pixel? */
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1443
diff changeset
1823 if((uintptr_t)srcp & 2) {
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1824 Uint16 d = *dstp, s = *srcp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1825 *dstp = BLEND16_50(d, s, mask);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1826 srcp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1827 dstp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1828 w--;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1829 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1830 /* srcp and dstp are now 32-bit aligned */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1831
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1832 while(w > 1) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1833 Uint32 sw = *(Uint32 *)srcp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1834 Uint32 dw = *(Uint32 *)dstp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1835 *(Uint32 *)dstp = BLEND2x16_50(dw, sw, mask);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1836 srcp += 2;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1837 dstp += 2;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1838 w -= 2;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1839 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1840
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1841 /* last odd pixel? */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1842 if(w) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1843 Uint16 d = *dstp, s = *srcp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1844 *dstp = BLEND16_50(d, s, mask);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1845 srcp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1846 dstp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1847 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1848 srcp += srcskip;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1849 dstp += dstskip;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1850 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1851 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1852 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
1853
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1854 #if GCC_ASMBLIT
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1855 /* fast RGB565->RGB565 blending with surface alpha */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1856 static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo *info)
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1857 {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1858 unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1859 if(alpha == 128) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1860 Blit16to16SurfaceAlpha128(info, 0xf7de);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1861 } else {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1862 int width = info->d_width;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1863 int height = info->d_height;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1864 Uint16 *srcp = (Uint16 *)info->s_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1865 int srcskip = info->s_skip >> 1;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1866 Uint16 *dstp = (Uint16 *)info->d_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1867 int dstskip = info->d_skip >> 1;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1868 Uint32 s, d;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1869 Uint8 load[8];
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1870
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1871 alpha &= ~(1+2+4); /* cut alpha to get the exact same behaviour */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1872 *(Uint64 *)load = alpha;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1873 alpha >>= 3; /* downscale alpha to 5 bits */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1874
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1875 movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1876 punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1877 punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1878 /* position alpha to allow for mullo and mulhi on diff channels
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1879 to reduce the number of operations */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1880 psllq_i2r(3, mm0);
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1881
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1882 /* Setup the 565 color channel masks */
720
f90d80d68071 N Sep 17 8791 Sam Lantinga Re: tks source released
Sam Lantinga <slouken@libsdl.org>
parents: 689
diff changeset
1883 *(Uint64 *)load = 0x07E007E007E007E0ULL;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1884 movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */
720
f90d80d68071 N Sep 17 8791 Sam Lantinga Re: tks source released
Sam Lantinga <slouken@libsdl.org>
parents: 689
diff changeset
1885 *(Uint64 *)load = 0x001F001F001F001FULL;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1886 movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1887 while(height--) {
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1888 DUFFS_LOOP_QUATRO2(
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1889 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1890 s = *srcp++;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1891 d = *dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1892 /*
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1893 * shift out the middle component (green) to
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1894 * the high 16 bits, and process all three RGB
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1895 * components at the same time.
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1896 */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1897 s = (s | s << 16) & 0x07e0f81f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1898 d = (d | d << 16) & 0x07e0f81f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1899 d += (s - d) * alpha >> 5;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1900 d &= 0x07e0f81f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1901 *dstp++ = d | d >> 16;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1902 },{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1903 s = *srcp++;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1904 d = *dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1905 /*
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1906 * shift out the middle component (green) to
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1907 * the high 16 bits, and process all three RGB
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1908 * components at the same time.
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1909 */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1910 s = (s | s << 16) & 0x07e0f81f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1911 d = (d | d << 16) & 0x07e0f81f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1912 d += (s - d) * alpha >> 5;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1913 d &= 0x07e0f81f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1914 *dstp++ = d | d >> 16;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1915 s = *srcp++;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1916 d = *dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1917 /*
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1918 * shift out the middle component (green) to
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1919 * the high 16 bits, and process all three RGB
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1920 * components at the same time.
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1921 */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1922 s = (s | s << 16) & 0x07e0f81f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1923 d = (d | d << 16) & 0x07e0f81f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1924 d += (s - d) * alpha >> 5;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1925 d &= 0x07e0f81f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1926 *dstp++ = d | d >> 16;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1927 },{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1928 movq_m2r((*srcp), mm2);/* 4 src pixels -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1929 movq_m2r((*dstp), mm3);/* 4 dst pixels -> mm3 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1930
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1931 /* red -- does not need a mask since the right shift clears
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1932 the uninteresting bits */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1933 movq_r2r(mm2, mm5); /* src -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1934 movq_r2r(mm3, mm6); /* dst -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1935 psrlw_i2r(11, mm5); /* mm5 >> 11 -> mm5 [000r 000r 000r 000r] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1936 psrlw_i2r(11, mm6); /* mm6 >> 11 -> mm6 [000r 000r 000r 000r] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1937
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1938 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1939 psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1940 pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1941 /* alpha used is actually 11 bits
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1942 11 + 5 = 16 bits, so the sign bits are lost */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1943 psrlw_i2r(11, mm5); /* mm5 >> 11 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1944 paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1945 psllw_i2r(11, mm6); /* mm6 << 11 -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1946
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1947 movq_r2r(mm6, mm1); /* save new reds in dsts */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1948
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1949 /* green -- process the bits in place */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1950 movq_r2r(mm2, mm5); /* src -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1951 movq_r2r(mm3, mm6); /* dst -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1952 pand_r2r(mm4, mm5); /* src & MASKGREEN -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1953 pand_r2r(mm4, mm6); /* dst & MASKGREEN -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1954
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1955 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1956 psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1957 pmulhw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1958 /* 11 + 11 - 16 = 6 bits, so all the lower uninteresting
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1959 bits are gone and the sign bits present */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1960 psllw_i2r(5, mm5); /* mm5 << 5 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1961 paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1962
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1963 por_r2r(mm6, mm1); /* save new greens in dsts */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1964
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1965 /* blue */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1966 movq_r2r(mm2, mm5); /* src -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1967 movq_r2r(mm3, mm6); /* dst -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1968 pand_r2r(mm7, mm5); /* src & MASKBLUE -> mm5[000b 000b 000b 000b] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1969 pand_r2r(mm7, mm6); /* dst & MASKBLUE -> mm6[000b 000b 000b 000b] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1970
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1971 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1972 psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1973 pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1974 /* 11 + 5 = 16 bits, so the sign bits are lost and
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1975 the interesting bits will need to be MASKed */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1976 psrlw_i2r(11, mm5); /* mm5 >> 11 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1977 paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1978 pand_r2r(mm7, mm6); /* mm6 & MASKBLUE -> mm6[000b 000b 000b 000b] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1979
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1980 por_r2r(mm6, mm1); /* save new blues in dsts */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1981
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1982 movq_r2m(mm1, *dstp); /* mm1 -> 4 dst pixels */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1983
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1984 srcp += 4;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1985 dstp += 4;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
1986 }, width);
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1987 srcp += srcskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1988 dstp += dstskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1989 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1990 emms();
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1991 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1992 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1993
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1994 /* fast RGB555->RGB555 blending with surface alpha */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1995 static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo *info)
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1996 {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1997 unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1998 if(alpha == 128) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1999 Blit16to16SurfaceAlpha128(info, 0xfbde);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2000 } else {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2001 int width = info->d_width;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2002 int height = info->d_height;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2003 Uint16 *srcp = (Uint16 *)info->s_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2004 int srcskip = info->s_skip >> 1;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2005 Uint16 *dstp = (Uint16 *)info->d_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2006 int dstskip = info->d_skip >> 1;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2007 Uint32 s, d;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2008 Uint8 load[8];
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2009
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2010 alpha &= ~(1+2+4); /* cut alpha to get the exact same behaviour */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2011 *(Uint64 *)load = alpha;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2012 alpha >>= 3; /* downscale alpha to 5 bits */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2013
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2014 movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2015 punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2016 punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2017 /* position alpha to allow for mullo and mulhi on diff channels
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2018 to reduce the number of operations */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2019 psllq_i2r(3, mm0);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2020
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2021 /* Setup the 555 color channel masks */
720
f90d80d68071 N Sep 17 8791 Sam Lantinga Re: tks source released
Sam Lantinga <slouken@libsdl.org>
parents: 689
diff changeset
2022 *(Uint64 *)load = 0x03E003E003E003E0ULL;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2023 movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */
720
f90d80d68071 N Sep 17 8791 Sam Lantinga Re: tks source released
Sam Lantinga <slouken@libsdl.org>
parents: 689
diff changeset
2024 *(Uint64 *)load = 0x001F001F001F001FULL;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2025 movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2026 while(height--) {
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2027 DUFFS_LOOP_QUATRO2(
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2028 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2029 s = *srcp++;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2030 d = *dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2031 /*
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2032 * shift out the middle component (green) to
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2033 * the high 16 bits, and process all three RGB
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2034 * components at the same time.
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2035 */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2036 s = (s | s << 16) & 0x03e07c1f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2037 d = (d | d << 16) & 0x03e07c1f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2038 d += (s - d) * alpha >> 5;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2039 d &= 0x03e07c1f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2040 *dstp++ = d | d >> 16;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2041 },{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2042 s = *srcp++;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2043 d = *dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2044 /*
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2045 * shift out the middle component (green) to
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2046 * the high 16 bits, and process all three RGB
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2047 * components at the same time.
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2048 */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2049 s = (s | s << 16) & 0x03e07c1f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2050 d = (d | d << 16) & 0x03e07c1f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2051 d += (s - d) * alpha >> 5;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2052 d &= 0x03e07c1f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2053 *dstp++ = d | d >> 16;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2054 s = *srcp++;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2055 d = *dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2056 /*
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2057 * shift out the middle component (green) to
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2058 * the high 16 bits, and process all three RGB
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2059 * components at the same time.
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2060 */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2061 s = (s | s << 16) & 0x03e07c1f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2062 d = (d | d << 16) & 0x03e07c1f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2063 d += (s - d) * alpha >> 5;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2064 d &= 0x03e07c1f;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2065 *dstp++ = d | d >> 16;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2066 },{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2067 movq_m2r((*srcp), mm2);/* 4 src pixels -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2068 movq_m2r((*dstp), mm3);/* 4 dst pixels -> mm3 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2069
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2070 /* red -- process the bits in place */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2071 psllq_i2r(5, mm4); /* turn MASKGREEN into MASKRED */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2072 /* by reusing the GREEN mask we free up another mmx
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2073 register to accumulate the result */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2074
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2075 movq_r2r(mm2, mm5); /* src -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2076 movq_r2r(mm3, mm6); /* dst -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2077 pand_r2r(mm4, mm5); /* src & MASKRED -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2078 pand_r2r(mm4, mm6); /* dst & MASKRED -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2079
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2080 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2081 psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2082 pmulhw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2083 /* 11 + 15 - 16 = 10 bits, uninteresting bits will be
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2084 cleared by a MASK below */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2085 psllw_i2r(5, mm5); /* mm5 << 5 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2086 paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2087 pand_r2r(mm4, mm6); /* mm6 & MASKRED -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2088
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2089 psrlq_i2r(5, mm4); /* turn MASKRED back into MASKGREEN */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2090
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2091 movq_r2r(mm6, mm1); /* save new reds in dsts */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2092
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2093 /* green -- process the bits in place */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2094 movq_r2r(mm2, mm5); /* src -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2095 movq_r2r(mm3, mm6); /* dst -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2096 pand_r2r(mm4, mm5); /* src & MASKGREEN -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2097 pand_r2r(mm4, mm6); /* dst & MASKGREEN -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2098
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2099 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2100 psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2101 pmulhw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2102 /* 11 + 10 - 16 = 5 bits, so all the lower uninteresting
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2103 bits are gone and the sign bits present */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2104 psllw_i2r(5, mm5); /* mm5 << 5 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2105 paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2106
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2107 por_r2r(mm6, mm1); /* save new greens in dsts */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2108
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2109 /* blue */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2110 movq_r2r(mm2, mm5); /* src -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2111 movq_r2r(mm3, mm6); /* dst -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2112 pand_r2r(mm7, mm5); /* src & MASKBLUE -> mm5[000b 000b 000b 000b] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2113 pand_r2r(mm7, mm6); /* dst & MASKBLUE -> mm6[000b 000b 000b 000b] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2114
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2115 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2116 psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2117 pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2118 /* 11 + 5 = 16 bits, so the sign bits are lost and
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2119 the interesting bits will need to be MASKed */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2120 psrlw_i2r(11, mm5); /* mm5 >> 11 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2121 paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2122 pand_r2r(mm7, mm6); /* mm6 & MASKBLUE -> mm6[000b 000b 000b 000b] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2123
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2124 por_r2r(mm6, mm1); /* save new blues in dsts */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2125
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2126 movq_r2m(mm1, *dstp);/* mm1 -> 4 dst pixels */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2127
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2128 srcp += 4;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2129 dstp += 4;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2130 }, width);
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2131 srcp += srcskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2132 dstp += dstskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2133 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2134 emms();
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2135 }
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2136 }
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2137 /* End GCC_ASMBLIT */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2138
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2139 #elif MSVC_ASMBLIT
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2140 /* fast RGB565->RGB565 blending with surface alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2141 static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo *info)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2142 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2143 unsigned alpha = info->src->alpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2144 if(alpha == 128) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2145 Blit16to16SurfaceAlpha128(info, 0xf7de);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2146 } else {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2147 int width = info->d_width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2148 int height = info->d_height;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2149 Uint16 *srcp = (Uint16 *)info->s_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2150 int srcskip = info->s_skip >> 1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2151 Uint16 *dstp = (Uint16 *)info->d_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2152 int dstskip = info->d_skip >> 1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2153 Uint32 s, d;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2154
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2155 __m64 src1, dst1, src2, dst2, gmask, bmask, mm_res, mm_alpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2156
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2157 alpha &= ~(1+2+4); /* cut alpha to get the exact same behaviour */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2158 mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2159 alpha >>= 3; /* downscale alpha to 5 bits */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2160
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2161 mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2162 mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2163 /* position alpha to allow for mullo and mulhi on diff channels
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2164 to reduce the number of operations */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2165 mm_alpha = _mm_slli_si64(mm_alpha, 3);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2166
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2167 /* Setup the 565 color channel masks */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2168 gmask = _mm_set_pi32(0x07E007E0, 0x07E007E0); /* MASKGREEN -> gmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2169 bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2170
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2171 while(height--) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2172 DUFFS_LOOP_QUATRO2(
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2173 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2174 s = *srcp++;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2175 d = *dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2176 /*
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2177 * shift out the middle component (green) to
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2178 * the high 16 bits, and process all three RGB
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2179 * components at the same time.
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2180 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2181 s = (s | s << 16) & 0x07e0f81f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2182 d = (d | d << 16) & 0x07e0f81f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2183 d += (s - d) * alpha >> 5;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2184 d &= 0x07e0f81f;
1546
4b835e36633d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1542
diff changeset
2185 *dstp++ = (Uint16)(d | d >> 16);
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2186 },{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2187 s = *srcp++;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2188 d = *dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2189 /*
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2190 * shift out the middle component (green) to
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2191 * the high 16 bits, and process all three RGB
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2192 * components at the same time.
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2193 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2194 s = (s | s << 16) & 0x07e0f81f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2195 d = (d | d << 16) & 0x07e0f81f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2196 d += (s - d) * alpha >> 5;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2197 d &= 0x07e0f81f;
1546
4b835e36633d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1542
diff changeset
2198 *dstp++ = (Uint16)(d | d >> 16);
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2199 s = *srcp++;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2200 d = *dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2201 /*
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2202 * shift out the middle component (green) to
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2203 * the high 16 bits, and process all three RGB
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2204 * components at the same time.
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2205 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2206 s = (s | s << 16) & 0x07e0f81f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2207 d = (d | d << 16) & 0x07e0f81f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2208 d += (s - d) * alpha >> 5;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2209 d &= 0x07e0f81f;
1546
4b835e36633d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1542
diff changeset
2210 *dstp++ = (Uint16)(d | d >> 16);
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2211 },{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2212 src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2213 dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2214
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2215 /* red */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2216 src2 = src1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2217 src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 [000r 000r 000r 000r] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2218
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2219 dst2 = dst1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2220 dst2 = _mm_srli_pi16(dst2, 11); /* dst2 >> 11 -> dst2 [000r 000r 000r 000r] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2221
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2222 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2223 src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2224 src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2225 src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2226 dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2227 dst2 = _mm_slli_pi16(dst2, 11); /* dst2 << 11 -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2228
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2229 mm_res = dst2; /* RED -> mm_res */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2230
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2231 /* green -- process the bits in place */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2232 src2 = src1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2233 src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2234
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2235 dst2 = dst1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2236 dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2237
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2238 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2239 src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2240 src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2241 src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2242 dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2243
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2244 mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2245
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2246 /* blue */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2247 src2 = src1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2248 src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2249
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2250 dst2 = dst1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2251 dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2252
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2253 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2254 src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2255 src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2256 src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2257 dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2258 dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2259
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2260 mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2261
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2262 *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2263
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2264 srcp += 4;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2265 dstp += 4;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2266 }, width);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2267 srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2268 dstp += dstskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2269 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2270 _mm_empty();
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2271 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2272 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2273
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2274 /* fast RGB555->RGB555 blending with surface alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2275 static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo *info)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2276 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2277 unsigned alpha = info->src->alpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2278 if(alpha == 128) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2279 Blit16to16SurfaceAlpha128(info, 0xfbde);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2280 } else {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2281 int width = info->d_width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2282 int height = info->d_height;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2283 Uint16 *srcp = (Uint16 *)info->s_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2284 int srcskip = info->s_skip >> 1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2285 Uint16 *dstp = (Uint16 *)info->d_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2286 int dstskip = info->d_skip >> 1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2287 Uint32 s, d;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2288
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2289 __m64 src1, dst1, src2, dst2, rmask, gmask, bmask, mm_res, mm_alpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2290
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2291 alpha &= ~(1+2+4); /* cut alpha to get the exact same behaviour */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2292 mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2293 alpha >>= 3; /* downscale alpha to 5 bits */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2294
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2295 mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2296 mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2297 /* position alpha to allow for mullo and mulhi on diff channels
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2298 to reduce the number of operations */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2299 mm_alpha = _mm_slli_si64(mm_alpha, 3);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2300
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2301 /* Setup the 555 color channel masks */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2302 rmask = _mm_set_pi32(0x7C007C00, 0x7C007C00); /* MASKRED -> rmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2303 gmask = _mm_set_pi32(0x03E003E0, 0x03E003E0); /* MASKGREEN -> gmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2304 bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2305
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2306 while(height--) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2307 DUFFS_LOOP_QUATRO2(
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2308 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2309 s = *srcp++;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2310 d = *dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2311 /*
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2312 * shift out the middle component (green) to
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2313 * the high 16 bits, and process all three RGB
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2314 * components at the same time.
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2315 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2316 s = (s | s << 16) & 0x03e07c1f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2317 d = (d | d << 16) & 0x03e07c1f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2318 d += (s - d) * alpha >> 5;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2319 d &= 0x03e07c1f;
1546
4b835e36633d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1542
diff changeset
2320 *dstp++ = (Uint16)(d | d >> 16);
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2321 },{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2322 s = *srcp++;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2323 d = *dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2324 /*
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2325 * shift out the middle component (green) to
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2326 * the high 16 bits, and process all three RGB
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2327 * components at the same time.
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2328 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2329 s = (s | s << 16) & 0x03e07c1f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2330 d = (d | d << 16) & 0x03e07c1f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2331 d += (s - d) * alpha >> 5;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2332 d &= 0x03e07c1f;
1546
4b835e36633d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1542
diff changeset
2333 *dstp++ = (Uint16)(d | d >> 16);
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2334 s = *srcp++;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2335 d = *dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2336 /*
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2337 * shift out the middle component (green) to
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2338 * the high 16 bits, and process all three RGB
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2339 * components at the same time.
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2340 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2341 s = (s | s << 16) & 0x03e07c1f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2342 d = (d | d << 16) & 0x03e07c1f;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2343 d += (s - d) * alpha >> 5;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2344 d &= 0x03e07c1f;
1546
4b835e36633d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1542
diff changeset
2345 *dstp++ = (Uint16)(d | d >> 16);
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2346 },{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2347 src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2348 dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2349
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2350 /* red -- process the bits in place */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2351 src2 = src1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2352 src2 = _mm_and_si64(src2, rmask); /* src & MASKRED -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2353
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2354 dst2 = dst1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2355 dst2 = _mm_and_si64(dst2, rmask); /* dst & MASKRED -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2356
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2357 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2358 src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2359 src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2360 src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2361 dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2362 dst2 = _mm_and_si64(dst2, rmask); /* dst2 & MASKRED -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2363
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2364 mm_res = dst2; /* RED -> mm_res */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2365
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2366 /* green -- process the bits in place */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2367 src2 = src1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2368 src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2369
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2370 dst2 = dst1;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2371 dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2372
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2373 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2374 src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2375 src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2376 src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2377 dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2378
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2379 mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2380
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2381 /* blue */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2382 src2 = src1; /* src -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2383 src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2384
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2385 dst2 = dst1; /* dst -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2386 dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2387
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2388 /* blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2389 src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2390 src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2391 src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2392 dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2393 dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2394
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2395 mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2396
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2397 *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2398
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2399 srcp += 4;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2400 dstp += 4;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2401 }, width);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2402 srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2403 dstp += dstskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2404 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2405 _mm_empty();
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2406 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2407 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2408 #endif /* GCC_ASMBLIT, MSVC_ASMBLIT */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2409
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2410 /* fast RGB565->RGB565 blending with surface alpha */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2411 static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2412 {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2413 unsigned alpha = info->src->alpha;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2414 if(alpha == 128) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2415 Blit16to16SurfaceAlpha128(info, 0xf7de);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2416 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2417 int width = info->d_width;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2418 int height = info->d_height;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2419 Uint16 *srcp = (Uint16 *)info->s_pixels;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2420 int srcskip = info->s_skip >> 1;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2421 Uint16 *dstp = (Uint16 *)info->d_pixels;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2422 int dstskip = info->d_skip >> 1;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2423 alpha >>= 3; /* downscale alpha to 5 bits */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2424
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2425 while(height--) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2426 DUFFS_LOOP4({
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2427 Uint32 s = *srcp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2428 Uint32 d = *dstp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2429 /*
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2430 * shift out the middle component (green) to
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2431 * the high 16 bits, and process all three RGB
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2432 * components at the same time.
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2433 */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2434 s = (s | s << 16) & 0x07e0f81f;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2435 d = (d | d << 16) & 0x07e0f81f;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2436 d += (s - d) * alpha >> 5;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2437 d &= 0x07e0f81f;
1428
5f52867ba65c Update for Visual C++ 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
2438 *dstp++ = (Uint16)(d | d >> 16);
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2439 }, width);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2440 srcp += srcskip;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2441 dstp += dstskip;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2442 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2443 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2444 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2445
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2446 /* fast RGB555->RGB555 blending with surface alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2447 static void Blit555to555SurfaceAlpha(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2448 {
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2449 unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2450 if(alpha == 128) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2451 Blit16to16SurfaceAlpha128(info, 0xfbde);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2452 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2453 int width = info->d_width;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2454 int height = info->d_height;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2455 Uint16 *srcp = (Uint16 *)info->s_pixels;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2456 int srcskip = info->s_skip >> 1;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2457 Uint16 *dstp = (Uint16 *)info->d_pixels;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2458 int dstskip = info->d_skip >> 1;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2459 alpha >>= 3; /* downscale alpha to 5 bits */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2460
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2461 while(height--) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2462 DUFFS_LOOP4({
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2463 Uint32 s = *srcp++;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2464 Uint32 d = *dstp;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2465 /*
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2466 * shift out the middle component (green) to
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2467 * the high 16 bits, and process all three RGB
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2468 * components at the same time.
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2469 */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2470 s = (s | s << 16) & 0x03e07c1f;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2471 d = (d | d << 16) & 0x03e07c1f;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2472 d += (s - d) * alpha >> 5;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2473 d &= 0x03e07c1f;
1428
5f52867ba65c Update for Visual C++ 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
2474 *dstp++ = (Uint16)(d | d >> 16);
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2475 }, width);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2476 srcp += srcskip;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2477 dstp += dstskip;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
2478 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2479 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2480 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2481
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2482 /* fast ARGB8888->RGB565 blending with pixel alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2483 static void BlitARGBto565PixelAlpha(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2484 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2485 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2486 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2487 Uint32 *srcp = (Uint32 *)info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2488 int srcskip = info->s_skip >> 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2489 Uint16 *dstp = (Uint16 *)info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2490 int dstskip = info->d_skip >> 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2491
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2492 while(height--) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2493 DUFFS_LOOP4({
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2494 Uint32 s = *srcp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2495 unsigned alpha = s >> 27; /* downscale alpha to 5 bits */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2496 /* FIXME: Here we special-case opaque alpha since the
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2497 compositioning used (>>8 instead of /255) doesn't handle
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2498 it correctly. Also special-case alpha=0 for speed?
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2499 Benchmark this! */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2500 if(alpha) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2501 if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
1428
5f52867ba65c Update for Visual C++ 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
2502 *dstp = (Uint16)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f));
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2503 } else {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2504 Uint32 d = *dstp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2505 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2506 * convert source and destination to G0RAB65565
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2507 * and blend all components at the same time
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2508 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2509 s = ((s & 0xfc00) << 11) + (s >> 8 & 0xf800)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2510 + (s >> 3 & 0x1f);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2511 d = (d | d << 16) & 0x07e0f81f;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2512 d += (s - d) * alpha >> 5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2513 d &= 0x07e0f81f;
1428
5f52867ba65c Update for Visual C++ 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
2514 *dstp = (Uint16)(d | d >> 16);
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2515 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2516 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2517 srcp++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2518 dstp++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2519 }, width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2520 srcp += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2521 dstp += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2522 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2523 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2524
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2525 /* fast ARGB8888->RGB555 blending with pixel alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2526 static void BlitARGBto555PixelAlpha(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2527 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2528 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2529 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2530 Uint32 *srcp = (Uint32 *)info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2531 int srcskip = info->s_skip >> 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2532 Uint16 *dstp = (Uint16 *)info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2533 int dstskip = info->d_skip >> 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2534
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2535 while(height--) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2536 DUFFS_LOOP4({
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2537 unsigned alpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2538 Uint32 s = *srcp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2539 alpha = s >> 27; /* downscale alpha to 5 bits */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2540 /* FIXME: Here we special-case opaque alpha since the
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2541 compositioning used (>>8 instead of /255) doesn't handle
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2542 it correctly. Also special-case alpha=0 for speed?
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2543 Benchmark this! */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2544 if(alpha) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2545 if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
1428
5f52867ba65c Update for Visual C++ 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
2546 *dstp = (Uint16)((s >> 9 & 0x7c00) + (s >> 6 & 0x3e0) + (s >> 3 & 0x1f));
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2547 } else {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2548 Uint32 d = *dstp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2549 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2550 * convert source and destination to G0RAB65565
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2551 * and blend all components at the same time
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2552 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2553 s = ((s & 0xf800) << 10) + (s >> 9 & 0x7c00)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2554 + (s >> 3 & 0x1f);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2555 d = (d | d << 16) & 0x03e07c1f;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2556 d += (s - d) * alpha >> 5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2557 d &= 0x03e07c1f;
1428
5f52867ba65c Update for Visual C++ 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
2558 *dstp = (Uint16)(d | d >> 16);
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2559 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2560 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2561 srcp++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2562 dstp++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2563 }, width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2564 srcp += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2565 dstp += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2566 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2567 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2568
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2569 /* General (slow) N->N blending with per-surface alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2570 static void BlitNtoNSurfaceAlpha(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2571 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2572 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2573 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2574 Uint8 *src = info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2575 int srcskip = info->s_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2576 Uint8 *dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2577 int dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2578 SDL_PixelFormat *srcfmt = info->src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2579 SDL_PixelFormat *dstfmt = info->dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2580 int srcbpp = srcfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2581 int dstbpp = dstfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2582 unsigned sA = srcfmt->alpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2583 unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2584
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2585 if(sA) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2586 while ( height-- ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2587 DUFFS_LOOP4(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2588 {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2589 Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2590 unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2591 unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2592 unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2593 unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2594 unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2595 unsigned dB;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2596 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2597 DISEMBLE_RGB(dst, dstbpp, dstfmt, Pixel, dR, dG, dB);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2598 ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2599 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2600 src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2601 dst += dstbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2602 },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2603 width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2604 src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2605 dst += dstskip;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2606 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2607 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2608 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2609
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2610 /* General (slow) colorkeyed N->N blending with per-surface alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2611 static void BlitNtoNSurfaceAlphaKey(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2612 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2613 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2614 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2615 Uint8 *src = info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2616 int srcskip = info->s_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2617 Uint8 *dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2618 int dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2619 SDL_PixelFormat *srcfmt = info->src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2620 SDL_PixelFormat *dstfmt = info->dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2621 Uint32 ckey = srcfmt->colorkey;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2622 int srcbpp = srcfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2623 int dstbpp = dstfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2624 unsigned sA = srcfmt->alpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2625 unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2626
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2627 while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2628 DUFFS_LOOP4(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2629 {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2630 Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2631 unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2632 unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2633 unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2634 unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2635 unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2636 unsigned dB;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2637 RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2638 if(sA && Pixel != ckey) {
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2639 RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2640 DISEMBLE_RGB(dst, dstbpp, dstfmt, Pixel, dR, dG, dB);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2641 ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2642 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2643 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2644 src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2645 dst += dstbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2646 },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2647 width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2648 src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2649 dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2650 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2651 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2652
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2653 /* General (slow) N->N blending with pixel alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2654 static void BlitNtoNPixelAlpha(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2655 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2656 int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2657 int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2658 Uint8 *src = info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2659 int srcskip = info->s_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2660 Uint8 *dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2661 int dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2662 SDL_PixelFormat *srcfmt = info->src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2663 SDL_PixelFormat *dstfmt = info->dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2664
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2665 int srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2666 int dstbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2667
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2668 /* Set up some basic variables */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2669 srcbpp = srcfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2670 dstbpp = dstfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2671
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2672 /* FIXME: for 8bpp source alpha, this doesn't get opaque values
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2673 quite right. for <8bpp source alpha, it gets them very wrong
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2674 (check all macros!)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2675 It is unclear whether there is a good general solution that doesn't
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2676 need a branch (or a divide). */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2677 while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2678 DUFFS_LOOP4(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2679 {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2680 Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2681 unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2682 unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2683 unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2684 unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2685 unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2686 unsigned dB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2687 unsigned sA;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2688 unsigned dA;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2689 DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2690 if(sA) {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
2691 DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2692 ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2693 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2694 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2695 src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2696 dst += dstbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2697 },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2698 width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2699 src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2700 dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2701 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2702 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2703
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2704
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2705 SDL_loblit SDL_CalculateAlphaBlit(SDL_Surface *surface, int blit_index)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2706 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2707 SDL_PixelFormat *sf = surface->format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2708 SDL_PixelFormat *df = surface->map->dst->format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2709
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2710 if(sf->Amask == 0) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2711 if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2712 if(df->BytesPerPixel == 1)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2713 return BlitNto1SurfaceAlphaKey;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2714 else
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
2715 #if SDL_ALTIVEC_BLITTERS
1240
3b8a43c428bb From Bug #36:
Ryan C. Gordon <icculus@icculus.org>
parents: 1175
diff changeset
2716 if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 &&
3b8a43c428bb From Bug #36:
Ryan C. Gordon <icculus@icculus.org>
parents: 1175
diff changeset
2717 !(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec())
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
2718 return Blit32to32SurfaceAlphaKeyAltivec;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
2719 else
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
2720 #endif
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
2721 return BlitNtoNSurfaceAlphaKey;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2722 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2723 /* Per-surface alpha blits */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2724 switch(df->BytesPerPixel) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2725 case 1:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2726 return BlitNto1SurfaceAlpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2727
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2728 case 2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2729 if(surface->map->identity) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2730 if(df->Gmask == 0x7e0)
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2731 {
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
2732 #if MMX_ASMBLIT
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 720
diff changeset
2733 if(SDL_HasMMX())
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2734 return Blit565to565SurfaceAlphaMMX;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2735 else
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2736 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2737 return Blit565to565SurfaceAlpha;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2738 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2739 else if(df->Gmask == 0x3e0)
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2740 {
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
2741 #if MMX_ASMBLIT
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 720
diff changeset
2742 if(SDL_HasMMX())
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2743 return Blit555to555SurfaceAlphaMMX;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2744 else
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2745 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2746 return Blit555to555SurfaceAlpha;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2747 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2748 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2749 return BlitNtoNSurfaceAlpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2750
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2751 case 4:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2752 if(sf->Rmask == df->Rmask
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2753 && sf->Gmask == df->Gmask
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2754 && sf->Bmask == df->Bmask
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2755 && sf->BytesPerPixel == 4)
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2756 {
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
2757 #if MMX_ASMBLIT
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2758 if(sf->Rshift % 8 == 0
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2759 && sf->Gshift % 8 == 0
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2760 && sf->Bshift % 8 == 0
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2761 && SDL_HasMMX())
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2762 return BlitRGBtoRGBSurfaceAlphaMMX;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2763 #endif
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2764 if((sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2765 {
1617
b255b4058d37 Patch from Alex to fix reverted code
Sam Lantinga <slouken@libsdl.org>
parents: 1546
diff changeset
2766 #if SDL_ALTIVEC_BLITTERS
b255b4058d37 Patch from Alex to fix reverted code
Sam Lantinga <slouken@libsdl.org>
parents: 1546
diff changeset
2767 if(!(surface->map->dst->flags & SDL_HWSURFACE)
b255b4058d37 Patch from Alex to fix reverted code
Sam Lantinga <slouken@libsdl.org>
parents: 1546
diff changeset
2768 && SDL_HasAltiVec())
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2769 return BlitRGBtoRGBSurfaceAlphaAltivec;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2770 #endif
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2771 return BlitRGBtoRGBSurfaceAlpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2772 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2773 }
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2774 #if SDL_ALTIVEC_BLITTERS
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2775 if((sf->BytesPerPixel == 4) &&
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2776 !(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec())
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2777 return Blit32to32SurfaceAlphaAltivec;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2778 else
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2779 #endif
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2780 return BlitNtoNSurfaceAlpha;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2781
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2782 case 3:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2783 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2784 return BlitNtoNSurfaceAlpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2785 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2786 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2787 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2788 /* Per-pixel alpha blits */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2789 switch(df->BytesPerPixel) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2790 case 1:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2791 return BlitNto1PixelAlpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2792
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2793 case 2:
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
2794 #if SDL_ALTIVEC_BLITTERS
1240
3b8a43c428bb From Bug #36:
Ryan C. Gordon <icculus@icculus.org>
parents: 1175
diff changeset
2795 if(sf->BytesPerPixel == 4 && !(surface->map->dst->flags & SDL_HWSURFACE) &&
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
2796 df->Gmask == 0x7e0 &&
1240
3b8a43c428bb From Bug #36:
Ryan C. Gordon <icculus@icculus.org>
parents: 1175
diff changeset
2797 df->Bmask == 0x1f && SDL_HasAltiVec())
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
2798 return Blit32to565PixelAlphaAltivec;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
2799 else
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
2800 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2801 if(sf->BytesPerPixel == 4 && sf->Amask == 0xff000000
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2802 && sf->Gmask == 0xff00
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2803 && ((sf->Rmask == 0xff && df->Rmask == 0x1f)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2804 || (sf->Bmask == 0xff && df->Bmask == 0x1f))) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2805 if(df->Gmask == 0x7e0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2806 return BlitARGBto565PixelAlpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2807 else if(df->Gmask == 0x3e0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2808 return BlitARGBto555PixelAlpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2809 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2810 return BlitNtoNPixelAlpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2811
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2812 case 4:
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2813 if(sf->Rmask == df->Rmask
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2814 && sf->Gmask == df->Gmask
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2815 && sf->Bmask == df->Bmask
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2816 && sf->BytesPerPixel == 4)
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2817 {
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
2818 #if MMX_ASMBLIT
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2819 if(sf->Rshift % 8 == 0
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2820 && sf->Gshift % 8 == 0
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2821 && sf->Bshift % 8 == 0
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2822 && sf->Ashift % 8 == 0
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2823 && sf->Aloss == 0)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2824 {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2825 if(SDL_Has3DNow())
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2826 return BlitRGBtoRGBPixelAlphaMMX3DNOW;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2827 if(SDL_HasMMX())
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2828 return BlitRGBtoRGBPixelAlphaMMX;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2829 }
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2830 #endif
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2831 if(sf->Amask == 0xff000000)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2832 {
1617
b255b4058d37 Patch from Alex to fix reverted code
Sam Lantinga <slouken@libsdl.org>
parents: 1546
diff changeset
2833 #if SDL_ALTIVEC_BLITTERS
b255b4058d37 Patch from Alex to fix reverted code
Sam Lantinga <slouken@libsdl.org>
parents: 1546
diff changeset
2834 if(!(surface->map->dst->flags & SDL_HWSURFACE)
b255b4058d37 Patch from Alex to fix reverted code
Sam Lantinga <slouken@libsdl.org>
parents: 1546
diff changeset
2835 && SDL_HasAltiVec())
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2836 return BlitRGBtoRGBPixelAlphaAltivec;
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
2837 #endif
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2838 return BlitRGBtoRGBPixelAlpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2839 }
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
2840 }
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
2841 #if SDL_ALTIVEC_BLITTERS
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2842 if (sf->Amask && sf->BytesPerPixel == 4 &&
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2843 !(surface->map->dst->flags & SDL_HWSURFACE) && SDL_HasAltiVec())
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2844 return Blit32to32PixelAlphaAltivec;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2845 else
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
2846 #endif
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
2847 return BlitNtoNPixelAlpha;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2848
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2849 case 3:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2850 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2851 return BlitNtoNPixelAlpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2852 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2853 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2854 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2855