Mercurial > sdl-ios-xcode
changeset 4293:63b54ddd38ea SDL-1.2
Fixed bug #627
Increased accuracy of alpha blend calculation
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 10 Oct 2009 07:48:15 +0000 |
parents | 464126f4c7db |
children | 5b31c369820b |
files | src/video/SDL_blit.h src/video/SDL_blit_A.c |
diffstat | 2 files changed, 7 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/SDL_blit.h Sat Oct 10 07:33:18 2009 +0000 +++ b/src/video/SDL_blit.h Sat Oct 10 07:48:15 2009 +0000 @@ -384,22 +384,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)
--- a/src/video/SDL_blit_A.c Sat Oct 10 07:33:18 2009 +0000 +++ b/src/video/SDL_blit_A.c Sat Oct 10 07:48:15 2009 +0000 @@ -861,7 +861,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) \ ); \ @@ -994,7 +994,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++; \ @@ -1097,7 +1097,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; \ @@ -1296,7 +1296,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; \