diff --git a/Cargo.toml b/Cargo.toml index d0ccac0..abf772c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ default = [ "util" ] [dependencies] hidapi = "2.4" log = "0.4.8" -image = "0.25.1" +image = "0.25.2" imageproc = "0.24.0" thiserror = "1.0.30" ab_glyph = "0.2.25" diff --git a/src/images.rs b/src/images.rs index 7f72cd6..7b443d4 100644 --- a/src/images.rs +++ b/src/images.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use image::codecs::jpeg::JpegEncoder; -use image::io::Reader; +use image::ImageReader; use image::{imageops::FilterType, Pixel, Rgba}; use image::{DynamicImage, ExtendedColorType}; @@ -28,7 +28,7 @@ impl FromStr for Colour { fn from_str(s: &str) -> Result { if s.len() != 6 && s.len() != 8 { - return Err(format!("Expected colour in the hex form: RRGGBB")); + return Err("Expected colour in the hex form: RRGGBB".to_string()); } let r = @@ -43,7 +43,7 @@ impl FromStr for Colour { } /// Options for image loading and editing -#[derive(Debug)] +#[derive(Debug, Default)] #[cfg_attr(feature = "structopt", derive(structopt::StructOpt))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct ImageOptions { @@ -62,15 +62,6 @@ impl ImageOptions { } } -impl Default for ImageOptions { - fn default() -> Self { - Self { - background: None, - invert: false, - } - } -} - pub(crate) fn apply_transform( image: DynamicImage, rotation: Rotation, @@ -82,13 +73,12 @@ pub(crate) fn apply_transform( Rotation::Rot180 => image.rotate180(), Rotation::Rot270 => image.rotate270(), }; - let image = match mirroring { + match mirroring { Mirroring::None => image, Mirroring::X => image.flipv(), Mirroring::Y => image.fliph(), Mirroring::Both => image.flipv().fliph(), - }; - image + } } /// Load an image from a file, resize to defined x and y, and apply the provided options @@ -102,7 +92,7 @@ pub(crate) fn load_image( colour_order: ColourOrder, ) -> Result, Error> { // Open image reader - let reader = match Reader::open(path) { + let reader = match ImageReader::open(path) { Ok(v) => v, Err(e) => { error!("error loading file '{}': {:?}", path, e); diff --git a/src/info.rs b/src/info.rs index 6f6a693..20aa213 100644 --- a/src/info.rs +++ b/src/info.rs @@ -25,6 +25,7 @@ pub enum ImageMode { /// Stream Deck color mode #[derive(Debug, Clone, PartialEq)] +#[allow(clippy::upper_case_acronyms)] pub(crate) enum ColourOrder { RGB, BGR, @@ -159,10 +160,7 @@ impl Kind { } pub(crate) fn is_v2(&self) -> bool { - match self { - Kind::OriginalV2 | Kind::Xl | Kind::Mk2 => true, - _ => false, - } + matches!(self, Kind::OriginalV2 | Kind::Xl | Kind::Mk2) } } diff --git a/src/lib.rs b/src/lib.rs index 5c6a98b..b7da838 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -277,17 +277,17 @@ impl StreamDeck { let mut image = vec![0u8; self.kind.image_size_bytes()]; let colour_order = self.kind.image_colour_order(); - for i in 0..image.len() { + for (i, image_byte) in image.iter_mut().enumerate() { match i % 3 { 0 => { - image[i] = match colour_order { + *image_byte = match colour_order { ColourOrder::BGR => colour.b, ColourOrder::RGB => colour.r, } } - 1 => image[i] = colour.g, + 1 => *image_byte = colour.g, 2 => { - image[i] = match colour_order { + *image_byte = match colour_order { ColourOrder::BGR => colour.r, ColourOrder::RGB => colour.b, } @@ -328,7 +328,7 @@ impl StreamDeck { match pos { TextPosition::Absolute { x, y } => { let mut y = *y; - text.to_string().split("\n").for_each(|txt| { + text.split("\n").for_each(|txt| { draw_text_mut(&mut image, colour, *x, y, opts.scale, font, txt); y += (opts.scale.y * opts.line_height).round() as i32; }); @@ -376,7 +376,7 @@ impl StreamDeck { KeyDirection::LeftToRight => key + self.kind.key_index_offset(), // The original Streamdeck uses 1-indexed right-to-left KeyDirection::RightToLeft => { - let cols = self.kind.key_columns() as u8; + let cols = self.kind.key_columns(); let col = key % cols; let row = key / cols; row * cols + cols - col @@ -480,12 +480,14 @@ impl StreamDeck { } /// TextPosition is how to position text via set_button_text +#[derive(Debug, Clone)] pub enum TextPosition { /// Absolute positioning Absolute { x: i32, y: i32 }, } /// Text Options provide values for text buttons +#[derive(Debug, Clone)] pub struct TextOptions { foreground: Colour, background: Colour, @@ -518,7 +520,7 @@ impl Default for TextOptions { } // Convert RGB image data to BGR -fn rgb_to_bgr(data: &mut Vec) { +fn rgb_to_bgr(data: &mut [u8]) { for chunk in data.chunks_exact_mut(3) { chunk.swap(0, 2); }