Go to the documentation of this file.
21 #include "../SDL_internal.h"
96 #define MIN(a, b) ((a) < (b) ? (a) : (b))
99 #define PIXEL_COPY(to, from, len, bpp) \
100 SDL_memcpy(to, from, (size_t)(len) * (bpp))
106 #define OPAQUE_BLIT(to, from, length, bpp, alpha) \
107 PIXEL_COPY(to, from, length, bpp)
116 #define ALPHA_BLIT32_888(to, from, length, bpp, alpha) \
119 Uint32 *src = (Uint32 *)(from); \
120 Uint32 *dst = (Uint32 *)(to); \
121 for (i = 0; i < (int)(length); i++) { \
124 Uint32 s1 = s & 0xff00ff; \
125 Uint32 d1 = d & 0xff00ff; \
126 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
129 d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
140 #define ALPHA_BLIT16_565(to, from, length, bpp, alpha) \
143 Uint16 *src = (Uint16 *)(from); \
144 Uint16 *dst = (Uint16 *)(to); \
145 Uint32 ALPHA = alpha >> 3; \
146 for(i = 0; i < (int)(length); i++) { \
149 s = (s | s << 16) & 0x07e0f81f; \
150 d = (d | d << 16) & 0x07e0f81f; \
151 d += (s - d) * ALPHA >> 5; \
153 *dst++ = (Uint16)(d | d >> 16); \
157 #define ALPHA_BLIT16_555(to, from, length, bpp, alpha) \
160 Uint16 *src = (Uint16 *)(from); \
161 Uint16 *dst = (Uint16 *)(to); \
162 Uint32 ALPHA = alpha >> 3; \
163 for(i = 0; i < (int)(length); i++) { \
166 s = (s | s << 16) & 0x03e07c1f; \
167 d = (d | d << 16) & 0x03e07c1f; \
168 d += (s - d) * ALPHA >> 5; \
170 *dst++ = (Uint16)(d | d >> 16); \
177 #define ALPHA_BLIT_ANY(to, from, length, bpp, alpha) \
182 for (i = 0; i < (int)(length); i++) { \
184 unsigned rs, gs, bs, rd, gd, bd; \
187 s = *(Uint16 *)src; \
188 d = *(Uint16 *)dst; \
191 if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
192 s = (src[0] << 16) | (src[1] << 8) | src[2]; \
193 d = (dst[0] << 16) | (dst[1] << 8) | dst[2]; \
195 s = (src[2] << 16) | (src[1] << 8) | src[0]; \
196 d = (dst[2] << 16) | (dst[1] << 8) | dst[0]; \
200 s = *(Uint32 *)src; \
201 d = *(Uint32 *)dst; \
204 RGB_FROM_PIXEL(s, fmt, rs, gs, bs); \
205 RGB_FROM_PIXEL(d, fmt, rd, gd, bd); \
206 rd += (rs - rd) * alpha >> 8; \
207 gd += (gs - gd) * alpha >> 8; \
208 bd += (bs - bd) * alpha >> 8; \
209 PIXEL_FROM_RGB(d, fmt, rd, gd, bd); \
212 *(Uint16 *)dst = (Uint16)d; \
215 if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
216 dst[0] = (Uint8)(d >> 16); \
217 dst[1] = (Uint8)(d >> 8); \
218 dst[2] = (Uint8)(d); \
221 dst[1] = (Uint8)(d >> 8); \
222 dst[2] = (Uint8)(d >> 16); \
226 *(Uint32 *)dst = d; \
242 #define ALPHA_BLIT32_888_50(to, from, length, bpp, alpha) \
245 Uint32 *src = (Uint32 *)(from); \
246 Uint32 *dst = (Uint32 *)(to); \
247 for(i = 0; i < (int)(length); i++) { \
250 *dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \
251 + (s & d & 0x00010101); \
261 #define BLEND16_50(dst, src, mask) \
265 *dst++ = (Uint16)((((s & mask) + (d & mask)) >> 1) + \
266 (s & d & (~mask & 0xffff))); \
270 #define ALPHA_BLIT16_50(to, from, length, bpp, alpha, mask) \
272 unsigned n = (length); \
273 Uint16 *src = (Uint16 *)(from); \
274 Uint16 *dst = (Uint16 *)(to); \
275 if (((uintptr_t)src ^ (uintptr_t)dst) & 3) { \
278 BLEND16_50(dst, src, mask); \
280 if ((uintptr_t)src & 3) { \
282 BLEND16_50(dst, src, mask); \
285 for (; n > 1; n -= 2) { \
286 Uint32 s = *(Uint32 *)src; \
287 Uint32 d = *(Uint32 *)dst; \
288 *(Uint32 *)dst = ((s & (mask | mask << 16)) >> 1) \
289 + ((d & (mask | mask << 16)) >> 1) \
290 + (s & d & (~(mask | mask << 16))); \
295 BLEND16_50(dst, src, mask); \
299 #define ALPHA_BLIT16_565_50(to, from, length, bpp, alpha) \
300 ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7deU)
302 #define ALPHA_BLIT16_555_50(to, from, length, bpp, alpha) \
303 ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbdeU)
305 #define CHOOSE_BLIT(blitter, alpha, fmt) \
307 if (alpha == 255) { \
308 switch (fmt->BytesPerPixel) { \
309 case 1: blitter(1, Uint8, OPAQUE_BLIT); break; \
310 case 2: blitter(2, Uint8, OPAQUE_BLIT); break; \
311 case 3: blitter(3, Uint8, OPAQUE_BLIT); break; \
312 case 4: blitter(4, Uint16, OPAQUE_BLIT); break; \
315 switch (fmt->BytesPerPixel) { \
321 switch (fmt->Rmask | fmt->Gmask | fmt->Bmask) { \
323 if (fmt->Gmask == 0x07e0 \
324 || fmt->Rmask == 0x07e0 \
325 || fmt->Bmask == 0x07e0) { \
326 if (alpha == 128) { \
327 blitter(2, Uint8, ALPHA_BLIT16_565_50); \
329 blitter(2, Uint8, ALPHA_BLIT16_565); \
336 if (fmt->Gmask == 0x03e0 \
337 || fmt->Rmask == 0x03e0 \
338 || fmt->Bmask == 0x03e0) { \
339 if (alpha == 128) { \
340 blitter(2, Uint8, ALPHA_BLIT16_555_50); \
342 blitter(2, Uint8, ALPHA_BLIT16_555); \
351 blitter(2, Uint8, ALPHA_BLIT_ANY); \
356 blitter(3, Uint8, ALPHA_BLIT_ANY); \
360 if ((fmt->Rmask | fmt->Gmask | fmt->Bmask) == 0x00ffffff \
361 && (fmt->Gmask == 0xff00 || fmt->Rmask == 0xff00 \
362 || fmt->Bmask == 0xff00)) { \
363 if (alpha == 128) { \
364 blitter(4, Uint16, ALPHA_BLIT32_888_50); \
366 blitter(4, Uint16, ALPHA_BLIT32_888); \
369 blitter(4, Uint16, ALPHA_BLIT_ANY); \
379 #define RLEPIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
381 Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
382 ((g>>fmt->Gloss)<<fmt->Gshift)| \
383 ((b>>fmt->Bloss)<<fmt->Bshift)| \
397 #define RLECLIPBLIT(bpp, Type, do_blit) \
399 int linecount = srcrect->h; \
401 int left = srcrect->x; \
402 int right = left + srcrect->w; \
403 dstbuf -= left * bpp; \
406 ofs += *(Type *)srcbuf; \
407 run = ((Type *)srcbuf)[1]; \
408 srcbuf += 2 * sizeof(Type); \
415 if (left - ofs > 0) { \
416 start = left - ofs; \
419 goto nocopy ## bpp ## do_blit; \
421 startcol = ofs + start; \
422 if (len > right - startcol) \
423 len = right - startcol; \
424 do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \
427 nocopy ## bpp ## do_blit: \
428 srcbuf += run * bpp; \
435 dstbuf += surf_dst->pitch; \
476 int vskip = srcrect->
y;
480 #define RLESKIP(bpp, Type) \
483 ofs += *(Type *)srcbuf; \
484 run = ((Type *)srcbuf)[1]; \
485 srcbuf += sizeof(Type) * 2; \
487 srcbuf += run * bpp; \
520 if (srcrect->
x || srcrect->
w != surf_src->
w) {
525 #define RLEBLIT(bpp, Type, do_blit) \
527 int linecount = srcrect->h; \
531 ofs += *(Type *)srcbuf; \
532 run = ((Type *)srcbuf)[1]; \
533 srcbuf += 2 * sizeof(Type); \
535 do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \
536 srcbuf += run * bpp; \
542 dstbuf += surf_dst->pitch; \
573 #define BLIT_TRANSL_888(src, dst) \
577 unsigned alpha = s >> 24; \
578 Uint32 s1 = s & 0xff00ff; \
579 Uint32 d1 = d & 0xff00ff; \
580 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
583 d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
584 dst = d1 | d | 0xff000000; \
591 #define BLIT_TRANSL_565(src, dst) \
595 unsigned alpha = (s & 0x3e0) >> 5; \
597 d = (d | d << 16) & 0x07e0f81f; \
598 d += (s - d) * alpha >> 5; \
600 dst = (Uint16)(d | d >> 16); \
603 #define BLIT_TRANSL_555(src, dst) \
607 unsigned alpha = (s & 0x3e0) >> 5; \
609 d = (d | d << 16) & 0x03e07c1f; \
610 d += (s - d) * alpha >> 5; \
612 dst = (Uint16)(d | d >> 16); \
646 #define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend) \
648 int linecount = srcrect->h; \
649 int left = srcrect->x; \
650 int right = left + srcrect->w; \
651 dstbuf -= left * sizeof(Ptype); \
657 ofs += ((Ctype *)srcbuf)[0]; \
658 run = ((Ctype *)srcbuf)[1]; \
659 srcbuf += 2 * sizeof(Ctype); \
664 if(left - cofs > 0) { \
665 crun -= left - cofs; \
668 if(crun > right - cofs) \
669 crun = right - cofs; \
671 PIXEL_COPY(dstbuf + cofs * sizeof(Ptype), \
672 srcbuf + (cofs - ofs) * sizeof(Ptype), \
673 (unsigned)crun, sizeof(Ptype)); \
674 srcbuf += run * sizeof(Ptype); \
680 if(sizeof(Ptype) == 2) \
681 srcbuf += (uintptr_t)srcbuf & 2; \
686 ofs += ((Uint16 *)srcbuf)[0]; \
687 run = ((Uint16 *)srcbuf)[1]; \
693 if(left - cofs > 0) { \
694 crun -= left - cofs; \
697 if(crun > right - cofs) \
698 crun = right - cofs; \
700 Ptype *dst = (Ptype *)dstbuf + cofs; \
701 Uint32 *src = (Uint32 *)srcbuf + (cofs - ofs); \
703 for(i = 0; i < crun; i++) \
704 do_blend(src[i], dst[i]); \
710 dstbuf += surf_dst->pitch; \
711 } while(--linecount); \
734 Uint8 *srcbuf, *dstbuf;
751 int vskip = srcrect->
y;
778 ofs += ((
Uint16 *) srcbuf)[0];
779 run = ((
Uint16 *) srcbuf)[1];
780 srcbuf += 4 * (run + 1);
791 ofs += ((
Uint16 *) srcbuf)[0];
792 run = ((
Uint16 *) srcbuf)[1];
806 if (srcrect->
x || srcrect->
w != surf_src->
w) {
815 #define RLEALPHABLIT(Ptype, Ctype, do_blend) \
817 int linecount = srcrect->h; \
823 ofs += ((Ctype *)srcbuf)[0]; \
824 run = ((Ctype *)srcbuf)[1]; \
825 srcbuf += 2 * sizeof(Ctype); \
827 PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \
828 run, sizeof(Ptype)); \
829 srcbuf += run * sizeof(Ptype); \
835 if(sizeof(Ptype) == 2) \
836 srcbuf += (uintptr_t)srcbuf & 2; \
841 ofs += ((Uint16 *)srcbuf)[0]; \
842 run = ((Uint16 *)srcbuf)[1]; \
845 Ptype *dst = (Ptype *)dstbuf + ofs; \
847 for(i = 0; i < run; i++) { \
848 Uint32 src = *(Uint32 *)srcbuf; \
849 do_blend(src, *dst); \
856 dstbuf += surf_dst->pitch; \
857 } while(--linecount); \
862 if (df->
Gmask == 0x07e0 || df->
Rmask == 0x07e0
863 || df->
Bmask == 0x07e0)
899 for (
i = 0;
i <
n;
i++) {
917 for (
i = 0;
i <
n;
i++) {
936 for (
i = 0;
i <
n;
i++) {
941 *
d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((
a << 2) & 0x7e0);
955 for (
i = 0;
i <
n;
i++) {
960 *
d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((
a << 2) & 0x3e0);
974 for (
i = 0;
i <
n;
i++) {
977 a = (pix & 0x3e0) >> 2;
978 pix = (pix & ~0x3e0) | pix >> 16;
993 for (
i = 0;
i <
n;
i++) {
1010 for (
i = 0;
i <
n;
i++) {
1011 unsigned r,
g,
b,
a;
1021 #define ISOPAQUE(pixel, fmt) ((((pixel) & fmt->Amask) >> fmt->Ashift) == 255)
1023 #define ISTRANSL(pixel, fmt) \
1024 ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U)
1034 int max_transl_run = 65535;
1037 int (*copy_opaque) (
void *,
Uint32 *, int,
1039 int (*copy_transl) (
void *,
Uint32 *, int,
1046 if (
surface->format->BitsPerPixel != 32)
1057 if (df->
Gmask == 0x07e0
1058 || df->
Rmask == 0x07e0 || df->
Bmask == 0x07e0) {
1065 if (df->
Gmask == 0x03e0
1066 || df->
Rmask == 0x03e0 || df->
Bmask == 0x03e0) {
1075 max_opaque_run = 255;
1082 if (masksum != 0x00ffffff)
1086 max_opaque_run = 255;
1140 #define ADD_TRANSL_COUNTS(n, m) \
1141 (((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4)
1143 for (
y = 0;
y <
h;
y++) {
1144 int runstart, skipstart;
1156 skip = runstart - skipstart;
1160 while (skip > max_opaque_run) {
1162 skip -= max_opaque_run;
1164 len =
MIN(run, max_opaque_run);
1170 len =
MIN(run, max_opaque_run);
1191 skip = runstart - skipstart;
1192 blankline &= (skip ==
w);
1194 while (skip > max_transl_run) {
1196 skip -= max_transl_run;
1198 len =
MIN(run, max_transl_run);
1204 len =
MIN(run, max_transl_run);
1220 #undef ADD_OPAQUE_COUNTS
1221 #undef ADD_TRANSL_COUNTS
1250 return *(
const Uint16 *) srcbuf;
1256 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1257 return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16);
1259 return (srcbuf[0] << 16) + (srcbuf[1] << 8) + srcbuf[2];
1266 return *(
const Uint32 *) srcbuf;
1281 Uint8 *srcbuf, *lastline;
1283 const int bpp =
surface->format->BytesPerPixel;
1312 if (rlebuf ==
NULL) {
1318 maxn =
bpp == 4 ? 65535 : 255;
1320 rgbmask = ~
surface->format->Amask;
1321 ckey =
surface->map->info.colorkey & rgbmask;
1338 for (
y = 0;
y <
h;
y++) {
1347 while (
x <
w && (getpix(srcbuf +
x *
bpp) & rgbmask) == ckey)
1350 while (
x <
w && (getpix(srcbuf +
x *
bpp) & rgbmask) != ckey)
1352 skip = runstart - skipstart;
1358 while (skip > maxn) {
1417 if (
surface->format->BitsPerPixel < 8) {
1442 if (!
surface->map->identity) {
1477 int (*uncopy_opaque) (
Uint32 *,
void *, int,
1479 int (*uncopy_transl) (
Uint32 *,
void *, int,
1488 uncopy_opaque = uncopy_transl =
uncopy_32;
1500 srcbuf = (
Uint8 *) (df + 1);
1511 ofs += ((
Uint16 *) srcbuf)[0];
1512 run = ((
Uint16 *) srcbuf)[1];
1516 srcbuf += uncopy_opaque(
dst + ofs, srcbuf, run, df, sf);
1531 ofs += ((
Uint16 *) srcbuf)[0];
1532 run = ((
Uint16 *) srcbuf)[1];
1535 srcbuf += uncopy_transl(
dst + ofs, srcbuf, run, df, sf);
1569 full.
x = full.
y = 0;
#define SDL_UnlockSurface
static int uncopy_transl_16(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
#define BLIT_TRANSL_555(src, dst)
static Uint32 getpix_32(const Uint8 *srcbuf)
A collection of pixels used in software blitting.
static Uint32 getpix_24(const Uint8 *srcbuf)
#define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend)
#define SDL_COPY_RLE_COLORKEY
#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
static Uint32 getpix_16(const Uint8 *srcbuf)
static int SDL_RLEBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
GLboolean GLboolean GLboolean b
static int uncopy_32(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
#define CHOOSE_BLIT(blitter, alpha, fmt)
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
Uint32(* getpix_func)(const Uint8 *)
static int copy_transl_565(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
GLdouble GLdouble GLdouble r
#define SDL_COPY_COLORKEY
#define ADD_OPAQUE_COUNTS(n, m)
GLboolean GLboolean GLboolean GLboolean a
GLfloat GLfloat GLfloat GLfloat h
#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)
#define RLEPIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
GLfloat GLfloat GLfloat alpha
GLint GLint GLint GLint GLint x
static int copy_32(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect)
int SDL_RLESurface(SDL_Surface *surface)
#define RLESKIP(bpp, Type)
static const getpix_func getpixes[4]
#define RLECLIPBLIT(bpp, Type, do_blit)
#define BLIT_TRANSL_888(src, dst)
#define SDL_COPY_MODULATE_ALPHA
#define SDL_OutOfMemory()
static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha)
GLint GLint GLint GLint GLint GLint y
#define SDL_COPY_RLE_ALPHAKEY
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp
#define ISTRANSL(pixel, fmt)
static int uncopy_opaque_16(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
static int copy_opaque_16(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
static Uint32 getpix_8(const Uint8 *srcbuf)
static int SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)
A rectangle, with the origin at the upper left (integer).
static SDL_bool UnRLEAlpha(SDL_Surface *surface)
#define ISOPAQUE(pixel, fmt)
#define BLIT_TRANSL_565(src, dst)
static int RLEColorkeySurface(SDL_Surface *surface)
#define RLEBLIT(bpp, Type, do_blit)
static int copy_transl_555(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)
#define ADD_TRANSL_COUNTS(n, m)
#define SDL_COPY_MODULATE_COLOR
#define RLEALPHABLIT(Ptype, Ctype, do_blend)
static int RLEAlphaSurface(SDL_Surface *surface)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
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 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
GLubyte GLubyte GLubyte GLubyte w