Enable clippy with dev feature, and fix several clippy lints
This commit is contained in:
parent
9ebd652a32
commit
e0dfbf3533
3 changed files with 34 additions and 34 deletions
53
src/lib.rs
53
src/lib.rs
|
|
@ -1,3 +1,7 @@
|
||||||
|
#![cfg_attr(feature="dev", feature(plugin))]
|
||||||
|
#![cfg_attr(feature="dev", plugin(clippy))]
|
||||||
|
#![cfg_attr(feature="dev", allow(module_inception))]
|
||||||
|
|
||||||
extern crate bit_vec;
|
extern crate bit_vec;
|
||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
extern crate crc;
|
extern crate crc;
|
||||||
|
|
@ -483,8 +487,7 @@ fn optimize_png(mut png: &mut png::PngData, file_original_size: usize, opts: &Op
|
||||||
let best: Mutex<Option<TrialWithData>> = Mutex::new(None);
|
let best: Mutex<Option<TrialWithData>> = Mutex::new(None);
|
||||||
let combinations = filter.len() * compression.len() * memory.len() * strategies.len();
|
let combinations = filter.len() * compression.len() * memory.len() * strategies.len();
|
||||||
let mut results: Vec<(u8, u8, u8, u8)> = Vec::with_capacity(combinations);
|
let mut results: Vec<(u8, u8, u8, u8)> = Vec::with_capacity(combinations);
|
||||||
let filters: Mutex<HashMap<u8, Vec<u8>>> =
|
let filters: Mutex<HashMap<u8, Vec<u8>>> = Mutex::new(HashMap::with_capacity(filter.len()));
|
||||||
Mutex::new(HashMap::with_capacity(filter.len()));
|
|
||||||
if opts.verbosity.is_some() {
|
if opts.verbosity.is_some() {
|
||||||
writeln!(&mut stderr(), "Trying: {} combinations", combinations).ok();
|
writeln!(&mut stderr(), "Trying: {} combinations", combinations).ok();
|
||||||
}
|
}
|
||||||
|
|
@ -606,31 +609,25 @@ fn optimize_png(mut png: &mut png::PngData, file_original_size: usize, opts: &Op
|
||||||
fn perform_reductions(png: &mut png::PngData, opts: &Options) -> bool {
|
fn perform_reductions(png: &mut png::PngData, opts: &Options) -> bool {
|
||||||
let mut something_changed = false;
|
let mut something_changed = false;
|
||||||
|
|
||||||
if opts.palette_reduction {
|
if opts.palette_reduction && png.reduce_palette() {
|
||||||
if png.reduce_palette() {
|
something_changed = true;
|
||||||
something_changed = true;
|
if opts.verbosity == Some(1) {
|
||||||
if opts.verbosity == Some(1) {
|
report_reduction(png);
|
||||||
report_reduction(png);
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.bit_depth_reduction {
|
if opts.bit_depth_reduction && png.reduce_bit_depth() {
|
||||||
if png.reduce_bit_depth() {
|
something_changed = true;
|
||||||
something_changed = true;
|
if opts.verbosity == Some(1) {
|
||||||
if opts.verbosity == Some(1) {
|
report_reduction(png);
|
||||||
report_reduction(png);
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.color_type_reduction {
|
if opts.color_type_reduction && png.reduce_color_type() {
|
||||||
if png.reduce_color_type() {
|
something_changed = true;
|
||||||
something_changed = true;
|
if opts.verbosity == Some(1) {
|
||||||
if opts.verbosity == Some(1) {
|
report_reduction(png);
|
||||||
report_reduction(png);
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if something_changed && opts.verbosity.is_some() {
|
if something_changed && opts.verbosity.is_some() {
|
||||||
|
|
@ -668,15 +665,15 @@ fn report_reduction(png: &png::PngData) {
|
||||||
|
|
||||||
/// Strip headers from the `PngData` object, as requested by the passed `Options`
|
/// Strip headers from the `PngData` object, as requested by the passed `Options`
|
||||||
fn perform_strip(png: &mut png::PngData, opts: &Options) {
|
fn perform_strip(png: &mut png::PngData, opts: &Options) {
|
||||||
match &opts.strip {
|
match opts.strip {
|
||||||
// Strip headers
|
// Strip headers
|
||||||
&Headers::None => (),
|
Headers::None => (),
|
||||||
&Headers::Some(ref hdrs) => {
|
Headers::Some(ref hdrs) => {
|
||||||
for hdr in hdrs {
|
for hdr in hdrs {
|
||||||
png.aux_headers.remove(hdr);
|
png.aux_headers.remove(hdr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Headers::Safe => {
|
Headers::Safe => {
|
||||||
const PRESERVED_HEADERS: [&'static str; 9] = ["cHRM", "gAMA", "iCCP", "sBIT", "sRGB",
|
const PRESERVED_HEADERS: [&'static str; 9] = ["cHRM", "gAMA", "iCCP", "sBIT", "sRGB",
|
||||||
"bKGD", "hIST", "pHYs", "sPLT"];
|
"bKGD", "hIST", "pHYs", "sPLT"];
|
||||||
let hdrs = png.aux_headers.keys().cloned().collect::<Vec<String>>();
|
let hdrs = png.aux_headers.keys().cloned().collect::<Vec<String>>();
|
||||||
|
|
@ -686,7 +683,7 @@ fn perform_strip(png: &mut png::PngData, opts: &Options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Headers::All => {
|
Headers::All => {
|
||||||
png.aux_headers = HashMap::new();
|
png.aux_headers = HashMap::new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
#![cfg_attr(feature="dev", feature(plugin))]
|
||||||
|
#![cfg_attr(feature="dev", plugin(clippy))]
|
||||||
|
|
||||||
extern crate oxipng;
|
extern crate oxipng;
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
|
||||||
12
src/png.rs
12
src/png.rs
|
|
@ -300,24 +300,24 @@ impl PngData {
|
||||||
// Ancillary headers
|
// Ancillary headers
|
||||||
for (key, header) in self.aux_headers
|
for (key, header) in self.aux_headers
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&(ref key, _)| !(**key == "bKGD" || **key == "hIST" || **key == "tRNS")) {
|
.filter(|&(key, _)| !(*key == "bKGD" || *key == "hIST" || *key == "tRNS")) {
|
||||||
write_png_block(key.as_bytes(), header, &mut output);
|
write_png_block(key.as_bytes(), header, &mut output);
|
||||||
}
|
}
|
||||||
// Palette
|
// Palette
|
||||||
if let Some(ref palette) = self.palette {
|
if let Some(ref palette) = self.palette {
|
||||||
write_png_block(b"PLTE", &palette, &mut output);
|
write_png_block(b"PLTE", palette, &mut output);
|
||||||
if let Some(ref transparency_palette) = self.transparency_palette {
|
if let Some(ref transparency_palette) = self.transparency_palette {
|
||||||
// Transparency pixel
|
// Transparency pixel
|
||||||
write_png_block(b"tRNS", &transparency_palette, &mut output);
|
write_png_block(b"tRNS", transparency_palette, &mut output);
|
||||||
}
|
}
|
||||||
} else if let Some(ref transparency_pixel) = self.transparency_pixel {
|
} else if let Some(ref transparency_pixel) = self.transparency_pixel {
|
||||||
// Transparency pixel
|
// Transparency pixel
|
||||||
write_png_block(b"tRNS", &transparency_pixel, &mut output);
|
write_png_block(b"tRNS", transparency_pixel, &mut output);
|
||||||
}
|
}
|
||||||
// Special ancillary headers that need to come after PLTE but before IDAT
|
// Special ancillary headers that need to come after PLTE but before IDAT
|
||||||
for (key, header) in self.aux_headers
|
for (key, header) in self.aux_headers
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&(ref key, _)| **key == "bKGD" || **key == "hIST" || **key == "tRNS") {
|
.filter(|&(key, _)| *key == "bKGD" || *key == "hIST" || *key == "tRNS") {
|
||||||
write_png_block(key.as_bytes(), header, &mut output);
|
write_png_block(key.as_bytes(), header, &mut output);
|
||||||
}
|
}
|
||||||
// IDAT data
|
// IDAT data
|
||||||
|
|
@ -547,7 +547,7 @@ impl PngData {
|
||||||
}
|
}
|
||||||
|
|
||||||
let unused: Vec<u8> =
|
let unused: Vec<u8> =
|
||||||
(0..indexed_palette.len() as u8).filter(|i| !seen.contains(&i)).collect();
|
(0..indexed_palette.len() as u8).filter(|i| !seen.contains(i)).collect();
|
||||||
|
|
||||||
// Remove unused palette indices
|
// Remove unused palette indices
|
||||||
self.do_palette_reduction(&unused, &mut index_map, &mut indexed_palette);
|
self.do_palette_reduction(&unused, &mut index_map, &mut indexed_palette);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue