| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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/icc_profile.h" | 5 #include "ui/gfx/icc_profile.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/containers/mru_cache.h" | 9 #include "base/containers/mru_cache.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 ICCProfile::ICCProfile() = default; | 38 ICCProfile::ICCProfile() = default; |
| 39 ICCProfile::ICCProfile(ICCProfile&& other) = default; | 39 ICCProfile::ICCProfile(ICCProfile&& other) = default; |
| 40 ICCProfile::ICCProfile(const ICCProfile& other) = default; | 40 ICCProfile::ICCProfile(const ICCProfile& other) = default; |
| 41 ICCProfile& ICCProfile::operator=(ICCProfile&& other) = default; | 41 ICCProfile& ICCProfile::operator=(ICCProfile&& other) = default; |
| 42 ICCProfile& ICCProfile::operator=(const ICCProfile& other) = default; | 42 ICCProfile& ICCProfile::operator=(const ICCProfile& other) = default; |
| 43 ICCProfile::~ICCProfile() = default; | 43 ICCProfile::~ICCProfile() = default; |
| 44 | 44 |
| 45 bool ICCProfile::operator==(const ICCProfile& other) const { | 45 bool ICCProfile::operator==(const ICCProfile& other) const { |
| 46 return valid_ == other.valid_ && data_ == other.data_; | 46 if (type_ != other.type_) |
| 47 return false; |
| 48 switch (type_) { |
| 49 case Type::INVALID: |
| 50 return true; |
| 51 case Type::FROM_COLOR_SPACE: |
| 52 return color_space_ == other.color_space_; |
| 53 case Type::FROM_DATA: |
| 54 return data_ == other.data_; |
| 55 } |
| 56 return false; |
| 47 } | 57 } |
| 48 | 58 |
| 49 // static | 59 // static |
| 50 ICCProfile ICCProfile::FromData(const char* data, size_t size) { | 60 ICCProfile ICCProfile::FromData(const char* data, size_t size) { |
| 51 ICCProfile icc_profile; | 61 ICCProfile icc_profile; |
| 52 if (IsValidProfileLength(size)) { | 62 if (IsValidProfileLength(size)) { |
| 53 icc_profile.valid_ = true; | 63 icc_profile.type_ = Type::FROM_DATA; |
| 54 icc_profile.data_.insert(icc_profile.data_.begin(), data, data + size); | 64 icc_profile.data_.insert(icc_profile.data_.begin(), data, data + size); |
| 65 } else { |
| 66 return ICCProfile(); |
| 55 } | 67 } |
| 56 if (!icc_profile.valid_) | |
| 57 return icc_profile; | |
| 58 | 68 |
| 59 Cache& cache = g_cache.Get(); | 69 Cache& cache = g_cache.Get(); |
| 60 base::AutoLock lock(cache.lock); | 70 base::AutoLock lock(cache.lock); |
| 61 | 71 |
| 62 // Linearly search the cached ICC profiles to find one with the same data. | 72 // Linearly search the cached ICC profiles to find one with the same data. |
| 63 // If it exists, re-use its id and touch it in the cache. | 73 // If it exists, re-use its id and touch it in the cache. |
| 64 for (auto iter = cache.id_to_icc_profile_mru.begin(); | 74 for (auto iter = cache.id_to_icc_profile_mru.begin(); |
| 65 iter != cache.id_to_icc_profile_mru.end(); ++iter) { | 75 iter != cache.id_to_icc_profile_mru.end(); ++iter) { |
| 66 if (icc_profile.data_ == iter->second.data_) { | 76 if (icc_profile.data_ == iter->second.data_) { |
| 67 icc_profile.id_ = iter->second.id_; | 77 icc_profile.id_ = iter->second.id_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 98 // TODO(ccameron): Support constructing ICC profiles from arbitrary ColorSpace | 108 // TODO(ccameron): Support constructing ICC profiles from arbitrary ColorSpace |
| 99 // objects. | 109 // objects. |
| 100 return ICCProfile(); | 110 return ICCProfile(); |
| 101 } | 111 } |
| 102 | 112 |
| 103 const std::vector<char>& ICCProfile::GetData() const { | 113 const std::vector<char>& ICCProfile::GetData() const { |
| 104 return data_; | 114 return data_; |
| 105 } | 115 } |
| 106 | 116 |
| 107 ColorSpace ICCProfile::GetColorSpace() const { | 117 ColorSpace ICCProfile::GetColorSpace() const { |
| 108 if (!valid_) | 118 if (type_ == Type::INVALID) |
| 109 return gfx::ColorSpace(); | 119 return gfx::ColorSpace(); |
| 120 if (type_ == Type::FROM_COLOR_SPACE) |
| 121 return color_space_; |
| 110 | 122 |
| 111 ColorSpace color_space(ColorSpace::PrimaryID::CUSTOM, | 123 ColorSpace color_space(ColorSpace::PrimaryID::CUSTOM, |
| 112 ColorSpace::TransferID::CUSTOM, | 124 ColorSpace::TransferID::CUSTOM, |
| 113 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); | 125 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); |
| 114 color_space.icc_profile_id_ = id_; | 126 color_space.icc_profile_id_ = id_; |
| 115 | 127 |
| 116 // Move this ICC profile to the most recently used end of the cache. | 128 // Move this ICC profile to the most recently used end of the cache. |
| 117 { | 129 { |
| 118 Cache& cache = g_cache.Get(); | 130 Cache& cache = g_cache.Get(); |
| 119 base::AutoLock lock(cache.lock); | 131 base::AutoLock lock(cache.lock); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 180 |
| 169 return color_space; | 181 return color_space; |
| 170 } | 182 } |
| 171 | 183 |
| 172 // static | 184 // static |
| 173 bool ICCProfile::IsValidProfileLength(size_t length) { | 185 bool ICCProfile::IsValidProfileLength(size_t length) { |
| 174 return length >= kMinProfileLength && length <= kMaxProfileLength; | 186 return length >= kMinProfileLength && length <= kMaxProfileLength; |
| 175 } | 187 } |
| 176 | 188 |
| 177 } // namespace gfx | 189 } // namespace gfx |
| OLD | NEW |