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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 static inline unsigned Sk255To256(U8CPU value) { | 193 static inline unsigned Sk255To256(U8CPU value) { |
194 SkASSERT(SkToU8(value) == value); | 194 SkASSERT(SkToU8(value) == value); |
195 return value + (value >> 7); | 195 return value + (value >> 7); |
196 } | 196 } |
197 | 197 |
198 /** Multiplify value by 0..256, and shift the result down 8 | 198 /** Multiplify value by 0..256, and shift the result down 8 |
199 (i.e. return (value * alpha256) >> 8) | 199 (i.e. return (value * alpha256) >> 8) |
200 */ | 200 */ |
201 #define SkAlphaMul(value, alpha256) (((value) * (alpha256)) >> 8) | 201 #define SkAlphaMul(value, alpha256) (((value) * (alpha256)) >> 8) |
202 | 202 |
203 /** Inverted version of SkAlphaMul that properly subtracts off | |
204 * any fractional precision. | |
205 */ | |
206 #define SkAlphaMulInv256(value, alpha256) (((256<<8) - (value) * (alpha256)) >> 8) | |
mtklein
2016/07/26 19:29:43
Let's make this a static function and maybe try to
| |
207 | |
203 // The caller may want negative values, so keep all params signed (int) | 208 // The caller may want negative values, so keep all params signed (int) |
204 // so we don't accidentally slip into unsigned math and lose the sign | 209 // so we don't accidentally slip into unsigned math and lose the sign |
205 // extension when we shift (in SkAlphaMul) | 210 // extension when we shift (in SkAlphaMul) |
206 static inline int SkAlphaBlend(int src, int dst, int scale256) { | 211 static inline int SkAlphaBlend(int src, int dst, int scale256) { |
207 SkASSERT((unsigned)scale256 <= 256); | 212 SkASSERT((unsigned)scale256 <= 256); |
208 return dst + SkAlphaMul(src - dst, scale256); | 213 return dst + SkAlphaMul(src - dst, scale256); |
209 } | 214 } |
210 | 215 |
211 /** | 216 /** |
212 * Returns (src * alpha + dst * (255 - alpha)) / 255 | 217 * Returns (src * alpha + dst * (255 - alpha)) / 255 |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 } | 570 } |
566 | 571 |
567 static inline SkPMColor SkPMSrcOver(SkPMColor src, SkPMColor dst) { | 572 static inline SkPMColor SkPMSrcOver(SkPMColor src, SkPMColor dst) { |
568 return src + SkAlphaMulQ(dst, SkAlpha255To256(255 - SkGetPackedA32(src))); | 573 return src + SkAlphaMulQ(dst, SkAlpha255To256(255 - SkGetPackedA32(src))); |
569 } | 574 } |
570 | 575 |
571 static inline SkPMColor SkBlendARGB32(SkPMColor src, SkPMColor dst, U8CPU aa) { | 576 static inline SkPMColor SkBlendARGB32(SkPMColor src, SkPMColor dst, U8CPU aa) { |
572 SkASSERT((unsigned)aa <= 255); | 577 SkASSERT((unsigned)aa <= 255); |
573 | 578 |
574 unsigned src_scale = SkAlpha255To256(aa); | 579 unsigned src_scale = SkAlpha255To256(aa); |
575 unsigned dst_scale = SkAlpha255To256(255 - SkAlphaMul(SkGetPackedA32(src), s rc_scale)); | 580 unsigned dst_scale = SkAlphaMulInv256(SkGetPackedA32(src), src_scale); |
576 | 581 |
577 return SkAlphaMulQ(src, src_scale) + SkAlphaMulQ(dst, dst_scale); | 582 const uint32_t mask = 0xFF00FF; |
583 | |
584 uint32_t src_rb = (src & mask) * src_scale; | |
585 uint32_t src_ag = ((src >> 8) & mask) * src_scale; | |
586 | |
587 uint32_t dst_rb = (dst & mask) * dst_scale; | |
588 uint32_t dst_ag = ((dst >> 8) & mask) * dst_scale; | |
589 | |
590 return (((src_rb + dst_rb) >> 8) & mask) | ((src_ag + dst_ag) & ~mask); | |
578 } | 591 } |
579 | 592 |
580 //////////////////////////////////////////////////////////////////////////////// //////////// | 593 //////////////////////////////////////////////////////////////////////////////// //////////// |
581 // Convert a 32bit pixel to a 16bit pixel (no dither) | 594 // Convert a 32bit pixel to a 16bit pixel (no dither) |
582 | 595 |
583 #define SkR32ToR16_MACRO(r) ((unsigned)(r) >> (SK_R32_BITS - SK_R16_BITS)) | 596 #define SkR32ToR16_MACRO(r) ((unsigned)(r) >> (SK_R32_BITS - SK_R16_BITS)) |
584 #define SkG32ToG16_MACRO(g) ((unsigned)(g) >> (SK_G32_BITS - SK_G16_BITS)) | 597 #define SkG32ToG16_MACRO(g) ((unsigned)(g) >> (SK_G32_BITS - SK_G16_BITS)) |
585 #define SkB32ToB16_MACRO(b) ((unsigned)(b) >> (SK_B32_BITS - SK_B16_BITS)) | 598 #define SkB32ToB16_MACRO(b) ((unsigned)(b) >> (SK_B32_BITS - SK_B16_BITS)) |
586 | 599 |
587 #ifdef SK_DEBUG | 600 #ifdef SK_DEBUG |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1052 int srcG = SkColorGetG(src); | 1065 int srcG = SkColorGetG(src); |
1053 int srcB = SkColorGetB(src); | 1066 int srcB = SkColorGetB(src); |
1054 | 1067 |
1055 for (int i = 0; i < width; i++) { | 1068 for (int i = 0; i < width; i++) { |
1056 dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], mask[i], | 1069 dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], mask[i], |
1057 opaqueDst); | 1070 opaqueDst); |
1058 } | 1071 } |
1059 } | 1072 } |
1060 | 1073 |
1061 #endif | 1074 #endif |
OLD | NEW |