Mercurial > sdl-ios-xcode
annotate src/video/SDL_RLEaccel.c @ 1319:66f6c64c2c69
Logic bug in X11 Unicode input shutdown...was checking for == NULL
when it should be != NULL.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 01 Feb 2006 19:59:02 +0000 |
parents | c9b51268668f |
children | 450721ad5436 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1155
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
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:
1155
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 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:
1155
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
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:
1155
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1155
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:
1155
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:
1155
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
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 | 21 */ |
22 | |
23 /* | |
24 * RLE encoding for software colorkey and alpha-channel acceleration | |
25 * | |
26 * Original version by Sam Lantinga | |
27 * | |
28 * Mattias Engdegård (Yorick): Rewrite. New encoding format, encoder and | |
29 * decoder. Added per-surface alpha blitter. Added per-pixel alpha | |
30 * format, encoder and blitter. | |
31 * | |
32 * Many thanks to Xark and johns for hints, benchmarks and useful comments | |
33 * leading to this code. | |
34 * | |
35 * Welcome to Macro Mayhem. | |
36 */ | |
37 | |
38 /* | |
39 * The encoding translates the image data to a stream of segments of the form | |
40 * | |
41 * <skip> <run> <data> | |
42 * | |
43 * where <skip> is the number of transparent pixels to skip, | |
44 * <run> is the number of opaque pixels to blit, | |
45 * and <data> are the pixels themselves. | |
46 * | |
47 * This basic structure is used both for colorkeyed surfaces, used for simple | |
48 * binary transparency and for per-surface alpha blending, and for surfaces | |
49 * with per-pixel alpha. The details differ, however: | |
50 * | |
51 * Encoding of colorkeyed surfaces: | |
52 * | |
53 * Encoded pixels always have the same format as the target surface. | |
54 * <skip> and <run> are unsigned 8 bit integers, except for 32 bit depth | |
55 * where they are 16 bit. This makes the pixel data aligned at all times. | |
56 * Segments never wrap around from one scan line to the next. | |
57 * | |
58 * The end of the sequence is marked by a zero <skip>,<run> pair at the * | |
59 * beginning of a line. | |
60 * | |
61 * Encoding of surfaces with per-pixel alpha: | |
62 * | |
63 * The sequence begins with a struct RLEDestFormat describing the target | |
64 * pixel format, to provide reliable un-encoding. | |
65 * | |
66 * Each scan line is encoded twice: First all completely opaque pixels, | |
67 * encoded in the target format as described above, and then all | |
68 * partially transparent (translucent) pixels (where 1 <= alpha <= 254), | |
69 * in the following 32-bit format: | |
70 * | |
71 * For 32-bit targets, each pixel has the target RGB format but with | |
72 * the alpha value occupying the highest 8 bits. The <skip> and <run> | |
73 * counts are 16 bit. | |
74 * | |
75 * For 16-bit targets, each pixel has the target RGB format, but with | |
76 * the middle component (usually green) shifted 16 steps to the left, | |
77 * and the hole filled with the 5 most significant bits of the alpha value. | |
78 * i.e. if the target has the format rrrrrggggggbbbbb, | |
79 * the encoded pixel will be 00000gggggg00000rrrrr0aaaaabbbbb. | |
80 * The <skip> and <run> counts are 8 bit for the opaque lines, 16 bit | |
81 * for the translucent lines. Two padding bytes may be inserted | |
82 * before each translucent line to keep them 32-bit aligned. | |
83 * | |
84 * The end of the sequence is marked by a zero <skip>,<run> pair at the | |
85 * beginning of an opaque line. | |
86 */ | |
87 | |
88 #include <stdio.h> | |
89 #include <stdlib.h> | |
90 #include <string.h> | |
91 | |
92 #include "SDL_types.h" | |
93 #include "SDL_video.h" | |
94 #include "SDL_error.h" | |
95 #include "SDL_sysvideo.h" | |
96 #include "SDL_blit.h" | |
97 #include "SDL_memops.h" | |
98 #include "SDL_RLEaccel_c.h" | |
99 | |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
879
diff
changeset
|
100 #if (defined(i386) || defined(__x86_64__)) && defined(__GNUC__) && defined(USE_ASMBLIT) |
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
879
diff
changeset
|
101 #define MMX_ASMBLIT |
879
2bacec7930b1
Date: Wed, 31 Mar 2004 09:15:57 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
102 #endif |
2bacec7930b1
Date: Wed, 31 Mar 2004 09:15:57 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
103 |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
879
diff
changeset
|
104 #ifdef MMX_ASMBLIT |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
105 #include "mmx.h" |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
689
diff
changeset
|
106 #include "SDL_cpuinfo.h" |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
107 #endif |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
108 |
0 | 109 #ifndef MAX |
110 #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
111 #endif | |
112 #ifndef MIN | |
113 #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
114 #endif | |
115 | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
116 #define PIXEL_COPY(to, from, len, bpp) \ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
117 do { \ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
118 if(bpp == 4) { \ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
119 SDL_memcpy4(to, from, (unsigned)(len)); \ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
120 } else { \ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
121 SDL_memcpy(to, from, (unsigned)(len) * (bpp)); \ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
122 } \ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
123 } while(0) |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
124 |
0 | 125 /* |
126 * Various colorkey blit methods, for opaque and per-surface alpha | |
127 */ | |
128 | |
129 #define OPAQUE_BLIT(to, from, length, bpp, alpha) \ | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
130 PIXEL_COPY(to, from, length, bpp) |
0 | 131 |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
879
diff
changeset
|
132 #ifdef MMX_ASMBLIT |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
133 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
134 #define ALPHA_BLIT32_888MMX(to, from, length, bpp, alpha) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
135 do { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
136 Uint32 *srcp = (Uint32 *)(from); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
137 Uint32 *dstp = (Uint32 *)(to); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
138 int i = 0x00FF00FF; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
139 movd_m2r(*(&i), mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
140 punpckldq_r2r(mm3, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
141 i = 0xFF000000; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
142 movd_m2r(*(&i), mm7); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
143 punpckldq_r2r(mm7, mm7); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
144 i = alpha | alpha << 16; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
145 movd_m2r(*(&i), mm4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
146 punpckldq_r2r(mm4, mm4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
147 pcmpeqd_r2r(mm5,mm5); /* set mm5 to "1" */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
148 pxor_r2r(mm7, mm5); /* make clear alpha mask */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
149 i = length; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
150 if(i & 1) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
151 movd_m2r((*srcp), mm1); /* src -> mm1 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
152 punpcklbw_r2r(mm1, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
153 pand_r2r(mm3, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
154 movd_m2r((*dstp), mm2); /* dst -> mm2 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
155 punpcklbw_r2r(mm2, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
156 pand_r2r(mm3, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
157 psubw_r2r(mm2, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
158 pmullw_r2r(mm4, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
159 psrlw_i2r(8, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
160 paddw_r2r(mm1, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
161 pand_r2r(mm3, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
162 packuswb_r2r(mm2, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
163 pand_r2r(mm5, mm2); /* 00000RGB -> mm2 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
164 movd_r2m(mm2, *dstp); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
165 ++srcp; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
166 ++dstp; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
167 i--; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
168 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
169 for(; i > 0; --i) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
170 movq_m2r((*srcp), mm0); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
171 movq_r2r(mm0, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
172 punpcklbw_r2r(mm0, mm0); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
173 movq_m2r((*dstp), mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
174 punpckhbw_r2r(mm1, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
175 movq_r2r(mm2, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
176 pand_r2r(mm3, mm0); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
177 punpcklbw_r2r(mm2, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
178 pand_r2r(mm3, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
179 punpckhbw_r2r(mm6, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
180 pand_r2r(mm3, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
181 psubw_r2r(mm2, mm0); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
182 pmullw_r2r(mm4, mm0); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
183 pand_r2r(mm3, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
184 psubw_r2r(mm6, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
185 pmullw_r2r(mm4, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
186 psrlw_i2r(8, mm0); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
187 paddw_r2r(mm0, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
188 psrlw_i2r(8, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
189 paddw_r2r(mm1, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
190 pand_r2r(mm3, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
191 pand_r2r(mm3, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
192 packuswb_r2r(mm2, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
193 packuswb_r2r(mm6, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
194 psrlq_i2r(32, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
195 psllq_i2r(32, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
196 por_r2r(mm6, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
197 pand_r2r(mm5, mm2); /* 00000RGB -> mm2 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
198 movq_r2m(mm2, *dstp); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
199 srcp += 2; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
200 dstp += 2; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
201 i--; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
202 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
203 emms(); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
204 } while(0) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
205 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
206 #define ALPHA_BLIT16_565MMX(to, from, length, bpp, alpha) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
207 do { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
208 int i, n = 0; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
209 Uint16 *srcp = (Uint16 *)(from); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
210 Uint16 *dstp = (Uint16 *)(to); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
211 Uint32 ALPHA = 0xF800; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
212 movd_m2r(*(&ALPHA), mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
213 punpcklwd_r2r(mm1, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
214 punpcklwd_r2r(mm1, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
215 ALPHA = 0x07E0; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
216 movd_m2r(*(&ALPHA), mm4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
217 punpcklwd_r2r(mm4, mm4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
218 punpcklwd_r2r(mm4, mm4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
219 ALPHA = 0x001F; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
220 movd_m2r(*(&ALPHA), mm7); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
221 punpcklwd_r2r(mm7, mm7); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
222 punpcklwd_r2r(mm7, mm7); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
223 alpha &= ~(1+2+4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
224 i = (Uint32)alpha | (Uint32)alpha << 16; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
225 movd_m2r(*(&i), mm0); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
226 punpckldq_r2r(mm0, mm0); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
227 ALPHA = alpha >> 3; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
228 i = ((int)(length) & 3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
229 for(; i > 0; --i) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
230 Uint32 s = *srcp++; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
231 Uint32 d = *dstp; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
232 s = (s | s << 16) & 0x07e0f81f; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
233 d = (d | d << 16) & 0x07e0f81f; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
234 d += (s - d) * ALPHA >> 5; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
235 d &= 0x07e0f81f; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
236 *dstp++ = d | d >> 16; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
237 n++; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
238 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
239 i = (int)(length) - n; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
240 for(; i > 0; --i) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
241 movq_m2r((*dstp), mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
242 movq_m2r((*srcp), mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
243 movq_r2r(mm2, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
244 pand_r2r(mm1 , mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
245 psrlq_i2r(11, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
246 movq_r2r(mm3, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
247 pand_r2r(mm1 , mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
248 psrlq_i2r(11, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
249 psubw_r2r(mm6, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
250 pmullw_r2r(mm0, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
251 psrlw_i2r(8, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
252 paddw_r2r(mm5, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
253 psllq_i2r(11, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
254 pand_r2r(mm1, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
255 movq_r2r(mm4, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
256 por_r2r(mm7, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
257 pand_r2r(mm5, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
258 por_r2r(mm6, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
259 movq_r2r(mm2, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
260 pand_r2r(mm4 , mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
261 psrlq_i2r(5, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
262 movq_r2r(mm3, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
263 pand_r2r(mm4 , mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
264 psrlq_i2r(5, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
265 psubw_r2r(mm6, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
266 pmullw_r2r(mm0, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
267 psrlw_i2r(8, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
268 paddw_r2r(mm5, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
269 psllq_i2r(5, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
270 pand_r2r(mm4, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
271 movq_r2r(mm1, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
272 por_r2r(mm7, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
273 pand_r2r(mm5, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
274 por_r2r(mm6, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
275 movq_r2r(mm2, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
276 pand_r2r(mm7 , mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
277 movq_r2r(mm3, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
278 pand_r2r(mm7 , mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
279 psubw_r2r(mm6, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
280 pmullw_r2r(mm0, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
281 psrlw_i2r(8, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
282 paddw_r2r(mm5, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
283 pand_r2r(mm7, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
284 movq_r2r(mm1, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
285 por_r2r(mm4, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
286 pand_r2r(mm5, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
287 por_r2r(mm6, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
288 movq_r2m(mm3, *dstp); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
289 srcp += 4; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
290 dstp += 4; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
291 i -= 3; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
292 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
293 emms(); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
294 } while(0) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
295 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
296 #define ALPHA_BLIT16_555MMX(to, from, length, bpp, alpha) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
297 do { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
298 int i, n = 0; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
299 Uint16 *srcp = (Uint16 *)(from); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
300 Uint16 *dstp = (Uint16 *)(to); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
301 Uint32 ALPHA = 0x7C00; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
302 movd_m2r(*(&ALPHA), mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
303 punpcklwd_r2r(mm1, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
304 punpcklwd_r2r(mm1, mm1); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
305 ALPHA = 0x03E0; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
306 movd_m2r(*(&ALPHA), mm4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
307 punpcklwd_r2r(mm4, mm4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
308 punpcklwd_r2r(mm4, mm4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
309 ALPHA = 0x001F; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
310 movd_m2r(*(&ALPHA), mm7); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
311 punpcklwd_r2r(mm7, mm7); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
312 punpcklwd_r2r(mm7, mm7); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
313 alpha &= ~(1+2+4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
314 i = (Uint32)alpha | (Uint32)alpha << 16; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
315 movd_m2r(*(&i), mm0); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
316 punpckldq_r2r(mm0, mm0); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
317 i = ((int)(length) & 3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
318 ALPHA = alpha >> 3; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
319 for(; i > 0; --i) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
320 Uint32 s = *srcp++; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
321 Uint32 d = *dstp; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
322 s = (s | s << 16) & 0x03e07c1f; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
323 d = (d | d << 16) & 0x03e07c1f; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
324 d += (s - d) * ALPHA >> 5; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
325 d &= 0x03e07c1f; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
326 *dstp++ = d | d >> 16; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
327 n++; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
328 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
329 i = (int)(length) - n; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
330 for(; i > 0; --i) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
331 movq_m2r((*dstp), mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
332 movq_m2r((*srcp), mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
333 movq_r2r(mm2, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
334 pand_r2r(mm1 , mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
335 psrlq_i2r(10, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
336 movq_r2r(mm3, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
337 pand_r2r(mm1 , mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
338 psrlq_i2r(10, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
339 psubw_r2r(mm6, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
340 pmullw_r2r(mm0, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
341 psrlw_i2r(8, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
342 paddw_r2r(mm5, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
343 psllq_i2r(10, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
344 pand_r2r(mm1, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
345 movq_r2r(mm4, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
346 por_r2r(mm7, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
347 pand_r2r(mm5, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
348 por_r2r(mm6, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
349 movq_r2r(mm2, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
350 pand_r2r(mm4 , mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
351 psrlq_i2r(5, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
352 movq_r2r(mm3, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
353 pand_r2r(mm4 , mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
354 psrlq_i2r(5, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
355 psubw_r2r(mm6, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
356 pmullw_r2r(mm0, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
357 psrlw_i2r(8, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
358 paddw_r2r(mm5, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
359 psllq_i2r(5, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
360 pand_r2r(mm4, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
361 movq_r2r(mm1, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
362 por_r2r(mm7, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
363 pand_r2r(mm5, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
364 por_r2r(mm6, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
365 movq_r2r(mm2, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
366 pand_r2r(mm7 , mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
367 movq_r2r(mm3, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
368 pand_r2r(mm7 , mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
369 psubw_r2r(mm6, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
370 pmullw_r2r(mm0, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
371 psrlw_i2r(8, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
372 paddw_r2r(mm5, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
373 pand_r2r(mm7, mm6); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
374 movq_r2r(mm1, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
375 por_r2r(mm4, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
376 pand_r2r(mm5, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
377 por_r2r(mm6, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
378 movq_r2m(mm3, *dstp); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
379 srcp += 4; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
380 dstp += 4; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
381 i -= 3; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
382 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
383 emms(); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
384 } while(0) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
385 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
386 #endif |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
387 |
0 | 388 /* |
389 * For 32bpp pixels on the form 0x00rrggbb: | |
390 * If we treat the middle component separately, we can process the two | |
391 * remaining in parallel. This is safe to do because of the gap to the left | |
392 * of each component, so the bits from the multiplication don't collide. | |
393 * This can be used for any RGB permutation of course. | |
394 */ | |
395 #define ALPHA_BLIT32_888(to, from, length, bpp, alpha) \ | |
396 do { \ | |
397 int i; \ | |
398 Uint32 *src = (Uint32 *)(from); \ | |
399 Uint32 *dst = (Uint32 *)(to); \ | |
400 for(i = 0; i < (int)(length); i++) { \ | |
401 Uint32 s = *src++; \ | |
402 Uint32 d = *dst; \ | |
403 Uint32 s1 = s & 0xff00ff; \ | |
404 Uint32 d1 = d & 0xff00ff; \ | |
405 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \ | |
406 s &= 0xff00; \ | |
407 d &= 0xff00; \ | |
408 d = (d + ((s - d) * alpha >> 8)) & 0xff00; \ | |
409 *dst++ = d1 | d; \ | |
410 } \ | |
411 } while(0) | |
412 | |
413 /* | |
414 * For 16bpp pixels we can go a step further: put the middle component | |
415 * in the high 16 bits of a 32 bit word, and process all three RGB | |
416 * components at the same time. Since the smallest gap is here just | |
417 * 5 bits, we have to scale alpha down to 5 bits as well. | |
418 */ | |
419 #define ALPHA_BLIT16_565(to, from, length, bpp, alpha) \ | |
420 do { \ | |
421 int i; \ | |
422 Uint16 *src = (Uint16 *)(from); \ | |
423 Uint16 *dst = (Uint16 *)(to); \ | |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
424 Uint32 ALPHA = alpha >> 3; \ |
0 | 425 for(i = 0; i < (int)(length); i++) { \ |
426 Uint32 s = *src++; \ | |
427 Uint32 d = *dst; \ | |
428 s = (s | s << 16) & 0x07e0f81f; \ | |
429 d = (d | d << 16) & 0x07e0f81f; \ | |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
430 d += (s - d) * ALPHA >> 5; \ |
0 | 431 d &= 0x07e0f81f; \ |
432 *dst++ = d | d >> 16; \ | |
433 } \ | |
434 } while(0) | |
435 | |
436 #define ALPHA_BLIT16_555(to, from, length, bpp, alpha) \ | |
437 do { \ | |
438 int i; \ | |
439 Uint16 *src = (Uint16 *)(from); \ | |
440 Uint16 *dst = (Uint16 *)(to); \ | |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
441 Uint32 ALPHA = alpha >> 3; \ |
0 | 442 for(i = 0; i < (int)(length); i++) { \ |
443 Uint32 s = *src++; \ | |
444 Uint32 d = *dst; \ | |
445 s = (s | s << 16) & 0x03e07c1f; \ | |
446 d = (d | d << 16) & 0x03e07c1f; \ | |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
447 d += (s - d) * ALPHA >> 5; \ |
0 | 448 d &= 0x03e07c1f; \ |
449 *dst++ = d | d >> 16; \ | |
450 } \ | |
451 } while(0) | |
452 | |
453 /* | |
454 * The general slow catch-all function, for remaining depths and formats | |
455 */ | |
456 #define ALPHA_BLIT_ANY(to, from, length, bpp, alpha) \ | |
457 do { \ | |
458 int i; \ | |
459 Uint8 *src = from; \ | |
460 Uint8 *dst = to; \ | |
461 for(i = 0; i < (int)(length); i++) { \ | |
462 Uint32 s, d; \ | |
463 unsigned rs, gs, bs, rd, gd, bd; \ | |
464 switch(bpp) { \ | |
465 case 2: \ | |
466 s = *(Uint16 *)src; \ | |
467 d = *(Uint16 *)dst; \ | |
468 break; \ | |
469 case 3: \ | |
470 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { \ | |
471 s = (src[0] << 16) | (src[1] << 8) | src[2]; \ | |
472 d = (dst[0] << 16) | (dst[1] << 8) | dst[2]; \ | |
473 } else { \ | |
474 s = (src[2] << 16) | (src[1] << 8) | src[0]; \ | |
475 d = (dst[2] << 16) | (dst[1] << 8) | dst[0]; \ | |
476 } \ | |
477 break; \ | |
478 case 4: \ | |
479 s = *(Uint32 *)src; \ | |
480 d = *(Uint32 *)dst; \ | |
481 break; \ | |
482 } \ | |
483 RGB_FROM_PIXEL(s, fmt, rs, gs, bs); \ | |
484 RGB_FROM_PIXEL(d, fmt, rd, gd, bd); \ | |
485 rd += (rs - rd) * alpha >> 8; \ | |
486 gd += (gs - gd) * alpha >> 8; \ | |
487 bd += (bs - bd) * alpha >> 8; \ | |
488 PIXEL_FROM_RGB(d, fmt, rd, gd, bd); \ | |
489 switch(bpp) { \ | |
490 case 2: \ | |
491 *(Uint16 *)dst = d; \ | |
492 break; \ | |
493 case 3: \ | |
494 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { \ | |
495 dst[0] = d >> 16; \ | |
496 dst[1] = d >> 8; \ | |
497 dst[2] = d; \ | |
498 } else { \ | |
499 dst[0] = d; \ | |
500 dst[1] = d >> 8; \ | |
501 dst[2] = d >> 16; \ | |
502 } \ | |
503 break; \ | |
504 case 4: \ | |
505 *(Uint32 *)dst = d; \ | |
506 break; \ | |
507 } \ | |
508 src += bpp; \ | |
509 dst += bpp; \ | |
510 } \ | |
511 } while(0) | |
512 | |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
879
diff
changeset
|
513 #ifdef MMX_ASMBLIT |
0 | 514 |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
515 #define ALPHA_BLIT32_888_50MMX(to, from, length, bpp, alpha) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
516 do { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
517 Uint32 *srcp = (Uint32 *)(from); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
518 Uint32 *dstp = (Uint32 *)(to); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
519 int i = 0x00fefefe; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
520 movd_m2r(*(&i), mm4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
521 punpckldq_r2r(mm4, mm4); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
522 i = 0x00010101; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
523 movd_m2r(*(&i), mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
524 punpckldq_r2r(mm3, mm3); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
525 i = (int)(length); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
526 if( i & 1 ) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
527 Uint32 s = *srcp++; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
528 Uint32 d = *dstp; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
529 *dstp++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
530 + (s & d & 0x00010101); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
531 i--; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
532 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
533 for(; i > 0; --i) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
534 movq_m2r((*dstp), mm2); /* dst -> mm2 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
535 movq_r2r(mm2, mm6); /* dst -> mm6 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
536 movq_m2r((*srcp), mm1); /* src -> mm1 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
537 movq_r2r(mm1, mm5); /* src -> mm5 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
538 pand_r2r(mm4, mm6); /* dst & 0x00fefefe -> mm6 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
539 pand_r2r(mm4, mm5); /* src & 0x00fefefe -> mm5 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
540 paddd_r2r(mm6, mm5); /* (dst & 0x00fefefe) + (dst & 0x00fefefe) -> mm5 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
541 psrld_i2r(1, mm5); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
542 pand_r2r(mm1, mm2); /* s & d -> mm2 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
543 pand_r2r(mm3, mm2); /* s & d & 0x00010101 -> mm2 */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
544 paddd_r2r(mm5, mm2); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
545 movq_r2m(mm2, (*dstp)); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
546 dstp += 2; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
547 srcp += 2; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
548 i--; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
549 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
550 emms(); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
551 } while(0) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
552 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
553 #endif |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
554 |
0 | 555 /* |
556 * Special case: 50% alpha (alpha=128) | |
557 * This is treated specially because it can be optimized very well, and | |
558 * since it is good for many cases of semi-translucency. | |
559 * The theory is to do all three components at the same time: | |
560 * First zero the lowest bit of each component, which gives us room to | |
561 * add them. Then shift right and add the sum of the lowest bits. | |
562 */ | |
563 #define ALPHA_BLIT32_888_50(to, from, length, bpp, alpha) \ | |
564 do { \ | |
565 int i; \ | |
566 Uint32 *src = (Uint32 *)(from); \ | |
567 Uint32 *dst = (Uint32 *)(to); \ | |
568 for(i = 0; i < (int)(length); i++) { \ | |
569 Uint32 s = *src++; \ | |
570 Uint32 d = *dst; \ | |
571 *dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \ | |
572 + (s & d & 0x00010101); \ | |
573 } \ | |
574 } while(0) | |
575 | |
576 /* | |
577 * For 16bpp, we can actually blend two pixels in parallel, if we take | |
578 * care to shift before we add, not after. | |
579 */ | |
580 | |
581 /* helper: blend a single 16 bit pixel at 50% */ | |
582 #define BLEND16_50(dst, src, mask) \ | |
583 do { \ | |
584 Uint32 s = *src++; \ | |
585 Uint32 d = *dst; \ | |
586 *dst++ = (((s & mask) + (d & mask)) >> 1) \ | |
587 + (s & d & (~mask & 0xffff)); \ | |
588 } while(0) | |
589 | |
590 /* basic 16bpp blender. mask is the pixels to keep when adding. */ | |
591 #define ALPHA_BLIT16_50(to, from, length, bpp, alpha, mask) \ | |
592 do { \ | |
593 unsigned n = (length); \ | |
594 Uint16 *src = (Uint16 *)(from); \ | |
595 Uint16 *dst = (Uint16 *)(to); \ | |
596 if(((unsigned long)src ^ (unsigned long)dst) & 3) { \ | |
597 /* source and destination not in phase, blit one by one */ \ | |
598 while(n--) \ | |
599 BLEND16_50(dst, src, mask); \ | |
600 } else { \ | |
601 if((unsigned long)src & 3) { \ | |
602 /* first odd pixel */ \ | |
603 BLEND16_50(dst, src, mask); \ | |
604 n--; \ | |
605 } \ | |
606 for(; n > 1; n -= 2) { \ | |
607 Uint32 s = *(Uint32 *)src; \ | |
608 Uint32 d = *(Uint32 *)dst; \ | |
609 *(Uint32 *)dst = ((s & (mask | mask << 16)) >> 1) \ | |
610 + ((d & (mask | mask << 16)) >> 1) \ | |
611 + (s & d & (~(mask | mask << 16))); \ | |
612 src += 2; \ | |
613 dst += 2; \ | |
614 } \ | |
615 if(n) \ | |
616 BLEND16_50(dst, src, mask); /* last odd pixel */ \ | |
617 } \ | |
618 } while(0) | |
619 | |
620 #define ALPHA_BLIT16_565_50(to, from, length, bpp, alpha) \ | |
621 ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7de) | |
622 | |
623 #define ALPHA_BLIT16_555_50(to, from, length, bpp, alpha) \ | |
624 ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbde) | |
625 | |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
879
diff
changeset
|
626 #ifdef MMX_ASMBLIT |
0 | 627 |
628 #define CHOOSE_BLIT(blitter, alpha, fmt) \ | |
629 do { \ | |
630 if(alpha == 255) { \ | |
631 switch(fmt->BytesPerPixel) { \ | |
632 case 1: blitter(1, Uint8, OPAQUE_BLIT); break; \ | |
633 case 2: blitter(2, Uint8, OPAQUE_BLIT); break; \ | |
634 case 3: blitter(3, Uint8, OPAQUE_BLIT); break; \ | |
635 case 4: blitter(4, Uint16, OPAQUE_BLIT); break; \ | |
636 } \ | |
637 } else { \ | |
638 switch(fmt->BytesPerPixel) { \ | |
639 case 1: \ | |
640 /* No 8bpp alpha blitting */ \ | |
641 break; \ | |
642 \ | |
643 case 2: \ | |
644 switch(fmt->Rmask | fmt->Gmask | fmt->Bmask) { \ | |
645 case 0xffff: \ | |
646 if(fmt->Gmask == 0x07e0 \ | |
647 || fmt->Rmask == 0x07e0 \ | |
648 || fmt->Bmask == 0x07e0) { \ | |
649 if(alpha == 128) \ | |
650 blitter(2, Uint8, ALPHA_BLIT16_565_50); \ | |
651 else { \ | |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
689
diff
changeset
|
652 if(SDL_HasMMX()) \ |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
653 blitter(2, Uint8, ALPHA_BLIT16_565MMX); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
654 else \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
655 blitter(2, Uint8, ALPHA_BLIT16_565); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
656 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
657 } else \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
658 goto general16; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
659 break; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
660 \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
661 case 0x7fff: \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
662 if(fmt->Gmask == 0x03e0 \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
663 || fmt->Rmask == 0x03e0 \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
664 || fmt->Bmask == 0x03e0) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
665 if(alpha == 128) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
666 blitter(2, Uint8, ALPHA_BLIT16_555_50); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
667 else { \ |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
689
diff
changeset
|
668 if(SDL_HasMMX()) \ |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
669 blitter(2, Uint8, ALPHA_BLIT16_555MMX); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
670 else \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
671 blitter(2, Uint8, ALPHA_BLIT16_555); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
672 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
673 break; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
674 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
675 /* fallthrough */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
676 \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
677 default: \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
678 general16: \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
679 blitter(2, Uint8, ALPHA_BLIT_ANY); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
680 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
681 break; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
682 \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
683 case 3: \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
684 blitter(3, Uint8, ALPHA_BLIT_ANY); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
685 break; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
686 \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
687 case 4: \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
688 if((fmt->Rmask | fmt->Gmask | fmt->Bmask) == 0x00ffffff \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
689 && (fmt->Gmask == 0xff00 || fmt->Rmask == 0xff00 \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
690 || fmt->Bmask == 0xff00)) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
691 if(alpha == 128) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
692 { \ |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
689
diff
changeset
|
693 if(SDL_HasMMX()) \ |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
694 blitter(4, Uint16, ALPHA_BLIT32_888_50MMX);\ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
695 else \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
696 blitter(4, Uint16, ALPHA_BLIT32_888_50);\ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
697 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
698 else \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
699 { \ |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
689
diff
changeset
|
700 if(SDL_HasMMX()) \ |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
701 blitter(4, Uint16, ALPHA_BLIT32_888MMX);\ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
702 else \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
703 blitter(4, Uint16, ALPHA_BLIT32_888); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
704 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
705 } else \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
706 blitter(4, Uint16, ALPHA_BLIT_ANY); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
707 break; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
708 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
709 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
710 } while(0) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
711 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
712 #else |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
713 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
714 #define CHOOSE_BLIT(blitter, alpha, fmt) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
715 do { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
716 if(alpha == 255) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
717 switch(fmt->BytesPerPixel) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
718 case 1: blitter(1, Uint8, OPAQUE_BLIT); break; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
719 case 2: blitter(2, Uint8, OPAQUE_BLIT); break; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
720 case 3: blitter(3, Uint8, OPAQUE_BLIT); break; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
721 case 4: blitter(4, Uint16, OPAQUE_BLIT); break; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
722 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
723 } else { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
724 switch(fmt->BytesPerPixel) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
725 case 1: \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
726 /* No 8bpp alpha blitting */ \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
727 break; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
728 \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
729 case 2: \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
730 switch(fmt->Rmask | fmt->Gmask | fmt->Bmask) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
731 case 0xffff: \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
732 if(fmt->Gmask == 0x07e0 \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
733 || fmt->Rmask == 0x07e0 \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
734 || fmt->Bmask == 0x07e0) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
735 if(alpha == 128) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
736 blitter(2, Uint8, ALPHA_BLIT16_565_50); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
737 else { \ |
0 | 738 blitter(2, Uint8, ALPHA_BLIT16_565); \ |
739 } \ | |
740 } else \ | |
741 goto general16; \ | |
742 break; \ | |
743 \ | |
744 case 0x7fff: \ | |
745 if(fmt->Gmask == 0x03e0 \ | |
746 || fmt->Rmask == 0x03e0 \ | |
747 || fmt->Bmask == 0x03e0) { \ | |
748 if(alpha == 128) \ | |
749 blitter(2, Uint8, ALPHA_BLIT16_555_50); \ | |
750 else { \ | |
751 blitter(2, Uint8, ALPHA_BLIT16_555); \ | |
752 } \ | |
753 break; \ | |
754 } \ | |
755 /* fallthrough */ \ | |
756 \ | |
757 default: \ | |
758 general16: \ | |
759 blitter(2, Uint8, ALPHA_BLIT_ANY); \ | |
760 } \ | |
761 break; \ | |
762 \ | |
763 case 3: \ | |
764 blitter(3, Uint8, ALPHA_BLIT_ANY); \ | |
765 break; \ | |
766 \ | |
767 case 4: \ | |
768 if((fmt->Rmask | fmt->Gmask | fmt->Bmask) == 0x00ffffff \ | |
769 && (fmt->Gmask == 0xff00 || fmt->Rmask == 0xff00 \ | |
770 || fmt->Bmask == 0xff00)) { \ | |
771 if(alpha == 128) \ | |
772 blitter(4, Uint16, ALPHA_BLIT32_888_50); \ | |
773 else \ | |
774 blitter(4, Uint16, ALPHA_BLIT32_888); \ | |
775 } else \ | |
776 blitter(4, Uint16, ALPHA_BLIT_ANY); \ | |
777 break; \ | |
778 } \ | |
779 } \ | |
780 } while(0) | |
781 | |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
782 #endif |
0 | 783 |
784 /* | |
785 * This takes care of the case when the surface is clipped on the left and/or | |
786 * right. Top clipping has already been taken care of. | |
787 */ | |
788 static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst, | |
789 Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha) | |
790 { | |
791 SDL_PixelFormat *fmt = dst->format; | |
792 | |
793 #define RLECLIPBLIT(bpp, Type, do_blit) \ | |
794 do { \ | |
795 int linecount = srcrect->h; \ | |
796 int ofs = 0; \ | |
797 int left = srcrect->x; \ | |
798 int right = left + srcrect->w; \ | |
799 dstbuf -= left * bpp; \ | |
800 for(;;) { \ | |
801 int run; \ | |
802 ofs += *(Type *)srcbuf; \ | |
803 run = ((Type *)srcbuf)[1]; \ | |
804 srcbuf += 2 * sizeof(Type); \ | |
805 if(run) { \ | |
806 /* clip to left and right borders */ \ | |
807 if(ofs < right) { \ | |
808 int start = 0; \ | |
809 int len = run; \ | |
810 int startcol; \ | |
811 if(left - ofs > 0) { \ | |
812 start = left - ofs; \ | |
813 len -= start; \ | |
814 if(len <= 0) \ | |
815 goto nocopy ## bpp ## do_blit; \ | |
816 } \ | |
817 startcol = ofs + start; \ | |
818 if(len > right - startcol) \ | |
819 len = right - startcol; \ | |
820 do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \ | |
821 len, bpp, alpha); \ | |
822 } \ | |
823 nocopy ## bpp ## do_blit: \ | |
824 srcbuf += run * bpp; \ | |
825 ofs += run; \ | |
826 } else if(!ofs) \ | |
827 break; \ | |
828 if(ofs == w) { \ | |
829 ofs = 0; \ | |
830 dstbuf += dst->pitch; \ | |
831 if(!--linecount) \ | |
832 break; \ | |
833 } \ | |
834 } \ | |
835 } while(0) | |
836 | |
837 CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt); | |
838 | |
839 #undef RLECLIPBLIT | |
840 | |
841 } | |
842 | |
843 | |
844 /* blit a colorkeyed RLE surface */ | |
845 int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
846 SDL_Surface *dst, SDL_Rect *dstrect) | |
847 { | |
848 Uint8 *dstbuf; | |
849 Uint8 *srcbuf; | |
850 int x, y; | |
851 int w = src->w; | |
852 unsigned alpha; | |
853 | |
854 /* Lock the destination if necessary */ | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
855 if ( SDL_MUSTLOCK(dst) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
856 if ( SDL_LockSurface(dst) < 0 ) { |
0 | 857 return(-1); |
858 } | |
859 } | |
860 | |
861 /* Set up the source and destination pointers */ | |
862 x = dstrect->x; | |
863 y = dstrect->y; | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
864 dstbuf = (Uint8 *)dst->pixels |
0 | 865 + y * dst->pitch + x * src->format->BytesPerPixel; |
866 srcbuf = (Uint8 *)src->map->sw_data->aux_data; | |
867 | |
868 { | |
869 /* skip lines at the top if neccessary */ | |
870 int vskip = srcrect->y; | |
871 int ofs = 0; | |
872 if(vskip) { | |
873 | |
874 #define RLESKIP(bpp, Type) \ | |
875 for(;;) { \ | |
876 int run; \ | |
877 ofs += *(Type *)srcbuf; \ | |
878 run = ((Type *)srcbuf)[1]; \ | |
879 srcbuf += sizeof(Type) * 2; \ | |
880 if(run) { \ | |
881 srcbuf += run * bpp; \ | |
882 ofs += run; \ | |
883 } else if(!ofs) \ | |
884 goto done; \ | |
885 if(ofs == w) { \ | |
886 ofs = 0; \ | |
887 if(!--vskip) \ | |
888 break; \ | |
889 } \ | |
890 } | |
891 | |
892 switch(src->format->BytesPerPixel) { | |
893 case 1: RLESKIP(1, Uint8); break; | |
894 case 2: RLESKIP(2, Uint8); break; | |
895 case 3: RLESKIP(3, Uint8); break; | |
896 case 4: RLESKIP(4, Uint16); break; | |
897 } | |
898 | |
899 #undef RLESKIP | |
900 | |
901 } | |
902 } | |
903 | |
904 alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA | |
905 ? src->format->alpha : 255; | |
906 /* if left or right edge clipping needed, call clip blit */ | |
907 if ( srcrect->x || srcrect->w != src->w ) { | |
908 RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha); | |
909 } else { | |
910 SDL_PixelFormat *fmt = src->format; | |
911 | |
912 #define RLEBLIT(bpp, Type, do_blit) \ | |
913 do { \ | |
914 int linecount = srcrect->h; \ | |
915 int ofs = 0; \ | |
916 for(;;) { \ | |
917 unsigned run; \ | |
918 ofs += *(Type *)srcbuf; \ | |
919 run = ((Type *)srcbuf)[1]; \ | |
920 srcbuf += 2 * sizeof(Type); \ | |
921 if(run) { \ | |
922 do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \ | |
923 srcbuf += run * bpp; \ | |
924 ofs += run; \ | |
925 } else if(!ofs) \ | |
926 break; \ | |
927 if(ofs == w) { \ | |
928 ofs = 0; \ | |
929 dstbuf += dst->pitch; \ | |
930 if(!--linecount) \ | |
931 break; \ | |
932 } \ | |
933 } \ | |
934 } while(0) | |
935 | |
936 CHOOSE_BLIT(RLEBLIT, alpha, fmt); | |
937 | |
938 #undef RLEBLIT | |
939 } | |
940 | |
941 done: | |
942 /* Unlock the destination if necessary */ | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
943 if ( SDL_MUSTLOCK(dst) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
944 SDL_UnlockSurface(dst); |
0 | 945 } |
946 return(0); | |
947 } | |
948 | |
949 #undef OPAQUE_BLIT | |
950 | |
951 /* | |
952 * Per-pixel blitting macros for translucent pixels: | |
953 * These use the same techniques as the per-surface blitting macros | |
954 */ | |
955 | |
956 /* | |
957 * For 32bpp pixels, we have made sure the alpha is stored in the top | |
958 * 8 bits, so proceed as usual | |
959 */ | |
960 #define BLIT_TRANSL_888(src, dst) \ | |
961 do { \ | |
962 Uint32 s = src; \ | |
963 Uint32 d = dst; \ | |
964 unsigned alpha = s >> 24; \ | |
965 Uint32 s1 = s & 0xff00ff; \ | |
966 Uint32 d1 = d & 0xff00ff; \ | |
967 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \ | |
968 s &= 0xff00; \ | |
969 d &= 0xff00; \ | |
970 d = (d + ((s - d) * alpha >> 8)) & 0xff00; \ | |
971 dst = d1 | d; \ | |
972 } while(0) | |
973 | |
974 /* | |
975 * For 16bpp pixels, we have stored the 5 most significant alpha bits in | |
976 * bits 5-10. As before, we can process all 3 RGB components at the same time. | |
977 */ | |
978 #define BLIT_TRANSL_565(src, dst) \ | |
979 do { \ | |
980 Uint32 s = src; \ | |
981 Uint32 d = dst; \ | |
982 unsigned alpha = (s & 0x3e0) >> 5; \ | |
983 s &= 0x07e0f81f; \ | |
984 d = (d | d << 16) & 0x07e0f81f; \ | |
985 d += (s - d) * alpha >> 5; \ | |
986 d &= 0x07e0f81f; \ | |
987 dst = d | d >> 16; \ | |
988 } while(0) | |
989 | |
990 #define BLIT_TRANSL_555(src, dst) \ | |
991 do { \ | |
992 Uint32 s = src; \ | |
993 Uint32 d = dst; \ | |
994 unsigned alpha = (s & 0x3e0) >> 5; \ | |
995 s &= 0x03e07c1f; \ | |
996 d = (d | d << 16) & 0x03e07c1f; \ | |
997 d += (s - d) * alpha >> 5; \ | |
998 d &= 0x03e07c1f; \ | |
999 dst = d | d >> 16; \ | |
1000 } while(0) | |
1001 | |
1002 /* used to save the destination format in the encoding. Designed to be | |
1003 macro-compatible with SDL_PixelFormat but without the unneeded fields */ | |
1004 typedef struct { | |
1005 Uint8 BytesPerPixel; | |
1006 Uint8 Rloss; | |
1007 Uint8 Gloss; | |
1008 Uint8 Bloss; | |
1009 Uint8 Rshift; | |
1010 Uint8 Gshift; | |
1011 Uint8 Bshift; | |
1012 Uint8 Ashift; | |
1013 Uint32 Rmask; | |
1014 Uint32 Gmask; | |
1015 Uint32 Bmask; | |
1016 Uint32 Amask; | |
1017 } RLEDestFormat; | |
1018 | |
1019 /* blit a pixel-alpha RLE surface clipped at the right and/or left edges */ | |
1020 static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst, | |
1021 Uint8 *dstbuf, SDL_Rect *srcrect) | |
1022 { | |
1023 SDL_PixelFormat *df = dst->format; | |
1024 /* | |
1025 * clipped blitter: Ptype is the destination pixel type, | |
1026 * Ctype the translucent count type, and do_blend the macro | |
1027 * to blend one pixel. | |
1028 */ | |
1029 #define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend) \ | |
1030 do { \ | |
1031 int linecount = srcrect->h; \ | |
1032 int left = srcrect->x; \ | |
1033 int right = left + srcrect->w; \ | |
1034 dstbuf -= left * sizeof(Ptype); \ | |
1035 do { \ | |
1036 int ofs = 0; \ | |
1037 /* blit opaque pixels on one line */ \ | |
1038 do { \ | |
1039 unsigned run; \ | |
1040 ofs += ((Ctype *)srcbuf)[0]; \ | |
1041 run = ((Ctype *)srcbuf)[1]; \ | |
1042 srcbuf += 2 * sizeof(Ctype); \ | |
1043 if(run) { \ | |
1044 /* clip to left and right borders */ \ | |
1045 int cofs = ofs; \ | |
1046 int crun = run; \ | |
1047 if(left - cofs > 0) { \ | |
1048 crun -= left - cofs; \ | |
1049 cofs = left; \ | |
1050 } \ | |
1051 if(crun > right - cofs) \ | |
1052 crun = right - cofs; \ | |
1053 if(crun > 0) \ | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
1054 PIXEL_COPY(dstbuf + cofs * sizeof(Ptype), \ |
0 | 1055 srcbuf + (cofs - ofs) * sizeof(Ptype), \ |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
1056 (unsigned)crun, sizeof(Ptype)); \ |
0 | 1057 srcbuf += run * sizeof(Ptype); \ |
1058 ofs += run; \ | |
1059 } else if(!ofs) \ | |
1060 return; \ | |
1061 } while(ofs < w); \ | |
1062 /* skip padding if necessary */ \ | |
1063 if(sizeof(Ptype) == 2) \ | |
1064 srcbuf += (unsigned long)srcbuf & 2; \ | |
1065 /* blit translucent pixels on the same line */ \ | |
1066 ofs = 0; \ | |
1067 do { \ | |
1068 unsigned run; \ | |
1069 ofs += ((Uint16 *)srcbuf)[0]; \ | |
1070 run = ((Uint16 *)srcbuf)[1]; \ | |
1071 srcbuf += 4; \ | |
1072 if(run) { \ | |
1073 /* clip to left and right borders */ \ | |
1074 int cofs = ofs; \ | |
1075 int crun = run; \ | |
1076 if(left - cofs > 0) { \ | |
1077 crun -= left - cofs; \ | |
1078 cofs = left; \ | |
1079 } \ | |
1080 if(crun > right - cofs) \ | |
1081 crun = right - cofs; \ | |
1082 if(crun > 0) { \ | |
1083 Ptype *dst = (Ptype *)dstbuf + cofs; \ | |
1084 Uint32 *src = (Uint32 *)srcbuf + (cofs - ofs); \ | |
1085 int i; \ | |
1086 for(i = 0; i < crun; i++) \ | |
1087 do_blend(src[i], dst[i]); \ | |
1088 } \ | |
1089 srcbuf += run * 4; \ | |
1090 ofs += run; \ | |
1091 } \ | |
1092 } while(ofs < w); \ | |
1093 dstbuf += dst->pitch; \ | |
1094 } while(--linecount); \ | |
1095 } while(0) | |
1096 | |
1097 switch(df->BytesPerPixel) { | |
1098 case 2: | |
1099 if(df->Gmask == 0x07e0 || df->Rmask == 0x07e0 | |
1100 || df->Bmask == 0x07e0) | |
1101 RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565); | |
1102 else | |
1103 RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555); | |
1104 break; | |
1105 case 4: | |
1106 RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888); | |
1107 break; | |
1108 } | |
1109 } | |
1110 | |
1111 /* blit a pixel-alpha RLE surface */ | |
1112 int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
1113 SDL_Surface *dst, SDL_Rect *dstrect) | |
1114 { | |
1115 int x, y; | |
1116 int w = src->w; | |
1117 Uint8 *srcbuf, *dstbuf; | |
1118 SDL_PixelFormat *df = dst->format; | |
1119 | |
1120 /* Lock the destination if necessary */ | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1121 if ( SDL_MUSTLOCK(dst) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1122 if ( SDL_LockSurface(dst) < 0 ) { |
0 | 1123 return -1; |
1124 } | |
1125 } | |
1126 | |
1127 x = dstrect->x; | |
1128 y = dstrect->y; | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1129 dstbuf = (Uint8 *)dst->pixels |
0 | 1130 + y * dst->pitch + x * df->BytesPerPixel; |
1131 srcbuf = (Uint8 *)src->map->sw_data->aux_data + sizeof(RLEDestFormat); | |
1132 | |
1133 { | |
1134 /* skip lines at the top if necessary */ | |
1135 int vskip = srcrect->y; | |
1136 if(vskip) { | |
1137 int ofs; | |
1138 if(df->BytesPerPixel == 2) { | |
1139 /* the 16/32 interleaved format */ | |
1140 do { | |
1141 /* skip opaque line */ | |
1142 ofs = 0; | |
1143 do { | |
1144 int run; | |
1145 ofs += srcbuf[0]; | |
1146 run = srcbuf[1]; | |
1147 srcbuf += 2; | |
1148 if(run) { | |
1149 srcbuf += 2 * run; | |
1150 ofs += run; | |
1151 } else if(!ofs) | |
1152 goto done; | |
1153 } while(ofs < w); | |
1154 | |
1155 /* skip padding */ | |
1156 srcbuf += (unsigned long)srcbuf & 2; | |
1157 | |
1158 /* skip translucent line */ | |
1159 ofs = 0; | |
1160 do { | |
1161 int run; | |
1162 ofs += ((Uint16 *)srcbuf)[0]; | |
1163 run = ((Uint16 *)srcbuf)[1]; | |
1164 srcbuf += 4 * (run + 1); | |
1165 ofs += run; | |
1166 } while(ofs < w); | |
1167 } while(--vskip); | |
1168 } else { | |
1169 /* the 32/32 interleaved format */ | |
1170 vskip <<= 1; /* opaque and translucent have same format */ | |
1171 do { | |
1172 ofs = 0; | |
1173 do { | |
1174 int run; | |
1175 ofs += ((Uint16 *)srcbuf)[0]; | |
1176 run = ((Uint16 *)srcbuf)[1]; | |
1177 srcbuf += 4; | |
1178 if(run) { | |
1179 srcbuf += 4 * run; | |
1180 ofs += run; | |
1181 } else if(!ofs) | |
1182 goto done; | |
1183 } while(ofs < w); | |
1184 } while(--vskip); | |
1185 } | |
1186 } | |
1187 } | |
1188 | |
1189 /* if left or right edge clipping needed, call clip blit */ | |
1190 if(srcrect->x || srcrect->w != src->w) { | |
1191 RLEAlphaClipBlit(w, srcbuf, dst, dstbuf, srcrect); | |
1192 } else { | |
1193 | |
1194 /* | |
1195 * non-clipped blitter. Ptype is the destination pixel type, | |
1196 * Ctype the translucent count type, and do_blend the | |
1197 * macro to blend one pixel. | |
1198 */ | |
1199 #define RLEALPHABLIT(Ptype, Ctype, do_blend) \ | |
1200 do { \ | |
1201 int linecount = srcrect->h; \ | |
1202 do { \ | |
1203 int ofs = 0; \ | |
1204 /* blit opaque pixels on one line */ \ | |
1205 do { \ | |
1206 unsigned run; \ | |
1207 ofs += ((Ctype *)srcbuf)[0]; \ | |
1208 run = ((Ctype *)srcbuf)[1]; \ | |
1209 srcbuf += 2 * sizeof(Ctype); \ | |
1210 if(run) { \ | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
1211 PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
1212 run, sizeof(Ptype)); \ |
0 | 1213 srcbuf += run * sizeof(Ptype); \ |
1214 ofs += run; \ | |
1215 } else if(!ofs) \ | |
1216 goto done; \ | |
1217 } while(ofs < w); \ | |
1218 /* skip padding if necessary */ \ | |
1219 if(sizeof(Ptype) == 2) \ | |
1220 srcbuf += (unsigned long)srcbuf & 2; \ | |
1221 /* blit translucent pixels on the same line */ \ | |
1222 ofs = 0; \ | |
1223 do { \ | |
1224 unsigned run; \ | |
1225 ofs += ((Uint16 *)srcbuf)[0]; \ | |
1226 run = ((Uint16 *)srcbuf)[1]; \ | |
1227 srcbuf += 4; \ | |
1228 if(run) { \ | |
1229 Ptype *dst = (Ptype *)dstbuf + ofs; \ | |
1230 unsigned i; \ | |
1231 for(i = 0; i < run; i++) { \ | |
1232 Uint32 src = *(Uint32 *)srcbuf; \ | |
1233 do_blend(src, *dst); \ | |
1234 srcbuf += 4; \ | |
1235 dst++; \ | |
1236 } \ | |
1237 ofs += run; \ | |
1238 } \ | |
1239 } while(ofs < w); \ | |
1240 dstbuf += dst->pitch; \ | |
1241 } while(--linecount); \ | |
1242 } while(0) | |
1243 | |
1244 switch(df->BytesPerPixel) { | |
1245 case 2: | |
1246 if(df->Gmask == 0x07e0 || df->Rmask == 0x07e0 | |
1247 || df->Bmask == 0x07e0) | |
1248 RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565); | |
1249 else | |
1250 RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555); | |
1251 break; | |
1252 case 4: | |
1253 RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888); | |
1254 break; | |
1255 } | |
1256 } | |
1257 | |
1258 done: | |
1259 /* Unlock the destination if necessary */ | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1260 if ( SDL_MUSTLOCK(dst) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1261 SDL_UnlockSurface(dst); |
0 | 1262 } |
1263 return 0; | |
1264 } | |
1265 | |
1266 /* | |
1267 * Auxiliary functions: | |
1268 * The encoding functions take 32bpp rgb + a, and | |
1269 * return the number of bytes copied to the destination. | |
1270 * The decoding functions copy to 32bpp rgb + a, and | |
1271 * return the number of bytes copied from the source. | |
1272 * These are only used in the encoder and un-RLE code and are therefore not | |
1273 * highly optimised. | |
1274 */ | |
1275 | |
1276 /* encode 32bpp rgb + a into 16bpp rgb, losing alpha */ | |
1277 static int copy_opaque_16(void *dst, Uint32 *src, int n, | |
1278 SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt) | |
1279 { | |
1280 int i; | |
1281 Uint16 *d = dst; | |
1282 for(i = 0; i < n; i++) { | |
1283 unsigned r, g, b; | |
1284 RGB_FROM_PIXEL(*src, sfmt, r, g, b); | |
1285 PIXEL_FROM_RGB(*d, dfmt, r, g, b); | |
1286 src++; | |
1287 d++; | |
1288 } | |
1289 return n * 2; | |
1290 } | |
1291 | |
1292 /* decode opaque pixels from 16bpp to 32bpp rgb + a */ | |
1293 static int uncopy_opaque_16(Uint32 *dst, void *src, int n, | |
1294 RLEDestFormat *sfmt, SDL_PixelFormat *dfmt) | |
1295 { | |
1296 int i; | |
1297 Uint16 *s = src; | |
1298 unsigned alpha = dfmt->Amask ? 255 : 0; | |
1299 for(i = 0; i < n; i++) { | |
1300 unsigned r, g, b; | |
1301 RGB_FROM_PIXEL(*s, sfmt, r, g, b); | |
1302 PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha); | |
1303 s++; | |
1304 dst++; | |
1305 } | |
1306 return n * 2; | |
1307 } | |
1308 | |
1309 | |
1310 | |
1311 /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 565 */ | |
1312 static int copy_transl_565(void *dst, Uint32 *src, int n, | |
1313 SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt) | |
1314 { | |
1315 int i; | |
1316 Uint32 *d = dst; | |
1317 for(i = 0; i < n; i++) { | |
1318 unsigned r, g, b, a; | |
1319 Uint16 pix; | |
1320 RGBA_FROM_8888(*src, sfmt, r, g, b, a); | |
1321 PIXEL_FROM_RGB(pix, dfmt, r, g, b); | |
1322 *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0); | |
1323 src++; | |
1324 d++; | |
1325 } | |
1326 return n * 4; | |
1327 } | |
1328 | |
1329 /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 555 */ | |
1330 static int copy_transl_555(void *dst, Uint32 *src, int n, | |
1331 SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt) | |
1332 { | |
1333 int i; | |
1334 Uint32 *d = dst; | |
1335 for(i = 0; i < n; i++) { | |
1336 unsigned r, g, b, a; | |
1337 Uint16 pix; | |
1338 RGBA_FROM_8888(*src, sfmt, r, g, b, a); | |
1339 PIXEL_FROM_RGB(pix, dfmt, r, g, b); | |
1340 *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0); | |
1341 src++; | |
1342 d++; | |
1343 } | |
1344 return n * 4; | |
1345 } | |
1346 | |
1347 /* decode translucent pixels from 32bpp GORAB to 32bpp rgb + a */ | |
1348 static int uncopy_transl_16(Uint32 *dst, void *src, int n, | |
1349 RLEDestFormat *sfmt, SDL_PixelFormat *dfmt) | |
1350 { | |
1351 int i; | |
1352 Uint32 *s = src; | |
1353 for(i = 0; i < n; i++) { | |
1354 unsigned r, g, b, a; | |
1355 Uint32 pix = *s++; | |
1356 a = (pix & 0x3e0) >> 2; | |
1357 pix = (pix & ~0x3e0) | pix >> 16; | |
1358 RGB_FROM_PIXEL(pix, sfmt, r, g, b); | |
1359 PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a); | |
1360 dst++; | |
1361 } | |
1362 return n * 4; | |
1363 } | |
1364 | |
1365 /* encode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */ | |
1366 static int copy_32(void *dst, Uint32 *src, int n, | |
1367 SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt) | |
1368 { | |
1369 int i; | |
1370 Uint32 *d = dst; | |
1371 for(i = 0; i < n; i++) { | |
1372 unsigned r, g, b, a; | |
1373 Uint32 pixel; | |
1374 RGBA_FROM_8888(*src, sfmt, r, g, b, a); | |
1375 PIXEL_FROM_RGB(pixel, dfmt, r, g, b); | |
1376 *d++ = pixel | a << 24; | |
1377 src++; | |
1378 } | |
1379 return n * 4; | |
1380 } | |
1381 | |
1382 /* decode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */ | |
1383 static int uncopy_32(Uint32 *dst, void *src, int n, | |
1384 RLEDestFormat *sfmt, SDL_PixelFormat *dfmt) | |
1385 { | |
1386 int i; | |
1387 Uint32 *s = src; | |
1388 for(i = 0; i < n; i++) { | |
1389 unsigned r, g, b, a; | |
1390 Uint32 pixel = *s++; | |
1391 RGB_FROM_PIXEL(pixel, sfmt, r, g, b); | |
1392 a = pixel >> 24; | |
1393 PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a); | |
1394 dst++; | |
1395 } | |
1396 return n * 4; | |
1397 } | |
1398 | |
1399 #define ISOPAQUE(pixel, fmt) ((((pixel) & fmt->Amask) >> fmt->Ashift) == 255) | |
1400 | |
1401 #define ISTRANSL(pixel, fmt) \ | |
1402 ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U) | |
1403 | |
1404 /* convert surface to be quickly alpha-blittable onto dest, if possible */ | |
1405 static int RLEAlphaSurface(SDL_Surface *surface) | |
1406 { | |
1407 SDL_Surface *dest; | |
1408 SDL_PixelFormat *df; | |
1409 int maxsize = 0; | |
1410 int max_opaque_run; | |
1411 int max_transl_run = 65535; | |
1412 unsigned masksum; | |
1413 Uint8 *rlebuf, *dst; | |
1414 int (*copy_opaque)(void *, Uint32 *, int, | |
1415 SDL_PixelFormat *, SDL_PixelFormat *); | |
1416 int (*copy_transl)(void *, Uint32 *, int, | |
1417 SDL_PixelFormat *, SDL_PixelFormat *); | |
1418 | |
1419 dest = surface->map->dst; | |
1420 if(!dest) | |
1421 return -1; | |
1422 df = dest->format; | |
1423 if(surface->format->BitsPerPixel != 32) | |
1424 return -1; /* only 32bpp source supported */ | |
1425 | |
1426 /* find out whether the destination is one we support, | |
1427 and determine the max size of the encoded result */ | |
1428 masksum = df->Rmask | df->Gmask | df->Bmask; | |
1429 switch(df->BytesPerPixel) { | |
1430 case 2: | |
1431 /* 16bpp: only support 565 and 555 formats */ | |
1432 switch(masksum) { | |
1433 case 0xffff: | |
1434 if(df->Gmask == 0x07e0 | |
1435 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) { | |
1436 copy_opaque = copy_opaque_16; | |
1437 copy_transl = copy_transl_565; | |
1438 } else | |
1439 return -1; | |
1440 break; | |
1441 case 0x7fff: | |
1442 if(df->Gmask == 0x03e0 | |
1443 || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) { | |
1444 copy_opaque = copy_opaque_16; | |
1445 copy_transl = copy_transl_555; | |
1446 } else | |
1447 return -1; | |
1448 break; | |
1449 default: | |
1450 return -1; | |
1451 } | |
1452 max_opaque_run = 255; /* runs stored as bytes */ | |
1453 | |
1454 /* worst case is alternating opaque and translucent pixels, | |
1455 with room for alignment padding between lines */ | |
1456 maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2; | |
1457 break; | |
1458 case 4: | |
1459 if(masksum != 0x00ffffff) | |
1460 return -1; /* requires unused high byte */ | |
1461 copy_opaque = copy_32; | |
1462 copy_transl = copy_32; | |
1463 max_opaque_run = 255; /* runs stored as short ints */ | |
1464 | |
1465 /* worst case is alternating opaque and translucent pixels */ | |
1466 maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4; | |
1467 break; | |
1468 default: | |
1469 return -1; /* anything else unsupported right now */ | |
1470 } | |
1471 | |
1472 maxsize += sizeof(RLEDestFormat); | |
1473 rlebuf = (Uint8 *)malloc(maxsize); | |
1474 if(!rlebuf) { | |
1475 SDL_OutOfMemory(); | |
1476 return -1; | |
1477 } | |
1478 { | |
1479 /* save the destination format so we can undo the encoding later */ | |
1480 RLEDestFormat *r = (RLEDestFormat *)rlebuf; | |
1481 r->BytesPerPixel = df->BytesPerPixel; | |
1482 r->Rloss = df->Rloss; | |
1483 r->Gloss = df->Gloss; | |
1484 r->Bloss = df->Bloss; | |
1485 r->Rshift = df->Rshift; | |
1486 r->Gshift = df->Gshift; | |
1487 r->Bshift = df->Bshift; | |
1488 r->Ashift = df->Ashift; | |
1489 r->Rmask = df->Rmask; | |
1490 r->Gmask = df->Gmask; | |
1491 r->Bmask = df->Bmask; | |
1492 r->Amask = df->Amask; | |
1493 } | |
1494 dst = rlebuf + sizeof(RLEDestFormat); | |
1495 | |
1496 /* Do the actual encoding */ | |
1497 { | |
1498 int x, y; | |
1499 int h = surface->h, w = surface->w; | |
1500 SDL_PixelFormat *sf = surface->format; | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1501 Uint32 *src = (Uint32 *)surface->pixels; |
0 | 1502 Uint8 *lastline = dst; /* end of last non-blank line */ |
1503 | |
1504 /* opaque counts are 8 or 16 bits, depending on target depth */ | |
1505 #define ADD_OPAQUE_COUNTS(n, m) \ | |
1506 if(df->BytesPerPixel == 4) { \ | |
1507 ((Uint16 *)dst)[0] = n; \ | |
1508 ((Uint16 *)dst)[1] = m; \ | |
1509 dst += 4; \ | |
1510 } else { \ | |
1511 dst[0] = n; \ | |
1512 dst[1] = m; \ | |
1513 dst += 2; \ | |
1514 } | |
1515 | |
1516 /* translucent counts are always 16 bit */ | |
1517 #define ADD_TRANSL_COUNTS(n, m) \ | |
1518 (((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4) | |
1519 | |
1520 for(y = 0; y < h; y++) { | |
1521 int runstart, skipstart; | |
1522 int blankline = 0; | |
1523 /* First encode all opaque pixels of a scan line */ | |
1524 x = 0; | |
1525 do { | |
1526 int run, skip, len; | |
1527 skipstart = x; | |
1528 while(x < w && !ISOPAQUE(src[x], sf)) | |
1529 x++; | |
1530 runstart = x; | |
1531 while(x < w && ISOPAQUE(src[x], sf)) | |
1532 x++; | |
1533 skip = runstart - skipstart; | |
1534 if(skip == w) | |
1535 blankline = 1; | |
1536 run = x - runstart; | |
1537 while(skip > max_opaque_run) { | |
1538 ADD_OPAQUE_COUNTS(max_opaque_run, 0); | |
1539 skip -= max_opaque_run; | |
1540 } | |
1541 len = MIN(run, max_opaque_run); | |
1542 ADD_OPAQUE_COUNTS(skip, len); | |
1543 dst += copy_opaque(dst, src + runstart, len, sf, df); | |
1544 runstart += len; | |
1545 run -= len; | |
1546 while(run) { | |
1547 len = MIN(run, max_opaque_run); | |
1548 ADD_OPAQUE_COUNTS(0, len); | |
1549 dst += copy_opaque(dst, src + runstart, len, sf, df); | |
1550 runstart += len; | |
1551 run -= len; | |
1552 } | |
1553 } while(x < w); | |
1554 | |
1555 /* Make sure the next output address is 32-bit aligned */ | |
1556 dst += (unsigned long)dst & 2; | |
1557 | |
1558 /* Next, encode all translucent pixels of the same scan line */ | |
1559 x = 0; | |
1560 do { | |
1561 int run, skip, len; | |
1562 skipstart = x; | |
1563 while(x < w && !ISTRANSL(src[x], sf)) | |
1564 x++; | |
1565 runstart = x; | |
1566 while(x < w && ISTRANSL(src[x], sf)) | |
1567 x++; | |
1568 skip = runstart - skipstart; | |
1569 blankline &= (skip == w); | |
1570 run = x - runstart; | |
1571 while(skip > max_transl_run) { | |
1572 ADD_TRANSL_COUNTS(max_transl_run, 0); | |
1573 skip -= max_transl_run; | |
1574 } | |
1575 len = MIN(run, max_transl_run); | |
1576 ADD_TRANSL_COUNTS(skip, len); | |
1577 dst += copy_transl(dst, src + runstart, len, sf, df); | |
1578 runstart += len; | |
1579 run -= len; | |
1580 while(run) { | |
1581 len = MIN(run, max_transl_run); | |
1582 ADD_TRANSL_COUNTS(0, len); | |
1583 dst += copy_transl(dst, src + runstart, len, sf, df); | |
1584 runstart += len; | |
1585 run -= len; | |
1586 } | |
1587 if(!blankline) | |
1588 lastline = dst; | |
1589 } while(x < w); | |
1590 | |
1591 src += surface->pitch >> 2; | |
1592 } | |
1593 dst = lastline; /* back up past trailing blank lines */ | |
1594 ADD_OPAQUE_COUNTS(0, 0); | |
1595 } | |
1596 | |
1597 #undef ADD_OPAQUE_COUNTS | |
1598 #undef ADD_TRANSL_COUNTS | |
1599 | |
1600 /* Now that we have it encoded, release the original pixels */ | |
1601 if((surface->flags & SDL_PREALLOC) != SDL_PREALLOC | |
1602 && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { | |
1603 free( surface->pixels ); | |
1604 surface->pixels = NULL; | |
1605 } | |
1606 | |
1607 /* realloc the buffer to release unused memory */ | |
1608 { | |
1609 Uint8 *p = realloc(rlebuf, dst - rlebuf); | |
1610 if(!p) | |
1611 p = rlebuf; | |
1612 surface->map->sw_data->aux_data = p; | |
1613 } | |
1614 | |
1615 return 0; | |
1616 } | |
1617 | |
1618 static Uint32 getpix_8(Uint8 *srcbuf) | |
1619 { | |
1620 return *srcbuf; | |
1621 } | |
1622 | |
1623 static Uint32 getpix_16(Uint8 *srcbuf) | |
1624 { | |
1625 return *(Uint16 *)srcbuf; | |
1626 } | |
1627 | |
1628 static Uint32 getpix_24(Uint8 *srcbuf) | |
1629 { | |
1155
91569ec25acd
Fixed some compiler warnings about "unreachable code" on Watcom C.
Ryan C. Gordon <icculus@icculus.org>
parents:
944
diff
changeset
|
1630 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
91569ec25acd
Fixed some compiler warnings about "unreachable code" on Watcom C.
Ryan C. Gordon <icculus@icculus.org>
parents:
944
diff
changeset
|
1631 return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16); |
91569ec25acd
Fixed some compiler warnings about "unreachable code" on Watcom C.
Ryan C. Gordon <icculus@icculus.org>
parents:
944
diff
changeset
|
1632 #else |
91569ec25acd
Fixed some compiler warnings about "unreachable code" on Watcom C.
Ryan C. Gordon <icculus@icculus.org>
parents:
944
diff
changeset
|
1633 return (srcbuf[0] << 16) + (srcbuf[1] << 8) + srcbuf[2]; |
91569ec25acd
Fixed some compiler warnings about "unreachable code" on Watcom C.
Ryan C. Gordon <icculus@icculus.org>
parents:
944
diff
changeset
|
1634 #endif |
0 | 1635 } |
1636 | |
1637 static Uint32 getpix_32(Uint8 *srcbuf) | |
1638 { | |
1639 return *(Uint32 *)srcbuf; | |
1640 } | |
1641 | |
1642 typedef Uint32 (*getpix_func)(Uint8 *); | |
1643 | |
1644 static getpix_func getpixes[4] = { | |
1645 getpix_8, getpix_16, getpix_24, getpix_32 | |
1646 }; | |
1647 | |
1648 static int RLEColorkeySurface(SDL_Surface *surface) | |
1649 { | |
1650 Uint8 *rlebuf, *dst; | |
1651 int maxn; | |
1652 int y; | |
1653 Uint8 *srcbuf, *curbuf, *lastline; | |
1654 int maxsize = 0; | |
1655 int skip, run; | |
1656 int bpp = surface->format->BytesPerPixel; | |
1657 getpix_func getpix; | |
1658 Uint32 ckey, rgbmask; | |
1659 int w, h; | |
1660 | |
1661 /* calculate the worst case size for the compressed surface */ | |
1662 switch(bpp) { | |
1663 case 1: | |
1664 /* worst case is alternating opaque and transparent pixels, | |
1665 starting with an opaque pixel */ | |
1666 maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2; | |
1667 break; | |
1668 case 2: | |
1669 case 3: | |
1670 /* worst case is solid runs, at most 255 pixels wide */ | |
1671 maxsize = surface->h * (2 * (surface->w / 255 + 1) | |
1672 + surface->w * bpp) + 2; | |
1673 break; | |
1674 case 4: | |
1675 /* worst case is solid runs, at most 65535 pixels wide */ | |
1676 maxsize = surface->h * (4 * (surface->w / 65535 + 1) | |
1677 + surface->w * 4) + 4; | |
1678 break; | |
1679 } | |
1680 | |
1681 rlebuf = (Uint8 *)malloc(maxsize); | |
1682 if ( rlebuf == NULL ) { | |
1683 SDL_OutOfMemory(); | |
1684 return(-1); | |
1685 } | |
1686 | |
1687 /* Set up the conversion */ | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1688 srcbuf = (Uint8 *)surface->pixels; |
0 | 1689 curbuf = srcbuf; |
1690 maxn = bpp == 4 ? 65535 : 255; | |
1691 skip = run = 0; | |
1692 dst = rlebuf; | |
1693 rgbmask = ~surface->format->Amask; | |
1694 ckey = surface->format->colorkey & rgbmask; | |
1695 lastline = dst; | |
1696 getpix = getpixes[bpp - 1]; | |
1697 w = surface->w; | |
1698 h = surface->h; | |
1699 | |
1700 #define ADD_COUNTS(n, m) \ | |
1701 if(bpp == 4) { \ | |
1702 ((Uint16 *)dst)[0] = n; \ | |
1703 ((Uint16 *)dst)[1] = m; \ | |
1704 dst += 4; \ | |
1705 } else { \ | |
1706 dst[0] = n; \ | |
1707 dst[1] = m; \ | |
1708 dst += 2; \ | |
1709 } | |
1710 | |
1711 for(y = 0; y < h; y++) { | |
1712 int x = 0; | |
1713 int blankline = 0; | |
1714 do { | |
1715 int run, skip, len; | |
1716 int runstart; | |
1717 int skipstart = x; | |
1718 | |
1719 /* find run of transparent, then opaque pixels */ | |
1720 while(x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey) | |
1721 x++; | |
1722 runstart = x; | |
1723 while(x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey) | |
1724 x++; | |
1725 skip = runstart - skipstart; | |
1726 if(skip == w) | |
1727 blankline = 1; | |
1728 run = x - runstart; | |
1729 | |
1730 /* encode segment */ | |
1731 while(skip > maxn) { | |
1732 ADD_COUNTS(maxn, 0); | |
1733 skip -= maxn; | |
1734 } | |
1735 len = MIN(run, maxn); | |
1736 ADD_COUNTS(skip, len); | |
1737 memcpy(dst, srcbuf + runstart * bpp, len * bpp); | |
1738 dst += len * bpp; | |
1739 run -= len; | |
1740 runstart += len; | |
1741 while(run) { | |
1742 len = MIN(run, maxn); | |
1743 ADD_COUNTS(0, len); | |
1744 memcpy(dst, srcbuf + runstart * bpp, len * bpp); | |
1745 dst += len * bpp; | |
1746 runstart += len; | |
1747 run -= len; | |
1748 } | |
1749 if(!blankline) | |
1750 lastline = dst; | |
1751 } while(x < w); | |
1752 | |
1753 srcbuf += surface->pitch; | |
1754 } | |
1755 dst = lastline; /* back up bast trailing blank lines */ | |
1756 ADD_COUNTS(0, 0); | |
1757 | |
1758 #undef ADD_COUNTS | |
1759 | |
1760 /* Now that we have it encoded, release the original pixels */ | |
1761 if((surface->flags & SDL_PREALLOC) != SDL_PREALLOC | |
1762 && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { | |
1763 free( surface->pixels ); | |
1764 surface->pixels = NULL; | |
1765 } | |
1766 | |
1767 /* realloc the buffer to release unused memory */ | |
1768 { | |
1769 /* If realloc returns NULL, the original block is left intact */ | |
1770 Uint8 *p = realloc(rlebuf, dst - rlebuf); | |
1771 if(!p) | |
1772 p = rlebuf; | |
1773 surface->map->sw_data->aux_data = p; | |
1774 } | |
1775 | |
1776 return(0); | |
1777 } | |
1778 | |
1779 int SDL_RLESurface(SDL_Surface *surface) | |
1780 { | |
1781 int retcode; | |
1782 | |
1783 /* Clear any previous RLE conversion */ | |
1784 if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { | |
1785 SDL_UnRLESurface(surface, 1); | |
1786 } | |
1787 | |
1788 /* We don't support RLE encoding of bitmaps */ | |
1789 if ( surface->format->BitsPerPixel < 8 ) { | |
1790 return(-1); | |
1791 } | |
1792 | |
1793 /* Lock the surface if it's in hardware */ | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1794 if ( SDL_MUSTLOCK(surface) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1795 if ( SDL_LockSurface(surface) < 0 ) { |
0 | 1796 return(-1); |
1797 } | |
1798 } | |
1799 | |
1800 /* Encode */ | |
1801 if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { | |
1802 retcode = RLEColorkeySurface(surface); | |
1803 } else { | |
1804 if((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA | |
1805 && surface->format->Amask != 0) | |
1806 retcode = RLEAlphaSurface(surface); | |
1807 else | |
1808 retcode = -1; /* no RLE for per-surface alpha sans ckey */ | |
1809 } | |
1810 | |
1811 /* Unlock the surface if it's in hardware */ | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1812 if ( SDL_MUSTLOCK(surface) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1813 SDL_UnlockSurface(surface); |
0 | 1814 } |
1815 | |
1816 if(retcode < 0) | |
1817 return -1; | |
1818 | |
1819 /* The surface is now accelerated */ | |
1820 surface->flags |= SDL_RLEACCEL; | |
1821 | |
1822 return(0); | |
1823 } | |
1824 | |
1825 /* | |
1826 * Un-RLE a surface with pixel alpha | |
1827 * This may not give back exactly the image before RLE-encoding; all | |
1828 * completely transparent pixels will be lost, and colour and alpha depth | |
1829 * may have been reduced (when encoding for 16bpp targets). | |
1830 */ | |
944
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1831 static SDL_bool UnRLEAlpha(SDL_Surface *surface) |
0 | 1832 { |
1833 Uint8 *srcbuf; | |
1834 Uint32 *dst; | |
1835 SDL_PixelFormat *sf = surface->format; | |
1836 RLEDestFormat *df = surface->map->sw_data->aux_data; | |
1837 int (*uncopy_opaque)(Uint32 *, void *, int, | |
1838 RLEDestFormat *, SDL_PixelFormat *); | |
1839 int (*uncopy_transl)(Uint32 *, void *, int, | |
1840 RLEDestFormat *, SDL_PixelFormat *); | |
1841 int w = surface->w; | |
1842 int bpp = df->BytesPerPixel; | |
1843 | |
1844 if(bpp == 2) { | |
1845 uncopy_opaque = uncopy_opaque_16; | |
1846 uncopy_transl = uncopy_transl_16; | |
1847 } else { | |
1848 uncopy_opaque = uncopy_transl = uncopy_32; | |
1849 } | |
1850 | |
1851 surface->pixels = malloc(surface->h * surface->pitch); | |
944
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1852 if ( !surface->pixels ) { |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1853 return(SDL_FALSE); |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1854 } |
0 | 1855 /* fill background with transparent pixels */ |
1856 memset(surface->pixels, 0, surface->h * surface->pitch); | |
1857 | |
1858 dst = surface->pixels; | |
1859 srcbuf = (Uint8 *)(df + 1); | |
1860 for(;;) { | |
1861 /* copy opaque pixels */ | |
1862 int ofs = 0; | |
1863 do { | |
1864 unsigned run; | |
1865 if(bpp == 2) { | |
1866 ofs += srcbuf[0]; | |
1867 run = srcbuf[1]; | |
1868 srcbuf += 2; | |
1869 } else { | |
1870 ofs += ((Uint16 *)srcbuf)[0]; | |
1871 run = ((Uint16 *)srcbuf)[1]; | |
1872 srcbuf += 4; | |
1873 } | |
1874 if(run) { | |
1875 srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf); | |
1876 ofs += run; | |
1877 } else if(!ofs) | |
944
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1878 return(SDL_TRUE); |
0 | 1879 } while(ofs < w); |
1880 | |
1881 /* skip padding if needed */ | |
1882 if(bpp == 2) | |
1883 srcbuf += (unsigned long)srcbuf & 2; | |
1884 | |
1885 /* copy translucent pixels */ | |
1886 ofs = 0; | |
1887 do { | |
1888 unsigned run; | |
1889 ofs += ((Uint16 *)srcbuf)[0]; | |
1890 run = ((Uint16 *)srcbuf)[1]; | |
1891 srcbuf += 4; | |
1892 if(run) { | |
1893 srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf); | |
1894 ofs += run; | |
1895 } | |
1896 } while(ofs < w); | |
1897 dst += surface->pitch >> 2; | |
1898 } | |
944
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1899 /* Make the compiler happy */ |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1900 return(SDL_TRUE); |
0 | 1901 } |
1902 | |
1903 void SDL_UnRLESurface(SDL_Surface *surface, int recode) | |
1904 { | |
1905 if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { | |
1906 surface->flags &= ~SDL_RLEACCEL; | |
1907 | |
1908 if(recode && (surface->flags & SDL_PREALLOC) != SDL_PREALLOC | |
1909 && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { | |
1910 if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { | |
1911 SDL_Rect full; | |
1912 unsigned alpha_flag; | |
1913 | |
1914 /* re-create the original surface */ | |
1915 surface->pixels = malloc(surface->h * surface->pitch); | |
944
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1916 if ( !surface->pixels ) { |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1917 /* Oh crap... */ |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1918 surface->flags |= SDL_RLEACCEL; |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1919 return; |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1920 } |
0 | 1921 |
1922 /* fill it with the background colour */ | |
1923 SDL_FillRect(surface, NULL, surface->format->colorkey); | |
1924 | |
1925 /* now render the encoded surface */ | |
1926 full.x = full.y = 0; | |
1927 full.w = surface->w; | |
1928 full.h = surface->h; | |
1929 alpha_flag = surface->flags & SDL_SRCALPHA; | |
1930 surface->flags &= ~SDL_SRCALPHA; /* opaque blit */ | |
1931 SDL_RLEBlit(surface, &full, surface, &full); | |
1932 surface->flags |= alpha_flag; | |
944
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1933 } else { |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1934 if ( !UnRLEAlpha(surface) ) { |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1935 /* Oh crap... */ |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1936 surface->flags |= SDL_RLEACCEL; |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1937 return; |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1938 } |
cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
880
diff
changeset
|
1939 } |
0 | 1940 } |
1941 | |
1942 if ( surface->map && surface->map->sw_data->aux_data ) { | |
1943 free(surface->map->sw_data->aux_data); | |
1944 surface->map->sw_data->aux_data = NULL; | |
1945 } | |
1946 } | |
1947 } | |
1948 | |
1949 |