Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed bug #627
Browse files Browse the repository at this point in the history
Increased accuracy of alpha blend calculation
  • Loading branch information
slouken committed Oct 10, 2009
1 parent c2530cb commit 4c2bc75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
19 changes: 3 additions & 16 deletions src/video/SDL_blit.h
Expand Up @@ -444,22 +444,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)


Expand Down
8 changes: 4 additions & 4 deletions src/video/SDL_blit_A.c
Expand Up @@ -629,7 +629,7 @@ 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) \
); \
Expand Down Expand Up @@ -775,7 +775,7 @@ 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++; \
Expand Down Expand Up @@ -882,7 +882,7 @@ 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; \
Expand Down Expand Up @@ -1082,7 +1082,7 @@ 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; \
Expand Down

0 comments on commit 4c2bc75

Please sign in to comment.