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 |
11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
12 | 12 |
13 class SkFlattenableWriteBuffer; | |
14 class SkFlattenableReadBuffer; | |
15 | |
16 /** | 13 /** |
17 * Describes how to interpret the alpha compoent of a pixel. | 14 * Describes how to interpret the alpha compoent of a pixel. |
18 */ | 15 */ |
19 enum SkAlphaType { | 16 enum SkAlphaType { |
20 /** | 17 /** |
21 * All pixels should be treated as opaque, regardless of the value stored | 18 * All pixels should be treated as opaque, regardless of the value stored |
22 * in their alpha field. Used for legacy images that wrote 0 or garbarge | 19 * in their alpha field. Used for legacy images that wrote 0 or garbarge |
23 * in their alpha field, but intended the RGB to be treated as opaque. | 20 * in their alpha field, but intended the RGB to be treated as opaque. |
24 */ | 21 */ |
25 kIgnore_SkAlphaType, | 22 kIgnore_SkAlphaType, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } | 56 } |
60 | 57 |
61 /////////////////////////////////////////////////////////////////////////////// | 58 /////////////////////////////////////////////////////////////////////////////// |
62 | 59 |
63 /** | 60 /** |
64 * Describes how to interpret the components of a pixel. | 61 * Describes how to interpret the components of a pixel. |
65 */ | 62 */ |
66 enum SkColorType { | 63 enum SkColorType { |
67 kAlpha_8_SkColorType, | 64 kAlpha_8_SkColorType, |
68 kRGB_565_SkColorType, | 65 kRGB_565_SkColorType, |
69 kARGB_4444_SkColorType, | |
70 kRGBA_8888_SkColorType, | 66 kRGBA_8888_SkColorType, |
71 kBGRA_8888_SkColorType, | 67 kBGRA_8888_SkColorType, |
72 kIndex8_SkColorType, | 68 kIndex8_SkColorType, |
73 | 69 |
74 kLastEnum_SkColorType = kIndex8_SkColorType, | 70 kLastEnum_SkColorType = kIndex8_SkColorType, |
75 | 71 |
76 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) | 72 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
77 kPMColor_SkColorType = kBGRA_8888_SkColorType | 73 kPMColor_SkColorType = kBGRA_8888_SkColorType |
78 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) | 74 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
79 kPMColor_SkColorType = kRGBA_8888_SkColorType | 75 kPMColor_SkColorType = kRGBA_8888_SkColorType |
80 #else | 76 #else |
81 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" | 77 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" |
82 #endif | 78 #endif |
83 }; | 79 }; |
84 | 80 |
85 static int SkColorTypeBytesPerPixel(SkColorType ct) { | 81 static int SkColorTypeBytesPerPixel(SkColorType ct) { |
86 static const uint8_t gSize[] = { | 82 static const uint8_t gSize[] = { |
87 1, // Alpha_8 | 83 1, // Alpha_8 |
88 2, // RGB_565 | 84 2, // RGB_565 |
89 2, // ARGB_4444 | |
90 4, // RGBA_8888 | 85 4, // RGBA_8888 |
91 4, // BGRA_8888 | 86 4, // BGRA_8888 |
92 1, // kIndex_8 | 87 1, // kIndex_8 |
93 }; | 88 }; |
94 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType +
1), | 89 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType +
1), |
95 size_mismatch_with_SkColorType_enum); | 90 size_mismatch_with_SkColorType_enum); |
96 | 91 |
97 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); | 92 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); |
98 return gSize[ct]; | 93 return gSize[ct]; |
99 } | 94 } |
(...skipping 10 matching lines...) Expand all Loading... |
110 SkAlphaType fAlphaType; | 105 SkAlphaType fAlphaType; |
111 | 106 |
112 bool isOpaque() const { | 107 bool isOpaque() const { |
113 return SkAlphaTypeIsOpaque(fAlphaType); | 108 return SkAlphaTypeIsOpaque(fAlphaType); |
114 } | 109 } |
115 | 110 |
116 int bytesPerPixel() const { | 111 int bytesPerPixel() const { |
117 return SkColorTypeBytesPerPixel(fColorType); | 112 return SkColorTypeBytesPerPixel(fColorType); |
118 } | 113 } |
119 | 114 |
120 size_t minRowBytes() const { | |
121 return fWidth * this->bytesPerPixel(); | |
122 } | |
123 | |
124 bool operator==(const SkImageInfo& other) const { | 115 bool operator==(const SkImageInfo& other) const { |
125 return 0 == memcmp(this, &other, sizeof(other)); | 116 return 0 == memcmp(this, &other, sizeof(other)); |
126 } | 117 } |
127 bool operator!=(const SkImageInfo& other) const { | 118 bool operator!=(const SkImageInfo& other) const { |
128 return 0 != memcmp(this, &other, sizeof(other)); | 119 return 0 != memcmp(this, &other, sizeof(other)); |
129 } | 120 } |
130 | |
131 void unflatten(SkFlattenableReadBuffer&); | |
132 void flatten(SkFlattenableWriteBuffer&) const; | |
133 | |
134 size_t getSafeSize(size_t rowBytes) const { | |
135 if (0 == fHeight) { | |
136 return 0; | |
137 } | |
138 return (fHeight - 1) * rowBytes + fWidth * this->bytesPerPixel(); | |
139 } | |
140 }; | 121 }; |
141 | 122 |
142 #endif | 123 #endif |
OLD | NEW |