refactor: pointer sensor image resizing

Cache resized pointer image instead of resizing it every time when the
sensor is rendered.
Change sensor.width and .height fields to u32.
This commit is contained in:
Markus Zehnder
2025-08-24 22:22:00 +02:00
parent 84455e9254
commit 0953a4bad5
2 changed files with 10 additions and 17 deletions
+2 -2
View File
@@ -322,9 +322,9 @@ pub struct Sensor {
#[serde(deserialize_with = "f32_as_rounded_i32")]
pub y: i32,
/// Used for pointer type
pub width: Option<i32>,
pub width: Option<u32>,
/// Used for pointer type
pub height: Option<i32>,
pub height: Option<u32>,
/// Sensor graphic orientation
pub direction: Option<SensorDirection>,
+8 -15
View File
@@ -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