diff options
author | msarett <msarett@google.com> | 2016-05-27 07:39:02 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-27 07:39:02 -0700 |
commit | 23c5110ba291cfc303e3fdc73af99cd3d595df67 (patch) | |
tree | e91dd207442d664baed99bdce4579011203908ba | |
parent | 85f758c33446eaccfadc12292fa5a0e71d7661b9 (diff) |
Add SkColorSpace to SkImageInfo
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2000713003
Review-Url: https://codereview.chromium.org/2000713003
-rw-r--r-- | include/codec/SkEncodedInfo.h | 16 | ||||
-rw-r--r-- | include/core/SkImageInfo.h | 51 | ||||
-rw-r--r-- | src/codec/SkCodec.cpp | 4 | ||||
-rw-r--r-- | src/core/SkBitmap.cpp | 2 | ||||
-rw-r--r-- | src/core/SkImageInfo.cpp | 5 | ||||
-rw-r--r-- | src/core/SkMipMap.cpp | 2 | ||||
-rw-r--r-- | tests/ImageIsOpaqueTest.cpp | 4 |
7 files changed, 58 insertions, 26 deletions
diff --git a/include/codec/SkEncodedInfo.h b/include/codec/SkEncodedInfo.h index 0c5bd0b421..d35aa2bab4 100644 --- a/include/codec/SkEncodedInfo.h +++ b/include/codec/SkEncodedInfo.h @@ -9,7 +9,8 @@ #define SkEncodedInfo_DEFINED #include "SkImageInfo.h" -#include "../private/SkImageInfoPriv.h" + +class SkColorSpace; struct SkEncodedInfo { public: @@ -116,22 +117,21 @@ public: * Returns an SkImageInfo with Skia color and alpha types that are the * closest possible match to the encoded info. */ - SkImageInfo makeImageInfo(int width, int height) const { - SkColorProfileType profileType = SkDefaultColorProfile(); + SkImageInfo makeImageInfo(int width, int height, const sk_sp<SkColorSpace>& colorSpace) const { switch (fColor) { case kGray_Color: SkASSERT(kOpaque_Alpha == fAlpha); return SkImageInfo::Make(width, height, kGray_8_SkColorType, - kOpaque_SkAlphaType, profileType); + kOpaque_SkAlphaType, colorSpace); case kGrayAlpha_Color: SkASSERT(kOpaque_Alpha != fAlpha); return SkImageInfo::Make(width, height, kN32_SkColorType, - kUnpremul_SkAlphaType, profileType); + kUnpremul_SkAlphaType, colorSpace); case kPalette_Color: { SkAlphaType alphaType = (kOpaque_Alpha == fAlpha) ? kOpaque_SkAlphaType : kUnpremul_SkAlphaType; return SkImageInfo::Make(width, height, kIndex_8_SkColorType, - alphaType, profileType); + alphaType, colorSpace); } case kRGB_Color: case kBGR_Color: @@ -141,13 +141,13 @@ public: case kYCCK_Color: SkASSERT(kOpaque_Alpha == fAlpha); return SkImageInfo::Make(width, height, kN32_SkColorType, - kOpaque_SkAlphaType, profileType); + kOpaque_SkAlphaType, colorSpace); case kRGBA_Color: case kBGRA_Color: case kYUVA_Color: SkASSERT(kOpaque_Alpha != fAlpha); return SkImageInfo::Make(width, height, kN32_SkColorType, - kUnpremul_SkAlphaType, profileType); + kUnpremul_SkAlphaType, colorSpace); default: SkASSERT(false); return SkImageInfo::MakeUnknown(); diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index 4b308c05d8..af3d7393b3 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -8,6 +8,7 @@ #ifndef SkImageInfo_DEFINED #define SkImageInfo_DEFINED +#include "SkColorSpace.h" #include "SkMath.h" #include "SkRect.h" #include "SkSize.h" @@ -182,7 +183,8 @@ enum SkColorProfileType { struct SK_API SkImageInfo { public: SkImageInfo() - : fWidth(0) + : fColorSpace(nullptr) + , fWidth(0) , fHeight(0) , fColorType(kUnknown_SkColorType) , fAlphaType(kUnknown_SkAlphaType) @@ -191,15 +193,18 @@ public: static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at, SkColorProfileType pt = kLinear_SkColorProfileType) { - return SkImageInfo(width, height, ct, at, pt); + return SkImageInfo(width, height, ct, at, pt, nullptr); } + static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at, + sk_sp<SkColorSpace> cs); + /** * Sets colortype to the native ARGB32 type. */ static SkImageInfo MakeN32(int width, int height, SkAlphaType at, SkColorProfileType pt = kLinear_SkColorProfileType) { - return SkImageInfo(width, height, kN32_SkColorType, at, pt); + return SkImageInfo(width, height, kN32_SkColorType, at, pt, nullptr); } /** @@ -207,7 +212,7 @@ public: */ static SkImageInfo MakeN32Premul(int width, int height, SkColorProfileType pt = kLinear_SkColorProfileType) { - return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType, pt); + return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType, pt, nullptr); } /** @@ -220,12 +225,12 @@ public: static SkImageInfo MakeA8(int width, int height) { return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType, - kLinear_SkColorProfileType); + kLinear_SkColorProfileType, nullptr); } static SkImageInfo MakeUnknown(int width, int height) { return SkImageInfo(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType, - kLinear_SkColorProfileType); + kLinear_SkColorProfileType, nullptr); } static SkImageInfo MakeUnknown() { @@ -236,6 +241,9 @@ public: int height() const { return fHeight; } SkColorType colorType() const { return fColorType; } SkAlphaType alphaType() const { return fAlphaType; } + SkColorSpace* colorSpace() const { return fColorSpace.get(); } + + // Deprecated SkColorProfileType profileType() const { return fProfileType; } bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } @@ -244,6 +252,7 @@ public: return SkAlphaTypeIsOpaque(fAlphaType); } + // Deprecated bool isLinear() const { return kLinear_SkColorProfileType == fProfileType; } bool isSRGB() const { return kSRGB_SkColorProfileType == fProfileType; } @@ -255,15 +264,15 @@ public: * but with the specified width and height. */ SkImageInfo makeWH(int newWidth, int newHeight) const { - return SkImageInfo::Make(newWidth, newHeight, fColorType, fAlphaType, fProfileType); + return SkImageInfo(newWidth, newHeight, fColorType, fAlphaType, fProfileType, fColorSpace); } SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { - return SkImageInfo::Make(fWidth, fHeight, fColorType, newAlphaType, fProfileType); + return SkImageInfo(fWidth, fHeight, fColorType, newAlphaType, fProfileType, fColorSpace); } SkImageInfo makeColorType(SkColorType newColorType) const { - return SkImageInfo::Make(fWidth, fHeight, newColorType, fAlphaType, fProfileType); + return SkImageInfo(fWidth, fHeight, newColorType, fAlphaType, fProfileType, fColorSpace); } int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } @@ -285,10 +294,14 @@ public: } bool operator==(const SkImageInfo& other) const { - return 0 == memcmp(this, &other, sizeof(other)); + return fWidth == other.fWidth && fHeight == other.fHeight && + fColorType == other.fColorType && fAlphaType == other.fAlphaType && + fProfileType == other.fProfileType && fColorSpace == other.fColorSpace; } bool operator!=(const SkImageInfo& other) const { - return 0 != memcmp(this, &other, sizeof(other)); + return fWidth != other.fWidth || fHeight != other.fHeight || + fColorType != other.fColorType || fAlphaType != other.fAlphaType || + fProfileType != other.fProfileType || fColorSpace != other.fColorSpace; } void unflatten(SkReadBuffer&); @@ -314,17 +327,29 @@ public: return rowBytes >= rb; } + void reset() { + fWidth = 0; + fHeight = 0; + fColorType = kUnknown_SkColorType; + fAlphaType = kUnknown_SkAlphaType; + fProfileType = kLinear_SkColorProfileType; + fColorSpace = nullptr; + } + SkDEBUGCODE(void validate() const;) private: + sk_sp<SkColorSpace> fColorSpace; int fWidth; int fHeight; SkColorType fColorType; SkAlphaType fAlphaType; SkColorProfileType fProfileType; - SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorProfileType pt) - : fWidth(width) + SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorProfileType pt, + sk_sp<SkColorSpace> cs) + : fColorSpace(std::move(cs)) + , fWidth(width) , fHeight(height) , fColorType(ct) , fAlphaType(at) diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index 955c86d609..3da7f5fb07 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -117,10 +117,10 @@ SkCodec* SkCodec::NewFromData(SkData* data, SkPngChunkReader* reader) { SkCodec::SkCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream, sk_sp<SkColorSpace> colorSpace, Origin origin) : fEncodedInfo(info) - , fSrcInfo(info.makeImageInfo(width, height)) + , fSrcInfo(info.makeImageInfo(width, height, colorSpace)) , fStream(stream) , fNeedsRewind(false) - , fColorSpace(colorSpace) + , fColorSpace(std::move(colorSpace)) , fOrigin(origin) , fDstInfo() , fOptions() diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 3bb763b4f4..f9deb837fa 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -53,6 +53,7 @@ SkBitmap& SkBitmap::operator=(const SkBitmap& src) { // inc src reference counts SkSafeRef(src.fPixelRef); + SkSafeRef(src.fInfo.colorSpace()); // we reset our locks if we get blown away fPixelLockCount = 0; @@ -97,6 +98,7 @@ void SkBitmap::swap(SkBitmap& other) { void SkBitmap::reset() { this->freePixels(); + this->fInfo.reset(); sk_bzero(this, sizeof(*this)); } diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp index 5f0a4919ee..81a68f3de3 100644 --- a/src/core/SkImageInfo.cpp +++ b/src/core/SkImageInfo.cpp @@ -30,6 +30,11 @@ static bool color_type_is_valid(SkColorType colorType) { return (colorType >= 0) && (colorType <= kLastEnum_SkColorType); } +SkImageInfo SkImageInfo::Make(int width, int height, SkColorType ct, SkAlphaType at, + sk_sp<SkColorSpace> cs) { + return SkImageInfo(width, height, ct, at, SkDefaultColorProfile(), std::move(cs)); +} + void SkImageInfo::unflatten(SkReadBuffer& buffer) { fWidth = buffer.read32(); fHeight = buffer.read32(); diff --git a/src/core/SkMipMap.cpp b/src/core/SkMipMap.cpp index f579aae955..c851d64a90 100644 --- a/src/core/SkMipMap.cpp +++ b/src/core/SkMipMap.cpp @@ -451,7 +451,7 @@ SkMipMap* SkMipMap::Build(const SkPixmap& src, SkDiscardableFactoryProc fact) { height = SkTMax(1, height >> 1); rowBytes = SkToU32(SkColorTypeMinRowBytes(ct, width)); - levels[i].fPixmap = SkPixmap(SkImageInfo::Make(width, height, ct, at), addr, rowBytes); + new (&levels[i].fPixmap) SkPixmap(SkImageInfo::Make(width, height, ct, at), addr, rowBytes); levels[i].fScale = SkSize::Make(SkIntToScalar(width) / src.width(), SkIntToScalar(height) / src.height()); diff --git a/tests/ImageIsOpaqueTest.cpp b/tests/ImageIsOpaqueTest.cpp index d513e89ad2..52d3b97c52 100644 --- a/tests/ImageIsOpaqueTest.cpp +++ b/tests/ImageIsOpaqueTest.cpp @@ -24,10 +24,10 @@ static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info) SkASSERT(wb.bytesWritten() < sizeof(storage)); SkReadBuffer rb(storage, wb.bytesWritten()); - SkImageInfo info2; // pick a noisy byte pattern, so we ensure that unflatten sets all of our fields - memset(&info2, 0xB8, sizeof(info2)); + SkImageInfo info2 = SkImageInfo::Make(0xB8, 0xB8, (SkColorType) 0xB8, (SkAlphaType) 0xB8, + (SkColorProfileType) 0xB8); info2.unflatten(rb); REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten()); |