Skip to content

feat(jpeg): a granular JPEG library, its WASM kit and a browser-decoder oracle - #38

Merged
benjamin-small merged 20 commits into
mainfrom
jpeg-library
Oct 16, 2026
Merged

benjamin-small merged 20 commits into
mainfrom
jpeg-library

Conversation

@benjamin-small

Copy link
Copy Markdown
Owner

Slice 1 of the JPEG compression lab. Spec: docs/superpowers/specs/2026-10-15-jpeg-lab-design.md. Plan: docs/superpowers/plans/2026-10-15-jpeg-lab-1-library.md. There are no UI changes; the engine lab and the stage pages come in Plans 2–4.

What's in it

  • crates/jpeg: a new crate with no dependencies.
    • Every baseline JPEG stage is a pure function with its inverse: color, sampling, blocks, zigzag, dct, quant, rle, bits, huffman, jfif and metrics.
    • codec composes them into a JFIF encoder, which keeps a full Trace of every intermediate, and a decoder.
    • Malformed or hostile input returns an error and never panics.
  • viz-core:
    • jpeg_images: generated gradient, text and bars test images.
    • jpeg_kit: 24 stateless wasm-bindgen functions over the crate's parts. They check lengths and ranges and return a JsError for bad input.
  • Browser oracle (tests/jpeg_oracle.rs): headless Chrome decodes our files, and the result must match our decoder to within 3 levels per channel (max) and 0.5 (mean). It covers 3 images × 2 sizes × 3 subsamplings × 3 qualities.

Tests

  • cargo test --all-features: jpeg 85, viz-core 266.
  • wasm-pack test --chrome --headless: 40 tests (33 existing, 6 kit, 1 oracle).
  • fmt is clean, and the new code adds no clippy warnings.

…an symbols, oversized kit round trips

- dequantize multiplies in f32 and the decoder's DC predictor saturates, so
  a crafted file can no longer overflow i32 in decode
- encode validates its image (shared Rgb8Image::validate) and stores the
  clamped quality in Trace.options
- Huffman tables with duplicate symbols are refused
- the kit refuses round trips over the 16-megapixel decode cap up front
- MAX_DECODE_PIXELS is documented as a pixel count
- missing-docs sweep over crates/jpeg (zero warnings)
- state preconditions (amplitude range, non-empty planes, component counts,
  write_segments table/nibble limits); fix zigzag, text_px and huffman docs
- README layout names error and image; spec says what the Trace stores
@benjamin-small
benjamin-small merged commit 77d90a7 into main Oct 16, 2026
6 checks passed
@benjamin-small
benjamin-small deleted the jpeg-library branch October 16, 2026 12:40
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