Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved the colorkey and per-surface alpha into the blit info,
in preparation for support for general color channel modulation.

Removed and consolidated some data in the blit info.
  • Loading branch information
slouken committed Aug 17, 2007
1 parent 2517b56 commit af50243
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 146 deletions.
5 changes: 0 additions & 5 deletions include/SDL_pixels.h
Expand Up @@ -237,11 +237,6 @@ typedef struct SDL_PixelFormat
Uint32 Gmask;
Uint32 Bmask;
Uint32 Amask;

/* RGB color key information */
Uint32 colorkey;
/* Alpha value information (per-surface alpha) */
Uint8 alpha;
} SDL_PixelFormat;

/**
Expand Down
22 changes: 11 additions & 11 deletions src/video/SDL_RLEaccel.c
Expand Up @@ -859,7 +859,7 @@ SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
y = dstrect->y;
dstbuf = (Uint8 *) dst->pixels
+ y * dst->pitch + x * src->format->BytesPerPixel;
srcbuf = (Uint8 *) src->map->sw_data->aux_data;
srcbuf = (Uint8 *) src->map->data;

{
/* skip lines at the top if neccessary */
Expand Down Expand Up @@ -906,7 +906,7 @@ SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
}

alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA
? src->format->alpha : 255;
? (src->map->cmod >> 24) : 255;
/* if left or right edge clipping needed, call clip blit */
if (srcrect->x || srcrect->w != src->w) {
RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
Expand Down Expand Up @@ -1133,7 +1133,7 @@ SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
x = dstrect->x;
y = dstrect->y;
dstbuf = (Uint8 *) dst->pixels + y * dst->pitch + x * df->BytesPerPixel;
srcbuf = (Uint8 *) src->map->sw_data->aux_data + sizeof(RLEDestFormat);
srcbuf = (Uint8 *) src->map->data + sizeof(RLEDestFormat);

{
/* skip lines at the top if necessary */
Expand Down Expand Up @@ -1628,7 +1628,7 @@ RLEAlphaSurface(SDL_Surface * surface)
Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
if (!p)
p = rlebuf;
surface->map->sw_data->aux_data = p;
surface->map->data = p;
}

return 0;
Expand Down Expand Up @@ -1715,7 +1715,7 @@ RLEColorkeySurface(SDL_Surface * surface)
skip = run = 0;
dst = rlebuf;
rgbmask = ~surface->format->Amask;
ckey = surface->format->colorkey & rgbmask;
ckey = surface->map->ckey & rgbmask;
lastline = dst;
getpix = getpixes[bpp - 1];
w = surface->w;
Expand Down Expand Up @@ -1794,7 +1794,7 @@ RLEColorkeySurface(SDL_Surface * surface)
Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
if (!p)
p = rlebuf;
surface->map->sw_data->aux_data = p;
surface->map->data = p;
}

return (0);
Expand Down Expand Up @@ -1859,7 +1859,7 @@ UnRLEAlpha(SDL_Surface * surface)
Uint8 *srcbuf;
Uint32 *dst;
SDL_PixelFormat *sf = surface->format;
RLEDestFormat *df = surface->map->sw_data->aux_data;
RLEDestFormat *df = surface->map->data;
int (*uncopy_opaque) (Uint32 *, void *, int,
RLEDestFormat *, SDL_PixelFormat *);
int (*uncopy_transl) (Uint32 *, void *, int,
Expand Down Expand Up @@ -1948,7 +1948,7 @@ SDL_UnRLESurface(SDL_Surface * surface, int recode)
}

/* fill it with the background colour */
SDL_FillRect(surface, NULL, surface->format->colorkey);
SDL_FillRect(surface, NULL, surface->map->ckey);

/* now render the encoded surface */
full.x = full.y = 0;
Expand All @@ -1967,9 +1967,9 @@ SDL_UnRLESurface(SDL_Surface * surface, int recode)
}
}

if (surface->map && surface->map->sw_data->aux_data) {
SDL_free(surface->map->sw_data->aux_data);
surface->map->sw_data->aux_data = NULL;
if (surface->map && surface->map->data) {
SDL_free(surface->map->data);
surface->map->data = NULL;
}
}
}
Expand Down
37 changes: 17 additions & 20 deletions src/video/SDL_blit.c
Expand Up @@ -77,11 +77,12 @@ SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect,
info.d_width = dstrect->w;
info.d_height = dstrect->h;
info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel;
info.aux_data = src->map->sw_data->aux_data;
info.src = src->format;
info.table = src->map->table;
info.dst = dst->format;
RunBlit = src->map->sw_data->blit;
info.ckey = src->map->ckey;
info.cmod = src->map->cmod;
RunBlit = (SDL_loblit)src->map->data;

/* Run the actual software blit */
RunBlit(&info);
Expand Down Expand Up @@ -166,20 +167,21 @@ SDL_ChooseBlitFunc(SDL_BlitEntry * entries, int count)
int
SDL_CalculateBlit(SDL_Surface * surface)
{
SDL_loblit blit = NULL;
int blit_index;

/* Clean everything out to start */
if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 1);
}
surface->map->sw_blit = NULL;
surface->map->blit = NULL;

/* Get the blit function index, based on surface mode */
/* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */
blit_index = 0;
blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0;
if (surface->flags & SDL_SRCALPHA
&& (surface->format->alpha != SDL_ALPHA_OPAQUE
&& ((surface->map->cmod >> 24) != SDL_ALPHA_OPAQUE
|| surface->format->Amask)) {
blit_index |= 2;
}
Expand All @@ -188,34 +190,28 @@ SDL_CalculateBlit(SDL_Surface * surface)
if (surface->map->identity && blit_index == 0) {
/* Handle overlapping blits on the same surface */
if (surface == surface->map->dst) {
surface->map->sw_data->blit = SDL_BlitCopyOverlap;
blit = SDL_BlitCopyOverlap;
} else {
surface->map->sw_data->blit = SDL_BlitCopy;
blit = SDL_BlitCopy;
}
} else {
if (surface->format->BitsPerPixel < 8) {
surface->map->sw_data->blit =
SDL_CalculateBlit0(surface, blit_index);
blit = SDL_CalculateBlit0(surface, blit_index);
} else {
switch (surface->format->BytesPerPixel) {
case 1:
surface->map->sw_data->blit =
SDL_CalculateBlit1(surface, blit_index);
blit = SDL_CalculateBlit1(surface, blit_index);
break;
case 2:
case 3:
case 4:
surface->map->sw_data->blit =
SDL_CalculateBlitN(surface, blit_index);
break;
default:
surface->map->sw_data->blit = NULL;
blit = SDL_CalculateBlitN(surface, blit_index);
break;
}
}
}
/* Make sure we have a blit function */
if (surface->map->sw_data->blit == NULL) {
if (blit == NULL) {
SDL_InvalidateMap(surface->map);
SDL_SetError("Blit combination not supported");
return (-1);
Expand All @@ -227,15 +223,16 @@ SDL_CalculateBlit(SDL_Surface * surface)
&& (blit_index == 1
|| (blit_index == 3 && !surface->format->Amask))) {
if (SDL_RLESurface(surface) == 0)
surface->map->sw_blit = SDL_RLEBlit;
surface->map->blit = SDL_RLEBlit;
} else if (blit_index == 2 && surface->format->Amask) {
if (SDL_RLESurface(surface) == 0)
surface->map->sw_blit = SDL_RLEAlphaBlit;
surface->map->blit = SDL_RLEAlphaBlit;
}
}

if (surface->map->sw_blit == NULL) {
surface->map->sw_blit = SDL_SoftBlit;
if (surface->map->blit == NULL) {
surface->map->blit = SDL_SoftBlit;
surface->map->data = blit;
}
return (0);
}
Expand Down
15 changes: 5 additions & 10 deletions src/video/SDL_blit.h
Expand Up @@ -45,30 +45,25 @@ typedef struct
int d_width;
int d_height;
int d_skip;
void *aux_data;
SDL_PixelFormat *src;
Uint8 *table;
SDL_PixelFormat *dst;
Uint32 ckey, cmod;
} SDL_BlitInfo;

/* The type definition for the low level blit functions */
typedef void (*SDL_loblit) (SDL_BlitInfo * info);

/* This is the private info structure for software accelerated blits */
struct private_swaccel
{
SDL_loblit blit;
void *aux_data;
};

/* Blit mapping definition */
typedef struct SDL_BlitMap
{
SDL_Surface *dst;
int identity;
Uint8 *table;
SDL_blit sw_blit;
struct private_swaccel *sw_data;
SDL_blit blit;
void *data;
Uint32 ckey; /* colorkey */
Uint32 cmod; /* ARGB modulation */

/* the version count matches the destination; mismatch indicates
an invalid mapping */
Expand Down
14 changes: 7 additions & 7 deletions src/video/SDL_blit_0.c
Expand Up @@ -200,7 +200,7 @@ BlitBto1Key(SDL_BlitInfo * info)
Uint8 *dst = info->d_pixels;
int srcskip = info->s_skip;
int dstskip = info->d_skip;
Uint32 ckey = info->src->colorkey;
Uint32 ckey = info->ckey;
Uint8 *palmap = info->table;
int c;

Expand Down Expand Up @@ -253,7 +253,7 @@ BlitBto2Key(SDL_BlitInfo * info)
Uint16 *dstp = (Uint16 *) info->d_pixels;
int srcskip = info->s_skip;
int dstskip = info->d_skip;
Uint32 ckey = info->src->colorkey;
Uint32 ckey = info->ckey;
Uint8 *palmap = info->table;
int c;

Expand Down Expand Up @@ -288,7 +288,7 @@ BlitBto3Key(SDL_BlitInfo * info)
Uint8 *dst = info->d_pixels;
int srcskip = info->s_skip;
int dstskip = info->d_skip;
Uint32 ckey = info->src->colorkey;
Uint32 ckey = info->ckey;
Uint8 *palmap = info->table;
int c;

Expand Down Expand Up @@ -322,7 +322,7 @@ BlitBto4Key(SDL_BlitInfo * info)
Uint32 *dstp = (Uint32 *) info->d_pixels;
int srcskip = info->s_skip;
int dstskip = info->d_skip;
Uint32 ckey = info->src->colorkey;
Uint32 ckey = info->ckey;
Uint8 *palmap = info->table;
int c;

Expand Down Expand Up @@ -361,7 +361,7 @@ BlitBtoNAlpha(SDL_BlitInfo * info)
SDL_PixelFormat *dstfmt = info->dst;
int dstbpp;
int c;
const int A = info->src->alpha;
const int A = (info->cmod >> 24);

/* Set up some basic variables */
dstbpp = dstfmt->BytesPerPixel;
Expand Down Expand Up @@ -407,8 +407,8 @@ BlitBtoNAlphaKey(SDL_BlitInfo * info)
const SDL_Color *srcpal = srcfmt->palette->colors;
int dstbpp;
int c;
const int A = srcfmt->alpha;
Uint32 ckey = srcfmt->colorkey;
const int A = (info->cmod >> 24);
Uint32 ckey = info->ckey;

/* Set up some basic variables */
dstbpp = dstfmt->BytesPerPixel;
Expand Down
14 changes: 7 additions & 7 deletions src/video/SDL_blit_1.c
Expand Up @@ -290,7 +290,7 @@ Blit1to1Key(SDL_BlitInfo * info)
Uint8 *dst = info->d_pixels;
int dstskip = info->d_skip;
Uint8 *palmap = info->table;
Uint32 ckey = info->src->colorkey;
Uint32 ckey = info->ckey;

if (palmap) {
while (height--) {
Expand Down Expand Up @@ -337,7 +337,7 @@ Blit1to2Key(SDL_BlitInfo * info)
Uint16 *dstp = (Uint16 *) info->d_pixels;
int dstskip = info->d_skip;
Uint16 *palmap = (Uint16 *) info->table;
Uint32 ckey = info->src->colorkey;
Uint32 ckey = info->ckey;

/* Set up some basic variables */
dstskip /= 2;
Expand Down Expand Up @@ -369,7 +369,7 @@ Blit1to3Key(SDL_BlitInfo * info)
Uint8 *dst = info->d_pixels;
int dstskip = info->d_skip;
Uint8 *palmap = info->table;
Uint32 ckey = info->src->colorkey;
Uint32 ckey = info->ckey;
int o;

while (height--) {
Expand Down Expand Up @@ -402,7 +402,7 @@ Blit1to4Key(SDL_BlitInfo * info)
Uint32 *dstp = (Uint32 *) info->d_pixels;
int dstskip = info->d_skip;
Uint32 *palmap = (Uint32 *) info->table;
Uint32 ckey = info->src->colorkey;
Uint32 ckey = info->ckey;

/* Set up some basic variables */
dstskip /= 4;
Expand Down Expand Up @@ -436,7 +436,7 @@ Blit1toNAlpha(SDL_BlitInfo * info)
SDL_PixelFormat *dstfmt = info->dst;
const SDL_Color *srcpal = info->src->palette->colors;
int dstbpp;
const int A = info->src->alpha;
const int A = (info->cmod >> 24);

/* Set up some basic variables */
dstbpp = dstfmt->BytesPerPixel;
Expand Down Expand Up @@ -477,9 +477,9 @@ Blit1toNAlphaKey(SDL_BlitInfo * info)
SDL_PixelFormat *srcfmt = info->src;
SDL_PixelFormat *dstfmt = info->dst;
const SDL_Color *srcpal = info->src->palette->colors;
Uint32 ckey = srcfmt->colorkey;
Uint32 ckey = info->ckey;
int dstbpp;
const int A = srcfmt->alpha;
const int A = (info->cmod >> 24);

/* Set up some basic variables */
dstbpp = dstfmt->BytesPerPixel;
Expand Down

0 comments on commit af50243

Please sign in to comment.