Clippy fixes (#1985)
This commit is contained in:
parent
23c347e4f2
commit
065c8483e5
23 changed files with 60 additions and 60 deletions
|
|
@ -11,7 +11,7 @@ struct BenchDef {
|
|||
}
|
||||
|
||||
fn load_all(c: &mut Criterion) {
|
||||
const BENCH_DEFS: &'static [BenchDef] = &[
|
||||
const BENCH_DEFS: &[BenchDef] = &[
|
||||
BenchDef {
|
||||
dir: &["bmp", "images"],
|
||||
files: &[
|
||||
|
|
@ -106,4 +106,4 @@ fn bench_load(c: &mut Criterion, def: &BenchDef) {
|
|||
}
|
||||
}
|
||||
|
||||
const IMAGE_DIR: [&'static str; 3] = [".", "tests", "images"];
|
||||
const IMAGE_DIR: [&str; 3] = [".", "tests", "images"];
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ struct BenchDef {
|
|||
}
|
||||
|
||||
fn encode_all(c: &mut Criterion) {
|
||||
const BENCH_DEFS: &'static [BenchDef] = &[
|
||||
const BENCH_DEFS: &[BenchDef] = &[
|
||||
BenchDef {
|
||||
with: &Bmp,
|
||||
name: "bmp",
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ fn main() {
|
|||
|
||||
// Use the open function to load an image from a Path.
|
||||
// ```open``` returns a dynamic image.
|
||||
let im = image::open(&Path::new(&from)).unwrap();
|
||||
let im = image::open(Path::new(&from)).unwrap();
|
||||
// Write the contents of this image using extension guessing.
|
||||
im.save(&Path::new(&into)).unwrap();
|
||||
im.save(Path::new(&into)).unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,6 @@ fn main() {
|
|||
|
||||
// Use the open function to load an image from a Path.
|
||||
// ```open``` returns a dynamic image.
|
||||
let im = image::open(&Path::new(&from)).unwrap();
|
||||
let im = image::open(Path::new(&from)).unwrap();
|
||||
println!("{}", im.as_bytes().len());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ fn main() {
|
|||
|
||||
// Use the open function to load an image from a Path.
|
||||
// ```open``` returns a dynamic image.
|
||||
let im = image::open(&Path::new(&file)).unwrap();
|
||||
let im = image::open(Path::new(&file)).unwrap();
|
||||
|
||||
// The dimensions method returns the images width and height
|
||||
println!("dimensions {:?}", im.dimensions());
|
||||
|
|
@ -24,7 +24,7 @@ fn main() {
|
|||
// The color method returns the image's ColorType
|
||||
println!("{:?}", im.color());
|
||||
|
||||
let fout = &mut File::create(&Path::new(&format!("{}.png", file))).unwrap();
|
||||
let fout = &mut File::create(Path::new(&format!("{}.png", file))).unwrap();
|
||||
|
||||
// Write the contents of this image to the Writer in PNG format.
|
||||
im.write_to(fout, ImageFormat::Png).unwrap();
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ impl fmt::Display for Elapsed {
|
|||
fn fmt(&self, out: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match (self.0.as_secs(), self.0.subsec_nanos()) {
|
||||
(0, n) if n < 1000 => write!(out, "{} ns", n),
|
||||
(0, n) if n < 1000_000 => write!(out, "{} µs", n / 1000),
|
||||
(0, n) => write!(out, "{} ms", n / 1000_000),
|
||||
(0, n) if n < 1_000_000 => write!(out, "{} µs", n / 1000),
|
||||
(0, n) => write!(out, "{} ms", n / 1_000_000),
|
||||
(s, n) if s < 10 => write!(out, "{}.{:02} s", s, n / 10_000_000),
|
||||
(s, _) => write!(out, "{} s", s),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ impl fmt::Display for Elapsed {
|
|||
fn fmt(&self, out: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match (self.0.as_secs(), self.0.subsec_nanos()) {
|
||||
(0, n) if n < 1000 => write!(out, "{} ns", n),
|
||||
(0, n) if n < 1000_000 => write!(out, "{} µs", n / 1000),
|
||||
(0, n) => write!(out, "{} ms", n / 1000_000),
|
||||
(0, n) if n < 1_000_000 => write!(out, "{} µs", n / 1000),
|
||||
(0, n) => write!(out, "{} ms", n / 1_000_000),
|
||||
(s, n) if s < 10 => write!(out, "{}.{:02} s", s, n / 10_000_000),
|
||||
(s, _) => write!(out, "{} s", s),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -720,7 +720,7 @@ impl<R: Read + Seek> BmpDecoder<R> {
|
|||
),
|
||||
));
|
||||
}
|
||||
11 | 12 | 13 => {
|
||||
11..=13 => {
|
||||
// CMYK types are not implemented yet.
|
||||
return Err(ImageError::Unsupported(
|
||||
UnsupportedError::from_format_and_kind(
|
||||
|
|
@ -1428,7 +1428,7 @@ mod test {
|
|||
let mut decoder = super::BmpDecoder::new(f).unwrap();
|
||||
|
||||
let mut buf: Vec<u8> = vec![0; 8 * 8 * 3];
|
||||
decoder.read_rect(0, 0, 8, 8, &mut *buf).unwrap();
|
||||
decoder.read_rect(0, 0, 8, 8, &mut buf).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ mod tests {
|
|||
{
|
||||
let mut encoder = BmpEncoder::new(&mut encoded_data);
|
||||
encoder
|
||||
.encode(&image, width, height, c)
|
||||
.encode(image, width, height, c)
|
||||
.expect("could not encode image");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -267,9 +267,9 @@ impl<R: Read> DdsDecoder<R> {
|
|||
// The enum integer values were taken from https://docs.microsoft.com/en-us/windows/win32/api/dxgiformat/ne-dxgiformat-dxgi_format
|
||||
// DXT1 represents the different BC1 variants, DTX3 represents the different BC2 variants and DTX5 represents the different BC3 variants
|
||||
match dx10_header.dxgi_format {
|
||||
70 | 71 | 72 => DxtVariant::DXT1, // DXGI_FORMAT_BC1_TYPELESS, DXGI_FORMAT_BC1_UNORM or DXGI_FORMAT_BC1_UNORM_SRGB
|
||||
73 | 74 | 75 => DxtVariant::DXT3, // DXGI_FORMAT_BC2_TYPELESS, DXGI_FORMAT_BC2_UNORM or DXGI_FORMAT_BC2_UNORM_SRGB
|
||||
76 | 77 | 78 => DxtVariant::DXT5, // DXGI_FORMAT_BC3_TYPELESS, DXGI_FORMAT_BC3_UNORM or DXGI_FORMAT_BC3_UNORM_SRGB
|
||||
70..=72 => DxtVariant::DXT1, // DXGI_FORMAT_BC1_TYPELESS, DXGI_FORMAT_BC1_UNORM or DXGI_FORMAT_BC1_UNORM_SRGB
|
||||
73..=75 => DxtVariant::DXT3, // DXGI_FORMAT_BC2_TYPELESS, DXGI_FORMAT_BC2_UNORM or DXGI_FORMAT_BC2_UNORM_SRGB
|
||||
76..=78 => DxtVariant::DXT5, // DXGI_FORMAT_BC3_TYPELESS, DXGI_FORMAT_BC3_UNORM or DXGI_FORMAT_BC3_UNORM_SRGB
|
||||
_ => {
|
||||
return Err(ImageError::Unsupported(
|
||||
UnsupportedError::from_format_and_kind(
|
||||
|
|
@ -359,7 +359,7 @@ mod test {
|
|||
#[test]
|
||||
fn dimension_overflow() {
|
||||
// A DXT1 header set to 0xFFFF_FFFC width and height (the highest u32%4 == 0)
|
||||
let header = vec![
|
||||
let header = [
|
||||
0x44, 0x44, 0x53, 0x20, 0x7C, 0x0, 0x0, 0x0, 0x7, 0x10, 0x8, 0x0, 0xFC, 0xFF, 0xFF,
|
||||
0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0x0, 0xC0, 0x12, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0,
|
||||
0x0, 0x49, 0x4D, 0x41, 0x47, 0x45, 0x4D, 0x41, 0x47, 0x49, 0x43, 0x4B, 0x0, 0x0, 0x0,
|
||||
|
|
|
|||
|
|
@ -374,26 +374,26 @@ fn noruncombine_test() {
|
|||
v
|
||||
}
|
||||
|
||||
let v = vec![];
|
||||
let v = [];
|
||||
let mut rsi = NorunCombineIterator::new(&v[..]);
|
||||
assert_eq!(rsi.next(), None);
|
||||
|
||||
let v = vec![1];
|
||||
let v = [1];
|
||||
let mut rsi = NorunCombineIterator::new(&v[..]);
|
||||
assert_eq!(rsi.next(), Some(Norun(0, 1)));
|
||||
assert_eq!(rsi.next(), None);
|
||||
|
||||
let v = vec![2, 2];
|
||||
let v = [2, 2];
|
||||
let mut rsi = NorunCombineIterator::new(&v[..]);
|
||||
assert_eq!(rsi.next(), Some(Norun(0, 2)));
|
||||
assert_eq!(rsi.next(), None);
|
||||
|
||||
let v = vec![3, 3, 3];
|
||||
let v = [3, 3, 3];
|
||||
let mut rsi = NorunCombineIterator::new(&v[..]);
|
||||
assert_eq!(rsi.next(), Some(Run(3, 3)));
|
||||
assert_eq!(rsi.next(), None);
|
||||
|
||||
let v = vec![4, 4, 3, 3, 3];
|
||||
let v = [4, 4, 3, 3, 3];
|
||||
let mut rsi = NorunCombineIterator::new(&v[..]);
|
||||
assert_eq!(rsi.next(), Some(Norun(0, 2)));
|
||||
assert_eq!(rsi.next(), Some(Run(3, 3)));
|
||||
|
|
|
|||
|
|
@ -1058,7 +1058,7 @@ mod tests {
|
|||
let qtable = [0u8; 64];
|
||||
build_quantization_segment(&mut buf, 8, 1, &qtable);
|
||||
let mut expected = vec![];
|
||||
expected.push(0 << 4 | 1);
|
||||
expected.push(1);
|
||||
expected.extend_from_slice(&[0; 64]);
|
||||
assert_eq!(buf, expected)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1051,7 +1051,7 @@ ENDHDR
|
|||
fn pbm_binary() {
|
||||
// The data contains two rows of the image (each line is padded to the full byte). For
|
||||
// comments on its format, see documentation of `impl SampleType for PbmBit`.
|
||||
let pbmbinary = [&b"P4 6 2\n"[..], &[0b01101100 as u8, 0b10110111]].concat();
|
||||
let pbmbinary = [&b"P4 6 2\n"[..], &[0b01101100_u8, 0b10110111]].concat();
|
||||
let decoder = PnmDecoder::new(&pbmbinary[..]).unwrap();
|
||||
assert_eq!(decoder.color_type(), ColorType::L8);
|
||||
assert_eq!(decoder.original_color_type(), ExtendedColorType::L1);
|
||||
|
|
@ -1260,7 +1260,7 @@ ENDHDR
|
|||
|
||||
#[test]
|
||||
fn issue_1616_overflow() {
|
||||
let data = vec![
|
||||
let data = [
|
||||
80, 54, 10, 52, 50, 57, 52, 56, 50, 57, 52, 56, 35, 56, 10, 52, 10, 48, 10, 12, 12, 56,
|
||||
];
|
||||
// Validate: we have a header. Note: we might already calculate that this will fail but
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ mod tests {
|
|||
{
|
||||
let encoder = TgaEncoder::new(&mut encoded_data);
|
||||
encoder
|
||||
.encode(&image, width, height, c)
|
||||
.encode(image, width, height, c)
|
||||
.expect("could not encode image");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -735,7 +735,7 @@ mod tests {
|
|||
let mut output = Vec::new();
|
||||
super::WebPEncoder::new_lossless(&mut output)
|
||||
.write_image(
|
||||
&img.inner_pixels(),
|
||||
img.inner_pixels(),
|
||||
img.width(),
|
||||
img.height(),
|
||||
crate::ColorType::Rgba8,
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ impl HuffmanTree {
|
|||
return Err(DecoderError::HuffmanError.into());
|
||||
}
|
||||
|
||||
let mut code_length_hist = vec![0; MAX_ALLOWED_CODE_LENGTH + 1];
|
||||
let mut code_length_hist = [0; MAX_ALLOWED_CODE_LENGTH + 1];
|
||||
|
||||
for &length in code_lengths.iter() {
|
||||
code_length_hist[usize::from(length)] += 1;
|
||||
|
|
@ -78,7 +78,7 @@ impl HuffmanTree {
|
|||
code_length_hist[0] = 0;
|
||||
|
||||
let mut curr_code = 0;
|
||||
let mut next_codes = vec![None; MAX_ALLOWED_CODE_LENGTH + 1];
|
||||
let mut next_codes = [None; MAX_ALLOWED_CODE_LENGTH + 1];
|
||||
|
||||
for code_len in 1..=usize::from(max_code_length) {
|
||||
curr_code = (curr_code + code_length_hist[code_len - 1]) << 1;
|
||||
|
|
|
|||
32
src/color.rs
32
src/color.rs
|
|
@ -879,26 +879,26 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_blend_luma_alpha() {
|
||||
let ref mut a = LumaA([255 as u8, 255]);
|
||||
let b = LumaA([255 as u8, 255]);
|
||||
let a = &mut LumaA([255_u8, 255]);
|
||||
let b = LumaA([255_u8, 255]);
|
||||
a.blend(&b);
|
||||
assert_eq!(a.0[0], 255);
|
||||
assert_eq!(a.0[1], 255);
|
||||
|
||||
let ref mut a = LumaA([255 as u8, 0]);
|
||||
let b = LumaA([255 as u8, 255]);
|
||||
let a = &mut LumaA([255_u8, 0]);
|
||||
let b = LumaA([255_u8, 255]);
|
||||
a.blend(&b);
|
||||
assert_eq!(a.0[0], 255);
|
||||
assert_eq!(a.0[1], 255);
|
||||
|
||||
let ref mut a = LumaA([255 as u8, 255]);
|
||||
let b = LumaA([255 as u8, 0]);
|
||||
let a = &mut LumaA([255_u8, 255]);
|
||||
let b = LumaA([255_u8, 0]);
|
||||
a.blend(&b);
|
||||
assert_eq!(a.0[0], 255);
|
||||
assert_eq!(a.0[1], 255);
|
||||
|
||||
let ref mut a = LumaA([255 as u8, 0]);
|
||||
let b = LumaA([255 as u8, 0]);
|
||||
let a = &mut LumaA([255_u8, 0]);
|
||||
let b = LumaA([255_u8, 0]);
|
||||
a.blend(&b);
|
||||
assert_eq!(a.0[0], 255);
|
||||
assert_eq!(a.0[1], 0);
|
||||
|
|
@ -906,23 +906,23 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_blend_rgba() {
|
||||
let ref mut a = Rgba([255 as u8, 255, 255, 255]);
|
||||
let b = Rgba([255 as u8, 255, 255, 255]);
|
||||
let a = &mut Rgba([255_u8, 255, 255, 255]);
|
||||
let b = Rgba([255_u8, 255, 255, 255]);
|
||||
a.blend(&b);
|
||||
assert_eq!(a.0, [255, 255, 255, 255]);
|
||||
|
||||
let ref mut a = Rgba([255 as u8, 255, 255, 0]);
|
||||
let b = Rgba([255 as u8, 255, 255, 255]);
|
||||
let a = &mut Rgba([255_u8, 255, 255, 0]);
|
||||
let b = Rgba([255_u8, 255, 255, 255]);
|
||||
a.blend(&b);
|
||||
assert_eq!(a.0, [255, 255, 255, 255]);
|
||||
|
||||
let ref mut a = Rgba([255 as u8, 255, 255, 255]);
|
||||
let b = Rgba([255 as u8, 255, 255, 0]);
|
||||
let a = &mut Rgba([255_u8, 255, 255, 255]);
|
||||
let b = Rgba([255_u8, 255, 255, 0]);
|
||||
a.blend(&b);
|
||||
assert_eq!(a.0, [255, 255, 255, 255]);
|
||||
|
||||
let ref mut a = Rgba([255 as u8, 255, 255, 0]);
|
||||
let b = Rgba([255 as u8, 255, 255, 0]);
|
||||
let a = &mut Rgba([255_u8, 255, 255, 0]);
|
||||
let b = Rgba([255_u8, 255, 255, 0]);
|
||||
a.blend(&b);
|
||||
assert_eq!(a.0, [255, 255, 255, 0]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1344,7 +1344,7 @@ mod test {
|
|||
let pixels = vec![65535u16; 64 * 64];
|
||||
let img = super::ImageBuffer::from_vec(64, 64, pixels).unwrap();
|
||||
|
||||
let img = super::DynamicImage::ImageLuma16(img.into());
|
||||
let img = super::DynamicImage::ImageLuma16(img);
|
||||
assert!(img.as_luma16().is_some());
|
||||
|
||||
let bytes: Vec<u8> = img.into_bytes();
|
||||
|
|
|
|||
|
|
@ -1877,7 +1877,7 @@ mod tests {
|
|||
#[test]
|
||||
fn image_formats_are_recognized() {
|
||||
use ImageFormat::*;
|
||||
const ALL_FORMATS: &'static [ImageFormat] = &[
|
||||
const ALL_FORMATS: &[ImageFormat] = &[
|
||||
Avif, Png, Jpeg, Gif, WebP, Pnm, Tiff, Tga, Dds, Bmp, Ico, Hdr, Farbfeld, OpenExr,
|
||||
];
|
||||
for &format in ALL_FORMATS {
|
||||
|
|
|
|||
|
|
@ -1025,7 +1025,7 @@ mod tests {
|
|||
#[cfg(feature = "png")]
|
||||
fn test_resize_same_size() {
|
||||
use std::path::Path;
|
||||
let img = crate::open(&Path::new("./examples/fractal.png")).unwrap();
|
||||
let img = crate::open(Path::new("./examples/fractal.png")).unwrap();
|
||||
let resize = img.resize(img.width(), img.height(), FilterType::Triangle);
|
||||
assert!(img.pixels().eq(resize.pixels()))
|
||||
}
|
||||
|
|
@ -1034,7 +1034,7 @@ mod tests {
|
|||
#[cfg(feature = "png")]
|
||||
fn test_sample_bilinear() {
|
||||
use std::path::Path;
|
||||
let img = crate::open(&Path::new("./examples/fractal.png")).unwrap();
|
||||
let img = crate::open(Path::new("./examples/fractal.png")).unwrap();
|
||||
assert!(sample_bilinear(&img, 0., 0.).is_some());
|
||||
assert!(sample_bilinear(&img, 1., 0.).is_some());
|
||||
assert!(sample_bilinear(&img, 0., 1.).is_some());
|
||||
|
|
@ -1053,7 +1053,7 @@ mod tests {
|
|||
#[cfg(feature = "png")]
|
||||
fn test_sample_nearest() {
|
||||
use std::path::Path;
|
||||
let img = crate::open(&Path::new("./examples/fractal.png")).unwrap();
|
||||
let img = crate::open(Path::new("./examples/fractal.png")).unwrap();
|
||||
assert!(sample_nearest(&img, 0., 0.).is_some());
|
||||
assert!(sample_nearest(&img, 1., 0.).is_some());
|
||||
assert!(sample_nearest(&img, 0., 1.).is_some());
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ mod test {
|
|||
if new_w as u64 * 400u64 >= old_w as u64 * u64::from(u32::MAX) { return true; }
|
||||
|
||||
let result = super::resize_dimensions(old_w, 400, new_w, ::std::u32::MAX, false);
|
||||
let exact = (400 as f64 * new_w as f64 / old_w as f64).round() as u32;
|
||||
let exact = (400_f64 * new_w as f64 / old_w as f64).round() as u32;
|
||||
result.0 == new_w && result.1 == exact.max(1)
|
||||
}
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ mod test {
|
|||
if 400u64 * new_h as u64 >= old_h as u64 * u64::from(u32::MAX) { return true; }
|
||||
|
||||
let result = super::resize_dimensions(400, old_h, ::std::u32::MAX, new_h, false);
|
||||
let exact = (400 as f64 * new_h as f64 / old_h as f64).round() as u32;
|
||||
let exact = (400_f64 * new_h as f64 / old_h as f64).round() as u32;
|
||||
result.1 == new_h && result.0 == exact.max(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,11 +117,11 @@ impl std::str::FromStr for ReferenceTestCase {
|
|||
|
||||
if meta.len() == 1 {
|
||||
// `CRC`
|
||||
crc = parse_crc(&meta[0]).ok_or("malformed CRC")?;
|
||||
crc = parse_crc(meta[0]).ok_or("malformed CRC")?;
|
||||
kind = ReferenceTestKind::SingleImage;
|
||||
} else if meta.len() == 3 && meta[0] == "anim" {
|
||||
// `anim_FRAME_CRC`
|
||||
crc = parse_crc(&meta[2]).ok_or("malformed CRC")?;
|
||||
crc = parse_crc(meta[2]).ok_or("malformed CRC")?;
|
||||
let frame: usize = meta[1].parse().map_err(|_| "malformed frame number")?;
|
||||
kind = ReferenceTestKind::AnimatedFrame {
|
||||
frame: frame.checked_sub(1).ok_or("frame number must be 1-based")?,
|
||||
|
|
@ -211,7 +211,7 @@ fn check_references() {
|
|||
};
|
||||
|
||||
// Select a single frame
|
||||
let frame = frames.drain(frame_num..).nth(0).unwrap();
|
||||
let frame = frames.drain(frame_num..).next().unwrap();
|
||||
|
||||
// Convert the frame to a`RgbaImage`
|
||||
test_img = Some(DynamicImage::from(frame.into_buffer()));
|
||||
|
|
@ -239,7 +239,7 @@ fn check_references() {
|
|||
};
|
||||
|
||||
// Select a single frame
|
||||
let frame = frames.drain(frame_num..).nth(0).unwrap();
|
||||
let frame = frames.drain(frame_num..).next().unwrap();
|
||||
|
||||
// Convert the frame to a`RgbaImage`
|
||||
test_img = Some(DynamicImage::from(frame.into_buffer()));
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ use std::path::PathBuf;
|
|||
extern crate glob;
|
||||
extern crate image;
|
||||
|
||||
const BASE_PATH: [&'static str; 2] = [".", "tests"];
|
||||
const IMAGE_DIR: &'static str = "images";
|
||||
const BASE_PATH: [&str; 2] = [".", "tests"];
|
||||
const IMAGE_DIR: &str = "images";
|
||||
|
||||
fn process_images<F>(dir: &str, input_decoder: Option<&str>, func: F)
|
||||
where
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue