Repository navigation
#1482: lossy WebP export through libwebp (native builds), with a Lossless option - #1565
Merged
Merged
Conversation
…less option WebP exports are lossy at the export quality on desktop builds; a Lossless box keeps the old exact output. The encoder is libwebp (BSD-3-Clause, via the webp and libwebp-sys crates) behind lcc-codecs' webp-lossy feature; web and Android builds leave it out and stay lossless. Metadata (ICC, EXIF, XMP) is written into VP8X chunks around libwebp's bitstream. Sources: libwebp 1.3.1 (vendored by libwebp-sys 0.9.6), called through webp 0.3.1; no code copied. Manual: output/export-formats, platforms/web, docs/manual/import-export.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011VFDriGXJwNRKfVqKuo1hk
…ebP keeps alpha Manual: none, no user-visible change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011VFDriGXJwNRKfVqKuo1hk
…(the web build has no codecs crate) Manual: none, no user-visible change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011VFDriGXJwNRKfVqKuo1hk
# Conflicts: # NOTICE
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.
Requested by Andrew · project thread
Fixes #1482
Problem
WebP export was lossless only, so WebP files were far bigger than JPEGs of the same photo and the Quality slider did nothing for WebP. There is no production-quality pure-Rust lossy WebP encoder.
Change
webpcrate (MIT OR Apache-2.0) andlibwebp-sys(MIT, vendors libwebp 1.3.1 with the CVE-2023-4863 fix), behind lcc-codecs' newwebp-lossyfeature (on by default), only on targets other than wasm32 and Android, as AGENTS.md → "Rust first" allows (libwebp is listed there since POLICY: Rust first instead of pure Rust; black-box fits of Lightroom may ship as data #1548).lcc_codecs::encode_webp_lossy(img, quality, meta): grey expands to RGB, sizes validated (≤ 16383 px a side), libwebp encodes the bitstream, and our own RIFF writer wraps it in VP8X with ICCP, ALPH, EXIF andXMPchunks.WEBP_LOSSYsays whether this build has it.ExportOptions.webp_lossless(webpLosslessin commands and MCP, default false): WebP is lossy at the export Quality unless Lossless is ticked or the build has no libwebp.crates/codecs/LICENSE-libwebp.txtcarries libwebp's licence and patent grant.Not in this PR: Android and web stay lossless (libwebp isn't built there).
How it was checked
cargo fmt --check;cargo clippy -D warningson lcc-codecs, lcc-engine, lcc-ui-egui and lcc-mcp (all targets);cargo check -p lcc-codecs --no-default-featuresbuilds (only pre-existing warnings).webp_lossy_close_with_metadata(codecs round trip with ICC/EXIF/XMP and alpha),webp_exports_lossy_at_the_quality_or_lossless, alltests_export(43 passed; the exact-colour alpha tests now ask for lossless WebP and a lossy-alpha check was added), lcc-ui-egui export/dialog tests and--test it.cargo denynot run here (not installed); licences are MIT, MIT OR Apache-2.0 and BSD-3-Clause, all on the allow-list.Merging
webpcrate; the WebP container layout (VP8X/ICCP/ALPH/EXIF/XMP) from Google's WebP container specification.unsafe, build scripts, network access, spawned processes, deleted files, CI orxtaskgate changes: new dependencieswebp0.3 andlibwebp-sys0.9 (a C build script compiling the vendored libwebp; needs a C compiler on native CI runners). Nounsafein our crates.Checklist
tr(), in all 17 fork catalogsGenerated by Claude Code