Skip to content

feat: add Compress::set_dct_method - #54

Open
pashifika wants to merge 1 commit into
ImageOptim:mainfrom
pashifika:feat/compress-dct-method
Open

pashifika wants to merge 1 commit into
ImageOptim:mainfrom
pashifika:feat/compress-dct-method

Conversation

@pashifika

Copy link
Copy Markdown

Summary

Adds Compress::set_dct_method, mirroring the existing Decompress::dct_method.

libjpeg's dct_method field is read by both the compressor and the decompressor, and
cjpeg/djpeg both accept -dct islow|ifast|float. In this crate only the decompression
side is reachable: Compress keeps cinfo private and exposes no setter, so a caller that
wants to choose the encoder's DCT algorithm has no way to do it and silently gets the
library default.

Motivation

I am porting a JPEG recompression tool from Go to Rust. Its CLI has always exposed
--dct float|ifast|islow as the encoder DCT/IDCT method — the Go binding it used applied
the setting to both sides — so reproducing the flag needs this setter. Without it the flag
would have to be documented as decoder-only or dropped.

Changes

  • src/compress.rs: Compress::set_dct_method(&mut self, method: DctMethod), reusing the
    DctMethod enum already re-exported from lib.rs, so no new public type is introduced.
  • A test that encodes a small image with each of the three methods and asserts each
    produces output with an SOI marker.

Notes

  • No unsafe added: the method writes a plain field on cinfo, exactly as
    Decompress::dct_method does.
  • Naming follows the Compress convention (set_*) rather than Decompress's bare
    dct_method.
  • cargo test passes locally on aarch64-apple-darwin (18 lib tests, plus the integration
    and doc test targets).

libjpeg's `dct_method` is read by both the compressor and the decompressor,
and `cjpeg`/`djpeg` both accept `-dct`, but the setting was reachable only
through `Decompress::dct_method`. `Compress` keeps `cinfo` private, so a
caller that wants to pick the encoder's DCT algorithm has no way to do it.

Mirrors `Decompress::dct_method` exactly, reusing the existing `DctMethod`
enum, and adds a test that encodes with each of the three methods.
@pashifika
pashifika force-pushed the feat/compress-dct-method branch from cde150a to 77c0dd4 Compare August 30, 2026 00:56
pashifika added a commit to pashifika/comic-auto-resize that referenced this pull request Aug 30, 2026
The fork's two commits were authored under the wrong Git identity: the
scratch clone carried no repository-local `user.name`/`user.email` and
fell back to this machine's global configuration, which is not the
identity this project's OSS contributions belong under.

Both fork branches were rewritten with the correct identity and
force-pushed. The content is unchanged — `git diff` against the previous
heads is empty — so this is an attribution fix, not a code change.

- `[patch.crates-io]` rev is now 58f4e0ef91f2a0c477140734ef8b3fe5403befc3
- The upstream pull request's head is now
  77c0dd48bcba2d8ba97c823edfea6eadaf8673ea

Refs: ImageOptim/mozjpeg-rust#54
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