diff options
author | msarett <msarett@google.com> | 2016-07-29 08:58:33 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-29 08:58:33 -0700 |
commit | a714bc39294f19500269c8ec536139f75c4b1f25 (patch) | |
tree | ace87a445541ac0270ee318470c1f08773ee177e /src | |
parent | 00db3fd7a790ecfbb4ce3c65572e1bee2a0078db (diff) |
Fix various SkColorSpace bugs
(1) Fixes serialization/deserialization of wacky SkColorSpaces
(2) Fix gamma equals checking
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2194903002
Review-Url: https://codereview.chromium.org/2194903002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkColorSpace.cpp | 66 | ||||
-rw-r--r-- | src/core/SkColorSpaceXform.cpp | 2 | ||||
-rw-r--r-- | src/core/SkColorSpace_Base.h | 43 |
3 files changed, 67 insertions, 44 deletions
diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp index 6c34277b31..3874f0e7d0 100644 --- a/src/core/SkColorSpace.cpp +++ b/src/core/SkColorSpace.cpp @@ -201,49 +201,52 @@ struct ColorSpaceHeader { }; size_t SkColorSpace::writeToMemory(void* memory) const { - // If we have a named profile, only write the enum. - switch (fNamed) { - case kSRGB_Named: - case kAdobeRGB_Named: { - if (memory) { - *((ColorSpaceHeader*) memory) = - ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNamed, 0); + // 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 we have a named profile, only write the enum. + switch (fNamed) { + case kSRGB_Named: + case kAdobeRGB_Named: { + if (memory) { + *((ColorSpaceHeader*) memory) = + ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNamed, 0); + } + return sizeof(ColorSpaceHeader); } - return sizeof(ColorSpaceHeader); + default: + break; } - default: - break; - } - // If we have a named gamma, write the enum and the matrix. - switch (fGammaNamed) { - case kSRGB_GammaNamed: - case k2Dot2Curve_GammaNamed: - case kLinear_GammaNamed: { - if (memory) { - *((ColorSpaceHeader*) memory) = - ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNamed, - ColorSpaceHeader::kMatrix_Flag); - memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)); - fToXYZD50.as4x3ColMajorf((float*) memory); + // If we have a named gamma, write the enum and the matrix. + switch (fGammaNamed) { + case kSRGB_GammaNamed: + case k2Dot2Curve_GammaNamed: + case kLinear_GammaNamed: { + if (memory) { + *((ColorSpaceHeader*) memory) = + ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNamed, + ColorSpaceHeader::kMatrix_Flag); + memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)); + fToXYZD50.as4x3ColMajorf((float*) memory); + } + return sizeof(ColorSpaceHeader) + 12 * sizeof(float); } - return sizeof(ColorSpaceHeader) + 12 * sizeof(float); + default: + SkASSERT(false); + return 0; } - default: - break; } - // If we do not have a named gamma, this must have been created from an ICC profile. - // Since we were unable to recognize the gamma, we will have saved the ICC data. - SkASSERT(as_CSB(this)->fProfileData); - + // Otherwise, serialize the ICC data. size_t profileSize = as_CSB(this)->fProfileData->size(); if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { return 0; } if (memory) { - *((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(k0_Version, fNamed, fGammaNamed, + *((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(k0_Version, kUnknown_Named, + kNonStandard_GammaNamed, ColorSpaceHeader::kICC_Flag); memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)); @@ -316,7 +319,8 @@ sk_sp<SkColorSpace> SkColorSpace::Deserialize(const void* data, size_t length) { bool SkColorSpace::gammasAreMatching() const { const SkGammas* gammas = as_CSB(this)->gammas(); SkASSERT(gammas); - return gammas->fRedData == gammas->fGreenData && gammas->fGreenData == gammas->fBlueData; + return gammas->fRedType == gammas->fGreenType && gammas->fGreenType == gammas->fBlueType && + gammas->fRedData == gammas->fGreenData && gammas->fGreenData == gammas->fBlueData; } bool SkColorSpace::gammasAreNamed() const { diff --git a/src/core/SkColorSpaceXform.cpp b/src/core/SkColorSpaceXform.cpp index 4fbfa6cd9e..4a7f175082 100644 --- a/src/core/SkColorSpaceXform.cpp +++ b/src/core/SkColorSpaceXform.cpp @@ -404,7 +404,7 @@ static void build_gamma_tables(const T* outGammaTables[3], T* gammaTableStorage, // share the same table pointer. This should almost always be true. // I've never seen a profile where all three gamma curves didn't match. // But it is possible that they won't. - if (gammas->data(0) == gammas->data(i)) { + if (gammas->type(0) == gammas->type(i) && gammas->data(0) == gammas->data(i)) { outGammaTables[i] = outGammaTables[0]; continue; } diff --git a/src/core/SkColorSpace_Base.h b/src/core/SkColorSpace_Base.h index 6cfbb8c837..f4507732b5 100644 --- a/src/core/SkColorSpace_Base.h +++ b/src/core/SkColorSpace_Base.h @@ -70,38 +70,57 @@ struct SkGammas : SkRefCnt { }; bool isNamed(int i) const { - SkASSERT(0 <= i && i < 3); - return (&fRedType)[i] == Type::kNamed_Type; + return Type::kNamed_Type == this->type(i); } bool isValue(int i) const { - SkASSERT(0 <= i && i < 3); - return (&fRedType)[i] == Type::kValue_Type; + return Type::kValue_Type == this->type(i); } bool isTable(int i) const { - SkASSERT(0 <= i && i < 3); - return (&fRedType)[i] == Type::kTable_Type; + return Type::kTable_Type == this->type(i); } bool isParametric(int i) const { - SkASSERT(0 <= i && i < 3); - return (&fRedType)[i] == Type::kParam_Type; + return Type::kParam_Type == this->type(i); } const Data& data(int i) const { - SkASSERT(0 <= i && i < 3); - return (&fRedData)[i]; + switch (i) { + case 0: + return fRedData; + case 1: + return fGreenData; + case 2: + return fBlueData; + default: + SkASSERT(false); + return fRedData; + } } const float* table(int i) const { SkASSERT(isTable(i)); - return (&fRedData)[i].fTable.table(this); + return this->data(i).fTable.table(this); } const Params& params(int i) const { SkASSERT(isParametric(i)); - return (&fRedData)[i].params(this); + return this->data(i).params(this); + } + + Type type(int i) const { + switch (i) { + case 0: + return fRedType; + case 1: + return fGreenType; + case 2: + return fBlueType; + default: + SkASSERT(false); + return fRedType; + } } SkGammas() |