Skip to content
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

Image with transparency rendered grottily #3691

Open
1 task
akx opened this issue Feb 25, 2025 · 4 comments · May be fixed by #3705
Open
1 task

Image with transparency rendered grottily #3691

akx opened this issue Feb 25, 2025 · 4 comments · May be fixed by #3705
Labels
bug Something isn't working painting Related to painting subsystem

Comments

@akx
Copy link

akx commented Feb 25, 2025

Summary

When I visited my company's (@valohai) pricing page in Ladybird, I noticed some of our images are rendered grottily compared to Chrome. (We're changing those images to SVG, since they were blurry as well as grotty...)

I suspect this has to do with semi-transparent pixels, and possibly non-premultiplied blending.

Operating system

macOS

Steps to reproduce

  1. Build Ladybird on macOS from e5966ee
  2. Open attached reproducer.
  3. Notice grottiness around image edges.

Expected behavior

Less grotty edges. Please see screenshot below.

Actual behavior

See above for screenshot.

URL for a reduced test case

N/A

HTML/SVG/etc. source for a reduced test case

<!doctype html>
<html>
<body><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACUAAAAlCAYAAADFniADAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAKiSURBVHgBzZhBbxJBFMf/b8CLiUkv3pqIiTExaUU+gBG/QRuKiSfg6EXLJyh8AmgvHktPHoDUj7DGD0BBjYlpIo299UJi4oXuPt/sgsK6pTtuYfeXwO4Os8w/b97Me28IhnDvcA2p23kw5aFUFoQMWD5TCEN5HsJx+iC2YP+yKFcZwQAK25F7bRHBWyKkJI9rMIHRgj2uU+7lMEz3a0Vx710G6VsNud1CVEKKWyiK+91dsc4eTC2zmBEcrlO22ISpKB50G+ITu1gaVKPNQj3wl6BG/tw5FFOXsWwILdrYqfiblb+Bv3T3ViLIHQxlHrQb/uY5S018qIFV43B11sf+iJqssh5u1qnDMsLlODddlX+nT6VrMQmCO6637bi4lppY6Tvi5pKfU65oeZbyrBQ/OmK4l97xGhSVEIHet3M8fdV0r9FEqZKOrQopO4/kIMH+Tl7JXpFHkmBHRClkkSQkHRJH5/tIEpKbpWVXuGfyTpAzn55fzF395B6uIzSSNBJ/6jAM0KvMlI9vzZKNNAw5qO7803b64wIHnQ94XXyGB+t3ERURxWcmU7hoKrQgo6kKQvJ7cXSKP7zMwWcKDvpIEswnSrzdQpIgJQHZTllyZ1SXLRX7p+WlLv1OU3b2N4gbIsnZC5VJ6sLvkQRSyq1uXFG0WbTkO15h2kqPtofAbDqcVtX4fEvGnVgJs6JclQ7qiANy6lMrAb66j7IFHdj2sUp0Cb8xX8IHV8iDdkvmOFKKHArmI3pcLPubVVBfryMvdyodZz9IEK4SpZEVWYNDS3B++T/SFfGLK/OZ68+nvh5nMLZr0vMGplO2HVnls079X6IQWRzp86gjvUF7+2GIN2CIWyfqskxXQcRP3DPPuXxM8jN95sl04gZ7ia2U2zZygd9z0upGapwTwgAAAABJRU5ErkJggg==" width="128" />
</body>
</html>

Log output and (if possible) backtrace

No related log output for this page.

Screenshots or screen recordings

Same reproducer rendered using Ladybird, Firefox, Chrome.

Image

Build flags or config settings

No response

Contribute a patch?

  • I’ll contribute a patch for this myself.
@gmta
Copy link
Collaborator

gmta commented Feb 25, 2025

We propagate the decoded image's alpha premultiplication type all the way to the rendering library, and I fixed this specifically for PNG images a while ago. This might have regressed; I'll take a look.

@AtkinsSJ AtkinsSJ added bug Something isn't working painting Related to painting subsystem labels Feb 25, 2025
@gmta
Copy link
Collaborator

gmta commented Feb 25, 2025

This seems to happen when the image is not displayed in its original size; i.e. zooming in triggers the bug. When I change our Skia blending mode to nearest neighbour, the issue disappears:

Image

Both the original bitmap and the Skia bitmap have the right alpha type set.

@akx
Copy link
Author

akx commented Feb 25, 2025

@gmta Good catch. Here's an additional data point for that. Removing the size attribute from the tag makes the image render correctly on a low-DPI screen:

Image

When I move the window to my Mac's retina screen and refresh, I get grot (understandable, given that we're now rendering at a pixel multiplier).

Image

@gmta
Copy link
Collaborator

gmta commented Feb 25, 2025

Since swapping out the Skia sampler prevents the issue, this might be a bug on their side. Seems like it used to be the case they only supported premultiplied blending, while support for blending unpremultiplied color data is relatively recent.

gmta added a commit to gmta/ladybird that referenced this issue Feb 26, 2025
Although the PNG format inherently works with unpremultiplied color
data, we are seeing issues with Skia trying to blend unpremultiplied
colors and producing the typical erroneous darker color bands.

Our LibWeb tests actually had a couple of screenshot tests that exposed
these graphical glitches; see the big smiley faces in the CSS
backgrounds tests for example. The failing tests are now updated to
accommodate PNGLoader's new behavior.

Chromium seems to apply the same behavior; i.e. it actively decodes PNGs
to a premultiplied bitmap instead, citing the same shortcoming in Skia.

Fixes LadybirdBrowser#3691.
gmta added a commit to gmta/ladybird that referenced this issue Feb 26, 2025
Although the PNG format inherently works with unpremultiplied color
data, we are seeing issues with Skia trying to blend unpremultiplied
colors and producing the typical erroneous darker color bands.

Our LibWeb tests actually had a couple of screenshot tests that exposed
these graphical glitches; see the big smiley faces in the CSS
backgrounds tests for example. The failing tests are now updated to
accommodate PNGLoader's new behavior.

Chromium seems to apply the same behavior; i.e. it actively decodes PNGs
to a premultiplied bitmap instead, citing the same shortcoming in Skia.

Fixes LadybirdBrowser#3691.
gmta added a commit to gmta/ladybird that referenced this issue Feb 26, 2025
Although the PNG format inherently works with unpremultiplied color
data, we are seeing issues with Skia trying to blend unpremultiplied
colors and producing the typical erroneous darker color bands.

Our LibWeb tests actually had a couple of screenshot tests that exposed
these graphical glitches; see the big smiley faces in the CSS
backgrounds tests for example. The failing tests are now updated to
accommodate PNGLoader's new behavior.

Chromium seems to apply the same behavior; i.e. it actively decodes PNGs
to a premultiplied bitmap instead, citing the same shortcoming in Skia.

Fixes LadybirdBrowser#3691.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working painting Related to painting subsystem
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants