aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2018-05-10 14:29:21 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-10 19:14:26 +0000
commit1d686a962c775a69b54f165a23c20c57e506023b (patch)
tree5e2d5912adf6a4fda85a662478a781dd4ff7d8d8
parent52aacd602f792a01218ca903759f6b9d4ec28450 (diff)
Add SkColorSpace::toProfile
Now that A2B parsing is at least as strict as skcms_Parse, this can never fail, so switch to void. Also use the new programmatic profile helpers, which also ensures the data and profile space fields are set correctly. Bug: skia: Change-Id: Ifc4d89a919ca178c484839bdf88dae8a162c3e4f Reviewed-on: https://skia-review.googlesource.com/127336 Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Brian Osman <brianosman@google.com>
-rw-r--r--include/core/SkColorSpace.h11
-rw-r--r--src/core/SkColorSpaceXform_skcms.cpp57
2 files changed, 24 insertions, 44 deletions
diff --git a/include/core/SkColorSpace.h b/include/core/SkColorSpace.h
index 801ccf2098..97fb9a0357 100644
--- a/include/core/SkColorSpace.h
+++ b/include/core/SkColorSpace.h
@@ -139,6 +139,11 @@ public:
}
/**
+ * Convert this color space to an skcms ICC profile struct.
+ */
+ void toProfile(skcms_ICCProfile*) const;
+
+ /**
* Types of colorspaces.
*/
enum Type {
@@ -253,12 +258,6 @@ public:
*/
static bool Equals(const SkColorSpace* src, const SkColorSpace* dst);
- /**
- * If this color space was constructed from an ICC profile, return that profile data.
- * Otherise, return nullptr.
- */
- const SkData* profileData() const { return this->onProfileData(); }
-
virtual bool nonlinearBlending() const { return false; }
virtual sk_sp<SkColorSpace> makeNonlinearBlending() const { return nullptr; }
diff --git a/src/core/SkColorSpaceXform_skcms.cpp b/src/core/SkColorSpaceXform_skcms.cpp
index 5305b9bffd..8696e4bda3 100644
--- a/src/core/SkColorSpaceXform_skcms.cpp
+++ b/src/core/SkColorSpaceXform_skcms.cpp
@@ -68,42 +68,24 @@ bool SkColorSpaceXform_skcms::apply(ColorFormat dstFormat, void* dst,
dst, get_skcms_format(dstFormat), dstAlpha, &fDstProfile, count);
}
-static bool cs_to_profile(const SkColorSpace* cs, skcms_ICCProfile* profile) {
- if (cs->profileData()) {
- return skcms_Parse(cs->profileData()->data(), cs->profileData()->size(), profile);
+void SkColorSpace::toProfile(skcms_ICCProfile* profile) const {
+ if (auto blob = this->onProfileData()) {
+ SkAssertResult(skcms_Parse(blob->data(), blob->size(), profile));
+ } else {
+ SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor);
+ SkColorSpaceTransferFn tf;
+ SkAssertResult(this->toXYZD50(&toXYZ) && this->isNumericalTransferFn(&tf));
+
+ skcms_Matrix3x3 m = {{
+ { toXYZ.get(0, 0), toXYZ.get(0, 1), toXYZ.get(0, 2) },
+ { toXYZ.get(1, 0), toXYZ.get(1, 1), toXYZ.get(1, 2) },
+ { toXYZ.get(2, 0), toXYZ.get(2, 1), toXYZ.get(2, 2) },
+ }};
+
+ skcms_Init(profile);
+ skcms_SetTransferFunction(profile, (const skcms_TransferFunction*)&tf);
+ skcms_SetXYZD50(profile, &m);
}
-
- SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor);
- SkColorSpaceTransferFn tf;
- if (cs->toXYZD50(&toXYZ) && cs->isNumericalTransferFn(&tf)) {
- memset(profile, 0, sizeof(*profile));
-
- profile->has_trc = true;
- profile->trc[0].parametric.g = tf.fG;
- profile->trc[0].parametric.a = tf.fA;
- profile->trc[0].parametric.b = tf.fB;
- profile->trc[0].parametric.c = tf.fC;
- profile->trc[0].parametric.d = tf.fD;
- profile->trc[0].parametric.e = tf.fE;
- profile->trc[0].parametric.f = tf.fF;
- profile->trc[1].parametric = profile->trc[0].parametric;
- profile->trc[2].parametric = profile->trc[0].parametric;
-
- profile->has_toXYZD50 = true;
- for (int r = 0; r < 3; ++r) {
- for (int c = 0; c < 3; ++c) {
- profile->toXYZD50.vals[r][c] = toXYZ.get(r, c);
- }
- }
-
- return true;
- }
-
- // It should be impossible to make a color space that gets here with our available factories.
- // All ICC-based profiles have profileData. All remaining factories produce XYZ spaces with
- // a single (numerical) transfer function.
- SkDEBUGFAIL("How did we get here?");
- return false;
}
std::unique_ptr<SkColorSpaceXform> MakeSkcmsXform(SkColorSpace* src, SkColorSpace* dst,
@@ -113,9 +95,8 @@ std::unique_ptr<SkColorSpaceXform> MakeSkcmsXform(SkColorSpace* src, SkColorSpac
// in skcms.
skcms_ICCProfile srcProfile, dstProfile;
- if (!cs_to_profile(src, &srcProfile) || !cs_to_profile(dst, &dstProfile)) {
- return nullptr;
- }
+ src->toProfile(&srcProfile);
+ dst->toProfile(&dstProfile);
if (!skcms_MakeUsableAsDestination(&dstProfile)) {
return nullptr;