Mercurial > sdl-ios-xcode
annotate src/video/SDL_blit.h @ 1071:24470ffe8ee4
SDL will center surface on screen for us
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Mon, 06 Jun 2005 16:36:18 +0000 |
parents | ffaaf7ecf685 |
children | 2651158f59b8 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
689
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
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 | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
163
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #ifndef _SDL_blit_h | |
29 #define _SDL_blit_h | |
30 | |
31 #include "SDL_endian.h" | |
32 | |
33 /* The structure passed to the low level blit functions */ | |
34 typedef struct { | |
35 Uint8 *s_pixels; | |
36 int s_width; | |
37 int s_height; | |
38 int s_skip; | |
39 Uint8 *d_pixels; | |
40 int d_width; | |
41 int d_height; | |
42 int d_skip; | |
43 void *aux_data; | |
44 SDL_PixelFormat *src; | |
45 Uint8 *table; | |
46 SDL_PixelFormat *dst; | |
47 } SDL_BlitInfo; | |
48 | |
49 /* The type definition for the low level blit functions */ | |
50 typedef void (*SDL_loblit)(SDL_BlitInfo *info); | |
51 | |
52 /* This is the private info structure for software accelerated blits */ | |
53 struct private_swaccel { | |
54 SDL_loblit blit; | |
55 void *aux_data; | |
56 }; | |
57 | |
58 /* Blit mapping definition */ | |
59 typedef struct SDL_BlitMap { | |
60 SDL_Surface *dst; | |
61 int identity; | |
62 Uint8 *table; | |
63 SDL_blit hw_blit; | |
64 SDL_blit sw_blit; | |
65 struct private_hwaccel *hw_data; | |
66 struct private_swaccel *sw_data; | |
67 | |
68 /* the version count matches the destination; mismatch indicates | |
69 an invalid mapping */ | |
70 unsigned int format_version; | |
71 } SDL_BlitMap; | |
72 | |
73 | |
74 /* Functions found in SDL_blit.c */ | |
75 extern int SDL_CalculateBlit(SDL_Surface *surface); | |
76 | |
77 /* Functions found in SDL_blit_{0,1,N,A}.c */ | |
78 extern SDL_loblit SDL_CalculateBlit0(SDL_Surface *surface, int complex); | |
79 extern SDL_loblit SDL_CalculateBlit1(SDL_Surface *surface, int complex); | |
80 extern SDL_loblit SDL_CalculateBlitN(SDL_Surface *surface, int complex); | |
81 extern SDL_loblit SDL_CalculateAlphaBlit(SDL_Surface *surface, int complex); | |
82 | |
83 /* | |
84 * Useful macros for blitting routines | |
85 */ | |
86 | |
87 #define FORMAT_EQUAL(A, B) \ | |
88 ((A)->BitsPerPixel == (B)->BitsPerPixel \ | |
89 && ((A)->Rmask == (B)->Rmask) && ((A)->Amask == (B)->Amask)) | |
90 | |
91 /* Load pixel of the specified format from a buffer and get its R-G-B values */ | |
92 /* FIXME: rescale values to 0..255 here? */ | |
93 #define RGB_FROM_PIXEL(pixel, fmt, r, g, b) \ | |
94 { \ | |
95 r = (((pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss); \ | |
96 g = (((pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss); \ | |
97 b = (((pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss); \ | |
98 } | |
99 #define RGB_FROM_RGB565(pixel, r, g, b) \ | |
100 { \ | |
101 r = (((pixel&0xF800)>>11)<<3); \ | |
102 g = (((pixel&0x07E0)>>5)<<2); \ | |
103 b = ((pixel&0x001F)<<3); \ | |
104 } | |
105 #define RGB_FROM_RGB555(pixel, r, g, b) \ | |
106 { \ | |
107 r = (((pixel&0x7C00)>>10)<<3); \ | |
108 g = (((pixel&0x03E0)>>5)<<3); \ | |
109 b = ((pixel&0x001F)<<3); \ | |
110 } | |
111 #define RGB_FROM_RGB888(pixel, r, g, b) \ | |
112 { \ | |
113 r = ((pixel&0xFF0000)>>16); \ | |
114 g = ((pixel&0xFF00)>>8); \ | |
115 b = (pixel&0xFF); \ | |
116 } | |
117 #define RETRIEVE_RGB_PIXEL(buf, bpp, pixel) \ | |
118 do { \ | |
119 switch (bpp) { \ | |
120 case 2: \ | |
121 pixel = *((Uint16 *)(buf)); \ | |
122 break; \ | |
123 \ | |
124 case 3: { \ | |
125 Uint8 *B = (Uint8 *)(buf); \ | |
126 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ | |
127 pixel = B[0] + (B[1] << 8) + (B[2] << 16); \ | |
128 } else { \ | |
129 pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \ | |
130 } \ | |
131 } \ | |
132 break; \ | |
133 \ | |
134 case 4: \ | |
135 pixel = *((Uint32 *)(buf)); \ | |
136 break; \ | |
137 \ | |
138 default: \ | |
139 pixel = 0; /* appease gcc */ \ | |
140 break; \ | |
141 } \ | |
142 } while(0) | |
143 | |
144 #define DISEMBLE_RGB(buf, bpp, fmt, pixel, r, g, b) \ | |
145 do { \ | |
146 switch (bpp) { \ | |
147 case 2: \ | |
148 pixel = *((Uint16 *)(buf)); \ | |
149 break; \ | |
150 \ | |
151 case 3: { \ | |
152 Uint8 *B = (Uint8 *)buf; \ | |
153 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ | |
154 pixel = B[0] + (B[1] << 8) + (B[2] << 16); \ | |
155 } else { \ | |
156 pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \ | |
157 } \ | |
158 } \ | |
159 break; \ | |
160 \ | |
161 case 4: \ | |
162 pixel = *((Uint32 *)(buf)); \ | |
163 break; \ | |
164 \ | |
165 default: \ | |
166 pixel = 0; /* prevent gcc from complaining */ \ | |
167 break; \ | |
168 } \ | |
169 RGB_FROM_PIXEL(pixel, fmt, r, g, b); \ | |
170 } while(0) | |
171 | |
172 /* Assemble R-G-B values into a specified pixel format and store them */ | |
173 #define PIXEL_FROM_RGB(pixel, fmt, r, g, b) \ | |
174 { \ | |
175 pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ | |
176 ((g>>fmt->Gloss)<<fmt->Gshift)| \ | |
177 ((b>>fmt->Bloss)<<fmt->Bshift); \ | |
178 } | |
179 #define RGB565_FROM_RGB(pixel, r, g, b) \ | |
180 { \ | |
181 pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3); \ | |
182 } | |
183 #define RGB555_FROM_RGB(pixel, r, g, b) \ | |
184 { \ | |
185 pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3); \ | |
186 } | |
187 #define RGB888_FROM_RGB(pixel, r, g, b) \ | |
188 { \ | |
189 pixel = (r<<16)|(g<<8)|b; \ | |
190 } | |
191 #define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b) \ | |
192 { \ | |
193 switch (bpp) { \ | |
194 case 2: { \ | |
195 Uint16 pixel; \ | |
196 \ | |
197 PIXEL_FROM_RGB(pixel, fmt, r, g, b); \ | |
198 *((Uint16 *)(buf)) = pixel; \ | |
199 } \ | |
200 break; \ | |
201 \ | |
202 case 3: { \ | |
203 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ | |
204 *((buf)+fmt->Rshift/8) = r; \ | |
205 *((buf)+fmt->Gshift/8) = g; \ | |
206 *((buf)+fmt->Bshift/8) = b; \ | |
207 } else { \ | |
208 *((buf)+2-fmt->Rshift/8) = r; \ | |
209 *((buf)+2-fmt->Gshift/8) = g; \ | |
210 *((buf)+2-fmt->Bshift/8) = b; \ | |
211 } \ | |
212 } \ | |
213 break; \ | |
214 \ | |
215 case 4: { \ | |
216 Uint32 pixel; \ | |
217 \ | |
218 PIXEL_FROM_RGB(pixel, fmt, r, g, b); \ | |
219 *((Uint32 *)(buf)) = pixel; \ | |
220 } \ | |
221 break; \ | |
222 } \ | |
223 } | |
224 #define ASSEMBLE_RGB_AMASK(buf, bpp, fmt, r, g, b, Amask) \ | |
225 { \ | |
226 switch (bpp) { \ | |
227 case 2: { \ | |
228 Uint16 *bufp; \ | |
229 Uint16 pixel; \ | |
230 \ | |
231 bufp = (Uint16 *)buf; \ | |
232 PIXEL_FROM_RGB(pixel, fmt, r, g, b); \ | |
233 *bufp = pixel | (*bufp & Amask); \ | |
234 } \ | |
235 break; \ | |
236 \ | |
237 case 3: { \ | |
238 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ | |
239 *((buf)+fmt->Rshift/8) = r; \ | |
240 *((buf)+fmt->Gshift/8) = g; \ | |
241 *((buf)+fmt->Bshift/8) = b; \ | |
242 } else { \ | |
243 *((buf)+2-fmt->Rshift/8) = r; \ | |
244 *((buf)+2-fmt->Gshift/8) = g; \ | |
245 *((buf)+2-fmt->Bshift/8) = b; \ | |
246 } \ | |
247 } \ | |
248 break; \ | |
249 \ | |
250 case 4: { \ | |
251 Uint32 *bufp; \ | |
252 Uint32 pixel; \ | |
253 \ | |
254 bufp = (Uint32 *)buf; \ | |
255 PIXEL_FROM_RGB(pixel, fmt, r, g, b); \ | |
256 *bufp = pixel | (*bufp & Amask); \ | |
257 } \ | |
258 break; \ | |
259 } \ | |
260 } | |
261 | |
262 /* FIXME: Should we rescale alpha into 0..255 here? */ | |
263 #define RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a) \ | |
264 { \ | |
265 r = ((pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss; \ | |
266 g = ((pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss; \ | |
267 b = ((pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss; \ | |
268 a = ((pixel&fmt->Amask)>>fmt->Ashift)<<fmt->Aloss; \ | |
269 } | |
270 #define RGBA_FROM_8888(pixel, fmt, r, g, b, a) \ | |
271 { \ | |
272 r = (pixel&fmt->Rmask)>>fmt->Rshift; \ | |
273 g = (pixel&fmt->Gmask)>>fmt->Gshift; \ | |
274 b = (pixel&fmt->Bmask)>>fmt->Bshift; \ | |
275 a = (pixel&fmt->Amask)>>fmt->Ashift; \ | |
276 } | |
277 #define RGBA_FROM_RGBA8888(pixel, r, g, b, a) \ | |
278 { \ | |
279 r = (pixel>>24); \ | |
280 g = ((pixel>>16)&0xFF); \ | |
281 b = ((pixel>>8)&0xFF); \ | |
282 a = (pixel&0xFF); \ | |
283 } | |
284 #define RGBA_FROM_ARGB8888(pixel, r, g, b, a) \ | |
285 { \ | |
286 r = ((pixel>>16)&0xFF); \ | |
287 g = ((pixel>>8)&0xFF); \ | |
288 b = (pixel&0xFF); \ | |
289 a = (pixel>>24); \ | |
290 } | |
291 #define RGBA_FROM_ABGR8888(pixel, r, g, b, a) \ | |
292 { \ | |
293 r = (pixel&0xFF); \ | |
294 g = ((pixel>>8)&0xFF); \ | |
295 b = ((pixel>>16)&0xFF); \ | |
296 a = (pixel>>24); \ | |
297 } | |
298 #define DISEMBLE_RGBA(buf, bpp, fmt, pixel, r, g, b, a) \ | |
299 do { \ | |
300 switch (bpp) { \ | |
301 case 2: \ | |
302 pixel = *((Uint16 *)(buf)); \ | |
303 break; \ | |
304 \ | |
305 case 3: {/* FIXME: broken code (no alpha) */ \ | |
306 Uint8 *b = (Uint8 *)buf; \ | |
307 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ | |
308 pixel = b[0] + (b[1] << 8) + (b[2] << 16); \ | |
309 } else { \ | |
310 pixel = (b[0] << 16) + (b[1] << 8) + b[2]; \ | |
311 } \ | |
312 } \ | |
313 break; \ | |
314 \ | |
315 case 4: \ | |
316 pixel = *((Uint32 *)(buf)); \ | |
317 break; \ | |
318 \ | |
319 default: \ | |
320 pixel = 0; /* stop gcc complaints */ \ | |
321 break; \ | |
322 } \ | |
323 RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a); \ | |
324 pixel &= ~fmt->Amask; \ | |
325 } while(0) | |
326 | |
327 /* FIXME: this isn't correct, especially for Alpha (maximum != 255) */ | |
328 #define PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a) \ | |
329 { \ | |
330 pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ | |
331 ((g>>fmt->Gloss)<<fmt->Gshift)| \ | |
332 ((b>>fmt->Bloss)<<fmt->Bshift)| \ | |
535
917cc5c56176
Fixed alpha blending bug (thanks Glenn!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
333 ((a>>fmt->Aloss)<<fmt->Ashift); \ |
0 | 334 } |
335 #define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \ | |
336 { \ | |
337 switch (bpp) { \ | |
338 case 2: { \ | |
339 Uint16 pixel; \ | |
340 \ | |
341 PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a); \ | |
342 *((Uint16 *)(buf)) = pixel; \ | |
343 } \ | |
344 break; \ | |
345 \ | |
346 case 3: { /* FIXME: broken code (no alpha) */ \ | |
347 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ | |
348 *((buf)+fmt->Rshift/8) = r; \ | |
349 *((buf)+fmt->Gshift/8) = g; \ | |
350 *((buf)+fmt->Bshift/8) = b; \ | |
351 } else { \ | |
352 *((buf)+2-fmt->Rshift/8) = r; \ | |
353 *((buf)+2-fmt->Gshift/8) = g; \ | |
354 *((buf)+2-fmt->Bshift/8) = b; \ | |
355 } \ | |
356 } \ | |
357 break; \ | |
358 \ | |
359 case 4: { \ | |
360 Uint32 pixel; \ | |
361 \ | |
362 PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a); \ | |
363 *((Uint32 *)(buf)) = pixel; \ | |
364 } \ | |
365 break; \ | |
366 } \ | |
367 } | |
368 | |
369 /* Blend the RGB values of two pixels based on a source alpha value */ | |
370 #define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \ | |
371 do { \ | |
372 dR = (((sR-dR)*(A))>>8)+dR; \ | |
373 dG = (((sG-dG)*(A))>>8)+dG; \ | |
374 dB = (((sB-dB)*(A))>>8)+dB; \ | |
375 } while(0) | |
376 | |
1047
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
377 /* Blend the RGB values of two pixels based on a source alpha value */ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
378 #define ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB) \ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
379 do { \ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
380 unsigned tR, tG, tB, tA; \ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
381 tA = 255 - sA; \ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
382 tR = 1 + (sR * sA) + (dR * tA); \ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
383 dR = (tR + (tR >> 8)) >> 8; \ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
384 tG = 1 + (sG * sA) + (dG * tA); \ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
385 dG = (tG + (tG >> 8)) >> 8; \ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
386 tB = 1 + (sB * sA) + (dB * tA); \ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
387 dB = (tB + (tB >> 8)) >> 8; \ |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
388 } while(0) |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
389 |
ffaaf7ecf685
Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
390 |
0 | 391 /* This is a very useful loop for optimizing blitters */ |
553
417f8709e648
There's a bug in the VC7 optimizer relating to the duff loop optimization
Sam Lantinga <slouken@libsdl.org>
parents:
535
diff
changeset
|
392 #if defined(_MSC_VER) && (_MSC_VER == 1300) |
417f8709e648
There's a bug in the VC7 optimizer relating to the duff loop optimization
Sam Lantinga <slouken@libsdl.org>
parents:
535
diff
changeset
|
393 /* There's a bug in the Visual C++ 7 optimizer when compiling this code */ |
417f8709e648
There's a bug in the VC7 optimizer relating to the duff loop optimization
Sam Lantinga <slouken@libsdl.org>
parents:
535
diff
changeset
|
394 #else |
0 | 395 #define USE_DUFFS_LOOP |
553
417f8709e648
There's a bug in the VC7 optimizer relating to the duff loop optimization
Sam Lantinga <slouken@libsdl.org>
parents:
535
diff
changeset
|
396 #endif |
0 | 397 #ifdef USE_DUFFS_LOOP |
398 | |
399 /* 8-times unrolled loop */ | |
400 #define DUFFS_LOOP8(pixel_copy_increment, width) \ | |
401 { int n = (width+7)/8; \ | |
91
e85e03f195b4
From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
402 switch (width & 7) { \ |
0 | 403 case 0: do { pixel_copy_increment; \ |
404 case 7: pixel_copy_increment; \ | |
405 case 6: pixel_copy_increment; \ | |
406 case 5: pixel_copy_increment; \ | |
407 case 4: pixel_copy_increment; \ | |
408 case 3: pixel_copy_increment; \ | |
409 case 2: pixel_copy_increment; \ | |
410 case 1: pixel_copy_increment; \ | |
411 } while ( --n > 0 ); \ | |
412 } \ | |
413 } | |
414 | |
415 /* 4-times unrolled loop */ | |
416 #define DUFFS_LOOP4(pixel_copy_increment, width) \ | |
417 { int n = (width+3)/4; \ | |
91
e85e03f195b4
From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
418 switch (width & 3) { \ |
0 | 419 case 0: do { pixel_copy_increment; \ |
420 case 3: pixel_copy_increment; \ | |
421 case 2: pixel_copy_increment; \ | |
422 case 1: pixel_copy_increment; \ | |
423 } while ( --n > 0 ); \ | |
424 } \ | |
425 } | |
426 | |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
427 /* 2 - times unrolled loop */ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
428 #define DUFFS_LOOP_DOUBLE2(pixel_copy_increment, \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
429 double_pixel_copy_increment, width) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
430 { int n, w = width; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
431 if( w & 1 ) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
432 pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
433 w--; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
434 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
435 if ( w > 0 ) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
436 n = ( w + 2) / 4; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
437 switch( w & 2 ) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
438 case 0: do { double_pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
439 case 2: double_pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
440 } while ( --n > 0 ); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
441 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
442 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
443 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
444 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
445 /* 2 - times unrolled loop 4 pixels */ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
446 #define DUFFS_LOOP_QUATRO2(pixel_copy_increment, \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
447 double_pixel_copy_increment, \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
448 quatro_pixel_copy_increment, width) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
449 { int n, w = width; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
450 if(w & 1) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
451 pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
452 w--; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
453 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
454 if(w & 2) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
455 double_pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
456 w -= 2; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
457 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
458 if ( w > 0 ) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
459 n = ( w + 7 ) / 8; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
460 switch( w & 4 ) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
461 case 0: do { quatro_pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
462 case 4: quatro_pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
463 } while ( --n > 0 ); \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
464 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
465 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
466 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
467 |
0 | 468 /* Use the 8-times version of the loop by default */ |
469 #define DUFFS_LOOP(pixel_copy_increment, width) \ | |
470 DUFFS_LOOP8(pixel_copy_increment, width) | |
471 | |
472 #else | |
473 | |
474 /* Don't use Duff's device to unroll loops */ | |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
475 #define DUFFS_LOOP_DOUBLE2(pixel_copy_increment, \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
476 double_pixel_copy_increment, width) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
477 { int n = width; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
478 if( n & 1 ) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
479 pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
480 n--; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
481 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
482 n=n>>1; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
483 for(; n > 0; --n) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
484 double_pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
485 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
486 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
487 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
488 /* Don't use Duff's device to unroll loops */ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
489 #define DUFFS_LOOP_QUATRO2(pixel_copy_increment, \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
490 double_pixel_copy_increment, \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
491 quatro_pixel_copy_increment, width) \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
492 { int n = width; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
493 if(n & 1) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
494 pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
495 n--; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
496 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
497 if(n & 2) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
498 double_pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
499 n -= 2; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
500 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
501 n=n>>2; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
502 for(; n > 0; --n) { \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
503 quatro_pixel_copy_increment; \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
504 } \ |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
505 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
506 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
553
diff
changeset
|
507 /* Don't use Duff's device to unroll loops */ |
0 | 508 #define DUFFS_LOOP(pixel_copy_increment, width) \ |
509 { int n; \ | |
510 for ( n=width; n > 0; --n ) { \ | |
511 pixel_copy_increment; \ | |
512 } \ | |
513 } | |
514 #define DUFFS_LOOP8(pixel_copy_increment, width) \ | |
515 DUFFS_LOOP(pixel_copy_increment, width) | |
516 #define DUFFS_LOOP4(pixel_copy_increment, width) \ | |
517 DUFFS_LOOP(pixel_copy_increment, width) | |
518 | |
519 #endif /* USE_DUFFS_LOOP */ | |
520 | |
521 /* Prevent Visual C++ 6.0 from printing out stupid warnings */ | |
522 #if defined(_MSC_VER) && (_MSC_VER >= 600) | |
523 #pragma warning(disable: 4550) | |
524 #endif | |
525 | |
526 #endif /* _SDL_blit_h */ |