Chromium Code Reviews| Index: ui/gfx/color_space.cc |
| diff --git a/ui/gfx/color_space.cc b/ui/gfx/color_space.cc |
| index 0f5a42b601841ca529d42c456df504512c708914..5ae44aacb3fef5a89995eb43347b40dadc06209d 100644 |
| --- a/ui/gfx/color_space.cc |
| +++ b/ui/gfx/color_space.cc |
| @@ -9,6 +9,8 @@ |
| #include "base/lazy_instance.h" |
| #include "base/synchronization/lock.h" |
| #include "third_party/skia/include/core/SkColorSpace.h" |
| +#include "third_party/skia/include/core/SkData.h" |
| +#include "third_party/skia/include/core/SkICC.h" |
| #include "ui/gfx/icc_profile.h" |
| #include "ui/gfx/skia_color_space_util.h" |
| #include "ui/gfx/transform.h" |
| @@ -96,6 +98,27 @@ ColorSpace ColorSpace::CreateSRGB() { |
| } |
| // static |
| +ColorSpace ColorSpace::CreateCustom(const SkMatrix44& to_XYZD50, |
| + const SkColorSpaceTransferFn& fn) { |
| + ColorSpace result(ColorSpace::PrimaryID::CUSTOM, |
|
hubbe
2017/02/16 01:28:29
It would be really cool if we could map custom tra
ccameron
2017/02/16 01:58:47
Added a TODO. Might get to it soon (w/ some pendin
|
| + ColorSpace::TransferID::CUSTOM, ColorSpace::MatrixID::RGB, |
| + ColorSpace::RangeID::FULL); |
| + for (int row = 0; row < 3; ++row) { |
| + for (int col = 0; col < 3; ++col) { |
| + result.custom_primary_matrix_[3 * row + col] = to_XYZD50.get(row, col); |
| + } |
| + } |
| + result.custom_transfer_params_[0] = fn.fA; |
| + result.custom_transfer_params_[1] = fn.fB; |
| + result.custom_transfer_params_[2] = fn.fC; |
| + result.custom_transfer_params_[3] = fn.fD; |
| + result.custom_transfer_params_[4] = fn.fE; |
| + result.custom_transfer_params_[5] = fn.fF; |
| + result.custom_transfer_params_[6] = fn.fG; |
| + return result; |
| +} |
| + |
| +// static |
| ColorSpace ColorSpace::CreateSCRGBLinear() { |
| return ColorSpace(PrimaryID::BT709, TransferID::LINEAR_HDR, MatrixID::RGB, |
| RangeID::FULL); |
| @@ -242,6 +265,34 @@ sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const { |
| return SkColorSpace::MakeRGB(fn, to_xyz_d50); |
| } |
| +bool ColorSpace::GetICCProfile(ICCProfile* icc_profile) const { |
| + if (!IsValid()) |
| + return false; |
| + |
| + // If this was created from an ICC profile, retrieve that exact profile. |
| + ICCProfile result; |
| + if (ICCProfile::FromId(icc_profile_id_, false, icc_profile)) |
| + return true; |
| + |
| + // Otherwise, construct an ICC profile based on the best approximated |
| + // primaries and matrix. |
| + SkMatrix44 to_XYZD50_matrix; |
| + GetPrimaryMatrix(&to_XYZD50_matrix); |
| + SkColorSpaceTransferFn fn; |
| + if (!GetTransferFunction(&fn)) { |
| + DLOG(ERROR) << "Failed to get ColorSpace transfer function for ICCProfile."; |
| + return false; |
| + } |
| + sk_sp<SkData> data = SkICC::WriteToICC(fn, to_XYZD50_matrix); |
| + if (!data) { |
| + DLOG(ERROR) << "Failed to create SkICC."; |
| + return false; |
| + } |
| + *icc_profile = ICCProfile::FromData(data->data(), data->size()); |
| + DCHECK(icc_profile->IsValid()); |
| + return true; |
| +} |
| + |
| void ColorSpace::GetPrimaryMatrix(SkMatrix44* to_XYZD50) const { |
| SkColorSpacePrimaries primaries = {0}; |
| switch (primaries_) { |