diff --git a/src/cfg.rs b/src/cfg.rs index 63f7b5e..fe8c9ab 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -322,9 +322,9 @@ pub struct Sensor { #[serde(deserialize_with = "f32_as_rounded_i32")] pub y: i32, /// Used for pointer type - pub width: Option, + pub width: Option, /// Used for pointer type - pub height: Option, + pub height: Option, /// Sensor graphic orientation pub direction: Option, diff --git a/src/render.rs b/src/render.rs index 54d9c3c..c22cbdd 100644 --- a/src/render.rs +++ b/src/render.rs @@ -430,27 +430,20 @@ impl PanelRenderer { ImageProcessingError::ImageLoadError("No picture specified".to_string()) })?; - // TODO combine get image with resize - let mut pic = self + // Resize if dimensions specified + let size = if let (Some(width), Some(height)) = (sensor.width, sensor.height) { + Some((width, height)) + } else { + None + }; + let pic = self .image_cache - .get(pic_path, None) + .get(pic_path, size) .ok_or_else(|| { ImageProcessingError::ImageLoadError(format!("Failed to load: {:?}", pic_path)) })? .clone(); - // Resize if dimensions specified - if let (Some(width), Some(height)) = (sensor.width, sensor.height) { - let item_width = width as u32; - let item_height = height as u32; - pic = image::imageops::resize( - &pic, - item_width, - item_height, - image::imageops::FilterType::Lanczos3, - ); - } - let min_val = sensor.min_value.unwrap_or(0.0); let max_val = sensor.max_value.unwrap_or(100.0); let current_value = value