Closed Bug 1756803 Opened 2 years ago Closed 2 years ago

createImageBitmap handles premultiply alpha, resize and ImageData incorrectly

Categories

(Core :: Graphics: Canvas2D, defect)

Firefox 99
defect

Tracking

()

RESOLVED FIXED
100 Branch
Tracking Status
firefox-esr91 --- unaffected
firefox97 --- unaffected
firefox98 --- wontfix
firefox99 --- wontfix
firefox100 --- fixed

People

(Reporter: ashley, Assigned: angus.sawyer)

References

(Regression)

Details

(Keywords: regression)

Attachments

(1 file)

Steps to reproduce:

Nightly 99.0a1 (2022-02-23) appears to support the resizeWidth and resizeHeight options of createImageBitmap. However when also used with premultiplyAlpha: "premultiply", and passed an ImageData, it produces incorrect pixel data in the ImageBitmap.

Repro URL: https://downloads.scirra.com/labs/bugs/imagebitmapalpha/resize.html

This tests createImageBitmap with Blob, Image, Canvas and ImageData, each time specifying both to premultiply alpha and resize the image larger. It then uses a WebGL context to read back the ImageBitmap pixel data via texture upload.

Actual results:

The first three cases work OK, producing pixel data [0, 0, 40, 40]. The last case with ImageData fails, producing pixel data [0, 0, 254, 254].

I'm not even sure what it's done here: the original pixel data is [0, 0, 255, 44], i.e. semitransparent blue. So it's not that it's skipped premultiplying alpha - somehow the alpha value has actually increased.

Expected results:

The last case with ImageData should produce the same pixel data results as the first three cases - in this test, [0, 0, 40, 40].

The Bugbug bot thinks this bug should belong to the 'Core::Graphics: WebRender' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → Graphics: WebRender
Product: Firefox → Core

Any interest in investigating/fixing this?

Flags: needinfo?(angus.sawyer)
Regressed by: 1733559

Set release status flags based on info from the regressing bug 1733559

I'll take a look. ImageData takes a different path to everything else.

Flags: needinfo?(angus.sawyer)
Has Regression Range: --- → yes
Status: UNCONFIRMED → NEW
Component: Graphics: WebRender → Canvas: 2D
Ever confirmed: true

Two issues:

The result of scaling & premultiply is order critical, the previous order for ImageData was scale > premultiply, the other image sources were premultiplied by default so didn't expose this issue. Reorder in the ImageData and common code paths (the original order followed the w3c spec order of operations - maybe the spec needs amending).

The ImageData path did not set the premultiplied flag of the resulting ImageBitmap correctly so the image would be premultiplied again in PrepareForDrawTarget.

Assignee: nobody → angus.sawyer
Status: NEW → ASSIGNED
Severity: -- → S3

There's a r+ patch which didn't land and no activity in this bug for 2 weeks.
:angus.sawyer, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit auto_nag documentation.

Flags: needinfo?(aosmond)
Flags: needinfo?(angus.sawyer)
Pushed by aosmond@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/f1af395cec5d
scaling/premultiply alpha of ImageData r=aosmond
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 100 Branch
Flags: needinfo?(aosmond)
Flags: needinfo?(angus.sawyer)

The patch landed in nightly and beta is affected.
:angus.sawyer, is this bug important enough to require an uplift?
If not please set status_beta to wontfix.

For more information, please visit auto_nag documentation.

Flags: needinfo?(angus.sawyer)
Flags: needinfo?(angus.sawyer)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: