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

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

Issue 2323003002: Cache the inverse matrix on SkColorSpace. Rename xyz() to toXYZ(). (Closed)
Patch Set: Remove xyz() again 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.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 #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) 13 SkColorSpace::SkColorSpace(const SkMatrix44& toXYZD50)
14 : fToXYZD50(toXYZD50) 14 : fToXYZD50(toXYZD50)
15 {} 15 {}
16 16
17 SkColorSpace_Base::SkColorSpace_Base(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50) 17 SkColorSpace_Base::SkColorSpace_Base(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50)
18 : INHERITED(toXYZD50) 18 : INHERITED(toXYZD50)
19 , fGammaNamed(gammaNamed) 19 , fGammaNamed(gammaNamed)
20 , fGammas(nullptr) 20 , fGammas(nullptr)
21 , fProfileData(nullptr) 21 , fProfileData(nullptr)
22 , fFromXYZD50(SkMatrix44::kUninitialized_Constructor)
22 {} 23 {}
23 24
24 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, SkGamma Named gammaNamed, 25 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, SkGamma Named gammaNamed,
25 sk_sp<SkGammas> gammas, const SkMatrix44& t oXYZD50, 26 sk_sp<SkGammas> gammas, const SkMatrix44& t oXYZD50,
26 sk_sp<SkData> profileData) 27 sk_sp<SkData> profileData)
27 : INHERITED(toXYZD50) 28 : INHERITED(toXYZD50)
28 , fColorLUT(std::move(colorLUT)) 29 , fColorLUT(std::move(colorLUT))
29 , fGammaNamed(gammaNamed) 30 , fGammaNamed(gammaNamed)
30 , fGammas(std::move(gammas)) 31 , fGammas(std::move(gammas))
31 , fProfileData(std::move(profileData)) 32 , fProfileData(std::move(profileData))
33 , fFromXYZD50(SkMatrix44::kUninitialized_Constructor)
32 {} 34 {}
33 35
34 static constexpr float gSRGB_toXYZD50[] { 36 static constexpr float gSRGB_toXYZD50[] {
35 0.4358f, 0.2224f, 0.0139f, // * R 37 0.4358f, 0.2224f, 0.0139f, // * R
36 0.3853f, 0.7170f, 0.0971f, // * G 38 0.3853f, 0.7170f, 0.0971f, // * G
37 0.1430f, 0.0606f, 0.7139f, // * B 39 0.1430f, 0.0606f, 0.7139f, // * B
38 }; 40 };
39 41
40 static constexpr float gAdobeRGB_toXYZD50[] { 42 static constexpr float gAdobeRGB_toXYZD50[] {
41 0.6098f, 0.3111f, 0.0195f, // * R 43 0.6098f, 0.3111f, 0.0195f, // * R
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 177
176 bool SkColorSpace::gammaCloseToSRGB() const { 178 bool SkColorSpace::gammaCloseToSRGB() const {
177 return kSRGB_SkGammaNamed == as_CSB(this)->fGammaNamed || 179 return kSRGB_SkGammaNamed == as_CSB(this)->fGammaNamed ||
178 k2Dot2Curve_SkGammaNamed == as_CSB(this)->fGammaNamed; 180 k2Dot2Curve_SkGammaNamed == as_CSB(this)->fGammaNamed;
179 } 181 }
180 182
181 bool SkColorSpace::gammaIsLinear() const { 183 bool SkColorSpace::gammaIsLinear() const {
182 return kLinear_SkGammaNamed == as_CSB(this)->fGammaNamed; 184 return kLinear_SkGammaNamed == as_CSB(this)->fGammaNamed;
183 } 185 }
184 186
187 const SkMatrix44& SkColorSpace_Base::fromXYZD50() const {
188 fFromXYZOnce([this] {
189 if (!fToXYZD50.invert(&fFromXYZD50)) {
190 // If a client gives us a dst gamut with a transform that we can't i nvert, we will
191 // simply give them back a transform to sRGB gamut.
192 SkDEBUGFAIL("Non-invertible XYZ matrix, defaulting to sRGB");
193 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
194 srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50);
195 srgbToxyzD50.invert(&fFromXYZD50);
196 }
197 });
198 return fFromXYZD50;
199 }
200
185 //////////////////////////////////////////////////////////////////////////////// /////////////////// 201 //////////////////////////////////////////////////////////////////////////////// ///////////////////
186 202
187 enum Version { 203 enum Version {
188 k0_Version, // Initial version, header + flags for matrix and profile 204 k0_Version, // Initial version, header + flags for matrix and profile
189 }; 205 };
190 206
191 struct ColorSpaceHeader { 207 struct ColorSpaceHeader {
192 /** 208 /**
193 * If kMatrix_Flag is set, we will write 12 floats after the header. 209 * If kMatrix_Flag is set, we will write 12 floats after the header.
194 * Should not be set at the same time as the kICC_Flag or kFloatGamma_Flag. 210 * Should not be set at the same time as the kICC_Flag or kFloatGamma_Flag.
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 return false; 437 return false;
422 } 438 }
423 439
424 // It is unlikely that we will reach this case. 440 // It is unlikely that we will reach this case.
425 sk_sp<SkData> srcData = src->serialize(); 441 sk_sp<SkData> srcData = src->serialize();
426 sk_sp<SkData> dstData = dst->serialize(); 442 sk_sp<SkData> dstData = dst->serialize();
427 return srcData->size() == dstData->size() && 443 return srcData->size() == dstData->size() &&
428 0 == memcmp(srcData->data(), dstData->data(), srcData->size() ); 444 0 == memcmp(srcData->data(), dstData->data(), srcData->size() );
429 } 445 }
430 } 446 }
OLDNEW
« no previous file with comments | « include/core/SkColorSpace.h ('k') | src/core/SkColorSpaceXform.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698