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 "SkColorSpace.h" | 8 #include "SkColorSpace.h" |
9 #include "SkColorSpace_Base.h" | 9 #include "SkColorSpace_Base.h" |
10 #include "SkColorSpacePriv.h" | 10 #include "SkColorSpacePriv.h" |
11 #include "SkOnce.h" | 11 #include "SkOnce.h" |
12 | 12 |
13 SkColorSpace::SkColorSpace(const SkMatrix44& toXYZD50) | 13 SkColorSpace::SkColorSpace(const SkMatrix44& toXYZD50) |
14 : fToXYZD50(toXYZD50) | 14 : fToXYZD50(toXYZD50) |
15 {} | 15 {} |
16 | 16 |
17 SkColorSpace_Base::SkColorSpace_Base(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50) | 17 SkColorSpace_Base::SkColorSpace_Base(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50) |
18 : INHERITED(toXYZD50) | 18 : INHERITED(toXYZD50) |
19 , fGammaNamed(gammaNamed) | 19 , fGammaNamed(gammaNamed) |
20 , fGammas(nullptr) | 20 , fGammas(nullptr) |
21 , fProfileData(nullptr) | 21 , fProfileData(nullptr) |
22 , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) | |
22 {} | 23 {} |
23 | 24 |
24 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, SkGamma Named gammaNamed, | 25 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, SkGamma Named gammaNamed, |
25 sk_sp<SkGammas> gammas, const SkMatrix44& t oXYZD50, | 26 sk_sp<SkGammas> gammas, const SkMatrix44& t oXYZD50, |
26 sk_sp<SkData> profileData) | 27 sk_sp<SkData> profileData) |
27 : INHERITED(toXYZD50) | 28 : INHERITED(toXYZD50) |
28 , fColorLUT(std::move(colorLUT)) | 29 , fColorLUT(std::move(colorLUT)) |
29 , fGammaNamed(gammaNamed) | 30 , fGammaNamed(gammaNamed) |
30 , fGammas(std::move(gammas)) | 31 , fGammas(std::move(gammas)) |
31 , fProfileData(std::move(profileData)) | 32 , fProfileData(std::move(profileData)) |
33 , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) | |
32 {} | 34 {} |
33 | 35 |
34 static constexpr float gSRGB_toXYZD50[] { | 36 static constexpr float gSRGB_toXYZD50[] { |
35 0.4358f, 0.2224f, 0.0139f, // * R | 37 0.4358f, 0.2224f, 0.0139f, // * R |
36 0.3853f, 0.7170f, 0.0971f, // * G | 38 0.3853f, 0.7170f, 0.0971f, // * G |
37 0.1430f, 0.0606f, 0.7139f, // * B | 39 0.1430f, 0.0606f, 0.7139f, // * B |
38 }; | 40 }; |
39 | 41 |
40 static constexpr float gAdobeRGB_toXYZD50[] { | 42 static constexpr float gAdobeRGB_toXYZD50[] { |
41 0.6098f, 0.3111f, 0.0195f, // * R | 43 0.6098f, 0.3111f, 0.0195f, // * R |
42 0.2052f, 0.6257f, 0.0609f, // * G | 44 0.2052f, 0.6257f, 0.0609f, // * G |
43 0.1492f, 0.0632f, 0.7448f, // * B | 45 0.1492f, 0.0632f, 0.7448f, // * B |
44 }; | 46 }; |
45 | 47 |
48 const SkMatrix44& SkColorSpace_Base::fromXYZ() const { | |
msarett
2016/09/08 15:06:07
nit: In my head, this should be next to the other
| |
49 fFromXYZOnce([this] { | |
50 if (!fToXYZD50.invert(&fFromXYZD50)) { | |
51 SkDEBUGFAIL("Non-invertible XYZ matrix, defaulting to sRGB"); | |
52 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); | |
msarett
2016/09/08 15:06:07
I'm fine with this behavior, but just to be clear
| |
53 srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50); | |
54 srgbToxyzD50.invert(&fFromXYZD50); | |
55 } | |
56 }); | |
57 return fFromXYZD50; | |
58 } | |
59 | |
46 /** | 60 /** |
47 * Checks if our toXYZ matrix is a close match to a known color gamut. | 61 * Checks if our toXYZ matrix is a close match to a known color gamut. |
48 * | 62 * |
49 * @param toXYZD50 transformation matrix deduced from profile data | 63 * @param toXYZD50 transformation matrix deduced from profile data |
50 * @param standard 3x3 canonical transformation matrix | 64 * @param standard 3x3 canonical transformation matrix |
51 */ | 65 */ |
52 static bool xyz_almost_equal(const SkMatrix44& toXYZD50, const float* standard) { | 66 static bool xyz_almost_equal(const SkMatrix44& toXYZD50, const float* standard) { |
53 return color_space_almost_equal(toXYZD50.getFloat(0, 0), standard[0]) && | 67 return color_space_almost_equal(toXYZD50.getFloat(0, 0), standard[0]) && |
54 color_space_almost_equal(toXYZD50.getFloat(0, 1), standard[1]) && | 68 color_space_almost_equal(toXYZD50.getFloat(0, 1), standard[1]) && |
55 color_space_almost_equal(toXYZD50.getFloat(0, 2), standard[2]) && | 69 color_space_almost_equal(toXYZD50.getFloat(0, 2), standard[2]) && |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 return false; | 435 return false; |
422 } | 436 } |
423 | 437 |
424 // It is unlikely that we will reach this case. | 438 // It is unlikely that we will reach this case. |
425 sk_sp<SkData> srcData = src->serialize(); | 439 sk_sp<SkData> srcData = src->serialize(); |
426 sk_sp<SkData> dstData = dst->serialize(); | 440 sk_sp<SkData> dstData = dst->serialize(); |
427 return srcData->size() == dstData->size() && | 441 return srcData->size() == dstData->size() && |
428 0 == memcmp(srcData->data(), dstData->data(), srcData->size() ); | 442 0 == memcmp(srcData->data(), dstData->data(), srcData->size() ); |
429 } | 443 } |
430 } | 444 } |
OLD | NEW |