Chromium Code Reviews| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 kLastEnum_SkColorProfileType = kSRGB_SkColorProfileType | 176 kLastEnum_SkColorProfileType = kSRGB_SkColorProfileType |
| 176 }; | 177 }; |
| 177 | 178 |
| 178 /** | 179 /** |
| 179 * Describe an image's dimensions and pixel type. | 180 * Describe an image's dimensions and pixel type. |
| 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 : fColorSpace(nullptr) |
| 187 , fWidth(0) | |
| 186 , fHeight(0) | 188 , fHeight(0) |
| 187 , fColorType(kUnknown_SkColorType) | 189 , fColorType(kUnknown_SkColorType) |
| 188 , fAlphaType(kUnknown_SkAlphaType) | 190 , fAlphaType(kUnknown_SkAlphaType) |
| 189 , fProfileType(kLinear_SkColorProfileType) | 191 , fProfileType(kLinear_SkColorProfileType) |
| 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(); } | |
|
scroggo
2016/05/31 13:48:25
Now that SkColorSpace is in include/, can this ret
msarett
2016/05/31 14:30:08
Yeah I think it could. The reason I went with a b
scroggo
2016/05/31 14:52:06
I don't think Skia style has been updated, but my
reed1
2016/05/31 22:07:00
That doc needs updating. We have (so far at least)
| |
| 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; | |
|
scroggo
2016/05/31 13:48:25
Doesn't this check whether fColorSpace is the same
msarett
2016/05/31 14:30:08
This is deliberate, though maybe it's the wrong de
scroggo
2016/05/31 14:52:06
FWIW, I don't know that my test case is a normal u
| |
| 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() ; |
| 302 } | 315 } |
| 303 | 316 |
| 304 size_t getSafeSize(size_t rowBytes) const { | 317 size_t getSafeSize(size_t rowBytes) const { |
| 305 int64_t size = this->getSafeSize64(rowBytes); | 318 int64_t size = this->getSafeSize64(rowBytes); |
| 306 if (!sk_64_isS32(size)) { | 319 if (!sk_64_isS32(size)) { |
| 307 return 0; | 320 return 0; |
| 308 } | 321 } |
| 309 return sk_64_asS32(size); | 322 return sk_64_asS32(size); |
| 310 } | 323 } |
| 311 | 324 |
| 312 bool validRowBytes(size_t rowBytes) const { | 325 bool validRowBytes(size_t rowBytes) const { |
| 313 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); | 326 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); |
| 314 return rowBytes >= rb; | 327 return rowBytes >= rb; |
| 315 } | 328 } |
| 316 | 329 |
| 330 void reset() { | |
| 331 fWidth = 0; | |
| 332 fHeight = 0; | |
| 333 fColorType = kUnknown_SkColorType; | |
| 334 fAlphaType = kUnknown_SkAlphaType; | |
| 335 fProfileType = kLinear_SkColorProfileType; | |
| 336 fColorSpace = nullptr; | |
| 337 } | |
| 338 | |
| 317 SkDEBUGCODE(void validate() const;) | 339 SkDEBUGCODE(void validate() const;) |
| 318 | 340 |
| 319 private: | 341 private: |
| 342 sk_sp<SkColorSpace> fColorSpace; | |
| 320 int fWidth; | 343 int fWidth; |
| 321 int fHeight; | 344 int fHeight; |
| 322 SkColorType fColorType; | 345 SkColorType fColorType; |
| 323 SkAlphaType fAlphaType; | 346 SkAlphaType fAlphaType; |
| 324 SkColorProfileType fProfileType; | 347 SkColorProfileType fProfileType; |
| 325 | 348 |
| 326 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorPr ofileType pt) | 349 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorPr ofileType pt, |
| 327 : fWidth(width) | 350 sk_sp<SkColorSpace> cs) |
| 351 : fColorSpace(std::move(cs)) | |
| 352 , fWidth(width) | |
| 328 , fHeight(height) | 353 , fHeight(height) |
| 329 , fColorType(ct) | 354 , fColorType(ct) |
| 330 , fAlphaType(at) | 355 , fAlphaType(at) |
| 331 , fProfileType(pt) | 356 , fProfileType(pt) |
| 332 {} | 357 {} |
| 333 }; | 358 }; |
| 334 | 359 |
| 335 /////////////////////////////////////////////////////////////////////////////// | 360 /////////////////////////////////////////////////////////////////////////////// |
| 336 | 361 |
| 337 static inline bool SkColorAndProfileAreGammaCorrect(SkColorType ct, SkColorProfi leType pt) { | 362 static inline bool SkColorAndProfileAreGammaCorrect(SkColorType ct, SkColorProfi leType pt) { |
| 338 return kSRGB_SkColorProfileType == pt || kRGBA_F16_SkColorType == ct; | 363 return kSRGB_SkColorProfileType == pt || kRGBA_F16_SkColorType == ct; |
| 339 } | 364 } |
| 340 | 365 |
| 341 static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { | 366 static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { |
| 342 return SkColorAndProfileAreGammaCorrect(info.colorType(), info.profileType() ); | 367 return SkColorAndProfileAreGammaCorrect(info.colorType(), info.profileType() ); |
| 343 } | 368 } |
| 344 | 369 |
| 345 #endif | 370 #endif |
| OLD | NEW |