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

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

Issue 2641143004: Add LINEAR_HDR so that the linear scRGB colorspace will be HDR (Closed)
Patch Set: windows compile fix Created 3 years, 10 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_space_win.cc ('k') | 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 // 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 "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 float a = 1.11157219592173128753f; 194 float a = 1.11157219592173128753f;
195 float b = 0.02282158552944503135f; 195 float b = 0.02282158552944503135f;
196 if (v <= b) { 196 if (v <= b) {
197 return 4.0f * v; 197 return 4.0f * v;
198 } else { 198 } else {
199 return a * powf(v, 0.45f) - (a - 1.0f); 199 return a * powf(v, 0.45f) - (a - 1.0f);
200 } 200 }
201 } 201 }
202 202
203 case ColorSpace::TransferID::LINEAR: 203 case ColorSpace::TransferID::LINEAR:
204 case ColorSpace::TransferID::LINEAR_HDR:
204 return v; 205 return v;
205 206
206 case ColorSpace::TransferID::LOG: 207 case ColorSpace::TransferID::LOG:
207 if (v < 0.01f) 208 if (v < 0.01f)
208 return 0.0f; 209 return 0.0f;
209 return 1.0f + log(v) / log(10.0f) / 2.0f; 210 return 1.0f + log(v) / log(10.0f) / 2.0f;
210 211
211 case ColorSpace::TransferID::LOG_SQRT: 212 case ColorSpace::TransferID::LOG_SQRT:
212 if (v < sqrt(10.0f) / 1000.0f) 213 if (v < sqrt(10.0f) / 1000.0f)
213 return 0.0f; 214 return 0.0f;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 float a = 1.11157219592173128753f; 324 float a = 1.11157219592173128753f;
324 float b = 0.02282158552944503135f; 325 float b = 0.02282158552944503135f;
325 if (v <= FromLinear(ColorSpace::TransferID::SMPTE240M, b)) { 326 if (v <= FromLinear(ColorSpace::TransferID::SMPTE240M, b)) {
326 return v / 4.0f; 327 return v / 4.0f;
327 } else { 328 } else {
328 return powf((v + a - 1.0f) / a, 1.0f / 0.45f); 329 return powf((v + a - 1.0f) / a, 1.0f / 0.45f);
329 } 330 }
330 } 331 }
331 332
332 case ColorSpace::TransferID::LINEAR: 333 case ColorSpace::TransferID::LINEAR:
334 case ColorSpace::TransferID::LINEAR_HDR:
333 return v; 335 return v;
334 336
335 case ColorSpace::TransferID::LOG: 337 case ColorSpace::TransferID::LOG:
336 if (v < 0.0f) 338 if (v < 0.0f)
337 return 0.0f; 339 return 0.0f;
338 return powf(10.0f, (v - 1.0f) * 2.0f); 340 return powf(10.0f, (v - 1.0f) * 2.0f);
339 341
340 case ColorSpace::TransferID::LOG_SQRT: 342 case ColorSpace::TransferID::LOG_SQRT:
341 if (v < 0.0f) 343 if (v < 0.0f)
342 return 0.0f; 344 return 0.0f;
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 matrix_.TransformPoint(colors + i); 613 matrix_.TransformPoint(colors + i);
612 } 614 }
613 615
614 private: 616 private:
615 Transform matrix_; 617 Transform matrix_;
616 }; 618 };
617 619
618 class ColorTransformFromLinear : public ColorTransformInternal { 620 class ColorTransformFromLinear : public ColorTransformInternal {
619 public: 621 public:
620 explicit ColorTransformFromLinear(ColorSpace::TransferID transfer) 622 explicit ColorTransformFromLinear(ColorSpace::TransferID transfer)
621 : transfer_(transfer) {} 623 : transfer_(transfer) {
624 // Map LINEAR_HDR to LINEAR for optimizations.
625 if (transfer_ == ColorSpace::TransferID::LINEAR_HDR) {
626 transfer_ = ColorSpace::TransferID::LINEAR;
627 }
628 }
622 bool Prepend(ColorTransformInternal* prev) override { 629 bool Prepend(ColorTransformInternal* prev) override {
623 return prev->Join(*this); 630 return prev->Join(*this);
624 } 631 }
625 632
626 bool IsNull() override { return transfer_ == ColorSpace::TransferID::LINEAR; } 633 bool IsNull() override { return transfer_ == ColorSpace::TransferID::LINEAR; }
627 634
628 void transform(ColorTransform::TriStim* colors, size_t num) override { 635 void transform(ColorTransform::TriStim* colors, size_t num) override {
629 for (size_t i = 0; i < num; i++) { 636 for (size_t i = 0; i < num; i++) {
630 colors[i].set_x(FromLinear(transfer_, colors[i].x())); 637 colors[i].set_x(FromLinear(transfer_, colors[i].x()));
631 colors[i].set_y(FromLinear(transfer_, colors[i].y())); 638 colors[i].set_y(FromLinear(transfer_, colors[i].y()));
632 colors[i].set_z(FromLinear(transfer_, colors[i].z())); 639 colors[i].set_z(FromLinear(transfer_, colors[i].z()));
633 } 640 }
634 } 641 }
635 642
636 private: 643 private:
637 friend class ColorTransformToLinear; 644 friend class ColorTransformToLinear;
638 ColorSpace::TransferID transfer_; 645 ColorSpace::TransferID transfer_;
639 }; 646 };
640 647
641 class ColorTransformToLinear : public ColorTransformInternal { 648 class ColorTransformToLinear : public ColorTransformInternal {
642 public: 649 public:
643 explicit ColorTransformToLinear(ColorSpace::TransferID transfer) 650 explicit ColorTransformToLinear(ColorSpace::TransferID transfer)
644 : transfer_(transfer) {} 651 : transfer_(transfer) {
652 // Map LINEAR_HDR to LINEAR for optimizations.
653 if (transfer_ == ColorSpace::TransferID::LINEAR_HDR) {
654 transfer_ = ColorSpace::TransferID::LINEAR;
655 }
656 }
645 657
646 bool Prepend(ColorTransformInternal* prev) override { 658 bool Prepend(ColorTransformInternal* prev) override {
647 return prev->Join(*this); 659 return prev->Join(*this);
648 } 660 }
649 661
650 static bool IsGamma22(ColorSpace::TransferID transfer) { 662 static bool IsGamma22(ColorSpace::TransferID transfer) {
651 switch (transfer) { 663 switch (transfer) {
652 // We don't need to check BT709 here because it's been translated into 664 // We don't need to check BT709 here because it's been translated into
653 // SRGB in ColorSpaceToColorSpaceTransform::ColorSpaceToLinear below. 665 // SRGB in ColorSpaceToColorSpaceTransform::ColorSpaceToLinear below.
654 case ColorSpace::TransferID::GAMMA22: 666 case ColorSpace::TransferID::GAMMA22:
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 to_profile ? ColorSpace::CreateXYZD50() : to, intent, &builder); 1034 to_profile ? ColorSpace::CreateXYZD50() : to, intent, &builder);
1023 if (to_profile) { 1035 if (to_profile) {
1024 builder.Append(std::unique_ptr<ColorTransformInternal>( 1036 builder.Append(std::unique_ptr<ColorTransformInternal>(
1025 new QCMSColorTransform(GetXYZD50Profile(), to_profile))); 1037 new QCMSColorTransform(GetXYZD50Profile(), to_profile)));
1026 } 1038 }
1027 1039
1028 return builder.GetTransform(); 1040 return builder.GetTransform();
1029 } 1041 }
1030 1042
1031 } // namespace gfx 1043 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/color_space_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698