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

Side by Side Diff: ui/gfx/color_transform.cc

Issue 2229953003: Support for custom primaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test updated 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 | « ui/gfx/color_transform.h ('k') | ui/gfx/color_transform_fuzzer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/color_transform.h" 5 #include "ui/gfx/color_transform.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/gfx/color_space.h" 10 #include "ui/gfx/color_space.h"
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 NOTREACHED(); 493 NOTREACHED();
494 return Transform(); 494 return Transform();
495 } 495 }
496 496
497 class ColorSpaceToColorSpaceTransform : public ColorTransform { 497 class ColorSpaceToColorSpaceTransform : public ColorTransform {
498 public: 498 public:
499 ColorSpaceToColorSpaceTransform(const ColorSpace& from, 499 ColorSpaceToColorSpaceTransform(const ColorSpace& from,
500 const ColorSpace& to, 500 const ColorSpace& to,
501 Intent intent) 501 Intent intent)
502 : from_(from), to_(to) { 502 : from_(from), to_(to) {
503 if (intent == Intent::PERCEPTUAL) { 503 if (intent == Intent::INTENT_PERCEPTUAL) {
504 switch (from_.transfer_) { 504 switch (from_.transfer_) {
505 case ColorSpace::TransferID::UNSPECIFIED: 505 case ColorSpace::TransferID::UNSPECIFIED:
506 case ColorSpace::TransferID::BT709: 506 case ColorSpace::TransferID::BT709:
507 case ColorSpace::TransferID::SMPTE170M: 507 case ColorSpace::TransferID::SMPTE170M:
508 // See SMPTE 1886 508 // See SMPTE 1886
509 from_.transfer_ = ColorSpace::TransferID::GAMMA24; 509 from_.transfer_ = ColorSpace::TransferID::GAMMA24;
510 break; 510 break;
511 511
512 default: // Do nothing 512 default: // Do nothing
513 break; 513 break;
514 } 514 }
515 515
516 // TODO(hubbe): shrink gamuts here (never stretch gamuts) 516 // TODO(hubbe): shrink gamuts here (never stretch gamuts)
517 } 517 }
518 518
519 Transform* from_transfer_matrix = 519 Transform* from_transfer_matrix =
520 from_.matrix_ == ColorSpace::MatrixID::BT2020_CL ? &b_ : &a_; 520 from_.matrix_ == ColorSpace::MatrixID::BT2020_CL ? &b_ : &a_;
521 Transform* to_transfer_matrix = 521 Transform* to_transfer_matrix =
522 to_.matrix_ == ColorSpace::MatrixID::BT2020_CL ? &b_ : &c_; 522 to_.matrix_ == ColorSpace::MatrixID::BT2020_CL ? &b_ : &c_;
523 523
524 c_ *= Invert(GetRangeAdjustMatrix(to_.range_, to_.matrix_)); 524 c_ *= Invert(GetRangeAdjustMatrix(to_.range_, to_.matrix_));
525 *to_transfer_matrix *= GetTransferMatrix(to_.matrix_); 525 *to_transfer_matrix *= GetTransferMatrix(to_.matrix_);
526 b_ *= Invert(GetPrimaryMatrix(to_.primaries_)); 526 b_ *= Invert(GetPrimaryTransform(to_));
527 b_ *= GetPrimaryMatrix(from_.primaries_); 527 b_ *= GetPrimaryTransform(from_);
528 *from_transfer_matrix *= Invert(GetTransferMatrix(from_.matrix_)); 528 *from_transfer_matrix *= Invert(GetTransferMatrix(from_.matrix_));
529 a_ *= GetRangeAdjustMatrix(from_.range_, from_.matrix_); 529 a_ *= GetRangeAdjustMatrix(from_.range_, from_.matrix_);
530 } 530 }
531 531
532 static Transform GetPrimaryTransform(const ColorSpace& c) {
533 if (c.primaries_ == ColorSpace::PrimaryID::CUSTOM) {
534 return Transform(c.custom_primary_matrix_[0], c.custom_primary_matrix_[1],
535 c.custom_primary_matrix_[2], c.custom_primary_matrix_[3],
536 c.custom_primary_matrix_[4], c.custom_primary_matrix_[5],
537 c.custom_primary_matrix_[6], c.custom_primary_matrix_[7],
538 c.custom_primary_matrix_[8], c.custom_primary_matrix_[9],
539 c.custom_primary_matrix_[10],
540 c.custom_primary_matrix_[11], 0.0f, 0.0f, 0.0f, 1.0f);
541 } else {
542 return GetPrimaryMatrix(c.primaries_);
543 }
544 }
545
532 void transform(TriStim* colors, size_t num) override { 546 void transform(TriStim* colors, size_t num) override {
533 for (size_t i = 0; i < num; i++) { 547 for (size_t i = 0; i < num; i++) {
534 TriStim c = colors[i]; 548 TriStim c = colors[i];
535 a_.TransformPoint(&c); 549 a_.TransformPoint(&c);
536 c.set_x(ToLinear(from_.transfer_, c.x())); 550 c.set_x(ToLinear(from_.transfer_, c.x()));
537 c.set_y(ToLinear(from_.transfer_, c.y())); 551 c.set_y(ToLinear(from_.transfer_, c.y()));
538 c.set_z(ToLinear(from_.transfer_, c.z())); 552 c.set_z(ToLinear(from_.transfer_, c.z()));
539 b_.TransformPoint(&c); 553 b_.TransformPoint(&c);
540 c.set_x(FromLinear(to_.transfer_, c.x())); 554 c.set_x(FromLinear(to_.transfer_, c.x()));
541 c.set_y(FromLinear(to_.transfer_, c.y())); 555 c.set_y(FromLinear(to_.transfer_, c.y()));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 std::unique_ptr<ColorTransform>( 663 std::unique_ptr<ColorTransform>(
650 new QCMSColorTransform(GetXYZD50Profile(), to_profile)))); 664 new QCMSColorTransform(GetXYZD50Profile(), to_profile))));
651 } else { 665 } else {
652 return std::unique_ptr<ColorTransform>( 666 return std::unique_ptr<ColorTransform>(
653 new ColorSpaceToColorSpaceTransform(from, to, intent)); 667 new ColorSpaceToColorSpaceTransform(from, to, intent));
654 } 668 }
655 } 669 }
656 } 670 }
657 671
658 } // namespace gfx 672 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/color_transform.h ('k') | ui/gfx/color_transform_fuzzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698