OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 | 10 |
11 #ifndef GrColor_DEFINED | 11 #ifndef GrColor_DEFINED |
12 #define GrColor_DEFINED | 12 #define GrColor_DEFINED |
13 | 13 |
14 #include "GrTypes.h" | 14 #include "GrTypes.h" |
| 15 #include "SkColor.h" |
| 16 #include "SkColorPriv.h" |
| 17 #include "SkUnPreMultiply.h" |
15 | 18 |
16 /** | 19 /** |
17 * GrColor is 4 bytes for R, G, B, A, in a specific order defined below. The com
ponents are stored | 20 * GrColor is 4 bytes for R, G, B, A, in a specific order defined below. The com
ponents are stored |
18 * premultiplied. | 21 * premultiplied. |
19 */ | 22 */ |
20 typedef uint32_t GrColor; | 23 typedef uint32_t GrColor; |
21 | 24 |
22 // shift amount to assign a component to a GrColor int | 25 // shift amount to assign a component to a GrColor int |
23 // These shift values are chosen for compatibility with GL attrib arrays | 26 // These shift values are chosen for compatibility with GL attrib arrays |
24 // ES doesn't allow BGRA vertex attrib order so if they were not in this order | 27 // ES doesn't allow BGRA vertex attrib order so if they were not in this order |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 static inline float GrNormalizeByteToFloat(uint8_t value) { | 95 static inline float GrNormalizeByteToFloat(uint8_t value) { |
93 static const float ONE_OVER_255 = 1.f / 255.f; | 96 static const float ONE_OVER_255 = 1.f / 255.f; |
94 return value * ONE_OVER_255; | 97 return value * ONE_OVER_255; |
95 } | 98 } |
96 | 99 |
97 /** Determines whether the color is opaque or not. */ | 100 /** Determines whether the color is opaque or not. */ |
98 static inline bool GrColorIsOpaque(GrColor color) { | 101 static inline bool GrColorIsOpaque(GrColor color) { |
99 return (color & (0xFFU << GrColor_SHIFT_A)) == (0xFFU << GrColor_SHIFT_A); | 102 return (color & (0xFFU << GrColor_SHIFT_A)) == (0xFFU << GrColor_SHIFT_A); |
100 } | 103 } |
101 | 104 |
| 105 /** Returns an unpremuled version of the GrColor. */ |
| 106 static inline GrColor GrUnPreMulColor(GrColor color) { |
| 107 unsigned r = GrColorUnpackR(color); |
| 108 unsigned g = GrColorUnpackG(color); |
| 109 unsigned b = GrColorUnpackB(color); |
| 110 unsigned a = GrColorUnpackA(color); |
| 111 SkPMColor colorPM = SkPackARGB32(a, r, g, b); |
| 112 SkColor colorUPM = SkUnPreMultiply::PMColorToColor(colorPM); |
| 113 |
| 114 r = SkGetPackedR32(colorUPM); |
| 115 g = SkGetPackedG32(colorUPM); |
| 116 b = SkGetPackedB32(colorUPM); |
| 117 a = SkGetPackedA32(colorUPM); |
| 118 |
| 119 return GrColorPackRGBA(r, g, b, a); |
| 120 } |
| 121 |
102 /** | 122 /** |
103 * Flags used for bitfields of color components. They are defined so that the bi
t order reflects the | 123 * Flags used for bitfields of color components. They are defined so that the bi
t order reflects the |
104 * GrColor shift order. | 124 * GrColor shift order. |
105 */ | 125 */ |
106 enum GrColorComponentFlags { | 126 enum GrColorComponentFlags { |
107 kR_GrColorComponentFlag = 1 << (GrColor_SHIFT_R / 8), | 127 kR_GrColorComponentFlag = 1 << (GrColor_SHIFT_R / 8), |
108 kG_GrColorComponentFlag = 1 << (GrColor_SHIFT_G / 8), | 128 kG_GrColorComponentFlag = 1 << (GrColor_SHIFT_G / 8), |
109 kB_GrColorComponentFlag = 1 << (GrColor_SHIFT_B / 8), | 129 kB_GrColorComponentFlag = 1 << (GrColor_SHIFT_B / 8), |
110 kA_GrColorComponentFlag = 1 << (GrColor_SHIFT_A / 8), | 130 kA_GrColorComponentFlag = 1 << (GrColor_SHIFT_A / 8), |
111 | 131 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); | 180 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); |
161 GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig); | 181 GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig); |
162 GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig); | 182 GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig); |
163 GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig); | 183 GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig); |
164 GR_STATIC_ASSERT(10 == kASTC_12x12_GrPixelConfig); | 184 GR_STATIC_ASSERT(10 == kASTC_12x12_GrPixelConfig); |
165 GR_STATIC_ASSERT(11 == kRGBA_float_GrPixelConfig); | 185 GR_STATIC_ASSERT(11 == kRGBA_float_GrPixelConfig); |
166 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt); | 186 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt); |
167 } | 187 } |
168 | 188 |
169 #endif | 189 #endif |
OLD | NEW |