SDL_blit_slow: remove one nested 'if()' because of ARGB2101010 handling
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
diff --git a/src/video/SDL_blit_slow.c b/src/video/SDL_blit_slow.c
index df31a3b..ed9c692 100644
--- a/src/video/SDL_blit_slow.c
+++ b/src/video/SDL_blit_slow.c
@@ -24,6 +24,21 @@
#include "SDL_blit.h"
#include "SDL_blit_slow.h"
+#define FORMAT_ALPHA 0
+#define FORMAT_NO_ALPHA -1
+#define FORMAT_2101010 1
+#define FORMAT_HAS_ALPHA(format) format == 0
+#define FORMAT_HAS_NO_ALPHA(format) format < 0
+static int SDL_INLINE detect_format(SDL_PixelFormat *pf) {
+ if (pf->format == SDL_PIXELFORMAT_ARGB2101010) {
+ return FORMAT_2101010;
+ } else if (pf->Amask) {
+ return FORMAT_ALPHA;
+ } else {
+ return FORMAT_NO_ALPHA;
+ }
+}
+
/* The ONE TRUE BLITTER
* This puppy has to handle all the unoptimized cases - yes, it's slow.
*/
@@ -46,11 +61,14 @@ SDL_Blit_Slow(SDL_BlitInfo * info)
SDL_PixelFormat *dst_fmt = info->dst_fmt;
int srcbpp = src_fmt->BytesPerPixel;
int dstbpp = dst_fmt->BytesPerPixel;
- int srcfmt_isnot_2101010 = (src_fmt->format != SDL_PIXELFORMAT_ARGB2101010);
- int dstfmt_isnot_2101010 = (dst_fmt->format != SDL_PIXELFORMAT_ARGB2101010);
+ int srcfmt_val;
+ int dstfmt_val;
Uint32 rgbmask = ~src_fmt->Amask;
Uint32 ckey = info->colorkey & rgbmask;
+ srcfmt_val = detect_format(src_fmt);
+ dstfmt_val = detect_format(dst_fmt);
+
incy = (info->src_h << 16) / info->dst_h;
incx = (info->src_w << 16) / info->dst_w;
posy = incy / 2; /* start at the middle of pixel */
@@ -64,13 +82,12 @@ SDL_Blit_Slow(SDL_BlitInfo * info)
while (n--) {
srcx = posx >> 16;
src = (info->src + (srcy * info->src_pitch) + (srcx * srcbpp));
- if (srcfmt_isnot_2101010) {
- if (src_fmt->Amask) {
- DISEMBLE_RGBA(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB, srcA);
- } else {
- DISEMBLE_RGB(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB);
- srcA = 0xFF;
- }
+
+ if (FORMAT_HAS_ALPHA(srcfmt_val)) {
+ DISEMBLE_RGBA(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB, srcA);
+ } else if (FORMAT_HAS_NO_ALPHA(srcfmt_val)) {
+ DISEMBLE_RGB(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB);
+ srcA = 0xFF;
} else {
/* SDL_PIXELFORMAT_ARGB2101010 */
srcpixel = *((Uint32 *)(src));
@@ -89,13 +106,11 @@ SDL_Blit_Slow(SDL_BlitInfo * info)
continue;
}
}
- if (dstfmt_isnot_2101010) {
- if (dst_fmt->Amask) {
- DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB, dstA);
- } else {
- DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB);
- dstA = 0xFF;
- }
+ if (FORMAT_HAS_ALPHA(dstfmt_val)) {
+ DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB, dstA);
+ } else if (FORMAT_HAS_NO_ALPHA(dstfmt_val)) {
+ DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB);
+ dstA = 0xFF;
} else {
/* SDL_PIXELFORMAT_ARGB2101010 */
dstpixel = *((Uint32 *)(dst));
@@ -162,16 +177,15 @@ SDL_Blit_Slow(SDL_BlitInfo * info)
dstA = 255;
break;
}
- if (dstfmt_isnot_2101010) {
- if (dst_fmt->Amask) {
- ASSEMBLE_RGBA(dst, dstbpp, dst_fmt, dstR, dstG, dstB, dstA);
- } else {
- ASSEMBLE_RGB(dst, dstbpp, dst_fmt, dstR, dstG, dstB);
- }
+ if (FORMAT_HAS_ALPHA(dstfmt_val)) {
+ ASSEMBLE_RGBA(dst, dstbpp, dst_fmt, dstR, dstG, dstB, dstA);
+ } else if (FORMAT_HAS_NO_ALPHA(dstfmt_val)) {
+ ASSEMBLE_RGB(dst, dstbpp, dst_fmt, dstR, dstG, dstB);
} else {
- Uint32 Pixel;
- ARGB2101010_FROM_RGBA(Pixel, dstR, dstG, dstB, dstA);
- *(Uint32 *)dst = Pixel;
+ /* SDL_PIXELFORMAT_ARGB2101010 */
+ Uint32 pixel;
+ ARGB2101010_FROM_RGBA(pixel, dstR, dstG, dstB, dstA);
+ *(Uint32 *)dst = pixel;
}
posx += incx;
dst += dstbpp;