OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrColorSpaceXform.h" | 8 #include "GrColorSpaceXform.h" |
9 #include "SkColorSpace.h" | 9 #include "SkColorSpace.h" |
| 10 #include "SkColorSpace_Base.h" |
10 #include "SkMatrix44.h" | 11 #include "SkMatrix44.h" |
11 | 12 |
12 static inline bool sk_float_almost_equals(float x, float y, float tol) { | 13 static inline bool sk_float_almost_equals(float x, float y, float tol) { |
13 return sk_float_abs(x - y) <= tol; | 14 return sk_float_abs(x - y) <= tol; |
14 } | 15 } |
15 | 16 |
16 static inline bool matrix_is_almost_identity(const SkMatrix44& m, | 17 static inline bool matrix_is_almost_identity(const SkMatrix44& m, |
17 SkMScalar tol = SK_MScalar1 / (1 <<
12)) { | 18 SkMScalar tol = SK_MScalar1 / (1 <<
12)) { |
18 return | 19 return |
19 sk_float_almost_equals(m.getFloat(0, 0), 1.0f, tol) && | 20 sk_float_almost_equals(m.getFloat(0, 0), 1.0f, tol) && |
(...skipping 24 matching lines...) Expand all Loading... |
44 if (!src || !dst) { | 45 if (!src || !dst) { |
45 // Invalid | 46 // Invalid |
46 return nullptr; | 47 return nullptr; |
47 } | 48 } |
48 | 49 |
49 if (src == dst) { | 50 if (src == dst) { |
50 // Quick equality check - no conversion needed in this case | 51 // Quick equality check - no conversion needed in this case |
51 return nullptr; | 52 return nullptr; |
52 } | 53 } |
53 | 54 |
54 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor); | 55 SkMatrix44 srcToDst = as_CSB(dst)->fromXYZ(); |
55 if (!dst->xyz().invert(&srcToDst)) { | 56 srcToDst.postConcat(src->toXYZ()); |
56 return nullptr; | |
57 } | |
58 srcToDst.postConcat(src->xyz()); | |
59 | 57 |
60 if (matrix_is_almost_identity(srcToDst)) { | 58 if (matrix_is_almost_identity(srcToDst)) { |
61 return nullptr; | 59 return nullptr; |
62 } | 60 } |
63 | 61 |
64 return sk_make_sp<GrColorSpaceXform>(srcToDst, srcAlphaType); | 62 return sk_make_sp<GrColorSpaceXform>(srcToDst, srcAlphaType); |
65 } | 63 } |
OLD | NEW |