Closed Bug 2079663 Opened 1 month ago Closed 1 month ago

jxl decoder doesn't handle files that are premult alpha correctly

Categories

(Core :: Graphics: ImageLib, defect)

defect

Tracking

()

RESOLVED FIXED
160 Branch
Tracking Status
firefox158 --- fixed
firefox159 --- fixed
firefox160 --- fixed

People

(Reporter: tnikkel, Assigned: tnikkel)

References

Details

Attachments

(9 external files)

The name says what type it holds rather than what it is for. The next patch
adds a second row buffer, so name this one after its role: the row we hand to
the surface pipe when it can't read mPixelBuffer directly.

https://searchfox.org/firefox-main/rev/3c71a541b0e7ac6e086907b38670dabca9174c45/image/decoders/nsJXLDecoder.cpp#607

We assume jxl-rs always outputs unpremultiplied alpha, but for images with
premultiplied (associated) alpha it outputs the premultiplied values stored in
the file. We then premultiply them again, so semi-transparent areas come out
too dark. Color management and surfaces that want unpremultiplied data
(NO_PREMULTIPLY_ALPHA) also got premultiplied data.

Now we unpremultiply when color management or the surface needs it, and
otherwise tell the surface pipe not to premultiply. The spec doesn't say what
color values larger than alpha mean; we clamp them to alpha so the result
doesn't depend on whether color management runs.

Premultiplied and non-premultiplied versions of the same RGB and gray grids,
each compared against one PNG, plus the conformance suite's
alpha_premultiplied image compared against its reference PNG. cjxl
--premultiply=1 only marks the pixels as premultiplied, so the premultiplied
grids are encoded from PNGs that were premultiplied first.

Status: NEW → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 160 Branch

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/63495 for changes under testing/web-platform/tests

The name says what type it holds rather than what it is for. The next patch
adds a second row buffer, so name this one after its role: the row we hand to
the surface pipe when it can't read mPixelBuffer directly.

Original Revision: https://phabricator.services.mozilla.com/D331947

Attachment #9657146 - Flags: approval-mozilla-beta?

https://searchfox.org/firefox-main/rev/3c71a541b0e7ac6e086907b38670dabca9174c45/image/decoders/nsJXLDecoder.cpp#607

We assume jxl-rs always outputs unpremultiplied alpha, but for images with
premultiplied (associated) alpha it outputs the premultiplied values stored in
the file. We then premultiply them again, so semi-transparent areas come out
too dark. Color management and surfaces that want unpremultiplied data
(NO_PREMULTIPLY_ALPHA) also got premultiplied data.

Now we unpremultiply when color management or the surface needs it, and
otherwise tell the surface pipe not to premultiply. The spec doesn't say what
color values larger than alpha mean; we clamp them to alpha so the result
doesn't depend on whether color management runs.

Original Revision: https://phabricator.services.mozilla.com/D331951

Attachment #9657147 - Flags: approval-mozilla-beta?

Premultiplied and non-premultiplied versions of the same RGB and gray grids,
each compared against one PNG, plus the conformance suite's
alpha_premultiplied image compared against its reference PNG. cjxl
--premultiply=1 only marks the pixels as premultiplied, so the premultiplied
grids are encoded from PNGs that were premultiplied first.

Original Revision: https://phabricator.services.mozilla.com/D331952

Attachment #9657148 - Flags: approval-mozilla-beta?

firefox-beta Uplift Approval Request

  • User impact if declined/Reason for urgency: incorrect rendering of premultiplied alpha jpeg xl files
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: no
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: The change only affects JPEG XL images with premultiplied (associated) alpha, which are uncommon. For all other JPEG XL images the decoding path is unchanged. I've added good test coverage for premult files with new WPT reftests cover the RGB and grayscale cases and the JPEG XL conformance image.
  • String changes made/needed?: none
  • Is Android affected?: yes

Upstream PR merged by moz-wptsync-bot

Flags: in-testsuite+
Attachment #9657146 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9657147 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9657148 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

The name says what type it holds rather than what it is for. The next patch
adds a second row buffer, so name this one after its role: the row we hand to
the surface pipe when it can't read mPixelBuffer directly.

Original Revision: https://phabricator.services.mozilla.com/D331947

Attachment #9657984 - Flags: approval-mozilla-release?

https://searchfox.org/firefox-main/rev/3c71a541b0e7ac6e086907b38670dabca9174c45/image/decoders/nsJXLDecoder.cpp#607

We assume jxl-rs always outputs unpremultiplied alpha, but for images with
premultiplied (associated) alpha it outputs the premultiplied values stored in
the file. We then premultiply them again, so semi-transparent areas come out
too dark. Color management and surfaces that want unpremultiplied data
(NO_PREMULTIPLY_ALPHA) also got premultiplied data.

Now we unpremultiply when color management or the surface needs it, and
otherwise tell the surface pipe not to premultiply. The spec doesn't say what
color values larger than alpha mean; we clamp them to alpha so the result
doesn't depend on whether color management runs.

Original Revision: https://phabricator.services.mozilla.com/D331951

Attachment #9657985 - Flags: approval-mozilla-release?

Premultiplied and non-premultiplied versions of the same RGB and gray grids,
each compared against one PNG, plus the conformance suite's
alpha_premultiplied image compared against its reference PNG. cjxl
--premultiply=1 only marks the pixels as premultiplied, so the premultiplied
grids are encoded from PNGs that were premultiplied first.

Original Revision: https://phabricator.services.mozilla.com/D331952

Attachment #9657986 - Flags: approval-mozilla-release?

firefox-release Uplift Approval Request

  • User impact if declined/Reason for urgency: incorrect rendering of premultiplied alpha jpeg xl files
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: no
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: The change only affects JPEG XL images with premultiplied (associated) alpha, which are uncommon. For all other JPEG XL images the decoding path is unchanged. I've added good test coverage for premult files with new WPT reftests cover the RGB and grayscale cases and the JPEG XL conformance image.
  • String changes made/needed?: none
  • Is Android affected?: yes
Attachment #9657984 - Flags: approval-mozilla-release? → approval-mozilla-release+
Attachment #9657985 - Flags: approval-mozilla-release? → approval-mozilla-release+
Attachment #9657986 - Flags: approval-mozilla-release? → approval-mozilla-release+
QA Whiteboard: [qa-triage-done-c160/b159]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: