diff --git a/benches/deflate.rs b/benches/deflate.rs index d8cc984b..13373182 100644 --- a/benches/deflate.rs +++ b/benches/deflate.rs @@ -3,9 +3,9 @@ extern crate oxipng; extern crate test; -use oxipng::internal_tests::*; -use oxipng::*; use std::path::PathBuf; + +use oxipng::{internal_tests::*, *}; use test::Bencher; #[bench] diff --git a/benches/filters.rs b/benches/filters.rs index 67c701a6..50536b50 100644 --- a/benches/filters.rs +++ b/benches/filters.rs @@ -3,9 +3,9 @@ extern crate oxipng; extern crate test; -use oxipng::internal_tests::*; -use oxipng::*; use std::path::PathBuf; + +use oxipng::{internal_tests::*, *}; use test::Bencher; #[bench] diff --git a/benches/interlacing.rs b/benches/interlacing.rs index 3c17eadc..055734bc 100644 --- a/benches/interlacing.rs +++ b/benches/interlacing.rs @@ -3,9 +3,9 @@ extern crate oxipng; extern crate test; -use oxipng::internal_tests::*; -use oxipng::*; use std::path::PathBuf; + +use oxipng::{internal_tests::*, *}; use test::Bencher; #[bench] diff --git a/benches/reductions.rs b/benches/reductions.rs index cc210fc2..87dd3d3e 100644 --- a/benches/reductions.rs +++ b/benches/reductions.rs @@ -3,9 +3,9 @@ extern crate oxipng; extern crate test; -use oxipng::internal_tests::*; -use oxipng::*; use std::path::PathBuf; + +use oxipng::{internal_tests::*, *}; use test::Bencher; #[bench] diff --git a/benches/strategies.rs b/benches/strategies.rs index c3aab816..ab894b1a 100644 --- a/benches/strategies.rs +++ b/benches/strategies.rs @@ -3,9 +3,9 @@ extern crate oxipng; extern crate test; -use oxipng::internal_tests::*; -use oxipng::*; use std::path::PathBuf; + +use oxipng::{internal_tests::*, *}; use test::Bencher; #[bench] diff --git a/benches/zopfli.rs b/benches/zopfli.rs index 03f83f65..912782fe 100644 --- a/benches/zopfli.rs +++ b/benches/zopfli.rs @@ -3,10 +3,9 @@ extern crate oxipng; extern crate test; -use oxipng::internal_tests::*; -use oxipng::*; -use std::num::NonZeroU8; -use std::path::PathBuf; +use std::{num::NonZeroU8, path::PathBuf}; + +use oxipng::{internal_tests::*, *}; use test::Bencher; // SAFETY: trivially safe. Stopgap solution until const unwrap is stabilized. diff --git a/src/atomicmin.rs b/src/atomicmin.rs index 69a379f2..4f781c3a 100644 --- a/src/atomicmin.rs +++ b/src/atomicmin.rs @@ -1,5 +1,4 @@ -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering::SeqCst; +use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; #[derive(Debug)] pub struct AtomicMin { diff --git a/src/colors.rs b/src/colors.rs index d81b1346..1f33b7e8 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -1,6 +1,7 @@ -use rgb::{RGB16, RGBA8}; use std::{fmt, fmt::Display}; +use rgb::{RGB16, RGBA8}; + use crate::PngError; #[derive(Debug, PartialEq, Eq, Clone)] diff --git a/src/deflate/deflater.rs b/src/deflate/deflater.rs index 175e88a9..ac0f98ee 100644 --- a/src/deflate/deflater.rs +++ b/src/deflate/deflater.rs @@ -1,7 +1,7 @@ -use crate::atomicmin::AtomicMin; -use crate::{PngError, PngResult}; use libdeflater::*; +use crate::{atomicmin::AtomicMin, PngError, PngResult}; + pub fn deflate(data: &[u8], level: u8, max_size: &AtomicMin) -> PngResult> { let mut compressor = Compressor::new(CompressionLvl::new(level.into()).unwrap()); let capacity = max_size diff --git a/src/deflate/mod.rs b/src/deflate/mod.rs index 0e8a65f3..18f4812d 100644 --- a/src/deflate/mod.rs +++ b/src/deflate/mod.rs @@ -1,13 +1,11 @@ mod deflater; -use crate::AtomicMin; -use crate::{PngError, PngResult}; -pub use deflater::crc32; -pub use deflater::deflate; -pub use deflater::inflate; -use std::{fmt, fmt::Display}; - #[cfg(feature = "zopfli")] use std::num::NonZeroU8; +use std::{fmt, fmt::Display}; + +pub use deflater::{crc32, deflate, inflate}; + +use crate::{AtomicMin, PngError, PngResult}; #[cfg(feature = "zopfli")] mod zopfli_oxipng; #[cfg(feature = "zopfli")] diff --git a/src/deflate/zopfli_oxipng.rs b/src/deflate/zopfli_oxipng.rs index 651632a9..cb6e6eb4 100644 --- a/src/deflate/zopfli_oxipng.rs +++ b/src/deflate/zopfli_oxipng.rs @@ -1,6 +1,7 @@ -use crate::{PngError, PngResult}; use std::num::NonZeroU8; +use crate::{PngError, PngResult}; + pub fn deflate(data: &[u8], iterations: NonZeroU8) -> PngResult> { let mut output = Vec::with_capacity(data.len()); let options = zopfli::Options { diff --git a/src/error.rs b/src/error.rs index 550f0316..919c77f0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ +use std::{error::Error, fmt}; + use crate::colors::{BitDepth, ColorType}; -use std::error::Error; -use std::fmt; #[derive(Debug, Clone)] #[non_exhaustive] diff --git a/src/evaluate.rs b/src/evaluate.rs index e7c5c449..d797f075 100644 --- a/src/evaluate.rs +++ b/src/evaluate.rs @@ -1,24 +1,22 @@ //! Check if a reduction makes file smaller, and keep best reductions. //! Works asynchronously when possible -use crate::atomicmin::AtomicMin; -use crate::deflate; -use crate::filters::RowFilter; -use crate::png::PngImage; #[cfg(not(feature = "parallel"))] -use crate::rayon; -use crate::Deadline; -use crate::PngError; +use std::cell::RefCell; +use std::sync::{ + atomic::{AtomicUsize, Ordering::*}, + Arc, +}; + #[cfg(feature = "parallel")] use crossbeam_channel::{unbounded, Receiver, Sender}; use indexmap::IndexSet; use log::trace; use rayon::prelude::*; + #[cfg(not(feature = "parallel"))] -use std::cell::RefCell; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering::*; -use std::sync::Arc; +use crate::rayon; +use crate::{atomicmin::AtomicMin, deflate, filters::RowFilter, png::PngImage, Deadline, PngError}; pub struct Candidate { pub image: Arc, diff --git a/src/filters.rs b/src/filters.rs index a2136139..c265e4ec 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -1,5 +1,4 @@ -use std::mem::transmute; -use std::{fmt, fmt::Display}; +use std::{fmt, fmt::Display, mem::transmute}; use crate::error::PngError; diff --git a/src/headers.rs b/src/headers.rs index adbdd3ba..58dd56d2 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -1,14 +1,15 @@ -use crate::colors::{BitDepth, ColorType}; -use crate::deflate::{crc32, inflate}; -use crate::error::PngError; -use crate::interlace::Interlacing; -use crate::AtomicMin; -use crate::Deflaters; -use crate::PngResult; use indexmap::IndexSet; use log::warn; use rgb::{RGB16, RGBA8}; +use crate::{ + colors::{BitDepth, ColorType}, + deflate::{crc32, inflate}, + error::PngError, + interlace::Interlacing, + AtomicMin, Deflaters, PngResult, +}; + #[derive(Debug, Clone)] /// Headers from the IHDR chunk of the image pub struct IhdrData { diff --git a/src/interlace.rs b/src/interlace.rs index 0293dce1..96b05fd3 100644 --- a/src/interlace.rs +++ b/src/interlace.rs @@ -1,10 +1,9 @@ use std::{fmt, fmt::Display}; -use crate::headers::IhdrData; -use crate::png::PngImage; -use crate::PngError; use bitvec::prelude::*; +use crate::{headers::IhdrData, png::PngImage, PngError}; + #[repr(u8)] #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum Interlacing { diff --git a/src/lib.rs b/src/lib.rs index 35b7489d..8f9122b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,32 +25,40 @@ extern crate rayon; #[cfg(not(feature = "parallel"))] mod rayon; -use crate::atomicmin::AtomicMin; -use crate::evaluate::Evaluator; -use crate::headers::*; -use crate::png::PngData; -use crate::png::PngImage; -use crate::reduction::*; +use std::{ + borrow::Cow, + fs::{File, Metadata}, + io::{stdin, stdout, BufWriter, Read, Write}, + path::Path, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, + time::{Duration, Instant}, +}; + +pub use indexmap::{indexset, IndexSet}; use log::{debug, info, trace, warn}; use rayon::prelude::*; -use std::borrow::Cow; -use std::fs::{File, Metadata}; -use std::io::{stdin, stdout, BufWriter, Read, Write}; -use std::path::Path; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; -use std::time::{Duration, Instant}; - -pub use crate::colors::{BitDepth, ColorType}; -pub use crate::deflate::Deflaters; -pub use crate::error::PngError; -pub use crate::filters::RowFilter; -pub use crate::headers::StripChunks; -pub use crate::interlace::Interlacing; -pub use crate::options::{InFile, Options, OutFile}; -pub use indexmap::{indexset, IndexSet}; pub use rgb::{RGB16, RGBA8}; +use crate::{ + atomicmin::AtomicMin, + evaluate::Evaluator, + headers::*, + png::{PngData, PngImage}, + reduction::*, +}; +pub use crate::{ + colors::{BitDepth, ColorType}, + deflate::Deflaters, + error::PngError, + filters::RowFilter, + headers::StripChunks, + interlace::Interlacing, + options::{InFile, Options, OutFile}, +}; + mod atomicmin; mod colors; mod deflate; @@ -68,12 +76,9 @@ mod sanity_checks; /// Private to oxipng; don't use outside tests and benches #[doc(hidden)] pub mod internal_tests { - pub use crate::atomicmin::*; - pub use crate::deflate::*; - pub use crate::png::*; - pub use crate::reduction::*; #[cfg(feature = "sanity-checks")] pub use crate::sanity_checks::*; + pub use crate::{atomicmin::*, deflate::*, png::*, reduction::*}; } pub type PngResult = Result; diff --git a/src/main.rs b/src/main.rs index 44f281e4..150d3247 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,23 +16,15 @@ #[cfg(not(feature = "parallel"))] mod rayon; +#[cfg(feature = "zopfli")] +use std::num::NonZeroU8; +use std::{ffi::OsString, fs::DirBuilder, io::Write, path::PathBuf, process::exit, time::Duration}; + use clap::{value_parser, Arg, ArgAction, ArgMatches, Command}; use indexmap::IndexSet; use log::{error, warn, Level, LevelFilter}; -use oxipng::Deflaters; -use oxipng::Options; -use oxipng::RowFilter; -use oxipng::StripChunks; -use oxipng::{InFile, OutFile}; +use oxipng::{Deflaters, InFile, Options, OutFile, RowFilter, StripChunks}; use rayon::prelude::*; -use std::ffi::OsString; -use std::fs::DirBuilder; -use std::io::Write; -#[cfg(feature = "zopfli")] -use std::num::NonZeroU8; -use std::path::PathBuf; -use std::process::exit; -use std::time::Duration; fn main() { // Note: clap 'wrap_help' is enabled to automatically wrap lines according to terminal width. diff --git a/src/options.rs b/src/options.rs index 0523f76f..69a99a93 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,13 +1,13 @@ -use log::warn; -use std::fmt; -use std::path::{Path, PathBuf}; -use std::time::Duration; - -use crate::deflate::Deflaters; -use crate::filters::RowFilter; -use crate::headers::StripChunks; -use crate::interlace::Interlacing; +use std::{ + fmt, + path::{Path, PathBuf}, + time::Duration, +}; + use indexmap::{indexset, IndexSet}; +use log::warn; + +use crate::{deflate::Deflaters, filters::RowFilter, headers::StripChunks, interlace::Interlacing}; #[derive(Clone, Debug)] pub enum OutFile { diff --git a/src/png/mod.rs b/src/png/mod.rs index 6502d05e..2aa45b31 100644 --- a/src/png/mod.rs +++ b/src/png/mod.rs @@ -1,20 +1,25 @@ -use crate::colors::{BitDepth, ColorType}; -use crate::deflate; -use crate::error::PngError; -use crate::filters::*; -use crate::headers::*; -use crate::interlace::{deinterlace_image, interlace_image, Interlacing}; -use crate::Options; +use std::{ + fs::File, + io::{BufReader, Read, Write}, + path::Path, + sync::Arc, +}; + use bitvec::bitarr; use libdeflater::{CompressionLvl, Compressor}; use log::warn; use rgb::ComponentSlice; use rustc_hash::FxHashMap; -use std::fs::File; -use std::io::{BufReader, Read, Write}; -use std::iter::Iterator; -use std::path::Path; -use std::sync::Arc; + +use crate::{ + colors::{BitDepth, ColorType}, + deflate, + error::PngError, + filters::*, + headers::*, + interlace::{deinterlace_image, interlace_image, Interlacing}, + Options, +}; pub(crate) mod scan_lines; diff --git a/src/png/scan_lines.rs b/src/png/scan_lines.rs index 0ea33ae1..0c31dd4b 100644 --- a/src/png/scan_lines.rs +++ b/src/png/scan_lines.rs @@ -1,5 +1,4 @@ -use crate::interlace::Interlacing; -use crate::png::PngImage; +use crate::{interlace::Interlacing, png::PngImage}; /// An iterator over the scan lines of a PNG image #[derive(Debug, Clone)] diff --git a/src/reduction/alpha.rs b/src/reduction/alpha.rs index 3115c6cd..f0b408bc 100644 --- a/src/reduction/alpha.rs +++ b/src/reduction/alpha.rs @@ -1,8 +1,10 @@ use rgb::RGB16; -use crate::colors::{BitDepth, ColorType}; -use crate::headers::IhdrData; -use crate::png::PngImage; +use crate::{ + colors::{BitDepth, ColorType}, + headers::IhdrData, + png::PngImage, +}; /// Clean the alpha channel by setting the color of all fully transparent pixels to black pub fn cleaned_alpha_channel(png: &PngImage) -> Option { diff --git a/src/reduction/bit_depth.rs b/src/reduction/bit_depth.rs index e36536b7..6d5c9702 100644 --- a/src/reduction/bit_depth.rs +++ b/src/reduction/bit_depth.rs @@ -1,6 +1,8 @@ -use crate::colors::{BitDepth, ColorType}; -use crate::headers::IhdrData; -use crate::png::PngImage; +use crate::{ + colors::{BitDepth, ColorType}, + headers::IhdrData, + png::PngImage, +}; /// Attempt to reduce a 16-bit image to 8-bit, returning the reduced image if successful #[must_use] diff --git a/src/reduction/color.rs b/src/reduction/color.rs index 277902b1..a8e36adc 100644 --- a/src/reduction/color.rs +++ b/src/reduction/color.rs @@ -1,11 +1,14 @@ -use crate::colors::{BitDepth, ColorType}; -use crate::headers::IhdrData; -use crate::png::PngImage; +use std::hash::{BuildHasherDefault, Hash}; + use indexmap::IndexSet; -use rgb::alt::Gray; -use rgb::{ComponentMap, ComponentSlice, FromSlice, RGB, RGBA}; +use rgb::{alt::Gray, ComponentMap, ComponentSlice, FromSlice, RGB, RGBA}; use rustc_hash::FxHasher; -use std::hash::{BuildHasherDefault, Hash}; + +use crate::{ + colors::{BitDepth, ColorType}, + headers::IhdrData, + png::PngImage, +}; type FxIndexSet = IndexSet>; diff --git a/src/reduction/mod.rs b/src/reduction/mod.rs index a75ce3d2..4ef77650 100644 --- a/src/reduction/mod.rs +++ b/src/reduction/mod.rs @@ -1,10 +1,7 @@ -use crate::evaluate::Evaluator; -use crate::png::PngImage; -use crate::Deadline; -use crate::Deflaters; -use crate::Options; use std::sync::Arc; +use crate::{evaluate::Evaluator, png::PngImage, Deadline, Deflaters, Options}; + pub mod alpha; use crate::alpha::*; pub mod bit_depth; diff --git a/src/reduction/palette.rs b/src/reduction/palette.rs index b717ebc2..aa903559 100644 --- a/src/reduction/palette.rs +++ b/src/reduction/palette.rs @@ -1,11 +1,13 @@ -use crate::colors::{BitDepth, ColorType}; -use crate::headers::IhdrData; -use crate::png::scan_lines::ScanLine; -use crate::png::PngImage; -use crate::Interlacing; use indexmap::IndexSet; use rgb::RGBA8; +use crate::{ + colors::{BitDepth, ColorType}, + headers::IhdrData, + png::{scan_lines::ScanLine, PngImage}, + Interlacing, +}; + /// Attempt to reduce the number of colors in the palette, returning the reduced image if successful #[must_use] pub fn reduced_palette(png: &PngImage, optimize_alpha: bool) -> Option { diff --git a/tests/filters.rs b/tests/filters.rs index 5e2f0931..99984fda 100644 --- a/tests/filters.rs +++ b/tests/filters.rs @@ -1,9 +1,9 @@ -use indexmap::IndexSet; -use oxipng::internal_tests::*; -use oxipng::*; -use std::fs::remove_file; -use std::path::Path; -use std::path::PathBuf; +use std::{ + fs::remove_file, + path::{Path, PathBuf}, +}; + +use oxipng::{internal_tests::*, *}; const GRAYSCALE: u8 = 0; const RGB: u8 = 2; diff --git a/tests/flags.rs b/tests/flags.rs index baf0ea69..f925740a 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -1,15 +1,16 @@ -use indexmap::{indexset, IndexSet}; -use oxipng::internal_tests::*; -use oxipng::*; #[cfg(feature = "filetime")] use std::cell::RefCell; -use std::fs::remove_file; #[cfg(feature = "zopfli")] use std::num::NonZeroU8; #[cfg(feature = "filetime")] use std::ops::Deref; -use std::path::Path; -use std::path::PathBuf; +use std::{ + fs::remove_file, + path::{Path, PathBuf}, +}; + +use indexmap::indexset; +use oxipng::{internal_tests::*, *}; const GRAYSCALE: u8 = 0; const RGB: u8 = 2; @@ -100,13 +101,14 @@ fn test_it_converts( #[test] fn verbose_mode() { - #[cfg(feature = "parallel")] - use crossbeam_channel::{unbounded, Sender}; - use log::{set_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record}; use std::cell::RefCell; #[cfg(not(feature = "parallel"))] use std::sync::mpsc::{channel as unbounded, Sender}; + #[cfg(feature = "parallel")] + use crossbeam_channel::{unbounded, Sender}; + use log::{set_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record}; + // Rust runs tests in parallel by default. // We want to make sure that we verify only logs from our test. // diff --git a/tests/interlaced.rs b/tests/interlaced.rs index 8d7cd6ea..43b3d6a7 100644 --- a/tests/interlaced.rs +++ b/tests/interlaced.rs @@ -1,9 +1,9 @@ -use indexmap::IndexSet; -use oxipng::internal_tests::*; -use oxipng::*; -use std::fs::remove_file; -use std::path::Path; -use std::path::PathBuf; +use std::{ + fs::remove_file, + path::{Path, PathBuf}, +}; + +use oxipng::{internal_tests::*, *}; const GRAYSCALE: u8 = 0; const RGB: u8 = 2; diff --git a/tests/interlacing.rs b/tests/interlacing.rs index 541a0963..fd72df08 100644 --- a/tests/interlacing.rs +++ b/tests/interlacing.rs @@ -1,9 +1,9 @@ -use indexmap::IndexSet; -use oxipng::internal_tests::*; -use oxipng::*; -use std::fs::remove_file; -use std::path::Path; -use std::path::PathBuf; +use std::{ + fs::remove_file, + path::{Path, PathBuf}, +}; + +use oxipng::{internal_tests::*, *}; const RGB: u8 = 2; const INDEXED: u8 = 3; diff --git a/tests/lib.rs b/tests/lib.rs index 91068f4b..24b4ad58 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,7 +1,6 @@ +use std::{fs, fs::File, io::prelude::*}; + use oxipng::*; -use std::fs; -use std::fs::File; -use std::io::prelude::*; #[test] fn optimize_from_memory() { diff --git a/tests/raw.rs b/tests/raw.rs index 107bf5e5..3bf49591 100644 --- a/tests/raw.rs +++ b/tests/raw.rs @@ -1,7 +1,6 @@ -use oxipng::internal_tests::*; -use oxipng::*; -use std::path::PathBuf; -use std::sync::Arc; +use std::{path::PathBuf, sync::Arc}; + +use oxipng::{internal_tests::*, *}; fn get_opts() -> Options { Options { diff --git a/tests/reduction.rs b/tests/reduction.rs index fca6bfc7..221e320d 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -1,9 +1,9 @@ -use indexmap::IndexSet; -use oxipng::internal_tests::*; -use oxipng::*; -use std::fs::remove_file; -use std::path::Path; -use std::path::PathBuf; +use std::{ + fs::remove_file, + path::{Path, PathBuf}, +}; + +use oxipng::{internal_tests::*, *}; const GRAYSCALE: u8 = 0; const RGB: u8 = 2; diff --git a/tests/regression.rs b/tests/regression.rs index 570853bf..f21bd97c 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -1,10 +1,10 @@ -use indexmap::IndexSet; -use oxipng::internal_tests::*; -use oxipng::*; -use std::fs::remove_file; -use std::path::Path; -use std::path::PathBuf; -use std::sync::Arc; +use std::{ + fs::remove_file, + path::{Path, PathBuf}, + sync::Arc, +}; + +use oxipng::{internal_tests::*, *}; const GRAYSCALE: u8 = 0; const RGB: u8 = 2; diff --git a/tests/strategies.rs b/tests/strategies.rs index fb8f3cfb..7f8e0bcc 100644 --- a/tests/strategies.rs +++ b/tests/strategies.rs @@ -1,9 +1,9 @@ -use indexmap::IndexSet; -use oxipng::internal_tests::*; -use oxipng::*; -use std::fs::remove_file; -use std::path::Path; -use std::path::PathBuf; +use std::{ + fs::remove_file, + path::{Path, PathBuf}, +}; + +use oxipng::{internal_tests::*, *}; const GRAYSCALE: u8 = 0; const RGB: u8 = 2;