Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: src/core/SkColorSpace.cpp

Issue 2005263002: SkColorSpace tweaks (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkColorSpace.h ('k') | src/core/SkColorSpace_Base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkOnce.h" 10 #include "SkOnce.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 //////////////////////////////////////////////////////////////////////////////// ////////////////// 16 //////////////////////////////////////////////////////////////////////////////// //////////////////
17 17
18 SkColorSpace::SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Na med named) 18 SkColorSpace::SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Na med named)
19 : fGammaNamed(kNonStandard_GammaNamed) 19 : fGammaNamed(kNonStandard_GammaNamed)
20 , fToXYZD50(toXYZD50) 20 , fToXYZD50(toXYZD50)
21 , fNamed(named) 21 , fNamed(named)
22 {} 22 {}
23 23
24 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkGammas> gammas, const SkMatrix44& t oXYZD50, 24 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkGammas> gammas, const SkMatrix44& t oXYZD50,
25 Named named) 25 Named named)
26 : INHERITED(kNonStandard_GammaNamed, toXYZD50, named) 26 : INHERITED(kNonStandard_GammaNamed, toXYZD50, named)
27 , fGammas(gammas) 27 , fGammas(std::move(gammas))
28 {} 28 {}
29 29
30 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkGammas> gammas, GammaNamed gammaNam ed, 30 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkGammas> gammas, GammaNamed gammaNam ed,
31 const SkMatrix44& toXYZD50, Named named) 31 const SkMatrix44& toXYZD50, Named named)
32 : INHERITED(gammaNamed, toXYZD50, named) 32 : INHERITED(gammaNamed, toXYZD50, named)
33 , fGammas(gammas) 33 , fGammas(std::move(gammas))
34 {} 34 {}
35 35
36 SkColorSpace_Base::SkColorSpace_Base(SkColorLookUpTable* colorLUT, sk_sp<SkGamma s> gammas, 36 SkColorSpace_Base::SkColorSpace_Base(SkColorLookUpTable* colorLUT, sk_sp<SkGamma s> gammas,
37 const SkMatrix44& toXYZD50) 37 const SkMatrix44& toXYZD50)
38 : INHERITED(kNonStandard_GammaNamed, toXYZD50, kUnknown_Named) 38 : INHERITED(kNonStandard_GammaNamed, toXYZD50, kUnknown_Named)
39 , fColorLUT(colorLUT) 39 , fColorLUT(colorLUT)
40 , fGammas(gammas) 40 , fGammas(std::move(gammas))
41 {} 41 {}
42 42
43 const float gSRGB_toXYZD50[] { 43 const float gSRGB_toXYZD50[] {
44 0.4358f, 0.2224f, 0.0139f, // * R 44 0.4358f, 0.2224f, 0.0139f, // * R
45 0.3853f, 0.7170f, 0.0971f, // * G 45 0.3853f, 0.7170f, 0.0971f, // * G
46 0.1430f, 0.0606f, 0.7139f, // * B 46 0.1430f, 0.0606f, 0.7139f, // * B
47 }; 47 };
48 48
49 const float gAdobeRGB_toXYZD50[] { 49 const float gAdobeRGB_toXYZD50[] {
50 0.6098f, 0.3111f, 0.0195f, // * R 50 0.6098f, 0.3111f, 0.0195f, // * R
(...skipping 24 matching lines...) Expand all
75 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) && 75 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) &&
76 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) && 76 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) &&
77 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f); 77 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f);
78 } 78 }
79 79
80 static SkOnce g2Dot2CurveGammasOnce; 80 static SkOnce g2Dot2CurveGammasOnce;
81 static SkGammas* g2Dot2CurveGammas; 81 static SkGammas* g2Dot2CurveGammas;
82 static SkOnce gLinearGammasOnce; 82 static SkOnce gLinearGammasOnce;
83 static SkGammas* gLinearGammas; 83 static SkGammas* gLinearGammas;
84 84
85 sk_sp<SkColorSpace> SkColorSpace::NewRGB(float gammaVals[3], const SkMatrix44& t oXYZD50) { 85 sk_sp<SkColorSpace> SkColorSpace::NewRGB(const float gammaVals[3], const SkMatri x44& toXYZD50) {
86 sk_sp<SkGammas> gammas = nullptr; 86 sk_sp<SkGammas> gammas = nullptr;
87 GammaNamed gammaNamed = kNonStandard_GammaNamed; 87 GammaNamed gammaNamed = kNonStandard_GammaNamed;
88 88
89 // Check if we really have sRGB or Adobe RGB 89 // Check if we really have sRGB or Adobe RGB
90 if (color_space_almost_equal(2.2f, gammaVals[0]) && 90 if (color_space_almost_equal(2.2f, gammaVals[0]) &&
91 color_space_almost_equal(2.2f, gammaVals[1]) && 91 color_space_almost_equal(2.2f, gammaVals[1]) &&
92 color_space_almost_equal(2.2f, gammaVals[2])) 92 color_space_almost_equal(2.2f, gammaVals[2]))
93 { 93 {
94 g2Dot2CurveGammasOnce([] { 94 g2Dot2CurveGammasOnce([] {
95 g2Dot2CurveGammas = new SkGammas(2.2f, 2.2f, 2.2f); 95 g2Dot2CurveGammas = new SkGammas(2.2f, 2.2f, 2.2f);
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 mat.set3x3ColMajorf(toXYZ); 788 mat.set3x3ColMajorf(toXYZ);
789 if (gammas->isValues()) { 789 if (gammas->isValues()) {
790 // When we have values, take advantage of the NewFromRGB ini tializer. 790 // When we have values, take advantage of the NewFromRGB ini tializer.
791 // This allows us to check for canonical sRGB and Adobe RGB. 791 // This allows us to check for canonical sRGB and Adobe RGB.
792 float gammaVals[3]; 792 float gammaVals[3];
793 gammaVals[0] = gammas->fRed.fValue; 793 gammaVals[0] = gammas->fRed.fValue;
794 gammaVals[1] = gammas->fGreen.fValue; 794 gammaVals[1] = gammas->fGreen.fValue;
795 gammaVals[2] = gammas->fBlue.fValue; 795 gammaVals[2] = gammas->fBlue.fValue;
796 return SkColorSpace::NewRGB(gammaVals, mat); 796 return SkColorSpace::NewRGB(gammaVals, mat);
797 } else { 797 } else {
798 return sk_sp<SkColorSpace>(new SkColorSpace_Base(gammas, mat , kUnknown_Named)); 798 return sk_sp<SkColorSpace>(new SkColorSpace_Base(std::move(g ammas), mat,
799 kUnknown_Na med));
799 } 800 }
800 } 801 }
801 802
802 // Recognize color profile specified by A2B0 tag. 803 // Recognize color profile specified by A2B0 tag.
803 const ICCTag* a2b0 = ICCTag::Find(tags.get(), tagCount, kTAG_A2B0); 804 const ICCTag* a2b0 = ICCTag::Find(tags.get(), tagCount, kTAG_A2B0);
804 if (a2b0) { 805 if (a2b0) {
805 SkAutoTDelete<SkColorLookUpTable> colorLUT(new SkColorLookUpTabl e()); 806 SkAutoTDelete<SkColorLookUpTable> colorLUT(new SkColorLookUpTabl e());
806 SkGammaCurve curves[3]; 807 SkGammaCurve curves[3];
807 SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); 808 SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor);
808 if (!load_a2b0(colorLUT, curves, &toXYZ, a2b0->addr((const uint8 _t*) base), 809 if (!load_a2b0(colorLUT, curves, &toXYZ, a2b0->addr((const uint8 _t*) base),
809 a2b0->fLength)) { 810 a2b0->fLength)) {
810 return_null("Failed to parse A2B0 tag"); 811 return_null("Failed to parse A2B0 tag");
811 } 812 }
812 813
813 sk_sp<SkGammas> gammas(new SkGammas(std::move(curves[0]), std::m ove(curves[1]), 814 sk_sp<SkGammas> gammas(new SkGammas(std::move(curves[0]), std::m ove(curves[1]),
814 std::move(curves[2]))); 815 std::move(curves[2])));
815 if (colorLUT->fTable) { 816 if (colorLUT->fTable) {
816 return sk_sp<SkColorSpace>(new SkColorSpace_Base(colorLUT.re lease(), gammas, 817 return sk_sp<SkColorSpace>(new SkColorSpace_Base(colorLUT.re lease(),
817 toXYZ)); 818 std::move(g ammas), toXYZ));
818 } else if (gammas->isValues()) { 819 } else if (gammas->isValues()) {
819 // When we have values, take advantage of the NewFromRGB ini tializer. 820 // When we have values, take advantage of the NewFromRGB ini tializer.
820 // This allows us to check for canonical sRGB and Adobe RGB. 821 // This allows us to check for canonical sRGB and Adobe RGB.
821 float gammaVals[3]; 822 float gammaVals[3];
822 gammaVals[0] = gammas->fRed.fValue; 823 gammaVals[0] = gammas->fRed.fValue;
823 gammaVals[1] = gammas->fGreen.fValue; 824 gammaVals[1] = gammas->fGreen.fValue;
824 gammaVals[2] = gammas->fBlue.fValue; 825 gammaVals[2] = gammas->fBlue.fValue;
825 return SkColorSpace::NewRGB(gammaVals, toXYZ); 826 return SkColorSpace::NewRGB(gammaVals, toXYZ);
826 } else { 827 } else {
827 return sk_sp<SkColorSpace>(new SkColorSpace_Base(gammas, toX YZ, 828 return sk_sp<SkColorSpace>(new SkColorSpace_Base(std::move(g ammas), toXYZ,
828 kUnknown_Na med)); 829 kUnknown_Na med));
829 } 830 }
830 } 831 }
831
832 } 832 }
833 default: 833 default:
834 break; 834 break;
835 } 835 }
836 836
837 return_null("ICC profile contains unsupported colorspace"); 837 return_null("ICC profile contains unsupported colorspace");
838 } 838 }
OLDNEW
« no previous file with comments | « include/core/SkColorSpace.h ('k') | src/core/SkColorSpace_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698