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
This commit is contained in:
parent
00db3fd7a7
commit
a714bc3929
@ -140,7 +140,7 @@ void ColorCodecBench::onDelayedSetup() {
|
||||
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get()));
|
||||
fSrcData = codec->getICCData();
|
||||
sk_sp<SkData> dstData = SkData::MakeFromFileName(
|
||||
GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str());
|
||||
GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
|
||||
SkASSERT(dstData);
|
||||
|
||||
fDstSpace = nullptr;
|
||||
|
@ -869,7 +869,7 @@ Error ColorCodecSrc::draw(SkCanvas* canvas) const {
|
||||
|
||||
// Load the dst ICC profile. This particular dst is fairly similar to Adobe RGB.
|
||||
sk_sp<SkData> dstData = SkData::MakeFromFileName(
|
||||
GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str());
|
||||
GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
|
||||
if (!dstData) {
|
||||
return "Cannot read monitor profile. Is the resource path set correctly?";
|
||||
}
|
||||
|
BIN
resources/icc_profiles/HP_Z32x.icc
Normal file
BIN
resources/icc_profiles/HP_Z32x.icc
Normal file
Binary file not shown.
BIN
resources/icc_profiles/upperLeft.icc
Normal file
BIN
resources/icc_profiles/upperLeft.icc
Normal file
Binary file not shown.
BIN
resources/icc_profiles/upperRight.icc
Normal file
BIN
resources/icc_profiles/upperRight.icc
Normal file
Binary file not shown.
@ -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;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
default:
|
||||
SkASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
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);
|
||||
}
|
||||
return sizeof(ColorSpaceHeader) + 12 * sizeof(float);
|
||||
}
|
||||
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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -125,7 +125,7 @@ DEF_TEST(ColorSpaceWriteICC, r) {
|
||||
|
||||
// Test saving the original ICC data
|
||||
sk_sp<SkData> monitorData = SkData::MakeFromFileName(
|
||||
GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str());
|
||||
GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
|
||||
REPORTER_ASSERT(r, monitorData);
|
||||
if (!monitorData) {
|
||||
return;
|
||||
@ -211,7 +211,13 @@ DEF_TEST(ColorSpace_Serialize, r) {
|
||||
test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named).get(), true);
|
||||
|
||||
sk_sp<SkData> monitorData = SkData::MakeFromFileName(
|
||||
GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str());
|
||||
GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
|
||||
test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->size()).get(), false);
|
||||
monitorData = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc").c_str());
|
||||
test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->size()).get(), false);
|
||||
monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc").c_str());
|
||||
test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->size()).get(), false);
|
||||
monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str());
|
||||
test_serialize(r, SkColorSpace::NewICC(monitorData->data(), monitorData->size()).get(), false);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user