# HG changeset patch # User Sam Lantinga # Date 1255160937 0 # Node ID 90aec03bf9fd8cd3b6f4f60304f612048cd3d28e # Parent 4e83cdb58134a0cb3e53eb40b686c6a9d1ae83e2 Fixed bug #627 Increased accuracy of alpha blend calculation diff -r 4e83cdb58134 -r 90aec03bf9fd src/video/SDL_blit.h --- a/src/video/SDL_blit.h Sat Oct 10 07:34:15 2009 +0000 +++ b/src/video/SDL_blit.h Sat Oct 10 07:48:57 2009 +0000 @@ -444,22 +444,9 @@ /* 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) diff -r 4e83cdb58134 -r 90aec03bf9fd src/video/SDL_blit_A.c --- a/src/video/SDL_blit_A.c Sat Oct 10 07:34:15 2009 +0000 +++ b/src/video/SDL_blit_A.c Sat Oct 10 07:48:57 2009 +0000 @@ -629,7 +629,7 @@ 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) \ ); \ @@ -775,7 +775,7 @@ 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++; \ @@ -882,7 +882,7 @@ 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; \ @@ -1082,7 +1082,7 @@ 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; \