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

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

Issue 1928123002: Introduce SkGammas type to represent ICC gamma curves (Closed) Base URL: https://skia.googlesource.com/skia.git@delcolorspace
Patch Set: Fix Mac clang again Created 4 years, 7 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 | « src/core/SkColorSpace.h ('k') | tests/ColorSpaceTest.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 "SkAtomics.h" 8 #include "SkAtomics.h"
9 #include "SkColorSpace.h" 9 #include "SkColorSpace.h"
10 10
11 void SkFloat3::dump() const { 11 void SkFloat3::dump() const {
12 SkDebugf("[%7.4f %7.4f %7.4f]\n", fVec[0], fVec[1], fVec[2]); 12 SkDebugf("[%7.4f %7.4f %7.4f]\n", fVec[0], fVec[1], fVec[2]);
13 } 13 }
14 14
15 void SkFloat3x3::dump() const { 15 void SkFloat3x3::dump() const {
16 SkDebugf("[%7.4f %7.4f %7.4f] [%7.4f %7.4f %7.4f] [%7.4f %7.4f %7.4f]\n", 16 SkDebugf("[%7.4f %7.4f %7.4f] [%7.4f %7.4f %7.4f] [%7.4f %7.4f %7.4f]\n",
17 fMat[0], fMat[1], fMat[2], 17 fMat[0], fMat[1], fMat[2],
18 fMat[3], fMat[4], fMat[5], 18 fMat[3], fMat[4], fMat[5],
19 fMat[6], fMat[7], fMat[8]); 19 fMat[6], fMat[7], fMat[8]);
20 } 20 }
21 21
22 //////////////////////////////////////////////////////////////////////////////// ////////////////// 22 //////////////////////////////////////////////////////////////////////////////// //////////////////
23 23
24 static int32_t gUniqueColorSpaceID; 24 static int32_t gUniqueColorSpaceID;
25 25
26 SkColorSpace::SkColorSpace(const SkFloat3& gamma, const SkFloat3x3& toXYZD50, Na med named) 26 SkColorSpace::SkColorSpace(SkGammas gammas, const SkFloat3x3& toXYZD50, Named na med)
27 : fGamma(gamma) 27 : fGammas(std::move(gammas))
28 , fToXYZD50(toXYZD50) 28 , fToXYZD50(toXYZD50)
29 , fToXYZOffset({{ 0.0f, 0.0f, 0.0f }}) 29 , fToXYZOffset({{ 0.0f, 0.0f, 0.0f }})
30 , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID)) 30 , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID))
31 , fNamed(named) 31 , fNamed(named)
32 {} 32 {}
33 33
34 SkColorSpace::SkColorSpace(SkColorLookUpTable colorLUT, const SkFloat3& gamma, 34 SkColorSpace::SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas,
35 const SkFloat3x3& toXYZD50, const SkFloat3& toXYZOffs et) 35 const SkFloat3x3& toXYZD50, const SkFloat3& toXYZOffs et)
36 : fColorLUT(std::move(colorLUT)) 36 : fColorLUT(std::move(colorLUT))
37 , fGamma(gamma) 37 , fGammas(std::move(gammas))
38 , fToXYZD50(toXYZD50) 38 , fToXYZD50(toXYZD50)
39 , fToXYZOffset(toXYZOffset) 39 , fToXYZOffset(toXYZOffset)
40 , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID)) 40 , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID))
41 , fNamed(kUnknown_Named) 41 , fNamed(kUnknown_Named)
42 {} 42 {}
43 43
44 sk_sp<SkColorSpace> SkColorSpace::NewRGB(const SkFloat3x3& toXYZD50, const SkFlo at3& gamma) { 44 sk_sp<SkColorSpace> SkColorSpace::NewRGB(const SkFloat3x3& toXYZD50, SkGammas ga mmas) {
45 return sk_sp<SkColorSpace>(new SkColorSpace(gamma, toXYZD50, kUnknown_Named) ); 45 return sk_sp<SkColorSpace>(new SkColorSpace(std::move(gammas), toXYZD50, kUn known_Named));
46 } 46 }
47 47
48 const SkFloat3 gSRGB_gamma {{ 2.2f, 2.2f, 2.2f }};
49 const SkFloat3x3 gSRGB_toXYZD50 {{ 48 const SkFloat3x3 gSRGB_toXYZD50 {{
50 0.4358f, 0.2224f, 0.0139f, // * R 49 0.4358f, 0.2224f, 0.0139f, // * R
51 0.3853f, 0.7170f, 0.0971f, // * G 50 0.3853f, 0.7170f, 0.0971f, // * G
52 0.1430f, 0.0606f, 0.7139f, // * B 51 0.1430f, 0.0606f, 0.7139f, // * B
53 }}; 52 }};
54 53
55 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { 54 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
56 switch (named) { 55 switch (named) {
57 case kSRGB_Named: 56 case kSRGB_Named:
58 return sk_sp<SkColorSpace>(new SkColorSpace(gSRGB_gamma, gSRGB_toXYZ D50, kSRGB_Named)); 57 return sk_sp<SkColorSpace>(new SkColorSpace(SkGammas(2.2f, 2.2f, 2.2 f), gSRGB_toXYZD50,
58 kSRGB_Named));
59 default: 59 default:
60 break; 60 break;
61 } 61 }
62 return nullptr; 62 return nullptr;
63 } 63 }
64 64
65 //////////////////////////////////////////////////////////////////////////////// /////////////////// 65 //////////////////////////////////////////////////////////////////////////////// ///////////////////
66 66
67 #include "SkFixed.h" 67 #include "SkFixed.h"
68 #include "SkTemplates.h" 68 #include "SkTemplates.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 dst[0] = SkFixedToFloat(read_big_endian_int(src + 8)); 257 dst[0] = SkFixedToFloat(read_big_endian_int(src + 8));
258 dst[1] = SkFixedToFloat(read_big_endian_int(src + 12)); 258 dst[1] = SkFixedToFloat(read_big_endian_int(src + 12));
259 dst[2] = SkFixedToFloat(read_big_endian_int(src + 16)); 259 dst[2] = SkFixedToFloat(read_big_endian_int(src + 16));
260 SkColorSpacePrintf("XYZ %g %g %g\n", dst[0], dst[1], dst[2]); 260 SkColorSpacePrintf("XYZ %g %g %g\n", dst[0], dst[1], dst[2]);
261 return true; 261 return true;
262 } 262 }
263 263
264 static const uint32_t kTAG_CurveType = SkSetFourByteTag('c', 'u', 'r', 'v'); 264 static const uint32_t kTAG_CurveType = SkSetFourByteTag('c', 'u', 'r', 'v');
265 static const uint32_t kTAG_ParaCurveType = SkSetFourByteTag('p', 'a', 'r', 'a'); 265 static const uint32_t kTAG_ParaCurveType = SkSetFourByteTag('p', 'a', 'r', 'a');
266 266
267 // FIXME (msarett): 267 bool SkColorSpace::LoadGammas(SkGammaCurve* gammas, uint32_t numGammas, const ui nt8_t* src,
268 // We need to handle the possibility that the gamma curve does not correspond to 2.2f. 268 size_t len) {
269 static bool load_gammas(float* gammas, uint32_t numGammas, const uint8_t* src, s ize_t len) {
270 for (uint32_t i = 0; i < numGammas; i++) { 269 for (uint32_t i = 0; i < numGammas; i++) {
271 if (len < 12) { 270 if (len < 12) {
272 // FIXME (msarett): 271 // FIXME (msarett):
273 // We could potentially return false here after correctly parsing *s ome* of the 272 // We could potentially return false here after correctly parsing *s ome* of the
274 // gammas correctly. Should we somehow try to indicate a partial su ccess? 273 // gammas correctly. Should we somehow try to indicate a partial su ccess?
275 SkColorSpacePrintf("gamma tag is too small (%d bytes)", len); 274 SkColorSpacePrintf("gamma tag is too small (%d bytes)", len);
276 return false; 275 return false;
277 } 276 }
278 277
279 // We need to count the number of bytes in the tag, so we are able to mo ve to the 278 // We need to count the number of bytes in the tag, so we are able to mo ve to the
280 // next tag on the next loop iteration. 279 // next tag on the next loop iteration.
281 size_t tagBytes; 280 size_t tagBytes;
282 281
283 uint32_t type = read_big_endian_uint(src); 282 uint32_t type = read_big_endian_uint(src);
284 switch (type) { 283 switch (type) {
285 case kTAG_CurveType: { 284 case kTAG_CurveType: {
286 uint32_t count = read_big_endian_uint(src + 8); 285 uint32_t count = read_big_endian_uint(src + 8);
287 tagBytes = 12 + count * 2; 286 tagBytes = 12 + count * 2;
288 if (0 == count) { 287 if (0 == count) {
289 // Some tags require a gamma curve, but the author doesn't a ctually want 288 // Some tags require a gamma curve, but the author doesn't a ctually want
290 // to transform the data. In this case, it is common to see a curve with 289 // to transform the data. In this case, it is common to see a curve with
291 // a count of 0. 290 // a count of 0.
292 gammas[i] = 1.0f; 291 gammas[i].fValue = 1.0f;
293 break; 292 break;
294 } else if (len < 12 + 2 * count) { 293 } else if (len < 12 + 2 * count) {
295 SkColorSpacePrintf("gamma tag is too small (%d bytes)", len) ; 294 SkColorSpacePrintf("gamma tag is too small (%d bytes)", len) ;
296 return false; 295 return false;
297 } 296 }
298 297
299 const uint16_t* table = (const uint16_t*) (src + 12); 298 const uint16_t* table = (const uint16_t*) (src + 12);
300 if (1 == count) { 299 if (1 == count) {
301 // Table entry is the exponent (bias 256). 300 // The table entry is the gamma (with a bias of 256).
302 uint16_t value = read_big_endian_short((const uint8_t*) tabl e); 301 uint16_t value = read_big_endian_short((const uint8_t*) tabl e);
303 gammas[i] = value / 256.0f; 302 gammas[i].fValue = value / 256.0f;
304 SkColorSpacePrintf("gamma %d %g\n", value, *gamma); 303 SkColorSpacePrintf("gamma %d %g\n", value, *gamma);
305 break; 304 break;
306 } 305 }
307 306
308 // Print the interpolation table. For now, we ignore this and g uess 2.2f. 307 // Fill in the interpolation table.
308 // FIXME (msarett):
309 // We should recognize commonly occurring tables and just set ga mma to 2.2f.
310 gammas[i].fTableSize = count;
311 gammas[i].fTable = std::unique_ptr<float[]>(new float[count]);
309 for (uint32_t j = 0; j < count; j++) { 312 for (uint32_t j = 0; j < count; j++) {
310 SkColorSpacePrintf("curve[%d] %d\n", j, 313 gammas[i].fTable[j] =
311 read_big_endian_short((const uint8_t*) &table[j])); 314 (read_big_endian_short((const uint8_t*) &table[j])) / 65535.0f;
312 } 315 }
313
314 gammas[i] = 2.2f;
315 break; 316 break;
316 } 317 }
317 case kTAG_ParaCurveType: 318 case kTAG_ParaCurveType:
318 // Guess 2.2f. 319 // Guess 2.2f.
320 // FIXME (msarett): Handle parametric curves.
319 SkColorSpacePrintf("parametric curve\n"); 321 SkColorSpacePrintf("parametric curve\n");
320 gammas[i] = 2.2f; 322 gammas[i].fValue = 2.2f;
321 323
324 // Determine the size of the parametric curve tag.
322 switch(read_big_endian_short(src + 8)) { 325 switch(read_big_endian_short(src + 8)) {
323 case 0: 326 case 0:
324 tagBytes = 12 + 4; 327 tagBytes = 12 + 4;
325 break; 328 break;
326 case 1: 329 case 1:
327 tagBytes = 12 + 12; 330 tagBytes = 12 + 12;
328 break; 331 break;
329 case 2: 332 case 2:
330 tagBytes = 12 + 16; 333 tagBytes = 12 + 16;
331 break; 334 break;
(...skipping 19 matching lines...) Expand all
351 tagBytes = SkAlign4(tagBytes); 354 tagBytes = SkAlign4(tagBytes);
352 if (len < tagBytes) { 355 if (len < tagBytes) {
353 return false; 356 return false;
354 } 357 }
355 358
356 src += tagBytes; 359 src += tagBytes;
357 len -= tagBytes; 360 len -= tagBytes;
358 } 361 }
359 } 362 }
360 363
361 // If all of the gammas we encounter are 1.0f, indicate that we failed to lo ad gammas. 364 return true;
362 // There is no need to apply a gamma of 1.0f.
363 for (uint32_t i = 0; i < numGammas; i++) {
364 if (1.0f != gammas[i]) {
365 return true;
366 }
367 }
368
369 return false;
370 } 365 }
371 366
372 static const uint32_t kTAG_AtoBType = SkSetFourByteTag('m', 'A', 'B', ' '); 367 static const uint32_t kTAG_AtoBType = SkSetFourByteTag('m', 'A', 'B', ' ');
373 368
374 bool load_color_lut(SkColorLookUpTable* colorLUT, uint32_t inputChannels, uint32 _t outputChannels, 369 bool SkColorSpace::LoadColorLUT(SkColorLookUpTable* colorLUT, uint32_t inputChan nels,
375 const uint8_t* src, size_t len) { 370 uint32_t outputChannels, const uint8_t* src, siz e_t len) {
376 if (len < 20) { 371 if (len < 20) {
377 SkColorSpacePrintf("Color LUT tag is too small (%d bytes).", len); 372 SkColorSpacePrintf("Color LUT tag is too small (%d bytes).", len);
378 return false; 373 return false;
379 } 374 }
380 375
381 SkASSERT(inputChannels <= SkColorLookUpTable::kMaxChannels && 376 SkASSERT(inputChannels <= SkColorLookUpTable::kMaxChannels && 3 == outputCha nnels);
382 outputChannels <= SkColorLookUpTable::kMaxChannels);
383 colorLUT->fInputChannels = inputChannels; 377 colorLUT->fInputChannels = inputChannels;
384 colorLUT->fOutputChannels = outputChannels; 378 colorLUT->fOutputChannels = outputChannels;
385 uint32_t numEntries = 1; 379 uint32_t numEntries = 1;
386 for (uint32_t i = 0; i < inputChannels; i++) { 380 for (uint32_t i = 0; i < inputChannels; i++) {
387 colorLUT->fGridPoints[i] = src[i]; 381 colorLUT->fGridPoints[i] = src[i];
388 numEntries *= src[i]; 382 numEntries *= src[i];
389 } 383 }
390 numEntries *= outputChannels; 384 numEntries *= outputChannels;
391 385
392 // Space is provided for a maximum of the 16 input channels. Now we determi ne the precision 386 // Space is provided for a maximum of the 16 input channels. Now we determi ne the precision
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 toXYZ->fMat[7] = SkFixedToFloat(read_big_endian_int(src + 20)); 428 toXYZ->fMat[7] = SkFixedToFloat(read_big_endian_int(src + 20));
435 toXYZ->fMat[2] = SkFixedToFloat(read_big_endian_int(src + 24)); 429 toXYZ->fMat[2] = SkFixedToFloat(read_big_endian_int(src + 24));
436 toXYZ->fMat[5] = SkFixedToFloat(read_big_endian_int(src + 28)); 430 toXYZ->fMat[5] = SkFixedToFloat(read_big_endian_int(src + 28));
437 toXYZ->fMat[8] = SkFixedToFloat(read_big_endian_int(src + 32)); 431 toXYZ->fMat[8] = SkFixedToFloat(read_big_endian_int(src + 32));
438 toXYZOffset->fVec[0] = SkFixedToFloat(read_big_endian_int(src + 36)); 432 toXYZOffset->fVec[0] = SkFixedToFloat(read_big_endian_int(src + 36));
439 toXYZOffset->fVec[1] = SkFixedToFloat(read_big_endian_int(src + 40)); 433 toXYZOffset->fVec[1] = SkFixedToFloat(read_big_endian_int(src + 40));
440 toXYZOffset->fVec[2] = SkFixedToFloat(read_big_endian_int(src + 44)); 434 toXYZOffset->fVec[2] = SkFixedToFloat(read_big_endian_int(src + 44));
441 return true; 435 return true;
442 } 436 }
443 437
444 bool load_a2b0(SkColorLookUpTable* colorLUT, SkFloat3* gamma, SkFloat3x3* toXYZ, 438 bool SkColorSpace::LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkFl oat3x3* toXYZ,
445 SkFloat3* toXYZOffset, const uint8_t* src, size_t len) { 439 SkFloat3* toXYZOffset, const uint8_t* src, size_t le n) {
446 if (len < 32) { 440 if (len < 32) {
447 SkColorSpacePrintf("A to B tag is too small (%d bytes).", len); 441 SkColorSpacePrintf("A to B tag is too small (%d bytes).", len);
448 return false; 442 return false;
449 } 443 }
450 444
451 uint32_t type = read_big_endian_uint(src); 445 uint32_t type = read_big_endian_uint(src);
452 if (kTAG_AtoBType != type) { 446 if (kTAG_AtoBType != type) {
453 // FIXME (msarett): Need to support lut8Type and lut16Type. 447 // FIXME (msarett): Need to support lut8Type and lut16Type.
454 SkColorSpacePrintf("Unsupported A to B tag type.\n"); 448 SkColorSpacePrintf("Unsupported A to B tag type.\n");
455 return false; 449 return false;
456 } 450 }
457 451
458 // Read the number of channels. The four bytes that we skipped are reserved and 452 // Read the number of channels. The four bytes that we skipped are reserved and
459 // must be zero. 453 // must be zero.
460 uint8_t inputChannels = src[8]; 454 uint8_t inputChannels = src[8];
461 uint8_t outputChannels = src[9]; 455 uint8_t outputChannels = src[9];
462 if (0 == inputChannels || inputChannels > SkColorLookUpTable::kMaxChannels | | 456 if (0 == inputChannels || inputChannels > SkColorLookUpTable::kMaxChannels | |
463 0 < outputChannels || outputChannels > SkColorLookUpTable::kMaxChann els) { 457 3 != outputChannels) {
464 // The color LUT assumes that there are at most 16 input channels. For RGB 458 // The color LUT assumes that there are at most 16 input channels. For RGB
465 // profiles, output channels should be 3. 459 // profiles, output channels should be 3.
466 SkColorSpacePrintf("Too many input or output channels in A to B tag.\n") ; 460 SkColorSpacePrintf("Too many input or output channels in A to B tag.\n") ;
467 return false; 461 return false;
468 } 462 }
469 463
470 // Read the offsets of each element in the A to B tag. With the exception o f A curves and 464 // Read the offsets of each element in the A to B tag. With the exception o f A curves and
471 // B curves (which we do not yet support), we will handle these elements in the order in 465 // B curves (which we do not yet support), we will handle these elements in the order in
472 // which they should be applied (rather than the order in which they occur i n the tag). 466 // which they should be applied (rather than the order in which they occur i n the tag).
473 // If the offset is non-zero it indicates that the element is present. 467 // If the offset is non-zero it indicates that the element is present.
474 uint32_t offsetToACurves = read_big_endian_int(src + 28); 468 uint32_t offsetToACurves = read_big_endian_int(src + 28);
475 uint32_t offsetToBCurves = read_big_endian_int(src + 12); 469 uint32_t offsetToBCurves = read_big_endian_int(src + 12);
476 if ((0 != offsetToACurves) || (0 != offsetToBCurves)) { 470 if ((0 != offsetToACurves) || (0 != offsetToBCurves)) {
477 // FIXME (msarett): Handle A and B curves. 471 // FIXME (msarett): Handle A and B curves.
478 // Note that the A curve is technically required in order to have a colo r LUT. 472 // Note that the A curve is technically required in order to have a colo r LUT.
479 // However, all the A curves I have seen so far have are just placeholde rs that 473 // However, all the A curves I have seen so far have are just placeholde rs that
480 // don't actually transform the data. 474 // don't actually transform the data.
481 SkColorSpacePrintf("Ignoring A and/or B curve. Output may be wrong.\n") ; 475 SkColorSpacePrintf("Ignoring A and/or B curve. Output may be wrong.\n") ;
482 } 476 }
483 477
484 uint32_t offsetToColorLUT = read_big_endian_int(src + 24); 478 uint32_t offsetToColorLUT = read_big_endian_int(src + 24);
485 if (0 != offsetToColorLUT && offsetToColorLUT < len) { 479 if (0 != offsetToColorLUT && offsetToColorLUT < len) {
486 if (!load_color_lut(colorLUT, inputChannels, outputChannels, src + offse tToColorLUT, 480 if (!SkColorSpace::LoadColorLUT(colorLUT, inputChannels, outputChannels,
487 len - offsetToColorLUT)) { 481 src + offsetToColorLUT, len - offsetToCo lorLUT)) {
488 SkColorSpacePrintf("Failed to read color LUT from A to B tag.\n"); 482 SkColorSpacePrintf("Failed to read color LUT from A to B tag.\n");
489 } 483 }
490 } 484 }
491 485
492 uint32_t offsetToMCurves = read_big_endian_int(src + 20); 486 uint32_t offsetToMCurves = read_big_endian_int(src + 20);
493 if (0 != offsetToMCurves && offsetToMCurves < len) { 487 if (0 != offsetToMCurves && offsetToMCurves < len) {
494 if (!load_gammas(gamma->fVec, outputChannels, src + offsetToMCurves, len - offsetToMCurves)) 488 if (!SkColorSpace::LoadGammas(&gammas->fRed, outputChannels, src + offse tToMCurves,
495 { 489 len - offsetToMCurves)) {
496 SkColorSpacePrintf("Failed to read M curves from A to B tag.\n"); 490 SkColorSpacePrintf("Failed to read M curves from A to B tag.\n");
497 } 491 }
498 } 492 }
499 493
500 uint32_t offsetToMatrix = read_big_endian_int(src + 16); 494 uint32_t offsetToMatrix = read_big_endian_int(src + 16);
501 if (0 != offsetToMatrix && offsetToMatrix < len) { 495 if (0 != offsetToMatrix && offsetToMatrix < len) {
502 if (!load_matrix(toXYZ, toXYZOffset, src + offsetToMatrix, len - offsetT oMatrix)) { 496 if (!load_matrix(toXYZ, toXYZOffset, src + offsetToMatrix, len - offsetT oMatrix)) {
503 SkColorSpacePrintf("Failed to read matrix from A to B tag.\n"); 497 SkColorSpacePrintf("Failed to read matrix from A to B tag.\n");
504 } 498 }
505 } 499 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 SkFloat3x3 toXYZ; 554 SkFloat3x3 toXYZ;
561 if (!load_xyz(&toXYZ.fMat[0], r->addr((const uint8_t*) base), r- >fLength) || 555 if (!load_xyz(&toXYZ.fMat[0], r->addr((const uint8_t*) base), r- >fLength) ||
562 !load_xyz(&toXYZ.fMat[3], g->addr((const uint8_t*) base), g- >fLength) || 556 !load_xyz(&toXYZ.fMat[3], g->addr((const uint8_t*) base), g- >fLength) ||
563 !load_xyz(&toXYZ.fMat[6], b->addr((const uint8_t*) base), b- >fLength)) 557 !load_xyz(&toXYZ.fMat[6], b->addr((const uint8_t*) base), b- >fLength))
564 { 558 {
565 return_null("Need valid rgb tags for XYZ space"); 559 return_null("Need valid rgb tags for XYZ space");
566 } 560 }
567 561
568 // It is not uncommon to see missing or empty gamma tags. This indicates 562 // It is not uncommon to see missing or empty gamma tags. This indicates
569 // that we should use unit gamma. 563 // that we should use unit gamma.
570 SkFloat3 gamma {{ 1.0f, 1.0f, 1.0f }}; 564 SkGammas gammas;
571 r = ICCTag::Find(tags.get(), tagCount, kTAG_rTRC); 565 r = ICCTag::Find(tags.get(), tagCount, kTAG_rTRC);
572 g = ICCTag::Find(tags.get(), tagCount, kTAG_gTRC); 566 g = ICCTag::Find(tags.get(), tagCount, kTAG_gTRC);
573 b = ICCTag::Find(tags.get(), tagCount, kTAG_bTRC); 567 b = ICCTag::Find(tags.get(), tagCount, kTAG_bTRC);
574 if (!r || 568 if (!r || !SkColorSpace::LoadGammas(&gammas.fRed, 1,
575 !load_gammas(&gamma.fVec[0], 1, r->addr((const uint8_t*) bas e), r->fLength)) 569 r->addr((const uint8_t*) bas e), r->fLength)) {
576 {
577 SkColorSpacePrintf("Failed to read R gamma tag.\n"); 570 SkColorSpacePrintf("Failed to read R gamma tag.\n");
578 } 571 }
579 if (!g || 572 if (!g || !SkColorSpace::LoadGammas(&gammas.fGreen, 1,
580 !load_gammas(&gamma.fVec[1], 1, g->addr((const uint8_t*) bas e), g->fLength)) 573 g->addr((const uint8_t*) bas e), g->fLength)) {
581 {
582 SkColorSpacePrintf("Failed to read G gamma tag.\n"); 574 SkColorSpacePrintf("Failed to read G gamma tag.\n");
583 } 575 }
584 if (!b || 576 if (!b || !SkColorSpace::LoadGammas(&gammas.fBlue, 1,
585 !load_gammas(&gamma.fVec[2], 1, b->addr((const uint8_t*) bas e), b->fLength)) 577 b->addr((const uint8_t*) bas e), b->fLength)) {
586 {
587 SkColorSpacePrintf("Failed to read B gamma tag.\n"); 578 SkColorSpacePrintf("Failed to read B gamma tag.\n");
588 } 579 }
589 return SkColorSpace::NewRGB(toXYZ, gamma); 580 return SkColorSpace::NewRGB(toXYZ, std::move(gammas));
590 } 581 }
591 582
592 // Recognize color profile specified by A2B0 tag. 583 // Recognize color profile specified by A2B0 tag.
593 const ICCTag* a2b0 = ICCTag::Find(tags.get(), tagCount, kTAG_A2B0); 584 const ICCTag* a2b0 = ICCTag::Find(tags.get(), tagCount, kTAG_A2B0);
594 if (a2b0) { 585 if (a2b0) {
595 SkColorLookUpTable colorLUT; 586 SkColorLookUpTable colorLUT;
596 SkFloat3 gamma; 587 SkGammas gammas;
597 SkFloat3x3 toXYZ; 588 SkFloat3x3 toXYZ;
598 SkFloat3 toXYZOffset; 589 SkFloat3 toXYZOffset;
599 if (!load_a2b0(&colorLUT, &gamma, &toXYZ, &toXYZOffset, 590 if (!SkColorSpace::LoadA2B0(&colorLUT, &gammas, &toXYZ, &toXYZOf fset,
600 a2b0->addr((const uint8_t*) base), a2b0->fLength)) { 591 a2b0->addr((const uint8_t*) base), a 2b0->fLength)) {
601 return_null("Failed to parse A2B0 tag"); 592 return_null("Failed to parse A2B0 tag");
602 } 593 }
603 594
604 return sk_sp<SkColorSpace>(new SkColorSpace(std::move(colorLUT), gamma, toXYZ, 595 return sk_sp<SkColorSpace>(new SkColorSpace(std::move(colorLUT), std::move(gammas),
605 toXYZOffset)); 596 toXYZ, toXYZOffset)) ;
606 } 597 }
607 598
608 } 599 }
609 default: 600 default:
610 break; 601 break;
611 } 602 }
612 603
613 return_null("ICC profile contains unsupported colorspace"); 604 return_null("ICC profile contains unsupported colorspace");
614 } 605 }
OLDNEW
« no previous file with comments | « src/core/SkColorSpace.h ('k') | tests/ColorSpaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698