kornelski / cavif-rs

AVIF image creator in pure Rust
https://lib.rs/cavif
BSD 3-Clause "New" or "Revised" License
570 stars 27 forks source link

Premultiplied alpha support is broken since v0.6.4 #48

Closed baumanj closed 2 years ago

baumanj commented 2 years ago

It looks like the flag was left out of the transition to the new args parser in a95b3c285db85696999bf7f7eefd051680491d30. The following addition is sufficient to get the code running again:

diff --git a/src/main.rs b/src/main.rs
index fd93c31..6199377 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -75,6 +75,9 @@ fn run() -> Result<(), BoxError> {
         .arg(Arg::with_name("dirty-alpha")
             .long("dirty-alpha")
             .help("Keep RGB data of fully-transparent pixels (makes larger, lower quality files)"))
+        .arg(Arg::with_name("premultiplied-alpha")
+            .long("premultiplied-alpha")
+            .help("Alternative compression mode that lowers quality of semi-transparent colors. Warning: at low qualities it may create black artifacts in transparent areas."))
         .arg(Arg::with_name("color")
             .long("color")
             .default_value("ycbcr")

However, the output it generates is invalid per ISOBMFF (ISO 14496-12:2020) § 8.11.12.1 since it requires "Zero or one" iref boxes and the output generated has 2.

kornelski commented 2 years ago

The dirty-alpha workaround I've developed turned out to work much better than I expected, so I've decided to drop support for premultiplied alpha instead.