| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 /////////////////////////////////////////////////////////////////////////////// | 58 /////////////////////////////////////////////////////////////////////////////// |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Describes how to interpret the components of a pixel. | 61 * Describes how to interpret the components of a pixel. |
| 62 */ | 62 */ |
| 63 enum SkColorType { | 63 enum SkColorType { |
| 64 kAlpha_8_SkColorType, | 64 kAlpha_8_SkColorType, |
| 65 kRGB_565_SkColorType, | 65 kRGB_565_SkColorType, |
| 66 kARGB_4444_SkColorType, |
| 66 kRGBA_8888_SkColorType, | 67 kRGBA_8888_SkColorType, |
| 67 kBGRA_8888_SkColorType, | 68 kBGRA_8888_SkColorType, |
| 68 kIndex8_SkColorType, | 69 kIndex8_SkColorType, |
| 69 | 70 |
| 70 kLastEnum_SkColorType = kIndex8_SkColorType, | 71 kLastEnum_SkColorType = kIndex8_SkColorType, |
| 71 | 72 |
| 72 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) | 73 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
| 73 kPMColor_SkColorType = kBGRA_8888_SkColorType | 74 kPMColor_SkColorType = kBGRA_8888_SkColorType |
| 74 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) | 75 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
| 75 kPMColor_SkColorType = kRGBA_8888_SkColorType | 76 kPMColor_SkColorType = kRGBA_8888_SkColorType |
| 76 #else | 77 #else |
| 77 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" | 78 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" |
| 78 #endif | 79 #endif |
| 79 }; | 80 }; |
| 80 | 81 |
| 81 static int SkColorTypeBytesPerPixel(SkColorType ct) { | 82 static int SkColorTypeBytesPerPixel(SkColorType ct) { |
| 82 static const uint8_t gSize[] = { | 83 static const uint8_t gSize[] = { |
| 83 1, // Alpha_8 | 84 1, // Alpha_8 |
| 84 2, // RGB_565 | 85 2, // RGB_565 |
| 86 2, // ARGB_4444 |
| 85 4, // RGBA_8888 | 87 4, // RGBA_8888 |
| 86 4, // BGRA_8888 | 88 4, // BGRA_8888 |
| 87 1, // kIndex_8 | 89 1, // kIndex_8 |
| 88 }; | 90 }; |
| 89 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType +
1), | 91 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType +
1), |
| 90 size_mismatch_with_SkColorType_enum); | 92 size_mismatch_with_SkColorType_enum); |
| 91 | 93 |
| 92 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); | 94 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); |
| 93 return gSize[ct]; | 95 return gSize[ct]; |
| 94 } | 96 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 105 SkAlphaType fAlphaType; | 107 SkAlphaType fAlphaType; |
| 106 | 108 |
| 107 bool isOpaque() const { | 109 bool isOpaque() const { |
| 108 return SkAlphaTypeIsOpaque(fAlphaType); | 110 return SkAlphaTypeIsOpaque(fAlphaType); |
| 109 } | 111 } |
| 110 | 112 |
| 111 int bytesPerPixel() const { | 113 int bytesPerPixel() const { |
| 112 return SkColorTypeBytesPerPixel(fColorType); | 114 return SkColorTypeBytesPerPixel(fColorType); |
| 113 } | 115 } |
| 114 | 116 |
| 117 size_t minRowBytes() const { |
| 118 return fWidth * this->bytesPerPixel(); |
| 119 } |
| 120 |
| 115 bool operator==(const SkImageInfo& other) const { | 121 bool operator==(const SkImageInfo& other) const { |
| 116 return 0 == memcmp(this, &other, sizeof(other)); | 122 return 0 == memcmp(this, &other, sizeof(other)); |
| 117 } | 123 } |
| 118 bool operator!=(const SkImageInfo& other) const { | 124 bool operator!=(const SkImageInfo& other) const { |
| 119 return 0 != memcmp(this, &other, sizeof(other)); | 125 return 0 != memcmp(this, &other, sizeof(other)); |
| 120 } | 126 } |
| 127 |
| 128 bool isValid() const { |
| 129 return fWidth >= 0 && |
| 130 fHeight >= 0 && |
| 131 fColorType <= kLastEnum_SkColorType && |
| 132 fAlphaType <= kLastEnum_SkAlphaType; |
| 133 } |
| 134 |
| 135 void validate() const { |
| 136 SkASSERT(this->isValid()); |
| 137 } |
| 121 }; | 138 }; |
| 122 | 139 |
| 123 #endif | 140 #endif |
| OLD | NEW |