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

Side by Side Diff: src/core/SkColorSpace_Base.h

Issue 2159253005: Revert of Refactor parsing and storage of SkGammas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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 | « src/core/SkColorSpaceXform.cpp ('k') | src/core/SkColorSpace_ICC.cpp » ('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 #ifndef SkColorSpace_Base_DEFINED 8 #ifndef SkColorSpace_Base_DEFINED
9 #define SkColorSpace_Base_DEFINED 9 #define SkColorSpace_Base_DEFINED
10 10
11 #include "SkColorSpace.h" 11 #include "SkColorSpace.h"
12 #include "SkData.h" 12 #include "SkData.h"
13 #include "SkTemplates.h" 13 #include "SkTemplates.h"
14 14
15 struct SkGammas : SkRefCnt { 15 struct SkGammaCurve {
16 16 bool isNamed() const {
17 // There are four possible representations for gamma curves. kNone_Type is used 17 bool result = (SkColorSpace::kNonStandard_GammaNamed != fNamed);
18 // as a placeholder until the struct is initialized. It is not a valid valu e. 18 SkASSERT(!result || (0.0f == fValue));
19 enum class Type : uint8_t { 19 SkASSERT(!result || (0 == fTableSize));
20 kNone_Type, 20 SkASSERT(!result || (0.0f == fG && 0.0f == fE));
21 kNamed_Type, 21 return result;
22 kValue_Type,
23 kTable_Type,
24 kParam_Type,
25 };
26
27 // Contains information for a gamma table.
28 struct Table {
29 int fSize;
30 size_t fOffset;
31
32 const float* table(const SkGammas* base) const {
33 return SkTAddOffset<const float>(base, sizeof(SkGammas) + fOffset);
34 }
35 };
36
37 // Contains the parameters for a parametric curve.
38 struct Params {
39 // Y = (aX + b)^g + c for X >= d
40 // Y = eX + f otherwise
41 float fG;
42 float fA;
43 float fB;
44 float fC;
45 float fD;
46 float fE;
47 float fF;
48 };
49
50 // Contains the actual gamma curve information. Should be interpreted
51 // based on the type of the gamma curve.
52 union Data {
53 Data()
54 : fTable{ 0, 0 }
55 {}
56
57 SkColorSpace::GammaNamed fNamed;
58 float fValue;
59 Table fTable;
60 size_t fParamOffset;
61
62 const Params& params(const SkGammas* base) const {
63 return *SkTAddOffset<const Params>(base, sizeof(SkGammas) + fParamOf fset);
64 }
65 };
66
67 bool isNamed(int i) const {
68 SkASSERT(0 <= i && i < 3);
69 return (&fRedType)[i] == Type::kNamed_Type;
70 } 22 }
71 23
72 bool isValue(int i) const { 24 bool isValue() const {
73 SkASSERT(0 <= i && i < 3); 25 bool result = (0.0f != fValue);
74 return (&fRedType)[i] == Type::kValue_Type; 26 SkASSERT(!result || SkColorSpace::kNonStandard_GammaNamed == fNamed);
27 SkASSERT(!result || (0 == fTableSize));
28 SkASSERT(!result || (0.0f == fG && 0.0f == fE));
29 return result;
75 } 30 }
76 31
77 bool isTable(int i) const { 32 bool isTable() const {
78 SkASSERT(0 <= i && i < 3); 33 bool result = (0 != fTableSize);
79 return (&fRedType)[i] == Type::kTable_Type; 34 SkASSERT(!result || SkColorSpace::kNonStandard_GammaNamed == fNamed);
35 SkASSERT(!result || (0.0f == fValue));
36 SkASSERT(!result || (0.0f == fG && 0.0f == fE));
37 SkASSERT(!result || fTable);
38 return result;
80 } 39 }
81 40
82 bool isParametric(int i) const { 41 bool isParametric() const {
83 SkASSERT(0 <= i && i < 3); 42 bool result = (0.0f != fG || 0.0f != fE);
84 return (&fRedType)[i] == Type::kParam_Type; 43 SkASSERT(!result || SkColorSpace::kNonStandard_GammaNamed == fNamed);
44 SkASSERT(!result || (0.0f == fValue));
45 SkASSERT(!result || (0 == fTableSize));
46 return result;
85 } 47 }
86 48
87 const Data& data(int i) const { 49 // We have four different ways to represent gamma.
88 SkASSERT(0 <= i && i < 3); 50 // (1) A known, named type:
89 return (&fRedData)[i]; 51 SkColorSpace::GammaNamed fNamed;
52
53 // (2) A single value:
54 float fValue;
55
56 // (3) A lookup table:
57 uint32_t fTableSize;
58 std::unique_ptr<float[]> fTable;
59
60 // (4) Parameters for a curve:
61 // Y = (aX + b)^g + c for X >= d
62 // Y = eX + f otherwise
63 float fG;
64 float fA;
65 float fB;
66 float fC;
67 float fD;
68 float fE;
69 float fF;
70
71 SkGammaCurve()
72 : fNamed(SkColorSpace::kNonStandard_GammaNamed)
73 , fValue(0.0f)
74 , fTableSize(0)
75 , fTable(nullptr)
76 , fG(0.0f)
77 , fA(0.0f)
78 , fB(0.0f)
79 , fC(0.0f)
80 , fD(0.0f)
81 , fE(0.0f)
82 , fF(0.0f)
83 {}
84
85 bool quickEquals(const SkGammaCurve& that) const {
86 return (this->fNamed == that.fNamed) && (this->fValue == that.fValue) &&
87 (this->fTableSize == that.fTableSize) && (this->fTable == that.f Table) &&
88 (this->fG == that.fG) && (this->fA == that.fA) && (this->fB == t hat.fB) &&
89 (this->fC == that.fC) && (this->fD == that.fD) && (this->fE == t hat.fE) &&
90 (this->fF == that.fF);
91 }
92 };
93
94 struct SkGammas : public SkRefCnt {
95 public:
96 static SkColorSpace::GammaNamed Named(SkGammaCurve curves[3]) {
97 if (SkColorSpace::kLinear_GammaNamed == curves[0].fNamed &&
98 SkColorSpace::kLinear_GammaNamed == curves[1].fNamed &&
99 SkColorSpace::kLinear_GammaNamed == curves[2].fNamed)
100 {
101 return SkColorSpace::kLinear_GammaNamed;
102 }
103
104 if (SkColorSpace::kSRGB_GammaNamed == curves[0].fNamed &&
105 SkColorSpace::kSRGB_GammaNamed == curves[1].fNamed &&
106 SkColorSpace::kSRGB_GammaNamed == curves[2].fNamed)
107 {
108 return SkColorSpace::kSRGB_GammaNamed;
109 }
110
111 if (SkColorSpace::k2Dot2Curve_GammaNamed == curves[0].fNamed &&
112 SkColorSpace::k2Dot2Curve_GammaNamed == curves[1].fNamed &&
113 SkColorSpace::k2Dot2Curve_GammaNamed == curves[2].fNamed)
114 {
115 return SkColorSpace::k2Dot2Curve_GammaNamed;
116 }
117
118 return SkColorSpace::kNonStandard_GammaNamed;
90 } 119 }
91 120
92 const float* table(int i) const { 121 const SkGammaCurve& operator[](int i) const {
93 SkASSERT(isTable(i)); 122 SkASSERT(0 <= i && i < 3);
94 return (&fRedData)[i].fTable.table(this); 123 return (&fRed)[i];
95 } 124 }
96 125
97 const Params& params(int i) const { 126 const SkGammaCurve fRed;
98 SkASSERT(isParametric(i)); 127 const SkGammaCurve fGreen;
99 return (&fRedData)[i].params(this); 128 const SkGammaCurve fBlue;
100 }
101 129
102 SkGammas() 130 SkGammas(SkGammaCurve red, SkGammaCurve green, SkGammaCurve blue)
103 : fRedType(Type::kNone_Type) 131 : fRed(std::move(red))
104 , fGreenType(Type::kNone_Type) 132 , fGreen(std::move(green))
105 , fBlueType(Type::kNone_Type) 133 , fBlue(std::move(blue))
106 {} 134 {}
107 135
108 // These fields should only be modified when initializing the struct. 136 SkGammas() {}
109 Data fRedData; 137
110 Data fGreenData; 138 friend class SkColorSpace;
111 Data fBlueData;
112 Type fRedType;
113 Type fGreenType;
114 Type fBlueType;
115 }; 139 };
116 140
117 struct SkColorLookUpTable : public SkRefCnt { 141 struct SkColorLookUpTable : public SkRefCnt {
118 uint8_t fInputChannels; 142 uint8_t fInputChannels;
119 uint8_t fOutputChannels; 143 uint8_t fOutputChannels;
120 uint8_t fGridPoints[3]; 144 uint8_t fGridPoints[3];
121 std::unique_ptr<float[]> fTable; 145 std::unique_ptr<float[]> fTable;
122 146
123 SkColorLookUpTable() 147 SkColorLookUpTable()
124 : fInputChannels(0) 148 : fInputChannels(0)
(...skipping 17 matching lines...) Expand all
142 * Writes this object as an ICC profile. 166 * Writes this object as an ICC profile.
143 */ 167 */
144 sk_sp<SkData> writeToICC() const; 168 sk_sp<SkData> writeToICC() const;
145 169
146 private: 170 private:
147 171
148 static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkMatrix44& t oXYZD50); 172 static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkMatrix44& t oXYZD50);
149 173
150 SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& toXYZ, Named name d); 174 SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& toXYZ, Named name d);
151 175
152 SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, GammaNamed gammaNamed, 176 SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, sk_sp<SkGammas> gammas ,
153 sk_sp<SkGammas> gammas, const SkMatrix44& toXYZ, sk_sp<SkD ata> profileData); 177 const SkMatrix44& toXYZ, sk_sp<SkData> profileData);
154 178
155 sk_sp<SkColorLookUpTable> fColorLUT; 179 sk_sp<SkColorLookUpTable> fColorLUT;
156 sk_sp<SkGammas> fGammas; 180 sk_sp<SkGammas> fGammas;
157 sk_sp<SkData> fProfileData; 181 sk_sp<SkData> fProfileData;
158 182
159 friend class SkColorSpace; 183 friend class SkColorSpace;
160 friend class ColorSpaceXformTest; 184 friend class ColorSpaceXformTest;
161 typedef SkColorSpace INHERITED; 185 typedef SkColorSpace INHERITED;
162 }; 186 };
163 187
164 static inline SkColorSpace_Base* as_CSB(SkColorSpace* colorSpace) { 188 static inline SkColorSpace_Base* as_CSB(SkColorSpace* colorSpace) {
165 return static_cast<SkColorSpace_Base*>(colorSpace); 189 return static_cast<SkColorSpace_Base*>(colorSpace);
166 } 190 }
167 191
168 static inline const SkColorSpace_Base* as_CSB(const SkColorSpace* colorSpace) { 192 static inline const SkColorSpace_Base* as_CSB(const SkColorSpace* colorSpace) {
169 return static_cast<const SkColorSpace_Base*>(colorSpace); 193 return static_cast<const SkColorSpace_Base*>(colorSpace);
170 } 194 }
171 195
172 static inline SkColorSpace_Base* as_CSB(const sk_sp<SkColorSpace>& colorSpace) { 196 static inline SkColorSpace_Base* as_CSB(const sk_sp<SkColorSpace>& colorSpace) {
173 return static_cast<SkColorSpace_Base*>(colorSpace.get()); 197 return static_cast<SkColorSpace_Base*>(colorSpace.get());
174 } 198 }
175 199
176 #endif 200 #endif
OLDNEW
« no previous file with comments | « src/core/SkColorSpaceXform.cpp ('k') | src/core/SkColorSpace_ICC.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698