backport fix for bug #2976: SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Sat, 24 Mar 2018 22:44:12 +0300
branchSDL-1.2
changeset 1197394f71f4d90e9
parent 11972 0b5ac2b90ab1
child 11974 b8aca1c1ad6e
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
     1.1 --- a/src/video/SDL_blit_N.c	Sat Mar 24 22:41:17 2018 +0300
     1.2 +++ b/src/video/SDL_blit_N.c	Sat Mar 24 22:44:12 2018 +0300
     1.3 @@ -2039,6 +2039,30 @@
     1.4  	}
     1.5  }
     1.6  
     1.7 +/* blits 32 bit RGBA<->RGBA with both surfaces having the same R,G,B,A fields */
     1.8 +static void Blit4to4CopyAlpha(SDL_BlitInfo *info)
     1.9 +{
    1.10 +	int width = info->d_width;
    1.11 +	int height = info->d_height;
    1.12 +	Uint32 *src = (Uint32 *)info->s_pixels;
    1.13 +	int srcskip = info->s_skip;
    1.14 +	Uint32 *dst = (Uint32 *)info->d_pixels;
    1.15 +	int dstskip = info->d_skip;
    1.16 +
    1.17 +	/* RGBA->RGBA, COPY_ALPHA */
    1.18 +	while ( height-- ) {
    1.19 +		DUFFS_LOOP(
    1.20 +		{
    1.21 +			*dst = *src;
    1.22 +			++dst;
    1.23 +			++src;
    1.24 +		},
    1.25 +		width);
    1.26 +		src = (Uint32*)((Uint8*)src + srcskip);
    1.27 +		dst = (Uint32*)((Uint8*)dst + dstskip);
    1.28 +	}
    1.29 +}
    1.30 +
    1.31  static void BlitNtoN(SDL_BlitInfo *info)
    1.32  {
    1.33  	int width = info->d_width;
    1.34 @@ -2469,12 +2493,21 @@
    1.35  		blitfun = table[which].blitfunc;
    1.36  
    1.37  		if(blitfun == BlitNtoN) {  /* default C fallback catch-all. Slow! */
    1.38 -			/* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
    1.39  			if ( srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 &&
    1.40  			     srcfmt->Rmask == dstfmt->Rmask &&
    1.41  			     srcfmt->Gmask == dstfmt->Gmask &&
    1.42  			     srcfmt->Bmask == dstfmt->Bmask ) {
    1.43 -				blitfun = Blit4to4MaskAlpha;
    1.44 +				if( a_need == COPY_ALPHA ) {
    1.45 +				    if( srcfmt->Amask == dstfmt->Amask ) {
    1.46 +				    /* Fastpath C fallback: 32bit RGBA<->RGBA blit with matching RGBA */
    1.47 +					blitfun = Blit4to4CopyAlpha;
    1.48 +				    } else {
    1.49 +					blitfun = BlitNtoNCopyAlpha;
    1.50 +				    }
    1.51 +				} else {
    1.52 +				    /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
    1.53 +				    blitfun = Blit4to4MaskAlpha;
    1.54 +				}
    1.55  			} else if ( a_need == COPY_ALPHA ) {
    1.56  			    blitfun = BlitNtoNCopyAlpha;
    1.57  			}