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

Unified Diff: ui/gfx/skia_color_space_util.cc

Issue 2696603003: color: Towards ColorTransform optimizations and code generation (Closed)
Patch Set: Keep fixing the windows build Created 3 years, 10 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 | « ui/gfx/skia_color_space_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/skia_color_space_util.cc
diff --git a/ui/gfx/skia_color_space_util.cc b/ui/gfx/skia_color_space_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..60617e764b96ae9d2b58a41780f77aa232add497
--- /dev/null
+++ b/ui/gfx/skia_color_space_util.cc
@@ -0,0 +1,54 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/skia_color_space_util.h"
+
+#include <algorithm>
+#include <cmath>
+
+namespace gfx {
+
+namespace {
+
+const float kEpsilon = 1.f / 256.f;
+}
+
+float EvalSkTransferFn(const SkColorSpaceTransferFn& fn, float x) {
+ if (x < 0.f)
+ return 0.f;
+ if (x < fn.fD)
+ return fn.fC * x + fn.fF;
+ return std::pow(fn.fA * x + fn.fB, fn.fG) + fn.fE;
+}
+
+SkColorSpaceTransferFn SkTransferFnInverse(const SkColorSpaceTransferFn& fn) {
+ SkColorSpaceTransferFn fn_inv = {0};
+ if (fn.fA > 0 && fn.fG > 0) {
+ double a_to_the_g = std::pow(fn.fA, fn.fG);
+ fn_inv.fA = 1.f / a_to_the_g;
+ fn_inv.fB = -fn.fE / a_to_the_g;
+ fn_inv.fG = 1.f / fn.fG;
+ }
+ fn_inv.fD = fn.fC * fn.fD + fn.fF;
+ fn_inv.fE = -fn.fB / fn.fA;
+ if (fn.fC != 0) {
+ fn_inv.fC = 1.f / fn.fC;
+ fn_inv.fF = -fn.fF / fn.fC;
+ }
+ return fn_inv;
+}
+
+bool SkMatrixIsApproximatelyIdentity(const SkMatrix44& m) {
+ for (int i = 0; i < 4; ++i) {
+ for (int j = 0; j < 4; ++j) {
+ float identity_value = i == j ? 1 : 0;
+ float value = m.get(i, j);
+ if (std::abs(identity_value - value) > kEpsilon)
+ return false;
+ }
+ }
+ return true;
+}
+
+} // namespace gfx
« no previous file with comments | « ui/gfx/skia_color_space_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698