Skip to content

Commit 79a8f7b

Browse files
ccawley2011slouken
authored andcommitted
Reduce the size of the SDL_blit_0 alpha code
(cherry picked from commit 90f792f)
1 parent 302ab09 commit 79a8f7b

File tree

1 file changed

+19
-48
lines changed

1 file changed

+19
-48
lines changed

src/video/SDL_blit_0.c

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -605,34 +605,35 @@ SDL_FORCE_INLINE void BlitBto4Key(SDL_BlitInfo *info, const Uint32 srcbpp)
605605
}
606606
}
607607

608-
SDL_FORCE_INLINE void BlitBtoNAlpha(SDL_BlitInfo *info, const Uint32 srcbpp)
608+
static void BlitBtoNAlpha(SDL_BlitInfo *info)
609609
{
610-
const Uint32 mask = (1 << srcbpp) - 1;
611-
const Uint32 align = (8 / srcbpp) - 1;
612-
613610
int width = info->dst_w;
614611
int height = info->dst_h;
615612
Uint8 *src = info->src;
616613
Uint8 *dst = info->dst;
617614
int srcskip = info->src_skip;
618615
int dstskip = info->dst_skip;
619616
const SDL_Color *srcpal = info->src_fmt->palette->colors;
617+
SDL_PixelFormat *srcfmt = info->src_fmt;
620618
SDL_PixelFormat *dstfmt = info->dst_fmt;
621-
int dstbpp;
619+
int srcbpp, dstbpp;
622620
int c;
623-
Uint32 pixel;
621+
Uint32 pixel, mask, align;
624622
unsigned sR, sG, sB;
625623
unsigned dR, dG, dB, dA;
626624
const unsigned A = info->a;
627625

628626
/* Set up some basic variables */
627+
srcbpp = srcfmt->BytesPerPixel;
629628
dstbpp = dstfmt->BytesPerPixel;
630629
if (srcbpp == 4)
631630
srcskip += width - (width + 1) / 2;
632631
else if (srcbpp == 2)
633632
srcskip += width - (width + 3) / 4;
634633
else if (srcbpp == 1)
635634
srcskip += width - (width + 7) / 8;
635+
mask = (1 << srcbpp) - 1;
636+
align = (8 / srcbpp) - 1;
636637

637638
if (SDL_PIXELORDER(info->src_fmt->format) == SDL_BITMAPORDER_4321) {
638639
while (height--) {
@@ -681,11 +682,8 @@ SDL_FORCE_INLINE void BlitBtoNAlpha(SDL_BlitInfo *info, const Uint32 srcbpp)
681682
}
682683
}
683684

684-
SDL_FORCE_INLINE void BlitBtoNAlphaKey(SDL_BlitInfo *info, const Uint32 srcbpp)
685+
static void BlitBtoNAlphaKey(SDL_BlitInfo *info)
685686
{
686-
const Uint32 mask = (1 << srcbpp) - 1;
687-
const Uint32 align = (8 / srcbpp) - 1;
688-
689687
int width = info->dst_w;
690688
int height = info->dst_h;
691689
Uint8 *src = info->src;
@@ -695,22 +693,25 @@ SDL_FORCE_INLINE void BlitBtoNAlphaKey(SDL_BlitInfo *info, const Uint32 srcbpp)
695693
SDL_PixelFormat *srcfmt = info->src_fmt;
696694
SDL_PixelFormat *dstfmt = info->dst_fmt;
697695
const SDL_Color *srcpal = srcfmt->palette->colors;
698-
int dstbpp;
696+
int srcbpp, dstbpp;
699697
int c;
700-
Uint32 pixel;
698+
Uint32 pixel, mask, align;
701699
unsigned sR, sG, sB;
702700
unsigned dR, dG, dB, dA;
703701
const unsigned A = info->a;
704702
Uint32 ckey = info->colorkey;
705703

706704
/* Set up some basic variables */
705+
srcbpp = srcfmt->BytesPerPixel;
707706
dstbpp = dstfmt->BytesPerPixel;
708707
if (srcbpp == 4)
709708
srcskip += width - (width + 1) / 2;
710709
else if (srcbpp == 2)
711710
srcskip += width - (width + 3) / 4;
712711
else if (srcbpp == 1)
713712
srcskip += width - (width + 7) / 8;
713+
mask = (1 << srcbpp) - 1;
714+
align = (8 / srcbpp) - 1;
714715

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

804-
static void Blit1btoNAlpha(SDL_BlitInfo *info)
805-
{
806-
BlitBtoNAlpha(info, 1);
807-
}
808-
809-
static void Blit1btoNAlphaKey(SDL_BlitInfo *info)
810-
{
811-
BlitBtoNAlphaKey(info, 1);
812-
}
813-
814805

815806

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

856-
static void Blit2btoNAlpha(SDL_BlitInfo *info)
857-
{
858-
BlitBtoNAlpha(info, 2);
859-
}
860-
861-
static void Blit2btoNAlphaKey(SDL_BlitInfo *info)
862-
{
863-
BlitBtoNAlphaKey(info, 2);
864-
}
865-
866847

867848

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

908-
static void Blit4btoNAlpha(SDL_BlitInfo *info)
909-
{
910-
BlitBtoNAlpha(info, 4);
911-
}
912-
913-
static void Blit4btoNAlphaKey(SDL_BlitInfo *info)
914-
{
915-
BlitBtoNAlphaKey(info, 4);
916-
}
917-
918889

919890

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

938909
case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
939-
return which >= 2 ? Blit1btoNAlpha : (SDL_BlitFunc)NULL;
910+
return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc)NULL;
940911

941912
case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
942-
return which >= 2 ? Blit1btoNAlphaKey : (SDL_BlitFunc)NULL;
913+
return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc)NULL;
943914
}
944915
return NULL;
945916
}
@@ -953,10 +924,10 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
953924
return colorkey_blit_2b[which];
954925

955926
case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
956-
return which >= 2 ? Blit2btoNAlpha : (SDL_BlitFunc)NULL;
927+
return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc)NULL;
957928

958929
case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
959-
return which >= 2 ? Blit2btoNAlphaKey : (SDL_BlitFunc)NULL;
930+
return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc)NULL;
960931
}
961932
return NULL;
962933
}
@@ -970,10 +941,10 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
970941
return colorkey_blit_4b[which];
971942

972943
case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
973-
return which >= 2 ? Blit4btoNAlpha : (SDL_BlitFunc)NULL;
944+
return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc)NULL;
974945

975946
case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
976-
return which >= 2 ? Blit4btoNAlphaKey : (SDL_BlitFunc)NULL;
947+
return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc)NULL;
977948
}
978949
return NULL;
979950
}

0 commit comments

Comments
 (0)