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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/gfx/skia_color_space_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/gfx/skia_color_space_util.h"
6
7 #include <algorithm>
8 #include <cmath>
9
10 namespace gfx {
11
12 namespace {
13
14 const float kEpsilon = 1.f / 256.f;
15 }
16
17 float EvalSkTransferFn(const SkColorSpaceTransferFn& fn, float x) {
18 if (x < 0.f)
19 return 0.f;
20 if (x < fn.fD)
21 return fn.fC * x + fn.fF;
22 return std::pow(fn.fA * x + fn.fB, fn.fG) + fn.fE;
23 }
24
25 SkColorSpaceTransferFn SkTransferFnInverse(const SkColorSpaceTransferFn& fn) {
26 SkColorSpaceTransferFn fn_inv = {0};
27 if (fn.fA > 0 && fn.fG > 0) {
28 double a_to_the_g = std::pow(fn.fA, fn.fG);
29 fn_inv.fA = 1.f / a_to_the_g;
30 fn_inv.fB = -fn.fE / a_to_the_g;
31 fn_inv.fG = 1.f / fn.fG;
32 }
33 fn_inv.fD = fn.fC * fn.fD + fn.fF;
34 fn_inv.fE = -fn.fB / fn.fA;
35 if (fn.fC != 0) {
36 fn_inv.fC = 1.f / fn.fC;
37 fn_inv.fF = -fn.fF / fn.fC;
38 }
39 return fn_inv;
40 }
41
42 bool SkMatrixIsApproximatelyIdentity(const SkMatrix44& m) {
43 for (int i = 0; i < 4; ++i) {
44 for (int j = 0; j < 4; ++j) {
45 float identity_value = i == j ? 1 : 0;
46 float value = m.get(i, j);
47 if (std::abs(identity_value - value) > kEpsilon)
48 return false;
49 }
50 }
51 return true;
52 }
53
54 } // namespace gfx
OLDNEW
« 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