annotate src/video/SDL_blit_A.c @ 2934:1fcc36adc73d

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