Add header stripping

This commit is contained in:
Joshua Holmer 2016-01-12 11:06:52 -05:00
parent 922a9d304f
commit 939d886932
2 changed files with 35 additions and 2 deletions

View file

@ -3,6 +3,7 @@ extern crate crc;
extern crate libc; extern crate libc;
extern crate libz_sys; extern crate libz_sys;
use std::collections::HashMap;
use std::collections::HashSet; use std::collections::HashSet;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
@ -73,7 +74,9 @@ pub fn optimize(filepath: &Path, opts: &Options) -> Result<(), String> {
println!(" IDAT size = {} bytes", idat_original_size); println!(" IDAT size = {} bytes", idat_original_size);
println!(" File size = {} bytes", file_original_size); println!(" File size = {} bytes", file_original_size);
} }
// TODO: Bit depth/palette reduction // TODO: Color space reduction
// TODO: 16-bit Bit depth reduction
// TODO: Palette bit depth reduction
// //
// TODO: Apply interlacing changes // TODO: Apply interlacing changes
// //
@ -127,7 +130,10 @@ pub fn optimize(filepath: &Path, opts: &Options) -> Result<(), String> {
} }
} }
// TODO: Perform stripping if opts.strip {
// Strip headers
png.aux_headers = HashMap::new();
}
let output_data = png.output(); let output_data = png.output();
if file_original_size <= output_data.len() && !opts.force { if file_original_size <= output_data.len() && !opts.force {

View file

@ -129,3 +129,30 @@ fn reduce_palette_png() {
assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight);
assert!(png.palette.unwrap().len() == 43 * 3); assert!(png.palette.unwrap().len() == 43 * 3);
} }
#[test]
fn strip_headers() {
let input = PathBuf::from("tests/files/test_rgb.png");
let mut opts = get_opts(&input);
opts.strip = true;
let output = opts.out_file.clone();
match oxipng::optimize(&input, &opts) {
Ok(_) => (),
Err(x) => panic!(x.to_owned())
};
assert!(output.exists());
let png = match png::PngData::new(&output) {
Ok(x) => {
remove_file(output).ok();
x
},
Err(x) => {
remove_file(output).ok();
panic!(x.to_owned())
},
};
assert!(!png.aux_headers.contains_key("tEXt"));
}