0

Treat HLG images as 2.2 gamma on SDR displays.

This dramatically improves the quality of these images and is a
simple fix until real tone mapping can be provided.

Bug: 1216691
Change-Id: I8bde11bf4649f46115775d45472c099489b25a1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3297063
Reviewed-by: ccameron <ccameron@chromium.org>
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#944819}
This commit is contained in:
Dale Curtis
2021-11-24 03:37:40 +00:00
committed by Chromium LUCI CQ
parent 7e075b8ed5
commit 0f8348d1fa
3 changed files with 31 additions and 9 deletions

@ -316,7 +316,10 @@ int PaintImage::height() const {
: GetSkImageInfo().height();
}
gfx::ContentColorUsage PaintImage::GetContentColorUsage() const {
gfx::ContentColorUsage PaintImage::GetContentColorUsage(bool* is_hlg) const {
if (is_hlg)
*is_hlg = false;
// Right now, JS paint worklets can only be in sRGB
if (paint_worklet_input_)
return gfx::ContentColorUsage::kSRGB;
@ -328,10 +331,15 @@ gfx::ContentColorUsage PaintImage::GetContentColorUsage() const {
return gfx::ContentColorUsage::kSRGB;
skcms_TransferFunction fn;
if (!color_space->isNumericalTransferFn(&fn) &&
(skcms_TransferFunction_isPQish(&fn) ||
skcms_TransferFunction_isHLGish(&fn))) {
return gfx::ContentColorUsage::kHDR;
if (!color_space->isNumericalTransferFn(&fn)) {
if (skcms_TransferFunction_isPQish(&fn))
return gfx::ContentColorUsage::kHDR;
if (skcms_TransferFunction_isHLGish(&fn)) {
if (is_hlg)
*is_hlg = true;
return gfx::ContentColorUsage::kHDR;
}
}
// If it's not HDR and not SRGB, report it as WCG.

@ -282,7 +282,7 @@ class CC_PAINT_EXPORT PaintImage {
return paint_worklet_input_ ? nullptr : GetSkImageInfo().colorSpace();
}
gfx::ContentColorUsage GetContentColorUsage() const;
gfx::ContentColorUsage GetContentColorUsage(bool* is_hlg = nullptr) const;
// Returns whether this image will be decoded and rendered from YUV data
// and fills out |info|. |supported_data_types| indicates the bit depths and

@ -2934,14 +2934,28 @@ sk_sp<SkColorSpace> GpuImageDecodeCache::ColorSpaceForImageDecode(
bool GpuImageDecodeCache::NeedsColorSpaceAdjustedForUpload(
const DrawImage& image) const {
return image.sdr_white_level() != gfx::ColorSpace::kDefaultSDRWhiteLevel &&
image.paint_image().GetContentColorUsage() ==
gfx::ContentColorUsage::kHDR;
bool is_hlg = false;
if (image.paint_image().GetContentColorUsage(&is_hlg) !=
gfx::ContentColorUsage::kHDR) {
return false;
}
// Attempt basic "tonemapping" of HLG content when rendering to SDR.
if (is_hlg && !image.target_color_space().IsHDR())
return true;
return image.sdr_white_level() != gfx::ColorSpace::kDefaultSDRWhiteLevel;
}
sk_sp<SkColorSpace> GpuImageDecodeCache::ColorSpaceForImageUpload(
const DrawImage& image) const {
DCHECK(NeedsColorSpaceAdjustedForUpload(image));
if (!image.target_color_space().IsHDR()) {
// HLG is designed such that treating it as 2.2 gamma content works well.
constexpr skcms_TransferFunction kGamma22 = {2.2, 1, 0, 0, 0, 0, 0};
return SkColorSpace::MakeRGB(kGamma22, SkNamedGamut::kRec2020);
}
return gfx::ColorSpace(*image.paint_image().color_space())
.GetWithSDRWhiteLevel(image.sdr_white_level())
.ToSkColorSpace();