Go to the documentation of this file.
21 #include "../SDL_internal.h"
34 #define SDL_COPY_MODULATE_COLOR 0x00000001
35 #define SDL_COPY_MODULATE_ALPHA 0x00000002
36 #define SDL_COPY_BLEND 0x00000010
37 #define SDL_COPY_ADD 0x00000020
38 #define SDL_COPY_MOD 0x00000040
39 #define SDL_COPY_MUL 0x00000080
40 #define SDL_COPY_COLORKEY 0x00000100
41 #define SDL_COPY_NEAREST 0x00000200
42 #define SDL_COPY_RLE_DESIRED 0x00001000
43 #define SDL_COPY_RLE_COLORKEY 0x00002000
44 #define SDL_COPY_RLE_ALPHAKEY 0x00004000
45 #define SDL_COPY_RLE_MASK (SDL_COPY_RLE_DESIRED|SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY)
48 #define SDL_CPU_ANY 0x00000000
49 #define SDL_CPU_MMX 0x00000001
50 #define SDL_CPU_3DNOW 0x00000002
51 #define SDL_CPU_SSE 0x00000004
52 #define SDL_CPU_SSE2 0x00000008
53 #define SDL_CPU_ALTIVEC_PREFETCH 0x00000010
54 #define SDL_CPU_ALTIVEC_NOPREFETCH 0x00000020
114 #if defined(__GNUC__)
115 #define DECLARE_ALIGNED(t,v,a) t __attribute__((aligned(a))) v
116 #elif defined(_MSC_VER)
117 #define DECLARE_ALIGNED(t,v,a) __declspec(align(a)) t v
119 #define DECLARE_ALIGNED(t,v,a) t v
123 #define RGB_FROM_PIXEL(Pixel, fmt, r, g, b) \
125 r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
126 g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
127 b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
129 #define RGB_FROM_RGB565(Pixel, r, g, b) \
131 r = SDL_expand_byte[3][((Pixel&0xF800)>>11)]; \
132 g = SDL_expand_byte[2][((Pixel&0x07E0)>>5)]; \
133 b = SDL_expand_byte[3][(Pixel&0x001F)]; \
135 #define RGB_FROM_RGB555(Pixel, r, g, b) \
137 r = SDL_expand_byte[3][((Pixel&0x7C00)>>10)]; \
138 g = SDL_expand_byte[3][((Pixel&0x03E0)>>5)]; \
139 b = SDL_expand_byte[3][(Pixel&0x001F)]; \
141 #define RGB_FROM_RGB888(Pixel, r, g, b) \
143 r = ((Pixel&0xFF0000)>>16); \
144 g = ((Pixel&0xFF00)>>8); \
147 #define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel) \
151 Pixel = *((Uint8 *)(buf)); \
155 Pixel = *((Uint16 *)(buf)); \
159 Uint8 *B = (Uint8 *)(buf); \
160 if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
161 Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \
163 Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \
169 Pixel = *((Uint32 *)(buf)); \
178 #define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b) \
182 Pixel = *((Uint8 *)(buf)); \
183 RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
187 Pixel = *((Uint16 *)(buf)); \
188 RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
193 if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
194 r = *((buf)+fmt->Rshift/8); \
195 g = *((buf)+fmt->Gshift/8); \
196 b = *((buf)+fmt->Bshift/8); \
198 r = *((buf)+2-fmt->Rshift/8); \
199 g = *((buf)+2-fmt->Gshift/8); \
200 b = *((buf)+2-fmt->Bshift/8); \
206 Pixel = *((Uint32 *)(buf)); \
207 RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
219 #define PIXEL_FROM_RGB(Pixel, fmt, r, g, b) \
221 Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
222 ((g>>fmt->Gloss)<<fmt->Gshift)| \
223 ((b>>fmt->Bloss)<<fmt->Bshift)| \
226 #define RGB565_FROM_RGB(Pixel, r, g, b) \
228 Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3); \
230 #define RGB555_FROM_RGB(Pixel, r, g, b) \
232 Pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3); \
234 #define RGB888_FROM_RGB(Pixel, r, g, b) \
236 Pixel = (r<<16)|(g<<8)|b; \
238 #define ARGB8888_FROM_RGBA(Pixel, r, g, b, a) \
240 Pixel = (a<<24)|(r<<16)|(g<<8)|b; \
242 #define RGBA8888_FROM_RGBA(Pixel, r, g, b, a) \
244 Pixel = (r<<24)|(g<<16)|(b<<8)|a; \
246 #define ABGR8888_FROM_RGBA(Pixel, r, g, b, a) \
248 Pixel = (a<<24)|(b<<16)|(g<<8)|r; \
250 #define BGRA8888_FROM_RGBA(Pixel, r, g, b, a) \
252 Pixel = (b<<24)|(g<<16)|(r<<8)|a; \
254 #define ARGB2101010_FROM_RGBA(Pixel, r, g, b, a) \
256 r = r ? ((r << 2) | 0x3) : 0; \
257 g = g ? ((g << 2) | 0x3) : 0; \
258 b = b ? ((b << 2) | 0x3) : 0; \
260 Pixel = (a<<30)|(r<<20)|(g<<10)|b; \
262 #define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b) \
268 PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \
269 *((Uint8 *)(buf)) = _Pixel; \
276 PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \
277 *((Uint16 *)(buf)) = _Pixel; \
282 if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
283 *((buf)+fmt->Rshift/8) = r; \
284 *((buf)+fmt->Gshift/8) = g; \
285 *((buf)+fmt->Bshift/8) = b; \
287 *((buf)+2-fmt->Rshift/8) = r; \
288 *((buf)+2-fmt->Gshift/8) = g; \
289 *((buf)+2-fmt->Bshift/8) = b; \
297 PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \
298 *((Uint32 *)(buf)) = _Pixel; \
305 #define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a) \
307 r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
308 g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
309 b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
310 a = SDL_expand_byte[fmt->Aloss][((Pixel&fmt->Amask)>>fmt->Ashift)]; \
312 #define RGBA_FROM_8888(Pixel, fmt, r, g, b, a) \
314 r = (Pixel&fmt->Rmask)>>fmt->Rshift; \
315 g = (Pixel&fmt->Gmask)>>fmt->Gshift; \
316 b = (Pixel&fmt->Bmask)>>fmt->Bshift; \
317 a = (Pixel&fmt->Amask)>>fmt->Ashift; \
319 #define RGBA_FROM_RGBA8888(Pixel, r, g, b, a) \
322 g = ((Pixel>>16)&0xFF); \
323 b = ((Pixel>>8)&0xFF); \
326 #define RGBA_FROM_ARGB8888(Pixel, r, g, b, a) \
328 r = ((Pixel>>16)&0xFF); \
329 g = ((Pixel>>8)&0xFF); \
333 #define RGBA_FROM_ABGR8888(Pixel, r, g, b, a) \
336 g = ((Pixel>>8)&0xFF); \
337 b = ((Pixel>>16)&0xFF); \
340 #define RGBA_FROM_BGRA8888(Pixel, r, g, b, a) \
342 r = ((Pixel>>8)&0xFF); \
343 g = ((Pixel>>16)&0xFF); \
347 #define RGBA_FROM_ARGB2101010(Pixel, r, g, b, a) \
349 r = ((Pixel>>22)&0xFF); \
350 g = ((Pixel>>12)&0xFF); \
351 b = ((Pixel>>2)&0xFF); \
352 a = SDL_expand_byte[6][(Pixel>>30)]; \
354 #define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a) \
358 Pixel = *((Uint8 *)(buf)); \
359 RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
363 Pixel = *((Uint16 *)(buf)); \
364 RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
369 if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
370 r = *((buf)+fmt->Rshift/8); \
371 g = *((buf)+fmt->Gshift/8); \
372 b = *((buf)+fmt->Bshift/8); \
374 r = *((buf)+2-fmt->Rshift/8); \
375 g = *((buf)+2-fmt->Gshift/8); \
376 b = *((buf)+2-fmt->Bshift/8); \
383 Pixel = *((Uint32 *)(buf)); \
384 RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
396 #define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
398 Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
399 ((g>>fmt->Gloss)<<fmt->Gshift)| \
400 ((b>>fmt->Bloss)<<fmt->Bshift)| \
401 ((a>>fmt->Aloss)<<fmt->Ashift); \
403 #define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \
409 PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
410 *((Uint8 *)(buf)) = _pixel; \
417 PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
418 *((Uint16 *)(buf)) = _pixel; \
423 if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
424 *((buf)+fmt->Rshift/8) = r; \
425 *((buf)+fmt->Gshift/8) = g; \
426 *((buf)+fmt->Bshift/8) = b; \
428 *((buf)+2-fmt->Rshift/8) = r; \
429 *((buf)+2-fmt->Gshift/8) = g; \
430 *((buf)+2-fmt->Bshift/8) = b; \
438 PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
439 *((Uint32 *)(buf)) = _pixel; \
446 #define ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB) \
448 dR = (Uint8)((((int)(sR-dR)*(int)A)/255)+dR); \
449 dG = (Uint8)((((int)(sG-dG)*(int)A)/255)+dG); \
450 dB = (Uint8)((((int)(sB-dB)*(int)A)/255)+dB); \
455 #define ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA) \
457 dR = (Uint8)((((int)(sR-dR)*(int)sA)/255)+dR); \
458 dG = (Uint8)((((int)(sG-dG)*(int)sA)/255)+dG); \
459 dB = (Uint8)((((int)(sB-dB)*(int)sA)/255)+dB); \
460 dA = (Uint8)((int)sA+dA-((int)sA*dA)/255); \
465 #if defined(_MSC_VER) && (_MSC_VER == 1300)
468 #define USE_DUFFS_LOOP
470 #ifdef USE_DUFFS_LOOP
473 #define DUFFS_LOOP8(pixel_copy_increment, width) \
474 { int n = (width+7)/8; \
475 switch (width & 7) { \
476 case 0: do { pixel_copy_increment; \
477 case 7: pixel_copy_increment; \
478 case 6: pixel_copy_increment; \
479 case 5: pixel_copy_increment; \
480 case 4: pixel_copy_increment; \
481 case 3: pixel_copy_increment; \
482 case 2: pixel_copy_increment; \
483 case 1: pixel_copy_increment; \
484 } while ( --n > 0 ); \
489 #define DUFFS_LOOP4(pixel_copy_increment, width) \
490 { int n = (width+3)/4; \
491 switch (width & 3) { \
492 case 0: do { pixel_copy_increment; \
493 case 3: pixel_copy_increment; \
494 case 2: pixel_copy_increment; \
495 case 1: pixel_copy_increment; \
501 #define DUFFS_LOOP(pixel_copy_increment, width) \
502 DUFFS_LOOP8(pixel_copy_increment, width)
505 #define DUFFS_LOOP_124(pixel_copy_increment1, \
506 pixel_copy_increment2, \
507 pixel_copy_increment4, width) \
510 pixel_copy_increment1; n -= 1; \
513 pixel_copy_increment2; n -= 2; \
516 pixel_copy_increment4; n -= 4; \
521 pixel_copy_increment4; \
522 pixel_copy_increment4; \
530 #define DUFFS_LOOP(pixel_copy_increment, width) \
532 for ( n=width; n > 0; --n ) { \
533 pixel_copy_increment; \
536 #define DUFFS_LOOP8(pixel_copy_increment, width) \
537 DUFFS_LOOP(pixel_copy_increment, width)
538 #define DUFFS_LOOP4(pixel_copy_increment, width) \
539 DUFFS_LOOP(pixel_copy_increment, width)
540 #define DUFFS_LOOP_124(pixel_copy_increment1, \
541 pixel_copy_increment2, \
542 pixel_copy_increment4, width) \
543 DUFFS_LOOP(pixel_copy_increment1, width)
548 #if defined(_MSC_VER) && (_MSC_VER >= 600)
549 #pragma warning(disable: 4550)
A collection of pixels used in software blitting.
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
int(* SDL_blit)(struct SDL_Surface *src, SDL_Rect *srcrect, struct SDL_Surface *dst, SDL_Rect *dstrect)
The type of function used for surface blitting functions.
SDL_PixelFormat * src_fmt
SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface)
SDL_PixelFormat * dst_fmt
int SDL_CalculateBlit(SDL_Surface *surface)
Uint8 * SDL_expand_byte[9]
SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface *surface)
SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
Uint32 dst_palette_version
SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface *surface)
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Uint32 src_palette_version
void(* SDL_BlitFunc)(SDL_BlitInfo *info)