Skip to content

Extended colors should be clamped so they look the same in SDR and HDR layers. #47418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mattwoodrow
Copy link
Contributor

@mattwoodrow mattwoodrow commented Jul 1, 2025

d0099fa

Extended colors should be clamped so they look the same in SDR and HDR layers.
https://bugs.webkit.org/show_bug.cgi?id=292226
<rdar://150231788>

Reviewed by NOBODY (OOPS!).

Compute the headroom for extended colors, and tonemap them back into the SDR
range during WebCore::Color->CGColor conversion so that they appear identical
regardless of layer backing store contents format.

* Source/WebCore/platform/graphics/cg/ColorCG.cpp:
(WebCore::headroomForColor):
(WebCore::createCGColor):

d0099fa

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ❌ 🛠 ios ❌ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ❌ 🛠 ios-sim ❌ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ❌ 🧪 ios-wk2 ❌ 🧪 api-mac ✅ 🧪 api-wpe
❌ 🧪 ios-wk2-wpt ❌ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
❌ 🧪 api-ios ❌ 🧪 mac-wk2 ✅ 🛠 gtk
❌ 🛠 vision ❌ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
❌ 🛠 vision-sim ❌ 🧪 mac-wk2-stress ❌ 🧪 api-gtk
⏳ 🧪 vision-wk2 ❌ 🧪 mac-intel-wk2 ✅ 🛠 playstation
❌ 🛠 tv ❌ 🛠 mac-safer-cpp
❌ 🛠 tv-sim
❌ 🛠 watch
❌ 🛠 watch-sim

…R layers.

https://bugs.webkit.org/show_bug.cgi?id=292226
<rdar://150231788>

Reviewed by NOBODY (OOPS!).

Compute the headroom for extended colors, and tonemap them back into the SDR
range during WebCore::Color->CGColor conversion so that they appear identical
regardless of layer backing store contents format.

* Source/WebCore/platform/graphics/cg/ColorCG.cpp:
(WebCore::headroomForColor):
(WebCore::createCGColor):
@mattwoodrow mattwoodrow self-assigned this Jul 1, 2025
@mattwoodrow mattwoodrow added the Images For bugs in image handling. label Jul 1, 2025
@mattwoodrow mattwoodrow requested a review from weinig July 1, 2025 02:49
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jul 1, 2025
auto [c1, c2, c3, c4] = cgCompatibleComponents;
std::array<CGFloat, 4> cgFloatComponents { c1, c2, c3, c4 };

return adoptCF(CGColorCreate(cgColorSpace, cgFloatComponents.data()));
auto result = adoptCF(CGColorCreate(cgColorSpace, cgFloatComponents.data()));
Copy link
Contributor

@lilyspiniolas lilyspiniolas Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto result = adoptCF(CGColorCreate(cgColorSpace, cgFloatComponents.data()));
RetainPtr result = adoptCF(CGColorCreate(cgColorSpace, cgFloatComponents.data()));

auto result = adoptCF(CGColorCreate(cgColorSpace, cgFloatComponents.data()));

if (auto headroom = headroomForColor(color, cgColorSpace); headroom > 1) {
auto info = adoptCF(CGColorConversionInfoCreateForToneMapping(cgColorSpace, headroom, cgColorSpace, 1.0f, kCGToneMappingDefault, nullptr, nullptr));
Copy link
Contributor

@lilyspiniolas lilyspiniolas Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto info = adoptCF(CGColorConversionInfoCreateForToneMapping(cgColorSpace, headroom, cgColorSpace, 1.0f, kCGToneMappingDefault, nullptr, nullptr));
RetainPtr info = adoptCF(CGColorConversionInfoCreateForToneMapping(cgColorSpace, headroom, cgColorSpace, 1.0f, kCGToneMappingDefault, nullptr, nullptr));

@weinig
Copy link
Contributor

weinig commented Jul 1, 2025

Hey @mattwoodrow, I would love to talk to you more about this, as I have a few concerns here.

  1. I don't think this is the right approach for the platform. I think CSS colors should be able to use as much headroom as they need (constrained by dynamic-range-limit). My main argument, other than it being the most obvious behavior for authors, is that if an author can use a single 1x1 pixel image to get a color, it should be able to do the same thing with a CSS color.

  2. If, in the end, the decision is made to constrain CSS colors, I don't think this is the right place to do it, as you need the output color space to properly perform this mapping. That means, it probably needs to be done at painting time in the GraphicsContext.

I'd be happy to expand on this, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Images For bugs in image handling. merging-blocked Applied to prevent a change from being merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants