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>
This commit is contained in:
Brian Osman 2017-12-21 13:40:25 -05:00 committed by Skia Commit-Bot
parent 4aa4441186
commit e9edf8cc50
8 changed files with 31 additions and 32 deletions

View File

@ -119,6 +119,8 @@ public:
static sk_sp<SkColorSpace> MakeRGB(const SkColorSpaceTransferFn& coeffs, static sk_sp<SkColorSpace> MakeRGB(const SkColorSpaceTransferFn& coeffs,
const SkMatrix44& toXYZD50); const SkMatrix44& toXYZD50);
static sk_sp<SkColorSpace> MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50);
/** /**
* Create an SkColorSpace from an ICC profile. * Create an SkColorSpace from an ICC profile.
*/ */
@ -250,6 +252,8 @@ private:
virtual bool onIsNumericalTransferFn(SkColorSpaceTransferFn* coeffs) const = 0; virtual bool onIsNumericalTransferFn(SkColorSpaceTransferFn* coeffs) const = 0;
virtual bool onIsCMYK() const { return false; } virtual bool onIsCMYK() const { return false; }
virtual const SkData* onProfileData() const { return nullptr; }
using INHERITED = SkRefCnt; using INHERITED = SkRefCnt;
}; };

View File

@ -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. * 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); 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) { switch (gammaNamed) {
case kSRGB_SkGammaNamed: 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) { sk_sp<SkColorSpace> SkColorSpace::MakeRGB(RenderTargetGamma gamma, const SkMatrix44& toXYZD50) {
switch (gamma) { switch (gamma) {
case kLinear_RenderTargetGamma: case kLinear_RenderTargetGamma:
return SkColorSpace_Base::MakeRGB(kLinear_SkGammaNamed, toXYZD50); return SkColorSpace::MakeRGB(kLinear_SkGammaNamed, toXYZD50);
case kSRGB_RenderTargetGamma: case kSRGB_RenderTargetGamma:
return SkColorSpace_Base::MakeRGB(kSRGB_SkGammaNamed, toXYZD50); return SkColorSpace::MakeRGB(kSRGB_SkGammaNamed, toXYZD50);
default: default:
return nullptr; return nullptr;
} }
@ -161,15 +157,15 @@ sk_sp<SkColorSpace> SkColorSpace::MakeRGB(const SkColorSpaceTransferFn& coeffs,
} }
if (is_almost_srgb(coeffs)) { if (is_almost_srgb(coeffs)) {
return SkColorSpace::MakeRGB(kSRGB_RenderTargetGamma, toXYZD50); return SkColorSpace::MakeRGB(kSRGB_SkGammaNamed, toXYZD50);
} }
if (is_almost_2dot2(coeffs)) { if (is_almost_2dot2(coeffs)) {
return SkColorSpace_Base::MakeRGB(k2Dot2Curve_SkGammaNamed, toXYZD50); return SkColorSpace::MakeRGB(k2Dot2Curve_SkGammaNamed, toXYZD50);
} }
if (is_almost_linear(coeffs)) { 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)); void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkColorSpaceTransferFn));
@ -339,7 +335,7 @@ struct ColorSpaceHeader {
size_t SkColorSpace::writeToMemory(void* memory) const { size_t SkColorSpace::writeToMemory(void* memory) const {
// Start by trying the serialization fast path. If we haven't saved ICC profile data, // 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. // 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. // Profile data is mandatory for A2B0 color spaces.
SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(this)->type()); SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(this)->type());
const SkColorSpace_XYZ* thisXYZ = static_cast<const SkColorSpace_XYZ*>(this); 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. // 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)) { if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) {
return 0; return 0;
} }
@ -420,7 +416,7 @@ size_t SkColorSpace::writeToMemory(void* memory) const {
*((uint32_t*) memory) = (uint32_t) SkAlign4(profileSize); *((uint32_t*) memory) = (uint32_t) SkAlign4(profileSize);
memory = SkTAddOffset<void>(memory, sizeof(uint32_t)); 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); memset(SkTAddOffset<void>(memory, profileSize), 0, SkAlign4(profileSize) - profileSize);
} }
return sizeof(ColorSpaceHeader) + sizeof(uint32_t) + SkAlign4(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); SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor);
toXYZ.set3x4RowMajorf((const float*) data); toXYZ.set3x4RowMajorf((const float*) data);
return SkColorSpace_Base::MakeRGB((SkGammaNamed) header.fGammaNamed, toXYZ); return SkColorSpace::MakeRGB((SkGammaNamed) header.fGammaNamed, toXYZ);
} }
default: default:
break; break;
@ -520,8 +516,8 @@ bool SkColorSpace::Equals(const SkColorSpace* src, const SkColorSpace* dst) {
return false; return false;
} }
SkData* srcData = as_CSB(src)->fProfileData.get(); const SkData* srcData = src->onProfileData();
SkData* dstData = as_CSB(dst)->fProfileData.get(); const SkData* dstData = dst->onProfileData();
if (srcData || dstData) { if (srcData || dstData) {
if (srcData && dstData) { if (srcData && dstData) {
return srcData->size() == dstData->size() && return srcData->size() == dstData->size() &&

View File

@ -9,7 +9,7 @@
SkColorSpace_A2B::SkColorSpace_A2B(SkColorSpace::Type iccType, std::vector<Element> elements, SkColorSpace_A2B::SkColorSpace_A2B(SkColorSpace::Type iccType, std::vector<Element> elements,
PCS pcs, sk_sp<SkData> profileData) PCS pcs, sk_sp<SkData> profileData)
: INHERITED(std::move(profileData)) : fProfileData(std::move(profileData))
, fICCType(iccType) , fICCType(iccType)
, fElements(std::move(elements)) , fElements(std::move(elements))
, fPCS(pcs) , fPCS(pcs)

View File

@ -55,6 +55,8 @@ public:
bool onIsCMYK() const override { return SkColorSpace::kCMYK_Type == fICCType; } bool onIsCMYK() const override { return SkColorSpace::kCMYK_Type == fICCType; }
const SkData* onProfileData() const override { return fProfileData.get(); }
sk_sp<SkColorSpace> makeLinearGamma() const override { sk_sp<SkColorSpace> makeLinearGamma() const override {
// TODO: Analyze the extrema of our projection into XYZ and use suitable primaries? // 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. // 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); sk_sp<SkData> profileData);
private: private:
sk_sp<SkData> fProfileData;
SkColorSpace::Type fICCType; SkColorSpace::Type fICCType;
std::vector<Element> fElements; std::vector<Element> fElements;
PCS fPCS; PCS fPCS;

View File

@ -139,14 +139,7 @@ public:
virtual Type type() const = 0; virtual Type type() const = 0;
static sk_sp<SkColorSpace> MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50);
protected:
SkColorSpace_Base(sk_sp<SkData> profileData);
private: private:
sk_sp<SkData> fProfileData;
friend class SkColorSpace; friend class SkColorSpace;
friend class SkColorSpace_XYZ; friend class SkColorSpace_XYZ;
friend class ColorSpaceXformTest; friend class ColorSpaceXformTest;

View File

@ -1427,7 +1427,7 @@ static sk_sp<SkColorSpace> make_xyz(const ICCProfileHeader& header, ICCTag* tags
mat, std::move(profileData))); 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, 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(1, 1, kWhitePointD50[1]);
toXYZD50.setFloat(2, 2, kWhitePointD50[2]); toXYZD50.setFloat(2, 2, kWhitePointD50[2]);
if (SkGammas::Type::kNamed_Type == type) { if (SkGammas::Type::kNamed_Type == type) {
return SkColorSpace_Base::MakeRGB(data.fNamed, toXYZD50); return SkColorSpace::MakeRGB(data.fNamed, toXYZD50);
} }
size_t allocSize = sizeof(SkGammas); size_t allocSize = sizeof(SkGammas);

View File

@ -11,7 +11,7 @@
#include "SkOpts.h" #include "SkOpts.h"
SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50) SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50)
: INHERITED(nullptr) : fProfileData(nullptr)
, fGammaNamed(gammaNamed) , fGammaNamed(gammaNamed)
, fGammas(nullptr) , fGammas(nullptr)
, fToXYZD50(toXYZD50) , 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, SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, sk_sp<SkGammas> gammas,
const SkMatrix44& toXYZD50, sk_sp<SkData> profileData) const SkMatrix44& toXYZD50, sk_sp<SkData> profileData)
: INHERITED(std::move(profileData)) : fProfileData(std::move(profileData))
, fGammaNamed(gammaNamed) , fGammaNamed(gammaNamed)
, fGammas(std::move(gammas)) , fGammas(std::move(gammas))
, fToXYZD50(toXYZD50) , fToXYZD50(toXYZD50)
@ -86,14 +86,14 @@ sk_sp<SkColorSpace> SkColorSpace_XYZ::makeLinearGamma() const {
if (this->gammaIsLinear()) { if (this->gammaIsLinear()) {
return sk_ref_sp(const_cast<SkColorSpace_XYZ*>(this)); 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 { sk_sp<SkColorSpace> SkColorSpace_XYZ::makeSRGBGamma() const {
if (this->gammaCloseToSRGB()) { if (this->gammaCloseToSRGB()) {
return sk_ref_sp(const_cast<SkColorSpace_XYZ*>(this)); 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 { sk_sp<SkColorSpace> SkColorSpace_XYZ::makeColorSpin() const {

View File

@ -20,11 +20,11 @@ public:
const SkMatrix44* onFromXYZD50() const override; const SkMatrix44* onFromXYZD50() const override;
bool onGammaCloseToSRGB() const override; bool onGammaCloseToSRGB() const override;
bool onGammaIsLinear() const override; bool onGammaIsLinear() const override;
bool onIsNumericalTransferFn(SkColorSpaceTransferFn* coeffs) const override; bool onIsNumericalTransferFn(SkColorSpaceTransferFn* coeffs) const override;
const SkData* onProfileData() const override { return fProfileData.get(); }
Type type() const override { return Type::kXYZ; } Type type() const override { return Type::kXYZ; }
sk_sp<SkColorSpace> makeLinearGamma() const override; sk_sp<SkColorSpace> makeLinearGamma() const override;
@ -43,6 +43,8 @@ public:
const SkMatrix44& toXYZ, sk_sp<SkData> profileData); const SkMatrix44& toXYZ, sk_sp<SkData> profileData);
private: private:
sk_sp<SkData> fProfileData;
const SkGammaNamed fGammaNamed; const SkGammaNamed fGammaNamed;
sk_sp<SkGammas> fGammas; sk_sp<SkGammas> fGammas;
const SkMatrix44 fToXYZD50; const SkMatrix44 fToXYZD50;