| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 */ | 66 */ |
| 67 enum SkColorType { | 67 enum SkColorType { |
| 68 kUnknown_SkColorType, | 68 kUnknown_SkColorType, |
| 69 kAlpha_8_SkColorType, | 69 kAlpha_8_SkColorType, |
| 70 kRGB_565_SkColorType, | 70 kRGB_565_SkColorType, |
| 71 kARGB_4444_SkColorType, | 71 kARGB_4444_SkColorType, |
| 72 kRGBA_8888_SkColorType, | 72 kRGBA_8888_SkColorType, |
| 73 kBGRA_8888_SkColorType, | 73 kBGRA_8888_SkColorType, |
| 74 kIndex_8_SkColorType, | 74 kIndex_8_SkColorType, |
| 75 kGray_8_SkColorType, | 75 kGray_8_SkColorType, |
| 76 kRGBA_F16_SkColorType, |
| 76 | 77 |
| 77 kLastEnum_SkColorType = kGray_8_SkColorType, | 78 kLastEnum_SkColorType = kRGBA_F16_SkColorType, |
| 78 | 79 |
| 79 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) | 80 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
| 80 kN32_SkColorType = kBGRA_8888_SkColorType, | 81 kN32_SkColorType = kBGRA_8888_SkColorType, |
| 81 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) | 82 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
| 82 kN32_SkColorType = kRGBA_8888_SkColorType, | 83 kN32_SkColorType = kRGBA_8888_SkColorType, |
| 83 #else | 84 #else |
| 84 #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" |
| 85 #endif | 86 #endif |
| 86 }; | 87 }; |
| 87 | 88 |
| 88 static int SkColorTypeBytesPerPixel(SkColorType ct) { | 89 static int SkColorTypeBytesPerPixel(SkColorType ct) { |
| 89 static const uint8_t gSize[] = { | 90 static const uint8_t gSize[] = { |
| 90 0, // Unknown | 91 0, // Unknown |
| 91 1, // Alpha_8 | 92 1, // Alpha_8 |
| 92 2, // RGB_565 | 93 2, // RGB_565 |
| 93 2, // ARGB_4444 | 94 2, // ARGB_4444 |
| 94 4, // RGBA_8888 | 95 4, // RGBA_8888 |
| 95 4, // BGRA_8888 | 96 4, // BGRA_8888 |
| 96 1, // kIndex_8 | 97 1, // kIndex_8 |
| 97 1, // kGray_8 | 98 1, // kGray_8 |
| 99 8, // kRGBA_F16 |
| 98 }; | 100 }; |
| 99 static_assert(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1), | 101 static_assert(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1), |
| 100 "size_mismatch_with_SkColorType_enum"); | 102 "size_mismatch_with_SkColorType_enum"); |
| 101 | 103 |
| 102 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); | 104 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); |
| 103 return gSize[ct]; | 105 return gSize[ct]; |
| 104 } | 106 } |
| 105 | 107 |
| 106 static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { | 108 static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { |
| 107 return width * SkColorTypeBytesPerPixel(ct); | 109 return width * SkColorTypeBytesPerPixel(ct); |
| 108 } | 110 } |
| 109 | 111 |
| 110 static inline bool SkColorTypeIsValid(unsigned value) { | 112 static inline bool SkColorTypeIsValid(unsigned value) { |
| 111 return value <= kLastEnum_SkColorType; | 113 return value <= kLastEnum_SkColorType; |
| 112 } | 114 } |
| 113 | 115 |
| 114 static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size
_t rowBytes) { | 116 static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size
_t rowBytes) { |
| 115 int shift = 0; | 117 int shift = 0; |
| 116 switch (SkColorTypeBytesPerPixel(ct)) { | 118 switch (SkColorTypeBytesPerPixel(ct)) { |
| 119 case 8: shift = 3; break; |
| 117 case 4: shift = 2; break; | 120 case 4: shift = 2; break; |
| 118 case 2: shift = 1; break; | 121 case 2: shift = 1; break; |
| 119 case 1: shift = 0; break; | 122 case 1: shift = 0; break; |
| 120 default: return 0; | 123 default: return 0; |
| 121 } | 124 } |
| 122 return y * rowBytes + (x << shift); | 125 return y * rowBytes + (x << shift); |
| 123 } | 126 } |
| 124 | 127 |
| 125 /////////////////////////////////////////////////////////////////////////////// | 128 /////////////////////////////////////////////////////////////////////////////// |
| 126 | 129 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorPr
ofileType pt) | 312 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorPr
ofileType pt) |
| 310 : fWidth(width) | 313 : fWidth(width) |
| 311 , fHeight(height) | 314 , fHeight(height) |
| 312 , fColorType(ct) | 315 , fColorType(ct) |
| 313 , fAlphaType(at) | 316 , fAlphaType(at) |
| 314 , fProfileType(pt) | 317 , fProfileType(pt) |
| 315 {} | 318 {} |
| 316 }; | 319 }; |
| 317 | 320 |
| 318 #endif | 321 #endif |
| OLD | NEW |