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

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: Only plumb to effect - no need to store xform on GrTextureAccess 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
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
10 static inline bool sk_float_almost_equals(float x, float y, float tol) {
11 return sk_float_abs(x - y) <= tol;
12 }
13
14 static inline bool matrix_is_almost_identity(const SkMatrix44& m,
15 SkMScalar tol = SK_MScalar1 / (1 << 12)) {
16 return
bsalomon 2016/07/18 13:56:36 Is this something we should compute and store on t
Brian Osman 2016/07/18 14:07:33 Unfortunately, this is a property of the src + dst
msarett 2016/07/18 15:39:40 Yes I think we should cache the inverse matrix.
17 sk_float_almost_equals(m.getFloat(0, 0), 1.0f, tol) &&
18 sk_float_almost_equals(m.getFloat(0, 1), 0.0f, tol) &&
19 sk_float_almost_equals(m.getFloat(0, 2), 0.0f, tol) &&
20 sk_float_almost_equals(m.getFloat(0, 3), 0.0f, tol) &&
21 sk_float_almost_equals(m.getFloat(1, 0), 0.0f, tol) &&
22 sk_float_almost_equals(m.getFloat(1, 1), 1.0f, tol) &&
23 sk_float_almost_equals(m.getFloat(1, 2), 0.0f, tol) &&
24 sk_float_almost_equals(m.getFloat(1, 3), 0.0f, tol) &&
25 sk_float_almost_equals(m.getFloat(2, 0), 0.0f, tol) &&
26 sk_float_almost_equals(m.getFloat(2, 1), 0.0f, tol) &&
27 sk_float_almost_equals(m.getFloat(2, 2), 1.0f, tol) &&
28 sk_float_almost_equals(m.getFloat(2, 3), 0.0f, tol) &&
29 sk_float_almost_equals(m.getFloat(3, 0), 0.0f, tol) &&
30 sk_float_almost_equals(m.getFloat(3, 1), 0.0f, tol) &&
31 sk_float_almost_equals(m.getFloat(3, 2), 0.0f, tol) &&
32 sk_float_almost_equals(m.getFloat(3, 3), 1.0f, tol);
33 }
34
35 sk_sp<GrColorSpaceXform> GrColorSpaceXform::Make(SkColorSpace* src, SkColorSpace * dst) {
36 if (!src || !dst) {
37 // Invalid
38 return nullptr;
39 }
40
41 if (src == dst) {
42 // Quick equality check - no conversion needed in this case
43 return nullptr;
44 }
45
46 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor);
47 if (!dst->xyz().invert(&srcToDst)) {
48 return nullptr;
49 }
50 srcToDst.postConcat(src->xyz());
51
52 if (matrix_is_almost_identity(srcToDst)) {
53 return nullptr;
54 }
55
56 return sk_make_sp<GrColorSpaceXform>(srcToDst);
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698