Add ISO 21496-1 gain map support#504
Open
hjanuschka wants to merge 7 commits into
Open
Conversation
Implements parsing and serialization of gain maps in JPEG XL files. Gain maps allow images to store both SDR and HDR representations with metadata describing the conversion between them. The implementation: - Parses jhgm boxes from JXL containers - Provides GainMapBundle API matching libjxl's structure - Includes serialization/deserialization (binary compatible with libjxl) - Adds decoder.gain_map() method to access gain map data - Includes example and tests with sample file All tests passing, format verified against libjxl test vectors.
jonsneyers
reviewed
Nov 27, 2025
jonsneyers
reviewed
Nov 27, 2025
jonsneyers
reviewed
Nov 27, 2025
jonsneyers
reviewed
Nov 27, 2025
tirr-c
reviewed
Nov 27, 2025
veluca93
reviewed
Nov 28, 2025
- Fix ICC profile comment: clarify it uses JXL-specific compression, not Brotli - Fix gain_map comment: can be container, not just naked codestream - Use valid 12-byte minimal JXL codestream from mathiasbynens/small - Implement ColorEncoding parsing using BitReader/read_unconditional - Add try_reserve for gain_map_data to prevent DoS from large allocations - Use std::mem::take instead of clear() to actually free memory - Add warning log when gain map parsing fails
Benchmark @ 1361237 |
Galaxy4594
reviewed
Dec 21, 2025
- Fix comment: minimal JXL is 512x256 RGB, not 1x1 grayscale - Add warning log when color_encoding is set but serialization not implemented (requires BitWriter) - Remove conservative size estimate since color_encoding is always 0 - Update documentation to clarify the limitation
Contributor
|
@hjanuschka @veluca93 is there anything needed to before this PR can be merged? Would love to have this feature available. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
The decoder can now read gain maps from JXL files. Gain maps let images store both SDR and HDR versions with conversion metadata - pretty useful for cross-device HDR support.
Implementation
GainMapBundlestruct matching libjxl's APIjhgmboxes from containersTesting
All tests pass - verified against libjxl's test vectors to make sure the binary format matches exactly.
The only thing not implemented yet is ColorEncoding serialization (would need BitWriter), but that's rarely used since ICC profiles work fine.
Let me know if you'd like any changes!