SDL_RLEaccel_c.h File Reference
`#include "../SDL_internal.h"`
Include dependency graph for SDL_RLEaccel_c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions

int | SDL_RLESurface (SDL_Surface *surface)
int | SDL_RLEBlit (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
int | SDL_RLEAlphaBlit (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
void | SDL_UnRLESurface (SDL_Surface *surface, int recode)

## Function Documentation

## SDL_RLEAlphaBlit()

int SDL_RLEAlphaBlit | ( | SDL_Surface * | src,
|  | SDL_Rect * | srcrect,
|  | SDL_Surface * | 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().

{
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;
}
SDL_UnlockSurface
#define SDL_UnlockSurface
Definition: SDL_dynapi_overrides.h:449
BLIT_TRANSL_555
#define BLIT_TRANSL_555(src, dst)
Definition: SDL_RLEaccel.c:601
SDL_PixelFormat::Gmask
Uint32 Gmask
Definition: SDL_pixels.h:323
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_PixelFormat::BytesPerPixel
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
SDL_PixelFormat::Bmask
Uint32 Bmask
Definition: SDL_pixels.h:324
RLEDestFormat
Definition: SDL_RLEaccel.c:615
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:181
RLEAlphaClipBlit
static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect)
Definition: SDL_RLEaccel.c:635
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:157
done
int done
Definition: checkkeys.c:28
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
uintptr_t
unsigned int uintptr_t
Definition: SDL_config_windows.h:70
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_LockSurface
#define SDL_LockSurface
Definition: SDL_dynapi_overrides.h:448
RLEALPHABLIT
#define RLEALPHABLIT(Ptype, Ctype, do_blend)
SDL_PixelFormat::Rmask
Uint32 Rmask
Definition: SDL_pixels.h:322
SDL_MUSTLOCK
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
BLIT_TRANSL_565
#define BLIT_TRANSL_565(src, dst)
Definition: SDL_RLEaccel.c:589
BLIT_TRANSL_888
#define BLIT_TRANSL_888(src, dst)
Definition: SDL_RLEaccel.c:571
SDL_PixelFormat
Definition: SDL_pixels.h:315
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:169
SDL_PixelFormat::format
Uint32 format
Definition: SDL_pixels.h:317
SDL_Rect::y
int y
Definition: SDL_rect.h:66

## SDL_RLEBlit()

int SDL_RLEBlit | ( | SDL_Surface * | src,
|  | SDL_Rect * | srcrect,
|  | SDL_Surface * | 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().

{
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);
}
CHOOSE_BLIT
#define CHOOSE_BLIT(blitter, alpha, fmt)
Definition: SDL_RLEaccel.c:303
SDL_UnlockSurface
#define SDL_UnlockSurface
Definition: SDL_dynapi_overrides.h:449
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
alpha
GLfloat GLfloat GLfloat alpha
Definition: SDL_opengl_glext.h:412
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:157
done
int done
Definition: checkkeys.c:28
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
RLESKIP
#define RLESKIP(bpp, Type)
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_Rect::x
int x
Definition: SDL_rect.h:66
RLEClipBlit
static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha)
Definition: SDL_RLEaccel.c:390
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_LockSurface
#define SDL_LockSurface
Definition: SDL_dynapi_overrides.h:448
SDL_MUSTLOCK
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
SDL_PixelFormat
Definition: SDL_pixels.h:315
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:169
SDL_PixelFormat::format
Uint32 format
Definition: SDL_pixels.h:317
SDL_Rect::y
int y
Definition: SDL_rect.h:66
RLEBLIT
#define RLEBLIT(bpp, Type, do_blit)

## 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().

{
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);
}
SDL_COPY_MODULATE_COLOR
#define SDL_COPY_MODULATE_COLOR
Definition: SDL_blit.h:34
SDL_COPY_COLORKEY
#define SDL_COPY_COLORKEY
Definition: SDL_blit.h:39
SDL_BlitMap::blit
SDL_blit blit
Definition: SDL_blit.h:90
SDL_BlitInfo::flags
int flags
Definition: SDL_blit.h:68
SDL_COPY_MOD
#define SDL_COPY_MOD
Definition: SDL_blit.h:38
SDL_UnRLESurface
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
Definition: SDL_RLEaccel.c:1540
SDL_COPY_RLE_COLORKEY
#define SDL_COPY_RLE_COLORKEY
Definition: SDL_blit.h:42
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_ADD
#define SDL_COPY_ADD
Definition: SDL_blit.h:37
SDL_Surface::flags
Uint32 flags
Definition: SDL_surface.h:71
SDL_COPY_NEAREST
#define SDL_COPY_NEAREST
Definition: SDL_blit.h:40
SDL_Surface::map
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
SDL_Surface::pixels
void * pixels
Definition: SDL_surface.h:75
SDL_PixelFormat::BitsPerPixel
Uint8 BitsPerPixel
Definition: SDL_pixels.h:319
SDL_RLEAlphaBlit
int SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
Definition: SDL_RLEaccel.c:727
RLEColorkeySurface
static int RLEColorkeySurface(SDL_Surface *surface)
Definition: SDL_RLEaccel.c:1273
SDL_Surface::format
SDL_PixelFormat * format
Definition: SDL_surface.h:72
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_COPY_MODULATE_ALPHA
#define SDL_COPY_MODULATE_ALPHA
Definition: SDL_blit.h:35
SDL_COPY_RLE_ALPHAKEY
#define SDL_COPY_RLE_ALPHAKEY
Definition: SDL_blit.h:43
RLEAlphaSurface
static int RLEAlphaSurface(SDL_Surface *surface)
Definition: SDL_RLEaccel.c:1026
SDL_PixelFormat::Amask
Uint32 Amask
Definition: SDL_pixels.h:325
SDL_BlitMap::identity
int identity
Definition: SDL_blit.h:89
SDL_COPY_BLEND
#define SDL_COPY_BLEND
Definition: SDL_blit.h:36
SDL_BlitMap::info
SDL_BlitInfo info
Definition: SDL_blit.h:92
SDL_RLEACCEL
#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().

{
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_malloc(surface->h * surface->pitch);
if (!surface->pixels) {
/* Oh crap... */
surface->flags |= SDL_RLEACCEL;
return;
}
/* 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;
}
}
SDL_Surface::h
int h
Definition: SDL_surface.h:73
SDL_BlitInfo::flags
int flags
Definition: SDL_blit.h:68
SDL_COPY_RLE_COLORKEY
#define SDL_COPY_RLE_COLORKEY
Definition: SDL_blit.h:42
SDL_Surface::w
int w
Definition: SDL_surface.h:73
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_BlitInfo::colorkey
Uint32 colorkey
Definition: SDL_blit.h:69
SDL_Surface::flags
Uint32 flags
Definition: SDL_surface.h:71
SDL_Surface::map
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
SDL_Surface::pixels
void * pixels
Definition: SDL_surface.h:75
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
NULL
#define NULL
Definition: begin_code.h:164
UnRLEAlpha
static SDL_bool UnRLEAlpha(SDL_Surface *surface)
Definition: SDL_RLEaccel.c:1467
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_COPY_RLE_ALPHAKEY
#define SDL_COPY_RLE_ALPHAKEY
Definition: SDL_blit.h:43
SDL_FillRect
#define SDL_FillRect
Definition: SDL_dynapi_overrides.h:466
SDL_Surface::pitch
int pitch
Definition: SDL_surface.h:74
SDL_BlitMap::data
void * data
Definition: SDL_blit.h:91
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_BlitMap::info
SDL_BlitInfo info
Definition: SDL_blit.h:92
SDL_PREALLOC
#define SDL_PREALLOC
Definition: SDL_surface.h:53
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
SDL_RLEACCEL
#define SDL_RLEACCEL
Definition: SDL_surface.h:54