From 2c7f0a8f48a332c89ee3bdab5094fb84ef835173 Mon Sep 17 00:00:00 2001 From: Josh Holmer Date: Fri, 7 Jul 2023 21:02:26 -0400 Subject: [PATCH] Cargo fmt --- src/deflate/mod.rs | 20 ++++++++------------ src/deflate/zopfli_oxipng.rs | 2 +- src/lib.rs | 12 ++++++++++-- src/main.rs | 4 +++- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/deflate/mod.rs b/src/deflate/mod.rs index d5ac37a5..e9ef7a12 100644 --- a/src/deflate/mod.rs +++ b/src/deflate/mod.rs @@ -4,7 +4,7 @@ use crate::{PngError, PngResult}; pub use deflater::crc32; pub use deflater::deflate; pub use deflater::inflate; -use std::io::{BufWriter, copy, Cursor, Write}; +use std::io::{copy, BufWriter, Cursor, Write}; use std::{fmt, fmt::Display, io}; #[cfg(feature = "zopfli")] @@ -12,9 +12,9 @@ use zopfli::{DeflateEncoder, Options}; #[cfg(feature = "zopfli")] mod zopfli_oxipng; #[cfg(feature = "zopfli")] -pub use zopfli_oxipng::deflate as zopfli_deflate; -#[cfg(feature = "zopfli")] use simd_adler32::Adler32; +#[cfg(feature = "zopfli")] +pub use zopfli_oxipng::deflate as zopfli_deflate; #[derive(Clone, Copy, Debug, PartialEq, Eq)] /// DEFLATE algorithms supported by oxipng @@ -57,7 +57,7 @@ impl Deflater for Deflaters { pub struct BufferedZopfliDeflater { input_buffer_size: usize, output_buffer_size: usize, - options: Options + options: Options, } #[cfg(feature = "zopfli")] @@ -81,14 +81,13 @@ impl Default for BufferedZopfliDeflater { BufferedZopfliDeflater { input_buffer_size: 1024 * 1024, output_buffer_size: 64 * 1024, - options: Options::default() + options: Options::default(), } } } #[cfg(feature = "zopfli")] impl Deflater for BufferedZopfliDeflater { - /// Fork of the zlib_compress function in Zopfli. fn deflate(&self, data: &[u8], max_size: &AtomicMin) -> PngResult> { let mut out = Cursor::new(Vec::with_capacity(self.output_buffer_size)); @@ -101,15 +100,12 @@ impl Deflater for BufferedZopfliDeflater { let out = (|| -> io::Result> { let mut rolling_adler = Adler32::new(); - let mut in_data = zopfli_oxipng::HashingAndCountingRead::new(data, &mut rolling_adler, None); + let mut in_data = + zopfli_oxipng::HashingAndCountingRead::new(data, &mut rolling_adler, None); out.write_all(&cmfflg.to_be_bytes())?; let mut buffer = BufWriter::with_capacity( self.input_buffer_size, - DeflateEncoder::new( - self.options, - Default::default(), - &mut out, - ), + DeflateEncoder::new(self.options, Default::default(), &mut out), ); copy(&mut in_data, &mut buffer)?; buffer.into_inner()?.finish()?; diff --git a/src/deflate/zopfli_oxipng.rs b/src/deflate/zopfli_oxipng.rs index c6c77624..3c6c8d4f 100644 --- a/src/deflate/zopfli_oxipng.rs +++ b/src/deflate/zopfli_oxipng.rs @@ -1,6 +1,6 @@ -use std::io::{Error, ErrorKind, Read}; use crate::{PngError, PngResult}; use simd_adler32::Adler32; +use std::io::{Error, ErrorKind, Read}; pub fn deflate(data: &[u8], options: &zopfli::Options) -> PngResult> { use std::cmp::max; diff --git a/src/lib.rs b/src/lib.rs index c47b54c5..6095de18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -588,7 +588,13 @@ fn optimize_png( } else { Some(png.estimated_output_size()) }; - if let Some(new_png) = optimize_raw(raw.clone(), &opts, deadline.clone(), max_siz, &opts.deflatee) { + if let Some(new_png) = optimize_raw( + raw.clone(), + &opts, + deadline.clone(), + max_siz, + &opts.deflatee, + ) { png.raw = new_png.raw; png.idat_data = new_png.idat_data; } @@ -867,7 +873,9 @@ fn postprocess_chunks( deadline: Arc, orig_ihdr: &IhdrData, deflater: &T, -) where T: Deflater { +) where + T: Deflater, +{ if let Some(iccp_idx) = png.aux_chunks.iter().position(|c| &c.name == b"iCCP") { // See if we can replace an iCCP chunk with an sRGB chunk let may_replace_iccp = opts.strip != StripChunks::None && opts.strip.keep(b"sRGB"); diff --git a/src/main.rs b/src/main.rs index 84c7b12d..422e79d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -516,7 +516,9 @@ fn parse_opts_into_struct( if matches.get_flag("zopfli") { #[cfg(feature = "zopfli")] let zopfli_opts = zopfli::Options::default(); - opts.deflate = Deflaters::Zopfli { options: zopfli_opts }; + opts.deflate = Deflaters::Zopfli { + options: zopfli_opts, + }; } else if let Deflaters::Libdeflater { compression } = &mut opts.deflate { if let Some(x) = matches.get_one::("compression") { *compression = *x as u8;