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

Side by Side Diff: src/gpu/GrColorSpaceXform.cpp

Issue 2154753003: Introduce GrColorSpaceXform, for gamut conversion on textures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More progress & refactoring Created 4 years, 5 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 | « src/gpu/GrClipMaskManager.cpp ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrColorSpaceXform.h"
9 #include "SkColorSpace.h"
10
11 static inline bool sk_float_almost_equals(float x, float y, float tol) {
12 return sk_float_abs(x - y) <= tol;
13 }
14
15 static inline bool matrix_is_almost_identity(const SkMatrix44& m,
16 SkMScalar tol = SK_MScalar1 / (1 << 12)) {
17 return
18 sk_float_almost_equals(m.getFloat(0, 0), 1.0f, tol) &&
19 sk_float_almost_equals(m.getFloat(0, 1), 0.0f, tol) &&
20 sk_float_almost_equals(m.getFloat(0, 2), 0.0f, tol) &&
21 sk_float_almost_equals(m.getFloat(0, 3), 0.0f, tol) &&
22 sk_float_almost_equals(m.getFloat(1, 0), 0.0f, tol) &&
23 sk_float_almost_equals(m.getFloat(1, 1), 1.0f, tol) &&
24 sk_float_almost_equals(m.getFloat(1, 2), 0.0f, tol) &&
25 sk_float_almost_equals(m.getFloat(1, 3), 0.0f, tol) &&
26 sk_float_almost_equals(m.getFloat(2, 0), 0.0f, tol) &&
27 sk_float_almost_equals(m.getFloat(2, 1), 0.0f, tol) &&
28 sk_float_almost_equals(m.getFloat(2, 2), 1.0f, tol) &&
29 sk_float_almost_equals(m.getFloat(2, 3), 0.0f, tol) &&
30 sk_float_almost_equals(m.getFloat(3, 0), 0.0f, tol) &&
31 sk_float_almost_equals(m.getFloat(3, 1), 0.0f, tol) &&
32 sk_float_almost_equals(m.getFloat(3, 2), 0.0f, tol) &&
33 sk_float_almost_equals(m.getFloat(3, 3), 1.0f, tol);
34 }
35
36 sk_sp<GrColorSpaceXform> GrColorSpaceXform::Make(SkColorSpace* src, SkColorSpace * dst) {
37 if (!src || !dst) {
38 // Invalid
39 return nullptr;
40 }
41
42 if (src == dst) {
43 // Quick equality check - no conversion needed in this case
44 return nullptr;
45 }
46
47 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor);
48 if (!dst->xyz().invert(&srcToDst)) {
49 return nullptr;
50 }
51 srcToDst.postConcat(src->xyz());
52
53 if (matrix_is_almost_identity(srcToDst)) {
54 return nullptr;
55 }
56
57 return sk_make_sp<GrColorSpaceXform>(srcToDst);
58 }
OLDNEW
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698