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) | |
14 : fToXYZD50(toXYZD50) | |
15 {} | |
16 | |
17 SkColorSpace_Base::SkColorSpace_Base(SkGammaNamed gammaNamed, const SkMatrix44&
toXYZD50) | 13 SkColorSpace_Base::SkColorSpace_Base(SkGammaNamed gammaNamed, const SkMatrix44&
toXYZD50) |
18 : INHERITED(toXYZD50) | 14 : fGammaNamed(gammaNamed) |
19 , fGammaNamed(gammaNamed) | |
20 , fGammas(nullptr) | 15 , fGammas(nullptr) |
21 , fProfileData(nullptr) | 16 , fProfileData(nullptr) |
| 17 , fToXYZD50(toXYZD50) |
22 , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) | 18 , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) |
23 {} | 19 {} |
24 | 20 |
25 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, SkGamma
Named gammaNamed, | 21 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, SkGamma
Named gammaNamed, |
26 sk_sp<SkGammas> gammas, const SkMatrix44& t
oXYZD50, | 22 sk_sp<SkGammas> gammas, const SkMatrix44& t
oXYZD50, |
27 sk_sp<SkData> profileData) | 23 sk_sp<SkData> profileData) |
28 : INHERITED(toXYZD50) | 24 : fColorLUT(std::move(colorLUT)) |
29 , fColorLUT(std::move(colorLUT)) | |
30 , fGammaNamed(gammaNamed) | 25 , fGammaNamed(gammaNamed) |
31 , fGammas(std::move(gammas)) | 26 , fGammas(std::move(gammas)) |
32 , fProfileData(std::move(profileData)) | 27 , fProfileData(std::move(profileData)) |
| 28 , fToXYZD50(toXYZD50) |
33 , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) | 29 , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) |
34 {} | 30 {} |
35 | 31 |
36 static constexpr float gSRGB_toXYZD50[] { | 32 static constexpr float gSRGB_toXYZD50[] { |
37 0.4358f, 0.3853f, 0.1430f, // Rx, Gx, Bx | 33 0.4358f, 0.3853f, 0.1430f, // Rx, Gx, Bx |
38 0.2224f, 0.7170f, 0.0606f, // Ry, Gy, Gz | 34 0.2224f, 0.7170f, 0.0606f, // Ry, Gy, Gz |
39 0.0139f, 0.0971f, 0.7139f, // Rz, Gz, Bz | 35 0.0139f, 0.0971f, 0.7139f, // Rz, Gz, Bz |
40 }; | 36 }; |
41 | 37 |
42 static constexpr float gAdobeRGB_toXYZD50[] { | 38 static constexpr float gAdobeRGB_toXYZD50[] { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 default: | 181 default: |
186 break; | 182 break; |
187 } | 183 } |
188 return nullptr; | 184 return nullptr; |
189 } | 185 } |
190 | 186 |
191 sk_sp<SkColorSpace> SkColorSpace::makeLinearGamma() { | 187 sk_sp<SkColorSpace> SkColorSpace::makeLinearGamma() { |
192 if (this->gammaIsLinear()) { | 188 if (this->gammaIsLinear()) { |
193 return sk_ref_sp(this); | 189 return sk_ref_sp(this); |
194 } | 190 } |
195 return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, fToXYZD50); | 191 return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, as_CSB(this)->fToXYZD
50); |
196 } | 192 } |
197 | 193 |
198 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 194 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
199 | 195 |
200 bool SkColorSpace::gammaCloseToSRGB() const { | 196 bool SkColorSpace::gammaCloseToSRGB() const { |
201 return kSRGB_SkGammaNamed == as_CSB(this)->fGammaNamed || | 197 return kSRGB_SkGammaNamed == as_CSB(this)->fGammaNamed || |
202 k2Dot2Curve_SkGammaNamed == as_CSB(this)->fGammaNamed; | 198 k2Dot2Curve_SkGammaNamed == as_CSB(this)->fGammaNamed; |
203 } | 199 } |
204 | 200 |
205 bool SkColorSpace::gammaIsLinear() const { | 201 bool SkColorSpace::gammaIsLinear() const { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // If we have a named gamma, write the enum and the matrix. | 300 // If we have a named gamma, write the enum and the matrix. |
305 switch (as_CSB(this)->fGammaNamed) { | 301 switch (as_CSB(this)->fGammaNamed) { |
306 case kSRGB_SkGammaNamed: | 302 case kSRGB_SkGammaNamed: |
307 case k2Dot2Curve_SkGammaNamed: | 303 case k2Dot2Curve_SkGammaNamed: |
308 case kLinear_SkGammaNamed: { | 304 case kLinear_SkGammaNamed: { |
309 if (memory) { | 305 if (memory) { |
310 *((ColorSpaceHeader*) memory) = | 306 *((ColorSpaceHeader*) memory) = |
311 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)->
fGammaNamed, | 307 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)->
fGammaNamed, |
312 ColorSpaceHeader::kMatrix_Fla
g); | 308 ColorSpaceHeader::kMatrix_Fla
g); |
313 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
); | 309 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
); |
314 fToXYZD50.as3x4RowMajorf((float*) memory); | 310 as_CSB(this)->fToXYZD50.as3x4RowMajorf((float*) memory); |
315 } | 311 } |
316 return sizeof(ColorSpaceHeader) + 12 * sizeof(float); | 312 return sizeof(ColorSpaceHeader) + 12 * sizeof(float); |
317 } | 313 } |
318 default: | 314 default: |
319 // Otherwise, write the gamma values and the matrix. | 315 // Otherwise, write the gamma values and the matrix. |
320 if (memory) { | 316 if (memory) { |
321 *((ColorSpaceHeader*) memory) = | 317 *((ColorSpaceHeader*) memory) = |
322 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)->
fGammaNamed, | 318 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)->
fGammaNamed, |
323 ColorSpaceHeader::kFloatGamma
_Flag); | 319 ColorSpaceHeader::kFloatGamma
_Flag); |
324 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
); | 320 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
); |
325 | 321 |
326 const SkGammas* gammas = as_CSB(this)->gammas(); | 322 const SkGammas* gammas = as_CSB(this)->gammas(); |
327 SkASSERT(gammas); | 323 SkASSERT(gammas); |
328 SkASSERT(SkGammas::Type::kValue_Type == gammas->fRedType && | 324 SkASSERT(SkGammas::Type::kValue_Type == gammas->fRedType && |
329 SkGammas::Type::kValue_Type == gammas->fGreenType &
& | 325 SkGammas::Type::kValue_Type == gammas->fGreenType &
& |
330 SkGammas::Type::kValue_Type == gammas->fBlueType); | 326 SkGammas::Type::kValue_Type == gammas->fBlueType); |
331 *(((float*) memory) + 0) = gammas->fRedData.fValue; | 327 *(((float*) memory) + 0) = gammas->fRedData.fValue; |
332 *(((float*) memory) + 1) = gammas->fGreenData.fValue; | 328 *(((float*) memory) + 1) = gammas->fGreenData.fValue; |
333 *(((float*) memory) + 2) = gammas->fBlueData.fValue; | 329 *(((float*) memory) + 2) = gammas->fBlueData.fValue; |
334 memory = SkTAddOffset<void>(memory, 3 * sizeof(float)); | 330 memory = SkTAddOffset<void>(memory, 3 * sizeof(float)); |
335 | 331 |
336 fToXYZD50.as3x4RowMajorf((float*) memory); | 332 as_CSB(this)->fToXYZD50.as3x4RowMajorf((float*) memory); |
337 } | 333 } |
338 return sizeof(ColorSpaceHeader) + 15 * sizeof(float); | 334 return sizeof(ColorSpaceHeader) + 15 * sizeof(float); |
339 } | 335 } |
340 } | 336 } |
341 | 337 |
342 // Otherwise, serialize the ICC data. | 338 // Otherwise, serialize the ICC data. |
343 size_t profileSize = as_CSB(this)->fProfileData->size(); | 339 size_t profileSize = as_CSB(this)->fProfileData->size(); |
344 if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { | 340 if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { |
345 return 0; | 341 return 0; |
346 } | 342 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 return false; | 450 return false; |
455 } | 451 } |
456 | 452 |
457 // It's important to check fProfileData before named gammas. Some profiles
may have named | 453 // It's important to check fProfileData before named gammas. Some profiles
may have named |
458 // gammas, but also include other wacky features that cause us to save the d
ata. | 454 // gammas, but also include other wacky features that cause us to save the d
ata. |
459 switch (as_CSB(src)->fGammaNamed) { | 455 switch (as_CSB(src)->fGammaNamed) { |
460 case kSRGB_SkGammaNamed: | 456 case kSRGB_SkGammaNamed: |
461 case k2Dot2Curve_SkGammaNamed: | 457 case k2Dot2Curve_SkGammaNamed: |
462 case kLinear_SkGammaNamed: | 458 case kLinear_SkGammaNamed: |
463 return (as_CSB(src)->fGammaNamed == as_CSB(dst)->fGammaNamed) && | 459 return (as_CSB(src)->fGammaNamed == as_CSB(dst)->fGammaNamed) && |
464 (src->fToXYZD50 == dst->fToXYZD50); | 460 (as_CSB(src)->fToXYZD50 == as_CSB(dst)->fToXYZD50); |
465 default: | 461 default: |
466 if (as_CSB(src)->fGammaNamed != as_CSB(dst)->fGammaNamed) { | 462 if (as_CSB(src)->fGammaNamed != as_CSB(dst)->fGammaNamed) { |
467 return false; | 463 return false; |
468 } | 464 } |
469 | 465 |
470 // It is unlikely that we will reach this case. | 466 // It is unlikely that we will reach this case. |
471 sk_sp<SkData> srcData = src->serialize(); | 467 sk_sp<SkData> srcData = src->serialize(); |
472 sk_sp<SkData> dstData = dst->serialize(); | 468 sk_sp<SkData> dstData = dst->serialize(); |
473 return srcData->size() == dstData->size() && | 469 return srcData->size() == dstData->size() && |
474 0 == memcmp(srcData->data(), dstData->data(), srcData->size()
); | 470 0 == memcmp(srcData->data(), dstData->data(), srcData->size()
); |
475 } | 471 } |
476 } | 472 } |
OLD | NEW |