Fix clippy warnings in wallpaper.rs
This commit is contained in:
parent
4e276dc7ee
commit
6b97273fcf
@ -53,23 +53,25 @@ fn rgba_to_bgra(mut pixels: Vec<u8>) -> Vec<u8> {
|
|||||||
/// - Aspect ratio is preserved
|
/// - Aspect ratio is preserved
|
||||||
/// - Excess image is cropped (centered)
|
/// - Excess image is cropped (centered)
|
||||||
fn prepare_fill(img: &RgbaImage, screen_width: u32, screen_height: u32) -> PreparedWallpaper {
|
fn prepare_fill(img: &RgbaImage, screen_width: u32, screen_height: u32) -> PreparedWallpaper {
|
||||||
let img_w = img.width() as f32;
|
let img_w = f64::from(img.width());
|
||||||
let img_h = img.height() as f32;
|
let img_h = f64::from(img.height());
|
||||||
|
|
||||||
let screen_w = screen_width as f32;
|
let screen_w = f64::from(screen_width);
|
||||||
let screen_h = screen_height as f32;
|
let screen_h = f64::from(screen_height);
|
||||||
|
|
||||||
// Scale so that BOTH dimensions cover the screen
|
// Scale so that BOTH dimensions cover the screen
|
||||||
let scale = (screen_w / img_w).max(screen_h / img_h);
|
let scale = (screen_w / img_w).max(screen_h / img_h);
|
||||||
|
|
||||||
|
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
|
||||||
let scaled_w = (img_w * scale).round() as u32;
|
let scaled_w = (img_w * scale).round() as u32;
|
||||||
|
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
|
||||||
let scaled_h = (img_h * scale).round() as u32;
|
let scaled_h = (img_h * scale).round() as u32;
|
||||||
|
|
||||||
let resized = imageops::resize(img, scaled_w, scaled_h, imageops::FilterType::Lanczos3);
|
let resized = imageops::resize(img, scaled_w, scaled_h, imageops::FilterType::Lanczos3);
|
||||||
|
|
||||||
// Center the image; negative offsets cause cropping
|
// Center the image; negative offsets cause cropping
|
||||||
let offset_x = (screen_width as i32 - scaled_w as i32) / 2;
|
let offset_x = (screen_width.cast_signed() - scaled_w.cast_signed()) / 2;
|
||||||
let offset_y = (screen_height as i32 - scaled_h as i32) / 2;
|
let offset_y = (screen_height.cast_signed() - scaled_h.cast_signed()) / 2;
|
||||||
|
|
||||||
let pixels = rgba_to_bgra(resized.into_raw());
|
let pixels = rgba_to_bgra(resized.into_raw());
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user