Skip to content

#1482: lossy WebP export through libwebp (native builds), with a Lossless option - #1565

Merged
emmertex merged 7 commits into
mainfrom
claude/project-thread-e89cwz-webp
Nov 27, 2026
Merged

emmertex merged 7 commits into
mainfrom
claude/project-thread-e89cwz-webp

Conversation

@emmertex

Copy link
Copy Markdown
Owner

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

  • Encoder: libwebp (C, BSD-3-Clause) through the webp crate (MIT OR Apache-2.0) and libwebp-sys (MIT, vendors libwebp 1.3.1 with the CVE-2023-4863 fix), behind lcc-codecs' new webp-lossy feature (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 and XMP chunks. WEBP_LOSSY says whether this build has it.
  • ExportOptions.webp_lossless (webpLossless in commands and MCP, default false): WebP is lossy at the export Quality unless Lossless is ticked or the build has no libwebp.
  • Export dialog: a Lossless checkbox for WebP (greyed out, ticked, with a note on builds without libwebp) and the Quality slider for lossy WebP; the summary shows the quality.
  • NOTICE credits libwebp, libwebp-sys and webp; crates/codecs/LICENSE-libwebp.txt carries 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 warnings on lcc-codecs, lcc-engine, lcc-ui-egui and lcc-mcp (all targets); cargo check -p lcc-codecs --no-default-features builds (only pre-existing warnings).
  • Tests: webp_lossy_close_with_metadata (codecs round trip with ICC/EXIF/XMP and alpha), webp_exports_lossy_at_the_quality_or_lossless, all tests_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 deny not run here (not installed); licences are MIT, MIT OR Apache-2.0 and BSD-3-Clause, all on the allow-list.
  • Ran the app and looked: not done here (no display).

Merging

  • Overlap: none found.
  • Existing edits and libraries: saved export presets that use WebP now export lossy WebP at their Quality value (the new default). Tick Lossless in a preset to keep the old output. Called out in whats-new, the changelog and the manual.
  • Shared numbers taken: none.
  • Where it came from: libwebp's public API through the webp crate; the WebP container layout (VP8X/ICCP/ALPH/EXIF/XMP) from Google's WebP container specification.
  • New dependencies, unsafe, build scripts, network access, spawned processes, deleted files, CI or xtask gate changes: new dependencies webp 0.3 and libwebp-sys 0.9 (a C build script compiling the vendored libwebp; needs a C compiler on native CI runners). No unsafe in our crates.

Checklist

  • No new panic path in non-test code
  • New text goes through tr(), in all 17 fork catalogs
  • Manual updated (output/export-formats, platforms/web, docs/manual/import-export.md); whats-new and changelog entries added
  • New code has a caller
  • No new assets
  • Ready to merge

Generated by Claude Code

…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
@emmertex emmertex self-assigned this Nov 27, 2026
@emmertex
emmertex merged commit 5768380 into main Nov 27, 2026
10 of 11 checks passed
@emmertex
emmertex deleted the claude/project-thread-e89cwz-webp branch November 27, 2026 20:19
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.

Export: WebP is missing quality slider, only exports as lossless

2 participants