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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 1, // kGray_8 | 98 1, // kGray_8 |
99 8, // kRGBA_F16 | 99 8, // kRGBA_F16 |
100 }; | 100 }; |
101 static_assert(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1), | 101 static_assert(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1), |
102 "size_mismatch_with_SkColorType_enum"); | 102 "size_mismatch_with_SkColorType_enum"); |
103 | 103 |
104 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); | 104 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); |
105 return gSize[ct]; | 105 return gSize[ct]; |
106 } | 106 } |
107 | 107 |
| 108 static int SkColorTypeShiftPerPixel(SkColorType ct) { |
| 109 static const uint8_t gShift[] = { |
| 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]; |
| 125 } |
| 126 |
108 static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { | 127 static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { |
109 return width * SkColorTypeBytesPerPixel(ct); | 128 return width * SkColorTypeBytesPerPixel(ct); |
110 } | 129 } |
111 | 130 |
112 static inline bool SkColorTypeIsValid(unsigned value) { | 131 static inline bool SkColorTypeIsValid(unsigned value) { |
113 return value <= kLastEnum_SkColorType; | 132 return value <= kLastEnum_SkColorType; |
114 } | 133 } |
115 | 134 |
116 static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size
_t rowBytes) { | 135 static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size
_t rowBytes) { |
117 int shift = 0; | 136 if (kUnknown_SkColorType == ct) { |
118 switch (SkColorTypeBytesPerPixel(ct)) { | 137 return 0; |
119 case 8: shift = 3; break; | |
120 case 4: shift = 2; break; | |
121 case 2: shift = 1; break; | |
122 case 1: shift = 0; break; | |
123 default: return 0; | |
124 } | 138 } |
125 return y * rowBytes + (x << shift); | 139 return y * rowBytes + (x << SkColorTypeShiftPerPixel(ct)); |
126 } | 140 } |
127 | 141 |
128 /////////////////////////////////////////////////////////////////////////////// | 142 /////////////////////////////////////////////////////////////////////////////// |
129 | 143 |
130 /** | 144 /** |
131 * Return true if alphaType is supported by colorType. If there is a canonical | 145 * Return true if alphaType is supported by colorType. If there is a canonical |
132 * alphaType for this colorType, return it in canonical. | 146 * alphaType for this colorType, return it in canonical. |
133 */ | 147 */ |
134 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, | 148 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, |
135 SkAlphaType* canonical = NULL); | 149 SkAlphaType* canonical = NULL); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 259 } |
246 | 260 |
247 SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { | 261 SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { |
248 return SkImageInfo::Make(fWidth, fHeight, fColorType, newAlphaType, fPro
fileType); | 262 return SkImageInfo::Make(fWidth, fHeight, fColorType, newAlphaType, fPro
fileType); |
249 } | 263 } |
250 | 264 |
251 SkImageInfo makeColorType(SkColorType newColorType) const { | 265 SkImageInfo makeColorType(SkColorType newColorType) const { |
252 return SkImageInfo::Make(fWidth, fHeight, newColorType, fAlphaType, fPro
fileType); | 266 return SkImageInfo::Make(fWidth, fHeight, newColorType, fAlphaType, fPro
fileType); |
253 } | 267 } |
254 | 268 |
255 int bytesPerPixel() const { | 269 int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } |
256 return SkColorTypeBytesPerPixel(fColorType); | 270 |
257 } | 271 int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); } |
258 | 272 |
259 uint64_t minRowBytes64() const { | 273 uint64_t minRowBytes64() const { |
260 return sk_64_mul(fWidth, this->bytesPerPixel()); | 274 return sk_64_mul(fWidth, this->bytesPerPixel()); |
261 } | 275 } |
262 | 276 |
263 size_t minRowBytes() const { | 277 size_t minRowBytes() const { |
264 return (size_t)this->minRowBytes64(); | 278 return (size_t)this->minRowBytes64(); |
265 } | 279 } |
266 | 280 |
267 size_t computeOffset(int x, int y, size_t rowBytes) const { | 281 size_t computeOffset(int x, int y, size_t rowBytes) const { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 336 |
323 static inline bool SkColorAndProfileAreGammaCorrect(SkColorType ct, SkColorProfi
leType pt) { | 337 static inline bool SkColorAndProfileAreGammaCorrect(SkColorType ct, SkColorProfi
leType pt) { |
324 return kSRGB_SkColorProfileType == pt || kRGBA_F16_SkColorType == ct; | 338 return kSRGB_SkColorProfileType == pt || kRGBA_F16_SkColorType == ct; |
325 } | 339 } |
326 | 340 |
327 static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { | 341 static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { |
328 return SkColorAndProfileAreGammaCorrect(info.colorType(), info.profileType()
); | 342 return SkColorAndProfileAreGammaCorrect(info.colorType(), info.profileType()
); |
329 } | 343 } |
330 | 344 |
331 #endif | 345 #endif |
OLD | NEW |