OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | |
10 #ifndef SkColorPriv_DEFINED | 8 #ifndef SkColorPriv_DEFINED |
11 #define SkColorPriv_DEFINED | 9 #define SkColorPriv_DEFINED |
12 | 10 |
13 // turn this own for extra debug checking when blending onto 565 | 11 // turn this own for extra debug checking when blending onto 565 |
14 #ifdef SK_DEBUG | 12 #ifdef SK_DEBUG |
15 #define CHECK_FOR_565_OVERFLOW | 13 #define CHECK_FOR_565_OVERFLOW |
16 #endif | 14 #endif |
17 | 15 |
18 #include "SkColor.h" | 16 #include "SkColor.h" |
19 #include "SkMath.h" | 17 #include "SkMath.h" |
20 | 18 |
| 19 ////////////////////////////////////////////////////////////////////////////// |
| 20 |
| 21 #define SkASSERT_IS_BYTE(x) SkASSERT(0 == ((x) & ~0xFF)) |
| 22 |
| 23 /* |
| 24 * Skia's 32bit backend only supports 1 sizzle order at a time (compile-time). |
| 25 * This is specified by 4 defines SK_A32_SHIFT, SK_R32_SHIFT, ... for G and B. |
| 26 * |
| 27 * For easier compatibility with Skia's GPU backend, we further restrict these |
| 28 * to either (in memory-byte-order) RGBA or BGRA. Note that this "order" does |
| 29 * not directly correspond to the same shift-order, since we have to take endia
ness |
| 30 * into account. |
| 31 * |
| 32 * Here we enforce this constraint. |
| 33 */ |
| 34 |
| 35 #ifdef SK_CPU_BENDIAN |
| 36 #define SK_RGBA_R32_SHIFT 24 |
| 37 #define SK_RGBA_G32_SHIFT 16 |
| 38 #define SK_RGBA_B32_SHIFT 8 |
| 39 #define SK_RGBA_A32_SHIFT 0 |
| 40 |
| 41 #define SK_BGRA_B32_SHIFT 24 |
| 42 #define SK_BGRA_G32_SHIFT 16 |
| 43 #define SK_BGRA_R32_SHIFT 8 |
| 44 #define SK_BGRA_A32_SHIFT 0 |
| 45 #else |
| 46 #define SK_RGBA_R32_SHIFT 0 |
| 47 #define SK_RGBA_G32_SHIFT 8 |
| 48 #define SK_RGBA_B32_SHIFT 16 |
| 49 #define SK_RGBA_A32_SHIFT 24 |
| 50 |
| 51 #define SK_BGRA_B32_SHIFT 0 |
| 52 #define SK_BGRA_G32_SHIFT 8 |
| 53 #define SK_BGRA_R32_SHIFT 16 |
| 54 #define SK_BGRA_A32_SHIFT 24 |
| 55 #endif |
| 56 |
| 57 #if defined(SK_PMCOLOR_IS_RGBA) && defined(SK_PMCOLOR_IS_BGRA) |
| 58 #error "can't define PMCOLOR to be RGBA and BGRA" |
| 59 #endif |
| 60 |
| 61 #define LOCAL_PMCOLOR_SHIFTS_EQUIVALENT_TO_RGBA \ |
| 62 (SK_A32_SHIFT == SK_RGBA_A32_SHIFT && \ |
| 63 SK_R32_SHIFT == SK_RGBA_R32_SHIFT && \ |
| 64 SK_G32_SHIFT == SK_RGBA_G32_SHIFT && \ |
| 65 SK_B32_SHIFT == SK_RGBA_B32_SHIFT) |
| 66 |
| 67 #define LOCAL_PMCOLOR_SHIFTS_EQUIVALENT_TO_BGRA \ |
| 68 (SK_A32_SHIFT == SK_BGRA_A32_SHIFT && \ |
| 69 SK_R32_SHIFT == SK_BGRA_R32_SHIFT && \ |
| 70 SK_G32_SHIFT == SK_BGRA_G32_SHIFT && \ |
| 71 SK_B32_SHIFT == SK_BGRA_B32_SHIFT) |
| 72 |
| 73 |
| 74 #if defined(SK_PMCOLOR_IS_RGBA) && !LOCAL_PMCOLOR_SHIFTS_EQUIVALENT_TO_RGBA |
| 75 #error "SK_PMCOLOR_IS_RGBA does not match SK_*32_SHIFT values" |
| 76 #endif |
| 77 |
| 78 #if defined(SK_PMCOLOR_IS_BGRA) && !LOCAL_PMCOLOR_SHIFTS_EQUIVALENT_TO_BGRA |
| 79 #error "SK_PMCOLOR_IS_BGRA does not match SK_*32_SHIFT values" |
| 80 #endif |
| 81 |
| 82 #if !defined(SK_PMCOLOR_IS_RGBA) && !defined(SK_PMCOLOR_IS_RGBA) |
| 83 // deduce which to define from the _SHIFT defines |
| 84 |
| 85 #if LOCAL_PMCOLOR_SHIFTS_EQUIVALENT_TO_RGBA |
| 86 #define SK_PMCOLOR_IS_RGBA |
| 87 #elif LOCAL_PMCOLOR_SHIFTS_EQUIVALENT_TO_BGRA |
| 88 #define SK_PMCOLOR_IS_BGRA |
| 89 #else |
| 90 #error "need 32bit packing to be either RGBA or BGRA" |
| 91 #endif |
| 92 #endif |
| 93 |
| 94 // hide these now that we're done |
| 95 #undef LOCAL_PMCOLOR_SHIFTS_EQUIVALENT_TO_RGBA |
| 96 #undef LOCAL_PMCOLOR_SHIFTS_EQUIVALENT_TO_BGRA |
| 97 |
| 98 ////////////////////////////////////////////////////////////////////////////// |
| 99 |
| 100 // Reverse the bytes coorsponding to RED and BLUE in a packed pixels. Note the |
| 101 // pair of them are in the same 2 slots in both RGBA and BGRA, thus there is |
| 102 // no need to pass in the colortype to this function. |
| 103 static inline uint32_t SkSwizzle_RB(uint32_t c) { |
| 104 static const uint32_t kRBMask = (0xFF << SK_R32_SHIFT) | (0xFF << SK_B32_SHI
FT); |
| 105 |
| 106 unsigned c0 = (c >> SK_R32_SHIFT) & 0xFF; |
| 107 unsigned c1 = (c >> SK_B32_SHIFT) & 0xFF; |
| 108 return (c & ~kRBMask) | (c0 << SK_B32_SHIFT) | (c1 << SK_R32_SHIFT); |
| 109 } |
| 110 |
| 111 static inline uint32_t SkPackARGB_as_RGBA(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
| 112 SkASSERT_IS_BYTE(a); |
| 113 SkASSERT_IS_BYTE(r); |
| 114 SkASSERT_IS_BYTE(g); |
| 115 SkASSERT_IS_BYTE(b); |
| 116 return (a << SK_RGBA_A32_SHIFT) | (r << SK_RGBA_R32_SHIFT) | |
| 117 (g << SK_RGBA_G32_SHIFT) | (b << SK_RGBA_B32_SHIFT); |
| 118 } |
| 119 |
| 120 static inline uint32_t SkPackARGB_as_BGRA(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
| 121 SkASSERT_IS_BYTE(a); |
| 122 SkASSERT_IS_BYTE(r); |
| 123 SkASSERT_IS_BYTE(g); |
| 124 SkASSERT_IS_BYTE(b); |
| 125 return (a << SK_BGRA_A32_SHIFT) | (r << SK_BGRA_R32_SHIFT) | |
| 126 (g << SK_BGRA_G32_SHIFT) | (b << SK_BGRA_B32_SHIFT); |
| 127 } |
| 128 |
| 129 static inline SkPMColor SkSwizzle_RGBA_to_PMColor(uint32_t c) { |
| 130 #ifdef SK_PMCOLOR_IS_RGBA |
| 131 return c; |
| 132 #else |
| 133 return SkSwizzle_RB(c); |
| 134 #endif |
| 135 } |
| 136 |
| 137 static inline SkPMColor SkSwizzle_BGRA_to_PMColor(uint32_t c) { |
| 138 #ifdef SK_PMCOLOR_IS_BGRA |
| 139 return c; |
| 140 #else |
| 141 return SkSwizzle_RB(c); |
| 142 #endif |
| 143 } |
| 144 |
| 145 ////////////////////////////////////////////////////////////////////////////// |
| 146 |
21 ///@{ | 147 ///@{ |
22 /** See ITU-R Recommendation BT.709 at http://www.itu.int/rec/R-REC-BT.709/ .*/ | 148 /** See ITU-R Recommendation BT.709 at http://www.itu.int/rec/R-REC-BT.709/ .*/ |
23 #define SK_ITU_BT709_LUM_COEFF_R (0.2126f) | 149 #define SK_ITU_BT709_LUM_COEFF_R (0.2126f) |
24 #define SK_ITU_BT709_LUM_COEFF_G (0.7152f) | 150 #define SK_ITU_BT709_LUM_COEFF_G (0.7152f) |
25 #define SK_ITU_BT709_LUM_COEFF_B (0.0722f) | 151 #define SK_ITU_BT709_LUM_COEFF_B (0.0722f) |
26 ///@} | 152 ///@} |
27 | 153 |
28 ///@{ | 154 ///@{ |
29 /** A float value which specifies this channel's contribution to luminance. */ | 155 /** A float value which specifies this channel's contribution to luminance. */ |
30 #define SK_LUM_COEFF_R SK_ITU_BT709_LUM_COEFF_R | 156 #define SK_LUM_COEFF_R SK_ITU_BT709_LUM_COEFF_R |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 static inline SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { | 358 static inline SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
233 SkA32Assert(a); | 359 SkA32Assert(a); |
234 SkASSERT(r <= a); | 360 SkASSERT(r <= a); |
235 SkASSERT(g <= a); | 361 SkASSERT(g <= a); |
236 SkASSERT(b <= a); | 362 SkASSERT(b <= a); |
237 | 363 |
238 return (a << SK_A32_SHIFT) | (r << SK_R32_SHIFT) | | 364 return (a << SK_A32_SHIFT) | (r << SK_R32_SHIFT) | |
239 (g << SK_G32_SHIFT) | (b << SK_B32_SHIFT); | 365 (g << SK_G32_SHIFT) | (b << SK_B32_SHIFT); |
240 } | 366 } |
241 | 367 |
| 368 static inline uint32_t SkPackPMColor_as_RGBA(SkPMColor c) { |
| 369 return SkPackARGB_as_RGBA(SkGetPackedA32(c), SkGetPackedR32(c), |
| 370 SkGetPackedG32(c), SkGetPackedB32(c)); |
| 371 } |
| 372 |
| 373 static inline uint32_t SkPackPMColor_as_BGRA(SkPMColor c) { |
| 374 return SkPackARGB_as_BGRA(SkGetPackedA32(c), SkGetPackedR32(c), |
| 375 SkGetPackedG32(c), SkGetPackedB32(c)); |
| 376 } |
| 377 |
242 /** | 378 /** |
243 * Abstract 4-byte interpolation, implemented on top of SkPMColor | 379 * Abstract 4-byte interpolation, implemented on top of SkPMColor |
244 * utility functions. Third parameter controls blending of the first two: | 380 * utility functions. Third parameter controls blending of the first two: |
245 * (src, dst, 0) returns dst | 381 * (src, dst, 0) returns dst |
246 * (src, dst, 0xFF) returns src | 382 * (src, dst, 0xFF) returns src |
247 * srcWeight is [0..256], unlike SkFourByteInterp which takes [0..255] | 383 * srcWeight is [0..256], unlike SkFourByteInterp which takes [0..255] |
248 */ | 384 */ |
249 static inline SkPMColor SkFourByteInterp256(SkPMColor src, SkPMColor dst, | 385 static inline SkPMColor SkFourByteInterp256(SkPMColor src, SkPMColor dst, |
250 unsigned scale) { | 386 unsigned scale) { |
251 unsigned a = SkAlphaBlend(SkGetPackedA32(src), SkGetPackedA32(dst), scale); | 387 unsigned a = SkAlphaBlend(SkGetPackedA32(src), SkGetPackedA32(dst), scale); |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 int srcG = SkColorGetG(src); | 1043 int srcG = SkColorGetG(src); |
908 int srcB = SkColorGetB(src); | 1044 int srcB = SkColorGetB(src); |
909 | 1045 |
910 for (int i = 0; i < width; i++) { | 1046 for (int i = 0; i < width; i++) { |
911 dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], mask[i], | 1047 dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], mask[i], |
912 opaqueDst); | 1048 opaqueDst); |
913 } | 1049 } |
914 } | 1050 } |
915 | 1051 |
916 #endif | 1052 #endif |
OLD | NEW |