Skip to content

Commit

Permalink
Drop support for premultiplied alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Sep 25, 2021
1 parent aa19c15 commit 37847b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
11 changes: 4 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -149,7 +145,7 @@ fn run() -> Result<(), BoxError> {
};

let process = move |data: Vec<u8>, 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")),
Expand All @@ -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 {
Expand Down

0 comments on commit 37847b9

Please sign in to comment.