From 37847b95bb81d4cf90e36b7fab2c7fbbcf95abe2 Mon Sep 17 00:00:00 2001 From: Kornel Date: Sat, 25 Sep 2021 18:13:42 +0100 Subject: [PATCH] Drop support for premultiplied alpha --- README.md | 3 +-- src/main.rs | 11 ++++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index aba3efd..d584f33 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,7 @@ cavif [OPTIONS] IMAGES... There are additional options that tweak AVIF color space. The defaults in `cavif` are chosen to be the best, so use these options only when you know it's necessary: - * `--premultiplied-alpha` — Alternative compression mode that lowers quality of semi-transparent colors. Warning: at low qualities it may create black artifacts in transparent areas. - * `--dirty-alpha` — Preserve RGB values of fully transparent pixels. By default irrelevant color of transparent pixels is cleared to avoid wasting space. + * `--dirty-alpha` — Preserve RGB values of fully transparent pixels (not recommended). By default irrelevant color of transparent pixels is cleared to avoid wasting space. * `--color=rgb` — Encode using RGB instead of YCbCr color space. Makes colors closer to lossless, but makes files larger. Use only if you need to avoid even smallest color shifts. diff --git a/src/main.rs b/src/main.rs index fd93c31..d549c0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,11 +99,7 @@ fn run() -> Result<(), BoxError> { let overwrite = args.is_present("overwrite"); let quiet = args.is_present("quiet"); let threads: usize = value_t!(args, "threads", usize)?; - let premultiplied_alpha = args.is_present("premultiplied-alpha"); let dirty_alpha = args.is_present("dirty-alpha"); - if dirty_alpha && premultiplied_alpha { - return Err("premultiplied alpha option makes dirty alpha impossible".into()); - } let color_space = match args.value_of("color").expect("default") { "ycbcr" => ColorSpace::YCbCr, @@ -149,7 +145,7 @@ fn run() -> Result<(), BoxError> { }; let process = move |data: Vec, input_path: &MaybePath| -> Result<(), BoxError> { - let mut img = load_rgba(&data, premultiplied_alpha)?; + let mut img = load_rgba(&data, false)?; drop(data); let out_path = match (&output, input_path) { (None, MaybePath::Path(input)) => MaybePath::Path(input.with_extension("avif")), @@ -170,12 +166,13 @@ fn run() -> Result<(), BoxError> { }, _ => {}, } - if !dirty_alpha && !premultiplied_alpha { + if !dirty_alpha { img = cleared_alpha(img); } let (out_data, color_size, alpha_size) = encode_rgba(img.as_ref(), &Config { quality, speed, - alpha_quality, premultiplied_alpha, + alpha_quality, + premultiplied_alpha: false, color_space, threads, })?; match out_path {