* Add .whitesource configuration file * Experimental: allow Zopfli to use any size BufWriter * Allow user to specify the output buffer size as well * Allow user to specify maximum block splits * Reformat and fix warnings * Use deflater on iCCP chunk as well * Bug fix: need to implement Zlib format * Make functions const when possible * Switch to using zopfli::Options in prep for https://github.com/zopfli-rs/zopfli/pull/21 * Switch to using zopfli::Options in prep for https://github.com/zopfli-rs/zopfli/pull/21 * Cargo fmt * Fix compilation * Fix tests * Fix more lints * Fix more lints * Fix compilation more --------- Co-authored-by: mend-bolt-for-github[bot] <42819689+mend-bolt-for-github[bot]@users.noreply.github.com> Co-authored-by: Chris Hennick <hennickc@amazon.com> Co-authored-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
99 lines
2.3 KiB
Rust
99 lines
2.3 KiB
Rust
use oxipng::internal_tests::*;
|
|
use oxipng::*;
|
|
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
|
|
fn get_opts() -> Options {
|
|
Options {
|
|
force: true,
|
|
filter: indexset! { RowFilter::None },
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
fn test_it_converts(input: &str) {
|
|
let input = PathBuf::from(input);
|
|
let opts = get_opts();
|
|
let deflater = BufferedZopfliDeflater::default();
|
|
|
|
let original_data = PngData::read_file(&PathBuf::from(input)).unwrap();
|
|
let image = PngData::from_slice(&original_data, &opts).unwrap();
|
|
let png = Arc::try_unwrap(image.raw).unwrap();
|
|
|
|
let num_chunks = image.aux_chunks.len();
|
|
assert!(num_chunks > 0);
|
|
|
|
let mut raw = RawImage::new(
|
|
png.ihdr.width,
|
|
png.ihdr.height,
|
|
png.ihdr.color_type,
|
|
png.ihdr.bit_depth,
|
|
png.data,
|
|
)
|
|
.unwrap();
|
|
|
|
for chunk in image.aux_chunks {
|
|
raw.add_png_chunk(chunk.name, chunk.data);
|
|
}
|
|
|
|
let output = raw.create_optimized_png(&opts, &deflater).unwrap();
|
|
|
|
let new = PngData::from_slice(&output, &opts).unwrap();
|
|
assert!(new.aux_chunks.len() == num_chunks);
|
|
|
|
#[cfg(feature = "sanity-checks")]
|
|
assert!(validate_output(&output, &original_data));
|
|
}
|
|
|
|
#[test]
|
|
fn from_file() {
|
|
test_it_converts("tests/files/raw_api.png");
|
|
}
|
|
|
|
#[test]
|
|
fn custom_indexed() {
|
|
let opts = get_opts();
|
|
let deflater = BufferedZopfliDeflater::default();
|
|
|
|
let raw = RawImage::new(
|
|
4,
|
|
4,
|
|
ColorType::Indexed {
|
|
palette: vec![
|
|
RGBA8::new(255, 255, 255, 255),
|
|
RGBA8::new(255, 0, 0, 255),
|
|
RGBA8::new(0, 255, 0, 255),
|
|
RGBA8::new(0, 0, 255, 255),
|
|
],
|
|
},
|
|
BitDepth::Eight,
|
|
vec![0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3],
|
|
)
|
|
.unwrap();
|
|
|
|
raw.create_optimized_png(&opts, &deflater).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_depth() {
|
|
RawImage::new(
|
|
2,
|
|
2,
|
|
ColorType::RGBA,
|
|
BitDepth::Four,
|
|
vec![0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3],
|
|
)
|
|
.expect_err("Expected invalid depth for color type");
|
|
}
|
|
|
|
#[test]
|
|
fn incorrect_length() {
|
|
RawImage::new(
|
|
2,
|
|
2,
|
|
ColorType::RGBA,
|
|
BitDepth::Eight,
|
|
vec![0, 0, 1, 1, 0, 0, 1, 1],
|
|
)
|
|
.expect_err("Expected incorrect data length");
|
|
}
|