Bug 496350 - JXL images losslessly transcoded from jpg fail to load
Summary: JXL images losslessly transcoded from jpg fail to load
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kimageformats
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 6.7.0
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Alex Merry
URL:
Keywords:
: 496360 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-11-16 15:49 UTC by Alastor Tenebris
Modified: 2025-01-05 10:54 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Image Converted From PNG To JPG TO JXL (1.53 MB, image/jxl)
2024-11-19 00:43 UTC, Alastor Tenebris
Details
Image Converted From PNG To JXL (1.55 MB, image/jxl)
2024-11-19 00:44 UTC, Alastor Tenebris
Details
Screnshot of opening the file. (538.40 KB, image/png)
2024-11-19 00:49 UTC, Alastor Tenebris
Details
Animated JXL that fails to decode with kimageformats 6.9.0 (3.52 KB, image/jxl)
2024-12-31 22:09 UTC, FreshlyToe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alastor Tenebris 2024-11-16 15:49:41 UTC
***
If you're not sure this is actually a bug, instead post about it at https://discuss.kde.org

If you're reporting a crash, attach a backtrace with debug symbols; see https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports

Please remove this comment after reading and before submitting - thanks!
***

SUMMARY
JXL images that have been losslessly transcoded from a jpg do not load, regardless of what QT6 based app is used.

STEPS TO REPRODUCE
1. Transcode a jpg into a jxl file losslessly
2. Open the file in any QT6 image viewer

OBSERVED RESULT
The image fails to load

EXPECTED RESULT
The image loads

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora 41 Kinoite
KDE Plasma Version: 6.2.3
KDE Frameworks Version: 6.8.0
Qt Version: 6.8

ADDITIONAL INFORMATION
I tested this with YACReader (Flatpak) and Gwenview (Fedora RPMs and Flatpak). To make sure this wasn't a bug with the jxl library, I tested the images that failed to load in Eye Of Gnome (Fedora RPMs), and the images did load.

I've also noticed that jxls losslessly converted from PNGs occasionally render as spirals in YACReader.

Running Gwenview (Flatpak) from command line opening a transcoded jpg gives the error: "Unexpected event 16384 instead of JXL_DEC_COLOR_ENCODING"
Comment 1 Albert Astals Cid 2024-11-18 14:56:40 UTC
Can you attach a sample image that shows this problem?
Comment 2 Alastor Tenebris 2024-11-19 00:43:02 UTC
Created attachment 175935 [details]
Image Converted From PNG To JPG TO JXL
Comment 3 Alastor Tenebris 2024-11-19 00:44:59 UTC
Created attachment 175936 [details]
Image Converted From PNG To JXL
Comment 4 Alastor Tenebris 2024-11-19 00:49:42 UTC
Created attachment 175937 [details]
Screnshot of opening the file.

The left side is Eye of Gnome, the right is Gwenview. Both were installed via Fedora 41's RPMs.
Comment 5 Albert Astals Cid 2024-11-19 21:13:22 UTC
Mirco, can you have a look?
Comment 6 Bug Janitor Service 2024-11-19 23:32:11 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kimageformats/-/merge_requests/278
Comment 7 Albert Astals Cid 2024-11-20 16:34:03 UTC
Git commit 92a1752c1f72543b6693ee5113b5769b38b5edf4 by Albert Astals Cid, on behalf of Mirco Miranda.
Committed on 20/11/2024 at 16:34.
Pushed by aacid into branch 'master'.

JXL: load error with some lossless file

When loading lossless JXL images without ICC profile, the parser failed.
The problem was caused by Boxes being enabled (MR !250). The parser should probably be revised to be more flexible.

A  +-    --    autotests/read/jxl/rgb_lossless_noprof.jxl
A  +-    --    autotests/read/jxl/rgb_lossless_noprof.png
M  +8    -5    src/imageformats/jxl.cpp
M  +1    -1    src/imageformats/jxl_p.h

https://invent.kde.org/frameworks/kimageformats/-/commit/92a1752c1f72543b6693ee5113b5769b38b5edf4
Comment 8 Mirco Miranda 2024-11-20 20:45:15 UTC
*** Bug 496360 has been marked as a duplicate of this bug. ***
Comment 9 FreshlyToe 2024-12-31 21:29:59 UTC
Some animated JXLs still fail to decode with kimageformats 6.9.0:

`Unexpected event 16384 instead of JXL_DEC_FRAME`

(16384 = JXL_DEC_BOX)

The code around https://invent.kde.org/frameworks/kimageformats/-/blob/92a1752c1f72543b6693ee5113b5769b38b5edf4/src/imageformats/jxl.cpp#L361 assumes that all the JXL_DEC_FRAME events are contiguous, but in fact they can interleave with JXL_DEC_BOX.

I don't have the example file to share at the moment, but the sequence of decoder events was as follows:

JXL_DEC_BOX
JXL_DEC_BOX
JXL_DEC_BOX
JXL_DEC_BASIC_INFO
JXL_DEC_COLOR_ENCODING
JXL_DEC_BOX
JXL_DEC_BOX
JXL_DEC_FRAME
JXL_DEC_BOX
JXL_DEC_FRAME

Notice the FRAME - BOX - FRAME sequence at the end, which confuses the `countALLFrames` function.
Comment 10 FreshlyToe 2024-12-31 22:09:20 UTC
Created attachment 177007 [details]
Animated JXL that fails to decode with kimageformats 6.9.0

Attached an example.
Comment 11 Bug Janitor Service 2025-01-02 06:55:20 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kimageformats/-/merge_requests/303
Comment 12 Mirco Miranda 2025-01-04 06:46:51 UTC
Git commit e6a0f8758b5fc62f569635df971e06b8ff9ac365 by Mirco Miranda.
Committed on 04/01/2025 at 06:46.
Pushed by mircomir into branch 'master'.

JXL: Fix missing checks for BOXES when parsing animation

Fix error when parsing something like:

```
JXL_DEC_BOX
JXL_DEC_BOX
JXL_DEC_BOX
JXL_DEC_BASIC_INFO
JXL_DEC_COLOR_ENCODING
JXL_DEC_BOX
JXL_DEC_BOX
JXL_DEC_FRAME
JXL_DEC_BOX
JXL_DEC_FRAME
```

A  +-    --    autotests/read/jxl/bug_496350.jxl
A  +-    --    autotests/read/jxl/bug_496350.png
M  +28   -10   src/imageformats/jxl.cpp
M  +1    -0    src/imageformats/jxl_p.h

https://invent.kde.org/frameworks/kimageformats/-/commit/e6a0f8758b5fc62f569635df971e06b8ff9ac365
Comment 13 Mirco Miranda 2025-01-05 10:54:40 UTC
Fixes in KF 6.11