From ebe6a475bb5c795b4236dbb65d2b8df9287998c9 Mon Sep 17 00:00:00 2001 From: Kornel Date: Mon, 6 Jan 2025 11:40:54 +0000 Subject: [PATCH] Clippy --- src/animation.rs | 3 ++- src/buffer.rs | 4 ++-- src/codecs/avif/yuv.rs | 20 -------------------- src/codecs/bmp/decoder.rs | 8 ++++---- src/codecs/bmp/mod.rs | 1 - src/codecs/gif.rs | 1 + src/codecs/hdr/encoder.rs | 1 + src/codecs/hdr/mod.rs | 1 - src/codecs/jpeg/encoder.rs | 14 +++++++------- src/codecs/jpeg/mod.rs | 1 - src/codecs/png.rs | 1 - src/codecs/pnm/decoder.rs | 2 +- src/codecs/tga/decoder.rs | 2 +- src/flat.rs | 4 +--- src/image.rs | 3 ++- src/imageops/colorops.rs | 11 +++++------ src/imageops/fast_blur.rs | 7 ++++--- src/imageops/mod.rs | 5 ++--- src/imageops/sample.rs | 4 ++-- src/math/utils.rs | 8 ++++---- src/metadata.rs | 6 ++++-- src/utils/mod.rs | 2 +- 22 files changed, 44 insertions(+), 65 deletions(-) diff --git a/src/animation.rs b/src/animation.rs index 262ff38d6f..f6dac64247 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -28,6 +28,7 @@ impl<'a> Frames<'a> { impl Iterator for Frames<'_> { type Item = ImageResult; + fn next(&mut self) -> Option> { self.iterator.next() } @@ -356,7 +357,7 @@ impl Ord for Ratio { // We cast the types from `u32` to `u64` in order // to not overflow the multiplications. - (a as u64 * d as u64).cmp(&(c as u64 * b as u64)) + (u64::from(a) * u64::from(d)).cmp(&(u64::from(c) * u64::from(b))) } } diff --git a/src/buffer.rs b/src/buffer.rs index 269d446fc8..40a1c245b3 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1500,7 +1500,7 @@ mod test { fn slice_buffer() { let data = [0; 9]; let buf: ImageBuffer, _> = ImageBuffer::from_raw(3, 3, &data[..]).unwrap(); - assert_eq!(&*buf, &data[..]) + assert_eq!(&*buf, &data[..]); } macro_rules! new_buffer_zero_test { @@ -1535,7 +1535,7 @@ mod test { let b = a.get_mut(3 * 10).unwrap(); *b = 255; } - assert_eq!(a.get_pixel(0, 1)[0], 255) + assert_eq!(a.get_pixel(0, 1)[0], 255); } #[test] diff --git a/src/codecs/avif/yuv.rs b/src/codecs/avif/yuv.rs index e0c70174e6..62190c9038 100644 --- a/src/codecs/avif/yuv.rs +++ b/src/codecs/avif/yuv.rs @@ -265,7 +265,6 @@ fn qrshr(val: i32) -> i32 { /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(crate) fn yuv400_to_rgba8( image: YuvPlanarImage, rgba: &mut [u8], @@ -286,7 +285,6 @@ pub(crate) fn yuv400_to_rgba8( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(crate) fn yuv400_to_rgba10( image: YuvPlanarImage, rgba: &mut [u16], @@ -307,7 +305,6 @@ pub(crate) fn yuv400_to_rgba10( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(crate) fn yuv400_to_rgba12( image: YuvPlanarImage, rgba: &mut [u16], @@ -328,7 +325,6 @@ pub(crate) fn yuv400_to_rgba12( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// #[inline] fn yuv400_to_rgbx_impl< V: Copy + AsPrimitive + 'static + Sized, @@ -447,7 +443,6 @@ where /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(crate) fn yuv420_to_rgba8( image: YuvPlanarImage, rgb: &mut [u8], @@ -468,7 +463,6 @@ pub(crate) fn yuv420_to_rgba8( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(crate) fn yuv420_to_rgba10( image: YuvPlanarImage, rgb: &mut [u16], @@ -489,7 +483,6 @@ pub(crate) fn yuv420_to_rgba10( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(crate) fn yuv420_to_rgba12( image: YuvPlanarImage, rgb: &mut [u16], @@ -628,7 +621,6 @@ fn process_halved_chroma_row< /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// #[inline] fn yuv420_to_rgbx< V: Copy + AsPrimitive + 'static + Sized, @@ -790,7 +782,6 @@ where /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(crate) fn yuv422_to_rgba8( image: YuvPlanarImage, rgb: &mut [u8], @@ -811,7 +802,6 @@ pub(crate) fn yuv422_to_rgba8( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(crate) fn yuv422_to_rgba10( image: YuvPlanarImage, rgb: &mut [u16], @@ -832,7 +822,6 @@ pub(crate) fn yuv422_to_rgba10( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(crate) fn yuv422_to_rgba12( image: YuvPlanarImage, rgb: &mut [u16], @@ -853,7 +842,6 @@ pub(crate) fn yuv422_to_rgba12( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// fn yuv422_to_rgbx_impl< V: Copy + AsPrimitive + 'static + Sized, const CHANNELS: usize, @@ -979,7 +967,6 @@ where /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(crate) fn yuv444_to_rgba8( image: YuvPlanarImage, rgba: &mut [u8], @@ -1004,7 +991,6 @@ pub(crate) fn yuv444_to_rgba8( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(super) fn yuv444_to_rgba10( image: YuvPlanarImage, rgba: &mut [u16], @@ -1029,7 +1015,6 @@ pub(super) fn yuv444_to_rgba10( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// pub(super) fn yuv444_to_rgba12( image: YuvPlanarImage, rgba: &mut [u16], @@ -1054,7 +1039,6 @@ pub(super) fn yuv444_to_rgba12( /// * `range`: see [YuvIntensityRange] /// * `matrix`: see [YuvStandardMatrix] /// -/// #[inline] fn yuv444_to_rgbx_impl< V: Copy + AsPrimitive + 'static + Sized, @@ -1172,7 +1156,6 @@ where /// * `rgb`: RGB image layout /// * `range`: see [YuvIntensityRange] /// -/// fn gbr_to_rgba8( image: YuvPlanarImage, rgb: &mut [u8], @@ -1191,7 +1174,6 @@ fn gbr_to_rgba8( /// * `rgba`: RGBx image layout /// * `range`: see [YuvIntensityRange] /// -/// fn gbr_to_rgba10( image: YuvPlanarImage, rgba: &mut [u16], @@ -1210,7 +1192,6 @@ fn gbr_to_rgba10( /// * `rgba`: RGBx image layout /// * `range`: see [YuvIntensityRange] /// -/// fn gbr_to_rgba12( image: YuvPlanarImage, rgba: &mut [u16], @@ -1229,7 +1210,6 @@ fn gbr_to_rgba12( /// * `rgb`: RGB image layout /// * `range`: see [YuvIntensityRange] /// -/// #[inline] fn gbr_to_rgbx_impl< V: Copy + AsPrimitive + 'static + Sized, diff --git a/src/codecs/bmp/decoder.rs b/src/codecs/bmp/decoder.rs index 88339d7eef..109470cbf8 100644 --- a/src/codecs/bmp/decoder.rs +++ b/src/codecs/bmp/decoder.rs @@ -381,7 +381,7 @@ fn set_1bit_pixel_run<'a, T: Iterator>( let mut bit = 0x80; loop { if let Some(pixel) = pixel_iter.next() { - let rgb = palette[((idx & bit) != 0) as usize]; + let rgb = palette[usize::from((idx & bit) != 0)]; pixel[0] = rgb[0]; pixel[1] = rgb[1]; pixel[2] = rgb[2]; @@ -432,7 +432,7 @@ impl Bitfield { 4 => LOOKUP_TABLE_4_BIT_TO_8_BIT[(data & 0b00_1111) as usize], 5 => LOOKUP_TABLE_5_BIT_TO_8_BIT[(data & 0b01_1111) as usize], 6 => LOOKUP_TABLE_6_BIT_TO_8_BIT[(data & 0b11_1111) as usize], - 7 => ((data & 0x7f) << 1 | (data & 0x7f) >> 6) as u8, + 7 => (((data & 0x7f) << 1) | ((data & 0x7f) >> 6)) as u8, 8 => (data & 0xff) as u8, _ => panic!(), } @@ -1389,9 +1389,9 @@ mod test { let bitfield = Bitfield { shift: 0, len }; for i in 0..(1 << len) { let read = bitfield.read(i); - let calc = (i as f64 / ((1 << len) - 1) as f64 * 255f64).round() as u8; + let calc = (f64::from(i) / f64::from((1 << len) - 1) * 255f64).round() as u8; if read != calc { - println!("len:{} i:{} read:{} calc:{}", len, i, read, calc); + println!("len:{len} i:{i} read:{read} calc:{calc}"); } assert_eq!(read, calc); } diff --git a/src/codecs/bmp/mod.rs b/src/codecs/bmp/mod.rs index 549b1cf33c..8498d39078 100644 --- a/src/codecs/bmp/mod.rs +++ b/src/codecs/bmp/mod.rs @@ -5,7 +5,6 @@ //! # Related Links //! * //! * -//! pub use self::decoder::BmpDecoder; pub use self::encoder::BmpEncoder; diff --git a/src/codecs/gif.rs b/src/codecs/gif.rs index f77766d97b..f67a161306 100644 --- a/src/codecs/gif.rs +++ b/src/codecs/gif.rs @@ -76,6 +76,7 @@ impl Read for GifReader { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.0.read(buf) } + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { if self.0.position() == 0 && buf.is_empty() { mem::swap(buf, self.0.get_mut()); diff --git a/src/codecs/hdr/encoder.rs b/src/codecs/hdr/encoder.rs index 598ad539d9..9358cda321 100644 --- a/src/codecs/hdr/encoder.rs +++ b/src/codecs/hdr/encoder.rs @@ -181,6 +181,7 @@ impl<'a> NorunCombineIterator<'a> { // Combines sequential noruns produced by RunIterator impl Iterator for NorunCombineIterator<'_> { type Item = RunOrNot; + fn next(&mut self) -> Option { loop { match self.prev.take() { diff --git a/src/codecs/hdr/mod.rs b/src/codecs/hdr/mod.rs index b3325bc648..48a52e9749 100644 --- a/src/codecs/hdr/mod.rs +++ b/src/codecs/hdr/mod.rs @@ -6,7 +6,6 @@ //! //! * //! * -//! mod decoder; mod encoder; diff --git a/src/codecs/jpeg/encoder.rs b/src/codecs/jpeg/encoder.rs index 075270daec..d61951aeec 100644 --- a/src/codecs/jpeg/encoder.rs +++ b/src/codecs/jpeg/encoder.rs @@ -822,9 +822,9 @@ fn encode_coefficient(coefficient: i32) -> (u8, u16) { #[inline] fn rgb_to_ycbcr(pixel: P) -> (u8, u8, u8) { let [r, g, b] = pixel.to_rgb().0; - let r: i32 = r.to_u8().unwrap() as i32; - let g: i32 = g.to_u8().unwrap() as i32; - let b: i32 = b.to_u8().unwrap() as i32; + let r: i32 = i32::from(r.to_u8().unwrap()); + let g: i32 = i32::from(g.to_u8().unwrap()); + let b: i32 = i32::from(b.to_u8().unwrap()); /* JPEG RGB -> YCbCr is defined as following equations using Bt.601 Full Range matrix: @@ -1016,7 +1016,7 @@ mod tests { let result = encoder.write_image(&img, 65_536, 1, ExtendedColorType::L8); match result { Err(ImageError::Parameter(err)) => { - assert_eq!(err.kind(), DimensionMismatch) + assert_eq!(err.kind(), DimensionMismatch); } other => { panic!( @@ -1065,7 +1065,7 @@ mod tests { build_frame_header(&mut buf, 5, 100, 150, &components); assert_eq!( buf, - [5, 0, 150, 0, 100, 2, 1, 1 << 4 | 1, 5, 2, 1 << 4 | 1, 4] + [5, 0, 150, 0, 100, 2, 1, (1 << 4) | 1, 5, 2, (1 << 4) | 1, 4] ); } @@ -1093,7 +1093,7 @@ mod tests { }, ]; build_scan_header(&mut buf, &components); - assert_eq!(buf, [2, 1, 5 << 4 | 5, 2, 4 << 4 | 4, 0, 63, 0]); + assert_eq!(buf, [2, 1, (5 << 4) | 5, 2, (4 << 4) | 4, 0, 63, 0]); } #[test] @@ -1123,7 +1123,7 @@ mod tests { let mut expected = vec![]; expected.push(1); expected.extend_from_slice(&[0; 64]); - assert_eq!(buf, expected) + assert_eq!(buf, expected); } #[cfg(feature = "benchmarks")] diff --git a/src/codecs/jpeg/mod.rs b/src/codecs/jpeg/mod.rs index 4242733795..65ebecddbc 100644 --- a/src/codecs/jpeg/mod.rs +++ b/src/codecs/jpeg/mod.rs @@ -5,7 +5,6 @@ //! //! # Related Links //! * - The JPEG specification -//! pub use self::decoder::JpegDecoder; pub use self::encoder::{JpegEncoder, PixelDensity, PixelDensityUnit}; diff --git a/src/codecs/png.rs b/src/codecs/png.rs index 8cf296541a..de6cfbdf9c 100644 --- a/src/codecs/png.rs +++ b/src/codecs/png.rs @@ -4,7 +4,6 @@ //! //! # Related Links //! * - The PNG Specification -//! use std::borrow::Cow; use std::fmt; diff --git a/src/codecs/pnm/decoder.rs b/src/codecs/pnm/decoder.rs index 7b22f9c003..592f48f934 100644 --- a/src/codecs/pnm/decoder.rs +++ b/src/codecs/pnm/decoder.rs @@ -688,7 +688,7 @@ fn read_separated_ascii>(reader: &mut dyn Read) where T::Err: Display, { - let is_separator = |v: &u8| matches! { *v, b'\t' | b'\n' | b'\x0b' | b'\x0c' | b'\r' | b' ' }; + let is_separator = |v: &u8| matches!(*v, b'\t' | b'\n' | b'\x0b' | b'\x0c' | b'\r' | b' '); let token = reader .bytes() diff --git a/src/codecs/tga/decoder.rs b/src/codecs/tga/decoder.rs index 33045934ff..3ad28e72a4 100644 --- a/src/codecs/tga/decoder.rs +++ b/src/codecs/tga/decoder.rs @@ -196,7 +196,7 @@ impl TgaDecoder { fn bytes_to_index(bytes: &[u8]) -> usize { let mut result = 0usize; for byte in bytes { - result = result << 8 | *byte as usize; + result = (result << 8) | *byte as usize; } result } diff --git a/src/flat.rs b/src/flat.rs index a67dc9ab2f..0bbee51b1a 100644 --- a/src/flat.rs +++ b/src/flat.rs @@ -943,7 +943,7 @@ impl<'buf, Subpixel> FlatSamples<&'buf [Subpixel]> { /// use image::{flat::FlatSamples, GenericImage, RgbImage, Rgb}; /// /// let background = Rgb([20, 20, 20]); - /// let bg = FlatSamples::with_monocolor(&background, 200, 200);; + /// let bg = FlatSamples::with_monocolor(&background, 200, 200); /// /// let mut image = RgbImage::new(200, 200); /// paint_something(&mut image); @@ -986,7 +986,6 @@ impl<'buf, Subpixel> FlatSamples<&'buf [Subpixel]> { /// /// * For all indices inside bounds, the corresponding index is valid in the buffer /// * `P::channel_count()` agrees with `self.inner.layout.channels` -/// #[derive(Clone, Debug)] pub struct View where @@ -1009,7 +1008,6 @@ where /// * There is no aliasing of samples /// * The samples are packed, i.e. `self.inner.layout.sample_stride == 1` /// * `P::channel_count()` agrees with `self.inner.layout.channels` -/// #[derive(Clone, Debug)] pub struct ViewMut where diff --git a/src/image.rs b/src/image.rs index b150e41519..318b641d88 100644 --- a/src/image.rs +++ b/src/image.rs @@ -880,7 +880,7 @@ impl Clone for Pixels<'_, I> { /// use image::{GenericImageView, Rgb, RgbImage}; /// /// let buffer = RgbImage::new(10, 10); -/// let image: &dyn GenericImageView> = &buffer; +/// let image: &dyn GenericImageView> = &buffer; /// ``` pub trait GenericImageView { /// The type of pixel. @@ -1269,6 +1269,7 @@ where I: Deref, { type Target = SubImageInner; + fn deref(&self) -> &Self::Target { &self.inner } diff --git a/src/imageops/colorops.rs b/src/imageops/colorops.rs index 765e6e247b..7289c09ac8 100644 --- a/src/imageops/colorops.rs +++ b/src/imageops/colorops.rs @@ -1,7 +1,6 @@ //! Functions for altering and converting the color of pixelbufs use num_traits::NumCast; -use std::f64::consts::PI; use crate::color::{FromColor, IntoColor, Luma, LumaA}; use crate::image::{GenericImage, GenericImageView}; @@ -230,8 +229,8 @@ where let angle: f64 = NumCast::from(value).unwrap(); - let cosv = (angle * PI / 180.0).cos(); - let sinv = (angle * PI / 180.0).sin(); + let cosv = angle.to_radians().cos(); + let sinv = angle.to_radians().sin(); let matrix: [f64; 9] = [ // Reds 0.213 + cosv * 0.787 - sinv * 0.213, @@ -294,8 +293,8 @@ where let angle: f64 = NumCast::from(value).unwrap(); - let cosv = (angle * PI / 180.0).cos(); - let sinv = (angle * PI / 180.0).sin(); + let cosv = angle.to_radians().cos(); + let sinv = angle.to_radians().sin(); let matrix: [f64; 9] = [ // Reds 0.213 + cosv * 0.787 - sinv * 0.213, @@ -586,7 +585,7 @@ mod test { let cmap = BiLevel; dither(&mut image, &cmap); assert_eq!(&*image, &[0, 0xFF, 0xFF, 0]); - assert_eq!(index_colors(&image, &cmap).into_raw(), vec![0, 1, 1, 0]) + assert_eq!(index_colors(&image, &cmap).into_raw(), vec![0, 1, 1, 0]); } #[test] diff --git a/src/imageops/fast_blur.rs b/src/imageops/fast_blur.rs index 8ae25f2917..8f55160276 100644 --- a/src/imageops/fast_blur.rs +++ b/src/imageops/fast_blur.rs @@ -5,6 +5,7 @@ use crate::{ImageBuffer, Pixel, Primitive}; /// Approximation of Gaussian blur after /// Kovesi, P.: Fast Almost-Gaussian Filtering The Australian Pattern /// Recognition Society Conference: DICTA 2010. December 2010. Sydney. +#[must_use] pub fn fast_blur( image_buffer: &ImageBuffer>, sigma: f32, @@ -42,7 +43,7 @@ fn boxes_for_gauss(sigma: f32, n: usize) -> Vec { let w_ideal = f32::sqrt((12.0 * sigma.powi(2) / (n as f32)) + 1.0); let mut w_l = w_ideal.floor(); if w_l % 2.0 == 0.0 { - w_l -= 1.0 + w_l -= 1.0; }; let w_u = w_l + 2.0; @@ -90,7 +91,7 @@ fn horizontal_fast_blur_half( .to_f32() .unwrap_or(0.0) }) - .sum() + .sum(); } for column in 0..width { @@ -129,7 +130,7 @@ fn horizontal_fast_blur_half( channel_num, ) .to_f32() - .unwrap_or(0.0) + .unwrap_or(0.0); } } } diff --git a/src/imageops/mod.rs b/src/imageops/mod.rs index 61a742e038..ccd398a497 100644 --- a/src/imageops/mod.rs +++ b/src/imageops/mod.rs @@ -169,7 +169,6 @@ pub fn overlay_bounds( /// In particular, we want to ensure that all these coordinate accesses are safe: /// 1. `bottom.get_pixel(origin_bottom_x + [0..x_range), origin_bottom_y + [0..y_range))` /// 2. `top.get_pixel(origin_top_y + [0..x_range), origin_top_y + [0..y_range))` -/// fn overlay_bounds_ext( (bottom_width, bottom_height): (u32, u32), (top_width, top_height): (u32, u32), @@ -246,7 +245,7 @@ where /// /// # Examples /// ```no_run -/// use image::{RgbaImage}; +/// use image::RgbaImage; /// /// let mut img = RgbaImage::new(1920, 1080); /// let tile = image::open("tile.png").unwrap(); @@ -561,7 +560,7 @@ mod tests { let error = image_blurred_gauss_bytes .iter() .zip(image_blurred_fast_bytes.iter()) - .map(|(a, b)| ((*a as f32 - *b as f32) / (*a as f32))) + .map(|(a, b)| ((f32::from(*a) - f32::from(*b)) / f32::from(*a))) .sum::() / (image_blurred_gauss_bytes.len() as f32); assert!(error < 0.05); diff --git a/src/imageops/sample.rs b/src/imageops/sample.rs index 34e11704b5..e738fdd59c 100644 --- a/src/imageops/sample.rs +++ b/src/imageops/sample.rs @@ -984,7 +984,7 @@ where /// Performs a Gaussian blur on the supplied image. /// ```sigma``` is a measure of how much to blur by. -/// Use [crate::imageops::fast_blur()] for a faster but less +/// Use [`crate::imageops::fast_blur()`] for a faster but less /// accurate version. pub fn blur( image: &I, @@ -1082,7 +1082,7 @@ mod tests { use std::path::Path; 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())) + assert!(img.pixels().eq(resize.pixels())); } #[test] diff --git a/src/math/utils.rs b/src/math/utils.rs index 47f01efa6b..12fa46e20d 100644 --- a/src/math/utils.rs +++ b/src/math/utils.rs @@ -46,10 +46,10 @@ mod test { if old_w == 0 || new_w == 0 { return true; } // In this case, the scaling is limited by scaling of height. // We could check that case separately but it does not conform to the same expectation. - if new_w as u64 * 400u64 >= old_w as u64 * u64::from(u32::MAX) { return true; } + if u64::from(new_w) * 400u64 >= u64::from(old_w) * u64::from(u32::MAX) { return true; } let result = super::resize_dimensions(old_w, 400, new_w, u32::MAX, false); - let exact = (400_f64 * new_w as f64 / old_w as f64).round() as u32; + let exact = (400_f64 * f64::from(new_w) / f64::from(old_w)).round() as u32; result.0 == new_w && result.1 == exact.max(1) } } @@ -59,10 +59,10 @@ mod test { if old_h == 0 || new_h == 0 { return true; } // In this case, the scaling is limited by scaling of width. // We could check that case separately but it does not conform to the same expectation. - if 400u64 * new_h as u64 >= old_h as u64 * u64::from(u32::MAX) { return true; } + if 400u64 * u64::from(new_h) >= u64::from(old_h) * u64::from(u32::MAX) { return true; } let result = super::resize_dimensions(400, old_h, u32::MAX, new_h, false); - let exact = (400_f64 * new_h as f64 / old_h as f64).round() as u32; + let exact = (400_f64 * f64::from(new_h) / f64::from(old_h)).round() as u32; result.1 == new_h && result.0 == exact.max(1) } } diff --git a/src/metadata.rs b/src/metadata.rs index 5c2e308770..78e8c1d6c0 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -32,6 +32,7 @@ pub enum Orientation { impl Orientation { /// Converts from [Exif orientation](https://web.archive.org/web/20200412005226/https://www.impulseadventure.com/photo/exif-orientation.html) + #[must_use] pub fn from_exif(exif_orientation: u8) -> Option { match exif_orientation { 1 => Some(Self::NoTransforms), @@ -47,6 +48,7 @@ impl Orientation { } /// Converts into [Exif orientation](https://web.archive.org/web/20200412005226/https://www.impulseadventure.com/photo/exif-orientation.html) + #[must_use] pub fn to_exif(self) -> u8 { match self { Self::NoTransforms => 1, @@ -69,7 +71,7 @@ impl Orientation { match magic { [0x49, 0x49, 42, 0] => { let ifd_offset = reader.read_u32::().ok()?; - reader.set_position(ifd_offset as u64); + reader.set_position(u64::from(ifd_offset)); let entries = reader.read_u16::().ok()?; for _ in 0..entries { let tag = reader.read_u16::().ok()?; @@ -84,7 +86,7 @@ impl Orientation { } [0x4d, 0x4d, 0, 42] => { let ifd_offset = reader.read_u32::().ok()?; - reader.set_position(ifd_offset as u64); + reader.set_position(u64::from(ifd_offset)); let entries = reader.read_u16::().ok()?; for _ in 0..entries { let tag = reader.read_u16::().ok()?; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index dff6cc760a..f64834e28d 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -53,7 +53,7 @@ pub(crate) fn expand_bits(bit_depth: u8, row_size: u32, buf: &[u8]) -> Vec { // skip the pixels that can be neglected because scanlines should // start at byte boundaries if i % (row_len as usize) < (row_size as usize) { - let pixel = (v & mask << shift as usize) >> shift as usize; + let pixel = (v & (mask << shift as usize)) >> shift as usize; p.push(pixel * scaling_factor); } i += 1;