| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_space.h" | 5 #include "ui/gfx/color_space.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "third_party/skia/include/core/SkColorSpace.h" | 11 #include "third_party/skia/include/core/SkColorSpace.h" |
| 12 #include "ui/gfx/icc_profile.h" | 12 #include "ui/gfx/icc_profile.h" |
| 13 #include "ui/gfx/skia_color_space_util.h" |
| 13 #include "ui/gfx/transform.h" | 14 #include "ui/gfx/transform.h" |
| 14 | 15 |
| 15 namespace gfx { | 16 namespace gfx { |
| 16 | 17 |
| 17 namespace { | |
| 18 | |
| 19 SkColorSpaceTransferFn InvertTransferFn(SkColorSpaceTransferFn fn) { | |
| 20 SkColorSpaceTransferFn fn_inv = {0}; | |
| 21 if (fn.fA > 0 && fn.fG > 0) { | |
| 22 double a_to_the_g = pow(fn.fA, fn.fG); | |
| 23 fn_inv.fA = 1.f / a_to_the_g; | |
| 24 fn_inv.fB = -fn.fE / a_to_the_g; | |
| 25 fn_inv.fG = 1.f / fn.fG; | |
| 26 } | |
| 27 fn_inv.fD = fn.fC * fn.fD + fn.fF; | |
| 28 fn_inv.fE = -fn.fB / fn.fA; | |
| 29 if (fn.fC != 0) { | |
| 30 fn_inv.fC = 1.f / fn.fC; | |
| 31 fn_inv.fF = -fn.fF / fn.fC; | |
| 32 } | |
| 33 return fn_inv; | |
| 34 } | |
| 35 }; | |
| 36 | |
| 37 ColorSpace::PrimaryID ColorSpace::PrimaryIDFromInt(int primary_id) { | 18 ColorSpace::PrimaryID ColorSpace::PrimaryIDFromInt(int primary_id) { |
| 38 if (primary_id < 0 || primary_id > static_cast<int>(PrimaryID::LAST)) | 19 if (primary_id < 0 || primary_id > static_cast<int>(PrimaryID::LAST)) |
| 39 return PrimaryID::UNKNOWN; | 20 return PrimaryID::UNKNOWN; |
| 40 if (primary_id > static_cast<int>(PrimaryID::LAST_STANDARD_VALUE) && | 21 if (primary_id > static_cast<int>(PrimaryID::LAST_STANDARD_VALUE) && |
| 41 primary_id < 1000) | 22 primary_id < 1000) |
| 42 return PrimaryID::UNKNOWN; | 23 return PrimaryID::UNKNOWN; |
| 43 return static_cast<PrimaryID>(primary_id); | 24 return static_cast<PrimaryID>(primary_id); |
| 44 } | 25 } |
| 45 | 26 |
| 46 ColorSpace::TransferID ColorSpace::TransferIDFromInt(int transfer_id) { | 27 ColorSpace::TransferID ColorSpace::TransferIDFromInt(int transfer_id) { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 case ColorSpace::TransferID::SMPTEST2084_NON_HDR: | 460 case ColorSpace::TransferID::SMPTEST2084_NON_HDR: |
| 480 break; | 461 break; |
| 481 } | 462 } |
| 482 | 463 |
| 483 return false; | 464 return false; |
| 484 } | 465 } |
| 485 | 466 |
| 486 bool ColorSpace::GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const { | 467 bool ColorSpace::GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const { |
| 487 if (!GetTransferFunction(fn)) | 468 if (!GetTransferFunction(fn)) |
| 488 return false; | 469 return false; |
| 489 *fn = InvertTransferFn(*fn); | 470 *fn = SkTransferFnInverse(*fn); |
| 490 return true; | 471 return true; |
| 491 } | 472 } |
| 492 | 473 |
| 493 void ColorSpace::GetTransferMatrix(SkMatrix44* matrix) const { | 474 void ColorSpace::GetTransferMatrix(SkMatrix44* matrix) const { |
| 494 float Kr = 0; | 475 float Kr = 0; |
| 495 float Kb = 0; | 476 float Kb = 0; |
| 496 switch (matrix_) { | 477 switch (matrix_) { |
| 497 case ColorSpace::MatrixID::RGB: | 478 case ColorSpace::MatrixID::RGB: |
| 498 matrix->setIdentity(); | 479 matrix->setIdentity(); |
| 499 return; | 480 return; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 case MatrixID::BT2020_CL: | 588 case MatrixID::BT2020_CL: |
| 608 case MatrixID::YDZDX: | 589 case MatrixID::YDZDX: |
| 609 case MatrixID::UNKNOWN: | 590 case MatrixID::UNKNOWN: |
| 610 matrix->setScale(255.0f/219.0f, 255.0f/224.0f, 255.0f/224.0f); | 591 matrix->setScale(255.0f/219.0f, 255.0f/224.0f, 255.0f/224.0f); |
| 611 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); | 592 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); |
| 612 break; | 593 break; |
| 613 } | 594 } |
| 614 } | 595 } |
| 615 | 596 |
| 616 } // namespace gfx | 597 } // namespace gfx |
| OLD | NEW |