diff options
author | pkasting <pkasting@chromium.org> | 2014-09-02 13:40:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-02 13:40:48 -0700 |
commit | 280c2c6fbbf953d83710d2229280075585a1ab59 (patch) | |
tree | 71c28de9ca9d0e5528346be7767fb76d77c0fdb8 /include/core/SkColorPriv.h | |
parent | 5ee785d9c7a39b9b8d3ae48b5da170dcef848e11 (diff) |
Address MSVC warnings about possible value truncation. In the process removes some apparently unused code.
BUG=81439
TEST=none
R=reed@google.com
Author: pkasting@chromium.org
Review URL: https://codereview.chromium.org/517763002
Diffstat (limited to 'include/core/SkColorPriv.h')
-rw-r--r-- | include/core/SkColorPriv.h | 41 |
1 files changed, 7 insertions, 34 deletions
diff --git a/include/core/SkColorPriv.h b/include/core/SkColorPriv.h index c8d71a5a8c..9db768783f 100644 --- a/include/core/SkColorPriv.h +++ b/include/core/SkColorPriv.h @@ -306,7 +306,8 @@ static inline void SkBlendRGB16(const uint16_t src[], uint16_t dst[], do { uint32_t src32 = SkExpand_rgb_16(*src++); uint32_t dst32 = SkExpand_rgb_16(*dst); - *dst++ = SkCompact_rgb_16(dst32 + ((src32 - dst32) * srcScale >> 5)); + *dst++ = static_cast<uint16_t>( + SkCompact_rgb_16(dst32 + ((src32 - dst32) * srcScale >> 5))); } while (--count > 0); } @@ -785,7 +786,7 @@ static inline SkPMColor16 SkPackARGB4444(unsigned a, unsigned r, (g << SK_G4444_SHIFT) | (b << SK_B4444_SHIFT)); } -static inline U16CPU SkAlphaMulQ4(U16CPU c, unsigned scale) { +static inline SkPMColor16 SkAlphaMulQ4(SkPMColor16 c, int scale) { SkASSERT(scale <= 16); const unsigned mask = 0xF0F; //gMask_0F0F; @@ -795,14 +796,14 @@ static inline U16CPU SkAlphaMulQ4(U16CPU c, unsigned scale) { unsigned ag = ((c >> 4) & mask) * scale; return (rb & mask) | (ag & ~mask); #else - c = (c & mask) | ((c & (mask << 4)) << 12); - c = c * scale >> 4; - return (c & mask) | ((c >> 12) & (mask << 4)); + unsigned expanded_c = (c & mask) | ((c & (mask << 4)) << 12); + unsigned scaled_c = (expanded_c * scale) >> 4; + return (scaled_c & mask) | ((scaled_c >> 12) & (mask << 4)); #endif } /** Expand the SkPMColor16 color into a 32bit value that can be scaled all at - once by a value up to 16. Used in conjunction with SkCompact_4444. + once by a value up to 16. */ static inline uint32_t SkExpand_4444(U16CPU c) { SkASSERT(c == (uint16_t)c); @@ -811,18 +812,6 @@ static inline uint32_t SkExpand_4444(U16CPU c) { return (c & mask) | ((c & ~mask) << 12); } -/** Compress an expanded value (from SkExpand_4444) back down to a SkPMColor16. - NOTE: this explicitly does not clean the top 16 bits (which may be garbage). - It does this for speed, since if it is being written directly to 16bits of - memory, the top 16bits will be ignored. Casting the result to uint16_t here - would add 2 more instructions, slow us down. It is up to the caller to - perform the cast if needed. -*/ -static inline U16CPU SkCompact_4444(uint32_t c) { - const unsigned mask = 0xF0F; //gMask_0F0F; - return (c & mask) | ((c >> 12) & ~mask); -} - static inline uint16_t SkSrcOver4444To16(SkPMColor16 s, uint16_t d) { unsigned sa = SkGetPackedA4444(s); unsigned sr = SkR4444ToR565(SkGetPackedR4444(s)); @@ -854,22 +843,6 @@ static inline uint16_t SkBlend4444To16(SkPMColor16 src, uint16_t dst, int scale1 return SkSrcOver4444To16(SkAlphaMulQ4(src, scale16), dst); } -static inline uint16_t SkBlend4444(SkPMColor16 src, SkPMColor16 dst, int scale16) { - SkASSERT((unsigned)scale16 <= 16); - - uint32_t src32 = SkExpand_4444(src) * scale16; - // the scaled srcAlpha is the bottom byte -#ifdef SK_DEBUG - { - unsigned srcA = SkGetPackedA4444(src) * scale16; - SkASSERT(srcA == (src32 & 0xFF)); - } -#endif - unsigned dstScale = SkAlpha255To256(255 - (src32 & 0xFF)) >> 4; - uint32_t dst32 = SkExpand_4444(dst) * dstScale; - return SkCompact_4444((src32 + dst32) >> 4); -} - static inline SkPMColor SkPixel4444ToPixel32(U16CPU c) { uint32_t d = (SkGetPackedA4444(c) << SK_A32_SHIFT) | (SkGetPackedR4444(c) << SK_R32_SHIFT) | |