Skip to content

Commit ebe6a47

Browse files
committed
Clippy
1 parent f5f45fa commit ebe6a47

22 files changed

+44
-65
lines changed

src/animation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl<'a> Frames<'a> {
2828

2929
impl Iterator for Frames<'_> {
3030
type Item = ImageResult<Frame>;
31+
3132
fn next(&mut self) -> Option<ImageResult<Frame>> {
3233
self.iterator.next()
3334
}
@@ -356,7 +357,7 @@ impl Ord for Ratio {
356357
// We cast the types from `u32` to `u64` in order
357358
// to not overflow the multiplications.
358359

359-
(a as u64 * d as u64).cmp(&(c as u64 * b as u64))
360+
(u64::from(a) * u64::from(d)).cmp(&(u64::from(c) * u64::from(b)))
360361
}
361362
}
362363

src/buffer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ mod test {
15001500
fn slice_buffer() {
15011501
let data = [0; 9];
15021502
let buf: ImageBuffer<Luma<u8>, _> = ImageBuffer::from_raw(3, 3, &data[..]).unwrap();
1503-
assert_eq!(&*buf, &data[..])
1503+
assert_eq!(&*buf, &data[..]);
15041504
}
15051505

15061506
macro_rules! new_buffer_zero_test {
@@ -1535,7 +1535,7 @@ mod test {
15351535
let b = a.get_mut(3 * 10).unwrap();
15361536
*b = 255;
15371537
}
1538-
assert_eq!(a.get_pixel(0, 1)[0], 255)
1538+
assert_eq!(a.get_pixel(0, 1)[0], 255);
15391539
}
15401540

15411541
#[test]

src/codecs/avif/yuv.rs

-20
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ fn qrshr<const PRECISION: i32, const BIT_DEPTH: usize>(val: i32) -> i32 {
265265
/// * `range`: see [YuvIntensityRange]
266266
/// * `matrix`: see [YuvStandardMatrix]
267267
///
268-
///
269268
pub(crate) fn yuv400_to_rgba8(
270269
image: YuvPlanarImage<u8>,
271270
rgba: &mut [u8],
@@ -286,7 +285,6 @@ pub(crate) fn yuv400_to_rgba8(
286285
/// * `range`: see [YuvIntensityRange]
287286
/// * `matrix`: see [YuvStandardMatrix]
288287
///
289-
///
290288
pub(crate) fn yuv400_to_rgba10(
291289
image: YuvPlanarImage<u16>,
292290
rgba: &mut [u16],
@@ -307,7 +305,6 @@ pub(crate) fn yuv400_to_rgba10(
307305
/// * `range`: see [YuvIntensityRange]
308306
/// * `matrix`: see [YuvStandardMatrix]
309307
///
310-
///
311308
pub(crate) fn yuv400_to_rgba12(
312309
image: YuvPlanarImage<u16>,
313310
rgba: &mut [u16],
@@ -328,7 +325,6 @@ pub(crate) fn yuv400_to_rgba12(
328325
/// * `range`: see [YuvIntensityRange]
329326
/// * `matrix`: see [YuvStandardMatrix]
330327
///
331-
///
332328
#[inline]
333329
fn yuv400_to_rgbx_impl<
334330
V: Copy + AsPrimitive<i32> + 'static + Sized,
@@ -447,7 +443,6 @@ where
447443
/// * `range`: see [YuvIntensityRange]
448444
/// * `matrix`: see [YuvStandardMatrix]
449445
///
450-
///
451446
pub(crate) fn yuv420_to_rgba8(
452447
image: YuvPlanarImage<u8>,
453448
rgb: &mut [u8],
@@ -468,7 +463,6 @@ pub(crate) fn yuv420_to_rgba8(
468463
/// * `range`: see [YuvIntensityRange]
469464
/// * `matrix`: see [YuvStandardMatrix]
470465
///
471-
///
472466
pub(crate) fn yuv420_to_rgba10(
473467
image: YuvPlanarImage<u16>,
474468
rgb: &mut [u16],
@@ -489,7 +483,6 @@ pub(crate) fn yuv420_to_rgba10(
489483
/// * `range`: see [YuvIntensityRange]
490484
/// * `matrix`: see [YuvStandardMatrix]
491485
///
492-
///
493486
pub(crate) fn yuv420_to_rgba12(
494487
image: YuvPlanarImage<u16>,
495488
rgb: &mut [u16],
@@ -628,7 +621,6 @@ fn process_halved_chroma_row<
628621
/// * `range`: see [YuvIntensityRange]
629622
/// * `matrix`: see [YuvStandardMatrix]
630623
///
631-
///
632624
#[inline]
633625
fn yuv420_to_rgbx<
634626
V: Copy + AsPrimitive<i32> + 'static + Sized,
@@ -790,7 +782,6 @@ where
790782
/// * `range`: see [YuvIntensityRange]
791783
/// * `matrix`: see [YuvStandardMatrix]
792784
///
793-
///
794785
pub(crate) fn yuv422_to_rgba8(
795786
image: YuvPlanarImage<u8>,
796787
rgb: &mut [u8],
@@ -811,7 +802,6 @@ pub(crate) fn yuv422_to_rgba8(
811802
/// * `range`: see [YuvIntensityRange]
812803
/// * `matrix`: see [YuvStandardMatrix]
813804
///
814-
///
815805
pub(crate) fn yuv422_to_rgba10(
816806
image: YuvPlanarImage<u16>,
817807
rgb: &mut [u16],
@@ -832,7 +822,6 @@ pub(crate) fn yuv422_to_rgba10(
832822
/// * `range`: see [YuvIntensityRange]
833823
/// * `matrix`: see [YuvStandardMatrix]
834824
///
835-
///
836825
pub(crate) fn yuv422_to_rgba12(
837826
image: YuvPlanarImage<u16>,
838827
rgb: &mut [u16],
@@ -853,7 +842,6 @@ pub(crate) fn yuv422_to_rgba12(
853842
/// * `range`: see [YuvIntensityRange]
854843
/// * `matrix`: see [YuvStandardMatrix]
855844
///
856-
///
857845
fn yuv422_to_rgbx_impl<
858846
V: Copy + AsPrimitive<i32> + 'static + Sized,
859847
const CHANNELS: usize,
@@ -979,7 +967,6 @@ where
979967
/// * `range`: see [YuvIntensityRange]
980968
/// * `matrix`: see [YuvStandardMatrix]
981969
///
982-
///
983970
pub(crate) fn yuv444_to_rgba8(
984971
image: YuvPlanarImage<u8>,
985972
rgba: &mut [u8],
@@ -1004,7 +991,6 @@ pub(crate) fn yuv444_to_rgba8(
1004991
/// * `range`: see [YuvIntensityRange]
1005992
/// * `matrix`: see [YuvStandardMatrix]
1006993
///
1007-
///
1008994
pub(super) fn yuv444_to_rgba10(
1009995
image: YuvPlanarImage<u16>,
1010996
rgba: &mut [u16],
@@ -1029,7 +1015,6 @@ pub(super) fn yuv444_to_rgba10(
10291015
/// * `range`: see [YuvIntensityRange]
10301016
/// * `matrix`: see [YuvStandardMatrix]
10311017
///
1032-
///
10331018
pub(super) fn yuv444_to_rgba12(
10341019
image: YuvPlanarImage<u16>,
10351020
rgba: &mut [u16],
@@ -1054,7 +1039,6 @@ pub(super) fn yuv444_to_rgba12(
10541039
/// * `range`: see [YuvIntensityRange]
10551040
/// * `matrix`: see [YuvStandardMatrix]
10561041
///
1057-
///
10581042
#[inline]
10591043
fn yuv444_to_rgbx_impl<
10601044
V: Copy + AsPrimitive<i32> + 'static + Sized,
@@ -1172,7 +1156,6 @@ where
11721156
/// * `rgb`: RGB image layout
11731157
/// * `range`: see [YuvIntensityRange]
11741158
///
1175-
///
11761159
fn gbr_to_rgba8(
11771160
image: YuvPlanarImage<u8>,
11781161
rgb: &mut [u8],
@@ -1191,7 +1174,6 @@ fn gbr_to_rgba8(
11911174
/// * `rgba`: RGBx image layout
11921175
/// * `range`: see [YuvIntensityRange]
11931176
///
1194-
///
11951177
fn gbr_to_rgba10(
11961178
image: YuvPlanarImage<u16>,
11971179
rgba: &mut [u16],
@@ -1210,7 +1192,6 @@ fn gbr_to_rgba10(
12101192
/// * `rgba`: RGBx image layout
12111193
/// * `range`: see [YuvIntensityRange]
12121194
///
1213-
///
12141195
fn gbr_to_rgba12(
12151196
image: YuvPlanarImage<u16>,
12161197
rgba: &mut [u16],
@@ -1229,7 +1210,6 @@ fn gbr_to_rgba12(
12291210
/// * `rgb`: RGB image layout
12301211
/// * `range`: see [YuvIntensityRange]
12311212
///
1232-
///
12331213
#[inline]
12341214
fn gbr_to_rgbx_impl<
12351215
V: Copy + AsPrimitive<i32> + 'static + Sized,

src/codecs/bmp/decoder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ fn set_1bit_pixel_run<'a, T: Iterator<Item = &'a u8>>(
381381
let mut bit = 0x80;
382382
loop {
383383
if let Some(pixel) = pixel_iter.next() {
384-
let rgb = palette[((idx & bit) != 0) as usize];
384+
let rgb = palette[usize::from((idx & bit) != 0)];
385385
pixel[0] = rgb[0];
386386
pixel[1] = rgb[1];
387387
pixel[2] = rgb[2];
@@ -432,7 +432,7 @@ impl Bitfield {
432432
4 => LOOKUP_TABLE_4_BIT_TO_8_BIT[(data & 0b00_1111) as usize],
433433
5 => LOOKUP_TABLE_5_BIT_TO_8_BIT[(data & 0b01_1111) as usize],
434434
6 => LOOKUP_TABLE_6_BIT_TO_8_BIT[(data & 0b11_1111) as usize],
435-
7 => ((data & 0x7f) << 1 | (data & 0x7f) >> 6) as u8,
435+
7 => (((data & 0x7f) << 1) | ((data & 0x7f) >> 6)) as u8,
436436
8 => (data & 0xff) as u8,
437437
_ => panic!(),
438438
}
@@ -1389,9 +1389,9 @@ mod test {
13891389
let bitfield = Bitfield { shift: 0, len };
13901390
for i in 0..(1 << len) {
13911391
let read = bitfield.read(i);
1392-
let calc = (i as f64 / ((1 << len) - 1) as f64 * 255f64).round() as u8;
1392+
let calc = (f64::from(i) / f64::from((1 << len) - 1) * 255f64).round() as u8;
13931393
if read != calc {
1394-
println!("len:{} i:{} read:{} calc:{}", len, i, read, calc);
1394+
println!("len:{len} i:{i} read:{read} calc:{calc}");
13951395
}
13961396
assert_eq!(read, calc);
13971397
}

src/codecs/bmp/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//! # Related Links
66
//! * <https://msdn.microsoft.com/en-us/library/windows/desktop/dd183375%28v=vs.85%29.aspx>
77
//! * <https://en.wikipedia.org/wiki/BMP_file_format>
8-
//!
98
109
pub use self::decoder::BmpDecoder;
1110
pub use self::encoder::BmpEncoder;

src/codecs/gif.rs

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl<R> Read for GifReader<R> {
7676
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
7777
self.0.read(buf)
7878
}
79+
7980
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
8081
if self.0.position() == 0 && buf.is_empty() {
8182
mem::swap(buf, self.0.get_mut());

src/codecs/hdr/encoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ impl<'a> NorunCombineIterator<'a> {
181181
// Combines sequential noruns produced by RunIterator
182182
impl Iterator for NorunCombineIterator<'_> {
183183
type Item = RunOrNot;
184+
184185
fn next(&mut self) -> Option<Self::Item> {
185186
loop {
186187
match self.prev.take() {

src/codecs/hdr/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//!
77
//! * <http://radsite.lbl.gov/radiance/refer/filefmts.pdf>
88
//! * <http://www.graphics.cornell.edu/~bjw/rgbe/rgbe.c>
9-
//!
109
1110
mod decoder;
1211
mod encoder;

src/codecs/jpeg/encoder.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,9 @@ fn encode_coefficient(coefficient: i32) -> (u8, u16) {
822822
#[inline]
823823
fn rgb_to_ycbcr<P: Pixel>(pixel: P) -> (u8, u8, u8) {
824824
let [r, g, b] = pixel.to_rgb().0;
825-
let r: i32 = r.to_u8().unwrap() as i32;
826-
let g: i32 = g.to_u8().unwrap() as i32;
827-
let b: i32 = b.to_u8().unwrap() as i32;
825+
let r: i32 = i32::from(r.to_u8().unwrap());
826+
let g: i32 = i32::from(g.to_u8().unwrap());
827+
let b: i32 = i32::from(b.to_u8().unwrap());
828828

829829
/*
830830
JPEG RGB -> YCbCr is defined as following equations using Bt.601 Full Range matrix:
@@ -1016,7 +1016,7 @@ mod tests {
10161016
let result = encoder.write_image(&img, 65_536, 1, ExtendedColorType::L8);
10171017
match result {
10181018
Err(ImageError::Parameter(err)) => {
1019-
assert_eq!(err.kind(), DimensionMismatch)
1019+
assert_eq!(err.kind(), DimensionMismatch);
10201020
}
10211021
other => {
10221022
panic!(
@@ -1065,7 +1065,7 @@ mod tests {
10651065
build_frame_header(&mut buf, 5, 100, 150, &components);
10661066
assert_eq!(
10671067
buf,
1068-
[5, 0, 150, 0, 100, 2, 1, 1 << 4 | 1, 5, 2, 1 << 4 | 1, 4]
1068+
[5, 0, 150, 0, 100, 2, 1, (1 << 4) | 1, 5, 2, (1 << 4) | 1, 4]
10691069
);
10701070
}
10711071

@@ -1093,7 +1093,7 @@ mod tests {
10931093
},
10941094
];
10951095
build_scan_header(&mut buf, &components);
1096-
assert_eq!(buf, [2, 1, 5 << 4 | 5, 2, 4 << 4 | 4, 0, 63, 0]);
1096+
assert_eq!(buf, [2, 1, (5 << 4) | 5, 2, (4 << 4) | 4, 0, 63, 0]);
10971097
}
10981098

10991099
#[test]
@@ -1123,7 +1123,7 @@ mod tests {
11231123
let mut expected = vec![];
11241124
expected.push(1);
11251125
expected.extend_from_slice(&[0; 64]);
1126-
assert_eq!(buf, expected)
1126+
assert_eq!(buf, expected);
11271127
}
11281128

11291129
#[cfg(feature = "benchmarks")]

src/codecs/jpeg/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//!
66
//! # Related Links
77
//! * <http://www.w3.org/Graphics/JPEG/itu-t81.pdf> - The JPEG specification
8-
//!
98
109
pub use self::decoder::JpegDecoder;
1110
pub use self::encoder::{JpegEncoder, PixelDensity, PixelDensityUnit};

src/codecs/png.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//!
55
//! # Related Links
66
//! * <http://www.w3.org/TR/PNG/> - The PNG Specification
7-
//!
87
98
use std::borrow::Cow;
109
use std::fmt;

src/codecs/pnm/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ fn read_separated_ascii<T: FromStr<Err = ParseIntError>>(reader: &mut dyn Read)
688688
where
689689
T::Err: Display,
690690
{
691-
let is_separator = |v: &u8| matches! { *v, b'\t' | b'\n' | b'\x0b' | b'\x0c' | b'\r' | b' ' };
691+
let is_separator = |v: &u8| matches!(*v, b'\t' | b'\n' | b'\x0b' | b'\x0c' | b'\r' | b' ');
692692

693693
let token = reader
694694
.bytes()

src/codecs/tga/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<R: Read> TgaDecoder<R> {
196196
fn bytes_to_index(bytes: &[u8]) -> usize {
197197
let mut result = 0usize;
198198
for byte in bytes {
199-
result = result << 8 | *byte as usize;
199+
result = (result << 8) | *byte as usize;
200200
}
201201
result
202202
}

src/flat.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ impl<'buf, Subpixel> FlatSamples<&'buf [Subpixel]> {
943943
/// use image::{flat::FlatSamples, GenericImage, RgbImage, Rgb};
944944
///
945945
/// let background = Rgb([20, 20, 20]);
946-
/// let bg = FlatSamples::with_monocolor(&background, 200, 200);;
946+
/// let bg = FlatSamples::with_monocolor(&background, 200, 200);
947947
///
948948
/// let mut image = RgbImage::new(200, 200);
949949
/// paint_something(&mut image);
@@ -986,7 +986,6 @@ impl<'buf, Subpixel> FlatSamples<&'buf [Subpixel]> {
986986
///
987987
/// * For all indices inside bounds, the corresponding index is valid in the buffer
988988
/// * `P::channel_count()` agrees with `self.inner.layout.channels`
989-
///
990989
#[derive(Clone, Debug)]
991990
pub struct View<Buffer, P: Pixel>
992991
where
@@ -1009,7 +1008,6 @@ where
10091008
/// * There is no aliasing of samples
10101009
/// * The samples are packed, i.e. `self.inner.layout.sample_stride == 1`
10111010
/// * `P::channel_count()` agrees with `self.inner.layout.channels`
1012-
///
10131011
#[derive(Clone, Debug)]
10141012
pub struct ViewMut<Buffer, P: Pixel>
10151013
where

src/image.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ impl<I: ?Sized> Clone for Pixels<'_, I> {
880880
/// use image::{GenericImageView, Rgb, RgbImage};
881881
///
882882
/// let buffer = RgbImage::new(10, 10);
883-
/// let image: &dyn GenericImageView<Pixel=Rgb<u8>> = &buffer;
883+
/// let image: &dyn GenericImageView<Pixel = Rgb<u8>> = &buffer;
884884
/// ```
885885
pub trait GenericImageView {
886886
/// The type of pixel.
@@ -1269,6 +1269,7 @@ where
12691269
I: Deref,
12701270
{
12711271
type Target = SubImageInner<I>;
1272+
12721273
fn deref(&self) -> &Self::Target {
12731274
&self.inner
12741275
}

0 commit comments

Comments
 (0)