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