From 2479bc6c863272d50ff0d8e6cfd87326e4605e1d Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sat, 12 Oct 2024 16:06:31 +0100 Subject: [PATCH] Reduce the size of the SDL_blit_0 alpha code --- src/video/SDL_blit_0.c | 67 ++++++++++++------------------------------ 1 file changed, 19 insertions(+), 48 deletions(-) diff --git a/src/video/SDL_blit_0.c b/src/video/SDL_blit_0.c index e7750ddb3d491..3104f4ed6fbc4 100644 --- a/src/video/SDL_blit_0.c +++ b/src/video/SDL_blit_0.c @@ -605,11 +605,8 @@ 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; @@ -617,15 +614,17 @@ SDL_FORCE_INLINE void BlitBtoNAlpha(SDL_BlitInfo *info, const Uint32 srcbpp) 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; @@ -633,6 +632,8 @@ SDL_FORCE_INLINE void BlitBtoNAlpha(SDL_BlitInfo *info, const Uint32 srcbpp) 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,15 +693,16 @@ 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; @@ -711,6 +710,8 @@ SDL_FORCE_INLINE void BlitBtoNAlphaKey(SDL_BlitInfo *info, const Uint32 srcbpp) 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; }