SDL  2.0
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; \
}
GLenum GLenum dst
const GLfloat * m
uint16_t Uint16
Definition: SDL_stdinc.h:191
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
GLdouble n

Referenced by RLEColorkeySurface().

◆ 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; \
}
GLenum GLenum dst
const GLfloat * m
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLdouble n

Referenced by RLEAlphaSurface().

◆ ADD_TRANSL_COUNTS

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

Referenced by RLEAlphaSurface().

◆ 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)
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLenum src
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
GLenum GLint GLuint mask
unsigned int uintptr_t
uint32_t Uint32
Definition: SDL_stdinc.h:203
GLdouble n
GLuint GLsizei GLsizei * length

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)
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLenum src
GLfloat GLfloat GLfloat alpha
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
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
GLuint GLsizei GLsizei * length

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)
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLenum src
GLfloat GLfloat GLfloat alpha
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
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
GLuint GLsizei GLsizei * length

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)
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
GLenum src
GLfloat GLfloat GLfloat alpha
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
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
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
uint32_t Uint32
Definition: SDL_stdinc.h:203
GLuint GLsizei GLsizei * length

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)
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
GLenum src
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
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
uint32_t Uint32
Definition: SDL_stdinc.h:203
GLuint GLsizei GLsizei * length

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)
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLenum src
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
GLenum GLint GLuint mask

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)
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLenum src
GLfloat GLfloat GLfloat alpha
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

Definition at line 601 of file SDL_RLEaccel.c.

Referenced by RLEAlphaClipBlit(), and SDL_RLEAlphaBlit().

◆ 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)
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLenum src
GLfloat GLfloat GLfloat alpha
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

Definition at line 589 of file SDL_RLEaccel.c.

Referenced by RLEAlphaClipBlit(), and SDL_RLEAlphaBlit().

◆ 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)
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
GLenum src
GLfloat GLfloat GLfloat alpha
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
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1

Definition at line 571 of file SDL_RLEaccel.c.

Referenced by RLEAlphaClipBlit(), and SDL_RLEAlphaBlit().

◆ CHOOSE_BLIT

#define CHOOSE_BLIT (   blitter,
  alpha,
  fmt 
)

Definition at line 303 of file SDL_RLEaccel.c.

Referenced by RLEClipBlit(), and SDL_RLEBlit().

◆ ISOPAQUE

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

Definition at line 1019 of file SDL_RLEaccel.c.

Referenced by RLEAlphaSurface().

◆ ISTRANSL

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

Definition at line 1021 of file SDL_RLEaccel.c.

Referenced by RLEAlphaSurface().

◆ MIN

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

Definition at line 94 of file SDL_RLEaccel.c.

Referenced by RLEAlphaSurface(), and RLEColorkeySurface().

◆ 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 
)

Referenced by SDL_RLEAlphaBlit().

◆ RLEALPHACLIPBLIT

#define RLEALPHACLIPBLIT (   Ptype,
  Ctype,
  do_blend 
)

Referenced by RLEAlphaClipBlit().

◆ 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)
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
GLfloat GLfloat GLfloat alpha
GLubyte GLubyte GLubyte GLubyte w

Referenced by SDL_RLEBlit().

◆ RLECLIPBLIT

#define RLECLIPBLIT (   bpp,
  Type,
  do_blit 
)

Referenced by RLEClipBlit().

◆ 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); \
}
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
GLboolean GLboolean GLboolean b

Definition at line 377 of file SDL_RLEaccel.c.

Referenced by copy_32().

◆ 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; \
} \
}
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
int done
Definition: checkkeys.c:28
GLubyte GLubyte GLubyte GLubyte w

Referenced by SDL_RLEBlit().

Typedef Documentation

◆ getpix_func

typedef Uint32(* getpix_func) (Uint8 *)

Definition at line 1266 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.

References d, i, RGBA_FROM_8888, and RLEPIXEL_FROM_RGBA.

Referenced by RLEAlphaSurface().

988 {
989  int i;
990  Uint32 *d = dst;
991  for (i = 0; i < n; i++) {
992  unsigned r, g, b, a;
993  RGBA_FROM_8888(*src, sfmt, r, g, b, a);
994  RLEPIXEL_FROM_RGBA(*d, dfmt, r, g, b, a);
995  d++;
996  src++;
997  }
998  return n * 4;
999 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLenum GLenum dst
#define RLEPIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
Definition: SDL_RLEaccel.c:377
GLenum src
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
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
uint32_t Uint32
Definition: SDL_stdinc.h:203
GLdouble n
#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)
Definition: SDL_blit.h:311
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
GLboolean GLboolean GLboolean b

◆ 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.

References d, i, PIXEL_FROM_RGB, and RGB_FROM_PIXEL.

Referenced by RLEAlphaSurface().

894 {
895  int i;
896  Uint16 *d = dst;
897  for (i = 0; i < n; i++) {
898  unsigned r, g, b;
899  RGB_FROM_PIXEL(*src, sfmt, r, g, b);
900  PIXEL_FROM_RGB(*d, dfmt, r, g, b);
901  src++;
902  d++;
903  }
904  return n * 2;
905 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLenum src
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)
Definition: SDL_blit.h:122
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
GLdouble n
#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)
Definition: SDL_blit.h:218
GLboolean GLboolean g
GLboolean GLboolean GLboolean b

◆ 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.

References d, i, PIXEL_FROM_RGB, and RGBA_FROM_8888.

Referenced by RLEAlphaSurface().

950 {
951  int i;
952  Uint32 *d = dst;
953  for (i = 0; i < n; i++) {
954  unsigned r, g, b, a;
955  Uint16 pix;
956  RGBA_FROM_8888(*src, sfmt, r, g, b, a);
957  PIXEL_FROM_RGB(pix, dfmt, r, g, b);
958  *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
959  src++;
960  d++;
961  }
962  return n * 4;
963 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLenum src
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
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
uint32_t Uint32
Definition: SDL_stdinc.h:203
GLdouble n
#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)
Definition: SDL_blit.h:311
#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)
Definition: SDL_blit.h:218
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
GLboolean GLboolean GLboolean b

◆ 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.

References d, i, PIXEL_FROM_RGB, and RGBA_FROM_8888.

Referenced by RLEAlphaSurface().

931 {
932  int i;
933  Uint32 *d = dst;
934  for (i = 0; i < n; i++) {
935  unsigned r, g, b, a;
936  Uint16 pix;
937  RGBA_FROM_8888(*src, sfmt, r, g, b, a);
938  PIXEL_FROM_RGB(pix, dfmt, r, g, b);
939  *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
940  src++;
941  d++;
942  }
943  return n * 4;
944 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLenum src
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
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
uint32_t Uint32
Definition: SDL_stdinc.h:203
GLdouble n
#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)
Definition: SDL_blit.h:311
#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)
Definition: SDL_blit.h:218
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
GLboolean GLboolean GLboolean b

◆ getpix_16()

static Uint32 getpix_16 ( Uint8 srcbuf)
static

Definition at line 1245 of file SDL_RLEaccel.c.

1246 {
1247  return *(Uint16 *) srcbuf;
1248 }
uint16_t Uint16
Definition: SDL_stdinc.h:191

◆ getpix_24()

static Uint32 getpix_24 ( Uint8 srcbuf)
static

Definition at line 1251 of file SDL_RLEaccel.c.

1252 {
1253 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1254  return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16);
1255 #else
1256  return (srcbuf[0] << 16) + (srcbuf[1] << 8) + srcbuf[2];
1257 #endif
1258 }

◆ getpix_32()

static Uint32 getpix_32 ( Uint8 srcbuf)
static

Definition at line 1261 of file SDL_RLEaccel.c.

1262 {
1263  return *(Uint32 *) srcbuf;
1264 }
uint32_t Uint32
Definition: SDL_stdinc.h:203

◆ getpix_8()

static Uint32 getpix_8 ( Uint8 srcbuf)
static

Definition at line 1239 of file SDL_RLEaccel.c.

1240 {
1241  return *srcbuf;
1242 }

◆ 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.

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

Referenced by SDL_RLEAlphaBlit().

637 {
638  SDL_PixelFormat *df = surf_dst->format;
639  /*
640  * clipped blitter: Ptype is the destination pixel type,
641  * Ctype the translucent count type, and do_blend the macro
642  * to blend one pixel.
643  */
644 #define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend) \
645  do { \
646  int linecount = srcrect->h; \
647  int left = srcrect->x; \
648  int right = left + srcrect->w; \
649  dstbuf -= left * sizeof(Ptype); \
650  do { \
651  int ofs = 0; \
652  /* blit opaque pixels on one line */ \
653  do { \
654  unsigned run; \
655  ofs += ((Ctype *)srcbuf)[0]; \
656  run = ((Ctype *)srcbuf)[1]; \
657  srcbuf += 2 * sizeof(Ctype); \
658  if(run) { \
659  /* clip to left and right borders */ \
660  int cofs = ofs; \
661  int crun = run; \
662  if(left - cofs > 0) { \
663  crun -= left - cofs; \
664  cofs = left; \
665  } \
666  if(crun > right - cofs) \
667  crun = right - cofs; \
668  if(crun > 0) \
669  PIXEL_COPY(dstbuf + cofs * sizeof(Ptype), \
670  srcbuf + (cofs - ofs) * sizeof(Ptype), \
671  (unsigned)crun, sizeof(Ptype)); \
672  srcbuf += run * sizeof(Ptype); \
673  ofs += run; \
674  } else if(!ofs) \
675  return; \
676  } while(ofs < w); \
677  /* skip padding if necessary */ \
678  if(sizeof(Ptype) == 2) \
679  srcbuf += (uintptr_t)srcbuf & 2; \
680  /* blit translucent pixels on the same line */ \
681  ofs = 0; \
682  do { \
683  unsigned run; \
684  ofs += ((Uint16 *)srcbuf)[0]; \
685  run = ((Uint16 *)srcbuf)[1]; \
686  srcbuf += 4; \
687  if(run) { \
688  /* clip to left and right borders */ \
689  int cofs = ofs; \
690  int crun = run; \
691  if(left - cofs > 0) { \
692  crun -= left - cofs; \
693  cofs = left; \
694  } \
695  if(crun > right - cofs) \
696  crun = right - cofs; \
697  if(crun > 0) { \
698  Ptype *dst = (Ptype *)dstbuf + cofs; \
699  Uint32 *src = (Uint32 *)srcbuf + (cofs - ofs); \
700  int i; \
701  for(i = 0; i < crun; i++) \
702  do_blend(src[i], dst[i]); \
703  } \
704  srcbuf += run * 4; \
705  ofs += run; \
706  } \
707  } while(ofs < w); \
708  dstbuf += surf_dst->pitch; \
709  } while(--linecount); \
710  } while(0)
711 
712  switch (df->BytesPerPixel) {
713  case 2:
714  if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
716  else
718  break;
719  case 4:
721  break;
722  }
723 }
#define BLIT_TRANSL_555(src, dst)
Definition: SDL_RLEaccel.c:601
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
uint16_t Uint16
Definition: SDL_stdinc.h:191
#define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend)
uint8_t Uint8
Definition: SDL_stdinc.h:179
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define BLIT_TRANSL_565(src, dst)
Definition: SDL_RLEaccel.c:589
uint32_t Uint32
Definition: SDL_stdinc.h:203
#define BLIT_TRANSL_888(src, dst)
Definition: SDL_RLEaccel.c:571

◆ RLEAlphaSurface()

static int RLEAlphaSurface ( SDL_Surface surface)
static

Definition at line 1026 of file SDL_RLEaccel.c.

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

Referenced by SDL_RLESurface().

1027 {
1028  SDL_Surface *dest;
1029  SDL_PixelFormat *df;
1030  int maxsize = 0;
1031  int max_opaque_run;
1032  int max_transl_run = 65535;
1033  unsigned masksum;
1034  Uint8 *rlebuf, *dst;
1035  int (*copy_opaque) (void *, Uint32 *, int,
1036  SDL_PixelFormat *, SDL_PixelFormat *);
1037  int (*copy_transl) (void *, Uint32 *, int,
1038  SDL_PixelFormat *, SDL_PixelFormat *);
1039 
1040  dest = surface->map->dst;
1041  if (!dest)
1042  return -1;
1043  df = dest->format;
1044  if (surface->format->BitsPerPixel != 32)
1045  return -1; /* only 32bpp source supported */
1046 
1047  /* find out whether the destination is one we support,
1048  and determine the max size of the encoded result */
1049  masksum = df->Rmask | df->Gmask | df->Bmask;
1050  switch (df->BytesPerPixel) {
1051  case 2:
1052  /* 16bpp: only support 565 and 555 formats */
1053  switch (masksum) {
1054  case 0xffff:
1055  if (df->Gmask == 0x07e0
1056  || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
1057  copy_opaque = copy_opaque_16;
1058  copy_transl = copy_transl_565;
1059  } else
1060  return -1;
1061  break;
1062  case 0x7fff:
1063  if (df->Gmask == 0x03e0
1064  || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) {
1065  copy_opaque = copy_opaque_16;
1066  copy_transl = copy_transl_555;
1067  } else
1068  return -1;
1069  break;
1070  default:
1071  return -1;
1072  }
1073  max_opaque_run = 255; /* runs stored as bytes */
1074 
1075  /* worst case is alternating opaque and translucent pixels,
1076  with room for alignment padding between lines */
1077  maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2;
1078  break;
1079  case 4:
1080  if (masksum != 0x00ffffff)
1081  return -1; /* requires unused high byte */
1082  copy_opaque = copy_32;
1083  copy_transl = copy_32;
1084  max_opaque_run = 255; /* runs stored as short ints */
1085 
1086  /* worst case is alternating opaque and translucent pixels */
1087  maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4;
1088  break;
1089  default:
1090  return -1; /* anything else unsupported right now */
1091  }
1092 
1093  maxsize += sizeof(RLEDestFormat);
1094  rlebuf = (Uint8 *) SDL_malloc(maxsize);
1095  if (!rlebuf) {
1096  return SDL_OutOfMemory();
1097  }
1098  {
1099  /* save the destination format so we can undo the encoding later */
1100  RLEDestFormat *r = (RLEDestFormat *) rlebuf;
1101  r->BytesPerPixel = df->BytesPerPixel;
1102  r->Rmask = df->Rmask;
1103  r->Gmask = df->Gmask;
1104  r->Bmask = df->Bmask;
1105  r->Amask = df->Amask;
1106  r->Rloss = df->Rloss;
1107  r->Gloss = df->Gloss;
1108  r->Bloss = df->Bloss;
1109  r->Aloss = df->Aloss;
1110  r->Rshift = df->Rshift;
1111  r->Gshift = df->Gshift;
1112  r->Bshift = df->Bshift;
1113  r->Ashift = df->Ashift;
1114  }
1115  dst = rlebuf + sizeof(RLEDestFormat);
1116 
1117  /* Do the actual encoding */
1118  {
1119  int x, y;
1120  int h = surface->h, w = surface->w;
1121  SDL_PixelFormat *sf = surface->format;
1122  Uint32 *src = (Uint32 *) surface->pixels;
1123  Uint8 *lastline = dst; /* end of last non-blank line */
1124 
1125  /* opaque counts are 8 or 16 bits, depending on target depth */
1126 #define ADD_OPAQUE_COUNTS(n, m) \
1127  if(df->BytesPerPixel == 4) { \
1128  ((Uint16 *)dst)[0] = n; \
1129  ((Uint16 *)dst)[1] = m; \
1130  dst += 4; \
1131  } else { \
1132  dst[0] = n; \
1133  dst[1] = m; \
1134  dst += 2; \
1135  }
1136 
1137  /* translucent counts are always 16 bit */
1138 #define ADD_TRANSL_COUNTS(n, m) \
1139  (((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4)
1140 
1141  for (y = 0; y < h; y++) {
1142  int runstart, skipstart;
1143  int blankline = 0;
1144  /* First encode all opaque pixels of a scan line */
1145  x = 0;
1146  do {
1147  int run, skip, len;
1148  skipstart = x;
1149  while (x < w && !ISOPAQUE(src[x], sf))
1150  x++;
1151  runstart = x;
1152  while (x < w && ISOPAQUE(src[x], sf))
1153  x++;
1154  skip = runstart - skipstart;
1155  if (skip == w)
1156  blankline = 1;
1157  run = x - runstart;
1158  while (skip > max_opaque_run) {
1159  ADD_OPAQUE_COUNTS(max_opaque_run, 0);
1160  skip -= max_opaque_run;
1161  }
1162  len = MIN(run, max_opaque_run);
1163  ADD_OPAQUE_COUNTS(skip, len);
1164  dst += copy_opaque(dst, src + runstart, len, sf, df);
1165  runstart += len;
1166  run -= len;
1167  while (run) {
1168  len = MIN(run, max_opaque_run);
1169  ADD_OPAQUE_COUNTS(0, len);
1170  dst += copy_opaque(dst, src + runstart, len, sf, df);
1171  runstart += len;
1172  run -= len;
1173  }
1174  } while (x < w);
1175 
1176  /* Make sure the next output address is 32-bit aligned */
1177  dst += (uintptr_t) dst & 2;
1178 
1179  /* Next, encode all translucent pixels of the same scan line */
1180  x = 0;
1181  do {
1182  int run, skip, len;
1183  skipstart = x;
1184  while (x < w && !ISTRANSL(src[x], sf))
1185  x++;
1186  runstart = x;
1187  while (x < w && ISTRANSL(src[x], sf))
1188  x++;
1189  skip = runstart - skipstart;
1190  blankline &= (skip == w);
1191  run = x - runstart;
1192  while (skip > max_transl_run) {
1193  ADD_TRANSL_COUNTS(max_transl_run, 0);
1194  skip -= max_transl_run;
1195  }
1196  len = MIN(run, max_transl_run);
1197  ADD_TRANSL_COUNTS(skip, len);
1198  dst += copy_transl(dst, src + runstart, len, sf, df);
1199  runstart += len;
1200  run -= len;
1201  while (run) {
1202  len = MIN(run, max_transl_run);
1203  ADD_TRANSL_COUNTS(0, len);
1204  dst += copy_transl(dst, src + runstart, len, sf, df);
1205  runstart += len;
1206  run -= len;
1207  }
1208  if (!blankline)
1209  lastline = dst;
1210  } while (x < w);
1211 
1212  src += surface->pitch >> 2;
1213  }
1214  dst = lastline; /* back up past trailing blank lines */
1215  ADD_OPAQUE_COUNTS(0, 0);
1216  }
1217 
1218 #undef ADD_OPAQUE_COUNTS
1219 #undef ADD_TRANSL_COUNTS
1220 
1221  /* Now that we have it encoded, release the original pixels */
1222  if (!(surface->flags & SDL_PREALLOC)) {
1223  SDL_free(surface->pixels);
1224  surface->pixels = NULL;
1225  }
1226 
1227  /* realloc the buffer to release unused memory */
1228  {
1229  Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
1230  if (!p)
1231  p = rlebuf;
1232  surface->map->data = p;
1233  }
1234 
1235  return 0;
1236 }
static int copy_transl_555(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:948
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
static int copy_transl_565(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:929
GLenum GLenum dst
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
GLfloat GLfloat GLfloat GLfloat h
GLfloat GLfloat p
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
const GLfloat * m
uint16_t Uint16
Definition: SDL_stdinc.h:191
#define SDL_realloc
GLenum src
GLenum GLsizei len
#define ADD_OPAQUE_COUNTS(n, m)
Uint32 flags
Definition: SDL_surface.h:71
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
Definition: SDL_stdinc.h:179
#define SDL_free
Uint8 BitsPerPixel
Definition: SDL_pixels.h:319
static int copy_32(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:986
GLubyte GLubyte GLubyte GLubyte w
Uint8 BytesPerPixel
Definition: SDL_RLEaccel.c:617
unsigned int uintptr_t
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_Surface * dst
Definition: SDL_blit.h:88
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define ADD_TRANSL_COUNTS(n, m)
static int copy_opaque_16(void *dst, Uint32 *src, int n, SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:892
uint32_t Uint32
Definition: SDL_stdinc.h:203
GLdouble n
void * data
Definition: SDL_blit.h:91
#define SDL_malloc
#define ISTRANSL(pixel, fmt)
#define MIN(a, b)
Definition: SDL_RLEaccel.c:94
#define ISOPAQUE(pixel, fmt)
#define SDL_PREALLOC
Definition: SDL_surface.h:53

◆ 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.

References CHOOSE_BLIT, SDL_Surface::format, RLECLIPBLIT, and SDLCALL.

Referenced by SDL_RLEBlit().

392 {
393  SDL_PixelFormat *fmt = surf_dst->format;
394 
395 #define RLECLIPBLIT(bpp, Type, do_blit) \
396  do { \
397  int linecount = srcrect->h; \
398  int ofs = 0; \
399  int left = srcrect->x; \
400  int right = left + srcrect->w; \
401  dstbuf -= left * bpp; \
402  for (;;) { \
403  int run; \
404  ofs += *(Type *)srcbuf; \
405  run = ((Type *)srcbuf)[1]; \
406  srcbuf += 2 * sizeof(Type); \
407  if (run) { \
408  /* clip to left and right borders */ \
409  if (ofs < right) { \
410  int start = 0; \
411  int len = run; \
412  int startcol; \
413  if (left - ofs > 0) { \
414  start = left - ofs; \
415  len -= start; \
416  if (len <= 0) \
417  goto nocopy ## bpp ## do_blit; \
418  } \
419  startcol = ofs + start; \
420  if (len > right - startcol) \
421  len = right - startcol; \
422  do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \
423  len, bpp, alpha); \
424  } \
425  nocopy ## bpp ## do_blit: \
426  srcbuf += run * bpp; \
427  ofs += run; \
428  } else if (!ofs) \
429  break; \
430  \
431  if (ofs == w) { \
432  ofs = 0; \
433  dstbuf += surf_dst->pitch; \
434  if (!--linecount) \
435  break; \
436  } \
437  } \
438  } while(0)
439 
441 
442 #undef RLECLIPBLIT
443 
444 }
#define CHOOSE_BLIT(blitter, alpha, fmt)
Definition: SDL_RLEaccel.c:303
GLfloat GLfloat GLfloat alpha
#define RLECLIPBLIT(bpp, Type, do_blit)
SDL_PixelFormat * format
Definition: SDL_surface.h:72

◆ RLEColorkeySurface()

static int RLEColorkeySurface ( SDL_Surface surface)
static

Definition at line 1273 of file SDL_RLEaccel.c.

References ADD_COUNTS, SDL_PixelFormat::Amask, bpp, SDL_PixelFormat::BytesPerPixel, SDL_BlitInfo::colorkey, SDL_BlitMap::data, SDL_Surface::flags, SDL_Surface::format, getpixes, SDL_Surface::h, SDL_BlitMap::info, SDL_Surface::map, MIN, NULL, SDL_Surface::pitch, SDL_Surface::pixels, SDL_free, SDL_malloc, SDL_memcpy, SDL_OutOfMemory, SDL_PREALLOC, SDL_realloc, and SDL_Surface::w.

Referenced by SDL_RLESurface().

1274 {
1275  Uint8 *rlebuf, *dst;
1276  int maxn;
1277  int y;
1278  Uint8 *srcbuf, *lastline;
1279  int maxsize = 0;
1280  const int bpp = surface->format->BytesPerPixel;
1281  getpix_func getpix;
1282  Uint32 ckey, rgbmask;
1283  int w, h;
1284 
1285  /* calculate the worst case size for the compressed surface */
1286  switch (bpp) {
1287  case 1:
1288  /* worst case is alternating opaque and transparent pixels,
1289  starting with an opaque pixel */
1290  maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2;
1291  break;
1292  case 2:
1293  case 3:
1294  /* worst case is solid runs, at most 255 pixels wide */
1295  maxsize = surface->h * (2 * (surface->w / 255 + 1)
1296  + surface->w * bpp) + 2;
1297  break;
1298  case 4:
1299  /* worst case is solid runs, at most 65535 pixels wide */
1300  maxsize = surface->h * (4 * (surface->w / 65535 + 1)
1301  + surface->w * 4) + 4;
1302  break;
1303 
1304  default:
1305  return -1;
1306  }
1307 
1308  rlebuf = (Uint8 *) SDL_malloc(maxsize);
1309  if (rlebuf == NULL) {
1310  return SDL_OutOfMemory();
1311  }
1312 
1313  /* Set up the conversion */
1314  srcbuf = (Uint8 *) surface->pixels;
1315  maxn = bpp == 4 ? 65535 : 255;
1316  dst = rlebuf;
1317  rgbmask = ~surface->format->Amask;
1318  ckey = surface->map->info.colorkey & rgbmask;
1319  lastline = dst;
1320  getpix = getpixes[bpp - 1];
1321  w = surface->w;
1322  h = surface->h;
1323 
1324 #define ADD_COUNTS(n, m) \
1325  if(bpp == 4) { \
1326  ((Uint16 *)dst)[0] = n; \
1327  ((Uint16 *)dst)[1] = m; \
1328  dst += 4; \
1329  } else { \
1330  dst[0] = n; \
1331  dst[1] = m; \
1332  dst += 2; \
1333  }
1334 
1335  for (y = 0; y < h; y++) {
1336  int x = 0;
1337  int blankline = 0;
1338  do {
1339  int run, skip, len;
1340  int runstart;
1341  int skipstart = x;
1342 
1343  /* find run of transparent, then opaque pixels */
1344  while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
1345  x++;
1346  runstart = x;
1347  while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
1348  x++;
1349  skip = runstart - skipstart;
1350  if (skip == w)
1351  blankline = 1;
1352  run = x - runstart;
1353 
1354  /* encode segment */
1355  while (skip > maxn) {
1356  ADD_COUNTS(maxn, 0);
1357  skip -= maxn;
1358  }
1359  len = MIN(run, maxn);
1360  ADD_COUNTS(skip, len);
1361  SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
1362  dst += len * bpp;
1363  run -= len;
1364  runstart += len;
1365  while (run) {
1366  len = MIN(run, maxn);
1367  ADD_COUNTS(0, len);
1368  SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
1369  dst += len * bpp;
1370  runstart += len;
1371  run -= len;
1372  }
1373  if (!blankline)
1374  lastline = dst;
1375  } while (x < w);
1376 
1377  srcbuf += surface->pitch;
1378  }
1379  dst = lastline; /* back up bast trailing blank lines */
1380  ADD_COUNTS(0, 0);
1381 
1382 #undef ADD_COUNTS
1383 
1384  /* Now that we have it encoded, release the original pixels */
1385  if (!(surface->flags & SDL_PREALLOC)) {
1386  SDL_free(surface->pixels);
1387  surface->pixels = NULL;
1388  }
1389 
1390  /* realloc the buffer to release unused memory */
1391  {
1392  /* If realloc returns NULL, the original block is left intact */
1393  Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
1394  if (!p)
1395  p = rlebuf;
1396  surface->map->data = p;
1397  }
1398 
1399  return 0;
1400 }
GLenum GLenum dst
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
GLfloat GLfloat GLfloat GLfloat h
Uint32(* getpix_func)(Uint8 *)
GLfloat GLfloat p
const GLfloat * m
uint16_t Uint16
Definition: SDL_stdinc.h:191
#define SDL_realloc
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
GLenum GLsizei len
Uint32 colorkey
Definition: SDL_blit.h:69
Uint32 flags
Definition: SDL_surface.h:71
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
#define SDL_memcpy
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
Definition: SDL_stdinc.h:179
#define SDL_free
#define ADD_COUNTS(n, m)
GLubyte GLubyte GLubyte GLubyte w
static const getpix_func getpixes[4]
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_PixelFormat * format
Definition: SDL_surface.h:72
uint32_t Uint32
Definition: SDL_stdinc.h:203
GLdouble n
void * data
Definition: SDL_blit.h:91
#define SDL_malloc
#define MIN(a, b)
Definition: SDL_RLEaccel.c:94
SDL_BlitInfo info
Definition: SDL_blit.h:92
#define SDL_PREALLOC
Definition: SDL_surface.h:53

◆ 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.

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_Rect::w, SDL_Surface::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_RLESurface().

729 {
730  int x, y;
731  int w = surf_src->w;
732  Uint8 *srcbuf, *dstbuf;
733  SDL_PixelFormat *df = surf_dst->format;
734 
735  /* Lock the destination if necessary */
736  if (SDL_MUSTLOCK(surf_dst)) {
737  if (SDL_LockSurface(surf_dst) < 0) {
738  return -1;
739  }
740  }
741 
742  x = dstrect->x;
743  y = dstrect->y;
744  dstbuf = (Uint8 *) surf_dst->pixels + y * surf_dst->pitch + x * df->BytesPerPixel;
745  srcbuf = (Uint8 *) surf_src->map->data + sizeof(RLEDestFormat);
746 
747  {
748  /* skip lines at the top if necessary */
749  int vskip = srcrect->y;
750  if (vskip) {
751  int ofs;
752  if (df->BytesPerPixel == 2) {
753  /* the 16/32 interleaved format */
754  do {
755  /* skip opaque line */
756  ofs = 0;
757  do {
758  int run;
759  ofs += srcbuf[0];
760  run = srcbuf[1];
761  srcbuf += 2;
762  if (run) {
763  srcbuf += 2 * run;
764  ofs += run;
765  } else if (!ofs)
766  goto done;
767  } while (ofs < w);
768 
769  /* skip padding */
770  srcbuf += (uintptr_t) srcbuf & 2;
771 
772  /* skip translucent line */
773  ofs = 0;
774  do {
775  int run;
776  ofs += ((Uint16 *) srcbuf)[0];
777  run = ((Uint16 *) srcbuf)[1];
778  srcbuf += 4 * (run + 1);
779  ofs += run;
780  } while (ofs < w);
781  } while (--vskip);
782  } else {
783  /* the 32/32 interleaved format */
784  vskip <<= 1; /* opaque and translucent have same format */
785  do {
786  ofs = 0;
787  do {
788  int run;
789  ofs += ((Uint16 *) srcbuf)[0];
790  run = ((Uint16 *) srcbuf)[1];
791  srcbuf += 4;
792  if (run) {
793  srcbuf += 4 * run;
794  ofs += run;
795  } else if (!ofs)
796  goto done;
797  } while (ofs < w);
798  } while (--vskip);
799  }
800  }
801  }
802 
803  /* if left or right edge clipping needed, call clip blit */
804  if (srcrect->x || srcrect->w != surf_src->w) {
805  RLEAlphaClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect);
806  } else {
807 
808  /*
809  * non-clipped blitter. Ptype is the destination pixel type,
810  * Ctype the translucent count type, and do_blend the
811  * macro to blend one pixel.
812  */
813 #define RLEALPHABLIT(Ptype, Ctype, do_blend) \
814  do { \
815  int linecount = srcrect->h; \
816  do { \
817  int ofs = 0; \
818  /* blit opaque pixels on one line */ \
819  do { \
820  unsigned run; \
821  ofs += ((Ctype *)srcbuf)[0]; \
822  run = ((Ctype *)srcbuf)[1]; \
823  srcbuf += 2 * sizeof(Ctype); \
824  if(run) { \
825  PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \
826  run, sizeof(Ptype)); \
827  srcbuf += run * sizeof(Ptype); \
828  ofs += run; \
829  } else if(!ofs) \
830  goto done; \
831  } while(ofs < w); \
832  /* skip padding if necessary */ \
833  if(sizeof(Ptype) == 2) \
834  srcbuf += (uintptr_t)srcbuf & 2; \
835  /* blit translucent pixels on the same line */ \
836  ofs = 0; \
837  do { \
838  unsigned run; \
839  ofs += ((Uint16 *)srcbuf)[0]; \
840  run = ((Uint16 *)srcbuf)[1]; \
841  srcbuf += 4; \
842  if(run) { \
843  Ptype *dst = (Ptype *)dstbuf + ofs; \
844  unsigned i; \
845  for(i = 0; i < run; i++) { \
846  Uint32 src = *(Uint32 *)srcbuf; \
847  do_blend(src, *dst); \
848  srcbuf += 4; \
849  dst++; \
850  } \
851  ofs += run; \
852  } \
853  } while(ofs < w); \
854  dstbuf += surf_dst->pitch; \
855  } while(--linecount); \
856  } while(0)
857 
858  switch (df->BytesPerPixel) {
859  case 2:
860  if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0
861  || df->Bmask == 0x07e0)
863  else
865  break;
866  case 4:
868  break;
869  }
870  }
871 
872  done:
873  /* Unlock the destination if necessary */
874  if (SDL_MUSTLOCK(surf_dst)) {
875  SDL_UnlockSurface(surf_dst);
876  }
877  return 0;
878 }
#define SDL_UnlockSurface
#define BLIT_TRANSL_555(src, dst)
Definition: SDL_RLEaccel.c:601
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
uint16_t Uint16
Definition: SDL_stdinc.h:191
static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect)
Definition: SDL_RLEaccel.c:635
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
Definition: SDL_stdinc.h:179
int done
Definition: checkkeys.c:28
GLubyte GLubyte GLubyte GLubyte w
unsigned int uintptr_t
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_LockSurface
#define RLEALPHABLIT(Ptype, Ctype, do_blend)
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
#define BLIT_TRANSL_565(src, dst)
Definition: SDL_RLEaccel.c:589
uint32_t Uint32
Definition: SDL_stdinc.h:203
#define BLIT_TRANSL_888(src, dst)
Definition: SDL_RLEaccel.c:571
void * data
Definition: SDL_blit.h:91
int y
Definition: SDL_rect.h:66

◆ 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.

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_Rect::w, SDL_Surface::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_RLESurface(), and SDL_UnRLESurface().

451 {
452  Uint8 *dstbuf;
453  Uint8 *srcbuf;
454  int x, y;
455  int w = surf_src->w;
456  unsigned alpha;
457 
458  /* Lock the destination if necessary */
459  if (SDL_MUSTLOCK(surf_dst)) {
460  if (SDL_LockSurface(surf_dst) < 0) {
461  return (-1);
462  }
463  }
464 
465  /* Set up the source and destination pointers */
466  x = dstrect->x;
467  y = dstrect->y;
468  dstbuf = (Uint8 *) surf_dst->pixels
469  + y * surf_dst->pitch + x * surf_src->format->BytesPerPixel;
470  srcbuf = (Uint8 *) surf_src->map->data;
471 
472  {
473  /* skip lines at the top if necessary */
474  int vskip = srcrect->y;
475  int ofs = 0;
476  if (vskip) {
477 
478 #define RLESKIP(bpp, Type) \
479  for(;;) { \
480  int run; \
481  ofs += *(Type *)srcbuf; \
482  run = ((Type *)srcbuf)[1]; \
483  srcbuf += sizeof(Type) * 2; \
484  if(run) { \
485  srcbuf += run * bpp; \
486  ofs += run; \
487  } else if(!ofs) \
488  goto done; \
489  if(ofs == w) { \
490  ofs = 0; \
491  if(!--vskip) \
492  break; \
493  } \
494  }
495 
496  switch (surf_src->format->BytesPerPixel) {
497  case 1:
498  RLESKIP(1, Uint8);
499  break;
500  case 2:
501  RLESKIP(2, Uint8);
502  break;
503  case 3:
504  RLESKIP(3, Uint8);
505  break;
506  case 4:
507  RLESKIP(4, Uint16);
508  break;
509  }
510 
511 #undef RLESKIP
512 
513  }
514  }
515 
516  alpha = surf_src->map->info.a;
517  /* if left or right edge clipping needed, call clip blit */
518  if (srcrect->x || srcrect->w != surf_src->w) {
519  RLEClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect, alpha);
520  } else {
521  SDL_PixelFormat *fmt = surf_src->format;
522 
523 #define RLEBLIT(bpp, Type, do_blit) \
524  do { \
525  int linecount = srcrect->h; \
526  int ofs = 0; \
527  for(;;) { \
528  unsigned run; \
529  ofs += *(Type *)srcbuf; \
530  run = ((Type *)srcbuf)[1]; \
531  srcbuf += 2 * sizeof(Type); \
532  if(run) { \
533  do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \
534  srcbuf += run * bpp; \
535  ofs += run; \
536  } else if(!ofs) \
537  break; \
538  if(ofs == w) { \
539  ofs = 0; \
540  dstbuf += surf_dst->pitch; \
541  if(!--linecount) \
542  break; \
543  } \
544  } \
545  } while(0)
546 
547  CHOOSE_BLIT(RLEBLIT, alpha, fmt);
548 
549 #undef RLEBLIT
550  }
551 
552  done:
553  /* Unlock the destination if necessary */
554  if (SDL_MUSTLOCK(surf_dst)) {
555  SDL_UnlockSurface(surf_dst);
556  }
557  return (0);
558 }
#define CHOOSE_BLIT(blitter, alpha, fmt)
Definition: SDL_RLEaccel.c:303
#define SDL_UnlockSurface
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLfloat GLfloat GLfloat alpha
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
Definition: SDL_stdinc.h:179
int done
Definition: checkkeys.c:28
GLubyte GLubyte GLubyte GLubyte w
#define RLESKIP(bpp, Type)
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
int x
Definition: SDL_rect.h:66
static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha)
Definition: SDL_RLEaccel.c:390
int w
Definition: SDL_rect.h:67
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_LockSurface
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
void * data
Definition: SDL_blit.h:91
int y
Definition: SDL_rect.h:66
SDL_BlitInfo info
Definition: SDL_blit.h:92
#define RLEBLIT(bpp, Type, do_blit)
Uint8 a
Definition: SDL_blit.h:70

◆ SDL_RLESurface()

int SDL_RLESurface ( SDL_Surface surface)

Definition at line 1403 of file SDL_RLEaccel.c.

References SDL_PixelFormat::Amask, SDL_PixelFormat::BitsPerPixel, SDL_BlitMap::blit, SDL_BlitInfo::flags, SDL_Surface::flags, SDL_Surface::format, SDL_BlitMap::identity, SDL_BlitMap::info, SDL_Surface::map, SDL_Surface::pixels, 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().

1404 {
1405  int flags;
1406 
1407  /* Clear any previous RLE conversion */
1408  if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
1409  SDL_UnRLESurface(surface, 1);
1410  }
1411 
1412  /* We don't support RLE encoding of bitmaps */
1413  if (surface->format->BitsPerPixel < 8) {
1414  return -1;
1415  }
1416 
1417  /* Make sure the pixels are available */
1418  if (!surface->pixels) {
1419  return -1;
1420  }
1421 
1422  /* If we don't have colorkey or blending, nothing to do... */
1423  flags = surface->map->info.flags;
1424  if (!(flags & (SDL_COPY_COLORKEY | SDL_COPY_BLEND))) {
1425  return -1;
1426  }
1427 
1428  /* Pass on combinations not supported */
1429  if ((flags & SDL_COPY_MODULATE_COLOR) ||
1430  ((flags & SDL_COPY_MODULATE_ALPHA) && surface->format->Amask) ||
1431  (flags & (SDL_COPY_ADD | SDL_COPY_MOD)) ||
1432  (flags & SDL_COPY_NEAREST)) {
1433  return -1;
1434  }
1435 
1436  /* Encode and set up the blit */
1437  if (!surface->format->Amask || !(flags & SDL_COPY_BLEND)) {
1438  if (!surface->map->identity) {
1439  return -1;
1440  }
1441  if (RLEColorkeySurface(surface) < 0) {
1442  return -1;
1443  }
1444  surface->map->blit = SDL_RLEBlit;
1445  surface->map->info.flags |= SDL_COPY_RLE_COLORKEY;
1446  } else {
1447  if (RLEAlphaSurface(surface) < 0) {
1448  return -1;
1449  }
1450  surface->map->blit = SDL_RLEAlphaBlit;
1451  surface->map->info.flags |= SDL_COPY_RLE_ALPHAKEY;
1452  }
1453 
1454  /* The surface is now accelerated */
1455  surface->flags |= SDL_RLEACCEL;
1456 
1457  return (0);
1458 }
#define SDL_COPY_MODULATE_COLOR
Definition: SDL_blit.h:34
#define SDL_COPY_COLORKEY
Definition: SDL_blit.h:39
SDL_blit blit
Definition: SDL_blit.h:90
#define SDL_COPY_MOD
Definition: SDL_blit.h:38
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
#define SDL_COPY_RLE_COLORKEY
Definition: SDL_blit.h:42
int SDL_RLEBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
Definition: SDL_RLEaccel.c:449
#define SDL_COPY_ADD
Definition: SDL_blit.h:37
Uint32 flags
Definition: SDL_surface.h:71
#define SDL_COPY_NEAREST
Definition: SDL_blit.h:40
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
void * pixels
Definition: SDL_surface.h:75
Uint8 BitsPerPixel
Definition: SDL_pixels.h:319
int SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
Definition: SDL_RLEaccel.c:727
static int RLEColorkeySurface(SDL_Surface *surface)
SDL_PixelFormat * format
Definition: SDL_surface.h:72
GLbitfield flags
#define SDL_COPY_MODULATE_ALPHA
Definition: SDL_blit.h:35
#define SDL_COPY_RLE_ALPHAKEY
Definition: SDL_blit.h:43
static int RLEAlphaSurface(SDL_Surface *surface)
int identity
Definition: SDL_blit.h:89
#define SDL_COPY_BLEND
Definition: SDL_blit.h:36
SDL_BlitInfo info
Definition: SDL_blit.h:92
#define SDL_RLEACCEL
Definition: SDL_surface.h:54

◆ SDL_UnRLESurface()

void SDL_UnRLESurface ( SDL_Surface surface,
int  recode 
)

Definition at line 1540 of file SDL_RLEaccel.c.

References SDL_BlitInfo::colorkey, SDL_BlitMap::data, SDL_BlitInfo::flags, SDL_Surface::flags, SDL_Rect::h, SDL_Surface::h, SDL_BlitMap::info, SDL_Surface::map, NULL, SDL_Surface::pitch, SDL_Surface::pixels, SDL_COPY_RLE_ALPHAKEY, SDL_COPY_RLE_COLORKEY, SDL_FillRect, SDL_free, SDL_malloc, SDL_PREALLOC, SDL_RLEACCEL, SDL_RLEBlit(), UnRLEAlpha(), SDL_Rect::w, SDL_Surface::w, SDL_Rect::x, and SDL_Rect::y.

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

1541 {
1542  if (surface->flags & SDL_RLEACCEL) {
1543  surface->flags &= ~SDL_RLEACCEL;
1544 
1545  if (recode && !(surface->flags & SDL_PREALLOC)) {
1546  if (surface->map->info.flags & SDL_COPY_RLE_COLORKEY) {
1547  SDL_Rect full;
1548 
1549  /* re-create the original surface */
1550  surface->pixels = SDL_malloc(surface->h * surface->pitch);
1551  if (!surface->pixels) {
1552  /* Oh crap... */
1553  surface->flags |= SDL_RLEACCEL;
1554  return;
1555  }
1556 
1557  /* fill it with the background color */
1558  SDL_FillRect(surface, NULL, surface->map->info.colorkey);
1559 
1560  /* now render the encoded surface */
1561  full.x = full.y = 0;
1562  full.w = surface->w;
1563  full.h = surface->h;
1564  SDL_RLEBlit(surface, &full, surface, &full);
1565  } else {
1566  if (!UnRLEAlpha(surface)) {
1567  /* Oh crap... */
1568  surface->flags |= SDL_RLEACCEL;
1569  return;
1570  }
1571  }
1572  }
1573  surface->map->info.flags &=
1575 
1576  SDL_free(surface->map->data);
1577  surface->map->data = NULL;
1578  }
1579 }
#define SDL_COPY_RLE_COLORKEY
Definition: SDL_blit.h:42
int SDL_RLEBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
Definition: SDL_RLEaccel.c:449
Uint32 colorkey
Definition: SDL_blit.h:69
Uint32 flags
Definition: SDL_surface.h:71
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
void * pixels
Definition: SDL_surface.h:75
#define SDL_free
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define NULL
Definition: begin_code.h:164
static SDL_bool UnRLEAlpha(SDL_Surface *surface)
int h
Definition: SDL_rect.h:67
#define SDL_COPY_RLE_ALPHAKEY
Definition: SDL_blit.h:43
#define SDL_FillRect
void * data
Definition: SDL_blit.h:91
#define SDL_malloc
int y
Definition: SDL_rect.h:66
SDL_BlitInfo info
Definition: SDL_blit.h:92
#define SDL_PREALLOC
Definition: SDL_surface.h:53
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
#define SDL_RLEACCEL
Definition: SDL_surface.h:54

◆ 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.

References i, PIXEL_FROM_RGBA, and RGB_FROM_PIXEL.

Referenced by UnRLEAlpha().

1005 {
1006  int i;
1007  Uint32 *s = src;
1008  for (i = 0; i < n; i++) {
1009  unsigned r, g, b, a;
1010  Uint32 pixel = *s++;
1011  RGB_FROM_PIXEL(pixel, sfmt, r, g, b);
1012  a = pixel >> 24;
1013  PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
1014  dst++;
1015  }
1016  return n * 4;
1017 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
GLenum src
#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
Definition: SDL_blit.h:395
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)
Definition: SDL_blit.h:122
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
uint32_t Uint32
Definition: SDL_stdinc.h:203
GLdouble n
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
GLboolean GLboolean GLboolean b

◆ 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.

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

Referenced by UnRLEAlpha().

911 {
912  int i;
913  Uint16 *s = src;
914  unsigned alpha = dfmt->Amask ? 255 : 0;
915  for (i = 0; i < n; i++) {
916  unsigned r, g, b;
917  RGB_FROM_PIXEL(*s, sfmt, r, g, b);
918  PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha);
919  s++;
920  dst++;
921  }
922  return n * 2;
923 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLenum src
GLfloat GLfloat GLfloat alpha
#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
Definition: SDL_blit.h:395
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)
Definition: SDL_blit.h:122
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
GLdouble n
GLboolean GLboolean g
GLboolean GLboolean GLboolean b

◆ 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.

References i, PIXEL_FROM_RGBA, and RGB_FROM_PIXEL.

Referenced by UnRLEAlpha().

969 {
970  int i;
971  Uint32 *s = src;
972  for (i = 0; i < n; i++) {
973  unsigned r, g, b, a;
974  Uint32 pix = *s++;
975  a = (pix & 0x3e0) >> 2;
976  pix = (pix & ~0x3e0) | pix >> 16;
977  RGB_FROM_PIXEL(pix, sfmt, r, g, b);
978  PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
979  dst++;
980  }
981  return n * 4;
982 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLenum dst
GLenum src
#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)
Definition: SDL_blit.h:395
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)
Definition: SDL_blit.h:122
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
uint32_t Uint32
Definition: SDL_stdinc.h:203
GLdouble n
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
GLboolean GLboolean GLboolean b

◆ UnRLEAlpha()

static SDL_bool UnRLEAlpha ( SDL_Surface surface)
static

Definition at line 1467 of file SDL_RLEaccel.c.

References bpp, RLEDestFormat::BytesPerPixel, SDL_BlitMap::data, SDL_Surface::format, SDL_Surface::h, SDL_Surface::map, SDL_Surface::pitch, SDL_Surface::pixels, SDL_FALSE, SDL_malloc, SDL_memset, SDL_TRUE, uncopy_32(), uncopy_opaque_16(), uncopy_transl_16(), and SDL_Surface::w.

Referenced by SDL_UnRLESurface().

1468 {
1469  Uint8 *srcbuf;
1470  Uint32 *dst;
1471  SDL_PixelFormat *sf = surface->format;
1472  RLEDestFormat *df = surface->map->data;
1473  int (*uncopy_opaque) (Uint32 *, void *, int,
1475  int (*uncopy_transl) (Uint32 *, void *, int,
1476  RLEDestFormat *, SDL_PixelFormat *);
1477  int w = surface->w;
1478  int bpp = df->BytesPerPixel;
1479 
1480  if (bpp == 2) {
1481  uncopy_opaque = uncopy_opaque_16;
1482  uncopy_transl = uncopy_transl_16;
1483  } else {
1484  uncopy_opaque = uncopy_transl = uncopy_32;
1485  }
1486 
1487  surface->pixels = SDL_malloc(surface->h * surface->pitch);
1488  if (!surface->pixels) {
1489  return (SDL_FALSE);
1490  }
1491  /* fill background with transparent pixels */
1492  SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
1493 
1494  dst = surface->pixels;
1495  srcbuf = (Uint8 *) (df + 1);
1496  for (;;) {
1497  /* copy opaque pixels */
1498  int ofs = 0;
1499  do {
1500  unsigned run;
1501  if (bpp == 2) {
1502  ofs += srcbuf[0];
1503  run = srcbuf[1];
1504  srcbuf += 2;
1505  } else {
1506  ofs += ((Uint16 *) srcbuf)[0];
1507  run = ((Uint16 *) srcbuf)[1];
1508  srcbuf += 4;
1509  }
1510  if (run) {
1511  srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
1512  ofs += run;
1513  } else if (!ofs)
1514  return (SDL_TRUE);
1515  } while (ofs < w);
1516 
1517  /* skip padding if needed */
1518  if (bpp == 2)
1519  srcbuf += (uintptr_t) srcbuf & 2;
1520 
1521  /* copy translucent pixels */
1522  ofs = 0;
1523  do {
1524  unsigned run;
1525  ofs += ((Uint16 *) srcbuf)[0];
1526  run = ((Uint16 *) srcbuf)[1];
1527  srcbuf += 4;
1528  if (run) {
1529  srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
1530  ofs += run;
1531  }
1532  } while (ofs < w);
1533  dst += surface->pitch >> 2;
1534  }
1535  /* Make the compiler happy */
1536  return (SDL_TRUE);
1537 }
static int uncopy_transl_16(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:967
static int uncopy_32(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
GLenum GLenum dst
uint16_t Uint16
Definition: SDL_stdinc.h:191
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
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
Definition: SDL_stdinc.h:179
GLubyte GLubyte GLubyte GLubyte w
Uint8 BytesPerPixel
Definition: SDL_RLEaccel.c:617
unsigned int uintptr_t
SDL_PixelFormat * format
Definition: SDL_surface.h:72
uint32_t Uint32
Definition: SDL_stdinc.h:203
static int uncopy_opaque_16(Uint32 *dst, void *src, int n, RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
Definition: SDL_RLEaccel.c:909
void * data
Definition: SDL_blit.h:91
#define SDL_malloc
#define SDL_memset

Variable Documentation

◆ getpixes

const getpix_func getpixes[4]
static
Initial value:
= {
}
static Uint32 getpix_16(Uint8 *srcbuf)
static Uint32 getpix_32(Uint8 *srcbuf)
static Uint32 getpix_8(Uint8 *srcbuf)
static Uint32 getpix_24(Uint8 *srcbuf)

Definition at line 1268 of file SDL_RLEaccel.c.

Referenced by RLEColorkeySurface().