OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
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 SkImageInfo_DEFINED | 8 #ifndef SkImageInfo_DEFINED |
9 #define SkImageInfo_DEFINED | 9 #define SkImageInfo_DEFINED |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) | 80 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
81 kN32_SkColorType = kBGRA_8888_SkColorType, | 81 kN32_SkColorType = kBGRA_8888_SkColorType, |
82 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) | 82 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
83 kN32_SkColorType = kRGBA_8888_SkColorType, | 83 kN32_SkColorType = kRGBA_8888_SkColorType, |
84 #else | 84 #else |
85 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" | 85 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" |
86 #endif | 86 #endif |
87 }; | 87 }; |
88 | 88 |
89 extern const uint8_t gPrivate_SkColorTypeBytesPerPixel[]; | 89 static int SkColorTypeBytesPerPixel(SkColorType ct) { |
| 90 static const uint8_t gSize[] = { |
| 91 0, // Unknown |
| 92 1, // Alpha_8 |
| 93 2, // RGB_565 |
| 94 2, // ARGB_4444 |
| 95 4, // RGBA_8888 |
| 96 4, // BGRA_8888 |
| 97 1, // kIndex_8 |
| 98 1, // kGray_8 |
| 99 8, // kRGBA_F16 |
| 100 }; |
| 101 static_assert(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1), |
| 102 "size_mismatch_with_SkColorType_enum"); |
90 | 103 |
91 static int SkColorTypeBytesPerPixel(SkColorType ct) { | 104 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); |
92 SkASSERT((unsigned)ct <= (unsigned)kLastEnum_SkColorType); | 105 return gSize[ct]; |
93 return gPrivate_SkColorTypeBytesPerPixel[ct]; | |
94 } | 106 } |
95 | 107 |
96 extern const uint8_t gPrivate_SkColorTypeShiftPerPixel[]; | |
97 | |
98 static int SkColorTypeShiftPerPixel(SkColorType ct) { | 108 static int SkColorTypeShiftPerPixel(SkColorType ct) { |
99 SkASSERT((unsigned)ct <= (unsigned)kLastEnum_SkColorType); | 109 static const uint8_t gShift[] = { |
100 return gPrivate_SkColorTypeShiftPerPixel[ct]; | 110 0, // Unknown |
| 111 0, // Alpha_8 |
| 112 1, // RGB_565 |
| 113 1, // ARGB_4444 |
| 114 2, // RGBA_8888 |
| 115 2, // BGRA_8888 |
| 116 0, // kIndex_8 |
| 117 0, // kGray_8 |
| 118 3, // kRGBA_F16 |
| 119 }; |
| 120 static_assert(SK_ARRAY_COUNT(gShift) == (size_t)(kLastEnum_SkColorType + 1), |
| 121 "size_mismatch_with_SkColorType_enum"); |
| 122 |
| 123 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gShift)); |
| 124 return gShift[ct]; |
101 } | 125 } |
102 | 126 |
103 static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { | 127 static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { |
104 return width * SkColorTypeBytesPerPixel(ct); | 128 return width * SkColorTypeBytesPerPixel(ct); |
105 } | 129 } |
106 | 130 |
107 static inline bool SkColorTypeIsValid(unsigned value) { | 131 static inline bool SkColorTypeIsValid(unsigned value) { |
108 return value <= kLastEnum_SkColorType; | 132 return value <= kLastEnum_SkColorType; |
109 } | 133 } |
110 | 134 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 336 |
313 static inline bool SkColorAndProfileAreGammaCorrect(SkColorType ct, SkColorProfi
leType pt) { | 337 static inline bool SkColorAndProfileAreGammaCorrect(SkColorType ct, SkColorProfi
leType pt) { |
314 return kSRGB_SkColorProfileType == pt || kRGBA_F16_SkColorType == ct; | 338 return kSRGB_SkColorProfileType == pt || kRGBA_F16_SkColorType == ct; |
315 } | 339 } |
316 | 340 |
317 static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { | 341 static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { |
318 return SkColorAndProfileAreGammaCorrect(info.colorType(), info.profileType()
); | 342 return SkColorAndProfileAreGammaCorrect(info.colorType(), info.profileType()
); |
319 } | 343 } |
320 | 344 |
321 #endif | 345 #endif |
OLD | NEW |