94 #define MAX(a, b) ((a) > (b) ? (a) : (b))
97 #define MIN(a, b) ((a) < (b) ? (a) : (b))
100 #define PIXEL_COPY(to, from, len, bpp) \
101 SDL_memcpy(to, from, (size_t)(len) * (bpp))
107 #define OPAQUE_BLIT(to, from, length, bpp, alpha) \
108 PIXEL_COPY(to, from, length, bpp)
117 #define ALPHA_BLIT32_888(to, from, length, bpp, alpha) \
120 Uint32 *src = (Uint32 *)(from); \
121 Uint32 *dst = (Uint32 *)(to); \
122 for(i = 0; i < (int)(length); i++) { \
125 Uint32 s1 = s & 0xff00ff; \
126 Uint32 d1 = d & 0xff00ff; \
127 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
130 d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
141 #define ALPHA_BLIT16_565(to, from, length, bpp, alpha) \
144 Uint16 *src = (Uint16 *)(from); \
145 Uint16 *dst = (Uint16 *)(to); \
146 Uint32 ALPHA = alpha >> 3; \
147 for(i = 0; i < (int)(length); i++) { \
150 s = (s | s << 16) & 0x07e0f81f; \
151 d = (d | d << 16) & 0x07e0f81f; \
152 d += (s - d) * ALPHA >> 5; \
154 *dst++ = (Uint16)(d | d >> 16); \
158 #define ALPHA_BLIT16_555(to, from, length, bpp, alpha) \
161 Uint16 *src = (Uint16 *)(from); \
162 Uint16 *dst = (Uint16 *)(to); \
163 Uint32 ALPHA = alpha >> 3; \
164 for(i = 0; i < (int)(length); i++) { \
167 s = (s | s << 16) & 0x03e07c1f; \
168 d = (d | d << 16) & 0x03e07c1f; \
169 d += (s - d) * ALPHA >> 5; \
171 *dst++ = (Uint16)(d | d >> 16); \
178 #define ALPHA_BLIT_ANY(to, from, length, bpp, alpha) \
183 for(i = 0; i < (int)(length); i++) { \
185 unsigned rs, gs, bs, rd, gd, bd; \
188 s = *(Uint16 *)src; \
189 d = *(Uint16 *)dst; \
192 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
193 s = (src[0] << 16) | (src[1] << 8) | src[2]; \
194 d = (dst[0] << 16) | (dst[1] << 8) | dst[2]; \
196 s = (src[2] << 16) | (src[1] << 8) | src[0]; \
197 d = (dst[2] << 16) | (dst[1] << 8) | dst[0]; \
201 s = *(Uint32 *)src; \
202 d = *(Uint32 *)dst; \
205 RGB_FROM_PIXEL(s, fmt, rs, gs, bs); \
206 RGB_FROM_PIXEL(d, fmt, rd, gd, bd); \
207 rd += (rs - rd) * alpha >> 8; \
208 gd += (gs - gd) * alpha >> 8; \
209 bd += (bs - bd) * alpha >> 8; \
210 PIXEL_FROM_RGB(d, fmt, rd, gd, bd); \
213 *(Uint16 *)dst = (Uint16)d; \
216 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
217 dst[0] = (Uint8)(d >> 16); \
218 dst[1] = (Uint8)(d >> 8); \
219 dst[2] = (Uint8)(d); \
222 dst[1] = (Uint8)(d >> 8); \
223 dst[2] = (Uint8)(d >> 16); \
227 *(Uint32 *)dst = d; \
243 #define ALPHA_BLIT32_888_50(to, from, length, bpp, alpha) \
246 Uint32 *src = (Uint32 *)(from); \
247 Uint32 *dst = (Uint32 *)(to); \
248 for(i = 0; i < (int)(length); i++) { \
251 *dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \
252 + (s & d & 0x00010101); \
262 #define BLEND16_50(dst, src, mask) \
266 *dst++ = (Uint16)((((s & mask) + (d & mask)) >> 1) + \
267 (s & d & (~mask & 0xffff))); \
271 #define ALPHA_BLIT16_50(to, from, length, bpp, alpha, mask) \
273 unsigned n = (length); \
274 Uint16 *src = (Uint16 *)(from); \
275 Uint16 *dst = (Uint16 *)(to); \
276 if(((uintptr_t)src ^ (uintptr_t)dst) & 3) { \
279 BLEND16_50(dst, src, mask); \
281 if((uintptr_t)src & 3) { \
283 BLEND16_50(dst, src, mask); \
286 for(; n > 1; n -= 2) { \
287 Uint32 s = *(Uint32 *)src; \
288 Uint32 d = *(Uint32 *)dst; \
289 *(Uint32 *)dst = ((s & (mask | mask << 16)) >> 1) \
290 + ((d & (mask | mask << 16)) >> 1) \
291 + (s & d & (~(mask | mask << 16))); \
296 BLEND16_50(dst, src, mask); \
300 #define ALPHA_BLIT16_565_50(to, from, length, bpp, alpha) \
301 ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7de)
303 #define ALPHA_BLIT16_555_50(to, from, length, bpp, alpha) \
304 ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbde)
306 #define CHOOSE_BLIT(blitter, alpha, fmt) \
309 switch(fmt->BytesPerPixel) { \
310 case 1: blitter(1, Uint8, OPAQUE_BLIT); break; \
311 case 2: blitter(2, Uint8, OPAQUE_BLIT); break; \
312 case 3: blitter(3, Uint8, OPAQUE_BLIT); break; \
313 case 4: blitter(4, Uint16, OPAQUE_BLIT); break; \
316 switch(fmt->BytesPerPixel) { \
322 switch(fmt->Rmask | fmt->Gmask | fmt->Bmask) { \
324 if(fmt->Gmask == 0x07e0 \
325 || fmt->Rmask == 0x07e0 \
326 || fmt->Bmask == 0x07e0) { \
328 blitter(2, Uint8, ALPHA_BLIT16_565_50); \
330 blitter(2, Uint8, ALPHA_BLIT16_565); \
337 if(fmt->Gmask == 0x03e0 \
338 || fmt->Rmask == 0x03e0 \
339 || fmt->Bmask == 0x03e0) { \
341 blitter(2, Uint8, ALPHA_BLIT16_555_50); \
343 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)) { \
364 blitter(4, Uint16, ALPHA_BLIT32_888_50); \
366 blitter(4, Uint16, ALPHA_BLIT32_888); \
368 blitter(4, Uint16, ALPHA_BLIT_ANY); \
384 #define RLECLIPBLIT(bpp, Type, do_blit) \
386 int linecount = srcrect->h; \
388 int left = srcrect->x; \
389 int right = left + srcrect->w; \
390 dstbuf -= left * bpp; \
393 ofs += *(Type *)srcbuf; \
394 run = ((Type *)srcbuf)[1]; \
395 srcbuf += 2 * sizeof(Type); \
402 if(left - ofs > 0) { \
403 start = left - ofs; \
406 goto nocopy ## bpp ## do_blit; \
408 startcol = ofs + start; \
409 if(len > right - startcol) \
410 len = right - startcol; \
411 do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \
414 nocopy ## bpp ## do_blit: \
415 srcbuf += run * bpp; \
421 dstbuf += dst->pitch; \
462 int vskip = srcrect->
y;
466 #define RLESKIP(bpp, Type) \
469 ofs += *(Type *)srcbuf; \
470 run = ((Type *)srcbuf)[1]; \
471 srcbuf += sizeof(Type) * 2; \
473 srcbuf += run * bpp; \
506 if (srcrect->
x || srcrect->
w != src->
w) {
507 RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
511 #define RLEBLIT(bpp, Type, do_blit) \
513 int linecount = srcrect->h; \
517 ofs += *(Type *)srcbuf; \
518 run = ((Type *)srcbuf)[1]; \
519 srcbuf += 2 * sizeof(Type); \
521 do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \
522 srcbuf += run * bpp; \
528 dstbuf += dst->pitch; \
559 #define BLIT_TRANSL_888(src, dst) \
563 unsigned alpha = s >> 24; \
564 Uint32 s1 = s & 0xff00ff; \
565 Uint32 d1 = d & 0xff00ff; \
566 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
569 d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
570 dst = d1 | d | 0xff000000; \
577 #define BLIT_TRANSL_565(src, dst) \
581 unsigned alpha = (s & 0x3e0) >> 5; \
583 d = (d | d << 16) & 0x07e0f81f; \
584 d += (s - d) * alpha >> 5; \
586 dst = (Uint16)(d | d >> 16); \
589 #define BLIT_TRANSL_555(src, dst) \
593 unsigned alpha = (s & 0x3e0) >> 5; \
595 d = (d | d << 16) & 0x03e07c1f; \
596 d += (s - d) * alpha >> 5; \
598 dst = (Uint16)(d | d >> 16); \
632 #define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend) \
634 int linecount = srcrect->h; \
635 int left = srcrect->x; \
636 int right = left + srcrect->w; \
637 dstbuf -= left * sizeof(Ptype); \
643 ofs += ((Ctype *)srcbuf)[0]; \
644 run = ((Ctype *)srcbuf)[1]; \
645 srcbuf += 2 * sizeof(Ctype); \
650 if(left - cofs > 0) { \
651 crun -= left - cofs; \
654 if(crun > right - cofs) \
655 crun = right - cofs; \
657 PIXEL_COPY(dstbuf + cofs * sizeof(Ptype), \
658 srcbuf + (cofs - ofs) * sizeof(Ptype), \
659 (unsigned)crun, sizeof(Ptype)); \
660 srcbuf += run * sizeof(Ptype); \
666 if(sizeof(Ptype) == 2) \
667 srcbuf += (uintptr_t)srcbuf & 2; \
672 ofs += ((Uint16 *)srcbuf)[0]; \
673 run = ((Uint16 *)srcbuf)[1]; \
679 if(left - cofs > 0) { \
680 crun -= left - cofs; \
683 if(crun > right - cofs) \
684 crun = right - cofs; \
686 Ptype *dst = (Ptype *)dstbuf + cofs; \
687 Uint32 *src = (Uint32 *)srcbuf + (cofs - ofs); \
689 for(i = 0; i < crun; i++) \
690 do_blend(src[i], dst[i]); \
696 dstbuf += dst->pitch; \
697 } while(--linecount); \
720 Uint8 *srcbuf, *dstbuf;
733 srcbuf = (
Uint8 *) src->
map->
data +
sizeof(RLEDestFormat);
737 int vskip = srcrect->
y;
764 ofs += ((
Uint16 *) srcbuf)[0];
765 run = ((
Uint16 *) srcbuf)[1];
766 srcbuf += 4 * (run + 1);
777 ofs += ((
Uint16 *) srcbuf)[0];
778 run = ((
Uint16 *) srcbuf)[1];
792 if (srcrect->
x || srcrect->
w != src->
w) {
801 #define RLEALPHABLIT(Ptype, Ctype, do_blend) \
803 int linecount = srcrect->h; \
809 ofs += ((Ctype *)srcbuf)[0]; \
810 run = ((Ctype *)srcbuf)[1]; \
811 srcbuf += 2 * sizeof(Ctype); \
813 PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \
814 run, sizeof(Ptype)); \
815 srcbuf += run * sizeof(Ptype); \
821 if(sizeof(Ptype) == 2) \
822 srcbuf += (uintptr_t)srcbuf & 2; \
827 ofs += ((Uint16 *)srcbuf)[0]; \
828 run = ((Uint16 *)srcbuf)[1]; \
831 Ptype *dst = (Ptype *)dstbuf + ofs; \
833 for(i = 0; i < run; i++) { \
834 Uint32 src = *(Uint32 *)srcbuf; \
835 do_blend(src, *dst); \
842 dstbuf += dst->pitch; \
843 } while(--linecount); \
848 if (df->
Gmask == 0x07e0 || df->
Rmask == 0x07e0
849 || df->
Bmask == 0x07e0)
885 for (i = 0; i <
n; i++) {
903 for (i = 0; i <
n; i++) {
922 for (i = 0; i <
n; i++) {
927 *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
941 for (i = 0; i <
n; i++) {
946 *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
960 for (i = 0; i <
n; i++) {
963 a = (pix & 0x3e0) >> 2;
964 pix = (pix & ~0x3e0) | pix >> 16;
979 for (i = 0; i <
n; i++) {
996 for (i = 0; i <
n; i++) {
1007 #define ISOPAQUE(pixel, fmt) ((((pixel) & fmt->Amask) >> fmt->Ashift) == 255)
1009 #define ISTRANSL(pixel, fmt) \
1010 ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U)
1020 int max_transl_run = 65535;
1025 int (*copy_transl) (
void *, Uint32 *,
int,
1026 SDL_PixelFormat *, SDL_PixelFormat *);
1028 dest = surface->
map->
dst;
1043 if (df->
Gmask == 0x07e0
1044 || df->
Rmask == 0x07e0 || df->
Bmask == 0x07e0) {
1051 if (df->
Gmask == 0x03e0
1052 || df->
Rmask == 0x03e0 || df->
Bmask == 0x03e0) {
1061 max_opaque_run = 255;
1065 maxsize = surface->
h * (2 + (4 + 2) * (surface->
w + 1)) + 2;
1068 if (masksum != 0x00ffffff)
1072 max_opaque_run = 255;
1075 maxsize = surface->
h * 2 * 4 * (surface->
w + 1) + 4;
1081 maxsize +=
sizeof(RLEDestFormat);
1088 RLEDestFormat *
r = (RLEDestFormat *) rlebuf;
1090 r->Rmask = df->
Rmask;
1091 r->Gmask = df->
Gmask;
1092 r->Bmask = df->
Bmask;
1093 r->Amask = df->
Amask;
1094 r->Rloss = df->
Rloss;
1095 r->Gloss = df->
Gloss;
1096 r->Bloss = df->
Bloss;
1097 r->Aloss = df->
Aloss;
1103 dst = rlebuf +
sizeof(RLEDestFormat);
1108 int h = surface->
h,
w = surface->
w;
1109 SDL_PixelFormat *sf = surface->
format;
1110 Uint32 *
src = (Uint32 *) surface->
pixels;
1111 Uint8 *lastline = dst;
1126 #define ADD_TRANSL_COUNTS(n, m) \
1127 (((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4)
1129 for (y = 0; y <
h; y++) {
1130 int runstart, skipstart;
1142 skip = runstart - skipstart;
1146 while (skip > max_opaque_run) {
1148 skip -= max_opaque_run;
1150 len =
MIN(run, max_opaque_run);
1152 dst += copy_opaque(dst, src + runstart, len, sf, df);
1156 len =
MIN(run, max_opaque_run);
1158 dst += copy_opaque(dst, src + runstart, len, sf, df);
1177 skip = runstart - skipstart;
1178 blankline &= (skip ==
w);
1180 while (skip > max_transl_run) {
1182 skip -= max_transl_run;
1184 len =
MIN(run, max_transl_run);
1186 dst += copy_transl(dst, src + runstart, len, sf, df);
1190 len =
MIN(run, max_transl_run);
1192 dst += copy_transl(dst, src + runstart, len, sf, df);
1200 src += surface->
pitch >> 2;
1206 #undef ADD_OPAQUE_COUNTS
1207 #undef ADD_TRANSL_COUNTS
1235 return *(
Uint16 *) srcbuf;
1241 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1242 return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16);
1244 return (srcbuf[0] << 16) + (srcbuf[1] << 8) + srcbuf[2];
1251 return *(
Uint32 *) srcbuf;
1266 Uint8 *srcbuf, *lastline;
1278 maxsize = surface->
h * 3 * (surface->
w / 2 + 1) + 2;
1283 maxsize = surface->
h * (2 * (surface->
w / 255 + 1)
1284 + surface->
w * bpp) + 2;
1288 maxsize = surface->
h * (4 * (surface->
w / 65535 + 1)
1289 + surface->
w * 4) + 4;
1294 if (rlebuf ==
NULL) {
1300 maxn = bpp == 4 ? 65535 : 255;
1320 for (y = 0; y <
h; y++) {
1329 while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
1332 while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
1334 skip = runstart - skipstart;
1340 while (skip > maxn) {
1344 len =
MIN(run, maxn);
1346 SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
1351 len =
MIN(run, maxn);
1353 SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
1362 srcbuf += surface->
pitch;
1457 RLEDestFormat *df = surface->
map->
data;
1463 int bpp = df->BytesPerPixel;
1469 uncopy_opaque = uncopy_transl =
uncopy_32;
1480 srcbuf = (
Uint8 *) (df + 1);
1491 ofs += ((
Uint16 *) srcbuf)[0];
1492 run = ((
Uint16 *) srcbuf)[1];
1496 srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
1510 ofs += ((
Uint16 *) srcbuf)[0];
1511 run = ((
Uint16 *) srcbuf)[1];
1514 srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
1518 dst += surface->
pitch >> 2;
1546 full.
x = full.
y = 0;
1547 full.
w = surface->
w;
1548 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
static int copy_transl_565(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst, Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha)
GLfloat GLfloat GLfloat GLfloat h
#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)
DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size)
A collection of pixels used in software blitting.
DECLSPEC void SDLCALL SDL_free(void *mem)
static Uint32 getpix_16(Uint8 *srcbuf)
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
GLboolean GLboolean GLboolean GLboolean a
#define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend)
#define SDL_COPY_RLE_COLORKEY
return Display return Display Bool Bool int d
#define ADD_OPAQUE_COUNTS(n, m)
DECLSPEC int SDLCALL SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface)
#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
#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)
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
#define RLESKIP(bpp, Type)
static const getpix_func getpixes[4]
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
#define RLECLIPBLIT(bpp, Type, do_blit)
GLclampf GLclampf GLclampf alpha
int SDL_RLESurface(SDL_Surface *surface)
static int RLEColorkeySurface(SDL_Surface *surface)
EGLSurface EGLint EGLint y
#define SDL_OutOfMemory()
int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
#define RLEALPHABLIT(Ptype, Ctype, do_blend)
#define ADD_TRANSL_COUNTS(n, m)
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
static SDL_bool UnRLEAlpha(SDL_Surface *surface)
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
static int copy_opaque_16(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
#define SDL_COPY_MODULATE_ALPHA
uint8_t Uint8
An unsigned 8-bit integer type.
#define BLIT_TRANSL_565(src, dst)
#define SDL_COPY_RLE_ALPHAKEY
static int RLEAlphaSurface(SDL_Surface *surface)
#define BLIT_TRANSL_888(src, dst)
int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
static Uint32 getpix_32(Uint8 *srcbuf)
GLdouble GLdouble GLdouble r
GLdouble GLdouble GLdouble b
static int uncopy_opaque_16(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
GLint GLint GLint GLint GLint w
uint16_t Uint16
An unsigned 16-bit integer type.
static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst, Uint8 *dstbuf, SDL_Rect *srcrect)
#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)
DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface)
Sets up a surface for directly accessing the pixels.
#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)