SDL_RLEaccel.c File Reference
`#include "../SDL_internal.h"`
`#include "SDL_video.h"`
`#include "SDL_sysvideo.h"`
`#include "SDL_blit.h"`
`#include "SDL_RLEaccel_c.h"`
Include dependency graph for SDL_RLEaccel.c:

Go to the source code of this file.

## Data Structures

struct | RLEDestFormat

## Macros

#define | MIN(a, b) ((a) < (b) ? (a) : (b))
#define | PIXEL_COPY(to, from, len, bpp) SDL_memcpy(to, from, (size_t)(len) * (bpp))
#define | OPAQUE_BLIT(to, from, length, bpp, alpha) PIXEL_COPY(to, from, length, bpp)
#define | ALPHA_BLIT32_888(to, from, length, bpp, alpha)
#define | ALPHA_BLIT16_565(to, from, length, bpp, alpha)
#define | ALPHA_BLIT16_555(to, from, length, bpp, alpha)
#define | ALPHA_BLIT_ANY(to, from, length, bpp, alpha)
#define | ALPHA_BLIT32_888_50(to, from, length, bpp, alpha)
#define | BLEND16_50(dst, src, mask)
#define | ALPHA_BLIT16_50(to, from, length, bpp, alpha, mask)
#define | ALPHA_BLIT16_565_50(to, from, length, bpp, alpha) ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7de)
#define | ALPHA_BLIT16_555_50(to, from, length, bpp, alpha) ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbde)
#define | CHOOSE_BLIT(blitter, alpha, fmt)
#define | RLEPIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
#define | RLECLIPBLIT(bpp, Type, do_blit)
#define | RLESKIP(bpp, Type)
#define | RLEBLIT(bpp, Type, do_blit)
#define | BLIT_TRANSL_888(src, dst)
#define | BLIT_TRANSL_565(src, dst)
#define | BLIT_TRANSL_555(src, dst)
#define | RLEALPHACLIPBLIT(Ptype, Ctype, do_blend)
#define | RLEALPHABLIT(Ptype, Ctype, do_blend)
#define | ISOPAQUE(pixel, fmt) ((((pixel) & fmt->Amask) >> fmt->Ashift) == 255)
#define | ISTRANSL(pixel, fmt) ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U)
#define | ADD_OPAQUE_COUNTS(n, m)
#define | ADD_TRANSL_COUNTS(n, m) (((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4)
#define | ADD_COUNTS(n, m)

## Typedefs

typedef Uint32(* | getpix_func) (Uint8 *)

## Functions

static void | RLEClipBlit (int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha)
int | SDL_RLEBlit (SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
static void | RLEAlphaClipBlit (int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect)
int | SDL_RLEAlphaBlit (SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
static int | copy_opaque_16 (void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
static int | uncopy_opaque_16 (Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
static int | copy_transl_565 (void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
static int | copy_transl_555 (void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
static int | uncopy_transl_16 (Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
static int | copy_32 (void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
static int | uncopy_32 (Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
static int | RLEAlphaSurface (SDL_Surface *surface)
static Uint32 | getpix_8 (Uint8 *srcbuf)
static Uint32 | getpix_16 (Uint8 *srcbuf)
static Uint32 | getpix_24 (Uint8 *srcbuf)
static Uint32 | getpix_32 (Uint8 *srcbuf)
static int | RLEColorkeySurface (SDL_Surface *surface)
int | SDL_RLESurface (SDL_Surface *surface)
static SDL_bool | UnRLEAlpha (SDL_Surface *surface)
void | SDL_UnRLESurface (SDL_Surface *surface, int recode)

## Variables

static const getpix_func | getpixes [4]

## Macro Definition Documentation

## ADD_COUNTS

#define ADD_COUNTS | ( |  | n,
|  |  | m
| ) |  |

Value:
if(bpp == 4) { \
((Uint16 *)dst)[0] = n; \
((Uint16 *)dst)[1] = m; \
dst += 4; \
} else { \
dst[0] = n; \
dst[1] = m; \
dst += 2; \
}

## ADD_OPAQUE_COUNTS

#define ADD_OPAQUE_COUNTS | ( |  | n,
|  |  | m
| ) |  |

Value:
if(df->BytesPerPixel == 4) { \
((Uint16 *)dst)[0] = n; \
((Uint16 *)dst)[1] = m; \
dst += 4; \
} else { \
dst[0] = n; \
dst[1] = m; \
dst += 2; \
}

## ADD_TRANSL_COUNTS

#define ADD_TRANSL_COUNTS | ( |  | n,
|  |  | m
| ) |  | (((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4)

## ALPHA_BLIT16_50

#define ALPHA_BLIT16_50 | ( |  | to,
|  |  | from,
|  |  | length,
|  |  | bpp,
|  |  | alpha,
|  |  | mask
| ) |  |

Value:
do { \
unsigned n = (length); \
Uint16 *src = (Uint16 *)(from); \
Uint16 *dst = (Uint16 *)(to); \
if (((uintptr_t)src ^ (uintptr_t)dst) & 3) { \
/* source and destination not in phase, blit one by one */ \
while (n--) \
BLEND16_50(dst, src, mask); \
} else { \
if ((uintptr_t)src & 3) { \
/* first odd pixel */ \
BLEND16_50(dst, src, mask); \
n--; \
} \
for (; n > 1; n -= 2) { \
Uint32 s = *(Uint32 *)src; \
Uint32 d = *(Uint32 *)dst; \
*(Uint32 *)dst = ((s & (mask | mask << 16)) >> 1) \
+ ((d & (mask | mask << 16)) >> 1) \
+ (s & d & (~(mask | mask << 16))); \
src += 2; \
dst += 2; \
} \
if (n) \
BLEND16_50(dst, src, mask); /* last odd pixel */ \
} \
} while(0)

Definition at line 268 of file SDL_RLEaccel.c.

## ALPHA_BLIT16_555

#define ALPHA_BLIT16_555 | ( |  | to,
|  |  | from,
|  |  | length,
|  |  | bpp,
|  |  | alpha
| ) |  |

Value:
do { \
int i; \
Uint16 *src = (Uint16 *)(from); \
Uint16 *dst = (Uint16 *)(to); \
Uint32 ALPHA = alpha >> 3; \
for(i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
s = (s | s << 16) & 0x03e07c1f; \
d = (d | d << 16) & 0x03e07c1f; \
d += (s - d) * ALPHA >> 5; \
d &= 0x03e07c1f; \
*dst++ = (Uint16)(d | d >> 16); \
} \
} while(0)

Definition at line 155 of file SDL_RLEaccel.c.

## ALPHA_BLIT16_555_50

#define ALPHA_BLIT16_555_50 | ( |  | to,
|  |  | from,
|  |  | length,
|  |  | bpp,
|  |  | alpha
| ) |  | ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbde)

Definition at line 300 of file SDL_RLEaccel.c.

## ALPHA_BLIT16_565

#define ALPHA_BLIT16_565 | ( |  | to,
|  |  | from,
|  |  | length,
|  |  | bpp,
|  |  | alpha
| ) |  |

Value:
do { \
int i; \
Uint16 *src = (Uint16 *)(from); \
Uint16 *dst = (Uint16 *)(to); \
Uint32 ALPHA = alpha >> 3; \
for(i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
s = (s | s << 16) & 0x07e0f81f; \
d = (d | d << 16) & 0x07e0f81f; \
d += (s - d) * ALPHA >> 5; \
d &= 0x07e0f81f; \
*dst++ = (Uint16)(d | d >> 16); \
} \
} while(0)

Definition at line 138 of file SDL_RLEaccel.c.

## ALPHA_BLIT16_565_50

#define ALPHA_BLIT16_565_50 | ( |  | to,
|  |  | from,
|  |  | length,
|  |  | bpp,
|  |  | alpha
| ) |  | ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7de)

Definition at line 297 of file SDL_RLEaccel.c.

## ALPHA_BLIT32_888

#define ALPHA_BLIT32_888 | ( |  | to,
|  |  | from,
|  |  | length,
|  |  | bpp,
|  |  | alpha
| ) |  |

Value:
do { \
int i; \
Uint32 *src = (Uint32 *)(from); \
Uint32 *dst = (Uint32 *)(to); \
for (i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
Uint32 s1 = s & 0xff00ff; \
Uint32 d1 = d & 0xff00ff; \
d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
s &= 0xff00; \
d &= 0xff00; \
d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
*dst++ = d1 | d; \
} \
} while (0)

Definition at line 114 of file SDL_RLEaccel.c.

## ALPHA_BLIT32_888_50

#define ALPHA_BLIT32_888_50 | ( |  | to,
|  |  | from,
|  |  | length,
|  |  | bpp,
|  |  | alpha
| ) |  |

Value:
do { \
int i; \
Uint32 *src = (Uint32 *)(from); \
Uint32 *dst = (Uint32 *)(to); \
for(i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
*dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \
+ (s & d & 0x00010101); \
} \
} while(0)

Definition at line 240 of file SDL_RLEaccel.c.

## ALPHA_BLIT_ANY

#define ALPHA_BLIT_ANY | ( |  | to,
|  |  | from,
|  |  | length,
|  |  | bpp,
|  |  | alpha
| ) |  |

Definition at line 175 of file SDL_RLEaccel.c.

## BLEND16_50

#define BLEND16_50 | ( |  | dst,
|  |  | src,
|  |  | mask
| ) |  |

Value:
do { \
Uint32 s = *src++; \
Uint32 d = *dst; \
*dst++ = (Uint16)((((s & mask) + (d & mask)) >> 1) + \
(s & d & (~mask & 0xffff))); \
} while(0)

Definition at line 259 of file SDL_RLEaccel.c.

## BLIT_TRANSL_555

#define BLIT_TRANSL_555 | ( |  | src,
|  |  | dst
| ) |  |

Value:
do { \
Uint32 s = src; \
Uint32 d = dst; \
unsigned alpha = (s & 0x3e0) >> 5; \
s &= 0x03e07c1f; \
d = (d | d << 16) & 0x03e07c1f; \
d += (s - d) * alpha >> 5; \
d &= 0x03e07c1f; \
dst = (Uint16)(d | d >> 16); \
} while(0)

Definition at line 601 of file SDL_RLEaccel.c.

## BLIT_TRANSL_565

#define BLIT_TRANSL_565 | ( |  | src,
|  |  | dst
| ) |  |

Value:
do { \
Uint32 s = src; \
Uint32 d = dst; \
unsigned alpha = (s & 0x3e0) >> 5; \
s &= 0x07e0f81f; \
d = (d | d << 16) & 0x07e0f81f; \
d += (s - d) * alpha >> 5; \
d &= 0x07e0f81f; \
dst = (Uint16)(d | d >> 16); \
} while(0)

Definition at line 589 of file SDL_RLEaccel.c.

## BLIT_TRANSL_888

#define BLIT_TRANSL_888 | ( |  | src,
|  |  | dst
| ) |  |

Value:
do { \
Uint32 s = src; \
Uint32 d = dst; \
unsigned alpha = s >> 24; \
Uint32 s1 = s & 0xff00ff; \
Uint32 d1 = d & 0xff00ff; \
d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
s &= 0xff00; \
d &= 0xff00; \
d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
dst = d1 | d | 0xff000000; \
} while(0)

Definition at line 571 of file SDL_RLEaccel.c.

## CHOOSE_BLIT

#define CHOOSE_BLIT | ( |  | blitter,
|  |  | alpha,
|  |  | fmt
| ) |  |

Definition at line 303 of file SDL_RLEaccel.c.

## ISOPAQUE

#define ISOPAQUE | ( |  | pixel,
|  |  | fmt
| ) |  | ((((pixel) & fmt->Amask) >> fmt->Ashift) == 255)

Definition at line 1019 of file SDL_RLEaccel.c.

## ISTRANSL

#define ISTRANSL | ( |  | pixel,
|  |  | fmt
| ) |  | ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U)

Definition at line 1021 of file SDL_RLEaccel.c.

## MIN

#define MIN | ( |  | a,
|  |  | b
| ) |  | ((a) < (b) ? (a) : (b))

Definition at line 94 of file SDL_RLEaccel.c.

## OPAQUE_BLIT

#define OPAQUE_BLIT | ( |  | to,
|  |  | from,
|  |  | length,
|  |  | bpp,
|  |  | alpha
| ) |  | PIXEL_COPY(to, from, length, bpp)

Definition at line 104 of file SDL_RLEaccel.c.

## PIXEL_COPY

#define PIXEL_COPY | ( |  | to,
|  |  | from,
|  |  | len,
|  |  | bpp
| ) |  | SDL_memcpy(to, from, (size_t)(len) * (bpp))

Definition at line 97 of file SDL_RLEaccel.c.

## RLEALPHABLIT

#define RLEALPHABLIT | ( |  | Ptype,
|  |  | Ctype,
|  |  | do_blend
| ) |  |

## RLEALPHACLIPBLIT

#define RLEALPHACLIPBLIT | ( |  | Ptype,
|  |  | Ctype,
|  |  | do_blend
| ) |  |

## RLEBLIT

#define RLEBLIT | ( |  | bpp,
|  |  | Type,
|  |  | do_blit
| ) |  |

Value:
do { \
int linecount = srcrect->h; \
int ofs = 0; \
for(;;) { \
unsigned run; \
ofs += *(Type *)srcbuf; \
run = ((Type *)srcbuf)[1]; \
srcbuf += 2 * sizeof(Type); \
if(run) { \
do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \
srcbuf += run * bpp; \
ofs += run; \
} else if(!ofs) \
break; \
if(ofs == w) { \
ofs = 0; \
dstbuf += surf_dst->pitch; \
if(!--linecount) \
break; \
} \
} \
} while(0)

## RLECLIPBLIT

#define RLECLIPBLIT | ( |  | bpp,
|  |  | Type,
|  |  | do_blit
| ) |  |

## RLEPIXEL_FROM_RGBA

#define RLEPIXEL_FROM_RGBA | ( |  | Pixel,
|  |  | fmt,
|  |  | r,
|  |  | g,
|  |  | b,
|  |  | a
| ) |  |

Value:
{ \
Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
((g>>fmt->Gloss)<<fmt->Gshift)| \
((b>>fmt->Bloss)<<fmt->Bshift)| \
(a<<24); \
}

Definition at line 377 of file SDL_RLEaccel.c.

## RLESKIP

#define RLESKIP | ( |  | bpp,
|  |  | Type
| ) |  |

Value:
for(;;) { \
int run; \
ofs += *(Type *)srcbuf; \
run = ((Type *)srcbuf)[1]; \
srcbuf += sizeof(Type) * 2; \
if(run) { \
srcbuf += run * bpp; \
ofs += run; \
} else if(!ofs) \
goto done; \
if(ofs == w) { \
ofs = 0; \
if(!--vskip) \
break; \
} \
}

## Typedef Documentation

## getpix_func

typedef Uint32(* getpix_func) (Uint8 *)

Definition at line 1267 of file SDL_RLEaccel.c.

## Function Documentation

## copy_32()

static int copy_32 | ( | void * | dst,
|  | Uint32 * | src,
|  | int | n,
|  | SDL_PixelFormat * | sfmt,
|  | SDL_PixelFormat * | dfmt
| ) |  |

static

Definition at line 986 of file SDL_RLEaccel.c.

{
int i;
Uint32 *d = dst;
for (i = 0; i < n; i++) {
unsigned r, g, b, a;
RGBA_FROM_8888(*src, sfmt, r, g, b, a);
RLEPIXEL_FROM_RGBA(*d, dfmt, r, g, b, a);
d++;
src++;
}
return n * 4;
}

References d, i, RGBA_FROM_8888, and RLEPIXEL_FROM_RGBA.

Referenced by RLEAlphaSurface().

## copy_opaque_16()

static int copy_opaque_16 | ( | void * | dst,
|  | Uint32 * | src,
|  | int | n,
|  | SDL_PixelFormat * | sfmt,
|  | SDL_PixelFormat * | dfmt
| ) |  |

static

Definition at line 892 of file SDL_RLEaccel.c.

{
int i;
Uint16 *d = dst;
for (i = 0; i < n; i++) {
unsigned r, g, b;
RGB_FROM_PIXEL(*src, sfmt, r, g, b);
PIXEL_FROM_RGB(*d, dfmt, r, g, b);
src++;
d++;
}
return n * 2;
}

References d, i, PIXEL_FROM_RGB, and RGB_FROM_PIXEL.

Referenced by RLEAlphaSurface().

## copy_transl_555()

static int copy_transl_555 | ( | void * | dst,
|  | Uint32 * | src,
|  | int | n,
|  | SDL_PixelFormat * | sfmt,
|  | SDL_PixelFormat * | dfmt
| ) |  |

static

Definition at line 948 of file SDL_RLEaccel.c.

{
int i;
Uint32 *d = dst;
for (i = 0; i < n; i++) {
unsigned r, g, b, a;
Uint16 pix;
RGBA_FROM_8888(*src, sfmt, r, g, b, a);
PIXEL_FROM_RGB(pix, dfmt, r, g, b);
*d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
src++;
d++;
}
return n * 4;
}

References d, i, PIXEL_FROM_RGB, and RGBA_FROM_8888.

Referenced by RLEAlphaSurface().

## copy_transl_565()

static int copy_transl_565 | ( | void * | dst,
|  | Uint32 * | src,
|  | int | n,
|  | SDL_PixelFormat * | sfmt,
|  | SDL_PixelFormat * | dfmt
| ) |  |

static

Definition at line 929 of file SDL_RLEaccel.c.

{
int i;
Uint32 *d = dst;
for (i = 0; i < n; i++) {
unsigned r, g, b, a;
Uint16 pix;
RGBA_FROM_8888(*src, sfmt, r, g, b, a);
PIXEL_FROM_RGB(pix, dfmt, r, g, b);
*d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
src++;
d++;
}
return n * 4;
}

References d, i, PIXEL_FROM_RGB, and RGBA_FROM_8888.

Referenced by RLEAlphaSurface().

## getpix_16()

static Uint32 getpix_16 | ( | Uint8 * | srcbuf | ) |

static

Definition at line 1246 of file SDL_RLEaccel.c.

{
return *(Uint16 *) srcbuf;
}

## getpix_24()

static Uint32 getpix_24 | ( | Uint8 * | srcbuf | ) |

static

Definition at line 1252 of file SDL_RLEaccel.c.

{
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16);
#else
return (srcbuf[0] << 16) + (srcbuf[1] << 8) + srcbuf[2];
#endif
}

## getpix_32()

static Uint32 getpix_32 | ( | Uint8 * | srcbuf | ) |

static

Definition at line 1262 of file SDL_RLEaccel.c.

{
return *(Uint32 *) srcbuf;
}

## getpix_8()

static Uint32 getpix_8 | ( | Uint8 * | srcbuf | ) |

static

Definition at line 1240 of file SDL_RLEaccel.c.

{
return *srcbuf;
}

## RLEAlphaClipBlit()

static void RLEAlphaClipBlit | ( | int | w,
|  | Uint8 * | srcbuf,
|  | SDL_Surface * | surf_dst,
|  | Uint8 * | dstbuf,
|  | SDL_Rect * | srcrect
| ) |  |

static

Definition at line 635 of file SDL_RLEaccel.c.

{
SDL_PixelFormat *df = surf_dst->format;
/*
* clipped blitter: Ptype is the destination pixel type,
* Ctype the translucent count type, and do_blend the macro
* to blend one pixel.
*/
#define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend) \
do { \
int linecount = srcrect->h; \
int left = srcrect->x; \
int right = left + srcrect->w; \
dstbuf -= left * sizeof(Ptype); \
do { \
int ofs = 0; \
/* blit opaque pixels on one line */ \
do { \
unsigned run; \
ofs += ((Ctype *)srcbuf)[0]; \
run = ((Ctype *)srcbuf)[1]; \
srcbuf += 2 * sizeof(Ctype); \
if(run) { \
/* clip to left and right borders */ \
int cofs = ofs; \
int crun = run; \
if(left - cofs > 0) { \
crun -= left - cofs; \
cofs = left; \
} \
if(crun > right - cofs) \
crun = right - cofs; \
if(crun > 0) \
PIXEL_COPY(dstbuf + cofs * sizeof(Ptype), \
srcbuf + (cofs - ofs) * sizeof(Ptype), \
(unsigned)crun, sizeof(Ptype)); \
srcbuf += run * sizeof(Ptype); \
ofs += run; \
} else if(!ofs) \
return; \
} while(ofs < w); \
/* skip padding if necessary */ \
if(sizeof(Ptype) == 2) \
srcbuf += (uintptr_t)srcbuf & 2; \
/* blit translucent pixels on the same line */ \
ofs = 0; \
do { \
unsigned run; \
ofs += ((Uint16 *)srcbuf)[0]; \
run = ((Uint16 *)srcbuf)[1]; \
srcbuf += 4; \
if(run) { \
/* clip to left and right borders */ \
int cofs = ofs; \
int crun = run; \
if(left - cofs > 0) { \
crun -= left - cofs; \
cofs = left; \
} \
if(crun > right - cofs) \
crun = right - cofs; \
if(crun > 0) { \
Ptype *dst = (Ptype *)dstbuf + cofs; \
Uint32 *src = (Uint32 *)srcbuf + (cofs - ofs); \
int i; \
for(i = 0; i < crun; i++) \
do_blend(src[i], dst[i]); \
} \
srcbuf += run * 4; \
ofs += run; \
} \
} while(ofs < w); \
dstbuf += surf_dst->pitch; \
} while(--linecount); \
} while(0)
switch (df->BytesPerPixel) {
case 2:
if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565);
else
RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555);
break;
case 4:
RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888);
break;
}
}

References BLIT_TRANSL_555, BLIT_TRANSL_565, BLIT_TRANSL_888, SDL_PixelFormat::Bmask, SDL_PixelFormat::BytesPerPixel, SDL_Surface::format, SDL_PixelFormat::Gmask, RLEALPHACLIPBLIT, and SDL_PixelFormat::Rmask.

Referenced by SDL_RLEAlphaBlit().

## RLEAlphaSurface()

static int RLEAlphaSurface | ( | SDL_Surface * | surface | ) |

static

Definition at line 1026 of file SDL_RLEaccel.c.

{
SDL_Surface *dest;
SDL_PixelFormat *df;
int maxsize = 0;
int max_opaque_run;
int max_transl_run = 65535;
unsigned masksum;
Uint8 *rlebuf, *dst;
int (*copy_opaque) (void *, Uint32 *, int,
SDL_PixelFormat *, SDL_PixelFormat *);
int (*copy_transl) (void *, Uint32 *, int,
SDL_PixelFormat *, SDL_PixelFormat *);
dest = surface->map->dst;
if (!dest)
return -1;
df = dest->format;
if (surface->format->BitsPerPixel != 32)
return -1; /* only 32bpp source supported */
/* find out whether the destination is one we support,
and determine the max size of the encoded result */
masksum = df->Rmask | df->Gmask | df->Bmask;
switch (df->BytesPerPixel) {
case 2:
/* 16bpp: only support 565 and 555 formats */
switch (masksum) {
case 0xffff:
if (df->Gmask == 0x07e0
|| df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
copy_opaque = copy_opaque_16;
copy_transl = copy_transl_565;
} else
return -1;
break;
case 0x7fff:
if (df->Gmask == 0x03e0
|| df->Rmask == 0x03e0 || df->Bmask == 0x03e0) {
copy_opaque = copy_opaque_16;
copy_transl = copy_transl_555;
} else
return -1;
break;
default:
return -1;
}
max_opaque_run = 255; /* runs stored as bytes */
/* worst case is alternating opaque and translucent pixels,
with room for alignment padding between lines */
maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2;
break;
case 4:
if (masksum != 0x00ffffff)
return -1; /* requires unused high byte */
copy_opaque = copy_32;
copy_transl = copy_32;
max_opaque_run = 255; /* runs stored as short ints */
/* worst case is alternating opaque and translucent pixels */
maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4;
break;
default:
return -1; /* anything else unsupported right now */
}
maxsize += sizeof(RLEDestFormat);
rlebuf = (Uint8 *) SDL_malloc(maxsize);
if (!rlebuf) {
return SDL_OutOfMemory();
}
{
/* save the destination format so we can undo the encoding later */
RLEDestFormat *r = (RLEDestFormat *) rlebuf;
r->BytesPerPixel = df->BytesPerPixel;
r->Rmask = df->Rmask;
r->Gmask = df->Gmask;
r->Bmask = df->Bmask;
r->Amask = df->Amask;
r->Rloss = df->Rloss;
r->Gloss = df->Gloss;
r->Bloss = df->Bloss;
r->Aloss = df->Aloss;
r->Rshift = df->Rshift;
r->Gshift = df->Gshift;
r->Bshift = df->Bshift;
r->Ashift = df->Ashift;
}
dst = rlebuf + sizeof(RLEDestFormat);
/* Do the actual encoding */
{
int x, y;
int h = surface->h, w = surface->w;
SDL_PixelFormat *sf = surface->format;
Uint32 *src = (Uint32 *) surface->pixels;
Uint8 *lastline = dst; /* end of last non-blank line */
/* opaque counts are 8 or 16 bits, depending on target depth */
#define ADD_OPAQUE_COUNTS(n, m) \
if(df->BytesPerPixel == 4) { \
((Uint16 *)dst)[0] = n; \
((Uint16 *)dst)[1] = m; \
dst += 4; \
} else { \
dst[0] = n; \
dst[1] = m; \
dst += 2; \
}
/* translucent counts are always 16 bit */
#define ADD_TRANSL_COUNTS(n, m) \
(((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4)
for (y = 0; y < h; y++) {
int runstart, skipstart;
int blankline = 0;
/* First encode all opaque pixels of a scan line */
x = 0;
do {
int run, skip, len;
skipstart = x;
while (x < w && !ISOPAQUE(src[x], sf))
x++;
runstart = x;
while (x < w && ISOPAQUE(src[x], sf))
x++;
skip = runstart - skipstart;
if (skip == w)
blankline = 1;
run = x - runstart;
while (skip > max_opaque_run) {
ADD_OPAQUE_COUNTS(max_opaque_run, 0);
skip -= max_opaque_run;
}
len = MIN(run, max_opaque_run);
ADD_OPAQUE_COUNTS(skip, len);
dst += copy_opaque(dst, src + runstart, len, sf, df);
runstart += len;
run -= len;
while (run) {
len = MIN(run, max_opaque_run);
ADD_OPAQUE_COUNTS(0, len);
dst += copy_opaque(dst, src + runstart, len, sf, df);
runstart += len;
run -= len;
}
} while (x < w);
/* Make sure the next output address is 32-bit aligned */
dst += (uintptr_t) dst & 2;
/* Next, encode all translucent pixels of the same scan line */
x = 0;
do {
int run, skip, len;
skipstart = x;
while (x < w && !ISTRANSL(src[x], sf))
x++;
runstart = x;
while (x < w && ISTRANSL(src[x], sf))
x++;
skip = runstart - skipstart;
blankline &= (skip == w);
run = x - runstart;
while (skip > max_transl_run) {
ADD_TRANSL_COUNTS(max_transl_run, 0);
skip -= max_transl_run;
}
len = MIN(run, max_transl_run);
ADD_TRANSL_COUNTS(skip, len);
dst += copy_transl(dst, src + runstart, len, sf, df);
runstart += len;
run -= len;
while (run) {
len = MIN(run, max_transl_run);
ADD_TRANSL_COUNTS(0, len);
dst += copy_transl(dst, src + runstart, len, sf, df);
runstart += len;
run -= len;
}
if (!blankline)
lastline = dst;
} while (x < w);
src += surface->pitch >> 2;
}
dst = lastline; /* back up past trailing blank lines */
ADD_OPAQUE_COUNTS(0, 0);
}
#undef ADD_OPAQUE_COUNTS
#undef ADD_TRANSL_COUNTS
/* Now that we have it encoded, release the original pixels */
if (!(surface->flags & SDL_PREALLOC)) {
SDL_SIMDFree(surface->pixels);
surface->pixels = NULL;
surface->flags &= ~SDL_SIMD_ALIGNED;
}
/* realloc the buffer to release unused memory */
{
Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
if (!p)
p = rlebuf;
surface->map->data = p;
}
return 0;
}

References ADD_OPAQUE_COUNTS, ADD_TRANSL_COUNTS, SDL_PixelFormat::Aloss, SDL_PixelFormat::Amask, SDL_PixelFormat::Ashift, SDL_PixelFormat::Bloss, SDL_PixelFormat::Bmask, SDL_PixelFormat::Bshift, SDL_PixelFormat::BytesPerPixel, RLEDestFormat::BytesPerPixel, copy_32(), copy_opaque_16(), copy_transl_555(), copy_transl_565(), SDL_BlitMap::dst, SDL_Surface::format, SDL_PixelFormat::format, SDL_PixelFormat::Gloss, SDL_PixelFormat::Gmask, SDL_PixelFormat::Gshift, ISOPAQUE, ISTRANSL, SDL_Surface::map, MIN, NULL, SDL_PixelFormat::Rloss, SDL_PixelFormat::Rmask, SDL_PixelFormat::Rshift, SDL_malloc, SDL_OutOfMemory, SDL_PREALLOC, SDL_realloc, SDL_SIMD_ALIGNED, and SDL_SIMDFree.

Referenced by SDL_RLESurface().

## RLEClipBlit()

static void RLEClipBlit | ( | int | w,
|  | Uint8 * | srcbuf,
|  | SDL_Surface * | surf_dst,
|  | Uint8 * | dstbuf,
|  | SDL_Rect * | srcrect,
|  | unsigned | alpha
| ) |  |

static

Definition at line 390 of file SDL_RLEaccel.c.

{
SDL_PixelFormat *fmt = surf_dst->format;
#define RLECLIPBLIT(bpp, Type, do_blit) \
do { \
int linecount = srcrect->h; \
int ofs = 0; \
int left = srcrect->x; \
int right = left + srcrect->w; \
dstbuf -= left * bpp; \
for (;;) { \
int run; \
ofs += *(Type *)srcbuf; \
run = ((Type *)srcbuf)[1]; \
srcbuf += 2 * sizeof(Type); \
if (run) { \
/* clip to left and right borders */ \
if (ofs < right) { \
int start = 0; \
int len = run; \
int startcol; \
if (left - ofs > 0) { \
start = left - ofs; \
len -= start; \
if (len <= 0) \
goto nocopy ## bpp ## do_blit; \
} \
startcol = ofs + start; \
if (len > right - startcol) \
len = right - startcol; \
do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \
len, bpp, alpha); \
} \
nocopy ## bpp ## do_blit: \
srcbuf += run * bpp; \
ofs += run; \
} else if (!ofs) \
break; \
\
if (ofs == w) { \
ofs = 0; \
dstbuf += surf_dst->pitch; \
if (!--linecount) \
break; \
} \
} \
} while(0)
CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt);
#undef RLECLIPBLIT
}

References CHOOSE_BLIT, SDL_Surface::format, and RLECLIPBLIT.

Referenced by SDL_RLEBlit().

## RLEColorkeySurface()

static int RLEColorkeySurface | ( | SDL_Surface * | surface | ) |

static

Definition at line 1274 of file SDL_RLEaccel.c.

{
Uint8 *rlebuf, *dst;
int maxn;
int y;
Uint8 *srcbuf, *lastline;
int maxsize = 0;
const int bpp = surface->format->BytesPerPixel;
getpix_func getpix;
Uint32 ckey, rgbmask;
int w, h;
/* calculate the worst case size for the compressed surface */
switch (bpp) {
case 1:
/* worst case is alternating opaque and transparent pixels,
starting with an opaque pixel */
maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2;
break;
case 2:
case 3:
/* worst case is solid runs, at most 255 pixels wide */
maxsize = surface->h * (2 * (surface->w / 255 + 1)
+ surface->w * bpp) + 2;
break;
case 4:
/* worst case is solid runs, at most 65535 pixels wide */
maxsize = surface->h * (4 * (surface->w / 65535 + 1)
+ surface->w * 4) + 4;
break;
default:
return -1;
}
rlebuf = (Uint8 *) SDL_malloc(maxsize);
if (rlebuf == NULL) {
return SDL_OutOfMemory();
}
/* Set up the conversion */
srcbuf = (Uint8 *) surface->pixels;
maxn = bpp == 4 ? 65535 : 255;
dst = rlebuf;
rgbmask = ~surface->format->Amask;
ckey = surface->map->info.colorkey & rgbmask;
lastline = dst;
getpix = getpixes[bpp - 1];
w = surface->w;
h = surface->h;
#define ADD_COUNTS(n, m) \
if(bpp == 4) { \
((Uint16 *)dst)[0] = n; \
((Uint16 *)dst)[1] = m; \
dst += 4; \
} else { \
dst[0] = n; \
dst[1] = m; \
dst += 2; \
}
for (y = 0; y < h; y++) {
int x = 0;
int blankline = 0;
do {
int run, skip, len;
int runstart;
int skipstart = x;
/* find run of transparent, then opaque pixels */
while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
x++;
runstart = x;
while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
x++;
skip = runstart - skipstart;
if (skip == w)
blankline = 1;
run = x - runstart;
/* encode segment */
while (skip > maxn) {
ADD_COUNTS(maxn, 0);
skip -= maxn;
}
len = MIN(run, maxn);
ADD_COUNTS(skip, len);
SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
dst += len * bpp;
run -= len;
runstart += len;
while (run) {
len = MIN(run, maxn);
ADD_COUNTS(0, len);
SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
dst += len * bpp;
runstart += len;
run -= len;
}
if (!blankline)
lastline = dst;
} while (x < w);
srcbuf += surface->pitch;
}
dst = lastline; /* back up bast trailing blank lines */
ADD_COUNTS(0, 0);
#undef ADD_COUNTS
/* Now that we have it encoded, release the original pixels */
if (!(surface->flags & SDL_PREALLOC)) {
SDL_SIMDFree(surface->pixels);
surface->pixels = NULL;
surface->flags &= ~SDL_SIMD_ALIGNED;
}
/* realloc the buffer to release unused memory */
{
/* If realloc returns NULL, the original block is left intact */
Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
if (!p)
p = rlebuf;
surface->map->data = p;
}
return 0;
}

References ADD_COUNTS, getpixes, MIN, NULL, SDL_malloc, SDL_memcpy, SDL_OutOfMemory, SDL_PREALLOC, SDL_realloc, SDL_SIMD_ALIGNED, and SDL_SIMDFree.

Referenced by SDL_RLESurface().

## SDL_RLEAlphaBlit()

int SDL_RLEAlphaBlit | ( | SDL_Surface * | surf_src,
|  | SDL_Rect * | srcrect,
|  | SDL_Surface * | surf_dst,
|  | SDL_Rect * | dstrect
| ) |  |

Definition at line 727 of file SDL_RLEaccel.c.

{
int x, y;
int w = surf_src->w;
Uint8 *srcbuf, *dstbuf;
SDL_PixelFormat *df = surf_dst->format;
/* Lock the destination if necessary */
if (SDL_MUSTLOCK(surf_dst)) {
if (SDL_LockSurface(surf_dst) < 0) {
return -1;
}
}
x = dstrect->x;
y = dstrect->y;
dstbuf = (Uint8 *) surf_dst->pixels + y * surf_dst->pitch + x * df->BytesPerPixel;
srcbuf = (Uint8 *) surf_src->map->data + sizeof(RLEDestFormat);
{
/* skip lines at the top if necessary */
int vskip = srcrect->y;
if (vskip) {
int ofs;
if (df->BytesPerPixel == 2) {
/* the 16/32 interleaved format */
do {
/* skip opaque line */
ofs = 0;
do {
int run;
ofs += srcbuf[0];
run = srcbuf[1];
srcbuf += 2;
if (run) {
srcbuf += 2 * run;
ofs += run;
} else if (!ofs)
goto done;
} while (ofs < w);
/* skip padding */
srcbuf += (uintptr_t) srcbuf & 2;
/* skip translucent line */
ofs = 0;
do {
int run;
ofs += ((Uint16 *) srcbuf)[0];
run = ((Uint16 *) srcbuf)[1];
srcbuf += 4 * (run + 1);
ofs += run;
} while (ofs < w);
} while (--vskip);
} else {
/* the 32/32 interleaved format */
vskip <<= 1; /* opaque and translucent have same format */
do {
ofs = 0;
do {
int run;
ofs += ((Uint16 *) srcbuf)[0];
run = ((Uint16 *) srcbuf)[1];
srcbuf += 4;
if (run) {
srcbuf += 4 * run;
ofs += run;
} else if (!ofs)
goto done;
} while (ofs < w);
} while (--vskip);
}
}
}
/* if left or right edge clipping needed, call clip blit */
if (srcrect->x || srcrect->w != surf_src->w) {
RLEAlphaClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect);
} else {
/*
* non-clipped blitter. Ptype is the destination pixel type,
* Ctype the translucent count type, and do_blend the
* macro to blend one pixel.
*/
#define RLEALPHABLIT(Ptype, Ctype, do_blend) \
do { \
int linecount = srcrect->h; \
do { \
int ofs = 0; \
/* blit opaque pixels on one line */ \
do { \
unsigned run; \
ofs += ((Ctype *)srcbuf)[0]; \
run = ((Ctype *)srcbuf)[1]; \
srcbuf += 2 * sizeof(Ctype); \
if(run) { \
PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \
run, sizeof(Ptype)); \
srcbuf += run * sizeof(Ptype); \
ofs += run; \
} else if(!ofs) \
goto done; \
} while(ofs < w); \
/* skip padding if necessary */ \
if(sizeof(Ptype) == 2) \
srcbuf += (uintptr_t)srcbuf & 2; \
/* blit translucent pixels on the same line */ \
ofs = 0; \
do { \
unsigned run; \
ofs += ((Uint16 *)srcbuf)[0]; \
run = ((Uint16 *)srcbuf)[1]; \
srcbuf += 4; \
if(run) { \
Ptype *dst = (Ptype *)dstbuf + ofs; \
unsigned i; \
for(i = 0; i < run; i++) { \
Uint32 src = *(Uint32 *)srcbuf; \
do_blend(src, *dst); \
srcbuf += 4; \
dst++; \
} \
ofs += run; \
} \
} while(ofs < w); \
dstbuf += surf_dst->pitch; \
} while(--linecount); \
} while(0)
switch (df->BytesPerPixel) {
case 2:
if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0
|| df->Bmask == 0x07e0)
RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565);
else
RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555);
break;
case 4:
RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888);
break;
}
}
done:
/* Unlock the destination if necessary */
if (SDL_MUSTLOCK(surf_dst)) {
SDL_UnlockSurface(surf_dst);
}
return 0;
}

References BLIT_TRANSL_555, BLIT_TRANSL_565, BLIT_TRANSL_888, SDL_PixelFormat::Bmask, SDL_PixelFormat::BytesPerPixel, SDL_BlitMap::data, done, SDL_Surface::format, SDL_PixelFormat::Gmask, SDL_Surface::map, SDL_Surface::pitch, SDL_Surface::pixels, RLEALPHABLIT, RLEAlphaClipBlit(), SDL_PixelFormat::Rmask, SDL_LockSurface, SDL_MUSTLOCK, SDL_UnlockSurface, SDL_Surface::w, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_RLESurface().

## SDL_RLEBlit()

int SDL_RLEBlit | ( | SDL_Surface * | surf_src,
|  | SDL_Rect * | srcrect,
|  | SDL_Surface * | surf_dst,
|  | SDL_Rect * | dstrect
| ) |  |

Definition at line 449 of file SDL_RLEaccel.c.

{
Uint8 *dstbuf;
Uint8 *srcbuf;
int x, y;
int w = surf_src->w;
unsigned alpha;
/* Lock the destination if necessary */
if (SDL_MUSTLOCK(surf_dst)) {
if (SDL_LockSurface(surf_dst) < 0) {
return (-1);
}
}
/* Set up the source and destination pointers */
x = dstrect->x;
y = dstrect->y;
dstbuf = (Uint8 *) surf_dst->pixels
+ y * surf_dst->pitch + x * surf_src->format->BytesPerPixel;
srcbuf = (Uint8 *) surf_src->map->data;
{
/* skip lines at the top if necessary */
int vskip = srcrect->y;
int ofs = 0;
if (vskip) {
#define RLESKIP(bpp, Type) \
for(;;) { \
int run; \
ofs += *(Type *)srcbuf; \
run = ((Type *)srcbuf)[1]; \
srcbuf += sizeof(Type) * 2; \
if(run) { \
srcbuf += run * bpp; \
ofs += run; \
} else if(!ofs) \
goto done; \
if(ofs == w) { \
ofs = 0; \
if(!--vskip) \
break; \
} \
}
switch (surf_src->format->BytesPerPixel) {
case 1:
RLESKIP(1, Uint8);
break;
case 2:
RLESKIP(2, Uint8);
break;
case 3:
RLESKIP(3, Uint8);
break;
case 4:
RLESKIP(4, Uint16);
break;
}
#undef RLESKIP
}
}
alpha = surf_src->map->info.a;
/* if left or right edge clipping needed, call clip blit */
if (srcrect->x || srcrect->w != surf_src->w) {
RLEClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect, alpha);
} else {
SDL_PixelFormat *fmt = surf_src->format;
#define RLEBLIT(bpp, Type, do_blit) \
do { \
int linecount = srcrect->h; \
int ofs = 0; \
for(;;) { \
unsigned run; \
ofs += *(Type *)srcbuf; \
run = ((Type *)srcbuf)[1]; \
srcbuf += 2 * sizeof(Type); \
if(run) { \
do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \
srcbuf += run * bpp; \
ofs += run; \
} else if(!ofs) \
break; \
if(ofs == w) { \
ofs = 0; \
dstbuf += surf_dst->pitch; \
if(!--linecount) \
break; \
} \
} \
} while(0)
CHOOSE_BLIT(RLEBLIT, alpha, fmt);
#undef RLEBLIT
}
done:
/* Unlock the destination if necessary */
if (SDL_MUSTLOCK(surf_dst)) {
SDL_UnlockSurface(surf_dst);
}
return (0);
}

References SDL_BlitInfo::a, SDL_PixelFormat::BytesPerPixel, CHOOSE_BLIT, SDL_BlitMap::data, done, SDL_Surface::format, SDL_BlitMap::info, SDL_Surface::map, SDL_Surface::pitch, SDL_Surface::pixels, RLEBLIT, RLEClipBlit(), RLESKIP, SDL_LockSurface, SDL_MUSTLOCK, SDL_UnlockSurface, SDL_Surface::w, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_RLESurface(), and SDL_UnRLESurface().

## SDL_RLESurface()

int SDL_RLESurface | ( | SDL_Surface * | surface | ) |

Definition at line 1405 of file SDL_RLEaccel.c.

{
int flags;
/* Clear any previous RLE conversion */
if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 1);
}
/* We don't support RLE encoding of bitmaps */
if (surface->format->BitsPerPixel < 8) {
return -1;
}
/* Make sure the pixels are available */
if (!surface->pixels) {
return -1;
}
/* If we don't have colorkey or blending, nothing to do... */
flags = surface->map->info.flags;
if (!(flags & (SDL_COPY_COLORKEY | SDL_COPY_BLEND))) {
return -1;
}
/* Pass on combinations not supported */
if ((flags & SDL_COPY_MODULATE_COLOR) ||
((flags & SDL_COPY_MODULATE_ALPHA) && surface->format->Amask) ||
(flags & (SDL_COPY_ADD | SDL_COPY_MOD)) ||
(flags & SDL_COPY_NEAREST)) {
return -1;
}
/* Encode and set up the blit */
if (!surface->format->Amask || !(flags & SDL_COPY_BLEND)) {
if (!surface->map->identity) {
return -1;
}
if (RLEColorkeySurface(surface) < 0) {
return -1;
}
surface->map->blit = SDL_RLEBlit;
surface->map->info.flags |= SDL_COPY_RLE_COLORKEY;
} else {
if (RLEAlphaSurface(surface) < 0) {
return -1;
}
surface->map->blit = SDL_RLEAlphaBlit;
surface->map->info.flags |= SDL_COPY_RLE_ALPHAKEY;
}
/* The surface is now accelerated */
surface->flags |= SDL_RLEACCEL;
return (0);
}

References RLEAlphaSurface(), RLEColorkeySurface(), SDL_COPY_ADD, SDL_COPY_BLEND, SDL_COPY_COLORKEY, SDL_COPY_MOD, SDL_COPY_MODULATE_ALPHA, SDL_COPY_MODULATE_COLOR, SDL_COPY_NEAREST, SDL_COPY_RLE_ALPHAKEY, SDL_COPY_RLE_COLORKEY, SDL_RLEACCEL, SDL_RLEAlphaBlit(), SDL_RLEBlit(), and SDL_UnRLESurface().

Referenced by SDL_CalculateBlit(), and SDL_UnlockSurface().

## SDL_UnRLESurface()

void SDL_UnRLESurface | ( | SDL_Surface * | surface,
|  | int | recode
| ) |  |

Definition at line 1545 of file SDL_RLEaccel.c.

{
if (surface->flags & SDL_RLEACCEL) {
surface->flags &= ~SDL_RLEACCEL;
if (recode && !(surface->flags & SDL_PREALLOC)) {
if (surface->map->info.flags & SDL_COPY_RLE_COLORKEY) {
SDL_Rect full;
/* re-create the original surface */
surface->pixels = SDL_SIMDAlloc(surface->h * surface->pitch);
if (!surface->pixels) {
/* Oh crap... */
surface->flags |= SDL_RLEACCEL;
return;
}
surface->flags |= SDL_SIMD_ALIGNED;
/* fill it with the background color */
SDL_FillRect(surface, NULL, surface->map->info.colorkey);
/* now render the encoded surface */
full.x = full.y = 0;
full.w = surface->w;
full.h = surface->h;
SDL_RLEBlit(surface, &full, surface, &full);
} else {
if (!UnRLEAlpha(surface)) {
/* Oh crap... */
surface->flags |= SDL_RLEACCEL;
return;
}
}
}
surface->map->info.flags &=
~(SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY);
SDL_free(surface->map->data);
surface->map->data = NULL;
}
}

References SDL_Rect::h, NULL, SDL_COPY_RLE_ALPHAKEY, SDL_COPY_RLE_COLORKEY, SDL_FillRect, SDL_free, SDL_PREALLOC, SDL_RLEACCEL, SDL_RLEBlit(), SDL_SIMD_ALIGNED, SDL_SIMDAlloc, UnRLEAlpha(), SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_CalculateBlit(), SDL_FreeSurface(), SDL_LockSurface(), SDL_MapSurface(), and SDL_RLESurface().

## uncopy_32()

static int uncopy_32 | ( | Uint32 * | dst,
|  | void * | src,
|  | int | n,
|  | RLEDestFormat * | sfmt,
|  | SDL_PixelFormat * | dfmt
| ) |  |

static

Definition at line 1003 of file SDL_RLEaccel.c.

{
int i;
Uint32 *s = src;
for (i = 0; i < n; i++) {
unsigned r, g, b, a;
Uint32 pixel = *s++;
RGB_FROM_PIXEL(pixel, sfmt, r, g, b);
a = pixel >> 24;
PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
dst++;
}
return n * 4;
}

References i, PIXEL_FROM_RGBA, and RGB_FROM_PIXEL.

Referenced by UnRLEAlpha().

## uncopy_opaque_16()

static int uncopy_opaque_16 | ( | Uint32 * | dst,
|  | void * | src,
|  | int | n,
|  | RLEDestFormat * | sfmt,
|  | SDL_PixelFormat * | dfmt
| ) |  |

static

Definition at line 909 of file SDL_RLEaccel.c.

{
int i;
Uint16 *s = src;
unsigned alpha = dfmt->Amask ? 255 : 0;
for (i = 0; i < n; i++) {
unsigned r, g, b;
RGB_FROM_PIXEL(*s, sfmt, r, g, b);
PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha);
s++;
dst++;
}
return n * 2;
}

References SDL_PixelFormat::Amask, i, PIXEL_FROM_RGBA, and RGB_FROM_PIXEL.

Referenced by UnRLEAlpha().

## uncopy_transl_16()

static int uncopy_transl_16 | ( | Uint32 * | dst,
|  | void * | src,
|  | int | n,
|  | RLEDestFormat * | sfmt,
|  | SDL_PixelFormat * | dfmt
| ) |  |

static

Definition at line 967 of file SDL_RLEaccel.c.

{
int i;
Uint32 *s = src;
for (i = 0; i < n; i++) {
unsigned r, g, b, a;
Uint32 pix = *s++;
a = (pix & 0x3e0) >> 2;
pix = (pix & ~0x3e0) | pix >> 16;
RGB_FROM_PIXEL(pix, sfmt, r, g, b);
PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
dst++;
}
return n * 4;
}

References i, PIXEL_FROM_RGBA, and RGB_FROM_PIXEL.

Referenced by UnRLEAlpha().

## UnRLEAlpha()

static SDL_bool UnRLEAlpha | ( | SDL_Surface * | surface | ) |

static

Definition at line 1469 of file SDL_RLEaccel.c.

{
Uint8 *srcbuf;
Uint32 *dst;
SDL_PixelFormat *sf = surface->format;
RLEDestFormat *df = surface->map->data;
int (*uncopy_opaque) (Uint32 *, void *, int,
RLEDestFormat *, SDL_PixelFormat *);
int (*uncopy_transl) (Uint32 *, void *, int,
RLEDestFormat *, SDL_PixelFormat *);
int w = surface->w;
int bpp = df->BytesPerPixel;
if (bpp == 2) {
uncopy_opaque = uncopy_opaque_16;
uncopy_transl = uncopy_transl_16;
} else {
uncopy_opaque = uncopy_transl = uncopy_32;
}
surface->pixels = SDL_SIMDAlloc(surface->h * surface->pitch);
if (!surface->pixels) {
return (SDL_FALSE);
}
surface->flags |= SDL_SIMD_ALIGNED;
/* fill background with transparent pixels */
SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
dst = surface->pixels;
srcbuf = (Uint8 *) (df + 1);
for (;;) {
/* copy opaque pixels */
int ofs = 0;
do {
unsigned run;
if (bpp == 2) {
ofs += srcbuf[0];
run = srcbuf[1];
srcbuf += 2;
} else {
ofs += ((Uint16 *) srcbuf)[0];
run = ((Uint16 *) srcbuf)[1];
srcbuf += 4;
}
if (run) {
srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
ofs += run;
} else if (!ofs) {
goto end_function;
}
} while (ofs < w);
/* skip padding if needed */
if (bpp == 2)
srcbuf += (uintptr_t) srcbuf & 2;
/* copy translucent pixels */
ofs = 0;
do {
unsigned run;
ofs += ((Uint16 *) srcbuf)[0];
run = ((Uint16 *) srcbuf)[1];
srcbuf += 4;
if (run) {
srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
ofs += run;
}
} while (ofs < w);
dst += surface->pitch >> 2;
}
end_function:
return (SDL_TRUE);
}

References RLEDestFormat::BytesPerPixel, SDL_PixelFormat::format, SDL_FALSE, SDL_memset, SDL_SIMD_ALIGNED, SDL_SIMDAlloc, SDL_TRUE, uncopy_32(), uncopy_opaque_16(), and uncopy_transl_16().

Referenced by SDL_UnRLESurface().

## Variable Documentation

## getpixes

const getpix_func getpixes[4]

static

Initial value:
= {
getpix_8, getpix_16, getpix_24, getpix_32
}

Definition at line 1269 of file SDL_RLEaccel.c.

Referenced by RLEColorkeySurface().

SDL_PixelFormat::Rshift
Uint8 Rshift
Definition: SDL_pixels.h:330
SDL_UnlockSurface
#define SDL_UnlockSurface
Definition: SDL_dynapi_overrides.h:449
SDL_PixelFormat::Ashift
Uint8 Ashift
Definition: SDL_pixels.h:333
MIN
#define MIN(a, b)
Definition: SDL_RLEaccel.c:94
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:386
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
uncopy_transl_16
static int uncopy_transl_16(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:967
RLEDestFormat
Definition: SDL_RLEaccel.c:615
BLIT_TRANSL_555
#define BLIT_TRANSL_555(src, dst)
Definition: SDL_RLEaccel.c:601
SDL_PixelFormat::BytesPerPixel
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
mask
GLenum GLint GLuint mask
Definition: SDL_opengl_glext.h:657
SDL_Surface
A collection of pixels used in software blitting.
Definition: SDL_surface.h:70
RLEALPHACLIPBLIT
#define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend)
SDL_COPY_RLE_COLORKEY
#define SDL_COPY_RLE_COLORKEY
Definition: SDL_blit.h:42
SDL_RLEACCEL
#define SDL_RLEACCEL
Definition: SDL_surface.h:54
PIXEL_FROM_RGBA
#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
Definition: SDL_blit.h:395
NULL
#define NULL
Definition: begin_code.h:167
surface
EGLSurface surface
Definition: eglext.h:248
getpix_24
static Uint32 getpix_24(Uint8 *srcbuf)
Definition: SDL_RLEaccel.c:1252
SDL_PixelFormat::format
Uint32 format
Definition: SDL_pixels.h:317
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1109
uncopy_32
static int uncopy_32(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:1003
SDL_Surface::pixels
void * pixels
Definition: SDL_surface.h:76
g
GLboolean GLboolean g
Definition: SDL_opengl_glext.h:1109
CHOOSE_BLIT
#define CHOOSE_BLIT(blitter, alpha, fmt)
Definition: SDL_RLEaccel.c:303
SDL_Surface::w
int w
Definition: SDL_surface.h:74
SDL_UnRLESurface
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
Definition: SDL_RLEaccel.c:1545
copy_transl_565
static int copy_transl_565(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:929
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
SDL_realloc
#define SDL_realloc
Definition: SDL_dynapi_overrides.h:376
getpix_func
Uint32(* getpix_func)(Uint8 *)
Definition: SDL_RLEaccel.c:1267
Type
Type
Definition: SDL_windowsjoystick_c.h:46
SDL_MUSTLOCK
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:62
RLEDestFormat::BytesPerPixel
Uint8 BytesPerPixel
Definition: SDL_RLEaccel.c:617
SDL_COPY_COLORKEY
#define SDL_COPY_COLORKEY
Definition: SDL_blit.h:39
SDL_BlitMap::info
SDL_BlitInfo info
Definition: SDL_blit.h:92
SDL_PixelFormat::Rmask
Uint32 Rmask
Definition: SDL_pixels.h:322
ADD_OPAQUE_COUNTS
#define ADD_OPAQUE_COUNTS(n, m)
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1109
getpix_16
static Uint32 getpix_16(Uint8 *srcbuf)
Definition: SDL_RLEaccel.c:1246
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
length
GLuint GLsizei GLsizei * length
Definition: SDL_opengl_glext.h:669
SDL_Rect::x
int x
Definition: SDL_rect.h:79
RGBA_FROM_8888
#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)
Definition: SDL_blit.h:311
SDL_Rect::w
int w
Definition: SDL_rect.h:80
n
GLdouble n
Definition: SDL_opengl_glext.h:1952
s1
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
Definition: SDL_opengl_glext.h:8583
SDL_PREALLOC
#define SDL_PREALLOC
Definition: SDL_surface.h:53
RLEPIXEL_FROM_RGBA
#define RLEPIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
Definition: SDL_RLEaccel.c:377
alpha
GLfloat GLfloat GLfloat alpha
Definition: SDL_opengl_glext.h:412
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1737
SDL_Surface::pitch
int pitch
Definition: SDL_surface.h:75
len
GLenum GLsizei len
Definition: SDL_opengl_glext.h:2926
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
done
int done
Definition: checkkeys.c:28
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_Rect::y
int y
Definition: SDL_rect.h:79
copy_32
static int copy_32(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:986
SDL_Rect::h
int h
Definition: SDL_rect.h:80
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_RLEBlit
int SDL_RLEBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
Definition: SDL_RLEaccel.c:449
SDL_COPY_BLEND
#define SDL_COPY_BLEND
Definition: SDL_blit.h:36
RLEAlphaClipBlit
static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect)
Definition: SDL_RLEaccel.c:635
RLESKIP
#define RLESKIP(bpp, Type)
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
getpixes
static const getpix_func getpixes[4]
Definition: SDL_RLEaccel.c:1269
ADD_COUNTS
#define ADD_COUNTS(n, m)
RLECLIPBLIT
#define RLECLIPBLIT(bpp, Type, do_blit)
SDL_PixelFormat::Amask
Uint32 Amask
Definition: SDL_pixels.h:325
SDL_Surface::map
struct SDL_BlitMap * map
Definition: SDL_surface.h:89
SDL_PixelFormat
Definition: SDL_pixels.h:315
SDL_BlitInfo::a
Uint8 a
Definition: SDL_blit.h:70
SDL_PixelFormat::Gmask
Uint32 Gmask
Definition: SDL_pixels.h:323
BLIT_TRANSL_888
#define BLIT_TRANSL_888(src, dst)
Definition: SDL_RLEaccel.c:571
SDL_COPY_MODULATE_ALPHA
#define SDL_COPY_MODULATE_ALPHA
Definition: SDL_blit.h:35
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
RLEClipBlit
static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha)
Definition: SDL_RLEaccel.c:390
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_COPY_RLE_ALPHAKEY
#define SDL_COPY_RLE_ALPHAKEY
Definition: SDL_blit.h:43
SDL_PixelFormat::Bloss
Uint8 Bloss
Definition: SDL_pixels.h:328
SDL_BlitMap::data
void * data
Definition: SDL_blit.h:91
SDL_LockSurface
#define SDL_LockSurface
Definition: SDL_dynapi_overrides.h:448
SDL_PixelFormat::Bmask
Uint32 Bmask
Definition: SDL_pixels.h:324
ISTRANSL
#define ISTRANSL(pixel, fmt)
Definition: SDL_RLEaccel.c:1021
uncopy_opaque_16
static int uncopy_opaque_16(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:909
copy_opaque_16
static int copy_opaque_16(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:892
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
src
GLenum src
Definition: SDL_opengl_glext.h:1737
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
PIXEL_FROM_RGB
#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)
Definition: SDL_blit.h:218
SDL_PixelFormat::Bshift
Uint8 Bshift
Definition: SDL_pixels.h:332
s
GLdouble s
Definition: SDL_opengl.h:2063
SDL_PixelFormat::Aloss
Uint8 Aloss
Definition: SDL_pixels.h:329
SDL_COPY_NEAREST
#define SDL_COPY_NEAREST
Definition: SDL_blit.h:40
SDL_Rect
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77
SDL_RLEAlphaBlit
int SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
Definition: SDL_RLEaccel.c:727
UnRLEAlpha
static SDL_bool UnRLEAlpha(SDL_Surface *surface)
Definition: SDL_RLEaccel.c:1469
SDL_PixelFormat::Rloss
Uint8 Rloss
Definition: SDL_pixels.h:326
SDL_SIMDAlloc
#define SDL_SIMDAlloc
Definition: SDL_dynapi_overrides.h:718
ISOPAQUE
#define ISOPAQUE(pixel, fmt)
Definition: SDL_RLEaccel.c:1019
BLIT_TRANSL_565
#define BLIT_TRANSL_565(src, dst)
Definition: SDL_RLEaccel.c:589
SDL_COPY_ADD
#define SDL_COPY_ADD
Definition: SDL_blit.h:37
getpix_8
static Uint32 getpix_8(Uint8 *srcbuf)
Definition: SDL_RLEaccel.c:1240
SDL_COPY_MOD
#define SDL_COPY_MOD
Definition: SDL_blit.h:38
SDL_FillRect
#define SDL_FillRect
Definition: SDL_dynapi_overrides.h:466
RLEColorkeySurface
static int RLEColorkeySurface(SDL_Surface *surface)
Definition: SDL_RLEaccel.c:1274
SDL_PixelFormat::Gloss
Uint8 Gloss
Definition: SDL_pixels.h:327
RLEBLIT
#define RLEBLIT(bpp, Type, do_blit)
copy_transl_555
static int copy_transl_555(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:948
RGB_FROM_PIXEL
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)
Definition: SDL_blit.h:122
ADD_TRANSL_COUNTS
#define ADD_TRANSL_COUNTS(n, m)
SDL_PixelFormat::Gshift
Uint8 Gshift
Definition: SDL_pixels.h:331
SDL_BlitMap::dst
SDL_Surface * dst
Definition: SDL_blit.h:88
SDL_COPY_MODULATE_COLOR
#define SDL_COPY_MODULATE_COLOR
Definition: SDL_blit.h:34
RLEALPHABLIT
#define RLEALPHABLIT(Ptype, Ctype, do_blend)
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_Surface::format
SDL_PixelFormat * format
Definition: SDL_surface.h:73
i
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)
Definition: SDL_x11sym.h:50
SDL_SIMD_ALIGNED
#define SDL_SIMD_ALIGNED
Definition: SDL_surface.h:56
RLEAlphaSurface
static int RLEAlphaSurface(SDL_Surface *surface)
Definition: SDL_RLEaccel.c:1026
getpix_32
static Uint32 getpix_32(Uint8 *srcbuf)
Definition: SDL_RLEaccel.c:1262
d
const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char const char const SDL_SCANF_FORMAT_STRING 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
Definition: SDL_dynapi_procs.h:117
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
SDL_SIMDFree
#define SDL_SIMDFree
Definition: SDL_dynapi_overrides.h:719
uintptr_t
unsigned int uintptr_t
Definition: SDL_config_windows.h:70
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179