| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkColorPriv_DEFINED | 8 #ifndef SkColorPriv_DEFINED |
| 9 #define SkColorPriv_DEFINED | 9 #define SkColorPriv_DEFINED |
| 10 | 10 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 * This is slightly more accurate than SkAlpha255To256. | 186 * This is slightly more accurate than SkAlpha255To256. |
| 187 */ | 187 */ |
| 188 static inline unsigned Sk255To256(U8CPU value) { | 188 static inline unsigned Sk255To256(U8CPU value) { |
| 189 SkASSERT(SkToU8(value) == value); | 189 SkASSERT(SkToU8(value) == value); |
| 190 return value + (value >> 7); | 190 return value + (value >> 7); |
| 191 } | 191 } |
| 192 | 192 |
| 193 /** Multiplify value by 0..256, and shift the result down 8 | 193 /** Multiplify value by 0..256, and shift the result down 8 |
| 194 (i.e. return (value * alpha256) >> 8) | 194 (i.e. return (value * alpha256) >> 8) |
| 195 */ | 195 */ |
| 196 #define SkAlphaMul(value, alpha256) (SkMulS16(value, alpha256) >> 8) | 196 #define SkAlphaMul(value, alpha256) (((value) * (alpha256)) >> 8) |
| 197 | 197 |
| 198 // The caller may want negative values, so keep all params signed (int) | 198 // The caller may want negative values, so keep all params signed (int) |
| 199 // so we don't accidentally slip into unsigned math and lose the sign | 199 // so we don't accidentally slip into unsigned math and lose the sign |
| 200 // extension when we shift (in SkAlphaMul) | 200 // extension when we shift (in SkAlphaMul) |
| 201 static inline int SkAlphaBlend(int src, int dst, int scale256) { | 201 static inline int SkAlphaBlend(int src, int dst, int scale256) { |
| 202 SkASSERT((unsigned)scale256 <= 256); | 202 SkASSERT((unsigned)scale256 <= 256); |
| 203 return dst + SkAlphaMul(src - dst, scale256); | 203 return dst + SkAlphaMul(src - dst, scale256); |
| 204 } | 204 } |
| 205 | 205 |
| 206 /** | 206 /** |
| 207 * Returns (src * alpha + dst * (255 - alpha)) / 255 | 207 * Returns (src * alpha + dst * (255 - alpha)) / 255 |
| 208 * | 208 * |
| 209 * This is more accurate than SkAlphaBlend, but slightly slower | 209 * This is more accurate than SkAlphaBlend, but slightly slower |
| 210 */ | 210 */ |
| 211 static inline int SkAlphaBlend255(S16CPU src, S16CPU dst, U8CPU alpha) { | 211 static inline int SkAlphaBlend255(S16CPU src, S16CPU dst, U8CPU alpha) { |
| 212 SkASSERT((int16_t)src == src); | 212 SkASSERT((int16_t)src == src); |
| 213 SkASSERT((int16_t)dst == dst); | 213 SkASSERT((int16_t)dst == dst); |
| 214 SkASSERT((uint8_t)alpha == alpha); | 214 SkASSERT((uint8_t)alpha == alpha); |
| 215 | 215 |
| 216 int prod = SkMulS16(src - dst, alpha) + 128; | 216 int prod = (src - dst) * alpha + 128; |
| 217 prod = (prod + (prod >> 8)) >> 8; | 217 prod = (prod + (prod >> 8)) >> 8; |
| 218 return dst + prod; | 218 return dst + prod; |
| 219 } | 219 } |
| 220 | 220 |
| 221 #define SK_R16_BITS 5 | 221 #define SK_R16_BITS 5 |
| 222 #define SK_G16_BITS 6 | 222 #define SK_G16_BITS 6 |
| 223 #define SK_B16_BITS 5 | 223 #define SK_B16_BITS 5 |
| 224 | 224 |
| 225 #define SK_R16_SHIFT (SK_B16_BITS + SK_G16_BITS) | 225 #define SK_R16_SHIFT (SK_B16_BITS + SK_G16_BITS) |
| 226 #define SK_G16_SHIFT (SK_B16_BITS) | 226 #define SK_G16_SHIFT (SK_B16_BITS) |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 int srcG = SkColorGetG(src); | 1043 int srcG = SkColorGetG(src); |
| 1044 int srcB = SkColorGetB(src); | 1044 int srcB = SkColorGetB(src); |
| 1045 | 1045 |
| 1046 for (int i = 0; i < width; i++) { | 1046 for (int i = 0; i < width; i++) { |
| 1047 dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], mask[i], | 1047 dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], mask[i], |
| 1048 opaqueDst); | 1048 opaqueDst); |
| 1049 } | 1049 } |
| 1050 } | 1050 } |
| 1051 | 1051 |
| 1052 #endif | 1052 #endif |
| OLD | NEW |