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)
 
void SDL_UnRLESurface (SDL_Surface *surface, int recode)
 

Function Documentation

◆ SDL_RLESurface()

int SDL_RLESurface ( SDL_Surface surface)

Definition at line 1407 of file SDL_RLEaccel.c.

1408 {
1409  int flags;
1410 
1411  /* Clear any previous RLE conversion */
1412  if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
1414  }
1415 
1416  /* We don't support RLE encoding of bitmaps */
1417  if (surface->format->BitsPerPixel < 8) {
1418  return -1;
1419  }
1420 
1421  /* Make sure the pixels are available */
1422  if (!surface->pixels) {
1423  return -1;
1424  }
1425 
1426  /* If we don't have colorkey or blending, nothing to do... */
1427  flags = surface->map->info.flags;
1428  if (!(flags & (SDL_COPY_COLORKEY | SDL_COPY_BLEND))) {
1429  return -1;
1430  }
1431 
1432  /* Pass on combinations not supported */
1433  if ((flags & SDL_COPY_MODULATE_COLOR) ||
1434  ((flags & SDL_COPY_MODULATE_ALPHA) && surface->format->Amask) ||
1436  (flags & SDL_COPY_NEAREST)) {
1437  return -1;
1438  }
1439 
1440  /* Encode and set up the blit */
1441  if (!surface->format->Amask || !(flags & SDL_COPY_BLEND)) {
1442  if (!surface->map->identity) {
1443  return -1;
1444  }
1445  if (RLEColorkeySurface(surface) < 0) {
1446  return -1;
1447  }
1448  surface->map->blit = SDL_RLEBlit;
1449  surface->map->info.flags |= SDL_COPY_RLE_COLORKEY;
1450  } else {
1451  if (RLEAlphaSurface(surface) < 0) {
1452  return -1;
1453  }
1454  surface->map->blit = SDL_RLEAlphaBlit;
1455  surface->map->info.flags |= SDL_COPY_RLE_ALPHAKEY;
1456  }
1457 
1458  /* The surface is now accelerated */
1459  surface->flags |= SDL_RLEACCEL;
1460 
1461  return (0);
1462 }

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

Referenced by SDL_CalculateBlit(), and SDL_UnlockSurface().

◆ SDL_UnRLESurface()

void SDL_UnRLESurface ( SDL_Surface surface,
int  recode 
)

Definition at line 1547 of file SDL_RLEaccel.c.

1548 {
1549  if (surface->flags & SDL_RLEACCEL) {
1550  surface->flags &= ~SDL_RLEACCEL;
1551 
1552  if (recode && !(surface->flags & SDL_PREALLOC)) {
1553  if (surface->map->info.flags & SDL_COPY_RLE_COLORKEY) {
1554  SDL_Rect full;
1555 
1556  /* re-create the original surface */
1557  surface->pixels = SDL_SIMDAlloc(surface->h * surface->pitch);
1558  if (!surface->pixels) {
1559  /* Oh crap... */
1560  surface->flags |= SDL_RLEACCEL;
1561  return;
1562  }
1563  surface->flags |= SDL_SIMD_ALIGNED;
1564 
1565  /* fill it with the background color */
1566  SDL_FillRect(surface, NULL, surface->map->info.colorkey);
1567 
1568  /* now render the encoded surface */
1569  full.x = full.y = 0;
1570  full.w = surface->w;
1571  full.h = surface->h;
1572  SDL_RLEBlit(surface, &full, surface, &full);
1573  } else {
1574  if (!UnRLEAlpha(surface)) {
1575  /* Oh crap... */
1576  surface->flags |= SDL_RLEACCEL;
1577  return;
1578  }
1579  }
1580  }
1581  surface->map->info.flags &=
1583 
1584  SDL_free(surface->map->data);
1585  surface->map->data = NULL;
1586  }
1587 }

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

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

SDL_COPY_RLE_COLORKEY
#define SDL_COPY_RLE_COLORKEY
Definition: SDL_blit.h:43
SDL_RLEACCEL
#define SDL_RLEACCEL
Definition: SDL_surface.h:54
SDL_RLEBlit
static int SDL_RLEBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
Definition: SDL_RLEaccel.c:451
NULL
#define NULL
Definition: begin_code.h:167
surface
EGLSurface surface
Definition: eglext.h:248
SDL_UnRLESurface
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
Definition: SDL_RLEaccel.c:1547
SDL_COPY_COLORKEY
#define SDL_COPY_COLORKEY
Definition: SDL_blit.h:40
SDL_Rect::x
int x
Definition: SDL_rect.h:79
SDL_Rect::w
int w
Definition: SDL_rect.h:80
SDL_PREALLOC
#define SDL_PREALLOC
Definition: SDL_surface.h:53
SDL_COPY_MUL
#define SDL_COPY_MUL
Definition: SDL_blit.h:39
SDL_Rect::y
int y
Definition: SDL_rect.h:79
SDL_Rect::h
int h
Definition: SDL_rect.h:80
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_COPY_BLEND
#define SDL_COPY_BLEND
Definition: SDL_blit.h:36
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:44
SDL_RLEAlphaBlit
static int SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect, SDL_Surface *surf_dst, SDL_Rect *dstrect)
Definition: SDL_RLEaccel.c:729
SDL_COPY_NEAREST
#define SDL_COPY_NEAREST
Definition: SDL_blit.h:41
SDL_Rect
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77
UnRLEAlpha
static SDL_bool UnRLEAlpha(SDL_Surface *surface)
Definition: SDL_RLEaccel.c:1471
SDL_SIMDAlloc
#define SDL_SIMDAlloc
Definition: SDL_dynapi_overrides.h:718
SDL_COPY_ADD
#define SDL_COPY_ADD
Definition: SDL_blit.h:37
SDL_COPY_MOD
#define SDL_COPY_MOD
Definition: SDL_blit.h:38
SDL_FillRect
#define SDL_FillRect
Definition: SDL_dynapi_overrides.h:466
RLEColorkeySurface
static int RLEColorkeySurface(SDL_Surface *surface)
Definition: SDL_RLEaccel.c:1276
SDL_COPY_MODULATE_COLOR
#define SDL_COPY_MODULATE_COLOR
Definition: SDL_blit.h:34
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1483
SDL_SIMD_ALIGNED
#define SDL_SIMD_ALIGNED
Definition: SDL_surface.h:56
RLEAlphaSurface
static int RLEAlphaSurface(SDL_Surface *surface)
Definition: SDL_RLEaccel.c:1028