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

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

Issue 2318663003: Delete SkColorSpace::gammaNamed() from public API (Closed) Base URL: https://skia.googlesource.com/skia.git@delunknownnamed
Patch Set: Rebase Created 4 years, 3 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/SkColorSpaceXform.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 "SkColorSpacePriv.h" 10 #include "SkColorSpacePriv.h"
11 #include "SkOnce.h" 11 #include "SkOnce.h"
12 12
13 SkColorSpace::SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50) 13 SkColorSpace::SkColorSpace(const SkMatrix44& toXYZD50)
14 : fGammaNamed(gammaNamed) 14 : fToXYZD50(toXYZD50)
15 , fToXYZD50(toXYZD50)
16 {} 15 {}
17 16
18 SkColorSpace_Base::SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& to XYZD50) 17 SkColorSpace_Base::SkColorSpace_Base(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50)
19 : INHERITED(gammaNamed, toXYZD50) 18 : INHERITED(toXYZD50)
19 , fGammaNamed(gammaNamed)
20 , fGammas(nullptr) 20 , fGammas(nullptr)
21 , fProfileData(nullptr) 21 , fProfileData(nullptr)
22 {} 22 {}
23 23
24 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, GammaNa med gammaNamed, 24 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, SkGamma Named gammaNamed,
25 sk_sp<SkGammas> gammas, const SkMatrix44& t oXYZD50, 25 sk_sp<SkGammas> gammas, const SkMatrix44& t oXYZD50,
26 sk_sp<SkData> profileData) 26 sk_sp<SkData> profileData)
27 : INHERITED(gammaNamed, toXYZD50) 27 : INHERITED(toXYZD50)
28 , fColorLUT(std::move(colorLUT)) 28 , fColorLUT(std::move(colorLUT))
29 , fGammaNamed(gammaNamed)
29 , fGammas(std::move(gammas)) 30 , fGammas(std::move(gammas))
30 , fProfileData(std::move(profileData)) 31 , fProfileData(std::move(profileData))
31 {} 32 {}
32 33
33 static constexpr float gSRGB_toXYZD50[] { 34 static constexpr float gSRGB_toXYZD50[] {
34 0.4358f, 0.2224f, 0.0139f, // * R 35 0.4358f, 0.2224f, 0.0139f, // * R
35 0.3853f, 0.7170f, 0.0971f, // * G 36 0.3853f, 0.7170f, 0.0971f, // * G
36 0.1430f, 0.0606f, 0.7139f, // * B 37 0.1430f, 0.0606f, 0.7139f, // * B
37 }; 38 };
38 39
(...skipping 26 matching lines...) Expand all
65 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) && 66 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) &&
66 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) && 67 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) &&
67 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f); 68 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f);
68 } 69 }
69 70
70 sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(const float values[3], const SkMat rix44& toXYZD50) { 71 sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(const float values[3], const SkMat rix44& toXYZD50) {
71 if (0.0f > values[0] || 0.0f > values[1] || 0.0f > values[2]) { 72 if (0.0f > values[0] || 0.0f > values[1] || 0.0f > values[2]) {
72 return nullptr; 73 return nullptr;
73 } 74 }
74 75
75 GammaNamed gammaNamed = kNonStandard_GammaNamed; 76 SkGammaNamed gammaNamed = kNonStandard_SkGammaNamed;
76 if (color_space_almost_equal(2.2f, values[0]) && 77 if (color_space_almost_equal(2.2f, values[0]) &&
77 color_space_almost_equal(2.2f, values[1]) && 78 color_space_almost_equal(2.2f, values[1]) &&
78 color_space_almost_equal(2.2f, values[2])) { 79 color_space_almost_equal(2.2f, values[2])) {
79 gammaNamed = k2Dot2Curve_GammaNamed; 80 gammaNamed = k2Dot2Curve_SkGammaNamed;
80 } else if (color_space_almost_equal(1.0f, values[0]) && 81 } else if (color_space_almost_equal(1.0f, values[0]) &&
81 color_space_almost_equal(1.0f, values[1]) && 82 color_space_almost_equal(1.0f, values[1]) &&
82 color_space_almost_equal(1.0f, values[2])) { 83 color_space_almost_equal(1.0f, values[2])) {
83 gammaNamed = kLinear_GammaNamed; 84 gammaNamed = kLinear_SkGammaNamed;
84 } 85 }
85 86
86 if (kNonStandard_GammaNamed == gammaNamed) { 87 if (kNonStandard_SkGammaNamed == gammaNamed) {
87 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas()); 88 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas());
88 gammas->fRedType = SkGammas::Type::kValue_Type; 89 gammas->fRedType = SkGammas::Type::kValue_Type;
89 gammas->fGreenType = SkGammas::Type::kValue_Type; 90 gammas->fGreenType = SkGammas::Type::kValue_Type;
90 gammas->fBlueType = SkGammas::Type::kValue_Type; 91 gammas->fBlueType = SkGammas::Type::kValue_Type;
91 gammas->fRedData.fValue = values[0]; 92 gammas->fRedData.fValue = values[0];
92 gammas->fGreenData.fValue = values[1]; 93 gammas->fGreenData.fValue = values[1];
93 gammas->fBlueData.fValue = values[2]; 94 gammas->fBlueData.fValue = values[2];
94 return sk_sp<SkColorSpace>(new SkColorSpace_Base(nullptr, kNonStandard_G ammaNamed, gammas, 95 return sk_sp<SkColorSpace>(new SkColorSpace_Base(nullptr, kNonStandard_S kGammaNamed, gammas,
95 toXYZD50, nullptr)); 96 toXYZD50, nullptr));
96 } 97 }
97 98
98 return SkColorSpace_Base::NewRGB(gammaNamed, toXYZD50); 99 return SkColorSpace_Base::NewRGB(gammaNamed, toXYZD50);
99 } 100 }
100 101
101 sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(GammaNamed gammaNamed, const SkMat rix44& toXYZD50) { 102 sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(SkGammaNamed gammaNamed, const SkM atrix44& toXYZD50) {
102 switch (gammaNamed) { 103 switch (gammaNamed) {
103 case kSRGB_GammaNamed: 104 case kSRGB_SkGammaNamed:
104 if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) { 105 if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) {
105 return SkColorSpace::NewNamed(kSRGB_Named); 106 return SkColorSpace::NewNamed(kSRGB_Named);
106 } 107 }
107 break; 108 break;
108 case k2Dot2Curve_GammaNamed: 109 case k2Dot2Curve_SkGammaNamed:
109 if (xyz_almost_equal(toXYZD50, gAdobeRGB_toXYZD50)) { 110 if (xyz_almost_equal(toXYZD50, gAdobeRGB_toXYZD50)) {
110 return SkColorSpace::NewNamed(kAdobeRGB_Named); 111 return SkColorSpace::NewNamed(kAdobeRGB_Named);
111 } 112 }
112 break; 113 break;
113 case kNonStandard_GammaNamed: 114 case kNonStandard_SkGammaNamed:
114 // This is not allowed. 115 // This is not allowed.
115 return nullptr; 116 return nullptr;
116 default: 117 default:
117 break; 118 break;
118 } 119 }
119 120
120 return sk_sp<SkColorSpace>(new SkColorSpace_Base(gammaNamed, toXYZD50)); 121 return sk_sp<SkColorSpace>(new SkColorSpace_Base(gammaNamed, toXYZD50));
121 } 122 }
122 123
123 sk_sp<SkColorSpace> SkColorSpace::NewRGB(GammaNamed gammaNamed, const SkMatrix44 & toXYZD50) { 124 sk_sp<SkColorSpace> SkColorSpace::NewRGB(GammaNamed gammaNamed, const SkMatrix44 & toXYZD50) {
124 return SkColorSpace_Base::NewRGB(gammaNamed, toXYZD50); 125 switch (gammaNamed) {
126 case kLinear_GammaNamed:
127 return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, toXYZD50);
128 case kSRGB_GammaNamed:
129 return SkColorSpace_Base::NewRGB(kSRGB_SkGammaNamed, toXYZD50);
130 default:
131 return nullptr;
132 }
125 } 133 }
126 134
127 static SkColorSpace* gAdobeRGB; 135 static SkColorSpace* gAdobeRGB;
128 static SkColorSpace* gSRGB; 136 static SkColorSpace* gSRGB;
129 137
130 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { 138 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
131 static SkOnce sRGBOnce; 139 static SkOnce sRGBOnce;
132 static SkOnce adobeRGBOnce; 140 static SkOnce adobeRGBOnce;
133 141
134 switch (named) { 142 switch (named) {
135 case kSRGB_Named: { 143 case kSRGB_Named: {
136 sRGBOnce([] { 144 sRGBOnce([] {
137 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); 145 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
138 srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50); 146 srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50);
139 147
140 // Force the mutable type mask to be computed. This avoids race s. 148 // Force the mutable type mask to be computed. This avoids race s.
141 (void)srgbToxyzD50.getType(); 149 (void)srgbToxyzD50.getType();
142 gSRGB = new SkColorSpace_Base(kSRGB_GammaNamed, srgbToxyzD50); 150 gSRGB = new SkColorSpace_Base(kSRGB_SkGammaNamed, srgbToxyzD50);
143 }); 151 });
144 return sk_ref_sp<SkColorSpace>(gSRGB); 152 return sk_ref_sp<SkColorSpace>(gSRGB);
145 } 153 }
146 case kAdobeRGB_Named: { 154 case kAdobeRGB_Named: {
147 adobeRGBOnce([] { 155 adobeRGBOnce([] {
148 SkMatrix44 adobergbToxyzD50(SkMatrix44::kUninitialized_Construct or); 156 SkMatrix44 adobergbToxyzD50(SkMatrix44::kUninitialized_Construct or);
149 adobergbToxyzD50.set3x3RowMajorf(gAdobeRGB_toXYZD50); 157 adobergbToxyzD50.set3x3RowMajorf(gAdobeRGB_toXYZD50);
150 158
151 // Force the mutable type mask to be computed. This avoids race s. 159 // Force the mutable type mask to be computed. This avoids race s.
152 (void)adobergbToxyzD50.getType(); 160 (void)adobergbToxyzD50.getType();
153 gAdobeRGB = new SkColorSpace_Base(k2Dot2Curve_GammaNamed, adober gbToxyzD50); 161 gAdobeRGB = new SkColorSpace_Base(k2Dot2Curve_SkGammaNamed, adob ergbToxyzD50);
154 }); 162 });
155 return sk_ref_sp<SkColorSpace>(gAdobeRGB); 163 return sk_ref_sp<SkColorSpace>(gAdobeRGB);
156 } 164 }
157 default: 165 default:
158 break; 166 break;
159 } 167 }
160 return nullptr; 168 return nullptr;
161 } 169 }
162 170
163 sk_sp<SkColorSpace> SkColorSpace::makeLinearGamma() { 171 sk_sp<SkColorSpace> SkColorSpace::makeLinearGamma() {
164 return SkColorSpace_Base::NewRGB(kLinear_GammaNamed, fToXYZD50); 172 return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, fToXYZD50);
173 }
174 //////////////////////////////////////////////////////////////////////////////// ///////////////////
175
176 bool SkColorSpace::gammaCloseToSRGB() const {
177 return kSRGB_SkGammaNamed == as_CSB(this)->fGammaNamed ||
178 k2Dot2Curve_SkGammaNamed == as_CSB(this)->fGammaNamed;
179 }
180
181 bool SkColorSpace::gammaIsLinear() const {
182 return kLinear_SkGammaNamed == as_CSB(this)->fGammaNamed;
165 } 183 }
166 184
167 //////////////////////////////////////////////////////////////////////////////// /////////////////// 185 //////////////////////////////////////////////////////////////////////////////// ///////////////////
168 186
169 enum Version { 187 enum Version {
170 k0_Version, // Initial version, header + flags for matrix and profile 188 k0_Version, // Initial version, header + flags for matrix and profile
171 }; 189 };
172 190
173 struct ColorSpaceHeader { 191 struct ColorSpaceHeader {
174 /** 192 /**
(...skipping 21 matching lines...) Expand all
196 static ColorSpaceHeader Pack(Version version, uint8_t named, uint8_t gammaNa med, uint8_t flags) 214 static ColorSpaceHeader Pack(Version version, uint8_t named, uint8_t gammaNa med, uint8_t flags)
197 { 215 {
198 ColorSpaceHeader header; 216 ColorSpaceHeader header;
199 217
200 SkASSERT(k0_Version == version); 218 SkASSERT(k0_Version == version);
201 header.fVersion = (uint8_t) version; 219 header.fVersion = (uint8_t) version;
202 220
203 SkASSERT(named <= SkColorSpace::kAdobeRGB_Named); 221 SkASSERT(named <= SkColorSpace::kAdobeRGB_Named);
204 header.fNamed = (uint8_t) named; 222 header.fNamed = (uint8_t) named;
205 223
206 SkASSERT(gammaNamed <= SkColorSpace::kNonStandard_GammaNamed); 224 SkASSERT(gammaNamed <= kNonStandard_SkGammaNamed);
207 header.fGammaNamed = (uint8_t) gammaNamed; 225 header.fGammaNamed = (uint8_t) gammaNamed;
208 226
209 SkASSERT(flags <= kFloatGamma_Flag); 227 SkASSERT(flags <= kFloatGamma_Flag);
210 header.fFlags = flags; 228 header.fFlags = flags;
211 return header; 229 return header;
212 } 230 }
213 231
214 uint8_t fVersion; // Always zero 232 uint8_t fVersion; // Always zero
215 uint8_t fNamed; // Must be a SkColorSpace::Named 233 uint8_t fNamed; // Must be a SkColorSpace::Named
216 uint8_t fGammaNamed; // Must be a SkColorSpace::GammaNamed 234 uint8_t fGammaNamed; // Must be a SkGammaNamed
217 uint8_t fFlags; // Some combination of the flags listed above 235 uint8_t fFlags; // Some combination of the flags listed above
218 }; 236 };
219 237
220 size_t SkColorSpace::writeToMemory(void* memory) const { 238 size_t SkColorSpace::writeToMemory(void* memory) const {
221 // Start by trying the serialization fast path. If we haven't saved ICC pro file data, 239 // Start by trying the serialization fast path. If we haven't saved ICC pro file data,
222 // we must have a profile that we can serialize easily. 240 // we must have a profile that we can serialize easily.
223 if (!as_CSB(this)->fProfileData) { 241 if (!as_CSB(this)->fProfileData) {
224 // If we have a named profile, only write the enum. 242 // If we have a named profile, only write the enum.
225 if (this == gSRGB) { 243 if (this == gSRGB) {
226 if (memory) { 244 if (memory) {
227 *((ColorSpaceHeader*) memory) = 245 *((ColorSpaceHeader*) memory) =
228 ColorSpaceHeader::Pack(k0_Version, kSRGB_Named, fGammaNa med, 0); 246 ColorSpaceHeader::Pack(k0_Version, kSRGB_Named,
247 as_CSB(this)->fGammaNamed, 0);
229 } 248 }
230 return sizeof(ColorSpaceHeader); 249 return sizeof(ColorSpaceHeader);
231 } else if (this == gAdobeRGB) { 250 } else if (this == gAdobeRGB) {
232 if (memory) { 251 if (memory) {
233 *((ColorSpaceHeader*) memory) = 252 *((ColorSpaceHeader*) memory) =
234 ColorSpaceHeader::Pack(k0_Version, kAdobeRGB_Named, fGam maNamed, 0); 253 ColorSpaceHeader::Pack(k0_Version, kAdobeRGB_Named,
254 as_CSB(this)->fGammaNamed, 0);
235 } 255 }
236 } 256 }
237 257
238 // If we have a named gamma, write the enum and the matrix. 258 // If we have a named gamma, write the enum and the matrix.
239 switch (fGammaNamed) { 259 switch (as_CSB(this)->fGammaNamed) {
240 case kSRGB_GammaNamed: 260 case kSRGB_SkGammaNamed:
241 case k2Dot2Curve_GammaNamed: 261 case k2Dot2Curve_SkGammaNamed:
242 case kLinear_GammaNamed: { 262 case kLinear_SkGammaNamed: {
243 if (memory) { 263 if (memory) {
244 *((ColorSpaceHeader*) memory) = 264 *((ColorSpaceHeader*) memory) =
245 ColorSpaceHeader::Pack(k0_Version, 0, fGammaNamed, 265 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)-> fGammaNamed,
246 ColorSpaceHeader::kMatrix_Fla g); 266 ColorSpaceHeader::kMatrix_Fla g);
247 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader) ); 267 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader) );
248 fToXYZD50.as4x3ColMajorf((float*) memory); 268 fToXYZD50.as4x3ColMajorf((float*) memory);
249 } 269 }
250 return sizeof(ColorSpaceHeader) + 12 * sizeof(float); 270 return sizeof(ColorSpaceHeader) + 12 * sizeof(float);
251 } 271 }
252 default: 272 default:
253 // Otherwise, write the gamma values and the matrix. 273 // Otherwise, write the gamma values and the matrix.
254 if (memory) { 274 if (memory) {
255 *((ColorSpaceHeader*) memory) = 275 *((ColorSpaceHeader*) memory) =
256 ColorSpaceHeader::Pack(k0_Version, 0, fGammaNamed, 276 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)-> fGammaNamed,
257 ColorSpaceHeader::kFloatGamma _Flag); 277 ColorSpaceHeader::kFloatGamma _Flag);
258 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader) ); 278 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader) );
259 279
260 const SkGammas* gammas = as_CSB(this)->gammas(); 280 const SkGammas* gammas = as_CSB(this)->gammas();
261 SkASSERT(gammas); 281 SkASSERT(gammas);
262 SkASSERT(SkGammas::Type::kValue_Type == gammas->fRedType && 282 SkASSERT(SkGammas::Type::kValue_Type == gammas->fRedType &&
263 SkGammas::Type::kValue_Type == gammas->fGreenType & & 283 SkGammas::Type::kValue_Type == gammas->fGreenType & &
264 SkGammas::Type::kValue_Type == gammas->fBlueType); 284 SkGammas::Type::kValue_Type == gammas->fBlueType);
265 *(((float*) memory) + 0) = gammas->fRedData.fValue; 285 *(((float*) memory) + 0) = gammas->fRedData.fValue;
266 *(((float*) memory) + 1) = gammas->fGreenData.fValue; 286 *(((float*) memory) + 1) = gammas->fGreenData.fValue;
267 *(((float*) memory) + 2) = gammas->fBlueData.fValue; 287 *(((float*) memory) + 2) = gammas->fBlueData.fValue;
268 memory = SkTAddOffset<void>(memory, 3 * sizeof(float)); 288 memory = SkTAddOffset<void>(memory, 3 * sizeof(float));
269 289
270 fToXYZD50.as4x3ColMajorf((float*) memory); 290 fToXYZD50.as4x3ColMajorf((float*) memory);
271 } 291 }
272 return sizeof(ColorSpaceHeader) + 15 * sizeof(float); 292 return sizeof(ColorSpaceHeader) + 15 * sizeof(float);
273 } 293 }
274 } 294 }
275 295
276 // Otherwise, serialize the ICC data. 296 // Otherwise, serialize the ICC data.
277 size_t profileSize = as_CSB(this)->fProfileData->size(); 297 size_t profileSize = as_CSB(this)->fProfileData->size();
278 if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { 298 if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) {
279 return 0; 299 return 0;
280 } 300 }
281 301
282 if (memory) { 302 if (memory) {
283 *((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(k0_Version, 0, 303 *((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(k0_Version, 0,
284 kNonStandard_Gamm aNamed, 304 kNonStandard_SkGa mmaNamed,
285 ColorSpaceHeader: :kICC_Flag); 305 ColorSpaceHeader: :kICC_Flag);
286 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)); 306 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader));
287 307
288 *((uint32_t*) memory) = (uint32_t) SkAlign4(profileSize); 308 *((uint32_t*) memory) = (uint32_t) SkAlign4(profileSize);
289 memory = SkTAddOffset<void>(memory, sizeof(uint32_t)); 309 memory = SkTAddOffset<void>(memory, sizeof(uint32_t));
290 310
291 memcpy(memory, as_CSB(this)->fProfileData->data(), profileSize); 311 memcpy(memory, as_CSB(this)->fProfileData->data(), profileSize);
292 memset(SkTAddOffset<void>(memory, profileSize), 0, SkAlign4(profileSize) - profileSize); 312 memset(SkTAddOffset<void>(memory, profileSize), 0, SkAlign4(profileSize) - profileSize);
293 } 313 }
294 return sizeof(ColorSpaceHeader) + sizeof(uint32_t) + SkAlign4(profileSize); 314 return sizeof(ColorSpaceHeader) + sizeof(uint32_t) + SkAlign4(profileSize);
(...skipping 15 matching lines...) Expand all
310 return nullptr; 330 return nullptr;
311 } 331 }
312 332
313 ColorSpaceHeader header = *((const ColorSpaceHeader*) data); 333 ColorSpaceHeader header = *((const ColorSpaceHeader*) data);
314 data = SkTAddOffset<const void>(data, sizeof(ColorSpaceHeader)); 334 data = SkTAddOffset<const void>(data, sizeof(ColorSpaceHeader));
315 length -= sizeof(ColorSpaceHeader); 335 length -= sizeof(ColorSpaceHeader);
316 if (0 == header.fFlags) { 336 if (0 == header.fFlags) {
317 return NewNamed((Named) header.fNamed); 337 return NewNamed((Named) header.fNamed);
318 } 338 }
319 339
320 switch ((GammaNamed) header.fGammaNamed) { 340 switch ((SkGammaNamed) header.fGammaNamed) {
321 case kSRGB_GammaNamed: 341 case kSRGB_SkGammaNamed:
322 case k2Dot2Curve_GammaNamed: 342 case k2Dot2Curve_SkGammaNamed:
323 case kLinear_GammaNamed: { 343 case kLinear_SkGammaNamed: {
324 if (ColorSpaceHeader::kMatrix_Flag != header.fFlags || length < 12 * sizeof(float)) { 344 if (ColorSpaceHeader::kMatrix_Flag != header.fFlags || length < 12 * sizeof(float)) {
325 return nullptr; 345 return nullptr;
326 } 346 }
327 347
328 SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); 348 SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor);
329 toXYZ.set4x3ColMajorf((const float*) data); 349 toXYZ.set4x3ColMajorf((const float*) data);
330 return NewRGB((GammaNamed) header.fGammaNamed, toXYZ); 350 return SkColorSpace_Base::NewRGB((SkGammaNamed) header.fGammaNamed, toXYZ);
331 } 351 }
332 default: 352 default:
333 break; 353 break;
334 } 354 }
335 355
336 switch (header.fFlags) { 356 switch (header.fFlags) {
337 case ColorSpaceHeader::kICC_Flag: { 357 case ColorSpaceHeader::kICC_Flag: {
338 if (length < sizeof(uint32_t)) { 358 if (length < sizeof(uint32_t)) {
339 return nullptr; 359 return nullptr;
340 } 360 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 if (srcData && dstData) { 403 if (srcData && dstData) {
384 return srcData->size() == dstData->size() && 404 return srcData->size() == dstData->size() &&
385 0 == memcmp(srcData->data(), dstData->data(), srcData->size() ); 405 0 == memcmp(srcData->data(), dstData->data(), srcData->size() );
386 } 406 }
387 407
388 return false; 408 return false;
389 } 409 }
390 410
391 // It's important to check fProfileData before named gammas. Some profiles may have named 411 // It's important to check fProfileData before named gammas. Some profiles may have named
392 // gammas, but also include other wacky features that cause us to save the d ata. 412 // gammas, but also include other wacky features that cause us to save the d ata.
393 switch (src->fGammaNamed) { 413 switch (as_CSB(src)->fGammaNamed) {
394 case kSRGB_GammaNamed: 414 case kSRGB_SkGammaNamed:
395 case k2Dot2Curve_GammaNamed: 415 case k2Dot2Curve_SkGammaNamed:
396 case kLinear_GammaNamed: 416 case kLinear_SkGammaNamed:
397 return (src->fGammaNamed == dst->fGammaNamed) && (src->fToXYZD50 == dst->fToXYZD50); 417 return (as_CSB(src)->fGammaNamed == as_CSB(dst)->fGammaNamed) &&
418 (src->fToXYZD50 == dst->fToXYZD50);
398 default: 419 default:
399 if (src->fGammaNamed != dst->fGammaNamed) { 420 if (as_CSB(src)->fGammaNamed != as_CSB(dst)->fGammaNamed) {
400 return false; 421 return false;
401 } 422 }
402 423
403 // It is unlikely that we will reach this case. 424 // It is unlikely that we will reach this case.
404 sk_sp<SkData> srcData = src->serialize(); 425 sk_sp<SkData> srcData = src->serialize();
405 sk_sp<SkData> dstData = dst->serialize(); 426 sk_sp<SkData> dstData = dst->serialize();
406 return srcData->size() == dstData->size() && 427 return srcData->size() == dstData->size() &&
407 0 == memcmp(srcData->data(), dstData->data(), srcData->size() ); 428 0 == memcmp(srcData->data(), dstData->data(), srcData->size() );
408 } 429 }
409 } 430 }
OLDNEW
« no previous file with comments | « include/core/SkColorSpace.h ('k') | src/core/SkColorSpaceXform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698