feat(sharp): AVIF encode (.avif) + quality-aware JPEG/AVIF encoding#5456
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (10)
📝 WalkthroughWalkthroughAdds AVIF output format to the ChangesSharp AVIF Encoding
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
- .avif(quality): AVIF output via image's `avif` feature (pure-Rust ravif/rav1e).
Encode-only — AVIF decode needs C dav1d, kept out for the static-binary model.
- encode_to_vec helper honours quality for JPEG (JpegEncoder::new_with_quality)
and AVIF (AvifEncoder::new_with_speed_quality); fixes the pre-existing gap where
.jpeg(q) quality was ignored by the default write_to path. toFile encodes by the
output path extension (so .toFile('x.avif') works) and honours quality.
Wired end-to-end (media.rs row, stdlib_ffi decl, entries.rs manifest, fluent
allowlist) + docs regen. Validated: .avif().toBuffer() -> AVIF ftyp/avif box;
.toFile('x.avif') -> valid AVIF (ISO Media); jpeg quality affects size; 9/9 tests.
Stacked on the EXIF/extend/trim/composite branch (#5455).
f14894c to
2331e24
Compare
PR 2 of 2 in the sharp batch. Stacked on #5455 (base is that branch, so this diff shows only the AVIF changes; it'll retarget to
mainonce #5455 merges).Pure-Rust, keeps the static-binary model.
.avif(quality)— AVIF outputVia the
imagecrate'saviffeature (the pure-Rustravif/rav1eencoder).sharp(input).resize(…).avif(50).toBuffer()yields a real AVIF Buffer (ftyp/avifbox);.toFile('out.avif')writes a valid AVIF and reportsformat: "avif".Encode-only — AVIF decode is intentionally out (it needs the C
dav1dlibrary, which would break the no-system-deps model).sharp('x.avif')input isn't supported.Quality now honoured for JPEG + AVIF
Encoding routes through a new
encode_to_vechelper usingJpegEncoder::new_with_quality/AvifEncoder::new_with_speed_quality. This also fixes a pre-existing gap:.jpeg(q)stored a quality the defaultwrite_topath ignored — now.jpeg(20)really is smaller than.jpeg(95).toFileencodes by the output path's extension (so.toFile('x.avif')works) and honours quality.Validation
.avif().toBuffer()→ AVIFftyp/avifbox;.toFile('x.avif')→file(1)reportsISO Media, AVIF Image.perry-ext-sharpunit suite 9/9; API docs regenerated (+avif).Size note
Enabling AVIF pulls
rav1e(a large pure-Rust AV1 encoder) into sharp binaries — a deliberate trade for AVIF output. SVG rasterization (resvg) was deferred to a separate opt-in PR (per discussion) to avoid bloating every sharp binary with its dependency tree.Animated WebP
Still out — the
imagecrate has no animated-WebP encoder; a separate codec path would be needed.Summary by CodeRabbit
New Features
Documentation