From db8ae756e9d21e78e143accdfb62e3913cd0dbdc Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 24 Mar 2018 22:44:12 +0300 Subject: [PATCH] backport fix for bug #2976: Fix RGBA<->RGBA blit that was broken with the optimization from bug #11 id.zeta@yahoo.com --- src/video/SDL_blit_N.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/video/SDL_blit_N.c b/src/video/SDL_blit_N.c index ac029d1d3..146a10007 100644 --- a/src/video/SDL_blit_N.c +++ b/src/video/SDL_blit_N.c @@ -2039,6 +2039,30 @@ static void Blit4to4MaskAlpha(SDL_BlitInfo *info) } } +/* blits 32 bit RGBA<->RGBA with both surfaces having the same R,G,B,A fields */ +static void Blit4to4CopyAlpha(SDL_BlitInfo *info) +{ + int width = info->d_width; + int height = info->d_height; + Uint32 *src = (Uint32 *)info->s_pixels; + int srcskip = info->s_skip; + Uint32 *dst = (Uint32 *)info->d_pixels; + int dstskip = info->d_skip; + + /* RGBA->RGBA, COPY_ALPHA */ + while ( height-- ) { + DUFFS_LOOP( + { + *dst = *src; + ++dst; + ++src; + }, + width); + src = (Uint32*)((Uint8*)src + srcskip); + dst = (Uint32*)((Uint8*)dst + dstskip); + } +} + static void BlitNtoN(SDL_BlitInfo *info) { int width = info->d_width; @@ -2469,12 +2493,21 @@ SDL_loblit SDL_CalculateBlitN(SDL_Surface *surface, int blit_index) blitfun = table[which].blitfunc; if(blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */ - /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */ if ( srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 && srcfmt->Rmask == dstfmt->Rmask && srcfmt->Gmask == dstfmt->Gmask && srcfmt->Bmask == dstfmt->Bmask ) { - blitfun = Blit4to4MaskAlpha; + if( a_need == COPY_ALPHA ) { + if( srcfmt->Amask == dstfmt->Amask ) { + /* Fastpath C fallback: 32bit RGBA<->RGBA blit with matching RGBA */ + blitfun = Blit4to4CopyAlpha; + } else { + blitfun = BlitNtoNCopyAlpha; + } + } else { + /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */ + blitfun = Blit4to4MaskAlpha; + } } else if ( a_need == COPY_ALPHA ) { blitfun = BlitNtoNCopyAlpha; }