Skip to content

Start the JPEG quality search at 1, mozjpeg's lowest quality - #10

Open
lndgalante wants to merge 1 commit into
heydeer:mainfrom
lndgalante:jpeg-lowest-quality
Open

lndgalante wants to merge 1 commit into
heydeer:mainfrom
lndgalante:jpeg-lowest-quality

Conversation

@lndgalante

Copy link
Copy Markdown

Found while testing oxlint-plugin-slimdeer, which runs slimdeer's wasm build.

The bug

A JPEG of one flat color fails:

$ slimdeer flat.jpg
slimdeer: flat.jpg: no such JPEG quality or table: Options { quality: 0, quant_table: Some(2), full_chroma: false, progressive: true }

Four flat JPEGs made with macOS sips all fail this way at the automatic target, at main (eafae5e). The first also fails at --target 70 and 90, and works at 95.

image input with this change, automatic target
1200×400, #3366CC, made at quality 90 8,490 bytes quality 1, score 86.214, 1,742 bytes
800×200, white, quality 80 3,417 bytes quality 1, score 100, 820 bytes
1920×1080, #222222, quality 95 33,677 bytes quality 1, score 95.417, 6,453 bytes
256×256, #DC2626, quality 75 1,901 bytes quality 1, score 87.213, 527 bytes

The cause

quality::search covers 0–100, as WebP and AVIF do. mozjpeg takes 1–100, and vendor/mozjpeg/src/lib.rs refuses 0. When no quality falls short of the target, the search works its way down and its last rounds ask for quality 0, so compress_jpeg returns the encoder's error. One flat color is the easy way to get there, but any JPEG whose answer is in the low single digits can.

The fix

A search's files say the lowest quality their encoder takes: Tried::LOWEST, 0 unless they say otherwise, and 1 for JPEG's Attempt. The search's lower end starts one under it instead of at −1.

What else changes

For a search that worked before, one round. With 8 the lowest quality reaching the target and nothing short of it yet, the next qualities tried are 2, 4, 6 rather than 1, 3, 5 (I compared the old and new round for every hi from 1 to 100). Where scores rise with quality, that ends on the same answer. On flat colors they go up and down: a 160×120 flat #3366CC that worked before now lands on quality 2 instead of 4, both reaching its target. The pinned same_bytes_everywhere digests are unchanged.

One thing I left alone: at quality 1 the flat blue (50, 102, 204) comes out as (51, 97, 210), which scores 86.2 against an automatic target of 74.65. Whether a flat color should be held to a higher score is a separate question.

Tests

a_flat_color_goes_down_to_the_lowest_quality in tests/jpeg.rs: plain white at the automatic target is a hit at quality 1. It fails on main with the error above. cargo fmt --all --check, cargo clippy --release --all-targets -- -D warnings (also with each optional feature on its own) and cargo test --release pass on macOS arm64 with Rust 1.100.0.

🤖 Generated with Claude Code

The quality search JPEG shares with WebP and AVIF covers 0-100, but
mozjpeg takes 1-100 and its wrapper refuses 0. A JPEG on which nothing
falls short of the target (one flat color is enough) sends the search
to the bottom of the range, where it asked for quality 0 and
compress_jpeg failed: "no such JPEG quality or table: Options
{ quality: 0, .. }".

A search's files now say the lowest quality their encoder takes
(Tried::LOWEST, 0 unless they say otherwise), and JPEG's say 1.

A search that worked before tries the same qualities, except in one
spot: with 8 the lowest quality reaching the target and nothing short
of it yet, the next round is 2, 4, 6 rather than 1, 3, 5. That is the
same answer wherever scores rise with quality.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 18, 2026

Copy link
Copy Markdown

@lndgalante is attempting to deploy a commit to the Adastralab AI Team on Vercel.

A member of the Team first needs to authorize it.

@heydeer heydeer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review completed. No issues found.

Walkthrough

For safety, HeyDeer automatically approves only PRs opened by people with write access. Someone with write access can approve this one when ready.

ℹ️ About this review
  • Review summary: No new problems were found.
  • Risk level: medium. The PR changes the shared quality search's lower bound in src/quality.rs, which also drives WebP and AVIF, and it alters the probe order for existing JPEG searches, so a missed mistake would need a revert or a follow-up fix rather than a one-line rollback. It is not high because it touches no stored data, credits, security, or external contract.
  • Review depth: Standard
  • Trigger source: Automatic (PR opened)
  • View in HeyDeer · Config

HeyDeer reviews public repositories for free. Set it up for your open-source project →

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