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

Unified Diff: src/core/SkColorSpace_XYZ.cpp

Issue 2389983002: Refactored SkColorSpace and added in a Lab PCS GM (Closed)
Patch Set: migrated call from SkColorSpace_Base::makeLinearGamma() to SkColorSpace_XYZ::makeLinearGamma() Created 4 years, 2 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
« no previous file with comments | « src/core/SkColorSpace_XYZ.h ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkColorSpace_XYZ.cpp
diff --git a/src/core/SkColorSpace_XYZ.cpp b/src/core/SkColorSpace_XYZ.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1f62245d7353a14475495531eff8d98ab48492ed
--- /dev/null
+++ b/src/core/SkColorSpace_XYZ.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkColorSpace_XYZ.h"
+#include "SkColorSpaceXform_Base.h"
+
+static constexpr float gSRGB_toXYZD50[] {
+ 0.4358f, 0.3853f, 0.1430f, // Rx, Gx, Bx
+ 0.2224f, 0.7170f, 0.0606f, // Ry, Gy, Gz
+ 0.0139f, 0.0971f, 0.7139f, // Rz, Gz, Bz
+};
+
+SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50)
+ : INHERITED(nullptr)
+ , fGammaNamed(gammaNamed)
+ , fGammas(nullptr)
+ , fToXYZD50(toXYZD50)
+ , fFromXYZD50(SkMatrix44::kUninitialized_Constructor)
+{}
+
+SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, sk_sp<SkGammas> gammas,
+ const SkMatrix44& toXYZD50, sk_sp<SkData> profileData)
+ : INHERITED(std::move(profileData))
+ , fGammaNamed(gammaNamed)
+ , fGammas(std::move(gammas))
+ , fToXYZD50(toXYZD50)
+ , fFromXYZD50(SkMatrix44::kUninitialized_Constructor)
+{}
+
+const SkMatrix44* SkColorSpace_XYZ::fromXYZD50() const {
+ fFromXYZOnce([this] {
+ if (!fToXYZD50.invert(&fFromXYZD50)) {
+ // If a client gives us a dst gamut with a transform that we can't invert, we will
+ // simply give them back a transform to sRGB gamut.
+ SkDEBUGFAIL("Non-invertible XYZ matrix, defaulting to sRGB");
+ SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
+ srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50);
+ srgbToxyzD50.invert(&fFromXYZD50);
+ }
+ });
+ return &fFromXYZD50;
+}
+
+bool SkColorSpace_XYZ::onGammaCloseToSRGB() const {
+ return kSRGB_SkGammaNamed == fGammaNamed || k2Dot2Curve_SkGammaNamed == fGammaNamed;
+}
+
+bool SkColorSpace_XYZ::onGammaIsLinear() const {
+ return kLinear_SkGammaNamed == fGammaNamed;
+}
+
+sk_sp<SkColorSpace> SkColorSpace_XYZ::makeLinearGamma() {
+ if (this->gammaIsLinear()) {
+ return sk_ref_sp(this);
+ }
+ return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, fToXYZD50);
+}
+
+void SkColorSpace_XYZ::toDstGammaTables(const uint8_t* tables[3], sk_sp<SkData>* storage,
+ int numTables) const {
+ fToDstGammaOnce([this, numTables] {
+ const bool gammasAreMatching = numTables <= 1;
+ fDstStorage =
+ SkData::MakeUninitialized(numTables * SkColorSpaceXform_Base::kDstGammaTableSize);
+ SkColorSpaceXform_Base::BuildDstGammaTables(fToDstGammaTables,
+ (uint8_t*) fDstStorage->writable_data(), this,
+ gammasAreMatching);
+ });
+
+ *storage = fDstStorage;
+ tables[0] = fToDstGammaTables[0];
+ tables[1] = fToDstGammaTables[1];
+ tables[2] = fToDstGammaTables[2];
+}
« no previous file with comments | « src/core/SkColorSpace_XYZ.h ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698