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

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

Issue 2304753002: Add SkColorSpacePrimaries to help with making D50 matrices (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Simplify even more 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
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 switch (gamma) { 125 switch (gamma) {
126 case kLinear_RenderTargetGamma: 126 case kLinear_RenderTargetGamma:
127 return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, toXYZD50); 127 return SkColorSpace_Base::NewRGB(kLinear_SkGammaNamed, toXYZD50);
128 case kSRGB_RenderTargetGamma: 128 case kSRGB_RenderTargetGamma:
129 return SkColorSpace_Base::NewRGB(kSRGB_SkGammaNamed, toXYZD50); 129 return SkColorSpace_Base::NewRGB(kSRGB_SkGammaNamed, toXYZD50);
130 default: 130 default:
131 return nullptr; 131 return nullptr;
132 } 132 }
133 } 133 }
134 134
135 sk_sp<SkColorSpace> SkColorSpace::NewRGB(const SkTransferFn& coeffs, const SkMat rix44& toXYZD50) {
136 // TODO: Check if coeffs match sRGB, 2.2, or linear.
137 // TODO: Make sure coefficients describe a valid curve. Return nullptr if t hey don't.
138 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkTransferFn));
139 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas());
140 void* storage = SkTAddOffset<void>(memory, sizeof(SkGammas));
141 memcpy(storage, &coeffs, sizeof(SkTransferFn));
142 gammas->fRedType = SkGammas::Type::kParam_Type;
143 gammas->fGreenType = SkGammas::Type::kParam_Type;
144 gammas->fBlueType = SkGammas::Type::kParam_Type;
145
146 SkGammas::Data data;
147 data.fParamOffset = 0;
148 gammas->fRedData = data;
149 gammas->fGreenData = data;
150 gammas->fBlueData = data;
151 return sk_sp<SkColorSpace>(new SkColorSpace_Base(nullptr, kNonStandard_SkGa mmaNamed,
152 std::move(gammas), toXYZD5 0, nullptr));
153 }
154
135 static SkColorSpace* gAdobeRGB; 155 static SkColorSpace* gAdobeRGB;
136 static SkColorSpace* gSRGB; 156 static SkColorSpace* gSRGB;
137 157
138 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { 158 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
139 static SkOnce sRGBOnce; 159 static SkOnce sRGBOnce;
140 static SkOnce adobeRGBOnce; 160 static SkOnce adobeRGBOnce;
141 161
142 switch (named) { 162 switch (named) {
143 case kSRGB_Named: { 163 case kSRGB_Named: {
144 sRGBOnce([] { 164 sRGBOnce([] {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (memory) { 283 if (memory) {
264 *((ColorSpaceHeader*) memory) = 284 *((ColorSpaceHeader*) memory) =
265 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)-> fGammaNamed, 285 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)-> fGammaNamed,
266 ColorSpaceHeader::kMatrix_Fla g); 286 ColorSpaceHeader::kMatrix_Fla g);
267 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader) ); 287 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader) );
268 fToXYZD50.as4x3ColMajorf((float*) memory); 288 fToXYZD50.as4x3ColMajorf((float*) memory);
269 } 289 }
270 return sizeof(ColorSpaceHeader) + 12 * sizeof(float); 290 return sizeof(ColorSpaceHeader) + 12 * sizeof(float);
271 } 291 }
272 default: 292 default:
293 // TODO: Fix this to serialize properly.
294
273 // Otherwise, write the gamma values and the matrix. 295 // Otherwise, write the gamma values and the matrix.
274 if (memory) { 296 if (memory) {
275 *((ColorSpaceHeader*) memory) = 297 *((ColorSpaceHeader*) memory) =
276 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)-> fGammaNamed, 298 ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)-> fGammaNamed,
277 ColorSpaceHeader::kFloatGamma _Flag); 299 ColorSpaceHeader::kFloatGamma _Flag);
278 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader) ); 300 memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader) );
279 301
280 const SkGammas* gammas = as_CSB(this)->gammas(); 302 const SkGammas* gammas = as_CSB(this)->gammas();
281 SkASSERT(gammas); 303 SkASSERT(gammas);
282 SkASSERT(SkGammas::Type::kValue_Type == gammas->fRedType && 304 SkASSERT(SkGammas::Type::kValue_Type == gammas->fRedType &&
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 uint32_t profileSize = *((uint32_t*) data); 384 uint32_t profileSize = *((uint32_t*) data);
363 data = SkTAddOffset<const void>(data, sizeof(uint32_t)); 385 data = SkTAddOffset<const void>(data, sizeof(uint32_t));
364 length -= sizeof(uint32_t); 386 length -= sizeof(uint32_t);
365 if (length < profileSize) { 387 if (length < profileSize) {
366 return nullptr; 388 return nullptr;
367 } 389 }
368 390
369 return NewICC(data, profileSize); 391 return NewICC(data, profileSize);
370 } 392 }
371 case ColorSpaceHeader::kFloatGamma_Flag: { 393 case ColorSpaceHeader::kFloatGamma_Flag: {
394 // TODO: Fix this to deserialize properly.
395
372 if (length < 15 * sizeof(float)) { 396 if (length < 15 * sizeof(float)) {
373 return nullptr; 397 return nullptr;
374 } 398 }
375 399
376 float gammas[3]; 400 float gammas[3];
377 gammas[0] = *(((const float*) data) + 0); 401 gammas[0] = *(((const float*) data) + 0);
378 gammas[1] = *(((const float*) data) + 1); 402 gammas[1] = *(((const float*) data) + 1);
379 gammas[2] = *(((const float*) data) + 2); 403 gammas[2] = *(((const float*) data) + 2);
380 data = SkTAddOffset<const void>(data, 3 * sizeof(float)); 404 data = SkTAddOffset<const void>(data, 3 * sizeof(float));
381 405
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 return false; 445 return false;
422 } 446 }
423 447
424 // It is unlikely that we will reach this case. 448 // It is unlikely that we will reach this case.
425 sk_sp<SkData> srcData = src->serialize(); 449 sk_sp<SkData> srcData = src->serialize();
426 sk_sp<SkData> dstData = dst->serialize(); 450 sk_sp<SkData> dstData = dst->serialize();
427 return srcData->size() == dstData->size() && 451 return srcData->size() == dstData->size() &&
428 0 == memcmp(srcData->data(), dstData->data(), srcData->size() ); 452 0 == memcmp(srcData->data(), dstData->data(), srcData->size() );
429 } 453 }
430 } 454 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698