tannerhelland / PhotoDemon

A free portable photo editor focused on pro-grade features, high performance, and maximum usability.
https://photodemon.org
Other
1.3k stars 192 forks source link

Overhauled - and greatly improved - JPEG XL support #501

Closed tannerhelland closed 8 months ago

tannerhelland commented 8 months ago

This horrifying project has taken me over a year to complete. I apologize for the delay.

JPEG XL support is very complicated. While I've worked on this overhaul, Google dropped JPEG XL support from Chrome, which won't help the format's broader adoption. Other software also struggles to use libjxl because of its poor error handling, and the library's API is still not stable.

I had originally written direct interfaces between PhotoDemon and libjxl. This was complicated because PhotoDemon's 32-bit nature (and support of extremely old Windows versions) requires a lot of manual work. Every new libjxl release would break my builds and even when they worked, things like malformed or large JPEG XL files could bring down all of PhotoDemon.

I have now rewritten PhotoDemon's libjxl interface using external processes. Separate libjxl executables are shelled as necessary, and they communicate with PhotoDemon over stdin/out/err (mostly stderr, because the libjxl designers are masochists who return standard output that way 🤦‍♂️ ). This means that crashes in libjxl no longer destroy PhotoDemon, and changes to the libjxl interface (or half-implemented features) no longer crash either. libjxl memory usage is wildly variable depending on settings, so this also adds a greater layer of protection because the standalone libjxl executables now have their own address space, separate from PD. (This greatly improves reliability when importing or exporting large images.)

I have also added support for animated JXL files, which is an entirely new level of suffering but a unique win for PD.

The downside of this approach is that it is slower and larger (file-size speaking) than the old implementation. Previews when exporting are more sluggish, especially on older or bogged-down systems, and animation previews during export can be particularly painful on large animations. These are all compromises I am willing to accept for greatly improved reliability.

Because this format is seeing minimal usage "in the wild", I don't intend to ship JPEG XL support in standard PD downloads. (It bloats the download considerably.) Instead, if you attempt to interact with the format (import or export), PhotoDemon now offers to download and auto-configure a portable copy of libjxl for you.

I do not want to work on JPEG XL support ever again, but if you encounter problems, let me know and I will investigate. Otherwise, I consider this feature pretty much complete.

ZPNRG commented 5 months ago

@tannerhelland Thank you for sharing this. I'm not sure how much I will continue to use PhotoDemon, but I certainly understand the decision to minimize effort and reduce priority in supporting JPEG XL if the format is that much of a pain to deal with. I have certainly seen how slow it it is to generate a file (depending on the settings used).