diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-10-06 20:04:36 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-10-06 20:04:36 +0000 |
commit | 0abb499dafb2550ad81afe11ffede5cab4904575 (patch) | |
tree | e052346b9735e24aab333a7be3a2db8621110798 /include/core | |
parent | 01744a46e8cf0419f9e85ac148fe2bed2120e51f (diff) |
add SkAlphaBlend255
git-svn-id: http://skia.googlecode.com/svn/trunk@2426 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkColorPriv.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/include/core/SkColorPriv.h b/include/core/SkColorPriv.h index 5b307c10d1..714e845af0 100644 --- a/include/core/SkColorPriv.h +++ b/include/core/SkColorPriv.h @@ -44,6 +44,21 @@ static inline int SkAlphaBlend(int src, int dst, int scale256) { return dst + SkAlphaMul(src - dst, scale256); } +/** + * Returns (src * alpha + dst * (255 - alpha)) / 255 + * + * This is more accurate than SkAlphaBlend, but slightly slower + */ +static inline int SkAlphaBlend255(S16CPU src, S16CPU dst, U8CPU alpha) { + SkASSERT((int16_t)src == src); + SkASSERT((int16_t)dst == dst); + SkASSERT((uint8_t)alpha == alpha); + + int prod = SkMulS16(src - dst, alpha) + 128; + prod = (prod + (prod >> 8)) >> 8; + return dst + prod; +} + #define SK_R16_BITS 5 #define SK_G16_BITS 6 #define SK_B16_BITS 5 |