comparison src/video/SDL_blit.h @ 3363:90aec03bf9fd

Fixed bug #627 Increased accuracy of alpha blend calculation
author Sam Lantinga <slouken@libsdl.org>
date Sat, 10 Oct 2009 07:48:57 +0000
parents 8d93bfecb9dc
children dc2911c207e4
comparison
equal deleted inserted replaced
3362:4e83cdb58134 3363:90aec03bf9fd
442 } 442 }
443 443
444 /* Blend the RGB values of two Pixels based on a source alpha value */ 444 /* Blend the RGB values of two Pixels based on a source alpha value */
445 #define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \ 445 #define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \
446 do { \ 446 do { \
447 dR = (((sR-dR)*(A))>>8)+dR; \ 447 dR = (((sR-dR)*(A)+255)>>8)+dR; \
448 dG = (((sG-dG)*(A))>>8)+dG; \ 448 dG = (((sG-dG)*(A)+255)>>8)+dG; \
449 dB = (((sB-dB)*(A))>>8)+dB; \ 449 dB = (((sB-dB)*(A)+255)>>8)+dB; \
450 } while(0)
451
452 /* Blend the RGB values of two Pixels based on a source alpha value */
453 #define ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB) \
454 do { \
455 unsigned tR, tG, tB, tA; \
456 tA = 255 - sA; \
457 tR = 1 + (sR * sA) + (dR * tA); \
458 dR = (tR + (tR >> 8)) >> 8; \
459 tG = 1 + (sG * sA) + (dG * tA); \
460 dG = (tG + (tG >> 8)) >> 8; \
461 tB = 1 + (sB * sA) + (dB * tA); \
462 dB = (tB + (tB >> 8)) >> 8; \
463 } while(0) 450 } while(0)
464 451
465 452
466 /* This is a very useful loop for optimizing blitters */ 453 /* This is a very useful loop for optimizing blitters */
467 #if defined(_MSC_VER) && (_MSC_VER == 1300) 454 #if defined(_MSC_VER) && (_MSC_VER == 1300)