Bug 237082
Summary: | createImageBitmap cannot premultiply alpha with ImageData | ||
---|---|---|---|
Product: | WebKit | Reporter: | Ashley Gullen <ashley> |
Component: | Canvas | Assignee: | Matt Woodrow <mattwoodrow> |
Status: | RESOLVED FIXED | ||
Severity: | Normal | CC: | bfulgham, dino, dpaddock, webkit-bug-importer |
Priority: | P2 | Keywords: | InRadar |
Version: | Safari 15 | ||
Hardware: | Unspecified | ||
OS: | Unspecified | ||
Bug Depends on: | |||
Bug Blocks: | 182424 |
Ashley Gullen
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 | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/89382358>
Brent Fulgham
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
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
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
Pull request: https://github.com/WebKit/WebKit/pull/12834
Brent Fulgham
It doesn't look like WPT has any coverage for createImageBitmap with 'premultiply' set.
Matt Woodrow
Pull request: https://github.com/WebKit/WebKit/pull/12891
EWS
Committed 263137@main (aa1ea27b114e): <https://commits.webkit.org/263137@main>
Reviewed commits have been landed. Closing PR #12891 and removing active labels.