这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@alistair7
Copy link
Contributor

Description

I noticed there's no easy way to tell djxl not to fall back on decoding to pixels if JPEG reconstruction fails, so I added a --reconstruct_jpeg flag that means "losslessly reconstruct a JPEG or do nothing". Mutually exclusive with --pixels_to_jpeg and --jpeg_quality.

I was going to extend --pixels_to_jpeg to take a 1 or 0 argument, with 0 having this effect, but decided that was more confusing (and less backwards compatible).

$ ./djxl -v -h
JPEG XL decoder v0.12.0 bcb9a074 [_AVX2_,SSE4,SSE2] {GNU 13.3.0}
...
 -J, --reconstruct_jpeg
    Losslessly reconstruct a JPEG if possible, and fail otherwise.
...

New Behaviour

$ ./djxl good_jpeg.jxl reconstructed.jpg; echo $?
JPEG XL decoder v0.12.0 bcb9a074 [_AVX2_,SSE4,SSE2] {GNU 13.3.0}
Reconstructed to JPEG.
4094 x 2894, 17.721 MP/s, 5.186 MB/s, 8 threads. 
0

$ ./djxl bad_jpeg.jxl reconstructed.jpg; echo $?
JPEG XL decoder v0.12.0 bcb9a074 [_AVX2_,SSE4,SSE2] {GNU 13.3.0}
./lib/jxl/jpeg/jpeg_data.cc:121: JXL_FAILURE: Unknown app marker type 4
./lib/jxl/fields.cc:394: JXL_RETURN_IF_ERROR code=1: visitor.Visit(fields)
./lib/jxl/jpeg/dec_jpeg_data.cc:31: JXL_RETURN_IF_ERROR code=1: Bundle::Read(&br, jpeg_data)
Failed to decode image
Warning: could not decode losslessly to JPEG. Retrying with --pixels_to_jpeg...
Decoded to pixels.
4094 x 2894, 17.608 MP/s, 8 threads.
0

$ ./djxl --reconstruct_jpeg bad_jpeg.jxl reconstructed.jpg; echo $?
JPEG XL decoder v0.12.0 bcb9a074 [_AVX2_,SSE4,SSE2] {GNU 13.3.0}
./lib/jxl/jpeg/jpeg_data.cc:121: JXL_FAILURE: Unknown app marker type 4
./lib/jxl/fields.cc:394: JXL_RETURN_IF_ERROR code=1: visitor.Visit(fields)
./lib/jxl/jpeg/dec_jpeg_data.cc:31: JXL_RETURN_IF_ERROR code=1: Bundle::Read(&br, jpeg_data)
Failed to decode image
Error: could not decode losslessly to JPEG.
1

$ ./djxl good_jpeg.jxl pixels.png; echo $?
JPEG XL decoder v0.12.0 bcb9a074 [_AVX2_,SSE4,SSE2] {GNU 13.3.0}
Decoded to pixels.
4094 x 2894, 17.653 MP/s, 8 threads.
0

$ ./djxl --reconstruct_jpeg good_jpeg.jxl pixels.png; echo $?
JPEG XL decoder v0.12.0 bcb9a074 [_AVX2_,SSE4,SSE2] {GNU 13.3.0}
Error: --reconstruct_jpeg requires output format to be JPEG.
1

Pull Request Checklist

  • CLA Signed: Have you signed the Contributor License Agreement (individual or corporate, as appropriate)? Only contributions from signed contributors can be accepted.
  • Authors: Have you considered adding your name to the AUTHORS file?
  • Code Style: Have you ensured your code adheres to the project's coding style guidelines? You can use ./ci.sh lint for automatic code formatting.

Please review the full contributing guidelines for more details.

@eustas
Copy link
Contributor

eustas commented Oct 31, 2025

Hello. Thank you for your PR.

@eustas eustas added this pull request to the merge queue Nov 3, 2025
Merged via the queue into libjxl:main with commit 261599f Nov 3, 2025
96 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.

2 participants