| 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 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 #define GrColorUnpackB(color) (((color) >> GrColor_SHIFT_B) & 0xFF) | 70 #define GrColorUnpackB(color) (((color) >> GrColor_SHIFT_B) & 0xFF) |
| 71 #define GrColorUnpackA(color) (((color) >> GrColor_SHIFT_A) & 0xFF) | 71 #define GrColorUnpackA(color) (((color) >> GrColor_SHIFT_A) & 0xFF) |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Since premultiplied means that alpha >= color, we construct a color with | 74 * Since premultiplied means that alpha >= color, we construct a color with |
| 75 * each component==255 and alpha == 0 to be "illegal" | 75 * each component==255 and alpha == 0 to be "illegal" |
| 76 */ | 76 */ |
| 77 #define GrColor_ILLEGAL (~(0xFF << GrColor_SHIFT_A)) | 77 #define GrColor_ILLEGAL (~(0xFF << GrColor_SHIFT_A)) |
| 78 | 78 |
| 79 #define GrColor_WHITE 0xFFFFFFFF | 79 #define GrColor_WHITE 0xFFFFFFFF |
| 80 #define GrColor_TRANS_BLACK 0x0 | 80 #define GrColor_TRANSPARENT_BLACK 0x0 |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * Assert in debug builds that a GrColor is premultiplied. | 83 * Assert in debug builds that a GrColor is premultiplied. |
| 84 */ | 84 */ |
| 85 static inline void GrColorIsPMAssert(GrColor SkDEBUGCODE(c)) { | 85 static inline void GrColorIsPMAssert(GrColor SkDEBUGCODE(c)) { |
| 86 #ifdef SK_DEBUG | 86 #ifdef SK_DEBUG |
| 87 unsigned a = GrColorUnpackA(c); | 87 unsigned a = GrColorUnpackA(c); |
| 88 unsigned r = GrColorUnpackR(c); | 88 unsigned r = GrColorUnpackR(c); |
| 89 unsigned g = GrColorUnpackG(c); | 89 unsigned g = GrColorUnpackG(c); |
| 90 unsigned b = GrColorUnpackB(c); | 90 unsigned b = GrColorUnpackB(c); |
| 91 | 91 |
| 92 SkASSERT(r <= a); | 92 SkASSERT(r <= a); |
| 93 SkASSERT(g <= a); | 93 SkASSERT(g <= a); |
| 94 SkASSERT(b <= a); | 94 SkASSERT(b <= a); |
| 95 #endif | 95 #endif |
| 96 } | 96 } |
| 97 | 97 |
| 98 /** Inverts each color channel. */ |
| 99 static inline GrColor GrInvertColor(GrColor c) { |
| 100 U8CPU a = GrColorUnpackA(c); |
| 101 U8CPU r = GrColorUnpackR(c); |
| 102 U8CPU g = GrColorUnpackG(c); |
| 103 U8CPU b = GrColorUnpackB(c); |
| 104 return GrColorPackRGBA(0xff - r, 0xff - g, 0xff - b, 0xff - a); |
| 105 } |
| 106 |
| 107 static inline GrColor GrColorMul(GrColor c0, GrColor c1) { |
| 108 U8CPU r = SkMulDiv255Round(GrColorUnpackR(c0), GrColorUnpackR(c1)); |
| 109 U8CPU g = SkMulDiv255Round(GrColorUnpackG(c0), GrColorUnpackG(c1)); |
| 110 U8CPU b = SkMulDiv255Round(GrColorUnpackB(c0), GrColorUnpackB(c1)); |
| 111 U8CPU a = SkMulDiv255Round(GrColorUnpackA(c0), GrColorUnpackA(c1)); |
| 112 return GrColorPackRGBA(r, g, b, a); |
| 113 } |
| 114 |
| 115 static inline GrColor GrColorSatAdd(GrColor c0, GrColor c1) { |
| 116 unsigned r = SkTMin<unsigned>(GrColorUnpackR(c0) + GrColorUnpackR(c1), 0xff)
; |
| 117 unsigned g = SkTMin<unsigned>(GrColorUnpackG(c0) + GrColorUnpackG(c1), 0xff)
; |
| 118 unsigned b = SkTMin<unsigned>(GrColorUnpackB(c0) + GrColorUnpackB(c1), 0xff)
; |
| 119 unsigned a = SkTMin<unsigned>(GrColorUnpackA(c0) + GrColorUnpackA(c1), 0xff)
; |
| 120 return GrColorPackRGBA(r, g, b, a); |
| 121 } |
| 122 |
| 98 /** Converts a GrColor to an rgba array of GrGLfloat */ | 123 /** Converts a GrColor to an rgba array of GrGLfloat */ |
| 99 static inline void GrColorToRGBAFloat(GrColor color, float rgba[4]) { | 124 static inline void GrColorToRGBAFloat(GrColor color, float rgba[4]) { |
| 100 static const float ONE_OVER_255 = 1.f / 255.f; | 125 static const float ONE_OVER_255 = 1.f / 255.f; |
| 101 rgba[0] = GrColorUnpackR(color) * ONE_OVER_255; | 126 rgba[0] = GrColorUnpackR(color) * ONE_OVER_255; |
| 102 rgba[1] = GrColorUnpackG(color) * ONE_OVER_255; | 127 rgba[1] = GrColorUnpackG(color) * ONE_OVER_255; |
| 103 rgba[2] = GrColorUnpackB(color) * ONE_OVER_255; | 128 rgba[2] = GrColorUnpackB(color) * ONE_OVER_255; |
| 104 rgba[3] = GrColorUnpackA(color) * ONE_OVER_255; | 129 rgba[3] = GrColorUnpackA(color) * ONE_OVER_255; |
| 105 } | 130 } |
| 106 | 131 |
| 107 /** Normalizes and coverts an uint8_t to a float. [0, 255] -> [0.0, 1.0] */ | 132 /** Normalizes and coverts an uint8_t to a float. [0, 255] -> [0.0, 1.0] */ |
| 108 static inline float GrNormalizeByteToFloat(uint8_t value) { | 133 static inline float GrNormalizeByteToFloat(uint8_t value) { |
| 109 static const float ONE_OVER_255 = 1.f / 255.f; | 134 static const float ONE_OVER_255 = 1.f / 255.f; |
| 110 return value * ONE_OVER_255; | 135 return value * ONE_OVER_255; |
| 111 } | 136 } |
| 112 | 137 |
| 113 /** Determines whether the color is opaque or not. */ | 138 /** Determines whether the color is opaque or not. */ |
| 114 static inline bool GrColorIsOpaque(GrColor color) { | 139 static inline bool GrColorIsOpaque(GrColor color) { |
| 115 return (color & (0xFFU << GrColor_SHIFT_A)) == (0xFFU << GrColor_SHIFT_A); | 140 return (color & (0xFFU << GrColor_SHIFT_A)) == (0xFFU << GrColor_SHIFT_A); |
| 116 } | 141 } |
| 117 | 142 |
| 143 static inline GrColor GrPremulColor(GrColor color) { |
| 144 unsigned r = GrColorUnpackR(color); |
| 145 unsigned g = GrColorUnpackG(color); |
| 146 unsigned b = GrColorUnpackB(color); |
| 147 unsigned a = GrColorUnpackA(color); |
| 148 return GrColorPackRGBA(SkMulDiv255Round(r, a), |
| 149 SkMulDiv255Round(g, a), |
| 150 SkMulDiv255Round(b, a), |
| 151 a); |
| 152 } |
| 153 |
| 118 /** Returns an unpremuled version of the GrColor. */ | 154 /** Returns an unpremuled version of the GrColor. */ |
| 119 static inline GrColor GrUnPreMulColor(GrColor color) { | 155 static inline GrColor GrUnpremulColor(GrColor color) { |
| 156 GrColorIsPMAssert(color); |
| 120 unsigned r = GrColorUnpackR(color); | 157 unsigned r = GrColorUnpackR(color); |
| 121 unsigned g = GrColorUnpackG(color); | 158 unsigned g = GrColorUnpackG(color); |
| 122 unsigned b = GrColorUnpackB(color); | 159 unsigned b = GrColorUnpackB(color); |
| 123 unsigned a = GrColorUnpackA(color); | 160 unsigned a = GrColorUnpackA(color); |
| 124 SkPMColor colorPM = SkPackARGB32(a, r, g, b); | 161 SkPMColor colorPM = SkPackARGB32(a, r, g, b); |
| 125 SkColor colorUPM = SkUnPreMultiply::PMColorToColor(colorPM); | 162 SkColor colorUPM = SkUnPreMultiply::PMColorToColor(colorPM); |
| 126 | 163 |
| 127 r = SkColorGetR(colorUPM); | 164 r = SkColorGetR(colorUPM); |
| 128 g = SkColorGetG(colorUPM); | 165 g = SkColorGetG(colorUPM); |
| 129 b = SkColorGetB(colorUPM); | 166 b = SkColorGetB(colorUPM); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig); | 240 GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig); |
| 204 GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig); | 241 GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig); |
| 205 GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig); | 242 GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig); |
| 206 GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig); | 243 GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig); |
| 207 GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig); | 244 GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig); |
| 208 GR_STATIC_ASSERT(14 == kRGBA_half_GrPixelConfig); | 245 GR_STATIC_ASSERT(14 == kRGBA_half_GrPixelConfig); |
| 209 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt); | 246 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt); |
| 210 } | 247 } |
| 211 | 248 |
| 212 #endif | 249 #endif |
| OLD | NEW |