diff options
author | 2009-03-03 20:31:12 +0000 | |
---|---|---|
committer | 2009-03-03 20:31:12 +0000 | |
commit | 1116fb25e582a18db0f87890364fac72ccfe09ce (patch) | |
tree | 5fa6abc571cccd1116d9d19d9fbd884dfb70b82f /src/core | |
parent | d66efc273e4996fb18f343bd30dcd506a1698b5b (diff) |
change srcover (and dstover) to use the faster thought slightly less accurate
computation of the scale factor (+1 instead of SkAlpha255To256). This has the
upside of guaranteeing that if the dst is opaque (alpha==255), it will always
stay opaque.
git-svn-id: http://skia.googlecode.com/svn/trunk@104 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkXfermode.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp index 80bafcedc7..7c336c285a 100644 --- a/src/core/SkXfermode.cpp +++ b/src/core/SkXfermode.cpp @@ -344,21 +344,24 @@ static SkPMColor dst_modeproc(SkPMColor src, SkPMColor dst) { return dst; } -// kSrcOver_Mode, //!< [Sa + (1 - Sa)*Da, Sc + (1 - Sa)*Dc] +// kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Sc + (1 - Sa)*Dc] static SkPMColor srcover_modeproc(SkPMColor src, SkPMColor dst) { +#if 0 + // this is the old, more-correct way, but it doesn't guarantee that dst==255 + // will always stay opaque return src + SkAlphaMulQ(dst, SkAlpha255To256(255 - SkGetPackedA32(src))); +#else + // this is slightly faster, but more importantly guarantees that dst==255 + // will always stay opaque + return src + SkAlphaMulQ(dst, 256 - SkGetPackedA32(src)); +#endif } -// kDstOver_Mode, //!< [Sa + (1 - Sa)*Da, Dc + (1 - Da)*Sc] +// kDstOver_Mode, //!< [Sa + Da - Sa*Da, Dc + (1 - Da)*Sc] static SkPMColor dstover_modeproc(SkPMColor src, SkPMColor dst) { - unsigned sa = SkGetPackedA32(src); - unsigned da = SkGetPackedA32(dst); - unsigned ida = 255 - da; - - return SkPackARGB32(sa + da - SkAlphaMulAlpha(sa, da), - SkGetPackedR32(dst) + SkAlphaMulAlpha(ida, SkGetPackedR32(src)), - SkGetPackedG32(dst) + SkAlphaMulAlpha(ida, SkGetPackedG32(src)), - SkGetPackedB32(dst) + SkAlphaMulAlpha(ida, SkGetPackedB32(src))); + // this is the reverse of srcover, just flipping src and dst + // see srcover's comment about the 256 for opaqueness guarantees + return dst + SkAlphaMulQ(src, 256 - SkGetPackedA32(dst)); } // kSrcIn_Mode, //!< [Sa * Da, Sc * Da] |