Repository navigation
Conversation
`QuantizationTableType::Custom` clamped values to 1..=2048, but the DQT segment is written with 8-bit precision, so `QuantizationTable::get` truncated larger values: 256 was written as 0 (an invalid table entry) and 300 as 44, while the encoder quantized with the real value. Decoders then dequantized with a different table than the one used to encode. Clamp to 1..=255, the range baseline JPEG allows for 8-bit samples, and document it on the variant.
This was referenced Nov 23, 2026
Merged
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.
QuantizationTableType::Customclamps values to1..=2048, but the DQT segment is written with 8-bit precision (QuantizationTable::getreturns(x >> 3) as u8). Values above 255 are therefore truncated in the file while the encoder quantizes with the real value:Decoders then dequantize with a different table than the one the encoder used.
Change
Customvalues to1..=255, the range baseline JPEG allows for 8-bit samples.QuantizationTableType::Custom.A 16-bit DQT (Pq = 1) would preserve larger values, but it is not valid in a baseline frame, so clamping looked like the right fix here.
Tests
test_custom_q_table_above_255encodes withCustom([v; 64])for v = 256, 300 and 2048, finds the DQT marker and checks that the first table value is 255. It fails onmain(256 is written as 0).cargo fmt --checkandcargo testpass with--features simd, with--features use_wide, and with--no-default-features --tests, also on 1.89.