Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(693)

Side by Side Diff: include/core/SkImageInfo.h

Issue 147733004: Revert "SkBitmap now really stores SkImageInfo -- config is just a ruse" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkBitmap.h ('k') | include/core/SkPathRef.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkMath.h" 11 #include "SkTypes.h"
12 #include "SkSize.h" 12 #include "SkSize.h"
13 13
14 class SkWriteBuffer; 14 class SkWriteBuffer;
15 class SkReadBuffer; 15 class SkReadBuffer;
16 16
17 /** 17 /**
18 * Describes how to interpret the alpha compoent of a pixel. 18 * Describes how to interpret the alpha compoent of a pixel.
19 */ 19 */
20 enum SkAlphaType { 20 enum SkAlphaType {
21 /** 21 /**
(...skipping 30 matching lines...) Expand all
52 }; 52 };
53 53
54 static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) { 54 static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) {
55 SK_COMPILE_ASSERT(kIgnore_SkAlphaType < kOpaque_SkAlphaType, bad_alphatype_o rder); 55 SK_COMPILE_ASSERT(kIgnore_SkAlphaType < kOpaque_SkAlphaType, bad_alphatype_o rder);
56 SK_COMPILE_ASSERT(kPremul_SkAlphaType > kOpaque_SkAlphaType, bad_alphatype_o rder); 56 SK_COMPILE_ASSERT(kPremul_SkAlphaType > kOpaque_SkAlphaType, bad_alphatype_o rder);
57 SK_COMPILE_ASSERT(kUnpremul_SkAlphaType > kOpaque_SkAlphaType, bad_alphatype _order); 57 SK_COMPILE_ASSERT(kUnpremul_SkAlphaType > kOpaque_SkAlphaType, bad_alphatype _order);
58 58
59 return (unsigned)at <= kOpaque_SkAlphaType; 59 return (unsigned)at <= kOpaque_SkAlphaType;
60 } 60 }
61 61
62 static inline bool SkAlphaTypeIsValid(unsigned value) {
63 return value <= kLastEnum_SkAlphaType;
64 }
65
66 /////////////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////////////
67 63
68 /** 64 /**
69 * Describes how to interpret the components of a pixel. 65 * Describes how to interpret the components of a pixel.
70 */ 66 */
71 enum SkColorType { 67 enum SkColorType {
72 kUnknown_SkColorType,
73 kAlpha_8_SkColorType, 68 kAlpha_8_SkColorType,
74 kRGB_565_SkColorType, 69 kRGB_565_SkColorType,
75 kARGB_4444_SkColorType, 70 kARGB_4444_SkColorType,
76 kRGBA_8888_SkColorType, 71 kRGBA_8888_SkColorType,
77 kBGRA_8888_SkColorType, 72 kBGRA_8888_SkColorType,
78 kIndex_8_SkColorType, 73 kIndex_8_SkColorType,
79 74
80 kLastEnum_SkColorType = kIndex_8_SkColorType, 75 kLastEnum_SkColorType = kIndex_8_SkColorType,
81 76
82 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) 77 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
83 kPMColor_SkColorType = kBGRA_8888_SkColorType 78 kPMColor_SkColorType = kBGRA_8888_SkColorType
84 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) 79 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
85 kPMColor_SkColorType = kRGBA_8888_SkColorType 80 kPMColor_SkColorType = kRGBA_8888_SkColorType
86 #else 81 #else
87 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" 82 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order"
88 #endif 83 #endif
89 }; 84 };
90 85
91 static int SkColorTypeBytesPerPixel(SkColorType ct) { 86 static int SkColorTypeBytesPerPixel(SkColorType ct) {
92 static const uint8_t gSize[] = { 87 static const uint8_t gSize[] = {
93 0, // Unknown
94 1, // Alpha_8 88 1, // Alpha_8
95 2, // RGB_565 89 2, // RGB_565
96 2, // ARGB_4444 90 2, // ARGB_4444
97 4, // RGBA_8888 91 4, // RGBA_8888
98 4, // BGRA_8888 92 4, // BGRA_8888
99 1, // kIndex_8 93 1, // kIndex_8
100 }; 94 };
101 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1), 95 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1),
102 size_mismatch_with_SkColorType_enum); 96 size_mismatch_with_SkColorType_enum);
103 97
104 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); 98 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize));
105 return gSize[ct]; 99 return gSize[ct];
106 } 100 }
107 101
108 static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) {
109 return width * SkColorTypeBytesPerPixel(ct);
110 }
111
112 static inline bool SkColorTypeIsValid(unsigned value) {
113 return value <= kLastEnum_SkColorType;
114 }
115
116 /////////////////////////////////////////////////////////////////////////////// 102 ///////////////////////////////////////////////////////////////////////////////
117 103
118 /** 104 /**
119 * Describe an image's dimensions and pixel type. 105 * Describe an image's dimensions and pixel type.
120 */ 106 */
121 struct SkImageInfo { 107 struct SkImageInfo {
122 int fWidth; 108 int fWidth;
123 int fHeight; 109 int fHeight;
124 SkColorType fColorType; 110 SkColorType fColorType;
125 SkAlphaType fAlphaType; 111 SkAlphaType fAlphaType;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 152
167 static SkImageInfo MakeA8(int width, int height) { 153 static SkImageInfo MakeA8(int width, int height) {
168 SkASSERT(width >= 0); 154 SkASSERT(width >= 0);
169 SkASSERT(height >= 0); 155 SkASSERT(height >= 0);
170 SkImageInfo info = { 156 SkImageInfo info = {
171 width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType 157 width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType
172 }; 158 };
173 return info; 159 return info;
174 } 160 }
175 161
176 int width() const { return fWidth; }
177 int height() const { return fHeight; }
178 SkColorType colorType() const { return fColorType; }
179 SkAlphaType alphaType() const { return fAlphaType; }
180
181 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
182
183 bool isOpaque() const { 162 bool isOpaque() const {
184 return SkAlphaTypeIsOpaque(fAlphaType); 163 return SkAlphaTypeIsOpaque(fAlphaType);
185 } 164 }
186 165
187 SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); }
188
189 int bytesPerPixel() const { 166 int bytesPerPixel() const {
190 return SkColorTypeBytesPerPixel(fColorType); 167 return SkColorTypeBytesPerPixel(fColorType);
191 } 168 }
192 169
193 uint64_t minRowBytes64() const {
194 return sk_64_mul(fWidth, this->bytesPerPixel());
195 }
196
197 size_t minRowBytes() const { 170 size_t minRowBytes() const {
198 return (size_t)this->minRowBytes64(); 171 return fWidth * this->bytesPerPixel();
199 } 172 }
200 173
201 bool operator==(const SkImageInfo& other) const { 174 bool operator==(const SkImageInfo& other) const {
202 return 0 == memcmp(this, &other, sizeof(other)); 175 return 0 == memcmp(this, &other, sizeof(other));
203 } 176 }
204 bool operator!=(const SkImageInfo& other) const { 177 bool operator!=(const SkImageInfo& other) const {
205 return 0 != memcmp(this, &other, sizeof(other)); 178 return 0 != memcmp(this, &other, sizeof(other));
206 } 179 }
207 180
208 void unflatten(SkReadBuffer&); 181 void unflatten(SkReadBuffer&);
209 void flatten(SkWriteBuffer&) const; 182 void flatten(SkWriteBuffer&) const;
210 183
211 int64_t getSafeSize64(size_t rowBytes) const { 184 size_t getSafeSize(size_t rowBytes) const {
212 if (0 == fHeight) { 185 if (0 == fHeight) {
213 return 0; 186 return 0;
214 } 187 }
215 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel() ; 188 return (fHeight - 1) * rowBytes + fWidth * this->bytesPerPixel();
216 } 189 }
217
218 size_t getSafeSize(size_t rowBytes) const {
219 return (size_t)this->getSafeSize64(rowBytes);
220 }
221
222 bool validRowBytes(size_t rowBytes) const {
223 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel());
224 return rowBytes >= rb;
225 }
226
227 SkDEBUGCODE(void validate() const;)
228 }; 190 };
229 191
230 #endif 192 #endif
OLDNEW
« no previous file with comments | « include/core/SkBitmap.h ('k') | include/core/SkPathRef.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698