Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport size related PRs to SDL2 #11185

Merged
merged 3 commits into from
Oct 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Reduce the size of the SDL_blit_0 alpha code
  • Loading branch information
ccawley2011 committed Oct 12, 2024
commit 2479bc6c863272d50ff0d8e6cfd87326e4605e1d
67 changes: 19 additions & 48 deletions src/video/SDL_blit_0.c
Original file line number Diff line number Diff line change
@@ -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--) {
@@ -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;
@@ -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--) {
@@ -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) {
@@ -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) {
@@ -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)
@@ -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;
}
@@ -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;
}
@@ -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;
}