21 #include "../SDL_internal.h"
94 #define MIN(a, b) ((a) < (b) ? (a) : (b))
97 #define PIXEL_COPY(to, from, len, bpp) \
98 SDL_memcpy(to, from, (size_t)(len) * (bpp))
104 #define OPAQUE_BLIT(to, from, length, bpp, alpha) \
105 PIXEL_COPY(to, from, length, bpp)
114 #define ALPHA_BLIT32_888(to, from, length, bpp, alpha) \
117 Uint32 *src = (Uint32 *)(from); \
118 Uint32 *dst = (Uint32 *)(to); \
119 for (i = 0; i < (int)(length); i++) { \
122 Uint32 s1 = s & 0xff00ff; \
123 Uint32 d1 = d & 0xff00ff; \
124 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
127 d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
138 #define ALPHA_BLIT16_565(to, from, length, bpp, alpha) \
141 Uint16 *src = (Uint16 *)(from); \
142 Uint16 *dst = (Uint16 *)(to); \
143 Uint32 ALPHA = alpha >> 3; \
144 for(i = 0; i < (int)(length); i++) { \
147 s = (s | s << 16) & 0x07e0f81f; \
148 d = (d | d << 16) & 0x07e0f81f; \
149 d += (s - d) * ALPHA >> 5; \
151 *dst++ = (Uint16)(d | d >> 16); \
155 #define ALPHA_BLIT16_555(to, from, length, bpp, alpha) \
158 Uint16 *src = (Uint16 *)(from); \
159 Uint16 *dst = (Uint16 *)(to); \
160 Uint32 ALPHA = alpha >> 3; \
161 for(i = 0; i < (int)(length); i++) { \
164 s = (s | s << 16) & 0x03e07c1f; \
165 d = (d | d << 16) & 0x03e07c1f; \
166 d += (s - d) * ALPHA >> 5; \
168 *dst++ = (Uint16)(d | d >> 16); \
175 #define ALPHA_BLIT_ANY(to, from, length, bpp, alpha) \
180 for (i = 0; i < (int)(length); i++) { \
182 unsigned rs, gs, bs, rd, gd, bd; \
185 s = *(Uint16 *)src; \
186 d = *(Uint16 *)dst; \
189 if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
190 s = (src[0] << 16) | (src[1] << 8) | src[2]; \
191 d = (dst[0] << 16) | (dst[1] << 8) | dst[2]; \
193 s = (src[2] << 16) | (src[1] << 8) | src[0]; \
194 d = (dst[2] << 16) | (dst[1] << 8) | dst[0]; \
198 s = *(Uint32 *)src; \
199 d = *(Uint32 *)dst; \
202 RGB_FROM_PIXEL(s, fmt, rs, gs, bs); \
203 RGB_FROM_PIXEL(d, fmt, rd, gd, bd); \
204 rd += (rs - rd) * alpha >> 8; \
205 gd += (gs - gd) * alpha >> 8; \
206 bd += (bs - bd) * alpha >> 8; \
207 PIXEL_FROM_RGB(d, fmt, rd, gd, bd); \
210 *(Uint16 *)dst = (Uint16)d; \
213 if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
214 dst[0] = (Uint8)(d >> 16); \
215 dst[1] = (Uint8)(d >> 8); \
216 dst[2] = (Uint8)(d); \
219 dst[1] = (Uint8)(d >> 8); \
220 dst[2] = (Uint8)(d >> 16); \
224 *(Uint32 *)dst = d; \
240 #define ALPHA_BLIT32_888_50(to, from, length, bpp, alpha) \
243 Uint32 *src = (Uint32 *)(from); \
244 Uint32 *dst = (Uint32 *)(to); \
245 for(i = 0; i < (int)(length); i++) { \
248 *dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \
249 + (s & d & 0x00010101); \
259 #define BLEND16_50(dst, src, mask) \
263 *dst++ = (Uint16)((((s & mask) + (d & mask)) >> 1) + \
264 (s & d & (~mask & 0xffff))); \
268 #define ALPHA_BLIT16_50(to, from, length, bpp, alpha, mask) \
270 unsigned n = (length); \
271 Uint16 *src = (Uint16 *)(from); \
272 Uint16 *dst = (Uint16 *)(to); \
273 if (((uintptr_t)src ^ (uintptr_t)dst) & 3) { \
276 BLEND16_50(dst, src, mask); \
278 if ((uintptr_t)src & 3) { \
280 BLEND16_50(dst, src, mask); \
283 for (; n > 1; n -= 2) { \
284 Uint32 s = *(Uint32 *)src; \
285 Uint32 d = *(Uint32 *)dst; \
286 *(Uint32 *)dst = ((s & (mask | mask << 16)) >> 1) \
287 + ((d & (mask | mask << 16)) >> 1) \
288 + (s & d & (~(mask | mask << 16))); \
293 BLEND16_50(dst, src, mask); \
297 #define ALPHA_BLIT16_565_50(to, from, length, bpp, alpha) \
298 ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7de)
300 #define ALPHA_BLIT16_555_50(to, from, length, bpp, alpha) \
301 ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbde)
303 #define CHOOSE_BLIT(blitter, alpha, fmt) \
305 if (alpha == 255) { \
306 switch (fmt->BytesPerPixel) { \
307 case 1: blitter(1, Uint8, OPAQUE_BLIT); break; \
308 case 2: blitter(2, Uint8, OPAQUE_BLIT); break; \
309 case 3: blitter(3, Uint8, OPAQUE_BLIT); break; \
310 case 4: blitter(4, Uint16, OPAQUE_BLIT); break; \
313 switch (fmt->BytesPerPixel) { \
319 switch (fmt->Rmask | fmt->Gmask | fmt->Bmask) { \
321 if (fmt->Gmask == 0x07e0 \
322 || fmt->Rmask == 0x07e0 \
323 || fmt->Bmask == 0x07e0) { \
324 if (alpha == 128) { \
325 blitter(2, Uint8, ALPHA_BLIT16_565_50); \
327 blitter(2, Uint8, ALPHA_BLIT16_565); \
334 if (fmt->Gmask == 0x03e0 \
335 || fmt->Rmask == 0x03e0 \
336 || fmt->Bmask == 0x03e0) { \
337 if (alpha == 128) { \
338 blitter(2, Uint8, ALPHA_BLIT16_555_50); \
340 blitter(2, Uint8, ALPHA_BLIT16_555); \
349 blitter(2, Uint8, ALPHA_BLIT_ANY); \
354 blitter(3, Uint8, ALPHA_BLIT_ANY); \
358 if ((fmt->Rmask | fmt->Gmask | fmt->Bmask) == 0x00ffffff \
359 && (fmt->Gmask == 0xff00 || fmt->Rmask == 0xff00 \
360 || fmt->Bmask == 0xff00)) { \
361 if (alpha == 128) { \
362 blitter(4, Uint16, ALPHA_BLIT32_888_50); \
364 blitter(4, Uint16, ALPHA_BLIT32_888); \
367 blitter(4, Uint16, ALPHA_BLIT_ANY); \
377 #define RLEPIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
379 Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
380 ((g>>fmt->Gloss)<<fmt->Gshift)| \
381 ((b>>fmt->Bloss)<<fmt->Bshift)| \
395 #define RLECLIPBLIT(bpp, Type, do_blit) \
397 int linecount = srcrect->h; \
399 int left = srcrect->x; \
400 int right = left + srcrect->w; \
401 dstbuf -= left * bpp; \
404 ofs += *(Type *)srcbuf; \
405 run = ((Type *)srcbuf)[1]; \
406 srcbuf += 2 * sizeof(Type); \
413 if (left - ofs > 0) { \
414 start = left - ofs; \
417 goto nocopy ## bpp ## do_blit; \
419 startcol = ofs + start; \
420 if (len > right - startcol) \
421 len = right - startcol; \
422 do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \
425 nocopy ## bpp ## do_blit: \
426 srcbuf += run * bpp; \
433 dstbuf += surf_dst->pitch; \
474 int vskip = srcrect->
y;
478 #define RLESKIP(bpp, Type) \
481 ofs += *(Type *)srcbuf; \
482 run = ((Type *)srcbuf)[1]; \
483 srcbuf += sizeof(Type) * 2; \
485 srcbuf += run * bpp; \
518 if (srcrect->
x || srcrect->
w != surf_src->
w) {
519 RLEClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect, alpha);
523 #define RLEBLIT(bpp, Type, do_blit) \
525 int linecount = srcrect->h; \
529 ofs += *(Type *)srcbuf; \
530 run = ((Type *)srcbuf)[1]; \
531 srcbuf += 2 * sizeof(Type); \
533 do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \
534 srcbuf += run * bpp; \
540 dstbuf += surf_dst->pitch; \
571 #define BLIT_TRANSL_888(src, dst) \
575 unsigned alpha = s >> 24; \
576 Uint32 s1 = s & 0xff00ff; \
577 Uint32 d1 = d & 0xff00ff; \
578 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
581 d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
582 dst = d1 | d | 0xff000000; \
589 #define BLIT_TRANSL_565(src, dst) \
593 unsigned alpha = (s & 0x3e0) >> 5; \
595 d = (d | d << 16) & 0x07e0f81f; \
596 d += (s - d) * alpha >> 5; \
598 dst = (Uint16)(d | d >> 16); \
601 #define BLIT_TRANSL_555(src, dst) \
605 unsigned alpha = (s & 0x3e0) >> 5; \
607 d = (d | d << 16) & 0x03e07c1f; \
608 d += (s - d) * alpha >> 5; \
610 dst = (Uint16)(d | d >> 16); \
644 #define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend) \
646 int linecount = srcrect->h; \
647 int left = srcrect->x; \
648 int right = left + srcrect->w; \
649 dstbuf -= left * sizeof(Ptype); \
655 ofs += ((Ctype *)srcbuf)[0]; \
656 run = ((Ctype *)srcbuf)[1]; \
657 srcbuf += 2 * sizeof(Ctype); \
662 if(left - cofs > 0) { \
663 crun -= left - cofs; \
666 if(crun > right - cofs) \
667 crun = right - cofs; \
669 PIXEL_COPY(dstbuf + cofs * sizeof(Ptype), \
670 srcbuf + (cofs - ofs) * sizeof(Ptype), \
671 (unsigned)crun, sizeof(Ptype)); \
672 srcbuf += run * sizeof(Ptype); \
678 if(sizeof(Ptype) == 2) \
679 srcbuf += (uintptr_t)srcbuf & 2; \
684 ofs += ((Uint16 *)srcbuf)[0]; \
685 run = ((Uint16 *)srcbuf)[1]; \
691 if(left - cofs > 0) { \
692 crun -= left - cofs; \
695 if(crun > right - cofs) \
696 crun = right - cofs; \
698 Ptype *dst = (Ptype *)dstbuf + cofs; \
699 Uint32 *src = (Uint32 *)srcbuf + (cofs - ofs); \
701 for(i = 0; i < crun; i++) \
702 do_blend(src[i], dst[i]); \
708 dstbuf += surf_dst->pitch; \
709 } while(--linecount); \
732 Uint8 *srcbuf, *dstbuf;
749 int vskip = srcrect->
y;
776 ofs += ((
Uint16 *) srcbuf)[0];
777 run = ((
Uint16 *) srcbuf)[1];
778 srcbuf += 4 * (run + 1);
789 ofs += ((
Uint16 *) srcbuf)[0];
790 run = ((
Uint16 *) srcbuf)[1];
804 if (srcrect->
x || srcrect->
w != surf_src->
w) {
813 #define RLEALPHABLIT(Ptype, Ctype, do_blend) \
815 int linecount = srcrect->h; \
821 ofs += ((Ctype *)srcbuf)[0]; \
822 run = ((Ctype *)srcbuf)[1]; \
823 srcbuf += 2 * sizeof(Ctype); \
825 PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \
826 run, sizeof(Ptype)); \
827 srcbuf += run * sizeof(Ptype); \
833 if(sizeof(Ptype) == 2) \
834 srcbuf += (uintptr_t)srcbuf & 2; \
839 ofs += ((Uint16 *)srcbuf)[0]; \
840 run = ((Uint16 *)srcbuf)[1]; \
843 Ptype *dst = (Ptype *)dstbuf + ofs; \
845 for(i = 0; i < run; i++) { \
846 Uint32 src = *(Uint32 *)srcbuf; \
847 do_blend(src, *dst); \
854 dstbuf += surf_dst->pitch; \
855 } while(--linecount); \
860 if (df->
Gmask == 0x07e0 || df->
Rmask == 0x07e0
861 || df->
Bmask == 0x07e0)
897 for (i = 0; i <
n; i++) {
915 for (i = 0; i <
n; i++) {
934 for (i = 0; i <
n; i++) {
939 *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
953 for (i = 0; i <
n; i++) {
958 *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
972 for (i = 0; i <
n; i++) {
975 a = (pix & 0x3e0) >> 2;
976 pix = (pix & ~0x3e0) | pix >> 16;
991 for (i = 0; i <
n; i++) {
1008 for (i = 0; i <
n; i++) {
1009 unsigned r,
g,
b,
a;
1019 #define ISOPAQUE(pixel, fmt) ((((pixel) & fmt->Amask) >> fmt->Ashift) == 255)
1021 #define ISTRANSL(pixel, fmt) \
1022 ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U)
1032 int max_transl_run = 65535;
1035 int (*copy_opaque) (
void *,
Uint32 *, int,
1037 int (*copy_transl) (
void *, Uint32 *, int,
1038 SDL_PixelFormat *, SDL_PixelFormat *);
1040 dest = surface->
map->
dst;
1055 if (df->
Gmask == 0x07e0
1056 || df->
Rmask == 0x07e0 || df->
Bmask == 0x07e0) {
1063 if (df->
Gmask == 0x03e0
1064 || df->
Rmask == 0x03e0 || df->
Bmask == 0x03e0) {
1073 max_opaque_run = 255;
1077 maxsize = surface->
h * (2 + (4 + 2) * (surface->
w + 1)) + 2;
1080 if (masksum != 0x00ffffff)
1084 max_opaque_run = 255;
1087 maxsize = surface->
h * 2 * 4 * (surface->
w + 1) + 4;
1120 int h = surface->
h,
w = surface->
w;
1121 SDL_PixelFormat *sf = surface->
format;
1122 Uint32 *
src = (Uint32 *) surface->
pixels;
1123 Uint8 *lastline = dst;
1138 #define ADD_TRANSL_COUNTS(n, m) \
1139 (((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4)
1141 for (y = 0; y <
h; y++) {
1142 int runstart, skipstart;
1154 skip = runstart - skipstart;
1158 while (skip > max_opaque_run) {
1160 skip -= max_opaque_run;
1162 len =
MIN(run, max_opaque_run);
1164 dst += copy_opaque(dst, src + runstart, len, sf, df);
1168 len =
MIN(run, max_opaque_run);
1170 dst += copy_opaque(dst, src + runstart, len, sf, df);
1189 skip = runstart - skipstart;
1190 blankline &= (skip ==
w);
1192 while (skip > max_transl_run) {
1194 skip -= max_transl_run;
1196 len =
MIN(run, max_transl_run);
1198 dst += copy_transl(dst, src + runstart, len, sf, df);
1202 len =
MIN(run, max_transl_run);
1204 dst += copy_transl(dst, src + runstart, len, sf, df);
1212 src += surface->
pitch >> 2;
1218 #undef ADD_OPAQUE_COUNTS
1219 #undef ADD_TRANSL_COUNTS
1247 return *(
Uint16 *) srcbuf;
1253 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1254 return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16);
1256 return (srcbuf[0] << 16) + (srcbuf[1] << 8) + srcbuf[2];
1263 return *(
Uint32 *) srcbuf;
1278 Uint8 *srcbuf, *lastline;
1290 maxsize = surface->
h * 3 * (surface->
w / 2 + 1) + 2;
1295 maxsize = surface->
h * (2 * (surface->
w / 255 + 1)
1296 + surface->
w * bpp) + 2;
1300 maxsize = surface->
h * (4 * (surface->
w / 65535 + 1)
1301 + surface->
w * 4) + 4;
1309 if (rlebuf ==
NULL) {
1315 maxn = bpp == 4 ? 65535 : 255;
1335 for (y = 0; y <
h; y++) {
1344 while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
1347 while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
1349 skip = runstart - skipstart;
1355 while (skip > maxn) {
1359 len =
MIN(run, maxn);
1361 SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
1366 len =
MIN(run, maxn);
1368 SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
1377 srcbuf += surface->
pitch;
1473 int (*uncopy_opaque) (
Uint32 *,
void *, int,
1475 int (*uncopy_transl) (
Uint32 *,
void *, int,
1484 uncopy_opaque = uncopy_transl =
uncopy_32;
1495 srcbuf = (
Uint8 *) (df + 1);
1506 ofs += ((
Uint16 *) srcbuf)[0];
1507 run = ((
Uint16 *) srcbuf)[1];
1511 srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
1525 ofs += ((
Uint16 *) srcbuf)[0];
1526 run = ((
Uint16 *) srcbuf)[1];
1529 srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
1533 dst += surface->
pitch >> 2;
1561 full.
x = full.
y = 0;
1562 full.
w = surface->
w;
1563 full.
h = surface->
h;
static int copy_transl_555(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
#define CHOOSE_BLIT(blitter, alpha, fmt)
#define SDL_COPY_MODULATE_COLOR
GLdouble GLdouble GLdouble r
static int copy_transl_565(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
#define SDL_UnlockSurface
#define SDL_COPY_COLORKEY
static int uncopy_transl_16(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
#define BLIT_TRANSL_555(src, dst)
static int uncopy_32(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
GLint GLint GLint GLint GLint x
GLfloat GLfloat GLfloat GLfloat h
A collection of pixels used in software blitting.
#define RLEPIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
static Uint32 getpix_16(Uint8 *srcbuf)
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
#define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend)
#define SDL_COPY_RLE_COLORKEY
int SDL_RLEBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
#define ADD_OPAQUE_COUNTS(n, m)
GLfloat GLfloat GLfloat alpha
static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect)
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)
#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
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
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)
static int copy_32(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
GLubyte GLubyte GLubyte GLubyte w
#define RLESKIP(bpp, Type)
static const getpix_func getpixes[4]
GLint GLint GLint GLint GLint GLint y
int SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
#define RLECLIPBLIT(bpp, Type, do_blit)
static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha)
int SDL_RLESurface(SDL_Surface *surface)
static int RLEColorkeySurface(SDL_Surface *surface)
#define SDL_OutOfMemory()
#define RLEALPHABLIT(Ptype, Ctype, do_blend)
#define ADD_TRANSL_COUNTS(n, m)
static SDL_bool UnRLEAlpha(SDL_Surface *surface)
static int copy_opaque_16(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
#define SDL_COPY_MODULATE_ALPHA
#define BLIT_TRANSL_565(src, dst)
#define SDL_COPY_RLE_ALPHAKEY
static int RLEAlphaSurface(SDL_Surface *surface)
#define BLIT_TRANSL_888(src, dst)
static Uint32 getpix_32(Uint8 *srcbuf)
static int uncopy_opaque_16(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
#define ISTRANSL(pixel, fmt)
#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)
#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)
Uint32(* getpix_func)(Uint8 *)
static Uint32 getpix_8(Uint8 *srcbuf)
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b
#define ISOPAQUE(pixel, fmt)
A rectangle, with the origin at the upper left.
#define RLEBLIT(bpp, Type, do_blit)
static Uint32 getpix_24(Uint8 *srcbuf)