/usr/include/python2.7/pygame/surface.h is in python-pygame 1.9.1release+dfsg-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | /*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
Copyright (C) 2007 Marcus von Appen
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
#ifndef SURFACE_H
#define SURFACE_H
#include <SDL.h>
#include "pygame.h"
#define PYGAME_BLEND_ADD 0x1
#define PYGAME_BLEND_SUB 0x2
#define PYGAME_BLEND_MULT 0x3
#define PYGAME_BLEND_MIN 0x4
#define PYGAME_BLEND_MAX 0x5
#define PYGAME_BLEND_RGB_ADD 0x1
#define PYGAME_BLEND_RGB_SUB 0x2
#define PYGAME_BLEND_RGB_MULT 0x3
#define PYGAME_BLEND_RGB_MIN 0x4
#define PYGAME_BLEND_RGB_MAX 0x5
#define PYGAME_BLEND_RGBA_ADD 0x6
#define PYGAME_BLEND_RGBA_SUB 0x7
#define PYGAME_BLEND_RGBA_MULT 0x8
#define PYGAME_BLEND_RGBA_MIN 0x9
#define PYGAME_BLEND_RGBA_MAX 0x10
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define GET_PIXEL_24(b) (b[0] + (b[1] << 8) + (b[2] << 16))
#else
#define GET_PIXEL_24(b) (b[2] + (b[1] << 8) + (b[0] << 16))
#endif
#define GET_PIXEL(pxl, bpp, source) \
switch (bpp) \
{ \
case 2: \
pxl = *((Uint16 *) (source)); \
break; \
case 4: \
pxl = *((Uint32 *) (source)); \
break; \
default: \
{ \
Uint8 *b = (Uint8 *) source; \
pxl = GET_PIXEL_24(b); \
} \
break; \
}
#define GET_PIXELVALS(_sR, _sG, _sB, _sA, px, fmt, ppa) \
_sR = ((px & fmt->Rmask) >> fmt->Rshift); \
_sR = (_sR << fmt->Rloss) + (_sR >> (8 - (fmt->Rloss << 1))); \
_sG = ((px & fmt->Gmask) >> fmt->Gshift); \
_sG = (_sG << fmt->Gloss) + (_sG >> (8 - (fmt->Gloss << 1))); \
_sB = ((px & fmt->Bmask) >> fmt->Bshift); \
_sB = (_sB << fmt->Bloss) + (_sB >> (8 - (fmt->Bloss << 1))); \
if (ppa) \
{ \
_sA = ((px & fmt->Amask) >> fmt->Ashift); \
_sA = (_sA << fmt->Aloss) + (_sA >> (8 - (fmt->Aloss << 1))); \
} \
else \
{ \
_sA = 255; \
}
#define GET_PIXELVALS_1(sr, sg, sb, sa, _src, _fmt) \
sr = _fmt->palette->colors[*((Uint8 *) (_src))].r; \
sg = _fmt->palette->colors[*((Uint8 *) (_src))].g; \
sb = _fmt->palette->colors[*((Uint8 *) (_src))].b; \
sa = 255;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define SET_OFFSETS_24(or, og, ob, fmt) \
{ \
or = (fmt->Rshift == 0 ? 0 : \
fmt->Rshift == 8 ? 1 : \
2 ); \
og = (fmt->Gshift == 0 ? 0 : \
fmt->Gshift == 8 ? 1 : \
2 ); \
ob = (fmt->Bshift == 0 ? 0 : \
fmt->Bshift == 8 ? 1 : \
2 ); \
}
#define SET_OFFSETS_32(or, og, ob, fmt) \
{ \
or = (fmt->Rshift == 0 ? 0 : \
fmt->Rshift == 8 ? 1 : \
fmt->Rshift == 16 ? 2 : \
3 ); \
og = (fmt->Gshift == 0 ? 0 : \
fmt->Gshift == 8 ? 1 : \
fmt->Gshift == 16 ? 2 : \
3 ); \
ob = (fmt->Bshift == 0 ? 0 : \
fmt->Bshift == 8 ? 1 : \
fmt->Bshift == 16 ? 2 : \
3 ); \
}
#else
#define SET_OFFSETS_24(or, og, ob, fmt) \
{ \
or = (fmt->Rshift == 0 ? 2 : \
fmt->Rshift == 8 ? 1 : \
0 ); \
og = (fmt->Gshift == 0 ? 2 : \
fmt->Gshift == 8 ? 1 : \
0 ); \
ob = (fmt->Bshift == 0 ? 2 : \
fmt->Bshift == 8 ? 1 : \
0 ); \
}
#define SET_OFFSETS_32(or, og, ob, fmt) \
{ \
or = (fmt->Rshift == 0 ? 3 : \
fmt->Rshift == 8 ? 2 : \
fmt->Rshift == 16 ? 1 : \
0 ); \
og = (fmt->Gshift == 0 ? 3 : \
fmt->Gshift == 8 ? 2 : \
fmt->Gshift == 16 ? 1 : \
0 ); \
ob = (fmt->Bshift == 0 ? 3 : \
fmt->Bshift == 8 ? 2 : \
fmt->Bshift == 16 ? 1 : \
0 ); \
}
#endif
#define CREATE_PIXEL(buf, r, g, b, a, bp, ft) \
switch (bp) \
{ \
case 2: \
*((Uint16 *) (buf)) = \
((r >> ft->Rloss) << ft->Rshift) | \
((g >> ft->Gloss) << ft->Gshift) | \
((b >> ft->Bloss) << ft->Bshift) | \
((a >> ft->Aloss) << ft->Ashift); \
break; \
case 4: \
*((Uint32 *) (buf)) = \
((r >> ft->Rloss) << ft->Rshift) | \
((g >> ft->Gloss) << ft->Gshift) | \
((b >> ft->Bloss) << ft->Bshift) | \
((a >> ft->Aloss) << ft->Ashift); \
break; \
}
/* Pretty good idea from Tom Duff :-). */
#define LOOP_UNROLLED4(code, n, width) \
n = (width + 3) / 4; \
switch (width & 3) \
{ \
case 0: do { code; \
case 3: code; \
case 2: code; \
case 1: code; \
} while (--n > 0); \
}
/* Used in the srcbpp == dstbpp == 1 blend functions */
#define REPEAT_3(code) \
code; \
code; \
code;
#define REPEAT_4(code) \
code; \
code; \
code; \
code;
#define BLEND_ADD(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
tmp = dR + sR; dR = (tmp <= 255 ? tmp : 255); \
tmp = dG + sG; dG = (tmp <= 255 ? tmp : 255); \
tmp = dB + sB; dB = (tmp <= 255 ? tmp : 255);
#define BLEND_SUB(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
tmp = dR - sR; dR = (tmp >= 0 ? tmp : 0); \
tmp = dG - sG; dG = (tmp >= 0 ? tmp : 0); \
tmp = dB - sB; dB = (tmp >= 0 ? tmp : 0);
#define BLEND_MULT(sR, sG, sB, sA, dR, dG, dB, dA) \
dR = (dR && sR) ? (dR * sR) >> 8 : 0; \
dG = (dG && sG) ? (dG * sG) >> 8 : 0; \
dB = (dB && sB) ? (dB * sB) >> 8 : 0;
#define BLEND_MIN(sR, sG, sB, sA, dR, dG, dB, dA) \
if(sR < dR) { dR = sR; } \
if(sG < dG) { dG = sG; } \
if(sB < dB) { dB = sB; }
#define BLEND_MAX(sR, sG, sB, sA, dR, dG, dB, dA) \
if(sR > dR) { dR = sR; } \
if(sG > dG) { dG = sG; } \
if(sB > dB) { dB = sB; }
#define BLEND_RGBA_ADD(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
tmp = dR + sR; dR = (tmp <= 255 ? tmp : 255); \
tmp = dG + sG; dG = (tmp <= 255 ? tmp : 255); \
tmp = dB + sB; dB = (tmp <= 255 ? tmp : 255); \
tmp = dA + sA; dA = (tmp <= 255 ? tmp : 255);
#define BLEND_RGBA_SUB(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
tmp = dR - sR; dR = (tmp >= 0 ? tmp : 0); \
tmp = dG - sG; dG = (tmp >= 0 ? tmp : 0); \
tmp = dB - sB; dB = (tmp >= 0 ? tmp : 0); \
tmp = dA - sA; dA = (tmp >= 0 ? tmp : 0);
#define BLEND_RGBA_MULT(sR, sG, sB, sA, dR, dG, dB, dA) \
dR = (dR && sR) ? (dR * sR) >> 8 : 0; \
dG = (dG && sG) ? (dG * sG) >> 8 : 0; \
dB = (dB && sB) ? (dB * sB) >> 8 : 0; \
dA = (dA && sA) ? (dA * sA) >> 8 : 0;
#define BLEND_RGBA_MIN(sR, sG, sB, sA, dR, dG, dB, dA) \
if(sR < dR) { dR = sR; } \
if(sG < dG) { dG = sG; } \
if(sB < dB) { dB = sB; } \
if(sA < dA) { dA = sA; }
#define BLEND_RGBA_MAX(sR, sG, sB, sA, dR, dG, dB, dA) \
if(sR > dR) { dR = sR; } \
if(sG > dG) { dG = sG; } \
if(sB > dB) { dB = sB; } \
if(sA > dA) { dA = sA; }
#if 1
/* Choose an alpha blend equation. If the sign is preserved on a right shift
* then use a specialized, faster, equation. Otherwise a more general form,
* where all additions are done before the shift, is needed.
*/
#if (-1 >> 1) < 0
#define ALPHA_BLEND_COMP(sC, dC, sA) ((((sC - dC) * sA + sC) >> 8) + dC)
#else
#define ALPHA_BLEND_COMP(sC, dC, sA) (((dC << 8) + (sC - dC) * sA + sC) >> 8)
#endif
#define ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB, dA) \
do { \
if (dA) \
{ \
dR = ALPHA_BLEND_COMP(sR, dR, sA); \
dG = ALPHA_BLEND_COMP(sG, dG, sA); \
dB = ALPHA_BLEND_COMP(sB, dB, sA); \
dA = sA + dA - ((sA * dA) / 255); \
} \
else \
{ \
dR = sR; \
dG = sG; \
dB = sB; \
dA = sA; \
} \
} while(0)
#elif 0
#define ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB, dA) \
do { \
if(sA){ \
if(dA && sA < 255){ \
int dContrib = dA*(255 - sA)/255; \
dA = sA+dA - ((sA*dA)/255); \
dR = (dR*dContrib + sR*sA)/dA; \
dG = (dG*dContrib + sG*sA)/dA; \
dB = (dB*dContrib + sB*sA)/dA; \
}else{ \
dR = sR; \
dG = sG; \
dB = sB; \
dA = sA; \
} \
} \
} while(0)
#endif
int
surface_fill_blend (SDL_Surface *surface, SDL_Rect *rect, Uint32 color,
int blendargs);
int
pygame_AlphaBlit (SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect, int the_args);
int
pygame_Blit (SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect, int the_args);
#endif /* SURFACE_H */
|