| OLD | NEW |
| 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 1.0f / m1); | 391 1.0f / m1); |
| 392 } | 392 } |
| 393 | 393 |
| 394 case ColorSpace::TransferID::SMPTEST428_1: | 394 case ColorSpace::TransferID::SMPTEST428_1: |
| 395 return (powf(v, 2.6f) - 52.37f) / 48.0f; | 395 return (powf(v, 2.6f) - 52.37f) / 48.0f; |
| 396 | 396 |
| 397 // Chrome-specific values below | 397 // Chrome-specific values below |
| 398 case ColorSpace::TransferID::GAMMA24: | 398 case ColorSpace::TransferID::GAMMA24: |
| 399 v = fmax(0.0f, v); | 399 v = fmax(0.0f, v); |
| 400 return powf(v, 2.4f); | 400 return powf(v, 2.4f); |
| 401 |
| 402 case ColorSpace::TransferID::SMPTEST2084_NON_HDR: |
| 403 v = fmax(0.0f, v); |
| 404 return fmin(2.3f * pow(v, 2.8f), v / 5.0f + 0.8f); |
| 401 } | 405 } |
| 402 } | 406 } |
| 403 | 407 |
| 408 namespace { |
| 409 // Assumes bt2020 |
| 410 float Luma(const ColorTransform::TriStim& c) { |
| 411 return c.x() * 0.2627f + c.y() * 0.6780f + c.z() * 0.0593f; |
| 412 } |
| 413 }; |
| 414 |
| 415 GFX_EXPORT ColorTransform::TriStim ToLinear(ColorSpace::TransferID id, |
| 416 ColorTransform::TriStim color) { |
| 417 ColorTransform::TriStim ret(ToLinear(id, color.x()), ToLinear(id, color.y()), |
| 418 ToLinear(id, color.z())); |
| 419 |
| 420 if (id == ColorSpace::TransferID::SMPTEST2084_NON_HDR) { |
| 421 if (Luma(ret) > 0.0) { |
| 422 ColorTransform::TriStim smpte2084( |
| 423 ToLinear(ColorSpace::TransferID::SMPTEST2084, color.x()), |
| 424 ToLinear(ColorSpace::TransferID::SMPTEST2084, color.y()), |
| 425 ToLinear(ColorSpace::TransferID::SMPTEST2084, color.z())); |
| 426 smpte2084.Scale(Luma(ret) / Luma(smpte2084)); |
| 427 ret = smpte2084; |
| 428 } |
| 429 } |
| 430 |
| 431 return ret; |
| 432 } |
| 433 |
| 404 GFX_EXPORT Transform GetTransferMatrix(ColorSpace::MatrixID id) { | 434 GFX_EXPORT Transform GetTransferMatrix(ColorSpace::MatrixID id) { |
| 405 float Kr = 0.0f, Kb = 0.0f; | 435 float Kr = 0.0f, Kb = 0.0f; |
| 406 switch (id) { | 436 switch (id) { |
| 407 case ColorSpace::MatrixID::RGB: | 437 case ColorSpace::MatrixID::RGB: |
| 408 return Transform(); | 438 return Transform(); |
| 409 | 439 |
| 410 case ColorSpace::MatrixID::BT709: | 440 case ColorSpace::MatrixID::BT709: |
| 411 case ColorSpace::MatrixID::UNSPECIFIED: | 441 case ColorSpace::MatrixID::UNSPECIFIED: |
| 412 case ColorSpace::MatrixID::RESERVED: | 442 case ColorSpace::MatrixID::RESERVED: |
| 413 Kr = 0.2126f; | 443 Kr = 0.2126f; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 : from_(from), to_(to) { | 532 : from_(from), to_(to) { |
| 503 if (intent == Intent::INTENT_PERCEPTUAL) { | 533 if (intent == Intent::INTENT_PERCEPTUAL) { |
| 504 switch (from_.transfer_) { | 534 switch (from_.transfer_) { |
| 505 case ColorSpace::TransferID::UNSPECIFIED: | 535 case ColorSpace::TransferID::UNSPECIFIED: |
| 506 case ColorSpace::TransferID::BT709: | 536 case ColorSpace::TransferID::BT709: |
| 507 case ColorSpace::TransferID::SMPTE170M: | 537 case ColorSpace::TransferID::SMPTE170M: |
| 508 // See SMPTE 1886 | 538 // See SMPTE 1886 |
| 509 from_.transfer_ = ColorSpace::TransferID::GAMMA24; | 539 from_.transfer_ = ColorSpace::TransferID::GAMMA24; |
| 510 break; | 540 break; |
| 511 | 541 |
| 542 case ColorSpace::TransferID::SMPTEST2084: |
| 543 // We don't have an HDR display, so replace SMPTE 2084 with something |
| 544 // that returns ranges more or less suitable for a normal display. |
| 545 from_.transfer_ = ColorSpace::TransferID::SMPTEST2084_NON_HDR; |
| 546 break; |
| 547 |
| 512 default: // Do nothing | 548 default: // Do nothing |
| 513 break; | 549 break; |
| 514 } | 550 } |
| 515 | 551 |
| 516 // TODO(hubbe): shrink gamuts here (never stretch gamuts) | 552 // TODO(hubbe): shrink gamuts here (never stretch gamuts) |
| 517 } | 553 } |
| 518 | 554 |
| 519 Transform* from_transfer_matrix = | 555 Transform* from_transfer_matrix = |
| 520 from_.matrix_ == ColorSpace::MatrixID::BT2020_CL ? &b_ : &a_; | 556 from_.matrix_ == ColorSpace::MatrixID::BT2020_CL ? &b_ : &a_; |
| 521 Transform* to_transfer_matrix = | 557 Transform* to_transfer_matrix = |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 std::unique_ptr<ColorTransform>( | 699 std::unique_ptr<ColorTransform>( |
| 664 new QCMSColorTransform(GetXYZD50Profile(), to_profile)))); | 700 new QCMSColorTransform(GetXYZD50Profile(), to_profile)))); |
| 665 } else { | 701 } else { |
| 666 return std::unique_ptr<ColorTransform>( | 702 return std::unique_ptr<ColorTransform>( |
| 667 new ColorSpaceToColorSpaceTransform(from, to, intent)); | 703 new ColorSpaceToColorSpaceTransform(from, to, intent)); |
| 668 } | 704 } |
| 669 } | 705 } |
| 670 } | 706 } |
| 671 | 707 |
| 672 } // namespace gfx | 708 } // namespace gfx |
| OLD | NEW |