This commit is contained in:
Andrew 2022-12-10 15:15:10 +13:00
parent 63e1aa33b0
commit aac1a86408
32 changed files with 95 additions and 734 deletions

View file

@ -196,49 +196,9 @@ fn reductions_palette_full_reduction(b: &mut Bencher) {
} }
#[bench] #[bench]
fn reductions_alpha_black(b: &mut Bencher) { fn reductions_alpha(b: &mut Bencher) {
let input = test::black_box(PathBuf::from("tests/files/rgba_8_reduce_alpha_black.png")); let input = test::black_box(PathBuf::from("tests/files/rgba_8_reduce_alpha.png"));
let png = PngData::new(&input, false).unwrap(); let png = PngData::new(&input, false).unwrap();
b.iter(|| alpha::filtered_alpha_channel(&png.raw, AlphaOptim::Black)); b.iter(|| alpha::cleaned_alpha_channel(&png.raw));
}
#[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));
} }

View file

@ -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",
}
)
}
}

View file

@ -42,7 +42,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; use std::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
pub use crate::colors::AlphaOptim;
pub use crate::deflate::Deflaters; pub use crate::deflate::Deflaters;
pub use crate::error::PngError; pub use crate::error::PngError;
pub use crate::filters::RowFilter; pub use crate::filters::RowFilter;
@ -159,8 +158,8 @@ pub struct Options {
/// ///
/// Default: `None` /// Default: `None`
pub interlace: Option<u8>, pub interlace: Option<u8>,
/// Alpha filtering strategies to use /// Whether to allow transparent pixels to be altered to improve compression.
pub alphas: IndexSet<colors::AlphaOptim>, pub optimize_alpha: bool,
/// Whether to attempt bit depth reduction /// Whether to attempt bit depth reduction
/// ///
/// Default: `true` /// Default: `true`
@ -295,7 +294,7 @@ impl Default for Options {
preserve_attrs: false, preserve_attrs: false,
filter: indexset! {RowFilter::None, RowFilter::Sub, RowFilter::Entropy, RowFilter::Bigrams}, filter: indexset! {RowFilter::None, RowFilter::Sub, RowFilter::Entropy, RowFilter::Bigrams},
interlace: None, interlace: None,
alphas: IndexSet::new(), optimize_alpha: false,
bit_depth_reduction: true, bit_depth_reduction: true,
color_type_reduction: true, color_type_reduction: true,
palette_reduction: true, palette_reduction: true,
@ -493,8 +492,8 @@ fn optimize_png(
// If alpha optimization is enabled, first perform a black alpha reduction // 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 // This can allow reductions from alpha to indexed which may not have been possible otherwise
if !opts.alphas.is_empty() { if opts.optimize_alpha {
if let Some(reduced) = filtered_alpha_channel(&png.raw, AlphaOptim::Black) { if let Some(reduced) = cleaned_alpha_channel(&png.raw) {
png.raw = Arc::new(reduced); png.raw = Arc::new(reduced);
} }
} }
@ -531,8 +530,7 @@ fn optimize_png(
if !filters.is_empty() { if !filters.is_empty() {
debug!("Evaluating: {} filters", filters.len()); debug!("Evaluating: {} filters", filters.len());
let eval = let eval = Evaluator::new(deadline, filters, eval_compression, opts.optimize_alpha);
Evaluator::new(deadline, filters, eval_compression, !opts.alphas.is_empty());
if eval_filter.is_some() { if eval_filter.is_some() {
eval.set_best_size(png.idat_data.len()); eval.set_best_size(png.idat_data.len());
} }
@ -598,7 +596,7 @@ fn optimize_png(
if deadline.passed() { if deadline.passed() {
return None; 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) perform_trial(filtered, opts, trial, &best_size)
}); });
best.reduce_with(|i, j| { best.reduce_with(|i, j| {

View file

@ -16,7 +16,6 @@
use clap::{AppSettings, Arg, ArgMatches, Command}; use clap::{AppSettings, Arg, ArgMatches, Command};
use indexmap::IndexSet; use indexmap::IndexSet;
use log::{error, warn}; use log::{error, warn};
use oxipng::AlphaOptim;
use oxipng::Deflaters; use oxipng::Deflaters;
use oxipng::Headers; use oxipng::Headers;
use oxipng::Options; use oxipng::Options;
@ -438,10 +437,7 @@ fn parse_opts_into_struct(
}; };
if matches.is_present("alpha") { if matches.is_present("alpha") {
opts.alphas.insert(AlphaOptim::Black); opts.optimize_alpha = true;
opts.alphas.insert(AlphaOptim::White);
opts.alphas.insert(AlphaOptim::Up);
opts.alphas.insert(AlphaOptim::Left);
} }
if matches.is_present("fast") { if matches.is_present("fast") {

View file

@ -1,9 +1,9 @@
use crate::colors::AlphaOptim;
use crate::colors::ColorType; use crate::colors::ColorType;
use crate::headers::IhdrData; use crate::headers::IhdrData;
use crate::png::PngImage; use crate::png::PngImage;
pub fn filtered_alpha_channel(png: &PngImage, optim: AlphaOptim) -> Option<PngImage> { /// Clean the alpha channel by setting the color of all fully transparent pixels to black
pub fn cleaned_alpha_channel(png: &PngImage) -> Option<PngImage> {
let (bpc, bpp) = match png.ihdr.color_type { let (bpc, bpp) = match png.ihdr.color_type {
ColorType::RGBA | ColorType::GrayscaleAlpha => { ColorType::RGBA | ColorType::GrayscaleAlpha => {
let cpp = png.channels_per_pixel(); let cpp = png.channels_per_pixel();
@ -15,167 +15,25 @@ pub fn filtered_alpha_channel(png: &PngImage, optim: AlphaOptim) -> Option<PngIm
} }
}; };
let raw_data = match optim {
AlphaOptim::NoOp => 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<u8> {
let mut reduced = Vec::with_capacity(png.data.len()); let mut reduced = Vec::with_capacity(png.data.len());
for line in png.scan_lines() { for line in png.scan_lines() {
reduced.push(line.filter); reduced.push(line.filter);
for pixel in line.data.chunks(bpp) { 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); reduced.resize(reduced.len() + bpp, 0);
} else { } else {
reduced.extend_from_slice(pixel); reduced.extend_from_slice(pixel);
} }
} }
} }
reduced
}
fn reduced_alpha_to_white(png: &PngImage, bpc: usize, bpp: usize) -> Vec<u8> { Some(PngImage {
let mut reduced = Vec::with_capacity(png.data.len()); data: reduced,
for line in png.scan_lines() { ihdr: png.ihdr,
reduced.push(line.filter); palette: png.palette.clone(),
for pixel in line.data.chunks(bpp) { transparency_pixel: png.transparency_pixel.clone(),
if pixel.iter().skip(bpp - bpc).fold(0, |sum, i| sum | i) == 0 { aux_headers: png.aux_headers.clone(),
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<u8> {
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<u8> {
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<u8> {
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<u8> {
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
} }
#[must_use] #[must_use]

View file

@ -12,7 +12,7 @@ use crate::bit_depth::reduce_bit_depth_8_or_less;
pub mod color; pub mod color;
use crate::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; pub(crate) use crate::bit_depth::reduce_bit_depth;
/// Attempt to reduce the number of colors in the palette /// Attempt to reduce the number of colors in the palette

View file

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

View file

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

View file

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

View file

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

View file

@ -22,7 +22,7 @@ fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
fn test_it_converts( fn test_it_converts(
input: &str, input: &str,
alpha: Option<AlphaOptim>, optimize_alpha: bool,
color_type_in: ColorType, color_type_in: ColorType,
bit_depth_in: BitDepth, bit_depth_in: BitDepth,
color_type_out: ColorType, color_type_out: ColorType,
@ -30,9 +30,7 @@ fn test_it_converts(
) { ) {
let input = PathBuf::from(input); let input = PathBuf::from(input);
let (output, mut opts) = get_opts(&input); let (output, mut opts) = get_opts(&input);
if let Some(alpha) = alpha { opts.optimize_alpha = optimize_alpha;
opts.alphas = [alpha].iter().cloned().collect();
}
let png = PngData::new(&input, opts.fix_errors).unwrap(); let png = PngData::new(&input, opts.fix_errors).unwrap();
assert_eq!(png.raw.ihdr.color_type, color_type_in); 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() { fn rgba_16_should_be_rgba_16() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_rgba_16.png", "tests/files/rgba_16_should_be_rgba_16.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, ColorType::RGBA,
@ -76,7 +74,7 @@ fn rgba_16_should_be_rgba_16() {
fn rgba_16_should_be_rgba_8() { fn rgba_16_should_be_rgba_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_rgba_8.png", "tests/files/rgba_16_should_be_rgba_8.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, ColorType::RGBA,
@ -88,7 +86,7 @@ fn rgba_16_should_be_rgba_8() {
fn rgba_8_should_be_rgba_8() { fn rgba_8_should_be_rgba_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_should_be_rgba_8.png", "tests/files/rgba_8_should_be_rgba_8.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, ColorType::RGBA,
@ -100,7 +98,7 @@ fn rgba_8_should_be_rgba_8() {
fn rgba_16_should_be_rgb_16() { fn rgba_16_should_be_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_rgb_16.png", "tests/files/rgba_16_should_be_rgb_16.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, ColorType::RGB,
@ -112,7 +110,7 @@ fn rgba_16_should_be_rgb_16() {
fn rgba_16_should_be_rgb_8() { fn rgba_16_should_be_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_rgb_8.png", "tests/files/rgba_16_should_be_rgb_8.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, ColorType::RGB,
@ -124,7 +122,7 @@ fn rgba_16_should_be_rgb_8() {
fn rgba_8_should_be_rgb_8() { fn rgba_8_should_be_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_should_be_rgb_8.png", "tests/files/rgba_8_should_be_rgb_8.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, ColorType::RGB,
@ -136,7 +134,7 @@ fn rgba_8_should_be_rgb_8() {
fn rgba_16_should_be_palette_8() { fn rgba_16_should_be_palette_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_palette_8.png", "tests/files/rgba_16_should_be_palette_8.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, ColorType::Indexed,
@ -148,7 +146,7 @@ fn rgba_16_should_be_palette_8() {
fn rgba_8_should_be_palette_8() { fn rgba_8_should_be_palette_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_should_be_palette_8.png", "tests/files/rgba_8_should_be_palette_8.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -160,7 +158,7 @@ fn rgba_8_should_be_palette_8() {
fn rgba_16_should_be_palette_4() { fn rgba_16_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_palette_4.png", "tests/files/rgba_16_should_be_palette_4.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, ColorType::Indexed,
@ -172,7 +170,7 @@ fn rgba_16_should_be_palette_4() {
fn rgba_8_should_be_palette_4() { fn rgba_8_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_should_be_palette_4.png", "tests/files/rgba_8_should_be_palette_4.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -184,7 +182,7 @@ fn rgba_8_should_be_palette_4() {
fn rgba_16_should_be_palette_2() { fn rgba_16_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_palette_2.png", "tests/files/rgba_16_should_be_palette_2.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, ColorType::Indexed,
@ -196,7 +194,7 @@ fn rgba_16_should_be_palette_2() {
fn rgba_8_should_be_palette_2() { fn rgba_8_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_should_be_palette_2.png", "tests/files/rgba_8_should_be_palette_2.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -208,7 +206,7 @@ fn rgba_8_should_be_palette_2() {
fn rgba_16_should_be_palette_1() { fn rgba_16_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_palette_1.png", "tests/files/rgba_16_should_be_palette_1.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, ColorType::Indexed,
@ -220,7 +218,7 @@ fn rgba_16_should_be_palette_1() {
fn rgba_8_should_be_palette_1() { fn rgba_8_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_should_be_palette_1.png", "tests/files/rgba_8_should_be_palette_1.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -232,7 +230,7 @@ fn rgba_8_should_be_palette_1() {
fn rgba_16_should_be_grayscale_alpha_16() { fn rgba_16_should_be_grayscale_alpha_16() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_grayscale_alpha_16.png", "tests/files/rgba_16_should_be_grayscale_alpha_16.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
@ -244,7 +242,7 @@ fn rgba_16_should_be_grayscale_alpha_16() {
fn rgba_16_should_be_grayscale_alpha_8() { fn rgba_16_should_be_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_grayscale_alpha_8.png", "tests/files/rgba_16_should_be_grayscale_alpha_8.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
@ -256,7 +254,7 @@ fn rgba_16_should_be_grayscale_alpha_8() {
fn rgba_8_should_be_grayscale_alpha_8() { fn rgba_8_should_be_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_should_be_grayscale_alpha_8.png", "tests/files/rgba_8_should_be_grayscale_alpha_8.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
@ -268,7 +266,7 @@ fn rgba_8_should_be_grayscale_alpha_8() {
fn rgba_16_should_be_grayscale_16() { fn rgba_16_should_be_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_grayscale_16.png", "tests/files/rgba_16_should_be_grayscale_16.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, ColorType::Grayscale,
@ -280,7 +278,7 @@ fn rgba_16_should_be_grayscale_16() {
fn rgba_16_should_be_grayscale_8() { fn rgba_16_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_grayscale_8.png", "tests/files/rgba_16_should_be_grayscale_8.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, ColorType::Grayscale,
@ -292,7 +290,7 @@ fn rgba_16_should_be_grayscale_8() {
fn rgba_8_should_be_grayscale_8() { fn rgba_8_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_should_be_grayscale_8.png", "tests/files/rgba_8_should_be_grayscale_8.png",
None, false,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, ColorType::Grayscale,
@ -304,7 +302,7 @@ fn rgba_8_should_be_grayscale_8() {
fn rgb_16_should_be_rgb_16() { fn rgb_16_should_be_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/rgb_16_should_be_rgb_16.png", "tests/files/rgb_16_should_be_rgb_16.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, ColorType::RGB,
@ -316,7 +314,7 @@ fn rgb_16_should_be_rgb_16() {
fn rgb_16_should_be_rgb_8() { fn rgb_16_should_be_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/rgb_16_should_be_rgb_8.png", "tests/files/rgb_16_should_be_rgb_8.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, ColorType::RGB,
@ -328,7 +326,7 @@ fn rgb_16_should_be_rgb_8() {
fn rgb_8_should_be_rgb_8() { fn rgb_8_should_be_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/rgb_8_should_be_rgb_8.png", "tests/files/rgb_8_should_be_rgb_8.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, ColorType::RGB,
@ -340,7 +338,7 @@ fn rgb_8_should_be_rgb_8() {
fn rgb_16_should_be_palette_8() { fn rgb_16_should_be_palette_8() {
test_it_converts( test_it_converts(
"tests/files/rgb_16_should_be_palette_8.png", "tests/files/rgb_16_should_be_palette_8.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, ColorType::Indexed,
@ -352,7 +350,7 @@ fn rgb_16_should_be_palette_8() {
fn rgb_8_should_be_palette_8() { fn rgb_8_should_be_palette_8() {
test_it_converts( test_it_converts(
"tests/files/rgb_8_should_be_palette_8.png", "tests/files/rgb_8_should_be_palette_8.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -364,7 +362,7 @@ fn rgb_8_should_be_palette_8() {
fn rgb_16_should_be_palette_4() { fn rgb_16_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/rgb_16_should_be_palette_4.png", "tests/files/rgb_16_should_be_palette_4.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, ColorType::Indexed,
@ -376,7 +374,7 @@ fn rgb_16_should_be_palette_4() {
fn rgb_8_should_be_palette_4() { fn rgb_8_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/rgb_8_should_be_palette_4.png", "tests/files/rgb_8_should_be_palette_4.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -388,7 +386,7 @@ fn rgb_8_should_be_palette_4() {
fn rgb_16_should_be_palette_2() { fn rgb_16_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/rgb_16_should_be_palette_2.png", "tests/files/rgb_16_should_be_palette_2.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, ColorType::Indexed,
@ -400,7 +398,7 @@ fn rgb_16_should_be_palette_2() {
fn rgb_8_should_be_palette_2() { fn rgb_8_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/rgb_8_should_be_palette_2.png", "tests/files/rgb_8_should_be_palette_2.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -412,7 +410,7 @@ fn rgb_8_should_be_palette_2() {
fn rgb_16_should_be_palette_1() { fn rgb_16_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/rgb_16_should_be_palette_1.png", "tests/files/rgb_16_should_be_palette_1.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, ColorType::Indexed,
@ -424,7 +422,7 @@ fn rgb_16_should_be_palette_1() {
fn rgb_8_should_be_palette_1() { fn rgb_8_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/rgb_8_should_be_palette_1.png", "tests/files/rgb_8_should_be_palette_1.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -436,7 +434,7 @@ fn rgb_8_should_be_palette_1() {
fn rgb_16_should_be_grayscale_16() { fn rgb_16_should_be_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/rgb_16_should_be_grayscale_16.png", "tests/files/rgb_16_should_be_grayscale_16.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, ColorType::Grayscale,
@ -448,7 +446,7 @@ fn rgb_16_should_be_grayscale_16() {
fn rgb_16_should_be_grayscale_8() { fn rgb_16_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/rgb_16_should_be_grayscale_8.png", "tests/files/rgb_16_should_be_grayscale_8.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, ColorType::Grayscale,
@ -460,7 +458,7 @@ fn rgb_16_should_be_grayscale_8() {
fn rgb_8_should_be_grayscale_8() { fn rgb_8_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/rgb_8_should_be_grayscale_8.png", "tests/files/rgb_8_should_be_grayscale_8.png",
None, false,
ColorType::RGB, ColorType::RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, ColorType::Grayscale,
@ -472,7 +470,7 @@ fn rgb_8_should_be_grayscale_8() {
fn palette_8_should_be_palette_8() { fn palette_8_should_be_palette_8() {
test_it_converts( test_it_converts(
"tests/files/palette_8_should_be_palette_8.png", "tests/files/palette_8_should_be_palette_8.png",
None, false,
ColorType::Indexed, ColorType::Indexed,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -484,7 +482,7 @@ fn palette_8_should_be_palette_8() {
fn palette_8_should_be_palette_4() { fn palette_8_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/palette_8_should_be_palette_4.png", "tests/files/palette_8_should_be_palette_4.png",
None, false,
ColorType::Indexed, ColorType::Indexed,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -496,7 +494,7 @@ fn palette_8_should_be_palette_4() {
fn palette_4_should_be_palette_4() { fn palette_4_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/palette_4_should_be_palette_4.png", "tests/files/palette_4_should_be_palette_4.png",
None, false,
ColorType::Indexed, ColorType::Indexed,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, ColorType::Indexed,
@ -508,7 +506,7 @@ fn palette_4_should_be_palette_4() {
fn palette_8_should_be_palette_2() { fn palette_8_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/palette_8_should_be_palette_2.png", "tests/files/palette_8_should_be_palette_2.png",
None, false,
ColorType::Indexed, ColorType::Indexed,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -520,7 +518,7 @@ fn palette_8_should_be_palette_2() {
fn palette_4_should_be_palette_2() { fn palette_4_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/palette_4_should_be_palette_2.png", "tests/files/palette_4_should_be_palette_2.png",
None, false,
ColorType::Indexed, ColorType::Indexed,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, ColorType::Indexed,
@ -532,7 +530,7 @@ fn palette_4_should_be_palette_2() {
fn palette_2_should_be_palette_2() { fn palette_2_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/palette_2_should_be_palette_2.png", "tests/files/palette_2_should_be_palette_2.png",
None, false,
ColorType::Indexed, ColorType::Indexed,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, ColorType::Indexed,
@ -544,7 +542,7 @@ fn palette_2_should_be_palette_2() {
fn palette_8_should_be_palette_1() { fn palette_8_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/palette_8_should_be_palette_1.png", "tests/files/palette_8_should_be_palette_1.png",
None, false,
ColorType::Indexed, ColorType::Indexed,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, ColorType::Indexed,
@ -556,7 +554,7 @@ fn palette_8_should_be_palette_1() {
fn palette_4_should_be_palette_1() { fn palette_4_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/palette_4_should_be_palette_1.png", "tests/files/palette_4_should_be_palette_1.png",
None, false,
ColorType::Indexed, ColorType::Indexed,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, ColorType::Indexed,
@ -568,7 +566,7 @@ fn palette_4_should_be_palette_1() {
fn palette_2_should_be_palette_1() { fn palette_2_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/palette_2_should_be_palette_1.png", "tests/files/palette_2_should_be_palette_1.png",
None, false,
ColorType::Indexed, ColorType::Indexed,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, ColorType::Indexed,
@ -580,7 +578,7 @@ fn palette_2_should_be_palette_1() {
fn palette_1_should_be_palette_1() { fn palette_1_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/palette_1_should_be_palette_1.png", "tests/files/palette_1_should_be_palette_1.png",
None, false,
ColorType::Indexed, ColorType::Indexed,
BitDepth::One, BitDepth::One,
ColorType::Indexed, ColorType::Indexed,
@ -592,7 +590,7 @@ fn palette_1_should_be_palette_1() {
fn grayscale_alpha_16_should_be_grayscale_alpha_16() { fn grayscale_alpha_16_should_be_grayscale_alpha_16() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png", "tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png",
None, false,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
@ -604,7 +602,7 @@ fn grayscale_alpha_16_should_be_grayscale_alpha_16() {
fn grayscale_alpha_16_should_be_grayscale_alpha_8() { fn grayscale_alpha_16_should_be_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_16_should_be_grayscale_alpha_8.png", "tests/files/grayscale_alpha_16_should_be_grayscale_alpha_8.png",
None, false,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
@ -616,7 +614,7 @@ fn grayscale_alpha_16_should_be_grayscale_alpha_8() {
fn grayscale_alpha_8_should_be_grayscale_alpha_8() { fn grayscale_alpha_8_should_be_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png", "tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png",
None, false,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
@ -628,7 +626,7 @@ fn grayscale_alpha_8_should_be_grayscale_alpha_8() {
fn grayscale_alpha_16_should_be_grayscale_16() { fn grayscale_alpha_16_should_be_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_16_should_be_grayscale_16.png", "tests/files/grayscale_alpha_16_should_be_grayscale_16.png",
None, false,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, ColorType::Grayscale,
@ -640,7 +638,7 @@ fn grayscale_alpha_16_should_be_grayscale_16() {
fn grayscale_alpha_16_should_be_grayscale_8() { fn grayscale_alpha_16_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_16_should_be_grayscale_8.png", "tests/files/grayscale_alpha_16_should_be_grayscale_8.png",
None, false,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, ColorType::Grayscale,
@ -652,7 +650,7 @@ fn grayscale_alpha_16_should_be_grayscale_8() {
fn grayscale_alpha_8_should_be_grayscale_8() { fn grayscale_alpha_8_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_8_should_be_grayscale_8.png", "tests/files/grayscale_alpha_8_should_be_grayscale_8.png",
None, false,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, ColorType::Grayscale,
@ -664,7 +662,7 @@ fn grayscale_alpha_8_should_be_grayscale_8() {
fn grayscale_16_should_be_grayscale_16() { fn grayscale_16_should_be_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/grayscale_16_should_be_grayscale_16.png", "tests/files/grayscale_16_should_be_grayscale_16.png",
None, false,
ColorType::Grayscale, ColorType::Grayscale,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, ColorType::Grayscale,
@ -676,7 +674,7 @@ fn grayscale_16_should_be_grayscale_16() {
fn grayscale_16_should_be_grayscale_8() { fn grayscale_16_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/grayscale_16_should_be_grayscale_8.png", "tests/files/grayscale_16_should_be_grayscale_8.png",
None, false,
ColorType::Grayscale, ColorType::Grayscale,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, ColorType::Grayscale,
@ -688,7 +686,7 @@ fn grayscale_16_should_be_grayscale_8() {
fn grayscale_8_should_be_grayscale_8() { fn grayscale_8_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/grayscale_8_should_be_grayscale_8.png", "tests/files/grayscale_8_should_be_grayscale_8.png",
None, false,
ColorType::Grayscale, ColorType::Grayscale,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, ColorType::Grayscale,
@ -827,10 +825,10 @@ fn palette_should_be_reduced_with_both() {
} }
#[test] #[test]
fn rgba_16_reduce_alpha_black() { fn rgba_16_reduce_alpha() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_reduce_alpha_black.png", "tests/files/rgba_16_reduce_alpha.png",
None, true,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, ColorType::RGBA,
@ -839,10 +837,10 @@ fn rgba_16_reduce_alpha_black() {
} }
#[test] #[test]
fn rgba_8_reduce_alpha_black() { fn rgba_8_reduce_alpha() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_reduce_alpha_black.png", "tests/files/rgba_8_reduce_alpha.png",
None, true,
ColorType::RGBA, ColorType::RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, ColorType::RGBA,
@ -851,10 +849,10 @@ fn rgba_8_reduce_alpha_black() {
} }
#[test] #[test]
fn grayscale_alpha_16_reduce_alpha_black() { fn grayscale_alpha_16_reduce_alpha() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_16_reduce_alpha_black.png", "tests/files/grayscale_alpha_16_reduce_alpha.png",
None, true,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
@ -863,250 +861,10 @@ fn grayscale_alpha_16_reduce_alpha_black() {
} }
#[test] #[test]
fn grayscale_alpha_8_reduce_alpha_black() { fn grayscale_alpha_8_reduce_alpha() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_8_reduce_alpha_black.png", "tests/files/grayscale_alpha_8_reduce_alpha.png",
None, true,
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),
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, ColorType::GrayscaleAlpha,

View file

@ -308,103 +308,11 @@ fn issue_92_filter_5() {
} }
#[test] #[test]
fn issue_113_white() { fn issue_113() {
let input = "tests/files/issue-113.png"; 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.interlace = Some(1);
opts.alphas = IndexSet::new(); opts.optimize_alpha = true;
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")));
test_it_converts( test_it_converts(
input, input,
Some((output, opts)), Some((output, opts)),
@ -429,97 +337,10 @@ fn issue_129() {
} }
#[test] #[test]
fn issue_133_black() { fn issue_133() {
let input = "tests/files/issue-133.png"; let input = "tests/files/issue-133.png";
let (_, mut opts) = get_opts(Path::new(input)); let (output, mut opts) = get_opts(Path::new(input));
opts.alphas = IndexSet::new(); opts.optimize_alpha = true;
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")));
test_it_converts( test_it_converts(
input, input,
Some((output, opts)), Some((output, opts)),