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:
+2
-2
@@ -322,9 +322,9 @@ pub struct Sensor {
|
|||||||
#[serde(deserialize_with = "f32_as_rounded_i32")]
|
#[serde(deserialize_with = "f32_as_rounded_i32")]
|
||||||
pub y: i32,
|
pub y: i32,
|
||||||
/// Used for pointer type
|
/// Used for pointer type
|
||||||
pub width: Option<i32>,
|
pub width: Option<u32>,
|
||||||
/// Used for pointer type
|
/// Used for pointer type
|
||||||
pub height: Option<i32>,
|
pub height: Option<u32>,
|
||||||
/// Sensor graphic orientation
|
/// Sensor graphic orientation
|
||||||
pub direction: Option<SensorDirection>,
|
pub direction: Option<SensorDirection>,
|
||||||
|
|
||||||
|
|||||||
+8
-15
@@ -430,27 +430,20 @@ impl PanelRenderer {
|
|||||||
ImageProcessingError::ImageLoadError("No picture specified".to_string())
|
ImageProcessingError::ImageLoadError("No picture specified".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// TODO combine get image with resize
|
// Resize if dimensions specified
|
||||||
let mut pic = self
|
let size = if let (Some(width), Some(height)) = (sensor.width, sensor.height) {
|
||||||
|
Some((width, height))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let pic = self
|
||||||
.image_cache
|
.image_cache
|
||||||
.get(pic_path, None)
|
.get(pic_path, size)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
ImageProcessingError::ImageLoadError(format!("Failed to load: {:?}", pic_path))
|
ImageProcessingError::ImageLoadError(format!("Failed to load: {:?}", pic_path))
|
||||||
})?
|
})?
|
||||||
.clone();
|
.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 min_val = sensor.min_value.unwrap_or(0.0);
|
||||||
let max_val = sensor.max_value.unwrap_or(100.0);
|
let max_val = sensor.max_value.unwrap_or(100.0);
|
||||||
let current_value = value
|
let current_value = value
|
||||||
|
|||||||
Reference in New Issue
Block a user