diff --git a/benches/reductions.rs b/benches/reductions.rs index 30eebe17..9c43dd18 100644 --- a/benches/reductions.rs +++ b/benches/reductions.rs @@ -196,49 +196,9 @@ fn reductions_palette_full_reduction(b: &mut Bencher) { } #[bench] -fn reductions_alpha_black(b: &mut Bencher) { - let input = test::black_box(PathBuf::from("tests/files/rgba_8_reduce_alpha_black.png")); +fn reductions_alpha(b: &mut Bencher) { + let input = test::black_box(PathBuf::from("tests/files/rgba_8_reduce_alpha.png")); let png = PngData::new(&input, false).unwrap(); - b.iter(|| alpha::filtered_alpha_channel(&png.raw, AlphaOptim::Black)); -} - -#[bench] -fn reductions_alpha_white(b: &mut Bencher) { - let input = test::black_box(PathBuf::from("tests/files/rgba_8_reduce_alpha_white.png")); - let png = PngData::new(&input, false).unwrap(); - - b.iter(|| alpha::filtered_alpha_channel(&png.raw, AlphaOptim::White)); -} - -#[bench] -fn reductions_alpha_left(b: &mut Bencher) { - let input = test::black_box(PathBuf::from("tests/files/rgba_8_reduce_alpha_left.png")); - let png = PngData::new(&input, false).unwrap(); - - b.iter(|| alpha::filtered_alpha_channel(&png.raw, AlphaOptim::Left)); -} - -#[bench] -fn reductions_alpha_right(b: &mut Bencher) { - let input = test::black_box(PathBuf::from("tests/files/rgba_8_reduce_alpha_right.png")); - let png = PngData::new(&input, false).unwrap(); - - b.iter(|| alpha::filtered_alpha_channel(&png.raw, AlphaOptim::Right)); -} - -#[bench] -fn reductions_alpha_up(b: &mut Bencher) { - let input = test::black_box(PathBuf::from("tests/files/rgba_8_reduce_alpha_up.png")); - let png = PngData::new(&input, false).unwrap(); - - b.iter(|| alpha::filtered_alpha_channel(&png.raw, AlphaOptim::Up)); -} - -#[bench] -fn reductions_alpha_down(b: &mut Bencher) { - let input = test::black_box(PathBuf::from("tests/files/rgba_8_reduce_alpha_down.png")); - let png = PngData::new(&input, false).unwrap(); - - b.iter(|| alpha::filtered_alpha_channel(&png.raw, AlphaOptim::Down)); + b.iter(|| alpha::cleaned_alpha_channel(&png.raw)); } diff --git a/src/colors.rs b/src/colors.rs index 350f4424..e339092b 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -117,33 +117,3 @@ impl BitDepth { } } } - -#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash)] -/// Potential optimization methods for alpha channel -pub enum AlphaOptim { - NoOp, - Black, - White, - Up, - Right, - Down, - Left, -} - -impl fmt::Display for AlphaOptim { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{}", - match *self { - AlphaOptim::NoOp => "_", - AlphaOptim::Black => "B", - AlphaOptim::White => "W", - AlphaOptim::Up => "U", - AlphaOptim::Right => "R", - AlphaOptim::Down => "D", - AlphaOptim::Left => "L", - } - ) - } -} diff --git a/src/lib.rs b/src/lib.rs index 6d3bd5e5..a69a528f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,6 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::time::{Duration, Instant}; -pub use crate::colors::AlphaOptim; pub use crate::deflate::Deflaters; pub use crate::error::PngError; pub use crate::filters::RowFilter; @@ -159,8 +158,8 @@ pub struct Options { /// /// Default: `None` pub interlace: Option, - /// Alpha filtering strategies to use - pub alphas: IndexSet, + /// Whether to allow transparent pixels to be altered to improve compression. + pub optimize_alpha: bool, /// Whether to attempt bit depth reduction /// /// Default: `true` @@ -295,7 +294,7 @@ impl Default for Options { preserve_attrs: false, filter: indexset! {RowFilter::None, RowFilter::Sub, RowFilter::Entropy, RowFilter::Bigrams}, interlace: None, - alphas: IndexSet::new(), + optimize_alpha: false, bit_depth_reduction: true, color_type_reduction: true, palette_reduction: true, @@ -493,8 +492,8 @@ fn optimize_png( // If alpha optimization is enabled, first perform a black alpha reduction // This can allow reductions from alpha to indexed which may not have been possible otherwise - if !opts.alphas.is_empty() { - if let Some(reduced) = filtered_alpha_channel(&png.raw, AlphaOptim::Black) { + if opts.optimize_alpha { + if let Some(reduced) = cleaned_alpha_channel(&png.raw) { png.raw = Arc::new(reduced); } } @@ -531,8 +530,7 @@ fn optimize_png( if !filters.is_empty() { debug!("Evaluating: {} filters", filters.len()); - let eval = - Evaluator::new(deadline, filters, eval_compression, !opts.alphas.is_empty()); + let eval = Evaluator::new(deadline, filters, eval_compression, opts.optimize_alpha); if eval_filter.is_some() { eval.set_best_size(png.idat_data.len()); } @@ -598,7 +596,7 @@ fn optimize_png( if deadline.passed() { return None; } - let filtered = &png.raw.filter_image(trial.filter, !opts.alphas.is_empty()); + let filtered = &png.raw.filter_image(trial.filter, opts.optimize_alpha); perform_trial(filtered, opts, trial, &best_size) }); best.reduce_with(|i, j| { diff --git a/src/main.rs b/src/main.rs index 61eaed71..1b52eada 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,6 @@ use clap::{AppSettings, Arg, ArgMatches, Command}; use indexmap::IndexSet; use log::{error, warn}; -use oxipng::AlphaOptim; use oxipng::Deflaters; use oxipng::Headers; use oxipng::Options; @@ -438,10 +437,7 @@ fn parse_opts_into_struct( }; if matches.is_present("alpha") { - opts.alphas.insert(AlphaOptim::Black); - opts.alphas.insert(AlphaOptim::White); - opts.alphas.insert(AlphaOptim::Up); - opts.alphas.insert(AlphaOptim::Left); + opts.optimize_alpha = true; } if matches.is_present("fast") { diff --git a/src/reduction/alpha.rs b/src/reduction/alpha.rs index b5d17805..a1b8e68b 100644 --- a/src/reduction/alpha.rs +++ b/src/reduction/alpha.rs @@ -1,9 +1,9 @@ -use crate::colors::AlphaOptim; use crate::colors::ColorType; use crate::headers::IhdrData; use crate::png::PngImage; -pub fn filtered_alpha_channel(png: &PngImage, optim: AlphaOptim) -> Option { +/// Clean the alpha channel by setting the color of all fully transparent pixels to black +pub fn cleaned_alpha_channel(png: &PngImage) -> Option { let (bpc, bpp) = match png.ihdr.color_type { ColorType::RGBA | ColorType::GrayscaleAlpha => { let cpp = png.channels_per_pixel(); @@ -15,167 +15,25 @@ pub fn filtered_alpha_channel(png: &PngImage, optim: AlphaOptim) -> Option return None, - AlphaOptim::Black => reduced_alpha_to_black(png, bpc, bpp), - AlphaOptim::White => reduced_alpha_to_white(png, bpc, bpp), - AlphaOptim::Up => reduced_alpha_to_up(png, bpc, bpp), - AlphaOptim::Down => reduced_alpha_to_down(png, bpc, bpp), - AlphaOptim::Left => reduced_alpha_to_left(png, bpc, bpp), - AlphaOptim::Right => reduced_alpha_to_right(png, bpc, bpp), - }; - - Some(PngImage { - data: raw_data, - ihdr: png.ihdr, - palette: png.palette.clone(), - transparency_pixel: png.transparency_pixel.clone(), - aux_headers: png.aux_headers.clone(), - }) -} - -fn reduced_alpha_to_black(png: &PngImage, bpc: usize, bpp: usize) -> Vec { let mut reduced = Vec::with_capacity(png.data.len()); for line in png.scan_lines() { reduced.push(line.filter); for pixel in line.data.chunks(bpp) { - if pixel.iter().skip(bpp - bpc).fold(0, |sum, i| sum | i) == 0 { + if pixel.iter().skip(bpp - bpc).all(|b| *b == 0) { reduced.resize(reduced.len() + bpp, 0); } else { reduced.extend_from_slice(pixel); } } } - reduced -} -fn reduced_alpha_to_white(png: &PngImage, bpc: usize, bpp: usize) -> Vec { - let mut reduced = Vec::with_capacity(png.data.len()); - for line in png.scan_lines() { - reduced.push(line.filter); - for pixel in line.data.chunks(bpp) { - if pixel.iter().skip(bpp - bpc).fold(0, |sum, i| sum | i) == 0 { - reduced.resize(reduced.len() + bpp - bpc, 255); - reduced.resize(reduced.len() + bpc, 0); - } else { - reduced.extend_from_slice(pixel); - } - } - } - reduced -} - -fn reduced_alpha_to_up(png: &PngImage, bpc: usize, bpp: usize) -> Vec { - let mut reduced = Vec::with_capacity(png.data.len()); - let mut prev_line = Vec::new(); - let mut transparent = Vec::new(); - for line in png.scan_lines() { - if line.data.len() != prev_line.len() { - prev_line = vec![0; line.data.len()]; - transparent = vec![0; line.data.len()]; - } - reduced.push(line.filter); - let line_start = reduced.len(); - let mut line_transparent = true; - for (col, (pixel, prev_pixel)) in - line.data.chunks(bpp).zip(prev_line.chunks(bpp)).enumerate() - { - if pixel.iter().skip(bpp - bpc).fold(0, |sum, i| sum | i) == 0 { - // Copy the color values from the previous line - reduced.extend_from_slice(&prev_pixel[0..(bpp - bpc)]); - reduced.resize(reduced.len() + bpc, 0); - transparent[col] += 1; - } else { - if transparent[col] > 0 { - // Copy the current color values upwards in this column - let mut offset = line_start + col * bpp; - for _ in 0..transparent[col] { - offset -= prev_line.len() + 1; - reduced[offset..(offset + bpp - bpc)] - .copy_from_slice(&pixel[..(bpp - bpc)]); - } - } - transparent[col] = i32::MIN; // Prevent copying upwards again - reduced.extend_from_slice(pixel); - line_transparent = false; - } - } - if line_transparent { - // Zero out the line if it's fully transparent - reduced.truncate(line_start); - reduced.resize(line_start + prev_line.len(), 0); - transparent = vec![0; prev_line.len()]; - } - prev_line = reduced[line_start..].to_vec(); - } - reduced -} - -fn reduced_alpha_to_down(png: &PngImage, bpc: usize, bpp: usize) -> Vec { - let mut reduced = Vec::with_capacity(png.data.len()); - let mut prev_line = Vec::new(); - for line in png.scan_lines() { - if line.data.len() != prev_line.len() { - prev_line = vec![0; line.data.len()]; - } - reduced.push(line.filter); - let line_start = reduced.len(); - for (pixel, prev_pixel) in line.data.chunks(bpp).zip(prev_line.chunks(bpp)) { - if pixel.iter().skip(bpp - bpc).fold(0, |sum, i| sum | i) == 0 { - reduced.extend_from_slice(&prev_pixel[0..(bpp - bpc)]); - reduced.resize(reduced.len() + bpc, 0); - } else { - reduced.extend_from_slice(pixel); - } - } - prev_line = reduced[line_start..].to_vec(); - } - reduced -} - -fn reduced_alpha_to_left(png: &PngImage, bpc: usize, bpp: usize) -> Vec { - let mut reduced = Vec::with_capacity(png.data.len()); - for line in png.scan_lines() { - reduced.push(line.filter); - let mut prev_pixel = vec![0; bpp]; - let mut transparent = 0; - for pixel in line.data.chunks(bpp) { - if pixel.iter().skip(bpp - bpc).fold(0, |sum, i| sum | i) == 0 { - // Count number of consecutive transparent pixel bytes - transparent += bpp; - } else { - prev_pixel[..(bpp - bpc)].copy_from_slice(&pixel[..(bpp - bpc)]); - if transparent > 0 { - // Copy the current color values to preceding transparent pixels - reduced.extend(prev_pixel.iter().cycle().take(transparent)); - transparent = 0; - } - reduced.extend_from_slice(pixel); - } - } - if transparent > 0 { - reduced.extend(prev_pixel.iter().cycle().take(transparent)); - } - } - reduced -} - -fn reduced_alpha_to_right(png: &PngImage, bpc: usize, bpp: usize) -> Vec { - let mut reduced = Vec::with_capacity(png.data.len()); - for line in png.scan_lines() { - reduced.push(line.filter); - let mut prev_pixel = vec![0; bpp]; - for pixel in line.data.chunks(bpp) { - if pixel.iter().skip(bpp - bpc).fold(0, |sum, i| sum | i) == 0 { - reduced.extend_from_slice(&prev_pixel[0..(bpp - bpc)]); - reduced.resize(reduced.len() + bpc, 0); - } else { - prev_pixel[..(bpp - bpc)].copy_from_slice(&pixel[..(bpp - bpc)]); - reduced.extend_from_slice(pixel); - } - } - } - reduced + Some(PngImage { + data: reduced, + ihdr: png.ihdr, + palette: png.palette.clone(), + transparency_pixel: png.transparency_pixel.clone(), + aux_headers: png.aux_headers.clone(), + }) } #[must_use] diff --git a/src/reduction/mod.rs b/src/reduction/mod.rs index 1ff56f91..31d590b2 100644 --- a/src/reduction/mod.rs +++ b/src/reduction/mod.rs @@ -12,7 +12,7 @@ use crate::bit_depth::reduce_bit_depth_8_or_less; pub mod color; use crate::color::*; -pub(crate) use crate::alpha::filtered_alpha_channel; +pub(crate) use crate::alpha::cleaned_alpha_channel; pub(crate) use crate::bit_depth::reduce_bit_depth; /// Attempt to reduce the number of colors in the palette diff --git a/tests/files/grayscale_alpha_16_reduce_alpha_black.png b/tests/files/grayscale_alpha_16_reduce_alpha.png similarity index 100% rename from tests/files/grayscale_alpha_16_reduce_alpha_black.png rename to tests/files/grayscale_alpha_16_reduce_alpha.png diff --git a/tests/files/grayscale_alpha_16_reduce_alpha_down.png b/tests/files/grayscale_alpha_16_reduce_alpha_down.png deleted file mode 100644 index 78b72778..00000000 Binary files a/tests/files/grayscale_alpha_16_reduce_alpha_down.png and /dev/null differ diff --git a/tests/files/grayscale_alpha_16_reduce_alpha_left.png b/tests/files/grayscale_alpha_16_reduce_alpha_left.png deleted file mode 100644 index 78b72778..00000000 Binary files a/tests/files/grayscale_alpha_16_reduce_alpha_left.png and /dev/null differ diff --git a/tests/files/grayscale_alpha_16_reduce_alpha_right.png b/tests/files/grayscale_alpha_16_reduce_alpha_right.png deleted file mode 100644 index 78b72778..00000000 Binary files a/tests/files/grayscale_alpha_16_reduce_alpha_right.png and /dev/null differ diff --git a/tests/files/grayscale_alpha_16_reduce_alpha_up.png b/tests/files/grayscale_alpha_16_reduce_alpha_up.png deleted file mode 100644 index 78b72778..00000000 Binary files a/tests/files/grayscale_alpha_16_reduce_alpha_up.png and /dev/null differ diff --git a/tests/files/grayscale_alpha_16_reduce_alpha_white.png b/tests/files/grayscale_alpha_16_reduce_alpha_white.png deleted file mode 100644 index 78b72778..00000000 Binary files a/tests/files/grayscale_alpha_16_reduce_alpha_white.png and /dev/null differ diff --git a/tests/files/grayscale_alpha_8_reduce_alpha_black.png b/tests/files/grayscale_alpha_8_reduce_alpha.png similarity index 100% rename from tests/files/grayscale_alpha_8_reduce_alpha_black.png rename to tests/files/grayscale_alpha_8_reduce_alpha.png diff --git a/tests/files/grayscale_alpha_8_reduce_alpha_down.png b/tests/files/grayscale_alpha_8_reduce_alpha_down.png deleted file mode 100644 index c2e1d1ce..00000000 Binary files a/tests/files/grayscale_alpha_8_reduce_alpha_down.png and /dev/null differ diff --git a/tests/files/grayscale_alpha_8_reduce_alpha_left.png b/tests/files/grayscale_alpha_8_reduce_alpha_left.png deleted file mode 100644 index c2e1d1ce..00000000 Binary files a/tests/files/grayscale_alpha_8_reduce_alpha_left.png and /dev/null differ diff --git a/tests/files/grayscale_alpha_8_reduce_alpha_right.png b/tests/files/grayscale_alpha_8_reduce_alpha_right.png deleted file mode 100644 index c2e1d1ce..00000000 Binary files a/tests/files/grayscale_alpha_8_reduce_alpha_right.png and /dev/null differ diff --git a/tests/files/grayscale_alpha_8_reduce_alpha_up.png b/tests/files/grayscale_alpha_8_reduce_alpha_up.png deleted file mode 100644 index c2e1d1ce..00000000 Binary files a/tests/files/grayscale_alpha_8_reduce_alpha_up.png and /dev/null differ diff --git a/tests/files/grayscale_alpha_8_reduce_alpha_white.png b/tests/files/grayscale_alpha_8_reduce_alpha_white.png deleted file mode 100644 index c2e1d1ce..00000000 Binary files a/tests/files/grayscale_alpha_8_reduce_alpha_white.png and /dev/null differ diff --git a/tests/files/rgba_16_reduce_alpha_black.png b/tests/files/rgba_16_reduce_alpha.png similarity index 100% rename from tests/files/rgba_16_reduce_alpha_black.png rename to tests/files/rgba_16_reduce_alpha.png diff --git a/tests/files/rgba_16_reduce_alpha_down.png b/tests/files/rgba_16_reduce_alpha_down.png deleted file mode 100644 index 4792bf00..00000000 Binary files a/tests/files/rgba_16_reduce_alpha_down.png and /dev/null differ diff --git a/tests/files/rgba_16_reduce_alpha_left.png b/tests/files/rgba_16_reduce_alpha_left.png deleted file mode 100644 index 4792bf00..00000000 Binary files a/tests/files/rgba_16_reduce_alpha_left.png and /dev/null differ diff --git a/tests/files/rgba_16_reduce_alpha_right.png b/tests/files/rgba_16_reduce_alpha_right.png deleted file mode 100644 index 4792bf00..00000000 Binary files a/tests/files/rgba_16_reduce_alpha_right.png and /dev/null differ diff --git a/tests/files/rgba_16_reduce_alpha_up.png b/tests/files/rgba_16_reduce_alpha_up.png deleted file mode 100644 index 4792bf00..00000000 Binary files a/tests/files/rgba_16_reduce_alpha_up.png and /dev/null differ diff --git a/tests/files/rgba_16_reduce_alpha_white.png b/tests/files/rgba_16_reduce_alpha_white.png deleted file mode 100644 index 4792bf00..00000000 Binary files a/tests/files/rgba_16_reduce_alpha_white.png and /dev/null differ diff --git a/tests/files/rgba_8_reduce_alpha_black.png b/tests/files/rgba_8_reduce_alpha.png similarity index 100% rename from tests/files/rgba_8_reduce_alpha_black.png rename to tests/files/rgba_8_reduce_alpha.png diff --git a/tests/files/rgba_8_reduce_alpha_down.png b/tests/files/rgba_8_reduce_alpha_down.png deleted file mode 100644 index 22a5a059..00000000 Binary files a/tests/files/rgba_8_reduce_alpha_down.png and /dev/null differ diff --git a/tests/files/rgba_8_reduce_alpha_left.png b/tests/files/rgba_8_reduce_alpha_left.png deleted file mode 100644 index 22a5a059..00000000 Binary files a/tests/files/rgba_8_reduce_alpha_left.png and /dev/null differ diff --git a/tests/files/rgba_8_reduce_alpha_right.png b/tests/files/rgba_8_reduce_alpha_right.png deleted file mode 100644 index 22a5a059..00000000 Binary files a/tests/files/rgba_8_reduce_alpha_right.png and /dev/null differ diff --git a/tests/files/rgba_8_reduce_alpha_up.png b/tests/files/rgba_8_reduce_alpha_up.png deleted file mode 100644 index 22a5a059..00000000 Binary files a/tests/files/rgba_8_reduce_alpha_up.png and /dev/null differ diff --git a/tests/files/rgba_8_reduce_alpha_white.png b/tests/files/rgba_8_reduce_alpha_white.png deleted file mode 100644 index 22a5a059..00000000 Binary files a/tests/files/rgba_8_reduce_alpha_white.png and /dev/null differ diff --git a/tests/reduction.rs b/tests/reduction.rs index 2d084ad9..161ee51a 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -22,7 +22,7 @@ fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { fn test_it_converts( input: &str, - alpha: Option, + optimize_alpha: bool, color_type_in: ColorType, bit_depth_in: BitDepth, color_type_out: ColorType, @@ -30,9 +30,7 @@ fn test_it_converts( ) { let input = PathBuf::from(input); let (output, mut opts) = get_opts(&input); - if let Some(alpha) = alpha { - opts.alphas = [alpha].iter().cloned().collect(); - } + opts.optimize_alpha = optimize_alpha; let png = PngData::new(&input, opts.fix_errors).unwrap(); assert_eq!(png.raw.ihdr.color_type, color_type_in); @@ -64,7 +62,7 @@ fn test_it_converts( fn rgba_16_should_be_rgba_16() { test_it_converts( "tests/files/rgba_16_should_be_rgba_16.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::RGBA, @@ -76,7 +74,7 @@ fn rgba_16_should_be_rgba_16() { fn rgba_16_should_be_rgba_8() { test_it_converts( "tests/files/rgba_16_should_be_rgba_8.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::RGBA, @@ -88,7 +86,7 @@ fn rgba_16_should_be_rgba_8() { fn rgba_8_should_be_rgba_8() { test_it_converts( "tests/files/rgba_8_should_be_rgba_8.png", - None, + false, ColorType::RGBA, BitDepth::Eight, ColorType::RGBA, @@ -100,7 +98,7 @@ fn rgba_8_should_be_rgba_8() { fn rgba_16_should_be_rgb_16() { test_it_converts( "tests/files/rgba_16_should_be_rgb_16.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::RGB, @@ -112,7 +110,7 @@ fn rgba_16_should_be_rgb_16() { fn rgba_16_should_be_rgb_8() { test_it_converts( "tests/files/rgba_16_should_be_rgb_8.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::RGB, @@ -124,7 +122,7 @@ fn rgba_16_should_be_rgb_8() { fn rgba_8_should_be_rgb_8() { test_it_converts( "tests/files/rgba_8_should_be_rgb_8.png", - None, + false, ColorType::RGBA, BitDepth::Eight, ColorType::RGB, @@ -136,7 +134,7 @@ fn rgba_8_should_be_rgb_8() { fn rgba_16_should_be_palette_8() { test_it_converts( "tests/files/rgba_16_should_be_palette_8.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::Indexed, @@ -148,7 +146,7 @@ fn rgba_16_should_be_palette_8() { fn rgba_8_should_be_palette_8() { test_it_converts( "tests/files/rgba_8_should_be_palette_8.png", - None, + false, ColorType::RGBA, BitDepth::Eight, ColorType::Indexed, @@ -160,7 +158,7 @@ fn rgba_8_should_be_palette_8() { fn rgba_16_should_be_palette_4() { test_it_converts( "tests/files/rgba_16_should_be_palette_4.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::Indexed, @@ -172,7 +170,7 @@ fn rgba_16_should_be_palette_4() { fn rgba_8_should_be_palette_4() { test_it_converts( "tests/files/rgba_8_should_be_palette_4.png", - None, + false, ColorType::RGBA, BitDepth::Eight, ColorType::Indexed, @@ -184,7 +182,7 @@ fn rgba_8_should_be_palette_4() { fn rgba_16_should_be_palette_2() { test_it_converts( "tests/files/rgba_16_should_be_palette_2.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::Indexed, @@ -196,7 +194,7 @@ fn rgba_16_should_be_palette_2() { fn rgba_8_should_be_palette_2() { test_it_converts( "tests/files/rgba_8_should_be_palette_2.png", - None, + false, ColorType::RGBA, BitDepth::Eight, ColorType::Indexed, @@ -208,7 +206,7 @@ fn rgba_8_should_be_palette_2() { fn rgba_16_should_be_palette_1() { test_it_converts( "tests/files/rgba_16_should_be_palette_1.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::Indexed, @@ -220,7 +218,7 @@ fn rgba_16_should_be_palette_1() { fn rgba_8_should_be_palette_1() { test_it_converts( "tests/files/rgba_8_should_be_palette_1.png", - None, + false, ColorType::RGBA, BitDepth::Eight, ColorType::Indexed, @@ -232,7 +230,7 @@ fn rgba_8_should_be_palette_1() { fn rgba_16_should_be_grayscale_alpha_16() { test_it_converts( "tests/files/rgba_16_should_be_grayscale_alpha_16.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::GrayscaleAlpha, @@ -244,7 +242,7 @@ fn rgba_16_should_be_grayscale_alpha_16() { fn rgba_16_should_be_grayscale_alpha_8() { test_it_converts( "tests/files/rgba_16_should_be_grayscale_alpha_8.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::GrayscaleAlpha, @@ -256,7 +254,7 @@ fn rgba_16_should_be_grayscale_alpha_8() { fn rgba_8_should_be_grayscale_alpha_8() { test_it_converts( "tests/files/rgba_8_should_be_grayscale_alpha_8.png", - None, + false, ColorType::RGBA, BitDepth::Eight, ColorType::GrayscaleAlpha, @@ -268,7 +266,7 @@ fn rgba_8_should_be_grayscale_alpha_8() { fn rgba_16_should_be_grayscale_16() { test_it_converts( "tests/files/rgba_16_should_be_grayscale_16.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::Grayscale, @@ -280,7 +278,7 @@ fn rgba_16_should_be_grayscale_16() { fn rgba_16_should_be_grayscale_8() { test_it_converts( "tests/files/rgba_16_should_be_grayscale_8.png", - None, + false, ColorType::RGBA, BitDepth::Sixteen, ColorType::Grayscale, @@ -292,7 +290,7 @@ fn rgba_16_should_be_grayscale_8() { fn rgba_8_should_be_grayscale_8() { test_it_converts( "tests/files/rgba_8_should_be_grayscale_8.png", - None, + false, ColorType::RGBA, BitDepth::Eight, ColorType::Grayscale, @@ -304,7 +302,7 @@ fn rgba_8_should_be_grayscale_8() { fn rgb_16_should_be_rgb_16() { test_it_converts( "tests/files/rgb_16_should_be_rgb_16.png", - None, + false, ColorType::RGB, BitDepth::Sixteen, ColorType::RGB, @@ -316,7 +314,7 @@ fn rgb_16_should_be_rgb_16() { fn rgb_16_should_be_rgb_8() { test_it_converts( "tests/files/rgb_16_should_be_rgb_8.png", - None, + false, ColorType::RGB, BitDepth::Sixteen, ColorType::RGB, @@ -328,7 +326,7 @@ fn rgb_16_should_be_rgb_8() { fn rgb_8_should_be_rgb_8() { test_it_converts( "tests/files/rgb_8_should_be_rgb_8.png", - None, + false, ColorType::RGB, BitDepth::Eight, ColorType::RGB, @@ -340,7 +338,7 @@ fn rgb_8_should_be_rgb_8() { fn rgb_16_should_be_palette_8() { test_it_converts( "tests/files/rgb_16_should_be_palette_8.png", - None, + false, ColorType::RGB, BitDepth::Sixteen, ColorType::Indexed, @@ -352,7 +350,7 @@ fn rgb_16_should_be_palette_8() { fn rgb_8_should_be_palette_8() { test_it_converts( "tests/files/rgb_8_should_be_palette_8.png", - None, + false, ColorType::RGB, BitDepth::Eight, ColorType::Indexed, @@ -364,7 +362,7 @@ fn rgb_8_should_be_palette_8() { fn rgb_16_should_be_palette_4() { test_it_converts( "tests/files/rgb_16_should_be_palette_4.png", - None, + false, ColorType::RGB, BitDepth::Sixteen, ColorType::Indexed, @@ -376,7 +374,7 @@ fn rgb_16_should_be_palette_4() { fn rgb_8_should_be_palette_4() { test_it_converts( "tests/files/rgb_8_should_be_palette_4.png", - None, + false, ColorType::RGB, BitDepth::Eight, ColorType::Indexed, @@ -388,7 +386,7 @@ fn rgb_8_should_be_palette_4() { fn rgb_16_should_be_palette_2() { test_it_converts( "tests/files/rgb_16_should_be_palette_2.png", - None, + false, ColorType::RGB, BitDepth::Sixteen, ColorType::Indexed, @@ -400,7 +398,7 @@ fn rgb_16_should_be_palette_2() { fn rgb_8_should_be_palette_2() { test_it_converts( "tests/files/rgb_8_should_be_palette_2.png", - None, + false, ColorType::RGB, BitDepth::Eight, ColorType::Indexed, @@ -412,7 +410,7 @@ fn rgb_8_should_be_palette_2() { fn rgb_16_should_be_palette_1() { test_it_converts( "tests/files/rgb_16_should_be_palette_1.png", - None, + false, ColorType::RGB, BitDepth::Sixteen, ColorType::Indexed, @@ -424,7 +422,7 @@ fn rgb_16_should_be_palette_1() { fn rgb_8_should_be_palette_1() { test_it_converts( "tests/files/rgb_8_should_be_palette_1.png", - None, + false, ColorType::RGB, BitDepth::Eight, ColorType::Indexed, @@ -436,7 +434,7 @@ fn rgb_8_should_be_palette_1() { fn rgb_16_should_be_grayscale_16() { test_it_converts( "tests/files/rgb_16_should_be_grayscale_16.png", - None, + false, ColorType::RGB, BitDepth::Sixteen, ColorType::Grayscale, @@ -448,7 +446,7 @@ fn rgb_16_should_be_grayscale_16() { fn rgb_16_should_be_grayscale_8() { test_it_converts( "tests/files/rgb_16_should_be_grayscale_8.png", - None, + false, ColorType::RGB, BitDepth::Sixteen, ColorType::Grayscale, @@ -460,7 +458,7 @@ fn rgb_16_should_be_grayscale_8() { fn rgb_8_should_be_grayscale_8() { test_it_converts( "tests/files/rgb_8_should_be_grayscale_8.png", - None, + false, ColorType::RGB, BitDepth::Eight, ColorType::Grayscale, @@ -472,7 +470,7 @@ fn rgb_8_should_be_grayscale_8() { fn palette_8_should_be_palette_8() { test_it_converts( "tests/files/palette_8_should_be_palette_8.png", - None, + false, ColorType::Indexed, BitDepth::Eight, ColorType::Indexed, @@ -484,7 +482,7 @@ fn palette_8_should_be_palette_8() { fn palette_8_should_be_palette_4() { test_it_converts( "tests/files/palette_8_should_be_palette_4.png", - None, + false, ColorType::Indexed, BitDepth::Eight, ColorType::Indexed, @@ -496,7 +494,7 @@ fn palette_8_should_be_palette_4() { fn palette_4_should_be_palette_4() { test_it_converts( "tests/files/palette_4_should_be_palette_4.png", - None, + false, ColorType::Indexed, BitDepth::Four, ColorType::Indexed, @@ -508,7 +506,7 @@ fn palette_4_should_be_palette_4() { fn palette_8_should_be_palette_2() { test_it_converts( "tests/files/palette_8_should_be_palette_2.png", - None, + false, ColorType::Indexed, BitDepth::Eight, ColorType::Indexed, @@ -520,7 +518,7 @@ fn palette_8_should_be_palette_2() { fn palette_4_should_be_palette_2() { test_it_converts( "tests/files/palette_4_should_be_palette_2.png", - None, + false, ColorType::Indexed, BitDepth::Four, ColorType::Indexed, @@ -532,7 +530,7 @@ fn palette_4_should_be_palette_2() { fn palette_2_should_be_palette_2() { test_it_converts( "tests/files/palette_2_should_be_palette_2.png", - None, + false, ColorType::Indexed, BitDepth::Two, ColorType::Indexed, @@ -544,7 +542,7 @@ fn palette_2_should_be_palette_2() { fn palette_8_should_be_palette_1() { test_it_converts( "tests/files/palette_8_should_be_palette_1.png", - None, + false, ColorType::Indexed, BitDepth::Eight, ColorType::Indexed, @@ -556,7 +554,7 @@ fn palette_8_should_be_palette_1() { fn palette_4_should_be_palette_1() { test_it_converts( "tests/files/palette_4_should_be_palette_1.png", - None, + false, ColorType::Indexed, BitDepth::Four, ColorType::Indexed, @@ -568,7 +566,7 @@ fn palette_4_should_be_palette_1() { fn palette_2_should_be_palette_1() { test_it_converts( "tests/files/palette_2_should_be_palette_1.png", - None, + false, ColorType::Indexed, BitDepth::Two, ColorType::Indexed, @@ -580,7 +578,7 @@ fn palette_2_should_be_palette_1() { fn palette_1_should_be_palette_1() { test_it_converts( "tests/files/palette_1_should_be_palette_1.png", - None, + false, ColorType::Indexed, BitDepth::One, ColorType::Indexed, @@ -592,7 +590,7 @@ fn palette_1_should_be_palette_1() { fn grayscale_alpha_16_should_be_grayscale_alpha_16() { test_it_converts( "tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png", - None, + false, ColorType::GrayscaleAlpha, BitDepth::Sixteen, ColorType::GrayscaleAlpha, @@ -604,7 +602,7 @@ fn grayscale_alpha_16_should_be_grayscale_alpha_16() { fn grayscale_alpha_16_should_be_grayscale_alpha_8() { test_it_converts( "tests/files/grayscale_alpha_16_should_be_grayscale_alpha_8.png", - None, + false, ColorType::GrayscaleAlpha, BitDepth::Sixteen, ColorType::GrayscaleAlpha, @@ -616,7 +614,7 @@ fn grayscale_alpha_16_should_be_grayscale_alpha_8() { fn grayscale_alpha_8_should_be_grayscale_alpha_8() { test_it_converts( "tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png", - None, + false, ColorType::GrayscaleAlpha, BitDepth::Eight, ColorType::GrayscaleAlpha, @@ -628,7 +626,7 @@ fn grayscale_alpha_8_should_be_grayscale_alpha_8() { fn grayscale_alpha_16_should_be_grayscale_16() { test_it_converts( "tests/files/grayscale_alpha_16_should_be_grayscale_16.png", - None, + false, ColorType::GrayscaleAlpha, BitDepth::Sixteen, ColorType::Grayscale, @@ -640,7 +638,7 @@ fn grayscale_alpha_16_should_be_grayscale_16() { fn grayscale_alpha_16_should_be_grayscale_8() { test_it_converts( "tests/files/grayscale_alpha_16_should_be_grayscale_8.png", - None, + false, ColorType::GrayscaleAlpha, BitDepth::Sixteen, ColorType::Grayscale, @@ -652,7 +650,7 @@ fn grayscale_alpha_16_should_be_grayscale_8() { fn grayscale_alpha_8_should_be_grayscale_8() { test_it_converts( "tests/files/grayscale_alpha_8_should_be_grayscale_8.png", - None, + false, ColorType::GrayscaleAlpha, BitDepth::Eight, ColorType::Grayscale, @@ -664,7 +662,7 @@ fn grayscale_alpha_8_should_be_grayscale_8() { fn grayscale_16_should_be_grayscale_16() { test_it_converts( "tests/files/grayscale_16_should_be_grayscale_16.png", - None, + false, ColorType::Grayscale, BitDepth::Sixteen, ColorType::Grayscale, @@ -676,7 +674,7 @@ fn grayscale_16_should_be_grayscale_16() { fn grayscale_16_should_be_grayscale_8() { test_it_converts( "tests/files/grayscale_16_should_be_grayscale_8.png", - None, + false, ColorType::Grayscale, BitDepth::Sixteen, ColorType::Grayscale, @@ -688,7 +686,7 @@ fn grayscale_16_should_be_grayscale_8() { fn grayscale_8_should_be_grayscale_8() { test_it_converts( "tests/files/grayscale_8_should_be_grayscale_8.png", - None, + false, ColorType::Grayscale, BitDepth::Eight, ColorType::Grayscale, @@ -827,10 +825,10 @@ fn palette_should_be_reduced_with_both() { } #[test] -fn rgba_16_reduce_alpha_black() { +fn rgba_16_reduce_alpha() { test_it_converts( - "tests/files/rgba_16_reduce_alpha_black.png", - None, + "tests/files/rgba_16_reduce_alpha.png", + true, ColorType::RGBA, BitDepth::Sixteen, ColorType::RGBA, @@ -839,10 +837,10 @@ fn rgba_16_reduce_alpha_black() { } #[test] -fn rgba_8_reduce_alpha_black() { +fn rgba_8_reduce_alpha() { test_it_converts( - "tests/files/rgba_8_reduce_alpha_black.png", - None, + "tests/files/rgba_8_reduce_alpha.png", + true, ColorType::RGBA, BitDepth::Eight, ColorType::RGBA, @@ -851,10 +849,10 @@ fn rgba_8_reduce_alpha_black() { } #[test] -fn grayscale_alpha_16_reduce_alpha_black() { +fn grayscale_alpha_16_reduce_alpha() { test_it_converts( - "tests/files/grayscale_alpha_16_reduce_alpha_black.png", - None, + "tests/files/grayscale_alpha_16_reduce_alpha.png", + true, ColorType::GrayscaleAlpha, BitDepth::Sixteen, ColorType::GrayscaleAlpha, @@ -863,250 +861,10 @@ fn grayscale_alpha_16_reduce_alpha_black() { } #[test] -fn grayscale_alpha_8_reduce_alpha_black() { +fn grayscale_alpha_8_reduce_alpha() { test_it_converts( - "tests/files/grayscale_alpha_8_reduce_alpha_black.png", - None, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn rgba_16_reduce_alpha_white() { - test_it_converts( - "tests/files/rgba_16_reduce_alpha_white.png", - Some(AlphaOptim::White), - ColorType::RGBA, - BitDepth::Sixteen, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn rgba_8_reduce_alpha_white() { - test_it_converts( - "tests/files/rgba_8_reduce_alpha_white.png", - Some(AlphaOptim::White), - ColorType::RGBA, - BitDepth::Eight, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn grayscale_alpha_16_reduce_alpha_white() { - test_it_converts( - "tests/files/grayscale_alpha_16_reduce_alpha_white.png", - Some(AlphaOptim::White), - ColorType::GrayscaleAlpha, - BitDepth::Sixteen, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn grayscale_alpha_8_reduce_alpha_white() { - test_it_converts( - "tests/files/grayscale_alpha_8_reduce_alpha_white.png", - Some(AlphaOptim::White), - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn rgba_16_reduce_alpha_down() { - test_it_converts( - "tests/files/rgba_16_reduce_alpha_down.png", - Some(AlphaOptim::Down), - ColorType::RGBA, - BitDepth::Sixteen, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn rgba_8_reduce_alpha_down() { - test_it_converts( - "tests/files/rgba_8_reduce_alpha_down.png", - Some(AlphaOptim::Down), - ColorType::RGBA, - BitDepth::Eight, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn grayscale_alpha_16_reduce_alpha_down() { - test_it_converts( - "tests/files/grayscale_alpha_16_reduce_alpha_down.png", - Some(AlphaOptim::Down), - ColorType::GrayscaleAlpha, - BitDepth::Sixteen, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn grayscale_alpha_8_reduce_alpha_down() { - test_it_converts( - "tests/files/grayscale_alpha_8_reduce_alpha_down.png", - Some(AlphaOptim::Down), - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn rgba_16_reduce_alpha_up() { - test_it_converts( - "tests/files/rgba_16_reduce_alpha_up.png", - Some(AlphaOptim::Up), - ColorType::RGBA, - BitDepth::Sixteen, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn rgba_8_reduce_alpha_up() { - test_it_converts( - "tests/files/rgba_8_reduce_alpha_up.png", - Some(AlphaOptim::Up), - ColorType::RGBA, - BitDepth::Eight, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn grayscale_alpha_16_reduce_alpha_up() { - test_it_converts( - "tests/files/grayscale_alpha_16_reduce_alpha_up.png", - Some(AlphaOptim::Up), - ColorType::GrayscaleAlpha, - BitDepth::Sixteen, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn grayscale_alpha_8_reduce_alpha_up() { - test_it_converts( - "tests/files/grayscale_alpha_8_reduce_alpha_up.png", - Some(AlphaOptim::Up), - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn rgba_16_reduce_alpha_left() { - test_it_converts( - "tests/files/rgba_16_reduce_alpha_left.png", - Some(AlphaOptim::Left), - ColorType::RGBA, - BitDepth::Sixteen, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn rgba_8_reduce_alpha_left() { - test_it_converts( - "tests/files/rgba_8_reduce_alpha_left.png", - Some(AlphaOptim::Left), - ColorType::RGBA, - BitDepth::Eight, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn grayscale_alpha_16_reduce_alpha_left() { - test_it_converts( - "tests/files/grayscale_alpha_16_reduce_alpha_left.png", - Some(AlphaOptim::Left), - ColorType::GrayscaleAlpha, - BitDepth::Sixteen, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn grayscale_alpha_8_reduce_alpha_left() { - test_it_converts( - "tests/files/grayscale_alpha_8_reduce_alpha_left.png", - Some(AlphaOptim::Left), - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn rgba_16_reduce_alpha_right() { - test_it_converts( - "tests/files/rgba_16_reduce_alpha_right.png", - Some(AlphaOptim::Right), - ColorType::RGBA, - BitDepth::Sixteen, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn rgba_8_reduce_alpha_right() { - test_it_converts( - "tests/files/rgba_8_reduce_alpha_right.png", - Some(AlphaOptim::Right), - ColorType::RGBA, - BitDepth::Eight, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn grayscale_alpha_16_reduce_alpha_right() { - test_it_converts( - "tests/files/grayscale_alpha_16_reduce_alpha_right.png", - Some(AlphaOptim::Right), - ColorType::GrayscaleAlpha, - BitDepth::Sixteen, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn grayscale_alpha_8_reduce_alpha_right() { - test_it_converts( - "tests/files/grayscale_alpha_8_reduce_alpha_right.png", - Some(AlphaOptim::Right), + "tests/files/grayscale_alpha_8_reduce_alpha.png", + true, ColorType::GrayscaleAlpha, BitDepth::Eight, ColorType::GrayscaleAlpha, diff --git a/tests/regression.rs b/tests/regression.rs index 30797d3d..4bd5ed3f 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -308,103 +308,11 @@ fn issue_92_filter_5() { } #[test] -fn issue_113_white() { +fn issue_113() { let input = "tests/files/issue-113.png"; - let (_, mut opts) = get_opts(Path::new(input)); + let (output, mut opts) = get_opts(Path::new(input)); opts.interlace = Some(1); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Black); - let output = OutFile::Path(Some(Path::new(input).with_extension("-white-out.png"))); - test_it_converts( - input, - Some((output, opts)), - ColorType::RGBA, - BitDepth::Eight, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn issue_113_black() { - let input = "tests/files/issue-113.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.interlace = Some(1); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Black); - let output = OutFile::Path(Some(Path::new(input).with_extension("-black-out.png"))); - test_it_converts( - input, - Some((output, opts)), - ColorType::RGBA, - BitDepth::Eight, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn issue_113_right() { - let input = "tests/files/issue-113.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.interlace = Some(1); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Right); - let output = OutFile::Path(Some(Path::new(input).with_extension("-right-out.png"))); - test_it_converts( - input, - Some((output, opts)), - ColorType::RGBA, - BitDepth::Eight, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn issue_113_left() { - let input = "tests/files/issue-113.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.interlace = Some(1); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Left); - let output = OutFile::Path(Some(Path::new(input).with_extension("-left-out.png"))); - test_it_converts( - input, - Some((output, opts)), - ColorType::RGBA, - BitDepth::Eight, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn issue_113_up() { - let input = "tests/files/issue-113.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.interlace = Some(1); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Up); - let output = OutFile::Path(Some(Path::new(input).with_extension("-up-out.png"))); - test_it_converts( - input, - Some((output, opts)), - ColorType::RGBA, - BitDepth::Eight, - ColorType::GrayscaleAlpha, - BitDepth::Eight, - ); -} - -#[test] -fn issue_113_down() { - let input = "tests/files/issue-113.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.interlace = Some(1); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Down); - let output = OutFile::Path(Some(Path::new(input).with_extension("-down-out.png"))); + opts.optimize_alpha = true; test_it_converts( input, Some((output, opts)), @@ -429,97 +337,10 @@ fn issue_129() { } #[test] -fn issue_133_black() { +fn issue_133() { let input = "tests/files/issue-133.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Black); - let output = OutFile::Path(Some(Path::new(input).with_extension("-black-out.png"))); - test_it_converts( - input, - Some((output, opts)), - ColorType::RGBA, - BitDepth::Eight, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn issue_133_white() { - let input = "tests/files/issue-133.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::White); - let output = OutFile::Path(Some(Path::new(input).with_extension("-white-out.png"))); - test_it_converts( - input, - Some((output, opts)), - ColorType::RGBA, - BitDepth::Eight, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn issue_133_up() { - let input = "tests/files/issue-133.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Up); - let output = OutFile::Path(Some(Path::new(input).with_extension("-up-out.png"))); - test_it_converts( - input, - Some((output, opts)), - ColorType::RGBA, - BitDepth::Eight, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn issue_133_down() { - let input = "tests/files/issue-133.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Down); - let output = OutFile::Path(Some(Path::new(input).with_extension("-down-out.png"))); - test_it_converts( - input, - Some((output, opts)), - ColorType::RGBA, - BitDepth::Eight, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn issue_133_right() { - let input = "tests/files/issue-133.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Right); - let output = OutFile::Path(Some(Path::new(input).with_extension("-right-out.png"))); - test_it_converts( - input, - Some((output, opts)), - ColorType::RGBA, - BitDepth::Eight, - ColorType::RGBA, - BitDepth::Eight, - ); -} - -#[test] -fn issue_133_left() { - let input = "tests/files/issue-133.png"; - let (_, mut opts) = get_opts(Path::new(input)); - opts.alphas = IndexSet::new(); - opts.alphas.insert(AlphaOptim::Left); - let output = OutFile::Path(Some(Path::new(input).with_extension("-left-out.png"))); + let (output, mut opts) = get_opts(Path::new(input)); + opts.optimize_alpha = true; test_it_converts( input, Some((output, opts)),