Index: ui/gfx/icc_profile.cc |
diff --git a/ui/gfx/icc_profile.cc b/ui/gfx/icc_profile.cc |
index 2635586a946b8607554731cba31123e52381fbee..ae74576f924128edf3be2744723b8011df3f4b96 100644 |
--- a/ui/gfx/icc_profile.cc |
+++ b/ui/gfx/icc_profile.cc |
@@ -108,17 +108,14 @@ ICCProfile ICCProfile::FromBestMonitor() { |
// static |
ICCProfile ICCProfile::FromColorSpace(const gfx::ColorSpace& color_space) { |
- if (color_space == gfx::ColorSpace()) |
+ if (!color_space.IsValid()) |
return ICCProfile(); |
// If |color_space| was created from an ICC profile, retrieve that exact |
// profile. |
- if (color_space.icc_profile_id_) { |
- Cache& cache = g_cache.Get(); |
- base::AutoLock lock(cache.lock); |
- auto found = cache.id_to_icc_profile_mru.Get(color_space.icc_profile_id_); |
- if (found != cache.id_to_icc_profile_mru.end()) |
- return found->second; |
+ ICCProfile result; |
+ if (FromId(color_space.icc_profile_id_, false, &result)) { |
+ return result; |
} |
// Otherwise, construct an ICC profile based on the best approximated |
@@ -130,18 +127,12 @@ ICCProfile ICCProfile::FromColorSpace(const gfx::ColorSpace& color_space) { |
DLOG(ERROR) << "Failed to get ColorSpace transfer function for ICCProfile."; |
return ICCProfile(); |
} |
- |
sk_sp<SkData> data = SkICC::WriteToICC(fn, to_XYZD50_matrix); |
if (!data) { |
DLOG(ERROR) << "Failed to create SkICC."; |
return ICCProfile(); |
} |
- |
- // gfx::ColorTransform assumes that this will return an empty profile for any |
- // color space that was not constructed from an ICC profile. |
- // TODO(ccameron): Fix this assumption. |
- // return FromData(data->data(), data->size()); |
- return ICCProfile(); |
+ return FromData(data->data(), data->size()); |
} |
const std::vector<char>& ICCProfile::GetData() const { |
@@ -161,6 +152,28 @@ const ColorSpace& ICCProfile::GetColorSpace() const { |
return color_space_; |
} |
+// static |
+bool ICCProfile::FromId(uint64_t id, |
+ bool only_if_needed, |
+ ICCProfile* icc_profile) { |
+ if (!id) |
+ return false; |
+ |
+ Cache& cache = g_cache.Get(); |
+ base::AutoLock lock(cache.lock); |
+ |
+ auto found = cache.id_to_icc_profile_mru.Get(id); |
+ if (found == cache.id_to_icc_profile_mru.end()) |
+ return false; |
+ |
+ const ICCProfile& found_icc_profile = found->second; |
+ if (found_icc_profile.color_space_is_accurate_ && only_if_needed) |
+ return false; |
+ |
+ *icc_profile = found_icc_profile; |
+ return true; |
+} |
+ |
void ICCProfile::ComputeColorSpaceAndCache() { |
if (!id_) |
return; |
@@ -176,51 +189,39 @@ void ICCProfile::ComputeColorSpaceAndCache() { |
} |
} |
- // Compute the color space. |
- color_space_ = gfx::ColorSpace( |
- ColorSpace::PrimaryID::CUSTOM, ColorSpace::TransferID::CUSTOM, |
- ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); |
- color_space_.icc_profile_id_ = id_; |
- color_space_.icc_profile_sk_color_space_ = |
- SkColorSpace::MakeICC(data_.data(), data_.size()); |
- |
+ color_space_is_accurate_ = true; |
+ SkMatrix44 to_XYZD50_matrix; |
+ SkColorSpaceTransferFn fn; |
sk_sp<SkICC> sk_icc = SkICC::Make(data_.data(), data_.size()); |
if (sk_icc) { |
- bool result; |
- SkMatrix44 to_XYZD50_matrix; |
- result = sk_icc->toXYZD50(&to_XYZD50_matrix); |
- if (result) { |
- for (int row = 0; row < 3; ++row) { |
- for (int col = 0; col < 3; ++col) { |
- color_space_.custom_primary_matrix_[3 * row + col] = |
- to_XYZD50_matrix.get(row, col); |
- } |
- } |
- } else { |
+ if (!sk_icc->toXYZD50(&to_XYZD50_matrix)) { |
// Just say that the primaries were the sRGB primaries if we can't |
// extract them. |
- color_space_.primaries_ = ColorSpace::PrimaryID::BT709; |
+ gfx::ColorSpace::CreateSRGB().GetPrimaryMatrix(&to_XYZD50_matrix); |
+ color_space_is_accurate_ = false; |
DLOG(ERROR) << "Unable to handle ICCProfile primaries."; |
} |
- SkColorSpaceTransferFn fn; |
- result = sk_icc->isNumericalTransferFn(&fn); |
- if (result) { |
- color_space_.custom_transfer_params_[0] = fn.fA; |
- color_space_.custom_transfer_params_[1] = fn.fB; |
- color_space_.custom_transfer_params_[2] = fn.fC; |
- color_space_.custom_transfer_params_[3] = fn.fD; |
- color_space_.custom_transfer_params_[4] = fn.fE; |
- color_space_.custom_transfer_params_[5] = fn.fF; |
- color_space_.custom_transfer_params_[6] = fn.fG; |
- } else { |
+ if (!sk_icc->isNumericalTransferFn(&fn)) { |
// Just say that the transfer function was sRGB if we cannot read it. |
// TODO(ccameron): Use a least squares approximation of the transfer |
// function when it is not numerical. |
- color_space_.transfer_ = ColorSpace::TransferID::IEC61966_2_1; |
+ gfx::ColorSpace::CreateSRGB().GetTransferFunction(&fn); |
+ color_space_is_accurate_ = false; |
DLOG(ERROR) << "Unable to handle ICCProfile transfer function."; |
} |
+ } else { |
+ gfx::ColorSpace::CreateSRGB().GetPrimaryMatrix(&to_XYZD50_matrix); |
+ gfx::ColorSpace::CreateSRGB().GetTransferFunction(&fn); |
+ color_space_is_accurate_ = false; |
+ DLOG(ERROR) << "Unable parse ICCProfile."; |
} |
+ // Compute the color space. |
+ color_space_ = gfx::ColorSpace::CreateCustom(to_XYZD50_matrix, fn); |
+ color_space_.icc_profile_id_ = id_; |
+ color_space_.icc_profile_sk_color_space_ = |
+ SkColorSpace::MakeICC(data_.data(), data_.size()); |
+ |
// Add to the cache. |
{ |
Cache& cache = g_cache.Get(); |