OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkColorSpace_XYZ.h" |
| 9 #include "SkColorSpaceXform_Base.h" |
| 10 |
| 11 static constexpr float gSRGB_toXYZD50[] { |
| 12 0.4358f, 0.3853f, 0.1430f, // Rx, Gx, Bx |
| 13 0.2224f, 0.7170f, 0.0606f, // Ry, Gy, Gz |
| 14 0.0139f, 0.0971f, 0.7139f, // Rz, Gz, Bz |
| 15 }; |
| 16 |
| 17 SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, const SkMatrix44& to
XYZD50) |
| 18 : INHERITED(nullptr) |
| 19 , fGammaNamed(gammaNamed) |
| 20 , fGammas(nullptr) |
| 21 , fToXYZD50(toXYZD50) |
| 22 , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) |
| 23 {} |
| 24 |
| 25 SkColorSpace_XYZ::SkColorSpace_XYZ(SkGammaNamed gammaNamed, sk_sp<SkGammas> gamm
as, |
| 26 const SkMatrix44& toXYZD50, sk_sp<SkData> pro
fileData) |
| 27 : INHERITED(std::move(profileData)) |
| 28 , fGammaNamed(gammaNamed) |
| 29 , fGammas(std::move(gammas)) |
| 30 , fToXYZD50(toXYZD50) |
| 31 , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) |
| 32 {} |
| 33 |
| 34 const SkMatrix44* SkColorSpace_XYZ::fromXYZD50() const { |
| 35 fFromXYZOnce([this] { |
| 36 if (!fToXYZD50.invert(&fFromXYZD50)) { |
| 37 // If a client gives us a dst gamut with a transform that we can't i
nvert, we will |
| 38 // simply give them back a transform to sRGB gamut. |
| 39 SkDEBUGFAIL("Non-invertible XYZ matrix, defaulting to sRGB"); |
| 40 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); |
| 41 srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50); |
| 42 srgbToxyzD50.invert(&fFromXYZD50); |
| 43 } |
| 44 }); |
| 45 return &fFromXYZD50; |
| 46 } |
| 47 |
| 48 bool SkColorSpace_XYZ::onGammaCloseToSRGB() const { |
| 49 return kSRGB_SkGammaNamed == fGammaNamed || k2Dot2Curve_SkGammaNamed == fGam
maNamed; |
| 50 } |
| 51 |
| 52 bool SkColorSpace_XYZ::onGammaIsLinear() const { |
| 53 return kLinear_SkGammaNamed == fGammaNamed; |
| 54 } |
| 55 |
| 56 sk_sp<SkColorSpace> SkColorSpace_XYZ::makeLinearGamma() { |
| 57 if (this->gammaIsLinear()) { |
| 58 return sk_ref_sp(this); |
| 59 } |
| 60 return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, fToXYZD50); |
| 61 } |
| 62 |
| 63 void SkColorSpace_XYZ::toDstGammaTables(const uint8_t* tables[3], sk_sp<SkData>*
storage, |
| 64 int numTables) const { |
| 65 fToDstGammaOnce([this, numTables] { |
| 66 const bool gammasAreMatching = numTables <= 1; |
| 67 fDstStorage = |
| 68 SkData::MakeUninitialized(numTables * SkColorSpaceXform_Base::kD
stGammaTableSize); |
| 69 SkColorSpaceXform_Base::BuildDstGammaTables(fToDstGammaTables, |
| 70 (uint8_t*) fDstStorage->writ
able_data(), this, |
| 71 gammasAreMatching); |
| 72 }); |
| 73 |
| 74 *storage = fDstStorage; |
| 75 tables[0] = fToDstGammaTables[0]; |
| 76 tables[1] = fToDstGammaTables[1]; |
| 77 tables[2] = fToDstGammaTables[2]; |
| 78 } |
OLD | NEW |