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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 * alphaType for this colorType, return it in canonical. | 128 * alphaType for this colorType, return it in canonical. |
129 */ | 129 */ |
130 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, | 130 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, |
131 SkAlphaType* canonical = NULL); | 131 SkAlphaType* canonical = NULL); |
132 | 132 |
133 /////////////////////////////////////////////////////////////////////////////// | 133 /////////////////////////////////////////////////////////////////////////////// |
134 | 134 |
135 /** | 135 /** |
136 * Describe an image's dimensions and pixel type. | 136 * Describe an image's dimensions and pixel type. |
137 */ | 137 */ |
138 struct SK_API SkImageInfo { | 138 struct SkImageInfo { |
139 public: | |
140 SkImageInfo() | |
141 : fWidth(0) | |
142 , fHeight(0) | |
143 , fColorType(kUnknown_SkColorType) | |
144 , fAlphaType(kIgnore_SkAlphaType) | |
145 , fProfile(kUnknown_Profile) | |
146 , fGamma(0) | |
147 {} | |
148 | |
149 int fWidth; | 139 int fWidth; |
150 int fHeight; | 140 int fHeight; |
151 SkColorType fColorType; | 141 SkColorType fColorType; |
152 SkAlphaType fAlphaType; | 142 SkAlphaType fAlphaType; |
153 | 143 |
154 /* | |
155 * Return an info with the specified attributes, tagged as sRGB. Note that
if the requested | |
156 * color type does not make sense with sRGB (e.g. kAlpha_8) then the sRGB r
equest is ignored. | |
157 * | |
158 * You can call isSRGB() on the returned info to determine if the request w
as fulfilled. | |
159 */ | |
160 static SkImageInfo MakeSRGB(int width, int height, SkColorType ct, SkAlphaTy
pe at); | |
161 | |
162 /* | |
163 * Return an info with the specified attributes, tagged with a specific gam
ma. | |
164 * Note that if the requested gamma is unsupported for the requested color
type, then the gamma | |
165 * value will be set to 1.0 (the default). | |
166 * | |
167 * You can call gamma() to query the resulting gamma value. | |
168 */ | |
169 static SkImageInfo MakeWithGamma(int width, int height, SkColorType ct, SkAl
phaType at, | |
170 float gamma); | |
171 | |
172 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t) { | 144 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t) { |
173 return MakeWithGamma(width, height, ct, at, 1); | 145 SkImageInfo info = { |
| 146 width, height, ct, at |
| 147 }; |
| 148 return info; |
174 } | 149 } |
175 | 150 |
176 /** | 151 /** |
177 * Sets colortype to the native ARGB32 type. | 152 * Sets colortype to the native ARGB32 type. |
178 */ | 153 */ |
179 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { | 154 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { |
180 return SkImageInfo(width, height, kN32_SkColorType, at, kExponential_Pro
file, 1); | 155 SkImageInfo info = { |
| 156 width, height, kN32_SkColorType, at |
| 157 }; |
| 158 return info; |
181 } | 159 } |
182 | 160 |
183 /** | 161 /** |
184 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | 162 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
185 */ | 163 */ |
186 static SkImageInfo MakeN32Premul(int width, int height) { | 164 static SkImageInfo MakeN32Premul(int width, int height) { |
187 return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType, | 165 SkImageInfo info = { |
188 kExponential_Profile, 1); | 166 width, height, kN32_SkColorType, kPremul_SkAlphaType |
| 167 }; |
| 168 return info; |
189 } | 169 } |
190 | 170 |
191 /** | 171 /** |
192 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | 172 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
193 */ | 173 */ |
194 static SkImageInfo MakeN32Premul(const SkISize& size) { | 174 static SkImageInfo MakeN32Premul(const SkISize& size) { |
195 return MakeN32Premul(size.width(), size.height()); | 175 return MakeN32Premul(size.width(), size.height()); |
196 } | 176 } |
197 | 177 |
198 static SkImageInfo MakeA8(int width, int height) { | 178 static SkImageInfo MakeA8(int width, int height) { |
199 return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaT
ype, | 179 SkImageInfo info = { |
200 kUnknown_Profile, 0); | 180 width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType |
| 181 }; |
| 182 return info; |
201 } | 183 } |
202 | 184 |
203 static SkImageInfo MakeUnknown(int width, int height) { | 185 static SkImageInfo MakeUnknown(int width, int height) { |
204 return SkImageInfo(width, height, kUnknown_SkColorType, kIgnore_SkAlphaT
ype, | 186 SkImageInfo info = { |
205 kUnknown_Profile, 0); | 187 width, height, kUnknown_SkColorType, kIgnore_SkAlphaType |
| 188 }; |
| 189 return info; |
206 } | 190 } |
207 | 191 |
208 static SkImageInfo MakeUnknown() { | 192 static SkImageInfo MakeUnknown() { |
209 return SkImageInfo(); | 193 SkImageInfo info = { |
| 194 0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType |
| 195 }; |
| 196 return info; |
210 } | 197 } |
211 | 198 |
212 int width() const { return fWidth; } | 199 int width() const { return fWidth; } |
213 int height() const { return fHeight; } | 200 int height() const { return fHeight; } |
214 SkColorType colorType() const { return fColorType; } | 201 SkColorType colorType() const { return fColorType; } |
215 SkAlphaType alphaType() const { return fAlphaType; } | 202 SkAlphaType alphaType() const { return fAlphaType; } |
216 | 203 |
217 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } | 204 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } |
218 | 205 |
219 bool isOpaque() const { | 206 bool isOpaque() const { |
(...skipping 22 matching lines...) Expand all Loading... |
242 return (size_t)this->minRowBytes64(); | 229 return (size_t)this->minRowBytes64(); |
243 } | 230 } |
244 | 231 |
245 bool operator==(const SkImageInfo& other) const { | 232 bool operator==(const SkImageInfo& other) const { |
246 return 0 == memcmp(this, &other, sizeof(other)); | 233 return 0 == memcmp(this, &other, sizeof(other)); |
247 } | 234 } |
248 bool operator!=(const SkImageInfo& other) const { | 235 bool operator!=(const SkImageInfo& other) const { |
249 return 0 != memcmp(this, &other, sizeof(other)); | 236 return 0 != memcmp(this, &other, sizeof(other)); |
250 } | 237 } |
251 | 238 |
252 // DEPRECATED : use the static Unflatten | |
253 void unflatten(SkReadBuffer&); | 239 void unflatten(SkReadBuffer&); |
254 void flatten(SkWriteBuffer&) const; | 240 void flatten(SkWriteBuffer&) const; |
255 | |
256 static SkImageInfo Unflatten(SkReadBuffer&); | |
257 | 241 |
258 int64_t getSafeSize64(size_t rowBytes) const { | 242 int64_t getSafeSize64(size_t rowBytes) const { |
259 if (0 == fHeight) { | 243 if (0 == fHeight) { |
260 return 0; | 244 return 0; |
261 } | 245 } |
262 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; | 246 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; |
263 } | 247 } |
264 | 248 |
265 size_t getSafeSize(size_t rowBytes) const { | 249 size_t getSafeSize(size_t rowBytes) const { |
266 return (size_t)this->getSafeSize64(rowBytes); | 250 return (size_t)this->getSafeSize64(rowBytes); |
267 } | 251 } |
268 | 252 |
269 bool validRowBytes(size_t rowBytes) const { | 253 bool validRowBytes(size_t rowBytes) const { |
270 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); | 254 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); |
271 return rowBytes >= rb; | 255 return rowBytes >= rb; |
272 } | 256 } |
273 | 257 |
274 SkDEBUGCODE(void validate() const;) | 258 SkDEBUGCODE(void validate() const;) |
275 | |
276 /** | |
277 * If the Info was tagged to be sRGB, return true, else return false. | |
278 */ | |
279 bool isSRGB() const { return kSRGB_Profile == fProfile; } | |
280 | |
281 /** | |
282 * If this was tagged with an explicit gamma value, return that value, else
return 0. | |
283 * If this was tagged as sRGB, return 0. | |
284 */ | |
285 float gamma() const { return fGamma; } | |
286 | |
287 private: | |
288 enum Profile { | |
289 kUnknown_Profile, | |
290 kSRGB_Profile, | |
291 kExponential_Profile, | |
292 }; | |
293 | |
294 uint32_t fProfile; | |
295 float fGamma; | |
296 | |
297 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, Profile p
, float g) | |
298 : fWidth(width) | |
299 , fHeight(height) | |
300 , fColorType(ct) | |
301 , fAlphaType(at) | |
302 , fProfile(p) | |
303 , fGamma(g) | |
304 {} | |
305 }; | 259 }; |
306 | 260 |
307 #endif | 261 #endif |
OLD | NEW |