SDL  2.0
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

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)
else
break;
case 4:
break;
}
}
/* Unlock the destination if necessary */
if (SDL_MUSTLOCK(surf_dst)) {
SDL_UnlockSurface(surf_dst);
}
return 0;
}
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:
break;
case 2:
break;
case 3:
break;
case 4:
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
}
/* Unlock the destination if necessary */
if (SDL_MUSTLOCK(surf_dst)) {
SDL_UnlockSurface(surf_dst);
}
return (0);
}
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;
} else {
if (RLEAlphaSurface(surface) < 0) {
return -1;
}
surface->map->blit = SDL_RLEAlphaBlit;
}
/* The surface is now accelerated */
surface->flags |= SDL_RLEACCEL;
return (0);
}
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_free(surface->map->data);
surface->map->data = NULL;
}
}