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 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 case ColorSpace::TransferID::SMPTEST2084: | 611 case ColorSpace::TransferID::SMPTEST2084: |
612 case ColorSpace::TransferID::SMPTEST2084_NON_HDR: | 612 case ColorSpace::TransferID::SMPTEST2084_NON_HDR: |
613 case ColorSpace::TransferID::INVALID: | 613 case ColorSpace::TransferID::INVALID: |
614 case ColorSpace::TransferID::ICC_BASED: | 614 case ColorSpace::TransferID::ICC_BASED: |
615 break; | 615 break; |
616 } | 616 } |
617 | 617 |
618 return false; | 618 return false; |
619 } | 619 } |
620 | 620 |
| 621 bool ColorSpace::Serialize(base::Pickle* pickle) const { |
| 622 if (!pickle->WriteUInt32(static_cast<uint32_t>(primaries_)) || |
| 623 !pickle->WriteUInt32(static_cast<uint32_t>(transfer_)) || |
| 624 !pickle->WriteUInt32(static_cast<uint32_t>(matrix_)) || |
| 625 !pickle->WriteUInt32(static_cast<uint32_t>(range_)) || |
| 626 !pickle->WriteUInt64(icc_profile_id_)) |
| 627 return false; |
| 628 if (primaries_ == PrimaryID::CUSTOM && |
| 629 !pickle->WriteBytes(reinterpret_cast<const char*>(custom_primary_matrix_), |
| 630 sizeof(custom_primary_matrix_))) |
| 631 return false; |
| 632 if (transfer_ == TransferID::CUSTOM && |
| 633 !pickle->WriteBytes( |
| 634 reinterpret_cast<const char*>(custom_transfer_params_), |
| 635 sizeof(custom_transfer_params_))) |
| 636 return false; |
| 637 return true; |
| 638 } |
| 639 |
| 640 template <typename T> |
| 641 static bool ReadValue(base::PickleIterator* iter, T* result) { |
| 642 uint32_t value; |
| 643 if (!iter->ReadUInt32(&value)) |
| 644 return false; |
| 645 *result = static_cast<T>(value); |
| 646 if (*result > T::LAST) |
| 647 return false; |
| 648 return true; |
| 649 } |
| 650 |
| 651 bool ColorSpace::ReadFromPickle(base::PickleIterator* iter) { |
| 652 if (!ReadValue(iter, &primaries_)) |
| 653 return false; |
| 654 if (!ReadValue(iter, &transfer_)) |
| 655 return false; |
| 656 if (!ReadValue(iter, &matrix_)) |
| 657 return false; |
| 658 if (!ReadValue(iter, &range_)) |
| 659 return false; |
| 660 if (!iter->ReadUInt64(&icc_profile_id_)) |
| 661 return false; |
| 662 |
| 663 if (primaries_ == PrimaryID::CUSTOM) { |
| 664 const char* data = nullptr; |
| 665 if (!iter->ReadBytes(&data, sizeof(custom_primary_matrix_))) |
| 666 return false; |
| 667 memcpy(custom_primary_matrix_, data, sizeof(custom_primary_matrix_)); |
| 668 } |
| 669 if (transfer_ == TransferID::CUSTOM) { |
| 670 const char* data = nullptr; |
| 671 if (!iter->ReadBytes(&data, sizeof(custom_transfer_params_))) |
| 672 return false; |
| 673 memcpy(custom_transfer_params_, data, sizeof(custom_transfer_params_)); |
| 674 } |
| 675 |
| 676 return true; |
| 677 } |
| 678 |
621 bool ColorSpace::GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const { | 679 bool ColorSpace::GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const { |
622 if (!GetTransferFunction(fn)) | 680 if (!GetTransferFunction(fn)) |
623 return false; | 681 return false; |
624 *fn = SkTransferFnInverse(*fn); | 682 *fn = SkTransferFnInverse(*fn); |
625 return true; | 683 return true; |
626 } | 684 } |
627 | 685 |
628 bool ColorSpace::HasExtendedSkTransferFn() const { | 686 bool ColorSpace::HasExtendedSkTransferFn() const { |
629 return transfer_ == TransferID::LINEAR_HDR || | 687 return transfer_ == TransferID::LINEAR_HDR || |
630 transfer_ == TransferID::IEC61966_2_1_HDR; | 688 transfer_ == TransferID::IEC61966_2_1_HDR; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); | 805 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); |
748 break; | 806 break; |
749 } | 807 } |
750 } | 808 } |
751 | 809 |
752 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) { | 810 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) { |
753 return out << color_space.ToString(); | 811 return out << color_space.ToString(); |
754 } | 812 } |
755 | 813 |
756 } // namespace gfx | 814 } // namespace gfx |
OLD | NEW |