Skip to content

Number ICC profile chunks from 1 - #56

Open
Willyham wants to merge 1 commit into
ImageOptim:mainfrom
Willyham:fix-icc-chunk-numbering
Open

Willyham wants to merge 1 commit into
ImageOptim:mainfrom
Willyham:fix-icc-chunk-numbering

Conversation

@Willyham

Copy link
Copy Markdown

Compress::write_icc_profile numbers its APP2 chunks from 0 (enumerate() is zero-based), so a one-chunk profile is written as chunk 0 of 1. The ICC specification (ICC.1, Annex B.4, "Embedding ICC profiles in JPEG files") numbers them from 1, and libjpeg's own jpeg_write_icc_profile in the vendored source does the same (int cur_marker = 1; /* per spec, counting starts at 1 */, jcicc.c).

Readers that validate the sequence drop a profile that starts at 0. We hit this with zune-jpeg (the decoder behind the image crate), which returned no ICC profile at all for files this crate wrote, so they read as untagged. Lenient readers that ignore the sequence byte still find the profile, which is probably why this went unnoticed.

The fix is one line: current_marker + 1. The icc_profile test previously checked only that each chunk begins with ICC_PROFILE\0; it now also checks each chunk's sequence number and chunk count, and that the chunks reassemble to tests/test.icc. The new assertions fail on the current code (sequence number: left 0, right 1) and pass with the fix. cargo test passes; the clippy and rustfmt output is unchanged by this patch.

(An alternative would be to call ffi::jpeg_write_icc_profile directly, but that binding is behind mozjpeg-sys's icc_io feature, which this crate doesn't enable, so I kept the change minimal.)

🤖 Generated with Claude Code

write_icc_profile numbered its APP2 chunks from 0. ICC.1 Annex B.4 numbers them from 1, as
libjpeg's own jpeg_write_icc_profile does, and readers that validate the sequence (zune-jpeg,
through the image crate, for one) ignore a profile that starts at 0, so the file reads as
untagged. The icc_profile test now checks each chunk's sequence number and count and that the
chunks reassemble to the original profile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Willyham
Willyham marked this pull request as ready for review September 27, 2026 13:03
@Willyham

Willyham commented Oct 6, 2026 •

Copy link
Copy Markdown
Author

@lilith not sure if you're still maintaining this or not - if you are, can you take a look? Thanks

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