RESOLVED FIXED 237082
createImageBitmap cannot premultiply alpha with ImageData
https://bugs.webkit.org/show_bug.cgi?id=237082
Summary createImageBitmap cannot premultiply alpha with ImageData
Ashley Gullen
Reported 2022-02-23 06:00:15 PST
Summary: when calling createImageBitmap() with an ImageData and the option premultiplyAlpha: "premultiply", the resulting ImageBitmap still does not have premultiplied alpha. It appears to work correctly with other overloads using Blob, Image and Canvas. Repro URL: https://downloads.scirra.com/labs/bugs/imagebitmapalpha/ The demo uses createImageBitmap() premultiplying alpha on Blob, Image, Canvas and ImageData. It uses a WebGL context to read the ImageBitmap pixel data back, via texture upload and readback. In the ImageData case, the texture pixel data still uses unpremultiplied alpha. Look in the console of the repro page and it will log pass/fail results. The ImageData case fails with pixel data [0, 0, 255, 44], with the expected result [0, 0, 44, 44].
Attachments
Radar WebKit Bug Importer
Comment 1 2022-02-23 15:36:46 PST
Brent Fulgham
Comment 2 2023-04-14 09:13:55 PDT
I initially though there might have been a mistake in the optimized code path for premultiplied alpha, but I tried the test case with the slow byte-wise math and the results are identical.
Brent Fulgham
Comment 3 2023-04-14 10:56:34 PDT
Source is unpremultiplied RGBA8, destination for createImageBitmap backing store is premultiplied BGRA8. Colorspace is unchanged. Although the test case talks about [12, 12], the math actually gives you [12, 3]. Inputs to vImagePremultiplyData_RGBA8888 look correct, e.g. the pixel at location 12, 3 in the source buffer is: 00 00 FF 2C The result of premultiplying is: 00 00 2C 2C Which is correct.
Brent Fulgham
Comment 4 2023-04-14 13:29:31 PDT
The RGBA8 is then permuted to BGRA to go into the IOSurface: 00 00 2C 2C Becomes 2C 00 00 2C So the image buffer is properly constructed. I think the issue is when this buffer is used to populate the textImage (WebGLRenderingContextBase::texImageSource) doesn't have the context that the image data is premultiplied; it looks like it rolls the premultiplication out of the buffer before loading into the texture.
Brent Fulgham
Comment 5 2023-04-17 17:21:32 PDT
Brent Fulgham
Comment 6 2023-04-18 11:33:32 PDT
It doesn't look like WPT has any coverage for createImageBitmap with 'premultiply' set.
Matt Woodrow
Comment 7 2023-04-18 16:25:34 PDT
EWS
Comment 8 2023-04-19 10:59:24 PDT
Committed 263137@main (aa1ea27b114e): <https://commits.webkit.org/263137@main> Reviewed commits have been landed. Closing PR #12891 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.