SDL_blit_slow: remove one nested 'if()' because of ARGB2101010 handling

This commit is contained in:
Sylvain 2022-03-16 18:08:20 +01:00
parent 56568ffb38
commit 93e7caab9a
No known key found for this signature in database
GPG Key ID: 5F87E02E5BC0939E
1 changed files with 39 additions and 25 deletions

View File

@ -24,6 +24,21 @@
#include "SDL_blit.h" #include "SDL_blit.h"
#include "SDL_blit_slow.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 /* The ONE TRUE BLITTER
* This puppy has to handle all the unoptimized cases - yes, it's slow. * 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; SDL_PixelFormat *dst_fmt = info->dst_fmt;
int srcbpp = src_fmt->BytesPerPixel; int srcbpp = src_fmt->BytesPerPixel;
int dstbpp = dst_fmt->BytesPerPixel; int dstbpp = dst_fmt->BytesPerPixel;
int srcfmt_isnot_2101010 = (src_fmt->format != SDL_PIXELFORMAT_ARGB2101010); int srcfmt_val;
int dstfmt_isnot_2101010 = (dst_fmt->format != SDL_PIXELFORMAT_ARGB2101010); int dstfmt_val;
Uint32 rgbmask = ~src_fmt->Amask; Uint32 rgbmask = ~src_fmt->Amask;
Uint32 ckey = info->colorkey & rgbmask; 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; incy = (info->src_h << 16) / info->dst_h;
incx = (info->src_w << 16) / info->dst_w; incx = (info->src_w << 16) / info->dst_w;
posy = incy / 2; /* start at the middle of pixel */ posy = incy / 2; /* start at the middle of pixel */
@ -64,13 +82,12 @@ SDL_Blit_Slow(SDL_BlitInfo * info)
while (n--) { while (n--) {
srcx = posx >> 16; srcx = posx >> 16;
src = (info->src + (srcy * info->src_pitch) + (srcx * srcbpp)); src = (info->src + (srcy * info->src_pitch) + (srcx * srcbpp));
if (srcfmt_isnot_2101010) {
if (src_fmt->Amask) { if (FORMAT_HAS_ALPHA(srcfmt_val)) {
DISEMBLE_RGBA(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB, srcA); DISEMBLE_RGBA(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB, srcA);
} else { } else if (FORMAT_HAS_NO_ALPHA(srcfmt_val)) {
DISEMBLE_RGB(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB); DISEMBLE_RGB(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB);
srcA = 0xFF; srcA = 0xFF;
}
} else { } else {
/* SDL_PIXELFORMAT_ARGB2101010 */ /* SDL_PIXELFORMAT_ARGB2101010 */
srcpixel = *((Uint32 *)(src)); srcpixel = *((Uint32 *)(src));
@ -89,13 +106,11 @@ SDL_Blit_Slow(SDL_BlitInfo * info)
continue; continue;
} }
} }
if (dstfmt_isnot_2101010) { if (FORMAT_HAS_ALPHA(dstfmt_val)) {
if (dst_fmt->Amask) {
DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB, dstA); DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB, dstA);
} else { } else if (FORMAT_HAS_NO_ALPHA(dstfmt_val)) {
DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB); DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB);
dstA = 0xFF; dstA = 0xFF;
}
} else { } else {
/* SDL_PIXELFORMAT_ARGB2101010 */ /* SDL_PIXELFORMAT_ARGB2101010 */
dstpixel = *((Uint32 *)(dst)); dstpixel = *((Uint32 *)(dst));
@ -162,16 +177,15 @@ SDL_Blit_Slow(SDL_BlitInfo * info)
dstA = 255; dstA = 255;
break; break;
} }
if (dstfmt_isnot_2101010) { if (FORMAT_HAS_ALPHA(dstfmt_val)) {
if (dst_fmt->Amask) {
ASSEMBLE_RGBA(dst, dstbpp, dst_fmt, dstR, dstG, dstB, dstA); ASSEMBLE_RGBA(dst, dstbpp, dst_fmt, dstR, dstG, dstB, dstA);
} else { } else if (FORMAT_HAS_NO_ALPHA(dstfmt_val)) {
ASSEMBLE_RGB(dst, dstbpp, dst_fmt, dstR, dstG, dstB); ASSEMBLE_RGB(dst, dstbpp, dst_fmt, dstR, dstG, dstB);
}
} else { } else {
Uint32 Pixel; /* SDL_PIXELFORMAT_ARGB2101010 */
ARGB2101010_FROM_RGBA(Pixel, dstR, dstG, dstB, dstA); Uint32 pixel;
*(Uint32 *)dst = Pixel; ARGB2101010_FROM_RGBA(pixel, dstR, dstG, dstB, dstA);
*(Uint32 *)dst = pixel;
} }
posx += incx; posx += incx;
dst += dstbpp; dst += dstbpp;