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 "SkAtomics.h" | 8 #include "SkAtomics.h" |
9 #include "SkColorSpace.h" | 9 #include "SkColorSpace.h" |
10 #include "SkOnce.h" | 10 #include "SkOncePtr.h" |
11 | 11 |
12 static bool color_space_almost_equal(float a, float b) { | 12 static bool color_space_almost_equal(float a, float b) { |
13 return SkTAbs(a - b) < 0.01f; | 13 return SkTAbs(a - b) < 0.01f; |
14 } | 14 } |
15 | 15 |
16 void SkFloat3::dump() const { | 16 void SkFloat3::dump() const { |
17 SkDebugf("[%7.4f %7.4f %7.4f]\n", fVec[0], fVec[1], fVec[2]); | 17 SkDebugf("[%7.4f %7.4f %7.4f]\n", fVec[0], fVec[1], fVec[2]); |
18 } | 18 } |
19 | 19 |
20 ////////////////////////////////////////////////////////////////////////////////
////////////////// | 20 ////////////////////////////////////////////////////////////////////////////////
////////////////// |
(...skipping 15 matching lines...) Expand all Loading... |
36 , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID)) | 36 , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID)) |
37 , fNamed(kUnknown_Named) | 37 , fNamed(kUnknown_Named) |
38 {} | 38 {} |
39 | 39 |
40 const float gSRGB_toXYZD50[] { | 40 const float gSRGB_toXYZD50[] { |
41 0.4358f, 0.2224f, 0.0139f, // * R | 41 0.4358f, 0.2224f, 0.0139f, // * R |
42 0.3853f, 0.7170f, 0.0971f, // * G | 42 0.3853f, 0.7170f, 0.0971f, // * G |
43 0.1430f, 0.0606f, 0.7139f, // * B | 43 0.1430f, 0.0606f, 0.7139f, // * B |
44 }; | 44 }; |
45 | 45 |
| 46 SK_DECLARE_STATIC_ONCE_PTR(SkColorSpace, sRGB); |
| 47 |
46 sk_sp<SkColorSpace> SkColorSpace::NewRGB(SkGammas gammas, const SkMatrix44& toXY
ZD50) { | 48 sk_sp<SkColorSpace> SkColorSpace::NewRGB(SkGammas gammas, const SkMatrix44& toXY
ZD50) { |
47 // Check if we really have sRGB | 49 // Check if we really have sRGB |
48 if (color_space_almost_equal(2.2f, gammas.fRed.fValue) && | 50 if (color_space_almost_equal(2.2f, gammas.fRed.fValue) && |
49 color_space_almost_equal(2.2f, gammas.fGreen.fValue) && | 51 color_space_almost_equal(2.2f, gammas.fGreen.fValue) && |
50 color_space_almost_equal(2.2f, gammas.fBlue.fValue) && | 52 color_space_almost_equal(2.2f, gammas.fBlue.fValue) && |
51 color_space_almost_equal(toXYZD50.getFloat(0, 0), gSRGB_toXYZD50[0]) && | 53 color_space_almost_equal(toXYZD50.getFloat(0, 0), gSRGB_toXYZD50[0]) && |
52 color_space_almost_equal(toXYZD50.getFloat(0, 1), gSRGB_toXYZD50[1]) && | 54 color_space_almost_equal(toXYZD50.getFloat(0, 1), gSRGB_toXYZD50[1]) && |
53 color_space_almost_equal(toXYZD50.getFloat(0, 2), gSRGB_toXYZD50[2]) && | 55 color_space_almost_equal(toXYZD50.getFloat(0, 2), gSRGB_toXYZD50[2]) && |
54 color_space_almost_equal(toXYZD50.getFloat(1, 0), gSRGB_toXYZD50[3]) && | 56 color_space_almost_equal(toXYZD50.getFloat(1, 0), gSRGB_toXYZD50[3]) && |
55 color_space_almost_equal(toXYZD50.getFloat(1, 1), gSRGB_toXYZD50[4]) && | 57 color_space_almost_equal(toXYZD50.getFloat(1, 1), gSRGB_toXYZD50[4]) && |
56 color_space_almost_equal(toXYZD50.getFloat(1, 2), gSRGB_toXYZD50[5]) && | 58 color_space_almost_equal(toXYZD50.getFloat(1, 2), gSRGB_toXYZD50[5]) && |
57 color_space_almost_equal(toXYZD50.getFloat(2, 0), gSRGB_toXYZD50[6]) && | 59 color_space_almost_equal(toXYZD50.getFloat(2, 0), gSRGB_toXYZD50[6]) && |
58 color_space_almost_equal(toXYZD50.getFloat(2, 1), gSRGB_toXYZD50[7]) && | 60 color_space_almost_equal(toXYZD50.getFloat(2, 1), gSRGB_toXYZD50[7]) && |
59 color_space_almost_equal(toXYZD50.getFloat(2, 2), gSRGB_toXYZD50[8]) && | 61 color_space_almost_equal(toXYZD50.getFloat(2, 2), gSRGB_toXYZD50[8]) && |
60 color_space_almost_equal(toXYZD50.getFloat(0, 3), 0.0f) && | 62 color_space_almost_equal(toXYZD50.getFloat(0, 3), 0.0f) && |
61 color_space_almost_equal(toXYZD50.getFloat(1, 3), 0.0f) && | 63 color_space_almost_equal(toXYZD50.getFloat(1, 3), 0.0f) && |
62 color_space_almost_equal(toXYZD50.getFloat(2, 3), 0.0f) && | 64 color_space_almost_equal(toXYZD50.getFloat(2, 3), 0.0f) && |
63 color_space_almost_equal(toXYZD50.getFloat(3, 0), 0.0f) && | 65 color_space_almost_equal(toXYZD50.getFloat(3, 0), 0.0f) && |
64 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) && | 66 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) && |
65 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) && | 67 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) && |
66 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f)) | 68 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f)) |
67 { | 69 { |
68 return SkColorSpace::NewNamed(kSRGB_Named); | 70 return SkColorSpace::NewNamed(kSRGB_Named); |
69 } | 71 } |
70 | 72 |
71 return sk_sp<SkColorSpace>(new SkColorSpace(std::move(gammas), toXYZD50, kUn
known_Named)); | 73 return sk_sp<SkColorSpace>(new SkColorSpace(std::move(gammas), toXYZD50, kUn
known_Named)); |
72 } | 74 } |
73 | 75 |
74 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { | 76 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { |
75 static SkOnce once; | |
76 static SkColorSpace* sRGB; | |
77 | |
78 switch (named) { | 77 switch (named) { |
79 case kSRGB_Named: { | 78 case kSRGB_Named: { |
80 once([] { | 79 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); |
81 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); | 80 srgbToxyzD50.set3x3ColMajorf(gSRGB_toXYZD50); |
82 srgbToxyzD50.set3x3ColMajorf(gSRGB_toXYZD50); | 81 return sk_ref_sp(sRGB.get([=]{ |
83 sRGB = new SkColorSpace(SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50
, kSRGB_Named); | 82 return new SkColorSpace(SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50
, kSRGB_Named); |
84 }); | 83 })); |
85 return sk_ref_sp(sRGB); | |
86 } | 84 } |
87 default: | 85 default: |
88 break; | 86 break; |
89 } | 87 } |
90 return nullptr; | 88 return nullptr; |
91 } | 89 } |
92 | 90 |
93 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 91 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
94 | 92 |
95 #include "SkFixed.h" | 93 #include "SkFixed.h" |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 toXYZ)); | 632 toXYZ)); |
635 } | 633 } |
636 | 634 |
637 } | 635 } |
638 default: | 636 default: |
639 break; | 637 break; |
640 } | 638 } |
641 | 639 |
642 return_null("ICC profile contains unsupported colorspace"); | 640 return_null("ICC profile contains unsupported colorspace"); |
643 } | 641 } |
OLD | NEW |