Skip to content

Commit

Permalink
Add PQ, HLG SkTransferFns and BT.2020 YUV to gfx::ColorSpace.
Browse files Browse the repository at this point in the history
Skia added support for these recently, so lets expose them in
gfx::ColorSpace. This will allow us to correct our YUV conversions for
BT.2020 content in GpuMemoryBuffer upload and PaintCanvasVideoRenderer.

BUG=960620
TEST=unittests pass
R=ccameron

Change-Id: I6a659de0da7f21070857b855796d65bdce227a2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1894770
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Auto-Submit: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711964}
  • Loading branch information
dalecurtis authored and Commit Bot committed Nov 2, 2019
1 parent 9fb9ee6 commit 75e5efb
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions ui/gfx/color_space.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,29 @@ ColorSpace::ColorSpace(const SkColorSpace& sk_color_space)
TransferID::INVALID,
MatrixID::RGB,
RangeID::FULL) {
// Special case the HDR transfer functions since they're not numerical
auto transfer_eq = [](skcms_TransferFunction x, skcms_TransferFunction y) {
return x.g == y.g && x.a == y.a && x.b == y.b && x.c == y.c && x.d == y.d &&
x.e == y.e && x.f == y.f;
};

skcms_TransferFunction fn;
if (sk_color_space.isNumericalTransferFn(&fn)) {
SetCustomTransferFunction(fn);
} else if (transfer_eq(fn, SkNamedTransferFn::kHLG)) {
transfer_ = TransferID::ARIB_STD_B67;
} else if (transfer_eq(fn, SkNamedTransferFn::kPQ)) {
transfer_ = TransferID::SMPTEST2084;
} else {
// Construct an invalid result: Unable to extract necessary parameters
return;
}

skcms_Matrix3x3 to_XYZD50;
if (!sk_color_space.isNumericalTransferFn(&fn) ||
!sk_color_space.toXYZD50(&to_XYZD50)) {
if (!sk_color_space.toXYZD50(&to_XYZD50)) {
// Construct an invalid result: Unable to extract necessary parameters
return;
}
SetCustomTransferFunction(fn);
SetCustomPrimaries(to_XYZD50);
}

Expand Down Expand Up @@ -460,6 +475,12 @@ sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const {
case TransferID::LINEAR_HDR:
transfer_fn = SkNamedTransferFn::kLinear;
break;
case TransferID::ARIB_STD_B67:
transfer_fn = SkNamedTransferFn::kHLG;
break;
case TransferID::SMPTEST2084:
transfer_fn = SkNamedTransferFn::kPQ;
break;
default:
if (!GetTransferFunction(&transfer_fn)) {
DLOG(ERROR) << "Failed to transfer function for SkColorSpace";
Expand Down Expand Up @@ -939,6 +960,10 @@ bool ColorSpace::ToSkYUVColorSpace(SkYUVColorSpace* out) const {
*out = kRec601_SkYUVColorSpace;
return true;

case MatrixID::BT2020_NCL:
*out = kBT2020_SkYUVColorSpace;
return true;

default:
break;
}
Expand Down

0 comments on commit 75e5efb

Please sign in to comment.