OLD | NEW |
(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 } |
OLD | NEW |