diff --git a/src/interlace.rs b/src/interlace.rs index aacf2514..81928c7d 100644 --- a/src/interlace.rs +++ b/src/interlace.rs @@ -40,7 +40,7 @@ pub fn interlace_image(png: &PngImage) -> PngImage { passes[6].extend(BitVec::from_elem(8, false)); } } - let bit_vec = BitVec::from_bytes(&line.data); + let bit_vec = BitVec::from_bytes(line.data); for (i, bit) in bit_vec.iter().enumerate() { // Avoid moving padded 0's into new image if i >= (png.ihdr.width * u32::from(bits_per_pixel)) as usize { @@ -105,7 +105,7 @@ pub fn deinterlace_image(png: &PngImage) -> PngImage { let mut pass_constants = interlaced_constants(current_pass); let mut current_y: usize = pass_constants.y_shift as usize; for line in png.scan_lines() { - let bit_vec = BitVec::from_bytes(&line.data); + let bit_vec = BitVec::from_bytes(line.data); let bits_in_line = ((png.ihdr.width - u32::from(pass_constants.x_shift) + u32::from(pass_constants.x_step) - 1) diff --git a/src/png/mod.rs b/src/png/mod.rs index 2c181b36..4df7169b 100644 --- a/src/png/mod.rs +++ b/src/png/mod.rs @@ -293,13 +293,7 @@ impl PngImage { last_pass = line.pass; } last_line.resize(line.data.len(), 0); - unfilter_line( - line.filter, - bpp, - &line.data, - &last_line, - &mut unfiltered_buf, - ); + unfilter_line(line.filter, bpp, line.data, &last_line, &mut unfiltered_buf); unfiltered.push(0); unfiltered.extend_from_slice(&unfiltered_buf); std::mem::swap(&mut last_line, &mut unfiltered_buf); @@ -334,7 +328,7 @@ impl PngImage { 0 }; filtered.push(filter); - filter_line(filter, bpp, &line.data, last_line, &mut f_buf); + filter_line(filter, bpp, line.data, last_line, &mut f_buf); filtered.extend_from_slice(&f_buf); } 5 => { @@ -347,7 +341,7 @@ impl PngImage { // Avoid vertical filtering on first line of each interlacing pass for filter in if last_pass == line.pass { 0..5 } else { 0..2 } { - filter_line(filter, bpp, &line.data, last_line, &mut f_buf); + filter_line(filter, bpp, line.data, last_line, &mut f_buf); let size = f_buf.iter().fold(0_u64, |acc, &x| { let signed = x as i8; acc + i16::from(signed).abs() as u64 diff --git a/src/reduction/bit_depth.rs b/src/reduction/bit_depth.rs index aef295cf..12c837f6 100644 --- a/src/reduction/bit_depth.rs +++ b/src/reduction/bit_depth.rs @@ -108,7 +108,7 @@ pub fn reduce_bit_depth_8_or_less(png: &PngImage, mut minimum_bits: usize) -> Op } } } else { - let bit_vec = BitVec::from_bytes(&line.data); + let bit_vec = BitVec::from_bytes(line.data); for byte in bit_vec.to_bytes() { while minimum_bits < bit_depth { let permutations: &[u8] = if minimum_bits == 1 { @@ -132,7 +132,7 @@ pub fn reduce_bit_depth_8_or_less(png: &PngImage, mut minimum_bits: usize) -> Op let mut reduced = BitVec::with_capacity(png.data.len() * 8); for line in png.scan_lines() { reduced.extend(BitVec::from_bytes(&[line.filter])); - let bit_vec = BitVec::from_bytes(&line.data); + let bit_vec = BitVec::from_bytes(line.data); for (i, bit) in bit_vec.iter().enumerate() { let bit_index = bit_depth - (i % bit_depth); if bit_index <= minimum_bits { diff --git a/tests/filters.rs b/tests/filters.rs index 124baed4..2f482e9b 100644 --- a/tests/filters.rs +++ b/tests/filters.rs @@ -6,14 +6,16 @@ use std::path::Path; use std::path::PathBuf; fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { - let mut options = oxipng::Options::default(); - options.force = true; + let mut options = oxipng::Options { + force: true, + ..Default::default() + }; let mut filter = IndexSet::new(); filter.insert(0); options.filter = filter; ( - OutFile::Path(Some(input.with_extension("out.png").to_owned())), + OutFile::Path(Some(input.with_extension("out.png"))), options, ) } diff --git a/tests/flags.rs b/tests/flags.rs index 6da0ac62..466e16f4 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -6,14 +6,16 @@ use std::path::Path; use std::path::PathBuf; fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { - let mut options = oxipng::Options::default(); - options.force = true; + let mut options = oxipng::Options { + force: true, + ..Default::default() + }; let mut filter = IndexSet::new(); filter.insert(0); options.filter = filter; ( - OutFile::Path(Some(input.with_extension("out.png").to_owned())), + OutFile::Path(Some(input.with_extension("out.png"))), options, ) } @@ -32,7 +34,7 @@ fn test_it_converts( assert_eq!(png.raw.ihdr.color_type, color_type_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) { Ok(_) => (), Err(x) => panic!("{}", x), }; @@ -163,7 +165,7 @@ fn strip_headers_list() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(output).ok(); @@ -197,7 +199,7 @@ fn strip_headers_safe() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(output).ok(); @@ -231,7 +233,7 @@ fn strip_headers_all() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(output).ok(); @@ -265,7 +267,7 @@ fn strip_headers_none() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(output).ok(); @@ -297,7 +299,7 @@ fn interlacing_0_to_1() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(output).ok(); @@ -327,7 +329,7 @@ fn interlacing_1_to_0() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(output).ok(); @@ -359,7 +361,7 @@ fn interlacing_0_to_1_small_files() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(output).ok(); @@ -393,7 +395,7 @@ fn interlacing_1_to_0_small_files() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(output).ok(); @@ -428,7 +430,7 @@ fn interlaced_0_to_1_other_filter_mode() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(output).ok(); @@ -478,7 +480,7 @@ fn fix_errors() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, false) { + let png = match PngData::new(output, false) { Ok(x) => x, Err(x) => { remove_file(output).ok(); diff --git a/tests/interlaced.rs b/tests/interlaced.rs index b7f15afc..65cc0ac2 100644 --- a/tests/interlaced.rs +++ b/tests/interlaced.rs @@ -6,14 +6,16 @@ use std::path::Path; use std::path::PathBuf; fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { - let mut options = oxipng::Options::default(); - options.force = true; + let mut options = oxipng::Options { + force: true, + ..Default::default() + }; let mut filter = IndexSet::new(); filter.insert(0); options.filter = filter; ( - OutFile::Path(Some(input.with_extension("out.png").to_owned())), + OutFile::Path(Some(input.with_extension("out.png"))), options, ) } diff --git a/tests/lib.rs b/tests/lib.rs index cce5520e..8f5e28d1 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,5 +1,3 @@ -use oxipng; - use oxipng::Headers; use oxipng::OutFile; use std::default::Default; diff --git a/tests/reduction.rs b/tests/reduction.rs index 1431c586..0951c628 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -6,14 +6,16 @@ use std::path::Path; use std::path::PathBuf; fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { - let mut options = oxipng::Options::default(); - options.force = true; + let mut options = oxipng::Options { + force: true, + ..Default::default() + }; let mut filter = IndexSet::new(); filter.insert(0); options.filter = filter; ( - OutFile::Path(Some(input.with_extension("out.png").to_owned())), + OutFile::Path(Some(input.with_extension("out.png"))), options, ) } @@ -711,7 +713,7 @@ fn small_files() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(&output).ok(); @@ -743,7 +745,7 @@ fn palette_should_be_reduced_with_dupes() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(&output).ok(); @@ -776,7 +778,7 @@ fn palette_should_be_reduced_with_unused() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(&output).ok(); @@ -809,7 +811,7 @@ fn palette_should_be_reduced_with_both() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(&output).ok(); diff --git a/tests/regression.rs b/tests/regression.rs index 2085741f..17a60f25 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -6,14 +6,16 @@ use std::path::Path; use std::path::PathBuf; fn get_opts(input: &Path) -> (OutFile, oxipng::Options) { - let mut options = oxipng::Options::default(); - options.force = true; + let mut options = oxipng::Options { + force: true, + ..Default::default() + }; let mut filter = IndexSet::new(); filter.insert(0); options.filter = filter; ( - OutFile::Path(Some(input.with_extension("out.png").to_owned())), + OutFile::Path(Some(input.with_extension("out.png"))), options, ) } @@ -99,7 +101,7 @@ fn issue_42() { let output = output.path().unwrap(); assert!(output.exists()); - let png = match PngData::new(&output, opts.fix_errors) { + let png = match PngData::new(output, opts.fix_errors) { Ok(x) => x, Err(x) => { remove_file(output).ok(); @@ -287,12 +289,10 @@ fn issue_92_filter_5() { let input = "tests/files/issue-92.png"; let (_, mut opts) = get_opts(Path::new(input)); opts.filter = [5].iter().cloned().collect(); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-f5-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-f5-out.png"))); test_it_converts( - &input, + input, Some((output, opts)), ColorType::Grayscale, BitDepth::Eight, @@ -308,9 +308,7 @@ fn issue_113_white() { opts.interlace = Some(1); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Black); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-white-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-white-out.png"))); test_it_converts( input, Some((output, opts)), @@ -328,9 +326,7 @@ fn issue_113_black() { opts.interlace = Some(1); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Black); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-black-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-black-out.png"))); test_it_converts( input, Some((output, opts)), @@ -348,9 +344,7 @@ fn issue_113_right() { opts.interlace = Some(1); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Right); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-right-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-right-out.png"))); test_it_converts( input, Some((output, opts)), @@ -368,9 +362,7 @@ fn issue_113_left() { opts.interlace = Some(1); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Left); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-left-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-left-out.png"))); test_it_converts( input, Some((output, opts)), @@ -388,9 +380,7 @@ fn issue_113_up() { opts.interlace = Some(1); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Up); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-up-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-up-out.png"))); test_it_converts( input, Some((output, opts)), @@ -408,9 +398,7 @@ fn issue_113_down() { opts.interlace = Some(1); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Down); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-down-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-down-out.png"))); test_it_converts( input, Some((output, opts)), @@ -440,9 +428,7 @@ fn issue_133_black() { let (_, mut opts) = get_opts(Path::new(input)); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Black); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-black-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-black-out.png"))); test_it_converts( input, Some((output, opts)), @@ -459,9 +445,7 @@ fn issue_133_white() { let (_, mut opts) = get_opts(Path::new(input)); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::White); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-white-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-white-out.png"))); test_it_converts( input, Some((output, opts)), @@ -478,9 +462,7 @@ fn issue_133_up() { let (_, mut opts) = get_opts(Path::new(input)); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Up); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-up-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-up-out.png"))); test_it_converts( input, Some((output, opts)), @@ -497,9 +479,7 @@ fn issue_133_down() { let (_, mut opts) = get_opts(Path::new(input)); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Down); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-down-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-down-out.png"))); test_it_converts( input, Some((output, opts)), @@ -516,9 +496,7 @@ fn issue_133_right() { let (_, mut opts) = get_opts(Path::new(input)); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Right); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-right-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-right-out.png"))); test_it_converts( input, Some((output, opts)), @@ -535,9 +513,7 @@ fn issue_133_left() { let (_, mut opts) = get_opts(Path::new(input)); opts.alphas = IndexSet::new(); opts.alphas.insert(AlphaOptim::Left); - let output = OutFile::Path(Some( - Path::new(input).with_extension("-left-out.png").to_owned(), - )); + let output = OutFile::Path(Some(Path::new(input).with_extension("-left-out.png"))); test_it_converts( input, Some((output, opts)),