| 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" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "third_party/skia/include/core/SkColorSpaceXform.h" | 12 #include "third_party/skia/include/core/SkColorSpaceXform.h" |
| 13 #include "third_party/skia/include/core/SkICC.h" | 13 #include "third_party/skia/include/core/SkICC.h" |
| 14 #include "ui/gfx/color_transform.h" | 14 #include "ui/gfx/color_transform.h" |
| 15 #include "ui/gfx/skia_color_space_util.h" | 15 #include "ui/gfx/skia_color_space_util.h" |
| 16 | 16 |
| 17 namespace gfx { | 17 namespace gfx { |
| 18 | 18 |
| 19 const uint64_t ICCProfile::test_id_adobe_rgb_ = 1; | 19 const uint64_t ICCProfile::test_id_adobe_rgb_ = 1; |
| 20 const uint64_t ICCProfile::test_id_color_spin_ = 2; | 20 const uint64_t ICCProfile::test_id_color_spin_ = 2; |
| 21 const uint64_t ICCProfile::test_id_generic_rgb_ = 3; | 21 const uint64_t ICCProfile::test_id_generic_rgb_ = 3; |
| 22 const uint64_t ICCProfile::test_id_srgb_ = 4; | 22 const uint64_t ICCProfile::test_id_srgb_ = 4; |
| 23 const uint64_t ICCProfile::test_id_no_analytic_tr_fn_ = 5; | 23 const uint64_t ICCProfile::test_id_no_analytic_tr_fn_ = 5; |
| 24 const uint64_t ICCProfile::test_id_a2b_only_ = 6; | 24 const uint64_t ICCProfile::test_id_a2b_only_ = 6; |
| 25 const uint64_t ICCProfile::test_id_overshoot_ = 7; |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // Allow keeping around a maximum of 8 cached ICC profiles. Beware that | 29 // Allow keeping around a maximum of 8 cached ICC profiles. Beware that |
| 29 // we will do a linear search thorugh currently-cached ICC profiles, | 30 // we will do a linear search thorugh currently-cached ICC profiles, |
| 30 // when creating a new ICC profile. | 31 // when creating a new ICC profile. |
| 31 const size_t kMaxCachedICCProfiles = 8; | 32 const size_t kMaxCachedICCProfiles = 8; |
| 32 | 33 |
| 33 struct Cache { | 34 struct Cache { |
| 34 Cache() : id_to_icc_profile_mru(kMaxCachedICCProfiles) {} | 35 Cache() : id_to_icc_profile_mru(kMaxCachedICCProfiles) {} |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 SkColorSpaceTransferFn fn; | 200 SkColorSpaceTransferFn fn; |
| 200 // First try to get a numerical transfer function from the profile. | 201 // First try to get a numerical transfer function from the profile. |
| 201 if (sk_icc->isNumericalTransferFn(&fn)) { | 202 if (sk_icc->isNumericalTransferFn(&fn)) { |
| 202 parametric_color_space_is_accurate = true; | 203 parametric_color_space_is_accurate = true; |
| 203 } else { | 204 } else { |
| 204 // If that fails, try to approximate the transfer function. | 205 // If that fails, try to approximate the transfer function. |
| 205 float fn_max_error = 0; | 206 float fn_max_error = 0; |
| 206 bool got_approximate_fn = | 207 bool got_approximate_fn = |
| 207 SkApproximateTransferFn(sk_icc, &fn_max_error, &fn); | 208 SkApproximateTransferFn(sk_icc, &fn_max_error, &fn); |
| 208 if (got_approximate_fn) { | 209 if (got_approximate_fn) { |
| 209 float kMaxError = 3.f / 256.f; | 210 float kMaxError = 2.f / 256.f; |
| 210 if (fn_max_error < kMaxError) { | 211 if (fn_max_error < kMaxError) { |
| 211 parametric_color_space_is_accurate = true; | 212 parametric_color_space_is_accurate = true; |
| 212 } else { | 213 } else { |
| 213 DLOG(ERROR) << "ICCProfile transfer function approximation " | 214 DLOG(ERROR) << "ICCProfile transfer function approximation " |
| 214 << "inexact, error: " << 256.f * fn_max_error << "/256"; | 215 << "inexact, error: " << 256.f * fn_max_error << "/256"; |
| 215 } | 216 } |
| 216 } else { | 217 } else { |
| 217 // And if that fails, just say that the transfer function was sRGB. | 218 // And if that fails, just say that the transfer function was sRGB. |
| 218 DLOG(ERROR) << "Failed to approximate ICCProfile transfer function."; | 219 DLOG(ERROR) << "Failed to approximate ICCProfile transfer function."; |
| 219 gfx::ColorSpace::CreateSRGB().GetTransferFunction(&fn); | 220 gfx::ColorSpace::CreateSRGB().GetTransferFunction(&fn); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 250 | 251 |
| 251 // Add to the cache. | 252 // Add to the cache. |
| 252 { | 253 { |
| 253 Cache& cache = g_cache.Get(); | 254 Cache& cache = g_cache.Get(); |
| 254 base::AutoLock lock(cache.lock); | 255 base::AutoLock lock(cache.lock); |
| 255 cache.id_to_icc_profile_mru.Put(id_, *this); | 256 cache.id_to_icc_profile_mru.Put(id_, *this); |
| 256 } | 257 } |
| 257 } | 258 } |
| 258 | 259 |
| 259 } // namespace gfx | 260 } // namespace gfx |
| OLD | NEW |