aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkColorSpaceXformSteps.cpp
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2018-05-24 12:33:23 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-24 18:24:48 +0000
commit6968f9ce54a627254ff91206df6c78de99930c89 (patch)
tree9c1608a40cec7b7148e6f1160c1a6fdf42e23d5a /src/core/SkColorSpaceXformSteps.cpp
parent7916c0ec353e059c4979102d015931a276103fd9 (diff)
SkColorSpaceXformSteps
Lots TODO. Change-Id: I95edb764b85a5140d432adb506c3b537869e6df4 Reviewed-on: https://skia-review.googlesource.com/129933 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Brian Osman <brianosman@google.com> Auto-Submit: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core/SkColorSpaceXformSteps.cpp')
-rw-r--r--src/core/SkColorSpaceXformSteps.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/core/SkColorSpaceXformSteps.cpp b/src/core/SkColorSpaceXformSteps.cpp
new file mode 100644
index 0000000000..0067a70934
--- /dev/null
+++ b/src/core/SkColorSpaceXformSteps.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkColorSpaceXformSteps.h"
+
+// Our logical flow modulo any optimization is:
+// For source colors:
+// 1) get colors into linear, unpremul format
+// 2) transform to dst gamut
+// 3) encode with dst transfer function if dst has non-linear blending
+// 4) premul so we can blend
+//
+// For destination colors:
+// a) Linearize if dst has linear blending
+// b) (Presumably all destinations are already premul, but logically, premul here)
+//
+// Now the source and destination pipelines unify:
+// I) blend the src and dst colors, which are encoded the same way in the same gamut
+// II) if dst has linear blending, encode using dst transfer function
+//
+// Step 1) is represented by three bits:
+// - early_unpremul, converting f(s)*a,a to f(s),a if src has non-linear blending
+// - linearize_src, converting f(s),a to s,a _or_ f(s*a),a to s*a,a
+// - late_unpremul, converting s*a,a to s,a if src has linear blending
+// So we'll either early_unpremul and linearize_src, or linearize_src and late_unpremul.
+//
+
+SkColorSpaceXformSteps::SkColorSpaceXformSteps(SkColorSpace* src, SkAlphaType srcAT,
+ SkColorSpace* dst) {
+ // Set all bools to false, all floats to 0.0f.
+ memset(this, 0, sizeof(*this));
+
+ // We have some options about what to do with null src or dst here.
+#if 1
+ SkASSERT(src && dst);
+#else
+ // If either the source or destination color space is unspecified,
+ // treat it as non-linearly-blended sRGB ("legacy").
+ sk_sp<SkColorSpace> sRGB_NL;
+ if (!src || !dst) {
+ sRGB_NL = SkColorSpace::MakeSRGB()->makeNonlinearBlending();
+ if (!src) { src = sRGB_NL.get(); }
+ if (!dst) { dst = sRGB_NL.get(); }
+ }
+#endif
+
+ bool srcNL = src->nonlinearBlending(),
+ srcPM = srcAT == kPremul_SkAlphaType,
+ dstNL = dst->nonlinearBlending();
+
+ // Step 1) get source colors into linear, unpremul format
+ this->early_unpremul = srcNL && srcPM;
+ this->linearize_src = true;
+ this->late_unpremul = !srcNL && srcPM;
+
+ // Step 2) transform source colors into destination gamut
+ this->gamut_transform = true;
+
+ // Step 3) encode with dst transfer function if dst has non-linear blending
+ this->early_encode = dstNL;
+
+ // Step 4) premul so we can blend
+ this->premul = true || !srcPM;
+
+ // Step a) linearize if dst has linear blending
+ this->linearize_dst = !dstNL;
+
+ // Step II) if dst has linear blending, encode back using dst transfer function before storing
+ this->late_encode = !dstNL;
+}