annotate src/surface.h @ 3194:9fcb7abf3185 default tip

Remove some gcc 4.7.2 compiler warnings
author Lenard Lindstrom <len-l@telus.net>
date Tue, 23 Apr 2013 19:53:36 -0700
parents 55d7ab7a344f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
1 /*
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
2 pygame - Python Game Library
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
3 Copyright (C) 2000-2001 Pete Shinners
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
4 Copyright (C) 2007 Marcus von Appen
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
5
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
6 This library is free software; you can redistribute it and/or
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
7 modify it under the terms of the GNU Library General Public
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
8 License as published by the Free Software Foundation; either
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
9 version 2 of the License, or (at your option) any later version.
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
10
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
11 This library is distributed in the hope that it will be useful,
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
14 Library General Public License for more details.
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
15
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
16 You should have received a copy of the GNU Library General Public
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
17 License along with this library; if not, write to the Free
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
19
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
20 Pete Shinners
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
21 pete@shinners.org
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
22 */
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
23
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
24 #ifndef SURFACE_H
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
25 #define SURFACE_H
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
26
2075
38a814e12f12 Remove distracting '"_POSIX_C_SOURCE" redefined' GCC warnings from linux builds.
Lenard Lindstrom <len-l@telus.net>
parents: 1514
diff changeset
27 /* This is defined in SDL.h */
38a814e12f12 Remove distracting '"_POSIX_C_SOURCE" redefined' GCC warnings from linux builds.
Lenard Lindstrom <len-l@telus.net>
parents: 1514
diff changeset
28 #if defined(_POSIX_C_SOURCE)
38a814e12f12 Remove distracting '"_POSIX_C_SOURCE" redefined' GCC warnings from linux builds.
Lenard Lindstrom <len-l@telus.net>
parents: 1514
diff changeset
29 #undef _POSIX_C_SOURCE
38a814e12f12 Remove distracting '"_POSIX_C_SOURCE" redefined' GCC warnings from linux builds.
Lenard Lindstrom <len-l@telus.net>
parents: 1514
diff changeset
30 #endif
38a814e12f12 Remove distracting '"_POSIX_C_SOURCE" redefined' GCC warnings from linux builds.
Lenard Lindstrom <len-l@telus.net>
parents: 1514
diff changeset
31
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
32 #include <SDL.h>
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
33 #include "pygame.h"
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
34
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
35 #define PYGAME_BLEND_ADD 0x1
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
36 #define PYGAME_BLEND_SUB 0x2
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
37 #define PYGAME_BLEND_MULT 0x3
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
38 #define PYGAME_BLEND_MIN 0x4
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
39 #define PYGAME_BLEND_MAX 0x5
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
40
1141
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
41 #define PYGAME_BLEND_RGB_ADD 0x1
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
42 #define PYGAME_BLEND_RGB_SUB 0x2
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
43 #define PYGAME_BLEND_RGB_MULT 0x3
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
44 #define PYGAME_BLEND_RGB_MIN 0x4
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
45 #define PYGAME_BLEND_RGB_MAX 0x5
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
46
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
47 #define PYGAME_BLEND_RGBA_ADD 0x6
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
48 #define PYGAME_BLEND_RGBA_SUB 0x7
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
49 #define PYGAME_BLEND_RGBA_MULT 0x8
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
50 #define PYGAME_BLEND_RGBA_MIN 0x9
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
51 #define PYGAME_BLEND_RGBA_MAX 0x10
3095
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
52 #define PYGAME_BLEND_PREMULTIPLIED 0x11
1141
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
53
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
54
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
55
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
56
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
57
1502
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
58 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
59 #define GET_PIXEL_24(b) (b[0] + (b[1] << 8) + (b[2] << 16))
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
60 #else
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
61 #define GET_PIXEL_24(b) (b[2] + (b[1] << 8) + (b[0] << 16))
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
62 #endif
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
63
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
64 #define GET_PIXEL(pxl, bpp, source) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
65 switch (bpp) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
66 { \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
67 case 2: \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
68 pxl = *((Uint16 *) (source)); \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
69 break; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
70 case 4: \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
71 pxl = *((Uint32 *) (source)); \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
72 break; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
73 default: \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
74 { \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
75 Uint8 *b = (Uint8 *) source; \
1502
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
76 pxl = GET_PIXEL_24(b); \
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
77 } \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
78 break; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
79 }
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
80
1505
902b98865c6c fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents: 1504
diff changeset
81 #define GET_PIXELVALS(_sR, _sG, _sB, _sA, px, fmt, ppa) \
985
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
82 _sR = ((px & fmt->Rmask) >> fmt->Rshift); \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
83 _sR = (_sR << fmt->Rloss) + (_sR >> (8 - (fmt->Rloss << 1))); \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
84 _sG = ((px & fmt->Gmask) >> fmt->Gshift); \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
85 _sG = (_sG << fmt->Gloss) + (_sG >> (8 - (fmt->Gloss << 1))); \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
86 _sB = ((px & fmt->Bmask) >> fmt->Bshift); \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
87 _sB = (_sB << fmt->Bloss) + (_sB >> (8 - (fmt->Bloss << 1))); \
1505
902b98865c6c fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents: 1504
diff changeset
88 if (ppa) \
985
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
89 { \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
90 _sA = ((px & fmt->Amask) >> fmt->Ashift); \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
91 _sA = (_sA << fmt->Aloss) + (_sA >> (8 - (fmt->Aloss << 1))); \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
92 } \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
93 else \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
94 { \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
95 _sA = 255; \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
96 }
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
97
985
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
98 #define GET_PIXELVALS_1(sr, sg, sb, sa, _src, _fmt) \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
99 sr = _fmt->palette->colors[*((Uint8 *) (_src))].r; \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
100 sg = _fmt->palette->colors[*((Uint8 *) (_src))].g; \
9799aebf78f9 Improved blit and fill macros for surface operations.
marcus
parents: 820
diff changeset
101 sb = _fmt->palette->colors[*((Uint8 *) (_src))].b; \
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
102 sa = 255;
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
103
1142
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
104
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
105
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
106
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
107
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
108
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
109
1502
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
110 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
111 #define SET_OFFSETS_24(or, og, ob, fmt) \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
112 { \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
113 or = (fmt->Rshift == 0 ? 0 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
114 fmt->Rshift == 8 ? 1 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
115 2 ); \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
116 og = (fmt->Gshift == 0 ? 0 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
117 fmt->Gshift == 8 ? 1 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
118 2 ); \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
119 ob = (fmt->Bshift == 0 ? 0 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
120 fmt->Bshift == 8 ? 1 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
121 2 ); \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
122 }
1514
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
123
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
124 #define SET_OFFSETS_32(or, og, ob, fmt) \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
125 { \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
126 or = (fmt->Rshift == 0 ? 0 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
127 fmt->Rshift == 8 ? 1 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
128 fmt->Rshift == 16 ? 2 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
129 3 ); \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
130 og = (fmt->Gshift == 0 ? 0 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
131 fmt->Gshift == 8 ? 1 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
132 fmt->Gshift == 16 ? 2 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
133 3 ); \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
134 ob = (fmt->Bshift == 0 ? 0 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
135 fmt->Bshift == 8 ? 1 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
136 fmt->Bshift == 16 ? 2 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
137 3 ); \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
138 }
1502
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
139 #else
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
140 #define SET_OFFSETS_24(or, og, ob, fmt) \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
141 { \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
142 or = (fmt->Rshift == 0 ? 2 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
143 fmt->Rshift == 8 ? 1 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
144 0 ); \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
145 og = (fmt->Gshift == 0 ? 2 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
146 fmt->Gshift == 8 ? 1 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
147 0 ); \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
148 ob = (fmt->Bshift == 0 ? 2 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
149 fmt->Bshift == 8 ? 1 : \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
150 0 ); \
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
151 }
1514
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
152
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
153 #define SET_OFFSETS_32(or, og, ob, fmt) \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
154 { \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
155 or = (fmt->Rshift == 0 ? 3 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
156 fmt->Rshift == 8 ? 2 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
157 fmt->Rshift == 16 ? 1 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
158 0 ); \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
159 og = (fmt->Gshift == 0 ? 3 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
160 fmt->Gshift == 8 ? 2 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
161 fmt->Gshift == 16 ? 1 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
162 0 ); \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
163 ob = (fmt->Bshift == 0 ? 3 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
164 fmt->Bshift == 8 ? 2 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
165 fmt->Bshift == 16 ? 1 : \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
166 0 ); \
eb0a75be1765 fix bug involving blit blends and 32 bit surfaces having non-standard masks
Lenard Lindstrom <len-l@telus.net>
parents: 1511
diff changeset
167 }
1502
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
168 #endif
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
169
b3dab2110999 BLEND_xxx blit options tested and bugs fixed
Lenard Lindstrom <len-l@telus.net>
parents: 1315
diff changeset
170
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
171 #define CREATE_PIXEL(buf, r, g, b, a, bp, ft) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
172 switch (bp) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
173 { \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
174 case 2: \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
175 *((Uint16 *) (buf)) = \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
176 ((r >> ft->Rloss) << ft->Rshift) | \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
177 ((g >> ft->Gloss) << ft->Gshift) | \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
178 ((b >> ft->Bloss) << ft->Bshift) | \
1315
baa6043f0695 fixing CREATE_PIXEL macro, it made no-alpha surfaces get filled with green
brian
parents: 1296
diff changeset
179 ((a >> ft->Aloss) << ft->Ashift); \
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
180 break; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
181 case 4: \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
182 *((Uint32 *) (buf)) = \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
183 ((r >> ft->Rloss) << ft->Rshift) | \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
184 ((g >> ft->Gloss) << ft->Gshift) | \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
185 ((b >> ft->Bloss) << ft->Bshift) | \
1315
baa6043f0695 fixing CREATE_PIXEL macro, it made no-alpha surfaces get filled with green
brian
parents: 1296
diff changeset
186 ((a >> ft->Aloss) << ft->Ashift); \
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
187 break; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
188 }
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
189
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
190 /* Pretty good idea from Tom Duff :-). */
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
191 #define LOOP_UNROLLED4(code, n, width) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
192 n = (width + 3) / 4; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
193 switch (width & 3) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
194 { \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
195 case 0: do { code; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
196 case 3: code; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
197 case 2: code; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
198 case 1: code; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
199 } while (--n > 0); \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
200 }
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
201
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
202 /* Used in the srcbpp == dstbpp == 1 blend functions */
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
203 #define REPEAT_3(code) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
204 code; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
205 code; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
206 code;
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
207
1142
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
208 #define REPEAT_4(code) \
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
209 code; \
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
210 code; \
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
211 code; \
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
212 code;
1141
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
213
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
214
1026
91bc7cc45d99 BLEND_* now take alpha into account
marcus
parents: 985
diff changeset
215 #define BLEND_ADD(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
216 tmp = dR + sR; dR = (tmp <= 255 ? tmp : 255); \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
217 tmp = dG + sG; dG = (tmp <= 255 ? tmp : 255); \
1034
9b607773c79f Reverted BLEND_* behaviour to use only RGB values.
marcus
parents: 1026
diff changeset
218 tmp = dB + sB; dB = (tmp <= 255 ? tmp : 255);
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
219
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
220 #define BLEND_SUB(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
221 tmp = dR - sR; dR = (tmp >= 0 ? tmp : 0); \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
222 tmp = dG - sG; dG = (tmp >= 0 ? tmp : 0); \
1034
9b607773c79f Reverted BLEND_* behaviour to use only RGB values.
marcus
parents: 1026
diff changeset
223 tmp = dB - sB; dB = (tmp >= 0 ? tmp : 0);
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
224
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
225 #define BLEND_MULT(sR, sG, sB, sA, dR, dG, dB, dA) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
226 dR = (dR && sR) ? (dR * sR) >> 8 : 0; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
227 dG = (dG && sG) ? (dG * sG) >> 8 : 0; \
1034
9b607773c79f Reverted BLEND_* behaviour to use only RGB values.
marcus
parents: 1026
diff changeset
228 dB = (dB && sB) ? (dB * sB) >> 8 : 0;
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
229
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
230 #define BLEND_MIN(sR, sG, sB, sA, dR, dG, dB, dA) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
231 if(sR < dR) { dR = sR; } \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
232 if(sG < dG) { dG = sG; } \
1034
9b607773c79f Reverted BLEND_* behaviour to use only RGB values.
marcus
parents: 1026
diff changeset
233 if(sB < dB) { dB = sB; }
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
234
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
235 #define BLEND_MAX(sR, sG, sB, sA, dR, dG, dB, dA) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
236 if(sR > dR) { dR = sR; } \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
237 if(sG > dG) { dG = sG; } \
1034
9b607773c79f Reverted BLEND_* behaviour to use only RGB values.
marcus
parents: 1026
diff changeset
238 if(sB > dB) { dB = sB; }
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
239
1141
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
240
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
241
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
242
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
243
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
244
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
245 #define BLEND_RGBA_ADD(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
246 tmp = dR + sR; dR = (tmp <= 255 ? tmp : 255); \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
247 tmp = dG + sG; dG = (tmp <= 255 ? tmp : 255); \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
248 tmp = dB + sB; dB = (tmp <= 255 ? tmp : 255); \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
249 tmp = dA + sA; dA = (tmp <= 255 ? tmp : 255);
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
250
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
251 #define BLEND_RGBA_SUB(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
252 tmp = dR - sR; dR = (tmp >= 0 ? tmp : 0); \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
253 tmp = dG - sG; dG = (tmp >= 0 ? tmp : 0); \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
254 tmp = dB - sB; dB = (tmp >= 0 ? tmp : 0); \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
255 tmp = dA - sA; dA = (tmp >= 0 ? tmp : 0);
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
256
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
257 #define BLEND_RGBA_MULT(sR, sG, sB, sA, dR, dG, dB, dA) \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
258 dR = (dR && sR) ? (dR * sR) >> 8 : 0; \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
259 dG = (dG && sG) ? (dG * sG) >> 8 : 0; \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
260 dB = (dB && sB) ? (dB * sB) >> 8 : 0; \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
261 dA = (dA && sA) ? (dA * sA) >> 8 : 0;
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
262
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
263 #define BLEND_RGBA_MIN(sR, sG, sB, sA, dR, dG, dB, dA) \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
264 if(sR < dR) { dR = sR; } \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
265 if(sG < dG) { dG = sG; } \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
266 if(sB < dB) { dB = sB; } \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
267 if(sA < dA) { dA = sA; }
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
268
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
269 #define BLEND_RGBA_MAX(sR, sG, sB, sA, dR, dG, dB, dA) \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
270 if(sR > dR) { dR = sR; } \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
271 if(sG > dG) { dG = sG; } \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
272 if(sB > dB) { dB = sB; } \
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
273 if(sA > dA) { dA = sA; }
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
274
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
275
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
276
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
277
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
278
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
279
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
280
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
281
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
282
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
283
99a96e8e563d Added BLEND_RGBA_* special flags for blit, and fill.
Rene Dudfield <renesd@gmail.com>
parents: 1034
diff changeset
284
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
285 #if 1
1296
2ef1988f57d3 alpha blit bug where source elements are decremented by 1
Lenard Lindstrom <len-l@telus.net>
parents: 1142
diff changeset
286 /* Choose an alpha blend equation. If the sign is preserved on a right shift
2ef1988f57d3 alpha blit bug where source elements are decremented by 1
Lenard Lindstrom <len-l@telus.net>
parents: 1142
diff changeset
287 * then use a specialized, faster, equation. Otherwise a more general form,
2ef1988f57d3 alpha blit bug where source elements are decremented by 1
Lenard Lindstrom <len-l@telus.net>
parents: 1142
diff changeset
288 * where all additions are done before the shift, is needed.
2ef1988f57d3 alpha blit bug where source elements are decremented by 1
Lenard Lindstrom <len-l@telus.net>
parents: 1142
diff changeset
289 */
2ef1988f57d3 alpha blit bug where source elements are decremented by 1
Lenard Lindstrom <len-l@telus.net>
parents: 1142
diff changeset
290 #if (-1 >> 1) < 0
1511
1403c372c528 fix erroneous ALPHA_BLEND macro argument
Lenard Lindstrom <len-l@telus.net>
parents: 1505
diff changeset
291 #define ALPHA_BLEND_COMP(sC, dC, sA) ((((sC - dC) * sA + sC) >> 8) + dC)
1296
2ef1988f57d3 alpha blit bug where source elements are decremented by 1
Lenard Lindstrom <len-l@telus.net>
parents: 1142
diff changeset
292 #else
1511
1403c372c528 fix erroneous ALPHA_BLEND macro argument
Lenard Lindstrom <len-l@telus.net>
parents: 1505
diff changeset
293 #define ALPHA_BLEND_COMP(sC, dC, sA) (((dC << 8) + (sC - dC) * sA + sC) >> 8)
1296
2ef1988f57d3 alpha blit bug where source elements are decremented by 1
Lenard Lindstrom <len-l@telus.net>
parents: 1142
diff changeset
294 #endif
2ef1988f57d3 alpha blit bug where source elements are decremented by 1
Lenard Lindstrom <len-l@telus.net>
parents: 1142
diff changeset
295
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
296 #define ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB, dA) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
297 do { \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
298 if (dA) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
299 { \
1511
1403c372c528 fix erroneous ALPHA_BLEND macro argument
Lenard Lindstrom <len-l@telus.net>
parents: 1505
diff changeset
300 dR = ALPHA_BLEND_COMP(sR, dR, sA); \
1403c372c528 fix erroneous ALPHA_BLEND macro argument
Lenard Lindstrom <len-l@telus.net>
parents: 1505
diff changeset
301 dG = ALPHA_BLEND_COMP(sG, dG, sA); \
1403c372c528 fix erroneous ALPHA_BLEND macro argument
Lenard Lindstrom <len-l@telus.net>
parents: 1505
diff changeset
302 dB = ALPHA_BLEND_COMP(sB, dB, sA); \
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
303 dA = sA + dA - ((sA * dA) / 255); \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
304 } \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
305 else \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
306 { \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
307 dR = sR; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
308 dG = sG; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
309 dB = sB; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
310 dA = sA; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
311 } \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
312 } while(0)
3095
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
313
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
314 #define ALPHA_BLEND_PREMULTIPLIED_COMP(sC, dC, sA) (sC + dC - ((dC * sA) >> 8))
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
315
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
316 #define ALPHA_BLEND_PREMULTIPLIED(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
317 do { \
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
318 tmp = ALPHA_BLEND_PREMULTIPLIED_COMP(sR, dR, sA); dR = (tmp > 255 ? 255 : tmp); \
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
319 tmp = ALPHA_BLEND_PREMULTIPLIED_COMP(sG, dG, sA); dG = (tmp > 255 ? 255 : tmp); \
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
320 tmp = ALPHA_BLEND_PREMULTIPLIED_COMP(sB, dB, sA); dB = (tmp > 255 ? 255 : tmp); \
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
321 dA = sA + dA - ((sA * dA) / 255); \
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
322 } while(0)
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
323 #elif 0
3095
549f3fb44e55 Add support for premultiplied alpha, necessary for integration with Cairo.
David Turner <novalis@novalis.org>
parents: 2075
diff changeset
324
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
325 #define ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB, dA) \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
326 do { \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
327 if(sA){ \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
328 if(dA && sA < 255){ \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
329 int dContrib = dA*(255 - sA)/255; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
330 dA = sA+dA - ((sA*dA)/255); \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
331 dR = (dR*dContrib + sR*sA)/dA; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
332 dG = (dG*dContrib + sG*sA)/dA; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
333 dB = (dB*dContrib + sB*sA)/dA; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
334 }else{ \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
335 dR = sR; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
336 dG = sG; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
337 dB = sB; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
338 dA = sA; \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
339 } \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
340 } \
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
341 } while(0)
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
342 #endif
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
343
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
344 int
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
345 surface_fill_blend (SDL_Surface *surface, SDL_Rect *rect, Uint32 color,
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
346 int blendargs);
3122
55d7ab7a344f Surface.fill() respects clipping rect or surface bounds with special flags.
Rene Dudfield <renesd@gmail.com>
parents: 3095
diff changeset
347
55d7ab7a344f Surface.fill() respects clipping rect or surface bounds with special flags.
Rene Dudfield <renesd@gmail.com>
parents: 3095
diff changeset
348 void
55d7ab7a344f Surface.fill() respects clipping rect or surface bounds with special flags.
Rene Dudfield <renesd@gmail.com>
parents: 3095
diff changeset
349 surface_respect_clip_rect (SDL_Surface *surface, SDL_Rect *rect);
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
350
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
351 int
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
352 pygame_AlphaBlit (SDL_Surface * src, SDL_Rect * srcrect,
1142
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1141
diff changeset
353 SDL_Surface * dst, SDL_Rect * dstrect, int the_args);
820
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
354
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
355 int
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
356 pygame_Blit (SDL_Surface * src, SDL_Rect * srcrect,
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
357 SDL_Surface * dst, SDL_Rect * dstrect, int the_args);
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
358
dbac3b5adc99 from the changes marcus made
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
359 #endif /* SURFACE_H */