Skip to content
Permalink
Browse files

Fixed bug #627

Increased accuracy of alpha blend calculation
  • Loading branch information
slouken committed Oct 10, 2009
1 parent 41c26d2 commit fe8930b3a2bb53000da362ac94c494f40ae95fbb
Showing with 7 additions and 20 deletions.
  1. +3 −16 src/video/SDL_blit.h
  2. +4 −4 src/video/SDL_blit_A.c
@@ -384,22 +384,9 @@ do { \
/* Blend the RGB values of two Pixels based on a source alpha value */
#define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \
do { \
dR = (((sR-dR)*(A))>>8)+dR; \
dG = (((sG-dG)*(A))>>8)+dG; \
dB = (((sB-dB)*(A))>>8)+dB; \
} while(0)

/* Blend the RGB values of two Pixels based on a source alpha value */
#define ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB) \
do { \
unsigned tR, tG, tB, tA; \
tA = 255 - sA; \
tR = 1 + (sR * sA) + (dR * tA); \
dR = (tR + (tR >> 8)) >> 8; \
tG = 1 + (sG * sA) + (dG * tA); \
dG = (tG + (tG >> 8)) >> 8; \
tB = 1 + (sB * sA) + (dB * tA); \
dB = (tB + (tB >> 8)) >> 8; \
dR = (((sR-dR)*(A)+255)>>8)+dR; \
dG = (((sG-dG)*(A)+255)>>8)+dG; \
dB = (((sB-dB)*(A)+255)>>8)+dB; \
} while(0)


@@ -861,7 +861,7 @@ static void Blit32to565PixelAlphaAltivec(SDL_BlitInfo *info)
dR = (dstpixel >> 8) & 0xf8; \
dG = (dstpixel >> 3) & 0xfc; \
dB = (dstpixel << 3) & 0xf8; \
ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
*((unsigned short *)dst) = ( \
((dR & 0xf8) << 8) | ((dG & 0xfc) << 3) | (dB >> 3) \
); \
@@ -994,7 +994,7 @@ static void Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo *info)
if(sA && Pixel != ckey) { \
RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
} \
dstp++; \
@@ -1097,7 +1097,7 @@ static void Blit32to32PixelAlphaAltivec(SDL_BlitInfo *info)
DISEMBLE_RGBA((Uint8 *)srcp, 4, srcfmt, Pixel, sR, sG, sB, sA); \
if(sA) { \
DISEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, Pixel, dR, dG, dB, dA); \
ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ASSEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, dR, dG, dB, dA); \
} \
++srcp; \
@@ -1296,7 +1296,7 @@ static void Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo *info)
unsigned sR, sG, sB, dR, dG, dB; \
DISEMBLE_RGB(((Uint8 *)srcp), 4, srcfmt, Pixel, sR, sG, sB); \
DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
++srcp; \
++dstp; \

0 comments on commit fe8930b

Please sign in to comment.