diff options
author | Brian Osman <brianosman@google.com> | 2017-12-21 13:40:25 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-21 21:01:35 +0000 |
commit | e9edf8cc50e50998f7074023f974ec034cfcec4c (patch) | |
tree | 945ec982008e0f88c0b40c76e172de2387899e4f | |
parent | 4aa4441186b06565a597ec4a9baac5a972fddb51 (diff) |
Remove more functionality from SkColorSpace_Base
Push profile data into XYZ and A2B classes
Move SkColorSpace_Base::MakeRGB to SkColorSpace
Bug: skia:
Change-Id: I4782eb2a5c77b54d302e1982654755015dea7651
Reviewed-on: https://skia-review.googlesource.com/88560
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
-rw-r--r-- | include/core/SkColorSpace.h | 4 | ||||
-rw-r--r-- | src/core/SkColorSpace.cpp | 28 | ||||
-rw-r--r-- | src/core/SkColorSpace_A2B.cpp | 2 | ||||
-rw-r--r-- | src/core/SkColorSpace_A2B.h | 4 | ||||
-rw-r--r-- | src/core/SkColorSpace_Base.h | 7 | ||||
-rw-r--r-- | src/core/SkColorSpace_ICC.cpp | 4 | ||||
-rw-r--r-- | src/core/SkColorSpace_XYZ.cpp | 8 | ||||
-rw-r--r-- | src/core/SkColorSpace_XYZ.h | 6 |
8 files changed, 31 insertions, 32 deletions
diff --git a/include/core/SkColorSpace.h b/include/core/SkColorSpace.h index d1d32abaa2..2908268306 100644 --- a/include/core/SkColorSpace.h +++ b/include/core/SkColorSpace.h @@ -119,6 +119,8 @@ public: static sk_sp<SkColorSpace> MakeRGB(const SkColorSpaceTransferFn& coeffs, const SkMatrix44& toXYZD50); + static sk_sp<SkColorSpace> MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50); + /** * Create an SkColorSpace from an ICC profile. */ @@ -250,6 +252,8 @@ private: virtual bool onIsNumericalTransferFn(SkColorSpaceTransferFn* coeffs) const = 0; virtual bool onIsCMYK() const { return false; } + virtual const SkData* onProfileData() const { return nullptr; } + using INHERITED = SkRefCnt; }; diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp index 235518d3b9..a1859fb2a5 100644 --- a/src/core/SkColorSpace.cpp +++ b/src/core/SkColorSpace.cpp @@ -82,10 +82,6 @@ bool SkColorSpacePrimaries::toXYZD50(SkMatrix44* toXYZ_D50) const { /////////////////////////////////////////////////////////////////////////////////////////////////// -SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkData> profileData) - : fProfileData(std::move(profileData)) -{} - /** * Checks if our toXYZ matrix is a close match to a known color gamut. * @@ -111,7 +107,7 @@ static bool xyz_almost_equal(const SkMatrix44& toXYZD50, const float* standard) color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f); } -sk_sp<SkColorSpace> SkColorSpace_Base::MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50) +sk_sp<SkColorSpace> SkColorSpace::MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50) { switch (gammaNamed) { case kSRGB_SkGammaNamed: @@ -146,9 +142,9 @@ sk_sp<SkColorSpace> SkColorSpace_Base::MakeRGB(SkGammaNamed gammaNamed, const Sk sk_sp<SkColorSpace> SkColorSpace::MakeRGB(RenderTargetGamma gamma, const SkMatrix44& toXYZD50) { switch (gamma) { case kLinear_RenderTargetGamma: - return SkColorSpace_Base::MakeRGB(kLinear_SkGammaNamed, toXYZD50); + return SkColorSpace::MakeRGB(kLinear_SkGammaNamed, toXYZD50); case kSRGB_RenderTargetGamma: - return SkColorSpace_Base::MakeRGB(kSRGB_SkGammaNamed, toXYZD50); + return SkColorSpace::MakeRGB(kSRGB_SkGammaNamed, toXYZD50); default: return nullptr; } @@ -161,15 +157,15 @@ sk_sp<SkColorSpace> SkColorSpace::MakeRGB(const SkColorSpaceTransferFn& coeffs, } if (is_almost_srgb(coeffs)) { - return SkColorSpace::MakeRGB(kSRGB_RenderTargetGamma, toXYZD50); + return SkColorSpace::MakeRGB(kSRGB_SkGammaNamed, toXYZD50); } if (is_almost_2dot2(coeffs)) { - return SkColorSpace_Base::MakeRGB(k2Dot2Curve_SkGammaNamed, toXYZD50); + return SkColorSpace::MakeRGB(k2Dot2Curve_SkGammaNamed, toXYZD50); } if (is_almost_linear(coeffs)) { - return SkColorSpace_Base::MakeRGB(kLinear_SkGammaNamed, toXYZD50); + return SkColorSpace::MakeRGB(kLinear_SkGammaNamed, toXYZD50); } void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkColorSpaceTransferFn)); @@ -339,7 +335,7 @@ struct ColorSpaceHeader { size_t SkColorSpace::writeToMemory(void* memory) const { // Start by trying the serialization fast path. If we haven't saved ICC profile data, // we must have a profile that we can serialize easily. - if (!as_CSB(this)->fProfileData) { + if (!this->onProfileData()) { // Profile data is mandatory for A2B0 color spaces. SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(this)->type()); const SkColorSpace_XYZ* thisXYZ = static_cast<const SkColorSpace_XYZ*>(this); @@ -406,7 +402,7 @@ size_t SkColorSpace::writeToMemory(void* memory) const { } // Otherwise, serialize the ICC data. - size_t profileSize = as_CSB(this)->fProfileData->size(); + size_t profileSize = this->onProfileData()->size(); if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { return 0; } @@ -420,7 +416,7 @@ size_t SkColorSpace::writeToMemory(void* memory) const { *((uint32_t*) memory) = (uint32_t) SkAlign4(profileSize); memory = SkTAddOffset<void>(memory, sizeof(uint32_t)); - memcpy(memory, as_CSB(this)->fProfileData->data(), profileSize); + memcpy(memory, this->onProfileData()->data(), profileSize); memset(SkTAddOffset<void>(memory, profileSize), 0, SkAlign4(profileSize) - profileSize); } return sizeof(ColorSpaceHeader) + sizeof(uint32_t) + SkAlign4(profileSize); @@ -466,7 +462,7 @@ sk_sp<SkColorSpace> SkColorSpace::Deserialize(const void* data, size_t length) { SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); toXYZ.set3x4RowMajorf((const float*) data); - return SkColorSpace_Base::MakeRGB((SkGammaNamed) header.fGammaNamed, toXYZ); + return SkColorSpace::MakeRGB((SkGammaNamed) header.fGammaNamed, toXYZ); } default: break; @@ -520,8 +516,8 @@ bool SkColorSpace::Equals(const SkColorSpace* src, const SkColorSpace* dst) { return false; } - SkData* srcData = as_CSB(src)->fProfileData.get(); - SkData* dstData = as_CSB(dst)->fProfileData.get(); + const SkData* srcData = src->onProfileData(); + const SkData* dstData = dst->onProfileData(); if (srcData || dstData) { if (srcData && dstData) { return srcData->size() == dstData->size() && diff --git a/src/core/SkColorSpace_A2B.cpp b/src/core/SkColorSpace_A2B.cpp index b5d8d37747..295f28f857 100644 --- a/src/core/SkColorSpace_A2B.cpp +++ b/src/core/SkColorSpace_A2B.cpp @@ -9,7 +9,7 @@ SkColorSpace_A2B::SkColorSpace_A2B(SkColorSpace::Type iccType, std::vector<Element> elements, PCS pcs, sk_sp<SkData> profileData) - : INHERITED(std::move(profileData)) + : fProfileData(std::move(profileData)) , fICCType(iccType) , fElements(std::move(elements)) , fPCS(pcs) diff --git a/src/core/SkColorSpace_A2B.h b/src/core/SkColorSpace_A2B.h index ca78c64db9..9bdd8ef10a 100644 --- a/src/core/SkColorSpace_A2B.h +++ b/src/core/SkColorSpace_A2B.h @@ -55,6 +55,8 @@ public: bool onIsCMYK() const override { return SkColorSpace::kCMYK_Type == fICCType; } + const SkData* onProfileData() const override { return fProfileData.get(); } + sk_sp<SkColorSpace> makeLinearGamma() const override { // TODO: Analyze the extrema of our projection into XYZ and use suitable primaries? // For now, just fall back to a default, because we don't have a good answer. @@ -168,6 +170,8 @@ public: sk_sp<SkData> profileData); private: + sk_sp<SkData> fProfileData; + SkColorSpace::Type fICCType; std::vector<Element> fElements; PCS fPCS; diff --git a/src/core/SkColorSpace_Base.h b/src/core/SkColorSpace_Base.h index 1b58280ccb..39522f71de 100644 --- a/src/core/SkColorSpace_Base.h +++ b/src/core/SkColorSpace_Base.h @@ -139,14 +139,7 @@ public: virtual Type type() const = 0; - static sk_sp<SkColorSpace> MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50); - -protected: - SkColorSpace_Base(sk_sp<SkData> profileData); - private: - sk_sp<SkData> fProfileData; - friend class SkColorSpace; friend class SkColorSpace_XYZ; friend class ColorSpaceXformTest; diff --git a/src/core/SkColorSpace_ICC.cpp b/src/core/SkColorSpace_ICC.cpp index 78318f6a56..a9a53dafad 100644 --- a/src/core/SkColorSpace_ICC.cpp +++ b/src/core/SkColorSpace_ICC.cpp @@ -1427,7 +1427,7 @@ static sk_sp<SkColorSpace> make_xyz(const ICCProfileHeader& header, ICCTag* tags mat, std::move(profileData))); } - return SkColorSpace_Base::MakeRGB(gammaNamed, mat); + return SkColorSpace::MakeRGB(gammaNamed, mat); } static sk_sp<SkColorSpace> make_gray(const ICCProfileHeader& header, ICCTag* tags, int tagCount, @@ -1452,7 +1452,7 @@ static sk_sp<SkColorSpace> make_gray(const ICCProfileHeader& header, ICCTag* tag toXYZD50.setFloat(1, 1, kWhitePointD50[1]); toXYZD50.setFloat(2, 2, kWhitePointD50[2]); if (SkGammas::Type::kNamed_Type == type) { - return SkColorSpace_Base::MakeRGB(data.fNamed, toXYZD50); + return SkColorSpace::MakeRGB(data.fNamed, toXYZD50); } size_t allocSize = sizeof(SkGammas); diff --git a/src/core/SkColorSpace_XYZ.cpp b/src/core/SkColorSpace_XYZ.cpp index 34a93f7047..105ed0f425 100644 --- a/src/core/SkColorSpace_XYZ.cpp +++ b/src/core/SkColorSpace_XYZ.cpp @@ -11,7 +11,7 @@ #include "SkOpts.h" SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50) - : INHERITED(nullptr) + : fProfileData(nullptr) , fGammaNamed(gammaNamed) , fGammas(nullptr) , fToXYZD50(toXYZD50) @@ -21,7 +21,7 @@ SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, const SkMatrix44& to SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, sk_sp<SkGammas> gammas, const SkMatrix44& toXYZD50, sk_sp<SkData> profileData) - : INHERITED(std::move(profileData)) + : fProfileData(std::move(profileData)) , fGammaNamed(gammaNamed) , fGammas(std::move(gammas)) , fToXYZD50(toXYZD50) @@ -86,14 +86,14 @@ sk_sp<SkColorSpace> SkColorSpace_XYZ::makeLinearGamma() const { if (this->gammaIsLinear()) { return sk_ref_sp(const_cast<SkColorSpace_XYZ*>(this)); } - return SkColorSpace_Base::MakeRGB(kLinear_SkGammaNamed, fToXYZD50); + return SkColorSpace::MakeRGB(kLinear_SkGammaNamed, fToXYZD50); } sk_sp<SkColorSpace> SkColorSpace_XYZ::makeSRGBGamma() const { if (this->gammaCloseToSRGB()) { return sk_ref_sp(const_cast<SkColorSpace_XYZ*>(this)); } - return SkColorSpace_Base::MakeRGB(kSRGB_SkGammaNamed, fToXYZD50); + return SkColorSpace::MakeRGB(kSRGB_SkGammaNamed, fToXYZD50); } sk_sp<SkColorSpace> SkColorSpace_XYZ::makeColorSpin() const { diff --git a/src/core/SkColorSpace_XYZ.h b/src/core/SkColorSpace_XYZ.h index 4e12a5a4b5..78b048e4f7 100644 --- a/src/core/SkColorSpace_XYZ.h +++ b/src/core/SkColorSpace_XYZ.h @@ -20,11 +20,11 @@ public: const SkMatrix44* onFromXYZD50() const override; bool onGammaCloseToSRGB() const override; - bool onGammaIsLinear() const override; - bool onIsNumericalTransferFn(SkColorSpaceTransferFn* coeffs) const override; + const SkData* onProfileData() const override { return fProfileData.get(); } + Type type() const override { return Type::kXYZ; } sk_sp<SkColorSpace> makeLinearGamma() const override; @@ -43,6 +43,8 @@ public: const SkMatrix44& toXYZ, sk_sp<SkData> profileData); private: + sk_sp<SkData> fProfileData; + const SkGammaNamed fGammaNamed; sk_sp<SkGammas> fGammas; const SkMatrix44 fToXYZD50; |