| 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 "SkColorSpace.h" |
| 12 #include "SkMath.h" | 12 #include "SkMath.h" |
| 13 #include "SkRect.h" | 13 #include "SkRect.h" |
| 14 #include "SkSize.h" | 14 #include "SkSize.h" |
| 15 | 15 |
| 16 #define SK_SUPPORT_LEGACY_COLORPROFILETYPE |
| 17 |
| 16 class SkReadBuffer; | 18 class SkReadBuffer; |
| 17 class SkWriteBuffer; | 19 class SkWriteBuffer; |
| 18 | 20 |
| 19 /** | 21 /** |
| 20 * Describes how to interpret the alpha component of a pixel. | 22 * Describes how to interpret the alpha component of a pixel. |
| 21 */ | 23 */ |
| 22 enum SkAlphaType { | 24 enum SkAlphaType { |
| 23 kUnknown_SkAlphaType, | 25 kUnknown_SkAlphaType, |
| 24 | 26 |
| 25 /** | 27 /** |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 kRec601_SkYUVColorSpace, | 164 kRec601_SkYUVColorSpace, |
| 163 /** HDTV standard Rec. 709 color space. Uses "studio swing" [16, 235] color | 165 /** HDTV standard Rec. 709 color space. Uses "studio swing" [16, 235] color |
| 164 range. See http://en.wikipedia.org/wiki/Rec._709 for details. */ | 166 range. See http://en.wikipedia.org/wiki/Rec._709 for details. */ |
| 165 kRec709_SkYUVColorSpace, | 167 kRec709_SkYUVColorSpace, |
| 166 | 168 |
| 167 kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace | 169 kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace |
| 168 }; | 170 }; |
| 169 | 171 |
| 170 /////////////////////////////////////////////////////////////////////////////// | 172 /////////////////////////////////////////////////////////////////////////////// |
| 171 | 173 |
| 174 #ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE |
| 172 enum SkColorProfileType { | 175 enum SkColorProfileType { |
| 173 kLinear_SkColorProfileType, | 176 kLinear_SkColorProfileType, |
| 174 kSRGB_SkColorProfileType, | 177 kSRGB_SkColorProfileType, |
| 175 | 178 |
| 176 kLastEnum_SkColorProfileType = kSRGB_SkColorProfileType | 179 kLastEnum_SkColorProfileType = kSRGB_SkColorProfileType |
| 177 }; | 180 }; |
| 181 #endif |
| 178 | 182 |
| 179 enum class SkSourceGammaTreatment { | 183 enum class SkSourceGammaTreatment { |
| 180 kRespect, | 184 kRespect, |
| 181 kIgnore, | 185 kIgnore, |
| 182 }; | 186 }; |
| 183 | 187 |
| 184 /** | 188 /** |
| 185 * Describe an image's dimensions and pixel type. | 189 * Describe an image's dimensions and pixel type. |
| 186 * Used for both src images and render-targets (surfaces). | 190 * Used for both src images and render-targets (surfaces). |
| 187 */ | 191 */ |
| 188 struct SK_API SkImageInfo { | 192 struct SK_API SkImageInfo { |
| 189 public: | 193 public: |
| 190 SkImageInfo() | 194 SkImageInfo() |
| 191 : fColorSpace(nullptr) | 195 : fColorSpace(nullptr) |
| 192 , fWidth(0) | 196 , fWidth(0) |
| 193 , fHeight(0) | 197 , fHeight(0) |
| 194 , fColorType(kUnknown_SkColorType) | 198 , fColorType(kUnknown_SkColorType) |
| 195 , fAlphaType(kUnknown_SkAlphaType) | 199 , fAlphaType(kUnknown_SkAlphaType) |
| 196 , fProfileType(kLinear_SkColorProfileType) | |
| 197 {} | 200 {} |
| 198 | 201 |
| 199 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t, | 202 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t, |
| 200 SkColorProfileType pt = kLinear_SkColorProfileType)
{ | 203 sk_sp<SkColorSpace> cs = nullptr) { |
| 201 sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ? | 204 return SkImageInfo(width, height, ct, at, std::move(cs)); |
| 202 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Name
d) : nullptr; | |
| 203 return SkImageInfo(width, height, ct, at, pt, cs); | |
| 204 } | 205 } |
| 205 | 206 |
| 206 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t, | |
| 207 sk_sp<SkColorSpace> cs); | |
| 208 | |
| 209 /** | 207 /** |
| 210 * Sets colortype to the native ARGB32 type. | 208 * Sets colortype to the native ARGB32 type. |
| 211 */ | 209 */ |
| 212 static SkImageInfo MakeN32(int width, int height, SkAlphaType at, | 210 static SkImageInfo MakeN32(int width, int height, SkAlphaType at, |
| 213 SkColorProfileType pt = kLinear_SkColorProfileTyp
e) { | 211 sk_sp<SkColorSpace> cs = nullptr) { |
| 214 sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ? | 212 return Make(width, height, kN32_SkColorType, at, cs); |
| 215 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Name
d) : nullptr; | |
| 216 return SkImageInfo(width, height, kN32_SkColorType, at, pt, cs); | |
| 217 } | |
| 218 | |
| 219 /** | |
| 220 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | |
| 221 */ | |
| 222 static SkImageInfo MakeN32Premul(int width, int height, | |
| 223 SkColorProfileType pt = kLinear_SkColorProf
ileType) { | |
| 224 sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ? | |
| 225 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Name
d) : nullptr; | |
| 226 return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType,
pt, cs); | |
| 227 } | |
| 228 | |
| 229 /** | |
| 230 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | |
| 231 */ | |
| 232 static SkImageInfo MakeN32Premul(const SkISize& size, | |
| 233 SkColorProfileType pt = kLinear_SkColorProf
ileType) { | |
| 234 return MakeN32Premul(size.width(), size.height(), pt); | |
| 235 } | 213 } |
| 236 | 214 |
| 237 /** | 215 /** |
| 238 * Create an ImageInfo marked as SRGB with N32 swizzle. | 216 * Create an ImageInfo marked as SRGB with N32 swizzle. |
| 239 */ | 217 */ |
| 240 static SkImageInfo MakeS32(int width, int height, SkAlphaType at); | 218 static SkImageInfo MakeS32(int width, int height, SkAlphaType at); |
| 241 | 219 |
| 220 /** |
| 221 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
| 222 */ |
| 223 static SkImageInfo MakeN32Premul(int width, int height) { |
| 224 return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, nullpt
r); |
| 225 } |
| 226 |
| 227 static SkImageInfo MakeN32Premul(const SkISize& size) { |
| 228 return MakeN32Premul(size.width(), size.height()); |
| 229 } |
| 230 |
| 242 static SkImageInfo MakeA8(int width, int height) { | 231 static SkImageInfo MakeA8(int width, int height) { |
| 243 return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaT
ype, | 232 return Make(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType, nu
llptr); |
| 244 kLinear_SkColorProfileType, nullptr); | |
| 245 } | 233 } |
| 246 | 234 |
| 247 static SkImageInfo MakeUnknown(int width, int height) { | 235 static SkImageInfo MakeUnknown(int width, int height) { |
| 248 return SkImageInfo(width, height, kUnknown_SkColorType, kUnknown_SkAlpha
Type, | 236 return Make(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType, n
ullptr); |
| 249 kLinear_SkColorProfileType, nullptr); | |
| 250 } | 237 } |
| 251 | 238 |
| 252 static SkImageInfo MakeUnknown() { | 239 static SkImageInfo MakeUnknown() { |
| 253 return SkImageInfo(); | 240 return MakeUnknown(0, 0); |
| 254 } | 241 } |
| 242 |
| 243 #ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE |
| 244 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t, |
| 245 SkColorProfileType pt) { |
| 246 sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ? |
| 247 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr; |
| 248 return Make(width, height, ct, at, cs); |
| 249 } |
| 250 |
| 251 static SkImageInfo MakeN32(int width, int height, SkAlphaType at, SkColorPro
fileType pt) { |
| 252 sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ? |
| 253 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Name
d) : nullptr; |
| 254 return SkImageInfo(width, height, kN32_SkColorType, at, cs); |
| 255 } |
| 256 |
| 257 /** |
| 258 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
| 259 */ |
| 260 static SkImageInfo MakeN32Premul(int width, int height, SkColorProfileType p
t) { |
| 261 sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ? |
| 262 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Name
d) : nullptr; |
| 263 return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, cs); |
| 264 } |
| 265 |
| 266 /** |
| 267 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
| 268 */ |
| 269 static SkImageInfo MakeN32Premul(const SkISize& size, SkColorProfileType pt)
{ |
| 270 return MakeN32Premul(size.width(), size.height(), pt); |
| 271 } |
| 272 |
| 273 SkColorProfileType profileType() const; |
| 274 bool isLinear() const { return kLinear_SkColorProfileType == this->profileTy
pe(); } |
| 275 bool isSRGB() const { return kSRGB_SkColorProfileType == this->profileType()
; } |
| 276 #endif |
| 255 | 277 |
| 256 int width() const { return fWidth; } | 278 int width() const { return fWidth; } |
| 257 int height() const { return fHeight; } | 279 int height() const { return fHeight; } |
| 258 SkColorType colorType() const { return fColorType; } | 280 SkColorType colorType() const { return fColorType; } |
| 259 SkAlphaType alphaType() const { return fAlphaType; } | 281 SkAlphaType alphaType() const { return fAlphaType; } |
| 260 SkColorSpace* colorSpace() const { return fColorSpace.get(); } | 282 SkColorSpace* colorSpace() const { return fColorSpace.get(); } |
| 261 | 283 |
| 262 // Deprecated | |
| 263 SkColorProfileType profileType() const { return fProfileType; } | |
| 264 | |
| 265 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } | 284 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } |
| 266 | 285 |
| 267 bool isOpaque() const { | 286 bool isOpaque() const { |
| 268 return SkAlphaTypeIsOpaque(fAlphaType); | 287 return SkAlphaTypeIsOpaque(fAlphaType); |
| 269 } | 288 } |
| 270 | 289 |
| 271 // Deprecated | |
| 272 bool isLinear() const { return kLinear_SkColorProfileType == fProfileType; } | |
| 273 bool isSRGB() const { return kSRGB_SkColorProfileType == fProfileType; } | |
| 274 | |
| 275 SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } | 290 SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } |
| 276 SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); } | 291 SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); } |
| 277 | 292 |
| 293 bool gammaCloseToSRGB() const { |
| 294 return fColorSpace && fColorSpace->gammaCloseToSRGB(); |
| 295 } |
| 296 |
| 278 /** | 297 /** |
| 279 * Return a new ImageInfo with the same colortype and alphatype as this inf
o, | 298 * Return a new ImageInfo with the same colortype and alphatype as this inf
o, |
| 280 * but with the specified width and height. | 299 * but with the specified width and height. |
| 281 */ | 300 */ |
| 282 SkImageInfo makeWH(int newWidth, int newHeight) const { | 301 SkImageInfo makeWH(int newWidth, int newHeight) const { |
| 283 return SkImageInfo(newWidth, newHeight, fColorType, fAlphaType, fProfile
Type, fColorSpace); | 302 return Make(newWidth, newHeight, fColorType, fAlphaType, fColorSpace); |
| 284 } | 303 } |
| 285 | 304 |
| 286 SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { | 305 SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { |
| 287 return SkImageInfo(fWidth, fHeight, fColorType, newAlphaType, fProfileTy
pe, fColorSpace); | 306 return Make(fWidth, fHeight, fColorType, newAlphaType, fColorSpace); |
| 288 } | 307 } |
| 289 | 308 |
| 290 SkImageInfo makeColorType(SkColorType newColorType) const { | 309 SkImageInfo makeColorType(SkColorType newColorType) const { |
| 291 return SkImageInfo(fWidth, fHeight, newColorType, fAlphaType, fProfileTy
pe, fColorSpace); | 310 return Make(fWidth, fHeight, newColorType, fAlphaType, fColorSpace); |
| 292 } | 311 } |
| 293 | 312 |
| 294 SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const { | 313 SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const { |
| 295 return SkImageInfo::Make(fWidth, fHeight, fColorType, fAlphaType, std::m
ove(cs)); | 314 return Make(fWidth, fHeight, fColorType, fAlphaType, std::move(cs)); |
| 296 } | 315 } |
| 297 | 316 |
| 298 int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } | 317 int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } |
| 299 | 318 |
| 300 int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); } | 319 int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); } |
| 301 | 320 |
| 302 uint64_t minRowBytes64() const { | 321 uint64_t minRowBytes64() const { |
| 303 return sk_64_mul(fWidth, this->bytesPerPixel()); | 322 return sk_64_mul(fWidth, this->bytesPerPixel()); |
| 304 } | 323 } |
| 305 | 324 |
| 306 size_t minRowBytes() const { | 325 size_t minRowBytes() const { |
| 307 return (size_t)this->minRowBytes64(); | 326 return (size_t)this->minRowBytes64(); |
| 308 } | 327 } |
| 309 | 328 |
| 310 size_t computeOffset(int x, int y, size_t rowBytes) const { | 329 size_t computeOffset(int x, int y, size_t rowBytes) const { |
| 311 SkASSERT((unsigned)x < (unsigned)fWidth); | 330 SkASSERT((unsigned)x < (unsigned)fWidth); |
| 312 SkASSERT((unsigned)y < (unsigned)fHeight); | 331 SkASSERT((unsigned)y < (unsigned)fHeight); |
| 313 return SkColorTypeComputeOffset(fColorType, x, y, rowBytes); | 332 return SkColorTypeComputeOffset(fColorType, x, y, rowBytes); |
| 314 } | 333 } |
| 315 | 334 |
| 316 bool operator==(const SkImageInfo& other) const { | 335 bool operator==(const SkImageInfo& other) const { |
| 317 return fWidth == other.fWidth && fHeight == other.fHeight && | 336 return fWidth == other.fWidth && fHeight == other.fHeight && |
| 318 fColorType == other.fColorType && fAlphaType == other.fAlphaType
&& | 337 fColorType == other.fColorType && fAlphaType == other.fAlphaType
&& |
| 319 fProfileType == other.fProfileType && fColorSpace == other.fColor
Space; | 338 fColorSpace == other.fColorSpace; |
| 320 } | 339 } |
| 321 bool operator!=(const SkImageInfo& other) const { | 340 bool operator!=(const SkImageInfo& other) const { |
| 322 return fWidth != other.fWidth || fHeight != other.fHeight || | 341 return fWidth != other.fWidth || fHeight != other.fHeight || |
| 323 fColorType != other.fColorType || fAlphaType != other.fAlphaType
|| | 342 fColorType != other.fColorType || fAlphaType != other.fAlphaType
|| |
| 324 fProfileType != other.fProfileType || fColorSpace != other.fColor
Space; | 343 fColorSpace != other.fColorSpace; |
| 325 } | 344 } |
| 326 | 345 |
| 327 void unflatten(SkReadBuffer&); | 346 void unflatten(SkReadBuffer&); |
| 328 void flatten(SkWriteBuffer&) const; | 347 void flatten(SkWriteBuffer&) const; |
| 329 | 348 |
| 330 int64_t getSafeSize64(size_t rowBytes) const { | 349 int64_t getSafeSize64(size_t rowBytes) const { |
| 331 if (0 == fHeight) { | 350 if (0 == fHeight) { |
| 332 return 0; | 351 return 0; |
| 333 } | 352 } |
| 334 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; | 353 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; |
| 335 } | 354 } |
| 336 | 355 |
| 337 size_t getSafeSize(size_t rowBytes) const { | 356 size_t getSafeSize(size_t rowBytes) const { |
| 338 int64_t size = this->getSafeSize64(rowBytes); | 357 int64_t size = this->getSafeSize64(rowBytes); |
| 339 if (!sk_64_isS32(size)) { | 358 if (!sk_64_isS32(size)) { |
| 340 return 0; | 359 return 0; |
| 341 } | 360 } |
| 342 return sk_64_asS32(size); | 361 return sk_64_asS32(size); |
| 343 } | 362 } |
| 344 | 363 |
| 345 bool validRowBytes(size_t rowBytes) const { | 364 bool validRowBytes(size_t rowBytes) const { |
| 346 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); | 365 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); |
| 347 return rowBytes >= rb; | 366 return rowBytes >= rb; |
| 348 } | 367 } |
| 349 | 368 |
| 350 void reset() { | 369 void reset() { |
| 370 fColorSpace = nullptr; |
| 351 fWidth = 0; | 371 fWidth = 0; |
| 352 fHeight = 0; | 372 fHeight = 0; |
| 353 fColorType = kUnknown_SkColorType; | 373 fColorType = kUnknown_SkColorType; |
| 354 fAlphaType = kUnknown_SkAlphaType; | 374 fAlphaType = kUnknown_SkAlphaType; |
| 355 fProfileType = kLinear_SkColorProfileType; | |
| 356 fColorSpace = nullptr; | |
| 357 } | 375 } |
| 358 | 376 |
| 359 SkDEBUGCODE(void validate() const;) | 377 SkDEBUGCODE(void validate() const;) |
| 360 | 378 |
| 361 private: | 379 private: |
| 362 sk_sp<SkColorSpace> fColorSpace; | 380 sk_sp<SkColorSpace> fColorSpace; |
| 363 int fWidth; | 381 int fWidth; |
| 364 int fHeight; | 382 int fHeight; |
| 365 SkColorType fColorType; | 383 SkColorType fColorType; |
| 366 SkAlphaType fAlphaType; | 384 SkAlphaType fAlphaType; |
| 367 SkColorProfileType fProfileType; | |
| 368 | 385 |
| 369 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorPr
ofileType pt, | 386 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, sk_sp<SkC
olorSpace> cs) |
| 370 sk_sp<SkColorSpace> cs) | |
| 371 : fColorSpace(std::move(cs)) | 387 : fColorSpace(std::move(cs)) |
| 372 , fWidth(width) | 388 , fWidth(width) |
| 373 , fHeight(height) | 389 , fHeight(height) |
| 374 , fColorType(ct) | 390 , fColorType(ct) |
| 375 , fAlphaType(at) | 391 , fAlphaType(at) |
| 376 , fProfileType(pt) | |
| 377 {} | 392 {} |
| 378 }; | 393 }; |
| 379 | 394 |
| 380 /////////////////////////////////////////////////////////////////////////////// | 395 /////////////////////////////////////////////////////////////////////////////// |
| 381 | 396 |
| 382 static inline bool SkColorAndColorSpaceAreGammaCorrect(SkColorType ct, SkColorSp
ace* cs) { | 397 static inline bool SkColorAndColorSpaceAreGammaCorrect(SkColorType ct, SkColorSp
ace* cs) { |
| 383 // Anything with a color-space attached is gamma-correct, as is F16. | 398 // Anything with a color-space attached is gamma-correct, as is F16. |
| 384 // To get legacy behavior, you need to ask for non-F16, with a nullptr color
space. | 399 // To get legacy behavior, you need to ask for non-F16, with a nullptr color
space. |
| 385 return (cs != nullptr) || kRGBA_F16_SkColorType == ct; | 400 return (cs != nullptr) || kRGBA_F16_SkColorType == ct; |
| 386 } | 401 } |
| 387 | 402 |
| 388 static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { | 403 static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { |
| 389 return SkColorAndColorSpaceAreGammaCorrect(info.colorType(), info.colorSpace
()); | 404 return SkColorAndColorSpaceAreGammaCorrect(info.colorType(), info.colorSpace
()); |
| 390 } | 405 } |
| 391 | 406 |
| 392 #endif | 407 #endif |
| OLD | NEW |