Fixed bug #627 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Sat, 10 Oct 2009 07:48:15 +0000
branchSDL-1.2
changeset 429363b54ddd38ea
parent 4292 464126f4c7db
child 4294 5b31c369820b
Fixed bug #627

Increased accuracy of alpha blend calculation
src/video/SDL_blit.h
src/video/SDL_blit_A.c
     1.1 --- a/src/video/SDL_blit.h	Sat Oct 10 07:33:18 2009 +0000
     1.2 +++ b/src/video/SDL_blit.h	Sat Oct 10 07:48:15 2009 +0000
     1.3 @@ -384,22 +384,9 @@
     1.4  /* Blend the RGB values of two Pixels based on a source alpha value */
     1.5  #define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)	\
     1.6  do {						\
     1.7 -	dR = (((sR-dR)*(A))>>8)+dR;		\
     1.8 -	dG = (((sG-dG)*(A))>>8)+dG;		\
     1.9 -	dB = (((sB-dB)*(A))>>8)+dB;		\
    1.10 -} while(0)
    1.11 -
    1.12 -/* Blend the RGB values of two Pixels based on a source alpha value */
    1.13 -#define ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB)	\
    1.14 -do {						\
    1.15 -    unsigned tR, tG, tB, tA; \
    1.16 -    tA = 255 - sA; \
    1.17 -    tR = 1 + (sR * sA) + (dR * tA); \
    1.18 -    dR = (tR + (tR >> 8)) >> 8; \
    1.19 -    tG = 1 + (sG * sA) + (dG * tA); \
    1.20 -    dG = (tG + (tG >> 8)) >> 8; \
    1.21 -    tB = 1 + (sB * sA) + (dB * tA); \
    1.22 -    dB = (tB + (tB >> 8)) >> 8; \
    1.23 +	dR = (((sR-dR)*(A)+255)>>8)+dR;		\
    1.24 +	dG = (((sG-dG)*(A)+255)>>8)+dG;		\
    1.25 +	dB = (((sB-dB)*(A)+255)>>8)+dB;		\
    1.26  } while(0)
    1.27  
    1.28  
     2.1 --- a/src/video/SDL_blit_A.c	Sat Oct 10 07:33:18 2009 +0000
     2.2 +++ b/src/video/SDL_blit_A.c	Sat Oct 10 07:48:15 2009 +0000
     2.3 @@ -861,7 +861,7 @@
     2.4                  dR = (dstpixel >> 8) & 0xf8; \
     2.5                  dG = (dstpixel >> 3) & 0xfc; \
     2.6                  dB = (dstpixel << 3) & 0xf8; \
     2.7 -                ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
     2.8 +                ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
     2.9                  *((unsigned short *)dst) = ( \
    2.10                      ((dR & 0xf8) << 8) | ((dG & 0xfc) << 3) | (dB >> 3) \
    2.11                  ); \
    2.12 @@ -994,7 +994,7 @@
    2.13              if(sA && Pixel != ckey) { \
    2.14                  RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
    2.15                  DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
    2.16 -                ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
    2.17 +                ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
    2.18                  ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
    2.19              } \
    2.20              dstp++; \
    2.21 @@ -1097,7 +1097,7 @@
    2.22              DISEMBLE_RGBA((Uint8 *)srcp, 4, srcfmt, Pixel, sR, sG, sB, sA); \
    2.23              if(sA) { \
    2.24                DISEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, Pixel, dR, dG, dB, dA); \
    2.25 -              ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
    2.26 +              ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
    2.27                ASSEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, dR, dG, dB, dA); \
    2.28              } \
    2.29              ++srcp; \
    2.30 @@ -1296,7 +1296,7 @@
    2.31              unsigned sR, sG, sB, dR, dG, dB; \
    2.32              DISEMBLE_RGB(((Uint8 *)srcp), 4, srcfmt, Pixel, sR, sG, sB); \
    2.33              DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
    2.34 -            ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
    2.35 +            ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
    2.36              ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
    2.37              ++srcp; \
    2.38              ++dstp; \