Repository navigation
Conversation
With set_progressive_scans(n) for n in 34..=64, each AC scan was given
64 / (n - 1) = 1 coefficient, and the first scan started at
max(0, 1) = 1 but ended at 1. Its header was written with Ss=1, Se=0,
which decoders reject ("invalid spectral selection parameters"), so the
whole file failed to decode even though the setter documents 2..=64 as
valid.
The ranges are now computed once in ac_scan_ranges, which splits the 63
AC coefficients evenly over n - 1 scans: [1 + k*63/(n-1),
1 + (k+1)*63/(n-1)). The writer and the optimized Huffman counting both
use it, so they cannot drift apart. The default 4 scans now split at
1/22/43 instead of 1/21/42.
No behavior change; output is byte-identical across a grid of 768 color type / sampling / progressive / optimized / restart / averaging combinations. - RestartState replaces the restart-marker bookkeeping that was pasted into all four scan loops. - init_buffers<T> replaces the identical init_rows and init_block_buffers. - optimize_huffman_table iterates the same (start, end) ranges the scans are written with ([(1, 64)] for sequential, ac_scan_ranges for progressive) instead of two near-copies of the AC counting loop, and count_ac_symbols mirrors JfifWriter::write_ac_block. - get_num_bits is removed in favor of get_code, which it duplicated (its only test asserted the two agree).
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.
Builds on #47. The first commit here is #47's. Only 91f4489 is new. I'll rebase once #47 merges.
This is a refactor with no behavior change. Over a grid of 768 combinations (4 color types × 4 sampling factors × {sequential, 2, 4, 64 scans} × optimized on/off × restart {off, 1, 5} × nearest/average subsampling), the output bytes are identical to #47.
RestartStatereplaces the restart-marker bookkeeping (restarts_to_go,restarts &= 7, …) that was pasted into all four scan loops.before_mcuwrites the marker when one is due and returns whether the caller must reset its DC prediction.init_buffers<T>replacesinit_rowsandinit_block_buffers, which were identical apart from the element type.optimize_huffman_tableloops over the same(start, end)ranges the scans are written with:[(1, 64)]for sequential,ac_scan_rangesfor progressive. Before, it had two near-copies of the AC counting loop.count_ac_symbolsmirrorsJfifWriter::write_ac_block.get_num_bitsis removed in favor ofget_code, which it duplicated. Its only test checked that the two agree.encoder.rs: +98 / −216.Note: this conflicts with #42, which fixes the DC counting at restart markers inside
optimize_huffman_table. The refactor keeps today's behavior on purpose. If #42 lands first, I'll rebase and carry its reset over (n % restart_interval == 0 → prev_dc = 0in the DC loop).