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

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

Issue 2377763002: Added kSRGBLinear_Named color space, along with tests (Closed)
Patch Set: Update some call sites Created 4 years, 2 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
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"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 case kSRGB_SkGammaNamed: 106 case kSRGB_SkGammaNamed:
107 if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) { 107 if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) {
108 return SkColorSpace::NewNamed(kSRGB_Named); 108 return SkColorSpace::NewNamed(kSRGB_Named);
109 } 109 }
110 break; 110 break;
111 case k2Dot2Curve_SkGammaNamed: 111 case k2Dot2Curve_SkGammaNamed:
112 if (xyz_almost_equal(toXYZD50, gAdobeRGB_toXYZD50)) { 112 if (xyz_almost_equal(toXYZD50, gAdobeRGB_toXYZD50)) {
113 return SkColorSpace::NewNamed(kAdobeRGB_Named); 113 return SkColorSpace::NewNamed(kAdobeRGB_Named);
114 } 114 }
115 break; 115 break;
116 case kLinear_SkGammaNamed:
117 if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) {
118 return SkColorSpace::NewNamed(kSRGBLinear_Named);
119 }
120 break;
116 case kNonStandard_SkGammaNamed: 121 case kNonStandard_SkGammaNamed:
117 // This is not allowed. 122 // This is not allowed.
118 return nullptr; 123 return nullptr;
119 default: 124 default:
120 break; 125 break;
121 } 126 }
122 127
123 return sk_sp<SkColorSpace>(new SkColorSpace_Base(gammaNamed, toXYZD50)); 128 return sk_sp<SkColorSpace>(new SkColorSpace_Base(gammaNamed, toXYZD50));
124 } 129 }
125 130
126 sk_sp<SkColorSpace> SkColorSpace::NewRGB(RenderTargetGamma gamma, const SkMatrix 44& toXYZD50) { 131 sk_sp<SkColorSpace> SkColorSpace::NewRGB(RenderTargetGamma gamma, const SkMatrix 44& toXYZD50) {
127 switch (gamma) { 132 switch (gamma) {
128 case kLinear_RenderTargetGamma: 133 case kLinear_RenderTargetGamma:
129 return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, toXYZD50); 134 return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, toXYZD50);
130 case kSRGB_RenderTargetGamma: 135 case kSRGB_RenderTargetGamma:
131 return SkColorSpace_Base::NewRGB(kSRGB_SkGammaNamed, toXYZD50); 136 return SkColorSpace_Base::NewRGB(kSRGB_SkGammaNamed, toXYZD50);
132 default: 137 default:
133 return nullptr; 138 return nullptr;
134 } 139 }
135 } 140 }
136 141
137 static SkColorSpace* gAdobeRGB; 142 static SkColorSpace* gAdobeRGB;
138 static SkColorSpace* gSRGB; 143 static SkColorSpace* gSRGB;
144 static SkColorSpace* gSRGBLinear;
139 145
140 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { 146 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
141 static SkOnce sRGBOnce; 147 static SkOnce sRGBOnce;
142 static SkOnce adobeRGBOnce; 148 static SkOnce adobeRGBOnce;
149 static SkOnce sRGBLinearOnce;
143 150
144 switch (named) { 151 switch (named) {
145 case kSRGB_Named: { 152 case kSRGB_Named: {
146 sRGBOnce([] { 153 sRGBOnce([] {
147 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); 154 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
148 srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50); 155 srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50);
149 156
150 // Force the mutable type mask to be computed. This avoids race s. 157 // Force the mutable type mask to be computed. This avoids race s.
151 (void)srgbToxyzD50.getType(); 158 (void)srgbToxyzD50.getType();
152 gSRGB = new SkColorSpace_Base(kSRGB_SkGammaNamed, srgbToxyzD50); 159 gSRGB = new SkColorSpace_Base(kSRGB_SkGammaNamed, srgbToxyzD50);
153 }); 160 });
154 return sk_ref_sp<SkColorSpace>(gSRGB); 161 return sk_ref_sp<SkColorSpace>(gSRGB);
155 } 162 }
156 case kAdobeRGB_Named: { 163 case kAdobeRGB_Named: {
157 adobeRGBOnce([] { 164 adobeRGBOnce([] {
158 SkMatrix44 adobergbToxyzD50(SkMatrix44::kUninitialized_Construct or); 165 SkMatrix44 adobergbToxyzD50(SkMatrix44::kUninitialized_Construct or);
159 adobergbToxyzD50.set3x3RowMajorf(gAdobeRGB_toXYZD50); 166 adobergbToxyzD50.set3x3RowMajorf(gAdobeRGB_toXYZD50);
160 167
161 // Force the mutable type mask to be computed. This avoids race s. 168 // Force the mutable type mask to be computed. This avoids race s.
162 (void)adobergbToxyzD50.getType(); 169 (void)adobergbToxyzD50.getType();
163 gAdobeRGB = new SkColorSpace_Base(k2Dot2Curve_SkGammaNamed, adob ergbToxyzD50); 170 gAdobeRGB = new SkColorSpace_Base(k2Dot2Curve_SkGammaNamed, adob ergbToxyzD50);
164 }); 171 });
165 return sk_ref_sp<SkColorSpace>(gAdobeRGB); 172 return sk_ref_sp<SkColorSpace>(gAdobeRGB);
166 } 173 }
174 case kSRGBLinear_Named: {
175 sRGBLinearOnce([] {
176 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
177 srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50);
178
179 // Force the mutable type mask to be computed. This avoids race s.
180 (void)srgbToxyzD50.getType();
181 gSRGBLinear = new SkColorSpace_Base(kLinear_SkGammaNamed, srgbTo xyzD50);
182 });
183 return sk_ref_sp<SkColorSpace>(gSRGBLinear);
184 }
167 default: 185 default:
168 break; 186 break;
169 } 187 }
170 return nullptr; 188 return nullptr;
171 } 189 }
172 190
173 sk_sp<SkColorSpace> SkColorSpace::makeLinearGamma() { 191 sk_sp<SkColorSpace> SkColorSpace::makeLinearGamma() {
174 if (this->gammaIsLinear()) { 192 if (this->gammaIsLinear()) {
175 return sk_ref_sp(this); 193 return sk_ref_sp(this);
176 } 194 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 ColorSpaceHeader::Pack(k0_Version, kSRGB_Named, 284 ColorSpaceHeader::Pack(k0_Version, kSRGB_Named,
267 as_CSB(this)->fGammaNamed, 0); 285 as_CSB(this)->fGammaNamed, 0);
268 } 286 }
269 return sizeof(ColorSpaceHeader); 287 return sizeof(ColorSpaceHeader);
270 } else if (this == gAdobeRGB) { 288 } else if (this == gAdobeRGB) {
271 if (memory) { 289 if (memory) {
272 *((ColorSpaceHeader*) memory) = 290 *((ColorSpaceHeader*) memory) =
273 ColorSpaceHeader::Pack(k0_Version, kAdobeRGB_Named, 291 ColorSpaceHeader::Pack(k0_Version, kAdobeRGB_Named,
274 as_CSB(this)->fGammaNamed, 0); 292 as_CSB(this)->fGammaNamed, 0);
275 } 293 }
294 return sizeof(ColorSpaceHeader);
Brian Osman 2016/09/27 20:49:49 Unrelated bug fix. (Discovered this while making t
msarett 2016/09/27 20:53:52 +1
295 } else if (this == gSRGBLinear) {
296 if (memory) {
297 *((ColorSpaceHeader*)memory) =
298 ColorSpaceHeader::Pack(k0_Version, kSRGBLinear_Named,
299 as_CSB(this)->fGammaNamed, 0);
300 }
301 return sizeof(ColorSpaceHeader);
276 } 302 }
277 303
278 // If we have a named gamma, write the enum and the matrix. 304 // If we have a named gamma, write the enum and the matrix.
279 switch (as_CSB(this)->fGammaNamed) { 305 switch (as_CSB(this)->fGammaNamed) {
280 case kSRGB_SkGammaNamed: 306 case kSRGB_SkGammaNamed:
281 case k2Dot2Curve_SkGammaNamed: 307 case k2Dot2Curve_SkGammaNamed:
282 case kLinear_SkGammaNamed: { 308 case kLinear_SkGammaNamed: {
283 if (memory) { 309 if (memory) {
284 *((ColorSpaceHeader*) memory) = 310 *((ColorSpaceHeader*) memory) =
285 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)-> fGammaNamed, 311 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)-> fGammaNamed,
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 return false; 467 return false;
442 } 468 }
443 469
444 // It is unlikely that we will reach this case. 470 // It is unlikely that we will reach this case.
445 sk_sp<SkData> srcData = src->serialize(); 471 sk_sp<SkData> srcData = src->serialize();
446 sk_sp<SkData> dstData = dst->serialize(); 472 sk_sp<SkData> dstData = dst->serialize();
447 return srcData->size() == dstData->size() && 473 return srcData->size() == dstData->size() &&
448 0 == memcmp(srcData->data(), dstData->data(), srcData->size() ); 474 0 == memcmp(srcData->data(), dstData->data(), srcData->size() );
449 } 475 }
450 } 476 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698