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 "SkColorSpace_Base.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 if (!src || !dst) { | 42 if (!src || !dst) { |
43 // Invalid | 43 // Invalid |
44 return nullptr; | 44 return nullptr; |
45 } | 45 } |
46 | 46 |
47 if (src == dst) { | 47 if (src == dst) { |
48 // Quick equality check - no conversion needed in this case | 48 // Quick equality check - no conversion needed in this case |
49 return nullptr; | 49 return nullptr; |
50 } | 50 } |
51 | 51 |
| 52 |
| 53 const SkMatrix44* toXYZD50 = as_CSB(src)->toXYZD50(); |
| 54 const SkMatrix44* fromXYZD50 = as_CSB(dst)->fromXYZD50(); |
| 55 if (!toXYZD50 || !fromXYZD50) { |
| 56 // unsupported colour spaces -- cannot specify gamut as a matrix |
| 57 return nullptr; |
| 58 } |
52 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor); | 59 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor); |
53 srcToDst.setConcat(as_CSB(dst)->fromXYZD50(), as_CSB(src)->toXYZD50()); | 60 srcToDst.setConcat(*fromXYZD50, *toXYZD50); |
54 | 61 |
55 if (matrix_is_almost_identity(srcToDst)) { | 62 if (matrix_is_almost_identity(srcToDst)) { |
56 return nullptr; | 63 return nullptr; |
57 } | 64 } |
58 | 65 |
59 return sk_make_sp<GrColorSpaceXform>(srcToDst); | 66 return sk_make_sp<GrColorSpaceXform>(srcToDst); |
60 } | 67 } |
61 | 68 |
62 bool GrColorSpaceXform::Equals(const GrColorSpaceXform* a, const GrColorSpaceXfo
rm* b) { | 69 bool GrColorSpaceXform::Equals(const GrColorSpaceXform* a, const GrColorSpaceXfo
rm* b) { |
63 if (a == b) { | 70 if (a == b) { |
64 return true; | 71 return true; |
65 } | 72 } |
66 | 73 |
67 if (!a || !b) { | 74 if (!a || !b) { |
68 return false; | 75 return false; |
69 } | 76 } |
70 | 77 |
71 return a->fSrcToDst == b->fSrcToDst; | 78 return a->fSrcToDst == b->fSrcToDst; |
72 } | 79 } |
73 | 80 |
74 GrColor4f GrColorSpaceXform::apply(const GrColor4f& srcColor) { | 81 GrColor4f GrColorSpaceXform::apply(const GrColor4f& srcColor) { |
75 GrColor4f result; | 82 GrColor4f result; |
76 fSrcToDst.mapScalars(srcColor.fRGBA, result.fRGBA); | 83 fSrcToDst.mapScalars(srcColor.fRGBA, result.fRGBA); |
77 return result; | 84 return result; |
78 } | 85 } |
OLD | NEW |