diff options
author | 2013-05-21 21:33:11 +0000 | |
---|---|---|
committer | 2013-05-21 21:33:11 +0000 | |
commit | b83cb9bf89d26b40e4db83db1b9782437d2adba7 (patch) | |
tree | d0d017c33983d9485c301c544f79c357d939b12e /include/core/SkColorPriv.h | |
parent | edef4aa8d84f9d0cfa49e9b7c761bb986af63142 (diff) |
add SkLerpXfermode
BUG=
R=bsalomon@google.com
Review URL: https://codereview.chromium.org/15602003
git-svn-id: http://skia.googlecode.com/svn/trunk@9229 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkColorPriv.h')
-rw-r--r-- | include/core/SkColorPriv.h | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/include/core/SkColorPriv.h b/include/core/SkColorPriv.h index 46f7d27184..5d2df62cef 100644 --- a/include/core/SkColorPriv.h +++ b/include/core/SkColorPriv.h @@ -273,16 +273,16 @@ static inline SkPMColor SkFourByteInterp(SkPMColor src, SkPMColor dst, * architectures than an equivalent 64b version and 30% faster than * SkFourByteInterp(). Third parameter controls blending of the first two: * (src, dst, 0) returns dst - * (src, dst, 0xFF) returns src - * ** Does not match the results of SkFourByteInterp() because we use + * (src, dst, 256) returns src + * ** Does not match the results of SkFourByteInterp256() because we use * a more accurate scale computation! * TODO: migrate Skia function to using an accurate 255->266 alpha * conversion. */ -static inline SkPMColor SkFastFourByteInterp(SkPMColor src, - SkPMColor dst, - U8CPU srcWeight) { - SkASSERT(srcWeight < 256); +static inline SkPMColor SkFastFourByteInterp256(SkPMColor src, + SkPMColor dst, + unsigned scale) { + SkASSERT(scale <= 256); // Reorders ARGB to AG-RB in order to reduce the number of operations. const uint32_t mask = 0xFF00FF; @@ -291,16 +291,21 @@ static inline SkPMColor SkFastFourByteInterp(SkPMColor src, uint32_t dst_rb = dst & mask; uint32_t dst_ag = (dst >> 8) & mask; - // scale = srcWeight + (srcWeight >> 7) is more accurate than - // scale = srcWeight + 1, but 7% slower - int scale = srcWeight + (srcWeight >> 7); - uint32_t ret_rb = src_rb * scale + (256 - scale) * dst_rb; uint32_t ret_ag = src_ag * scale + (256 - scale) * dst_ag; return (ret_ag & ~mask) | ((ret_rb & ~mask) >> 8); } +static inline SkPMColor SkFastFourByteInterp(SkPMColor src, + SkPMColor dst, + U8CPU srcWeight) { + SkASSERT(srcWeight <= 255); + // scale = srcWeight + (srcWeight >> 7) is more accurate than + // scale = srcWeight + 1, but 7% slower + return SkFastFourByteInterp256(src, dst, srcWeight + (srcWeight >> 7)); +} + /** * Same as SkPackARGB32, but this version guarantees to not check that the * values are premultiplied in the debug version. |