Fixup tests

This commit is contained in:
Andrew 2023-04-20 11:54:47 +12:00 committed by Josh Holmer
parent 91723507b4
commit 0669478181
7 changed files with 577 additions and 539 deletions

View file

@ -5,6 +5,12 @@ use std::fs::remove_file;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
const GRAYSCALE: u8 = 0;
const RGB: u8 = 2;
const INDEXED: u8 = 3;
const GRAYSCALE_ALPHA: u8 = 4;
const RGBA: u8 = 6;
fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
let mut options = oxipng::Options { let mut options = oxipng::Options {
force: true, force: true,
@ -23,9 +29,9 @@ fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
fn test_it_converts( fn test_it_converts(
input: &str, input: &str,
filter: RowFilter, filter: RowFilter,
color_type_in: ColorType, color_type_in: u8,
bit_depth_in: BitDepth, bit_depth_in: BitDepth,
color_type_out: ColorType, color_type_out: u8,
bit_depth_out: BitDepth, bit_depth_out: BitDepth,
) { ) {
let input = PathBuf::from(input); let input = PathBuf::from(input);
@ -34,7 +40,7 @@ fn test_it_converts(
let png = PngData::new(&input, opts.fix_errors).unwrap(); let png = PngData::new(&input, opts.fix_errors).unwrap();
opts.filter = IndexSet::new(); opts.filter = IndexSet::new();
opts.filter.insert(filter); opts.filter.insert(filter);
assert_eq!(png.raw.ihdr.color_type, color_type_in); assert_eq!(png.raw.ihdr.color_type.png_header_code(), color_type_in);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in);
match oxipng::optimize(&InFile::Path(input), &output, &opts) { match oxipng::optimize(&InFile::Path(input), &output, &opts) {
@ -52,12 +58,10 @@ fn test_it_converts(
} }
}; };
assert_eq!(png.raw.ihdr.color_type, color_type_out); assert_eq!(png.raw.ihdr.color_type.png_header_code(), color_type_out);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out);
if let Some(palette) = png.raw.palette.as_ref() { if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
assert!(palette.len() <= 1 << (png.raw.ihdr.bit_depth.as_u8() as usize)); assert!(palette.len() <= 1 << (png.raw.ihdr.bit_depth.as_u8() as usize));
} else {
assert_ne!(png.raw.ihdr.color_type, ColorType::Indexed);
} }
remove_file(output).ok(); remove_file(output).ok();
@ -68,9 +72,9 @@ fn filter_0_for_rgba_16() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_rgba_16.png", "tests/files/filter_0_for_rgba_16.png",
RowFilter::None, RowFilter::None,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -80,9 +84,9 @@ fn filter_1_for_rgba_16() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_rgba_16.png", "tests/files/filter_1_for_rgba_16.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -92,9 +96,9 @@ fn filter_2_for_rgba_16() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_rgba_16.png", "tests/files/filter_2_for_rgba_16.png",
RowFilter::Up, RowFilter::Up,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -104,9 +108,9 @@ fn filter_3_for_rgba_16() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_rgba_16.png", "tests/files/filter_3_for_rgba_16.png",
RowFilter::Average, RowFilter::Average,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -116,9 +120,9 @@ fn filter_4_for_rgba_16() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_rgba_16.png", "tests/files/filter_4_for_rgba_16.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -128,9 +132,9 @@ fn filter_5_for_rgba_16() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_rgba_16.png", "tests/files/filter_5_for_rgba_16.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -140,9 +144,9 @@ fn filter_0_for_rgba_8() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_rgba_8.png", "tests/files/filter_0_for_rgba_8.png",
RowFilter::None, RowFilter::None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -152,9 +156,9 @@ fn filter_1_for_rgba_8() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_rgba_8.png", "tests/files/filter_1_for_rgba_8.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -164,9 +168,9 @@ fn filter_2_for_rgba_8() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_rgba_8.png", "tests/files/filter_2_for_rgba_8.png",
RowFilter::Up, RowFilter::Up,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -176,9 +180,9 @@ fn filter_3_for_rgba_8() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_rgba_8.png", "tests/files/filter_3_for_rgba_8.png",
RowFilter::Average, RowFilter::Average,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -188,9 +192,9 @@ fn filter_4_for_rgba_8() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_rgba_8.png", "tests/files/filter_4_for_rgba_8.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -200,9 +204,9 @@ fn filter_5_for_rgba_8() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_rgba_8.png", "tests/files/filter_5_for_rgba_8.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -212,9 +216,9 @@ fn filter_0_for_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_rgb_16.png", "tests/files/filter_0_for_rgb_16.png",
RowFilter::None, RowFilter::None,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -224,9 +228,9 @@ fn filter_1_for_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_rgb_16.png", "tests/files/filter_1_for_rgb_16.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -236,9 +240,9 @@ fn filter_2_for_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_rgb_16.png", "tests/files/filter_2_for_rgb_16.png",
RowFilter::Up, RowFilter::Up,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -248,9 +252,9 @@ fn filter_3_for_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_rgb_16.png", "tests/files/filter_3_for_rgb_16.png",
RowFilter::Average, RowFilter::Average,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -260,9 +264,9 @@ fn filter_4_for_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_rgb_16.png", "tests/files/filter_4_for_rgb_16.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -272,9 +276,9 @@ fn filter_5_for_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_rgb_16.png", "tests/files/filter_5_for_rgb_16.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -284,9 +288,9 @@ fn filter_0_for_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_rgb_8.png", "tests/files/filter_0_for_rgb_8.png",
RowFilter::None, RowFilter::None,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -296,9 +300,9 @@ fn filter_1_for_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_rgb_8.png", "tests/files/filter_1_for_rgb_8.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -308,9 +312,9 @@ fn filter_2_for_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_rgb_8.png", "tests/files/filter_2_for_rgb_8.png",
RowFilter::Up, RowFilter::Up,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -320,9 +324,9 @@ fn filter_3_for_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_rgb_8.png", "tests/files/filter_3_for_rgb_8.png",
RowFilter::Average, RowFilter::Average,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -332,9 +336,9 @@ fn filter_4_for_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_rgb_8.png", "tests/files/filter_4_for_rgb_8.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -344,9 +348,9 @@ fn filter_5_for_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_rgb_8.png", "tests/files/filter_5_for_rgb_8.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -356,9 +360,9 @@ fn filter_0_for_grayscale_alpha_16() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_grayscale_alpha_16.png", "tests/files/filter_0_for_grayscale_alpha_16.png",
RowFilter::None, RowFilter::None,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -368,9 +372,9 @@ fn filter_1_for_grayscale_alpha_16() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_grayscale_alpha_16.png", "tests/files/filter_1_for_grayscale_alpha_16.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -380,9 +384,9 @@ fn filter_2_for_grayscale_alpha_16() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_grayscale_alpha_16.png", "tests/files/filter_2_for_grayscale_alpha_16.png",
RowFilter::Up, RowFilter::Up,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -392,9 +396,9 @@ fn filter_3_for_grayscale_alpha_16() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_grayscale_alpha_16.png", "tests/files/filter_3_for_grayscale_alpha_16.png",
RowFilter::Average, RowFilter::Average,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -404,9 +408,9 @@ fn filter_4_for_grayscale_alpha_16() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_grayscale_alpha_16.png", "tests/files/filter_4_for_grayscale_alpha_16.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -416,9 +420,9 @@ fn filter_5_for_grayscale_alpha_16() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_grayscale_alpha_16.png", "tests/files/filter_5_for_grayscale_alpha_16.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -428,9 +432,9 @@ fn filter_0_for_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_grayscale_alpha_8.png", "tests/files/filter_0_for_grayscale_alpha_8.png",
RowFilter::None, RowFilter::None,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -440,9 +444,9 @@ fn filter_1_for_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_grayscale_alpha_8.png", "tests/files/filter_1_for_grayscale_alpha_8.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -452,9 +456,9 @@ fn filter_2_for_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_grayscale_alpha_8.png", "tests/files/filter_2_for_grayscale_alpha_8.png",
RowFilter::Up, RowFilter::Up,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -464,9 +468,9 @@ fn filter_3_for_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_grayscale_alpha_8.png", "tests/files/filter_3_for_grayscale_alpha_8.png",
RowFilter::Average, RowFilter::Average,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -476,9 +480,9 @@ fn filter_4_for_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_grayscale_alpha_8.png", "tests/files/filter_4_for_grayscale_alpha_8.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -488,9 +492,9 @@ fn filter_5_for_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_grayscale_alpha_8.png", "tests/files/filter_5_for_grayscale_alpha_8.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -500,9 +504,9 @@ fn filter_0_for_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_grayscale_16.png", "tests/files/filter_0_for_grayscale_16.png",
RowFilter::None, RowFilter::None,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -512,9 +516,9 @@ fn filter_1_for_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_grayscale_16.png", "tests/files/filter_1_for_grayscale_16.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -524,9 +528,9 @@ fn filter_2_for_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_grayscale_16.png", "tests/files/filter_2_for_grayscale_16.png",
RowFilter::Up, RowFilter::Up,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -536,9 +540,9 @@ fn filter_3_for_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_grayscale_16.png", "tests/files/filter_3_for_grayscale_16.png",
RowFilter::Average, RowFilter::Average,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -548,9 +552,9 @@ fn filter_4_for_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_grayscale_16.png", "tests/files/filter_4_for_grayscale_16.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -560,9 +564,9 @@ fn filter_5_for_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_grayscale_16.png", "tests/files/filter_5_for_grayscale_16.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -572,9 +576,9 @@ fn filter_0_for_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_grayscale_8.png", "tests/files/filter_0_for_grayscale_8.png",
RowFilter::None, RowFilter::None,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -584,9 +588,9 @@ fn filter_1_for_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_grayscale_8.png", "tests/files/filter_1_for_grayscale_8.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -596,9 +600,9 @@ fn filter_2_for_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_grayscale_8.png", "tests/files/filter_2_for_grayscale_8.png",
RowFilter::Up, RowFilter::Up,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -608,9 +612,9 @@ fn filter_3_for_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_grayscale_8.png", "tests/files/filter_3_for_grayscale_8.png",
RowFilter::Average, RowFilter::Average,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -620,9 +624,9 @@ fn filter_4_for_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_grayscale_8.png", "tests/files/filter_4_for_grayscale_8.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -632,9 +636,9 @@ fn filter_5_for_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_grayscale_8.png", "tests/files/filter_5_for_grayscale_8.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -644,9 +648,9 @@ fn filter_0_for_palette_4() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_palette_4.png", "tests/files/filter_0_for_palette_4.png",
RowFilter::None, RowFilter::None,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -656,9 +660,9 @@ fn filter_1_for_palette_4() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_palette_4.png", "tests/files/filter_1_for_palette_4.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -668,9 +672,9 @@ fn filter_2_for_palette_4() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_palette_4.png", "tests/files/filter_2_for_palette_4.png",
RowFilter::Up, RowFilter::Up,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -680,9 +684,9 @@ fn filter_3_for_palette_4() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_palette_4.png", "tests/files/filter_3_for_palette_4.png",
RowFilter::Average, RowFilter::Average,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -692,9 +696,9 @@ fn filter_4_for_palette_4() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_palette_4.png", "tests/files/filter_4_for_palette_4.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -704,9 +708,9 @@ fn filter_5_for_palette_4() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_palette_4.png", "tests/files/filter_5_for_palette_4.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -716,9 +720,9 @@ fn filter_0_for_palette_2() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_palette_2.png", "tests/files/filter_0_for_palette_2.png",
RowFilter::None, RowFilter::None,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -728,9 +732,9 @@ fn filter_1_for_palette_2() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_palette_2.png", "tests/files/filter_1_for_palette_2.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -740,9 +744,9 @@ fn filter_2_for_palette_2() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_palette_2.png", "tests/files/filter_2_for_palette_2.png",
RowFilter::Up, RowFilter::Up,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -752,9 +756,9 @@ fn filter_3_for_palette_2() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_palette_2.png", "tests/files/filter_3_for_palette_2.png",
RowFilter::Average, RowFilter::Average,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -764,9 +768,9 @@ fn filter_4_for_palette_2() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_palette_2.png", "tests/files/filter_4_for_palette_2.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -776,9 +780,9 @@ fn filter_5_for_palette_2() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_palette_2.png", "tests/files/filter_5_for_palette_2.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -788,9 +792,9 @@ fn filter_0_for_palette_1() {
test_it_converts( test_it_converts(
"tests/files/filter_0_for_palette_1.png", "tests/files/filter_0_for_palette_1.png",
RowFilter::None, RowFilter::None,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -800,9 +804,9 @@ fn filter_1_for_palette_1() {
test_it_converts( test_it_converts(
"tests/files/filter_1_for_palette_1.png", "tests/files/filter_1_for_palette_1.png",
RowFilter::Sub, RowFilter::Sub,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -812,9 +816,9 @@ fn filter_2_for_palette_1() {
test_it_converts( test_it_converts(
"tests/files/filter_2_for_palette_1.png", "tests/files/filter_2_for_palette_1.png",
RowFilter::Up, RowFilter::Up,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -824,9 +828,9 @@ fn filter_3_for_palette_1() {
test_it_converts( test_it_converts(
"tests/files/filter_3_for_palette_1.png", "tests/files/filter_3_for_palette_1.png",
RowFilter::Average, RowFilter::Average,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -836,9 +840,9 @@ fn filter_4_for_palette_1() {
test_it_converts( test_it_converts(
"tests/files/filter_4_for_palette_1.png", "tests/files/filter_4_for_palette_1.png",
RowFilter::Paeth, RowFilter::Paeth,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -848,9 +852,9 @@ fn filter_5_for_palette_1() {
test_it_converts( test_it_converts(
"tests/files/filter_5_for_palette_1.png", "tests/files/filter_5_for_palette_1.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }

View file

@ -11,6 +11,11 @@ use std::ops::Deref;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
const GRAYSCALE: u8 = 0;
const RGB: u8 = 2;
const INDEXED: u8 = 3;
const RGBA: u8 = 6;
fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
let mut options = oxipng::Options { let mut options = oxipng::Options {
force: true, force: true,
@ -32,9 +37,9 @@ fn test_it_converts_callbacks<CBPRE, CBPOST>(
input: PathBuf, input: PathBuf,
output: &OutFile, output: &OutFile,
opts: &oxipng::Options, opts: &oxipng::Options,
color_type_in: ColorType, color_type_in: u8,
bit_depth_in: BitDepth, bit_depth_in: BitDepth,
color_type_out: ColorType, color_type_out: u8,
bit_depth_out: BitDepth, bit_depth_out: BitDepth,
mut callback_pre: CBPRE, mut callback_pre: CBPRE,
mut callback_post: CBPOST, mut callback_post: CBPOST,
@ -44,7 +49,7 @@ fn test_it_converts_callbacks<CBPRE, CBPOST>(
{ {
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.png_header_code(), color_type_in);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in);
callback_pre(&input); callback_pre(&input);
@ -66,7 +71,7 @@ fn test_it_converts_callbacks<CBPRE, CBPOST>(
} }
}; };
assert_eq!(png.raw.ihdr.color_type, color_type_out); assert_eq!(png.raw.ihdr.color_type.png_header_code(), color_type_out);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out);
remove_file(output).ok(); remove_file(output).ok();
@ -77,9 +82,9 @@ fn test_it_converts(
input: PathBuf, input: PathBuf,
output: &OutFile, output: &OutFile,
opts: &oxipng::Options, opts: &oxipng::Options,
color_type_in: ColorType, color_type_in: u8,
bit_depth_in: BitDepth, bit_depth_in: BitDepth,
color_type_out: ColorType, color_type_out: u8,
bit_depth_out: BitDepth, bit_depth_out: BitDepth,
) { ) {
test_it_converts_callbacks( test_it_converts_callbacks(
@ -153,9 +158,9 @@ fn verbose_mode() {
input, input,
&output, &output,
&opts, &opts,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
}; };
@ -411,7 +416,7 @@ fn interlacing_0_to_1_small_files() {
let png = PngData::new(&input, opts.fix_errors).unwrap(); let png = PngData::new(&input, opts.fix_errors).unwrap();
assert_eq!(png.raw.ihdr.interlaced, Interlacing::None); assert_eq!(png.raw.ihdr.interlaced, Interlacing::None);
assert_eq!(png.raw.ihdr.color_type, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
match oxipng::optimize(&InFile::Path(input), &output, &opts) { match oxipng::optimize(&InFile::Path(input), &output, &opts) {
@ -430,7 +435,7 @@ fn interlacing_0_to_1_small_files() {
}; };
assert_eq!(png.raw.ihdr.interlaced, Interlacing::Adam7); assert_eq!(png.raw.ihdr.interlaced, Interlacing::Adam7);
assert_eq!(png.raw.ihdr.color_type, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::One); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::One);
remove_file(output).ok(); remove_file(output).ok();
@ -445,7 +450,7 @@ fn interlacing_1_to_0_small_files() {
let png = PngData::new(&input, opts.fix_errors).unwrap(); let png = PngData::new(&input, opts.fix_errors).unwrap();
assert_eq!(png.raw.ihdr.interlaced, Interlacing::Adam7); assert_eq!(png.raw.ihdr.interlaced, Interlacing::Adam7);
assert_eq!(png.raw.ihdr.color_type, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
match oxipng::optimize(&InFile::Path(input), &output, &opts) { match oxipng::optimize(&InFile::Path(input), &output, &opts) {
@ -464,7 +469,7 @@ fn interlacing_1_to_0_small_files() {
}; };
assert_eq!(png.raw.ihdr.interlaced, Interlacing::None); assert_eq!(png.raw.ihdr.interlaced, Interlacing::None);
assert_eq!(png.raw.ihdr.color_type, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
// the depth can't be asserted reliably, because on such small file different zlib implementations pick different depth as the best // the depth can't be asserted reliably, because on such small file different zlib implementations pick different depth as the best
remove_file(output).ok(); remove_file(output).ok();
@ -556,9 +561,9 @@ fn preserve_attrs() {
input, input,
&output, &output,
&opts, &opts,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
callback_pre, callback_pre,
callback_post, callback_post,
@ -575,7 +580,7 @@ fn fix_errors() {
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, ColorType::RGBA); assert_eq!(png.raw.ihdr.color_type.png_header_code(), RGBA);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
match oxipng::optimize(&InFile::Path(input), &output, &opts) { match oxipng::optimize(&InFile::Path(input), &output, &opts) {
@ -593,7 +598,7 @@ fn fix_errors() {
} }
}; };
assert_eq!(png.raw.ihdr.color_type, ColorType::Grayscale); assert_eq!(png.raw.ihdr.color_type.png_header_code(), GRAYSCALE);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
// Cannot check if pixels are equal because image crate cannot read corrupt (input) PNGs // Cannot check if pixels are equal because image crate cannot read corrupt (input) PNGs
@ -613,9 +618,9 @@ fn zopfli_mode() {
input, input,
&output, &output,
&opts, &opts,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }

View file

@ -5,6 +5,12 @@ use std::fs::remove_file;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
const GRAYSCALE: u8 = 0;
const RGB: u8 = 2;
const INDEXED: u8 = 3;
const GRAYSCALE_ALPHA: u8 = 4;
const RGBA: u8 = 6;
fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
let mut options = oxipng::Options { let mut options = oxipng::Options {
force: true, force: true,
@ -22,16 +28,16 @@ fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
fn test_it_converts( fn test_it_converts(
input: &str, input: &str,
color_type_in: ColorType, color_type_in: u8,
bit_depth_in: BitDepth, bit_depth_in: BitDepth,
color_type_out: ColorType, color_type_out: u8,
bit_depth_out: BitDepth, bit_depth_out: BitDepth,
) { ) {
let input = PathBuf::from(input); let input = PathBuf::from(input);
let (output, opts) = get_opts(&input); let (output, opts) = get_opts(&input);
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.png_header_code(), color_type_in);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in);
assert_eq!(png.raw.ihdr.interlaced, Interlacing::Adam7); assert_eq!(png.raw.ihdr.interlaced, Interlacing::Adam7);
@ -50,7 +56,7 @@ fn test_it_converts(
} }
}; };
assert_eq!(png.raw.ihdr.color_type, color_type_out); assert_eq!(png.raw.ihdr.color_type.png_header_code(), color_type_out);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out);
remove_file(output).ok(); remove_file(output).ok();
@ -60,9 +66,9 @@ fn test_it_converts(
fn interlaced_rgba_16_should_be_rgba_16() { fn interlaced_rgba_16_should_be_rgba_16() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_rgba_16.png", "tests/files/interlaced_rgba_16_should_be_rgba_16.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -71,9 +77,9 @@ fn interlaced_rgba_16_should_be_rgba_16() {
fn interlaced_rgba_16_should_be_rgba_8() { fn interlaced_rgba_16_should_be_rgba_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_rgba_8.png", "tests/files/interlaced_rgba_16_should_be_rgba_8.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -82,9 +88,9 @@ fn interlaced_rgba_16_should_be_rgba_8() {
fn interlaced_rgba_8_should_be_rgba_8() { fn interlaced_rgba_8_should_be_rgba_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_8_should_be_rgba_8.png", "tests/files/interlaced_rgba_8_should_be_rgba_8.png",
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -93,9 +99,9 @@ fn interlaced_rgba_8_should_be_rgba_8() {
fn interlaced_rgba_16_should_be_rgb_16() { fn interlaced_rgba_16_should_be_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_rgb_16.png", "tests/files/interlaced_rgba_16_should_be_rgb_16.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -104,9 +110,9 @@ fn interlaced_rgba_16_should_be_rgb_16() {
fn interlaced_rgba_16_should_be_rgb_8() { fn interlaced_rgba_16_should_be_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_rgb_8.png", "tests/files/interlaced_rgba_16_should_be_rgb_8.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -115,9 +121,9 @@ fn interlaced_rgba_16_should_be_rgb_8() {
fn interlaced_rgba_8_should_be_rgb_8() { fn interlaced_rgba_8_should_be_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_8_should_be_rgb_8.png", "tests/files/interlaced_rgba_8_should_be_rgb_8.png",
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -126,9 +132,9 @@ fn interlaced_rgba_8_should_be_rgb_8() {
fn interlaced_rgba_16_should_be_palette_8() { fn interlaced_rgba_16_should_be_palette_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_palette_8.png", "tests/files/interlaced_rgba_16_should_be_palette_8.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -137,9 +143,9 @@ fn interlaced_rgba_16_should_be_palette_8() {
fn interlaced_rgba_8_should_be_palette_8() { fn interlaced_rgba_8_should_be_palette_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_8_should_be_palette_8.png", "tests/files/interlaced_rgba_8_should_be_palette_8.png",
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -148,9 +154,9 @@ fn interlaced_rgba_8_should_be_palette_8() {
fn interlaced_rgba_16_should_be_palette_4() { fn interlaced_rgba_16_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_palette_4.png", "tests/files/interlaced_rgba_16_should_be_palette_4.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -159,9 +165,9 @@ fn interlaced_rgba_16_should_be_palette_4() {
fn interlaced_rgba_8_should_be_palette_4() { fn interlaced_rgba_8_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_8_should_be_palette_4.png", "tests/files/interlaced_rgba_8_should_be_palette_4.png",
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -170,9 +176,9 @@ fn interlaced_rgba_8_should_be_palette_4() {
fn interlaced_rgba_16_should_be_palette_2() { fn interlaced_rgba_16_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_palette_2.png", "tests/files/interlaced_rgba_16_should_be_palette_2.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -181,9 +187,9 @@ fn interlaced_rgba_16_should_be_palette_2() {
fn interlaced_rgba_8_should_be_palette_2() { fn interlaced_rgba_8_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_8_should_be_palette_2.png", "tests/files/interlaced_rgba_8_should_be_palette_2.png",
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -192,9 +198,9 @@ fn interlaced_rgba_8_should_be_palette_2() {
fn interlaced_rgba_16_should_be_palette_1() { fn interlaced_rgba_16_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_palette_1.png", "tests/files/interlaced_rgba_16_should_be_palette_1.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -203,9 +209,9 @@ fn interlaced_rgba_16_should_be_palette_1() {
fn interlaced_rgba_8_should_be_palette_1() { fn interlaced_rgba_8_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_8_should_be_palette_1.png", "tests/files/interlaced_rgba_8_should_be_palette_1.png",
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -214,9 +220,9 @@ fn interlaced_rgba_8_should_be_palette_1() {
fn interlaced_rgba_16_should_be_grayscale_alpha_16() { fn interlaced_rgba_16_should_be_grayscale_alpha_16() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_grayscale_alpha_16.png", "tests/files/interlaced_rgba_16_should_be_grayscale_alpha_16.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -225,9 +231,9 @@ fn interlaced_rgba_16_should_be_grayscale_alpha_16() {
fn interlaced_rgba_16_should_be_grayscale_alpha_8() { fn interlaced_rgba_16_should_be_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_grayscale_alpha_8.png", "tests/files/interlaced_rgba_16_should_be_grayscale_alpha_8.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -236,9 +242,9 @@ fn interlaced_rgba_16_should_be_grayscale_alpha_8() {
fn interlaced_rgba_8_should_be_grayscale_alpha_8() { fn interlaced_rgba_8_should_be_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_8_should_be_grayscale_alpha_8.png", "tests/files/interlaced_rgba_8_should_be_grayscale_alpha_8.png",
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -247,9 +253,9 @@ fn interlaced_rgba_8_should_be_grayscale_alpha_8() {
fn interlaced_rgba_16_should_be_grayscale_16() { fn interlaced_rgba_16_should_be_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_grayscale_16.png", "tests/files/interlaced_rgba_16_should_be_grayscale_16.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -258,9 +264,9 @@ fn interlaced_rgba_16_should_be_grayscale_16() {
fn interlaced_rgba_16_should_be_grayscale_8() { fn interlaced_rgba_16_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_16_should_be_grayscale_8.png", "tests/files/interlaced_rgba_16_should_be_grayscale_8.png",
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -269,9 +275,9 @@ fn interlaced_rgba_16_should_be_grayscale_8() {
fn interlaced_rgba_8_should_be_grayscale_8() { fn interlaced_rgba_8_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgba_8_should_be_grayscale_8.png", "tests/files/interlaced_rgba_8_should_be_grayscale_8.png",
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -280,9 +286,9 @@ fn interlaced_rgba_8_should_be_grayscale_8() {
fn interlaced_rgb_16_should_be_rgb_16() { fn interlaced_rgb_16_should_be_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_16_should_be_rgb_16.png", "tests/files/interlaced_rgb_16_should_be_rgb_16.png",
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -291,9 +297,9 @@ fn interlaced_rgb_16_should_be_rgb_16() {
fn interlaced_rgb_16_should_be_rgb_8() { fn interlaced_rgb_16_should_be_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_16_should_be_rgb_8.png", "tests/files/interlaced_rgb_16_should_be_rgb_8.png",
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -302,9 +308,9 @@ fn interlaced_rgb_16_should_be_rgb_8() {
fn interlaced_rgb_8_should_be_rgb_8() { fn interlaced_rgb_8_should_be_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_8_should_be_rgb_8.png", "tests/files/interlaced_rgb_8_should_be_rgb_8.png",
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -313,9 +319,9 @@ fn interlaced_rgb_8_should_be_rgb_8() {
fn interlaced_rgb_16_should_be_palette_8() { fn interlaced_rgb_16_should_be_palette_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_16_should_be_palette_8.png", "tests/files/interlaced_rgb_16_should_be_palette_8.png",
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -324,9 +330,9 @@ fn interlaced_rgb_16_should_be_palette_8() {
fn interlaced_rgb_8_should_be_palette_8() { fn interlaced_rgb_8_should_be_palette_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_8_should_be_palette_8.png", "tests/files/interlaced_rgb_8_should_be_palette_8.png",
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -335,9 +341,9 @@ fn interlaced_rgb_8_should_be_palette_8() {
fn interlaced_rgb_16_should_be_palette_4() { fn interlaced_rgb_16_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_16_should_be_palette_4.png", "tests/files/interlaced_rgb_16_should_be_palette_4.png",
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -346,9 +352,9 @@ fn interlaced_rgb_16_should_be_palette_4() {
fn interlaced_rgb_8_should_be_palette_4() { fn interlaced_rgb_8_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_8_should_be_palette_4.png", "tests/files/interlaced_rgb_8_should_be_palette_4.png",
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -357,9 +363,9 @@ fn interlaced_rgb_8_should_be_palette_4() {
fn interlaced_rgb_16_should_be_palette_2() { fn interlaced_rgb_16_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_16_should_be_palette_2.png", "tests/files/interlaced_rgb_16_should_be_palette_2.png",
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -368,9 +374,9 @@ fn interlaced_rgb_16_should_be_palette_2() {
fn interlaced_rgb_8_should_be_palette_2() { fn interlaced_rgb_8_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_8_should_be_palette_2.png", "tests/files/interlaced_rgb_8_should_be_palette_2.png",
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -379,9 +385,9 @@ fn interlaced_rgb_8_should_be_palette_2() {
fn interlaced_rgb_16_should_be_palette_1() { fn interlaced_rgb_16_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_16_should_be_palette_1.png", "tests/files/interlaced_rgb_16_should_be_palette_1.png",
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -390,9 +396,9 @@ fn interlaced_rgb_16_should_be_palette_1() {
fn interlaced_rgb_8_should_be_palette_1() { fn interlaced_rgb_8_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_8_should_be_palette_1.png", "tests/files/interlaced_rgb_8_should_be_palette_1.png",
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -401,9 +407,9 @@ fn interlaced_rgb_8_should_be_palette_1() {
fn interlaced_rgb_16_should_be_grayscale_16() { fn interlaced_rgb_16_should_be_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_16_should_be_grayscale_16.png", "tests/files/interlaced_rgb_16_should_be_grayscale_16.png",
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -412,9 +418,9 @@ fn interlaced_rgb_16_should_be_grayscale_16() {
fn interlaced_rgb_16_should_be_grayscale_8() { fn interlaced_rgb_16_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_16_should_be_grayscale_8.png", "tests/files/interlaced_rgb_16_should_be_grayscale_8.png",
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -423,9 +429,9 @@ fn interlaced_rgb_16_should_be_grayscale_8() {
fn interlaced_rgb_8_should_be_grayscale_8() { fn interlaced_rgb_8_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_8_should_be_grayscale_8.png", "tests/files/interlaced_rgb_8_should_be_grayscale_8.png",
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -434,9 +440,9 @@ fn interlaced_rgb_8_should_be_grayscale_8() {
fn interlaced_palette_8_should_be_palette_8() { fn interlaced_palette_8_should_be_palette_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_8_should_be_palette_8.png", "tests/files/interlaced_palette_8_should_be_palette_8.png",
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -445,9 +451,9 @@ fn interlaced_palette_8_should_be_palette_8() {
fn interlaced_palette_8_should_be_palette_4() { fn interlaced_palette_8_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_8_should_be_palette_4.png", "tests/files/interlaced_palette_8_should_be_palette_4.png",
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -456,9 +462,9 @@ fn interlaced_palette_8_should_be_palette_4() {
fn interlaced_palette_4_should_be_palette_4() { fn interlaced_palette_4_should_be_palette_4() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_4_should_be_palette_4.png", "tests/files/interlaced_palette_4_should_be_palette_4.png",
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -467,9 +473,9 @@ fn interlaced_palette_4_should_be_palette_4() {
fn interlaced_palette_8_should_be_palette_2() { fn interlaced_palette_8_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_8_should_be_palette_2.png", "tests/files/interlaced_palette_8_should_be_palette_2.png",
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -478,9 +484,9 @@ fn interlaced_palette_8_should_be_palette_2() {
fn interlaced_palette_4_should_be_palette_2() { fn interlaced_palette_4_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_4_should_be_palette_2.png", "tests/files/interlaced_palette_4_should_be_palette_2.png",
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -489,9 +495,9 @@ fn interlaced_palette_4_should_be_palette_2() {
fn interlaced_palette_2_should_be_palette_2() { fn interlaced_palette_2_should_be_palette_2() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_2_should_be_palette_2.png", "tests/files/interlaced_palette_2_should_be_palette_2.png",
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -500,9 +506,9 @@ fn interlaced_palette_2_should_be_palette_2() {
fn interlaced_palette_8_should_be_palette_1() { fn interlaced_palette_8_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_8_should_be_palette_1.png", "tests/files/interlaced_palette_8_should_be_palette_1.png",
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -511,9 +517,9 @@ fn interlaced_palette_8_should_be_palette_1() {
fn interlaced_palette_4_should_be_palette_1() { fn interlaced_palette_4_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_4_should_be_palette_1.png", "tests/files/interlaced_palette_4_should_be_palette_1.png",
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -522,9 +528,9 @@ fn interlaced_palette_4_should_be_palette_1() {
fn interlaced_palette_2_should_be_palette_1() { fn interlaced_palette_2_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_2_should_be_palette_1.png", "tests/files/interlaced_palette_2_should_be_palette_1.png",
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -533,9 +539,9 @@ fn interlaced_palette_2_should_be_palette_1() {
fn interlaced_palette_1_should_be_palette_1() { fn interlaced_palette_1_should_be_palette_1() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_1_should_be_palette_1.png", "tests/files/interlaced_palette_1_should_be_palette_1.png",
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -544,9 +550,9 @@ fn interlaced_palette_1_should_be_palette_1() {
fn interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16() { fn interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16() {
test_it_converts( test_it_converts(
"tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16.png", "tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16.png",
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -555,9 +561,9 @@ fn interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16() {
fn interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8() { fn interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8.png", "tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8.png",
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -566,9 +572,9 @@ fn interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8() {
fn interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8() { fn interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8.png", "tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8.png",
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -577,9 +583,9 @@ fn interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8() {
fn interlaced_grayscale_alpha_16_should_be_grayscale_16() { fn interlaced_grayscale_alpha_16_should_be_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_16.png", "tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_16.png",
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -588,9 +594,9 @@ fn interlaced_grayscale_alpha_16_should_be_grayscale_16() {
fn interlaced_grayscale_alpha_16_should_be_grayscale_8() { fn interlaced_grayscale_alpha_16_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_8.png", "tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_8.png",
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -599,9 +605,9 @@ fn interlaced_grayscale_alpha_16_should_be_grayscale_8() {
fn interlaced_grayscale_alpha_8_should_be_grayscale_8() { fn interlaced_grayscale_alpha_8_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_8.png", "tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_8.png",
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -610,9 +616,9 @@ fn interlaced_grayscale_alpha_8_should_be_grayscale_8() {
fn interlaced_grayscale_16_should_be_grayscale_16() { fn interlaced_grayscale_16_should_be_grayscale_16() {
test_it_converts( test_it_converts(
"tests/files/interlaced_grayscale_16_should_be_grayscale_16.png", "tests/files/interlaced_grayscale_16_should_be_grayscale_16.png",
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -621,9 +627,9 @@ fn interlaced_grayscale_16_should_be_grayscale_16() {
fn interlaced_grayscale_16_should_be_grayscale_8() { fn interlaced_grayscale_16_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_grayscale_16_should_be_grayscale_8.png", "tests/files/interlaced_grayscale_16_should_be_grayscale_8.png",
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -632,9 +638,9 @@ fn interlaced_grayscale_16_should_be_grayscale_8() {
fn interlaced_grayscale_8_should_be_grayscale_8() { fn interlaced_grayscale_8_should_be_grayscale_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_grayscale_8_should_be_grayscale_8.png", "tests/files/interlaced_grayscale_8_should_be_grayscale_8.png",
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -643,9 +649,9 @@ fn interlaced_grayscale_8_should_be_grayscale_8() {
fn interlaced_small_files() { fn interlaced_small_files() {
test_it_converts( test_it_converts(
"tests/files/interlaced_small_files.png", "tests/files/interlaced_small_files.png",
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -654,9 +660,9 @@ fn interlaced_small_files() {
fn interlaced_odd_width() { fn interlaced_odd_width() {
test_it_converts( test_it_converts(
"tests/files/interlaced_odd_width.png", "tests/files/interlaced_odd_width.png",
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }

View file

@ -5,6 +5,9 @@ use std::fs::remove_file;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
const RGB: u8 = 2;
const INDEXED: u8 = 3;
fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
let mut options = oxipng::Options { let mut options = oxipng::Options {
force: true, force: true,
@ -23,16 +26,16 @@ fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
fn test_it_converts( fn test_it_converts(
input: &str, input: &str,
interlace: Interlacing, interlace: Interlacing,
color_type_in: ColorType, color_type_in: u8,
bit_depth_in: BitDepth, bit_depth_in: BitDepth,
color_type_out: ColorType, color_type_out: u8,
bit_depth_out: BitDepth, bit_depth_out: BitDepth,
) { ) {
let input = PathBuf::from(input); let input = PathBuf::from(input);
let (output, mut opts) = get_opts(&input); let (output, mut opts) = get_opts(&input);
let png = PngData::new(&input, opts.fix_errors).unwrap(); let png = PngData::new(&input, opts.fix_errors).unwrap();
opts.interlace = Some(interlace); opts.interlace = Some(interlace);
assert_eq!(png.raw.ihdr.color_type, color_type_in); assert_eq!(png.raw.ihdr.color_type.png_header_code(), color_type_in);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in);
assert_eq!( assert_eq!(
png.raw.ihdr.interlaced, png.raw.ihdr.interlaced,
@ -58,7 +61,7 @@ fn test_it_converts(
} }
}; };
assert_eq!(png.raw.ihdr.color_type, color_type_out); assert_eq!(png.raw.ihdr.color_type.png_header_code(), color_type_out);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out);
remove_file(output).ok(); remove_file(output).ok();
@ -69,9 +72,9 @@ fn deinterlace_rgb_16() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_16_should_be_rgb_16.png", "tests/files/interlaced_rgb_16_should_be_rgb_16.png",
Interlacing::None, Interlacing::None,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -81,9 +84,9 @@ fn deinterlace_rgb_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_rgb_8_should_be_rgb_8.png", "tests/files/interlaced_rgb_8_should_be_rgb_8.png",
Interlacing::None, Interlacing::None,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -93,9 +96,9 @@ fn deinterlace_palette_8() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_8_should_be_palette_8.png", "tests/files/interlaced_palette_8_should_be_palette_8.png",
Interlacing::None, Interlacing::None,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -105,9 +108,9 @@ fn deinterlace_palette_4() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_4_should_be_palette_4.png", "tests/files/interlaced_palette_4_should_be_palette_4.png",
Interlacing::None, Interlacing::None,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -117,9 +120,9 @@ fn deinterlace_palette_2() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_2_should_be_palette_2.png", "tests/files/interlaced_palette_2_should_be_palette_2.png",
Interlacing::None, Interlacing::None,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -129,9 +132,9 @@ fn deinterlace_palette_1() {
test_it_converts( test_it_converts(
"tests/files/interlaced_palette_1_should_be_palette_1.png", "tests/files/interlaced_palette_1_should_be_palette_1.png",
Interlacing::None, Interlacing::None,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -141,9 +144,9 @@ fn interlace_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",
Interlacing::Adam7, Interlacing::Adam7,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -153,9 +156,9 @@ fn interlace_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",
Interlacing::Adam7, Interlacing::Adam7,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -165,9 +168,9 @@ fn interlace_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",
Interlacing::Adam7, Interlacing::Adam7,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -177,9 +180,9 @@ fn interlace_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",
Interlacing::Adam7, Interlacing::Adam7,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -189,9 +192,9 @@ fn interlace_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",
Interlacing::Adam7, Interlacing::Adam7,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -201,9 +204,9 @@ fn interlace_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",
Interlacing::Adam7, Interlacing::Adam7,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }

View file

@ -5,6 +5,12 @@ use std::fs::remove_file;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
const GRAYSCALE: u8 = 0;
const RGB: u8 = 2;
const INDEXED: u8 = 3;
const GRAYSCALE_ALPHA: u8 = 4;
const RGBA: u8 = 6;
fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
let mut options = oxipng::Options { let mut options = oxipng::Options {
force: true, force: true,
@ -23,9 +29,9 @@ fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
fn test_it_converts( fn test_it_converts(
input: &str, input: &str,
optimize_alpha: bool, optimize_alpha: bool,
color_type_in: ColorType, color_type_in: u8,
bit_depth_in: BitDepth, bit_depth_in: BitDepth,
color_type_out: ColorType, color_type_out: u8,
bit_depth_out: BitDepth, bit_depth_out: BitDepth,
) { ) {
let input = PathBuf::from(input); let input = PathBuf::from(input);
@ -33,7 +39,7 @@ fn test_it_converts(
opts.optimize_alpha = optimize_alpha; opts.optimize_alpha = optimize_alpha;
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.png_header_code(), color_type_in);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in, "test file is broken"); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in, "test file is broken");
assert_eq!(png.raw.ihdr.interlaced, Interlacing::None); assert_eq!(png.raw.ihdr.interlaced, Interlacing::None);
@ -52,7 +58,7 @@ fn test_it_converts(
} }
}; };
assert_eq!(png.raw.ihdr.color_type, color_type_out); assert_eq!(png.raw.ihdr.color_type.png_header_code(), color_type_out);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out);
remove_file(output).ok(); remove_file(output).ok();
@ -63,9 +69,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -75,9 +81,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -87,9 +93,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -99,9 +105,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -111,9 +117,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -123,9 +129,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -135,9 +141,9 @@ fn rgba_16_should_be_rgb_trns_16() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_should_be_rgb_trns_16.png", "tests/files/rgba_16_should_be_rgb_trns_16.png",
true, true,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -147,9 +153,9 @@ fn rgba_8_should_be_rgb_trns_8() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_should_be_rgb_trns_8.png", "tests/files/rgba_8_should_be_rgb_trns_8.png",
true, true,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -159,9 +165,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -171,9 +177,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -183,9 +189,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -195,9 +201,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -207,9 +213,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -219,9 +225,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -231,9 +237,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -243,9 +249,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -255,9 +261,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -267,9 +273,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -279,9 +285,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -291,9 +297,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -303,9 +309,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -315,9 +321,9 @@ 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",
false, false,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -327,9 +333,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -339,9 +345,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -351,9 +357,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -363,9 +369,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -375,9 +381,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -387,9 +393,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -399,9 +405,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -411,9 +417,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -423,9 +429,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -435,9 +441,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -447,9 +453,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -459,9 +465,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -471,9 +477,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -483,9 +489,9 @@ 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",
false, false,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -495,9 +501,9 @@ 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",
false, false,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -507,9 +513,9 @@ 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",
false, false,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -519,9 +525,9 @@ 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",
false, false,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -531,9 +537,9 @@ 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",
false, false,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -543,9 +549,9 @@ 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",
false, false,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -555,9 +561,9 @@ 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",
false, false,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -567,9 +573,9 @@ 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",
false, false,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -579,9 +585,9 @@ 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",
false, false,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -591,9 +597,9 @@ 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",
false, false,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -603,9 +609,9 @@ 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",
false, false,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -615,9 +621,9 @@ 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",
false, false,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -627,9 +633,9 @@ 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",
false, false,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -639,9 +645,9 @@ 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",
false, false,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -651,9 +657,9 @@ 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",
false, false,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -663,9 +669,9 @@ 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",
false, false,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -675,9 +681,9 @@ 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",
false, false,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -687,9 +693,9 @@ 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",
false, false,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -699,9 +705,9 @@ 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",
false, false,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -711,9 +717,9 @@ 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",
false, false,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -723,9 +729,9 @@ fn grayscale_8_should_be_grayscale_4() {
test_it_converts( test_it_converts(
"tests/files/grayscale_8_should_be_grayscale_4.png", "tests/files/grayscale_8_should_be_grayscale_4.png",
false, false,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -735,9 +741,9 @@ fn grayscale_8_should_be_grayscale_2() {
test_it_converts( test_it_converts(
"tests/files/grayscale_8_should_be_grayscale_2.png", "tests/files/grayscale_8_should_be_grayscale_2.png",
false, false,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -747,9 +753,9 @@ fn grayscale_4_should_be_grayscale_2() {
test_it_converts( test_it_converts(
"tests/files/grayscale_4_should_be_grayscale_2.png", "tests/files/grayscale_4_should_be_grayscale_2.png",
false, false,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Four, BitDepth::Four,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -759,9 +765,9 @@ fn grayscale_8_should_be_grayscale_1() {
test_it_converts( test_it_converts(
"tests/files/grayscale_8_should_be_grayscale_1.png", "tests/files/grayscale_8_should_be_grayscale_1.png",
false, false,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::One, BitDepth::One,
); );
} }
@ -771,9 +777,9 @@ fn grayscale_4_should_be_grayscale_1() {
test_it_converts( test_it_converts(
"tests/files/grayscale_4_should_be_grayscale_1.png", "tests/files/grayscale_4_should_be_grayscale_1.png",
false, false,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Four, BitDepth::Four,
ColorType::Grayscale, GRAYSCALE,
BitDepth::One, BitDepth::One,
); );
} }
@ -783,9 +789,9 @@ fn grayscale_2_should_be_grayscale_1() {
test_it_converts( test_it_converts(
"tests/files/grayscale_2_should_be_grayscale_1.png", "tests/files/grayscale_2_should_be_grayscale_1.png",
false, false,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Two, BitDepth::Two,
ColorType::Grayscale, GRAYSCALE,
BitDepth::One, BitDepth::One,
); );
} }
@ -795,9 +801,9 @@ fn grayscale_alpha_16_should_be_grayscale_trns_16() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_16_should_be_grayscale_trns_16.png", "tests/files/grayscale_alpha_16_should_be_grayscale_trns_16.png",
true, true,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -807,9 +813,9 @@ fn grayscale_alpha_8_should_be_grayscale_trns_8() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_8_should_be_grayscale_trns_8.png", "tests/files/grayscale_alpha_8_should_be_grayscale_trns_8.png",
true, true,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -821,7 +827,7 @@ fn small_files() {
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, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
match oxipng::optimize(&InFile::Path(input), &output, &opts) { match oxipng::optimize(&InFile::Path(input), &output, &opts) {
@ -839,7 +845,7 @@ fn small_files() {
} }
}; };
assert_eq!(png.raw.ihdr.color_type, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
// depth varies depending on zlib implementation used // depth varies depending on zlib implementation used
remove_file(output).ok(); remove_file(output).ok();
@ -852,9 +858,11 @@ fn palette_should_be_reduced_with_dupes() {
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, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
assert_eq!(png.raw.palette.as_ref().unwrap().len(), 43); if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
assert_eq!(palette.len(), 43);
}
match oxipng::optimize(&InFile::Path(input), &output, &opts) { match oxipng::optimize(&InFile::Path(input), &output, &opts) {
Ok(_) => (), Ok(_) => (),
@ -871,9 +879,11 @@ fn palette_should_be_reduced_with_dupes() {
} }
}; };
assert_eq!(png.raw.ihdr.color_type, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
assert_eq!(png.raw.palette.as_ref().unwrap().len(), 35); if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
assert_eq!(palette.len(), 35);
}
remove_file(output).ok(); remove_file(output).ok();
} }
@ -885,9 +895,11 @@ fn palette_should_be_reduced_with_unused() {
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, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
assert_eq!(png.raw.palette.as_ref().unwrap().len(), 35); if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
assert_eq!(palette.len(), 35);
}
match oxipng::optimize(&InFile::Path(input), &output, &opts) { match oxipng::optimize(&InFile::Path(input), &output, &opts) {
Ok(_) => (), Ok(_) => (),
@ -904,9 +916,11 @@ fn palette_should_be_reduced_with_unused() {
} }
}; };
assert_eq!(png.raw.ihdr.color_type, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
assert_eq!(png.raw.palette.as_ref().unwrap().len(), 33); if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
assert_eq!(palette.len(), 33);
}
remove_file(output).ok(); remove_file(output).ok();
} }
@ -918,9 +932,11 @@ fn palette_should_be_reduced_with_both() {
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, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
assert_eq!(png.raw.palette.as_ref().unwrap().len(), 43); if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
assert_eq!(palette.len(), 43);
}
match oxipng::optimize(&InFile::Path(input), &output, &opts) { match oxipng::optimize(&InFile::Path(input), &output, &opts) {
Ok(_) => (), Ok(_) => (),
@ -937,9 +953,11 @@ fn palette_should_be_reduced_with_both() {
} }
}; };
assert_eq!(png.raw.ihdr.color_type, ColorType::Indexed); assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight); assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
assert_eq!(png.raw.palette.as_ref().unwrap().len(), 33); if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
assert_eq!(palette.len(), 33);
}
remove_file(output).ok(); remove_file(output).ok();
} }
@ -949,9 +967,9 @@ fn rgba_16_reduce_alpha() {
test_it_converts( test_it_converts(
"tests/files/rgba_16_reduce_alpha.png", "tests/files/rgba_16_reduce_alpha.png",
true, true,
ColorType::RGBA, RGBA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -961,9 +979,9 @@ fn rgba_8_reduce_alpha() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_reduce_alpha.png", "tests/files/rgba_8_reduce_alpha.png",
true, true,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -973,9 +991,9 @@ fn grayscale_alpha_16_reduce_alpha() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_16_reduce_alpha.png", "tests/files/grayscale_alpha_16_reduce_alpha.png",
true, true,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -985,9 +1003,9 @@ fn grayscale_alpha_8_reduce_alpha() {
test_it_converts( test_it_converts(
"tests/files/grayscale_alpha_8_reduce_alpha.png", "tests/files/grayscale_alpha_8_reduce_alpha.png",
true, true,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }

View file

@ -5,6 +5,12 @@ use std::fs::remove_file;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
const GRAYSCALE: u8 = 0;
const RGB: u8 = 2;
const INDEXED: u8 = 3;
const GRAYSCALE_ALPHA: u8 = 4;
const RGBA: u8 = 6;
fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
let mut options = oxipng::Options { let mut options = oxipng::Options {
force: true, force: true,
@ -23,9 +29,9 @@ fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
fn test_it_converts( fn test_it_converts(
input: &str, input: &str,
custom: Option<(OutFile, oxipng::Options)>, custom: Option<(OutFile, oxipng::Options)>,
color_type_in: ColorType, color_type_in: u8,
bit_depth_in: BitDepth, bit_depth_in: BitDepth,
color_type_out: ColorType, color_type_out: u8,
bit_depth_out: BitDepth, bit_depth_out: BitDepth,
) { ) {
let input = PathBuf::from(input); let input = PathBuf::from(input);
@ -33,7 +39,8 @@ fn test_it_converts(
let png = PngData::new(&input, opts.fix_errors).unwrap(); let png = PngData::new(&input, opts.fix_errors).unwrap();
assert_eq!( assert_eq!(
png.raw.ihdr.color_type, color_type_in, png.raw.ihdr.color_type.png_header_code(),
color_type_in,
"test file is broken" "test file is broken"
); );
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in, "test file is broken"); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in, "test file is broken");
@ -54,14 +61,15 @@ fn test_it_converts(
}; };
assert_eq!( assert_eq!(
png.raw.ihdr.color_type, color_type_out, png.raw.ihdr.color_type.png_header_code(),
color_type_out,
"optimized to wrong color type" "optimized to wrong color type"
); );
assert_eq!( assert_eq!(
png.raw.ihdr.bit_depth, bit_depth_out, png.raw.ihdr.bit_depth, bit_depth_out,
"optimized to wrong bit depth" "optimized to wrong bit depth"
); );
if let Some(palette) = png.raw.palette.as_ref() { if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
let mut max_palette_size = 1 << (png.raw.ihdr.bit_depth.as_u8() as usize); let mut max_palette_size = 1 << (png.raw.ihdr.bit_depth.as_u8() as usize);
// Ensure bKGD color is valid // Ensure bKGD color is valid
if let Some(&idx) = png.raw.aux_headers.get(b"bKGD").and_then(|b| b.first()) { if let Some(&idx) = png.raw.aux_headers.get(b"bKGD").and_then(|b| b.first()) {
@ -69,8 +77,6 @@ fn test_it_converts(
max_palette_size = max_palette_size.max(idx as usize + 1); max_palette_size = max_palette_size.max(idx as usize + 1);
} }
assert!(palette.len() <= max_palette_size); assert!(palette.len() <= max_palette_size);
} else {
assert_ne!(png.raw.ihdr.color_type, ColorType::Indexed);
} }
remove_file(output).ok(); remove_file(output).ok();
@ -81,9 +87,9 @@ fn issue_29() {
test_it_converts( test_it_converts(
"tests/files/issue-29.png", "tests/files/issue-29.png",
None, None,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -127,9 +133,9 @@ fn issue_52_01() {
test_it_converts( test_it_converts(
"tests/files/issue-52-01.png", "tests/files/issue-52-01.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -139,9 +145,9 @@ fn issue_52_02() {
test_it_converts( test_it_converts(
"tests/files/issue-52-02.png", "tests/files/issue-52-02.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -151,9 +157,9 @@ fn issue_52_03() {
test_it_converts( test_it_converts(
"tests/files/issue-52-03.png", "tests/files/issue-52-03.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -163,9 +169,9 @@ fn issue_52_04() {
test_it_converts( test_it_converts(
"tests/files/issue-52-04.png", "tests/files/issue-52-04.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -175,9 +181,9 @@ fn issue_52_05() {
test_it_converts( test_it_converts(
"tests/files/issue-52-05.png", "tests/files/issue-52-05.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -187,9 +193,9 @@ fn issue_52_06() {
test_it_converts( test_it_converts(
"tests/files/issue-52-06.png", "tests/files/issue-52-06.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -199,9 +205,9 @@ fn issue_56() {
test_it_converts( test_it_converts(
"tests/files/issue-56.png", "tests/files/issue-56.png",
None, None,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -211,9 +217,9 @@ fn issue_58() {
test_it_converts( test_it_converts(
"tests/files/issue-58.png", "tests/files/issue-58.png",
None, None,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -223,9 +229,9 @@ fn issue_59() {
test_it_converts( test_it_converts(
"tests/files/issue-59.png", "tests/files/issue-59.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -235,9 +241,9 @@ fn issue_60() {
test_it_converts( test_it_converts(
"tests/files/issue-60.png", "tests/files/issue-60.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -247,9 +253,9 @@ fn issue_80() {
test_it_converts( test_it_converts(
"tests/files/issue-80.png", "tests/files/issue-80.png",
None, None,
ColorType::Indexed, INDEXED,
BitDepth::Two, BitDepth::Two,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -259,9 +265,9 @@ fn issue_82() {
test_it_converts( test_it_converts(
"tests/files/issue-82.png", "tests/files/issue-82.png",
None, None,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
ColorType::Indexed, INDEXED,
BitDepth::Four, BitDepth::Four,
); );
} }
@ -271,9 +277,9 @@ fn issue_89() {
test_it_converts( test_it_converts(
"tests/files/issue-89.png", "tests/files/issue-89.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -283,9 +289,9 @@ fn issue_92_filter_0() {
test_it_converts( test_it_converts(
"tests/files/issue-92.png", "tests/files/issue-92.png",
None, None,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -300,9 +306,9 @@ fn issue_92_filter_5() {
test_it_converts( test_it_converts(
input, input,
Some((output, opts)), Some((output, opts)),
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -316,9 +322,9 @@ fn issue_113() {
test_it_converts( test_it_converts(
input, input,
Some((output, opts)), Some((output, opts)),
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::GrayscaleAlpha, GRAYSCALE_ALPHA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -326,14 +332,7 @@ fn issue_113() {
#[test] #[test]
fn issue_129() { fn issue_129() {
let input = "tests/files/issue-129.png"; let input = "tests/files/issue-129.png";
test_it_converts( test_it_converts(input, None, RGB, BitDepth::Eight, INDEXED, BitDepth::Eight);
input,
None,
ColorType::RGB,
BitDepth::Eight,
ColorType::Indexed,
BitDepth::Eight,
);
} }
#[test] #[test]
@ -344,9 +343,9 @@ fn issue_133() {
test_it_converts( test_it_converts(
input, input,
Some((output, opts)), Some((output, opts)),
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -356,9 +355,9 @@ fn issue_140() {
test_it_converts( test_it_converts(
"tests/files/issue-140.png", "tests/files/issue-140.png",
None, None,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Two, BitDepth::Two,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Two, BitDepth::Two,
); );
} }
@ -368,9 +367,9 @@ fn issue_141() {
test_it_converts( test_it_converts(
"tests/files/issue-141.png", "tests/files/issue-141.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -380,9 +379,9 @@ fn issue_153() {
test_it_converts( test_it_converts(
"tests/files/issue-153.png", "tests/files/issue-153.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -392,9 +391,9 @@ fn issue_159() {
test_it_converts( test_it_converts(
"tests/files/issue-159.png", "tests/files/issue-159.png",
None, None,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
ColorType::Indexed, INDEXED,
BitDepth::One, BitDepth::One,
); );
} }
@ -404,9 +403,9 @@ fn issue_171() {
test_it_converts( test_it_converts(
"tests/files/issue-171.png", "tests/files/issue-171.png",
None, None,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -416,9 +415,9 @@ fn issue_175() {
test_it_converts( test_it_converts(
"tests/files/issue-175.png", "tests/files/issue-175.png",
None, None,
ColorType::Grayscale, GRAYSCALE,
BitDepth::One, BitDepth::One,
ColorType::Grayscale, GRAYSCALE,
BitDepth::One, BitDepth::One,
); );
} }
@ -432,9 +431,9 @@ fn issue_182() {
test_it_converts( test_it_converts(
input, input,
Some((output, opts)), Some((output, opts)),
ColorType::Grayscale, GRAYSCALE,
BitDepth::One, BitDepth::One,
ColorType::Grayscale, GRAYSCALE,
BitDepth::One, BitDepth::One,
); );
} }
@ -444,9 +443,9 @@ fn issue_195() {
test_it_converts( test_it_converts(
"tests/files/issue-195.png", "tests/files/issue-195.png",
None, None,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -456,9 +455,9 @@ fn issue_426_01() {
test_it_converts( test_it_converts(
"tests/files/issue-426-01.png", "tests/files/issue-426-01.png",
None, None,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::One, BitDepth::One,
); );
} }
@ -468,9 +467,9 @@ fn issue_426_02() {
test_it_converts( test_it_converts(
"tests/files/issue-426-02.png", "tests/files/issue-426-02.png",
None, None,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::One, BitDepth::One,
); );
} }

View file

@ -5,6 +5,11 @@ use std::fs::remove_file;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
const GRAYSCALE: u8 = 0;
const RGB: u8 = 2;
const INDEXED: u8 = 3;
const RGBA: u8 = 6;
fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
let mut options = oxipng::Options { let mut options = oxipng::Options {
force: true, force: true,
@ -23,9 +28,9 @@ fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
fn test_it_converts( fn test_it_converts(
input: &str, input: &str,
filter: RowFilter, filter: RowFilter,
color_type_in: ColorType, color_type_in: u8,
bit_depth_in: BitDepth, bit_depth_in: BitDepth,
color_type_out: ColorType, color_type_out: u8,
bit_depth_out: BitDepth, bit_depth_out: BitDepth,
) { ) {
let input = PathBuf::from(input); let input = PathBuf::from(input);
@ -34,7 +39,7 @@ fn test_it_converts(
let png = PngData::new(&input, opts.fix_errors).unwrap(); let png = PngData::new(&input, opts.fix_errors).unwrap();
opts.filter = IndexSet::new(); opts.filter = IndexSet::new();
opts.filter.insert(filter); opts.filter.insert(filter);
assert_eq!(png.raw.ihdr.color_type, color_type_in); assert_eq!(png.raw.ihdr.color_type.png_header_code(), color_type_in);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_in);
match oxipng::optimize(&InFile::Path(input), &output, &opts) { match oxipng::optimize(&InFile::Path(input), &output, &opts) {
@ -52,12 +57,10 @@ fn test_it_converts(
} }
}; };
assert_eq!(png.raw.ihdr.color_type, color_type_out); assert_eq!(png.raw.ihdr.color_type.png_header_code(), color_type_out);
assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out); assert_eq!(png.raw.ihdr.bit_depth, bit_depth_out);
if let Some(palette) = png.raw.palette.as_ref() { if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
assert!(palette.len() <= 1 << (png.raw.ihdr.bit_depth.as_u8() as usize)); assert!(palette.len() <= 1 << (png.raw.ihdr.bit_depth.as_u8() as usize));
} else {
assert_ne!(png.raw.ihdr.color_type, ColorType::Indexed);
} }
remove_file(output).ok(); remove_file(output).ok();
@ -68,9 +71,9 @@ fn filter_minsum() {
test_it_converts( test_it_converts(
"tests/files/rgb_16_should_be_rgb_16.png", "tests/files/rgb_16_should_be_rgb_16.png",
RowFilter::MinSum, RowFilter::MinSum,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
ColorType::RGB, RGB,
BitDepth::Sixteen, BitDepth::Sixteen,
); );
} }
@ -80,9 +83,9 @@ fn filter_entropy() {
test_it_converts( test_it_converts(
"tests/files/rgb_8_should_be_rgb_8.png", "tests/files/rgb_8_should_be_rgb_8.png",
RowFilter::Entropy, RowFilter::Entropy,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGB, RGB,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -92,9 +95,9 @@ fn filter_bigrams() {
test_it_converts( test_it_converts(
"tests/files/rgba_8_should_be_rgba_8.png", "tests/files/rgba_8_should_be_rgba_8.png",
RowFilter::Bigrams, RowFilter::Bigrams,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
ColorType::RGBA, RGBA,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -104,9 +107,9 @@ fn filter_bigent() {
test_it_converts( test_it_converts(
"tests/files/grayscale_8_should_be_grayscale_8.png", "tests/files/grayscale_8_should_be_grayscale_8.png",
RowFilter::BigEnt, RowFilter::BigEnt,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
ColorType::Grayscale, GRAYSCALE,
BitDepth::Eight, BitDepth::Eight,
); );
} }
@ -116,9 +119,9 @@ fn filter_brute() {
test_it_converts( test_it_converts(
"tests/files/palette_8_should_be_palette_8.png", "tests/files/palette_8_should_be_palette_8.png",
RowFilter::Brute, RowFilter::Brute,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
ColorType::Indexed, INDEXED,
BitDepth::Eight, BitDepth::Eight,
); );
} }