Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Unified Diff: src/core/SkColorSpace.cpp

Issue 2304753002: Add SkColorSpacePrimaries to help with making D50 matrices (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Edits Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkColorSpace.cpp
diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp
index 647795fb65d37533a649c9e1bc6e85a3b29a136d..4b08d4b76d4498e5c4c9189ef74e7e474e2f7549 100644
--- a/src/core/SkColorSpace.cpp
+++ b/src/core/SkColorSpace.cpp
@@ -132,6 +132,44 @@ sk_sp<SkColorSpace> SkColorSpace::NewRGB(GammaNamed gammaNamed, const SkMatrix44
}
}
+sk_sp<SkColorSpace> SkColorSpace::NewRGB(const SkTransferFn& coeffs, const SkMatrix44& toXYZD50) {
+ // TODO: Check if coeffs match sRGB, 2.2, or linear.
+ // TODO: Make sure coefficients describe a valid curve. Return nullptr if they don't.
+ void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkTransferFn));
+ sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas());
+ void* storage = SkTAddOffset<void>(memory, sizeof(SkGammas));
+ memcpy(storage, &coeffs, sizeof(SkTransferFn));
+ gammas->fRedType = SkGammas::Type::kParam_Type;
+ gammas->fGreenType = SkGammas::Type::kParam_Type;
+ gammas->fBlueType = SkGammas::Type::kParam_Type;
+
+ SkGammas::Data data;
+ data.fParamOffset = 0;
+ gammas->fRedData = data;
+ gammas->fGreenData = data;
+ gammas->fBlueData = data;
+ return sk_sp<SkColorSpace>(new SkColorSpace_Base(nullptr, kNonStandard_SkGammaNamed,
+ std::move(gammas), toXYZD50, nullptr));
+}
+
+sk_sp<SkColorSpace> SkColorSpace::NewRGB(GammaNamed gammaNamed, const SkPrimaries& primaries) {
+ SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
+ if (!PrimariesToXYZD50(&toXYZD50, primaries)) {
+ return nullptr;
+ }
+
+ return NewRGB(gammaNamed, toXYZD50);
+}
+
+sk_sp<SkColorSpace> SkColorSpace::NewRGB(const SkTransferFn& coeffs, const SkPrimaries& primaries) {
+ SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
+ if (!PrimariesToXYZD50(&toXYZD50, primaries)) {
+ return nullptr;
+ }
+
+ return NewRGB(coeffs, toXYZD50);
+}
+
static SkColorSpace* gAdobeRGB;
static SkColorSpace* gSRGB;
@@ -270,6 +308,15 @@ size_t SkColorSpace::writeToMemory(void* memory) const {
return sizeof(ColorSpaceHeader) + 12 * sizeof(float);
}
default:
+ // TODO: This case gets trickier. The code below exists because I allow
+ // SkPngCodec to call a constructor with float gammas.
+ // I think the best thing to do would be:
+ // (1) Fix SkPngCodec to call one of the new constructors.
+ // (2) Handle serializing the parametric gammas here.
+ // TODO: In a separate CL, remove the idea of "exponential" gammas.
+ // These can be consumed by the parametric case. Maybe this CL
+ // should land first.
+
// Otherwise, write the gamma values and the matrix.
if (memory) {
*((ColorSpaceHeader*) memory) =
@@ -369,6 +416,8 @@ sk_sp<SkColorSpace> SkColorSpace::Deserialize(const void* data, size_t length) {
return NewICC(data, profileSize);
}
case ColorSpaceHeader::kFloatGamma_Flag: {
+ // TODO: This needs to be fixed to match the new version of serialize().
+
if (length < 15 * sizeof(float)) {
return nullptr;
}
@@ -420,6 +469,7 @@ bool SkColorSpace::Equals(const SkColorSpace* src, const SkColorSpace* dst) {
if (as_CSB(src)->fGammaNamed != as_CSB(dst)->fGammaNamed) {
return false;
}
+ // This should still work :).
// It is unlikely that we will reach this case.
sk_sp<SkData> srcData = src->serialize();

Powered by Google App Engine
This is Rietveld 408576698