Skip to content

Commit

Permalink
Reduce the size of the SDL_blit_0 alpha code
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 committed Oct 12, 2024
1 parent e2f2736 commit 2479bc6
Showing 1 changed file with 19 additions and 48 deletions.
67 changes: 19 additions & 48 deletions src/video/SDL_blit_0.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,34 +605,35 @@ SDL_FORCE_INLINE void BlitBto4Key(SDL_BlitInfo *info, const Uint32 srcbpp)
}
}

SDL_FORCE_INLINE void BlitBtoNAlpha(SDL_BlitInfo *info, const Uint32 srcbpp)
static void BlitBtoNAlpha(SDL_BlitInfo *info)
{
const Uint32 mask = (1 << srcbpp) - 1;
const Uint32 align = (8 / srcbpp) - 1;

int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint8 *dst = info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
const SDL_Color *srcpal = info->src_fmt->palette->colors;
SDL_PixelFormat *srcfmt = info->src_fmt;
SDL_PixelFormat *dstfmt = info->dst_fmt;
int dstbpp;
int srcbpp, dstbpp;
int c;
Uint32 pixel;
Uint32 pixel, mask, align;
unsigned sR, sG, sB;
unsigned dR, dG, dB, dA;
const unsigned A = info->a;

/* Set up some basic variables */
srcbpp = srcfmt->BytesPerPixel;
dstbpp = dstfmt->BytesPerPixel;
if (srcbpp == 4)
srcskip += width - (width + 1) / 2;
else if (srcbpp == 2)
srcskip += width - (width + 3) / 4;
else if (srcbpp == 1)
srcskip += width - (width + 7) / 8;
mask = (1 << srcbpp) - 1;
align = (8 / srcbpp) - 1;

if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) {
while (height--) {
Expand Down Expand Up @@ -681,11 +682,8 @@ SDL_FORCE_INLINE void BlitBtoNAlpha(SDL_BlitInfo *info, const Uint32 srcbpp)
}
}

SDL_FORCE_INLINE void BlitBtoNAlphaKey(SDL_BlitInfo *info, const Uint32 srcbpp)
static void BlitBtoNAlphaKey(SDL_BlitInfo *info)
{
const Uint32 mask = (1 << srcbpp) - 1;
const Uint32 align = (8 / srcbpp) - 1;

int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Expand All @@ -695,22 +693,25 @@ SDL_FORCE_INLINE void BlitBtoNAlphaKey(SDL_BlitInfo *info, const Uint32 srcbpp)
SDL_PixelFormat *srcfmt = info->src_fmt;
SDL_PixelFormat *dstfmt = info->dst_fmt;
const SDL_Color *srcpal = srcfmt->palette->colors;
int dstbpp;
int srcbpp, dstbpp;
int c;
Uint32 pixel;
Uint32 pixel, mask, align;
unsigned sR, sG, sB;
unsigned dR, dG, dB, dA;
const unsigned A = info->a;
Uint32 ckey = info->colorkey;

/* Set up some basic variables */
srcbpp = srcfmt->BytesPerPixel;
dstbpp = dstfmt->BytesPerPixel;
if (srcbpp == 4)
srcskip += width - (width + 1) / 2;
else if (srcbpp == 2)
srcskip += width - (width + 3) / 4;
else if (srcbpp == 1)
srcskip += width - (width + 7) / 8;
mask = (1 << srcbpp) - 1;
align = (8 / srcbpp) - 1;

if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) {
while (height--) {
Expand Down Expand Up @@ -801,16 +802,6 @@ static const SDL_BlitFunc colorkey_blit_1b[] = {
(SDL_BlitFunc)NULL, Blit1bto1Key, Blit1bto2Key, Blit1bto3Key, Blit1bto4Key
};

static void Blit1btoNAlpha(SDL_BlitInfo *info)
{
BlitBtoNAlpha(info, 1);
}

static void Blit1btoNAlphaKey(SDL_BlitInfo *info)
{
BlitBtoNAlphaKey(info, 1);
}



static void Blit2bto1(SDL_BlitInfo *info) {
Expand Down Expand Up @@ -853,16 +844,6 @@ static const SDL_BlitFunc colorkey_blit_2b[] = {
(SDL_BlitFunc)NULL, Blit2bto1Key, Blit2bto2Key, Blit2bto3Key, Blit2bto4Key
};

static void Blit2btoNAlpha(SDL_BlitInfo *info)
{
BlitBtoNAlpha(info, 2);
}

static void Blit2btoNAlphaKey(SDL_BlitInfo *info)
{
BlitBtoNAlphaKey(info, 2);
}



static void Blit4bto1(SDL_BlitInfo *info) {
Expand Down Expand Up @@ -905,16 +886,6 @@ static const SDL_BlitFunc colorkey_blit_4b[] = {
(SDL_BlitFunc)NULL, Blit4bto1Key, Blit4bto2Key, Blit4bto3Key, Blit4bto4Key
};

static void Blit4btoNAlpha(SDL_BlitInfo *info)
{
BlitBtoNAlpha(info, 4);
}

static void Blit4btoNAlphaKey(SDL_BlitInfo *info)
{
BlitBtoNAlphaKey(info, 4);
}



SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
Expand All @@ -936,10 +907,10 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
return colorkey_blit_1b[which];

case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit1btoNAlpha : (SDL_BlitFunc)NULL;
return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc)NULL;

case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit1btoNAlphaKey : (SDL_BlitFunc)NULL;
return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc)NULL;
}
return NULL;
}
Expand All @@ -953,10 +924,10 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
return colorkey_blit_2b[which];

case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit2btoNAlpha : (SDL_BlitFunc)NULL;
return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc)NULL;

case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit2btoNAlphaKey : (SDL_BlitFunc)NULL;
return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc)NULL;
}
return NULL;
}
Expand All @@ -970,10 +941,10 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
return colorkey_blit_4b[which];

case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit4btoNAlpha : (SDL_BlitFunc)NULL;
return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc)NULL;

case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit4btoNAlphaKey : (SDL_BlitFunc)NULL;
return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc)NULL;
}
return NULL;
}
Expand Down

0 comments on commit 2479bc6

Please sign in to comment.