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

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

Issue 2041753004: Name parametric gamma curve types (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | no next file » | 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 "SkEndian.h" 10 #include "SkEndian.h"
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 // Otherwise, fill in the interpolation table. 477 // Otherwise, fill in the interpolation table.
478 gammas[i].fTableSize = count; 478 gammas[i].fTableSize = count;
479 gammas[i].fTable = std::unique_ptr<float[]>(new float[count]); 479 gammas[i].fTable = std::unique_ptr<float[]>(new float[count]);
480 for (uint32_t j = 0; j < count; j++) { 480 for (uint32_t j = 0; j < count; j++) {
481 gammas[i].fTable[j] = 481 gammas[i].fTable[j] =
482 (read_big_endian_short((const uint8_t*) &table[j])) / 65535.0f; 482 (read_big_endian_short((const uint8_t*) &table[j])) / 65535.0f;
483 } 483 }
484 break; 484 break;
485 } 485 }
486 case kTAG_ParaCurveType: { 486 case kTAG_ParaCurveType: {
487 enum ParaCurveType {
488 kExponential_ParaCurveType = 0,
489 kGAB_ParaCurveType = 1,
490 kGABC_ParaCurveType = 2,
491 kGABDE_ParaCurveType = 3,
492 kGABCDEF_ParaCurveType = 4,
493 };
494
487 // Determine the format of the parametric curve tag. 495 // Determine the format of the parametric curve tag.
488 uint16_t format = read_big_endian_short(src + 8); 496 uint16_t format = read_big_endian_short(src + 8);
489 if (0 == format) { 497 if (kExponential_ParaCurveType == format) {
490 tagBytes = 12 + 4; 498 tagBytes = 12 + 4;
491 if (len < tagBytes) { 499 if (len < tagBytes) {
492 SkColorSpacePrintf("gamma tag is too small (%d bytes)", len); 500 SkColorSpacePrintf("gamma tag is too small (%d bytes)", len);
493 return false; 501 return false;
494 } 502 }
495 503
496 // Y = X^g 504 // Y = X^g
497 int32_t g = read_big_endian_int(src + 12); 505 int32_t g = read_big_endian_int(src + 12);
498 gammas[i].fValue = SkFixedToFloat(g); 506 gammas[i].fValue = SkFixedToFloat(g);
499 } else { 507 } else {
500 // Here's where the real parametric gammas start. There are many 508 // Here's where the real parametric gammas start. There are many
501 // permutations of the same equations. 509 // permutations of the same equations.
502 // 510 //
503 // Y = (aX + b)^g + c for X >= d 511 // Y = (aX + b)^g + c for X >= d
504 // Y = eX + f otherwise 512 // Y = eX + f otherwise
505 // 513 //
506 // We will fill in with zeros as necessary to always match t he above form. 514 // We will fill in with zeros as necessary to always match t he above form.
507 float g = 0.0f, a = 0.0f, b = 0.0f, c = 0.0f, d = 0.0f, e = 0.0f, f = 0.0f; 515 float g = 0.0f, a = 0.0f, b = 0.0f, c = 0.0f, d = 0.0f, e = 0.0f, f = 0.0f;
508 switch(format) { 516 switch(format) {
509 case 1: { 517 case kGAB_ParaCurveType: {
510 tagBytes = 12 + 12; 518 tagBytes = 12 + 12;
511 if (len < tagBytes) { 519 if (len < tagBytes) {
512 SkColorSpacePrintf("gamma tag is too small (%d b ytes)", len); 520 SkColorSpacePrintf("gamma tag is too small (%d b ytes)", len);
513 return false; 521 return false;
514 } 522 }
515 523
516 // Y = (aX + b)^g for X >= -b/a 524 // Y = (aX + b)^g for X >= -b/a
517 // Y = 0 otherwise 525 // Y = 0 otherwise
518 g = SkFixedToFloat(read_big_endian_int(src + 12)); 526 g = SkFixedToFloat(read_big_endian_int(src + 12));
519 a = SkFixedToFloat(read_big_endian_int(src + 16)); 527 a = SkFixedToFloat(read_big_endian_int(src + 16));
520 b = SkFixedToFloat(read_big_endian_int(src + 20)); 528 b = SkFixedToFloat(read_big_endian_int(src + 20));
521 d = -b / a; 529 d = -b / a;
522 break; 530 break;
523 } 531 }
524 case 2: 532 case kGABC_ParaCurveType:
525 tagBytes = 12 + 16; 533 tagBytes = 12 + 16;
526 if (len < tagBytes) { 534 if (len < tagBytes) {
527 SkColorSpacePrintf("gamma tag is too small (%d b ytes)", len); 535 SkColorSpacePrintf("gamma tag is too small (%d b ytes)", len);
528 return false; 536 return false;
529 } 537 }
530 538
531 // Y = (aX + b)^g + c for X >= -b/a 539 // Y = (aX + b)^g + c for X >= -b/a
532 // Y = c otherwise 540 // Y = c otherwise
533 g = SkFixedToFloat(read_big_endian_int(src + 12)); 541 g = SkFixedToFloat(read_big_endian_int(src + 12));
534 a = SkFixedToFloat(read_big_endian_int(src + 16)); 542 a = SkFixedToFloat(read_big_endian_int(src + 16));
535 b = SkFixedToFloat(read_big_endian_int(src + 20)); 543 b = SkFixedToFloat(read_big_endian_int(src + 20));
536 c = SkFixedToFloat(read_big_endian_int(src + 24)); 544 c = SkFixedToFloat(read_big_endian_int(src + 24));
537 d = -b / a; 545 d = -b / a;
538 f = c; 546 f = c;
539 break; 547 break;
540 case 3: 548 case kGABDE_ParaCurveType:
541 tagBytes = 12 + 20; 549 tagBytes = 12 + 20;
542 if (len < tagBytes) { 550 if (len < tagBytes) {
543 SkColorSpacePrintf("gamma tag is too small (%d b ytes)", len); 551 SkColorSpacePrintf("gamma tag is too small (%d b ytes)", len);
544 return false; 552 return false;
545 } 553 }
546 554
547 // Y = (aX + b)^g for X >= d 555 // Y = (aX + b)^g for X >= d
548 // Y = cX otherwise 556 // Y = cX otherwise
549 g = SkFixedToFloat(read_big_endian_int(src + 12)); 557 g = SkFixedToFloat(read_big_endian_int(src + 12));
550 a = SkFixedToFloat(read_big_endian_int(src + 16)); 558 a = SkFixedToFloat(read_big_endian_int(src + 16));
551 b = SkFixedToFloat(read_big_endian_int(src + 20)); 559 b = SkFixedToFloat(read_big_endian_int(src + 20));
552 d = SkFixedToFloat(read_big_endian_int(src + 28)); 560 d = SkFixedToFloat(read_big_endian_int(src + 28));
553 e = SkFixedToFloat(read_big_endian_int(src + 24)); 561 e = SkFixedToFloat(read_big_endian_int(src + 24));
554 break; 562 break;
555 case 4: 563 case kGABCDEF_ParaCurveType:
556 tagBytes = 12 + 28; 564 tagBytes = 12 + 28;
557 if (len < tagBytes) { 565 if (len < tagBytes) {
558 SkColorSpacePrintf("gamma tag is too small (%d b ytes)", len); 566 SkColorSpacePrintf("gamma tag is too small (%d b ytes)", len);
559 return false; 567 return false;
560 } 568 }
561 569
562 // Y = (aX + b)^g + c for X >= d 570 // Y = (aX + b)^g + c for X >= d
563 // Y = eX + f otherwise 571 // Y = eX + f otherwise
564 // NOTE: The ICC spec writes "cX" in place of "eX" b ut I think 572 // NOTE: The ICC spec writes "cX" in place of "eX" b ut I think
565 // it's a typo. 573 // it's a typo.
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 ptr32[4] = SkEndian_SwapBE32(0x000116cc); 1100 ptr32[4] = SkEndian_SwapBE32(0x000116cc);
1093 ptr += kTAG_XYZ_Bytes; 1101 ptr += kTAG_XYZ_Bytes;
1094 1102
1095 // Write copyright tag 1103 // Write copyright tag
1096 memcpy(ptr, gEmptyTextTag, sizeof(gEmptyTextTag)); 1104 memcpy(ptr, gEmptyTextTag, sizeof(gEmptyTextTag));
1097 1105
1098 // TODO (msarett): Should we try to hold onto the data so we can return imme diately if 1106 // TODO (msarett): Should we try to hold onto the data so we can return imme diately if
1099 // the client calls again? 1107 // the client calls again?
1100 return SkData::MakeFromMalloc(profile.release(), kICCProfileSize); 1108 return SkData::MakeFromMalloc(profile.release(), kICCProfileSize);
1101 } 1109 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698