Skip to content

Allow JPEG XL saving to be compiled out, and add FREEIMAGE_CODEC_EXPORT - #247

Merged
danoli3 merged 2 commits into
feat/heif-disable-savefrom
feat/jxl-disable-save
Nov 1, 2026
Merged

danoli3 merged 2 commits into
feat/heif-disable-savefrom
feat/jxl-disable-save

Conversation

@danoli3

@danoli3 danoli3 commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #246. The base branch is feat/heif-disable-save, so this diff only shows the JPEG XL and master-switch changes. Once #246 merges, GitHub retargets this PR to master.

Options

Option Default OFF does
FREEIMAGE_CODEC_EXPORT ON Turns off saving for HEIF/AVIF and JPEG XL
FREEIMAGE_HEIF_EXPORT ON Read-only HEIF/AVIF (from #246)
FREEIMAGE_JXL_EXPORT ON Read-only JPEG XL (new)

When FREEIMAGE_CODEC_EXPORT is OFF, both per-codec switches are forced off. The per-codec compile definitions now come from one rule in the codec loop: FREEIMAGE_<codec>_EXPORT=0.

The master switch is named FREEIMAGE_CODEC_EXPORT, not FREEIMAGE_EXPORT, because FREEIMAGE_EXPORTS is already the dllexport define for shared Windows builds.

JPEG XL

  • PluginJPEGXL.cpp does not include jxl/encode.h or compile Save, Depth or Type, and save_proc and the export callbacks stay unset. FreeImage_FIFSupportsWriting(FIF_JPEGXL) returns FALSE and saving fails. Loading is unchanged.
  • libjxl is still built in full. It doesn't install its decoder-only jxl_dec library, and with nothing referencing JxlEncoder* the linker leaves the encoder out of FreeImage anyway (measured below). Linking jxl_dec from libjxl's build tree would only save build time.

Tests

  • In a read-only build, JpegXLTest checks that JPEG XL reports no writer or export depth and that saving fails. Because the lossless round trips can't encode, the header-only and truncated-input checks run on the checked-in lossy.jxl fixture instead. The lossy/progressive/upsampled fixture decodes still run in both modes.
  • The read-only bundled-codecs.yml jobs added in Allow HEIF/AVIF saving to be compiled out #246 now pass -DFREEIMAGE_CODEC_EXPORT=OFF, so they cover both codecs.

Verified locally (macOS arm64, shared library, bundled libheif and libjxl)

Same commit for every row; only the export options differ. All 16 ctest tests pass in every configuration.

Configuration libFreeImage.dylib Change
All saving on (default) 18,784,280 B (18.8 MB) —
FREEIMAGE_JXL_EXPORT=OFF 16,259,816 B (16.3 MB) −2.52 MB (−13.4%)
FREEIMAGE_HEIF_EXPORT=OFF 15,059,592 B (15.1 MB) −3.72 MB (−19.8%)
FREEIMAGE_CODEC_EXPORT=OFF 12,501,992 B (12.5 MB) −6.28 MB (−33.4%)

The two per-codec savings add up to roughly the combined one.

All on HEIF off JXL off Both off
JxlEncoder* symbols 133 133 0 0
libaom AV1 encoder (aom_codec_av1_cx) yes no yes no
Kvazaar HEVC encoder (kvz_api_get) yes no yes no
HEIF encoding test encodes rejects save encodes rejects save

With HEIF export off, the bundled libaom.a alone goes from 5.4 MB to 1.8 MB. One libheif symbol, heif_context_encode_image, remains in read-only builds. It's part of libheif's own public API and stays compiled into libheif, but FreeImage doesn't call it. Static, Windows and Linux sizes are not measured.

Add FREEIMAGE_JXL_EXPORT, on by default. When it is off, PluginJPEGXL.cpp
does not include jxl/encode.h or compile Save and the export-support
callbacks, so the plugin registers as read-only. Nothing then references
libjxl's encoder, and the linker leaves it out of FreeImage.

Add FREEIMAGE_CODEC_EXPORT, on by default, which turns off saving for
HEIF/AVIF and JPEG XL together. The per-codec compile definitions now
come from one rule in the codec loop.

JpegXLTest checks that a read-only build reports no writer and rejects
saving, and runs header-only and truncated loads on a fixture. The
read-only CI jobs now use FREEIMAGE_CODEC_EXPORT=OFF.
@danoli3

danoli3 commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

Size difference

Shared libFreeImage.3.19.29.dylib, macOS arm64, Release, bundled libheif 1.23.7 (libde265, Kvazaar, libaom 3.15.2) and libjxl 0.12.0. Same commit (7d6ee93) for every row; only the export options differ.

Configuration Bytes Size Change
All saving on (default) 18,784,280 18.8 MB —
FREEIMAGE_JXL_EXPORT=OFF 16,259,816 16.3 MB −2.52 MB (−13.4%)
FREEIMAGE_HEIF_EXPORT=OFF 15,059,592 15.1 MB −3.72 MB (−19.8%)
FREEIMAGE_CODEC_EXPORT=OFF 12,501,992 12.5 MB −6.28 MB (−33.4%)

The two per-codec savings add up to roughly the combined one, so they don't overlap.

What drops out:

All on HEIF off JXL off Both off
JxlEncoder* symbols 133 133 0 0
libaom AV1 encoder (aom_codec_av1_cx) yes no yes no
Kvazaar HEVC encoder (kvz_api_get) yes no yes no
  • HEIF: Kvazaar isn't built or linked, and libaom is built with CONFIG_AV1_ENCODER=0. The bundled libaom.a alone goes from 5.4 MB to 1.8 MB.
  • JPEG XL: libjxl is still built in full, so build time doesn't change. Nothing references its encoder, so the linker leaves it out.

All 16 ctest tests pass in every configuration. Static builds should save the same amount once a consumer links them, but I haven't measured that. Windows and Linux sizes aren't measured either; the read-only CI jobs check that those builds work, not how big they are.

Add read-only jobs for FREEIMAGE_HEIF_EXPORT=OFF alone (macOS shared)
and FREEIMAGE_JXL_EXPORT=OFF alone (Ubuntu shared), next to the existing
FREEIMAGE_CODEC_EXPORT=OFF jobs. Every include entry sets all three
export keys, because a new job gets only the keys it lists and an empty
value would turn that codec off as well.

The codec consumer now takes optional expected writer support for
HEIF/AVIF and JPEG XL. CI derives the expectation from the matrix
rather than from CMake, so a broken FREEIMAGE_CODEC_EXPORT override
fails the job. Without arguments the consumer behaves as before.
@danoli3
danoli3 added this pull request to stack #249 November 1, 2026 00:18
@danoli3
danoli3 merged commit 113295a into master Nov 1, 2026
93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant