No subject


Wed Jan 24 21:54:03 PST 2007


/* 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)

For the case of blitting a white box sR,sG,sB=255 onto a black box
dR,dG,dB=0 and the source alpha is A=255 (fully opaque) we get a new
dR,dG,dB of 254 rather than 255 (as would be correct).

Correct would be to use the a /255 rather than the >>8 operation. This
is obviously done for speed reasons? 

Wouldn't it be better to precalculate the term (((sC-dC)*(A))/255) for
all (sC-dC) and (A)'s (adds a 128Kbyte lookup table) saving the bitshift
alltogether and gaining the added correctness of the /255 term.

Bye now
Andreas



More information about the SDL mailing list