(
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;