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

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: A few 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 abdd647a258c173e329a4db1f87b550192e14acb..3b892da11e8f724fff618ef04e3f9dcc71449c8b 100644
--- a/src/core/SkColorSpace.cpp
+++ b/src/core/SkColorSpace.cpp
@@ -125,6 +125,47 @@ sk_sp<SkColorSpace> SkColorSpace::NewRGB(GammaNamed gammaNamed, const SkMatrix44
return SkColorSpace_Base::NewRGB(gammaNamed, toXYZD50);
}
+sk_sp<SkColorSpace> SkColorSpace::NewRGB(const GammaCoefficients& coeffs,
+ const SkMatrix44& toXYZD50) {
+ // TODO: Check if coeffs match sRGB, 2.2, or linear.
+ // TODO: Make sure coefficients are non-crazy. Return nullptr if they are.
+ void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkColorSpace::GammaParams));
+ sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas());
+ void* storage = SkTAddOffset<void>(memory, sizeof(SkGammas));
+ memcpy(storage, &coeffs, sizeof(SkColorSpace::GammaParams));
+ 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_GammaNamed,
+ std::move(gammas), toXYZD50, nullptr);
+}
+
+sk_sp<SkColorSpace> SkColorSpace::NewRGB(GammaNamed gammaNamed, const Primaries& primaries) {
+ SkMatrix44 toXYZD50;
+ // TODO: Implement primaries_to_toXYZD50.
+ if (!primaries_to_toXYZD50(&toXYZD50, primaries)) {
+ return nullptr;
+ }
+
+ return NewRGB(gammaNamed, toXYZD50)
+}
+
+sk_sp<SkColorSpace> SkColorSpace::NewRGB(const GammaCoefficients& coeffs,
+ const Primaries& primaries) {
+ SkMatrix44 toXYZD50;
+ if (!primaries_to_toXYZD50(&toXYZD50, primaries)) {
+ return nullptr;
+ }
+
+ return NewRGB(coeffs, toXYZD50)
+}
+
sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
static SkOnce sRGBOnce;
static sk_sp<SkColorSpace> sRGB;
@@ -251,6 +292,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) =
@@ -354,6 +404,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;
}
@@ -415,6 +467,7 @@ bool SkColorSpace::Equals(const SkColorSpace* src, const SkColorSpace* dst) {
if (src->fGammaNamed != 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