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 "SkColorSpace.h" |
11 #include "SkMath.h" | 12 #include "SkMath.h" |
12 #include "SkRect.h" | 13 #include "SkRect.h" |
13 #include "SkSize.h" | 14 #include "SkSize.h" |
14 | 15 |
15 class SkReadBuffer; | 16 class SkReadBuffer; |
16 class SkWriteBuffer; | 17 class SkWriteBuffer; |
17 | 18 |
18 /** | 19 /** |
19 * Describes how to interpret the alpha component of a pixel. | 20 * Describes how to interpret the alpha component of a pixel. |
20 */ | 21 */ |
(...skipping 159 matching lines...) Loading... |
180 * Used for both src images and render-targets (surfaces). | 181 * Used for both src images and render-targets (surfaces). |
181 */ | 182 */ |
182 struct SK_API SkImageInfo { | 183 struct SK_API SkImageInfo { |
183 public: | 184 public: |
184 SkImageInfo() | 185 SkImageInfo() |
185 : fWidth(0) | 186 : fWidth(0) |
186 , fHeight(0) | 187 , fHeight(0) |
187 , fColorType(kUnknown_SkColorType) | 188 , fColorType(kUnknown_SkColorType) |
188 , fAlphaType(kUnknown_SkAlphaType) | 189 , fAlphaType(kUnknown_SkAlphaType) |
189 , fProfileType(kLinear_SkColorProfileType) | 190 , fProfileType(kLinear_SkColorProfileType) |
| 191 , fColorSpace(nullptr) |
190 {} | 192 {} |
191 | 193 |
192 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t, | 194 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t, |
193 SkColorProfileType pt = kLinear_SkColorProfileType)
{ | 195 SkColorProfileType pt = kLinear_SkColorProfileType)
{ |
194 return SkImageInfo(width, height, ct, at, pt); | 196 return SkImageInfo(width, height, ct, at, pt, nullptr); |
195 } | 197 } |
196 | 198 |
| 199 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t, |
| 200 sk_sp<SkColorSpace> cs); |
| 201 |
197 /** | 202 /** |
198 * Sets colortype to the native ARGB32 type. | 203 * Sets colortype to the native ARGB32 type. |
199 */ | 204 */ |
200 static SkImageInfo MakeN32(int width, int height, SkAlphaType at, | 205 static SkImageInfo MakeN32(int width, int height, SkAlphaType at, |
201 SkColorProfileType pt = kLinear_SkColorProfileTyp
e) { | 206 SkColorProfileType pt = kLinear_SkColorProfileTyp
e) { |
202 return SkImageInfo(width, height, kN32_SkColorType, at, pt); | 207 return SkImageInfo(width, height, kN32_SkColorType, at, pt, nullptr); |
203 } | 208 } |
204 | 209 |
205 /** | 210 /** |
206 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | 211 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
207 */ | 212 */ |
208 static SkImageInfo MakeN32Premul(int width, int height, | 213 static SkImageInfo MakeN32Premul(int width, int height, |
209 SkColorProfileType pt = kLinear_SkColorProf
ileType) { | 214 SkColorProfileType pt = kLinear_SkColorProf
ileType) { |
210 return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType,
pt); | 215 return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType,
pt, nullptr); |
211 } | 216 } |
212 | 217 |
213 /** | 218 /** |
214 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | 219 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
215 */ | 220 */ |
216 static SkImageInfo MakeN32Premul(const SkISize& size, | 221 static SkImageInfo MakeN32Premul(const SkISize& size, |
217 SkColorProfileType pt = kLinear_SkColorProf
ileType) { | 222 SkColorProfileType pt = kLinear_SkColorProf
ileType) { |
218 return MakeN32Premul(size.width(), size.height(), pt); | 223 return MakeN32Premul(size.width(), size.height(), pt); |
219 } | 224 } |
220 | 225 |
221 static SkImageInfo MakeA8(int width, int height) { | 226 static SkImageInfo MakeA8(int width, int height) { |
222 return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaT
ype, | 227 return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaT
ype, |
223 kLinear_SkColorProfileType); | 228 kLinear_SkColorProfileType, nullptr); |
224 } | 229 } |
225 | 230 |
226 static SkImageInfo MakeUnknown(int width, int height) { | 231 static SkImageInfo MakeUnknown(int width, int height) { |
227 return SkImageInfo(width, height, kUnknown_SkColorType, kUnknown_SkAlpha
Type, | 232 return SkImageInfo(width, height, kUnknown_SkColorType, kUnknown_SkAlpha
Type, |
228 kLinear_SkColorProfileType); | 233 kLinear_SkColorProfileType, nullptr); |
229 } | 234 } |
230 | 235 |
231 static SkImageInfo MakeUnknown() { | 236 static SkImageInfo MakeUnknown() { |
232 return SkImageInfo(); | 237 return SkImageInfo(); |
233 } | 238 } |
234 | 239 |
235 int width() const { return fWidth; } | 240 int width() const { return fWidth; } |
236 int height() const { return fHeight; } | 241 int height() const { return fHeight; } |
237 SkColorType colorType() const { return fColorType; } | 242 SkColorType colorType() const { return fColorType; } |
238 SkAlphaType alphaType() const { return fAlphaType; } | 243 SkAlphaType alphaType() const { return fAlphaType; } |
| 244 SkColorSpace* colorSpace() const { return fColorSpace.get(); } |
| 245 |
| 246 // Deprecated |
239 SkColorProfileType profileType() const { return fProfileType; } | 247 SkColorProfileType profileType() const { return fProfileType; } |
240 | 248 |
241 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } | 249 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } |
242 | 250 |
243 bool isOpaque() const { | 251 bool isOpaque() const { |
244 return SkAlphaTypeIsOpaque(fAlphaType); | 252 return SkAlphaTypeIsOpaque(fAlphaType); |
245 } | 253 } |
246 | 254 |
| 255 // Deprecated |
247 bool isLinear() const { return kLinear_SkColorProfileType == fProfileType; } | 256 bool isLinear() const { return kLinear_SkColorProfileType == fProfileType; } |
248 bool isSRGB() const { return kSRGB_SkColorProfileType == fProfileType; } | 257 bool isSRGB() const { return kSRGB_SkColorProfileType == fProfileType; } |
249 | 258 |
250 SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } | 259 SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } |
251 SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); } | 260 SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); } |
252 | 261 |
253 /** | 262 /** |
254 * Return a new ImageInfo with the same colortype and alphatype as this inf
o, | 263 * Return a new ImageInfo with the same colortype and alphatype as this inf
o, |
255 * but with the specified width and height. | 264 * but with the specified width and height. |
256 */ | 265 */ |
257 SkImageInfo makeWH(int newWidth, int newHeight) const { | 266 SkImageInfo makeWH(int newWidth, int newHeight) const { |
258 return SkImageInfo::Make(newWidth, newHeight, fColorType, fAlphaType, fP
rofileType); | 267 return SkImageInfo(newWidth, newHeight, fColorType, fAlphaType, fProfile
Type, fColorSpace); |
259 } | 268 } |
260 | 269 |
261 SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { | 270 SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { |
262 return SkImageInfo::Make(fWidth, fHeight, fColorType, newAlphaType, fPro
fileType); | 271 return SkImageInfo(fWidth, fHeight, fColorType, newAlphaType, fProfileTy
pe, fColorSpace); |
263 } | 272 } |
264 | 273 |
265 SkImageInfo makeColorType(SkColorType newColorType) const { | 274 SkImageInfo makeColorType(SkColorType newColorType) const { |
266 return SkImageInfo::Make(fWidth, fHeight, newColorType, fAlphaType, fPro
fileType); | 275 return SkImageInfo(fWidth, fHeight, newColorType, fAlphaType, fProfileTy
pe, fColorSpace); |
267 } | 276 } |
268 | 277 |
269 int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } | 278 int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } |
270 | 279 |
271 int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); } | 280 int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); } |
272 | 281 |
273 uint64_t minRowBytes64() const { | 282 uint64_t minRowBytes64() const { |
274 return sk_64_mul(fWidth, this->bytesPerPixel()); | 283 return sk_64_mul(fWidth, this->bytesPerPixel()); |
275 } | 284 } |
276 | 285 |
277 size_t minRowBytes() const { | 286 size_t minRowBytes() const { |
278 return (size_t)this->minRowBytes64(); | 287 return (size_t)this->minRowBytes64(); |
279 } | 288 } |
280 | 289 |
281 size_t computeOffset(int x, int y, size_t rowBytes) const { | 290 size_t computeOffset(int x, int y, size_t rowBytes) const { |
282 SkASSERT((unsigned)x < (unsigned)fWidth); | 291 SkASSERT((unsigned)x < (unsigned)fWidth); |
283 SkASSERT((unsigned)y < (unsigned)fHeight); | 292 SkASSERT((unsigned)y < (unsigned)fHeight); |
284 return SkColorTypeComputeOffset(fColorType, x, y, rowBytes); | 293 return SkColorTypeComputeOffset(fColorType, x, y, rowBytes); |
285 } | 294 } |
286 | 295 |
287 bool operator==(const SkImageInfo& other) const { | 296 bool operator==(const SkImageInfo& other) const { |
288 return 0 == memcmp(this, &other, sizeof(other)); | 297 return fWidth == other.fWidth && fHeight == other.fHeight && |
| 298 fColorType == other.fColorType && fAlphaType == other.fAlphaType
&& |
| 299 fProfileType == other.fProfileType && fColorSpace == other.fColor
Space; |
289 } | 300 } |
290 bool operator!=(const SkImageInfo& other) const { | 301 bool operator!=(const SkImageInfo& other) const { |
291 return 0 != memcmp(this, &other, sizeof(other)); | 302 return fWidth != other.fWidth || fHeight != other.fHeight || |
| 303 fColorType != other.fColorType || fAlphaType != other.fAlphaType
|| |
| 304 fProfileType != other.fProfileType || fColorSpace != other.fColor
Space; |
292 } | 305 } |
293 | 306 |
294 void unflatten(SkReadBuffer&); | 307 void unflatten(SkReadBuffer&); |
295 void flatten(SkWriteBuffer&) const; | 308 void flatten(SkWriteBuffer&) const; |
296 | 309 |
297 int64_t getSafeSize64(size_t rowBytes) const { | 310 int64_t getSafeSize64(size_t rowBytes) const { |
298 if (0 == fHeight) { | 311 if (0 == fHeight) { |
299 return 0; | 312 return 0; |
300 } | 313 } |
301 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; | 314 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; |
(...skipping 13 matching lines...) Loading... |
315 } | 328 } |
316 | 329 |
317 SkDEBUGCODE(void validate() const;) | 330 SkDEBUGCODE(void validate() const;) |
318 | 331 |
319 private: | 332 private: |
320 int fWidth; | 333 int fWidth; |
321 int fHeight; | 334 int fHeight; |
322 SkColorType fColorType; | 335 SkColorType fColorType; |
323 SkAlphaType fAlphaType; | 336 SkAlphaType fAlphaType; |
324 SkColorProfileType fProfileType; | 337 SkColorProfileType fProfileType; |
| 338 sk_sp<SkColorSpace> fColorSpace; |
325 | 339 |
326 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorPr
ofileType pt) | 340 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorPr
ofileType pt, |
| 341 sk_sp<SkColorSpace> cs) |
327 : fWidth(width) | 342 : fWidth(width) |
328 , fHeight(height) | 343 , fHeight(height) |
329 , fColorType(ct) | 344 , fColorType(ct) |
330 , fAlphaType(at) | 345 , fAlphaType(at) |
331 , fProfileType(pt) | 346 , fProfileType(pt) |
| 347 , fColorSpace(std::move(cs)) |
332 {} | 348 {} |
333 }; | 349 }; |
334 | 350 |
335 /////////////////////////////////////////////////////////////////////////////// | 351 /////////////////////////////////////////////////////////////////////////////// |
336 | 352 |
337 static inline bool SkColorAndProfileAreGammaCorrect(SkColorType ct, SkColorProfi
leType pt) { | 353 static inline bool SkColorAndProfileAreGammaCorrect(SkColorType ct, SkColorProfi
leType pt) { |
338 return kSRGB_SkColorProfileType == pt || kRGBA_F16_SkColorType == ct; | 354 return kSRGB_SkColorProfileType == pt || kRGBA_F16_SkColorType == ct; |
339 } | 355 } |
340 | 356 |
341 static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { | 357 static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { |
342 return SkColorAndProfileAreGammaCorrect(info.colorType(), info.profileType()
); | 358 return SkColorAndProfileAreGammaCorrect(info.colorType(), info.profileType()
); |
343 } | 359 } |
344 | 360 |
345 #endif | 361 #endif |
OLD | NEW |