Repository navigation
Conversation
…-2.0 The forward DCT (scalar, `wide` and AVX2) was ported from libjpeg, which is why the crate carries the IJG license next to MIT/Apache-2.0 (vstroebel#15, vstroebel#34, vstroebel#37). This replaces all three with an implementation written from the transform's definition in ITU-T T.81 (A.3.3), and drops IJG from the crate's license. - One separable integer algorithm: a vertical then a horizontal 8-point pass, each an even half over x(n) + x(7-n) and a 4x4 odd half over x(n) - x(7-n), with constants round(2^13 * sqrt(2) * cos(m*pi/16)) and 3 extra fraction bits between the passes. Every intermediate fits in an i32. - The scalar, `wide` and AVX2 versions round at the same points and produce identical coefficients (tested). The output keeps the 8*F(u,v) scale the quantization tables expect. Accuracy against the exact transform over 50,000 blocks (a quarter at the sample extremes): worst error 0.937 (was 1.334); coefficients that are not the nearest integer 7.36% (was 13.66%). A 512x512 test image encodes with PSNR within 0.002 dB and size within 0.08% at qualities 50, 75 and 90. Speed is unchanged or better. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The forward DCT is the only part of the crate derived from libjpeg, and it is why the crate's license is
(MIT OR Apache-2.0) AND IJG(#15, #34, #37). Downstream packagers have had to account for the extra IJG terms (Fedora, Chromium). This PR replaces the scalar,wideand AVX2 forward DCTs with an implementation written from the transform's definition in ITU-T T.81 (A.3.3), and drops IJG from the crate's license.Approach
x(n) + x(7-n)and a 4×4 odd half overx(n) - x(7-n).round(2^13·√2·cos(mπ/16)), with 3 extra fraction bits between the passes.i32.wideversions. The AVX2 version does the same arithmetic on rows of eighti32lanes, with two 8×8 transposes. All three round at the same points, so their coefficients are identical; the tests check this.8·F(u,v)scale and layout are kept, so quantization and everything after it are unchanged.Results
Accuracy against the exact transform (
f64), over 50,000 blocks, a quarter of them at the sample extremes:Image quality on a 512×512 synthetic RGB image (gradients, texture, edges), encoded and then decoded with
jpeg-decoder:Speed: per-block DCT time in a release build, two interleaved runs on a busy machine, so treat it as indicative:
Tests
wideand AVX2 match scalar exactly.cargo testpasses with default features,simd,use_wideand--no-default-features.wasm32-unknown-unknownbuilds.Notes
widetofearless_simdfor better performance, lessunsafe#41 (thefearless_simdport) touches the same SIMD code. I'm happy to rebase onto it, or to port this transform tofearless_simdif Port SIMD fromwidetofearless_simdfor better performance, lessunsafe#41 lands first.criterion/benches/fdct.rsdoesn't compile onmain: it passes[i16; 64]where the function takesAlignedBlock. I left that out of this PR.🤖 Generated with Claude Code