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:
parent
4aa4441186
commit
e9edf8cc50
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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() &&
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user