From 2f379d2c81f61db78b963fafc12fd831911890a8 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Thu, 26 Aug 2021 15:01:37 +0200 Subject: [PATCH] Add rotate flag --- src/bin/catprint.rs | 9 +++++++-- src/image.rs | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bin/catprint.rs b/src/bin/catprint.rs index 6f1c96f..5359fb9 100644 --- a/src/bin/catprint.rs +++ b/src/bin/catprint.rs @@ -35,12 +35,16 @@ struct Feed { #[derive(Clap)] struct Print { - /// The image you want to print out + /// The path to the image you want to print out input_image: String, /// The ditherer supposed to be used. none is good for text and vector graphics #[clap(arg_enum, short, long, default_value = "k-mean")] ditherer: Ditherers, + + /// Rotate picture by 90 degrees + #[clap(short, long)] + rotate: bool, } #[derive(ArgEnum)] @@ -87,7 +91,8 @@ async fn main_print(mut device: device::Device, print: Print) -> Result<(), Box< 10, )); - let image = image::Image::load(&std::path::PathBuf::from(print.input_image)).unwrap(); + let image = + image::Image::load(&std::path::PathBuf::from(print.input_image), print.rotate).unwrap(); let image = match print.ditherer { Ditherers::None => image, diff --git a/src/image.rs b/src/image.rs index 980fa59..fa85cb0 100644 --- a/src/image.rs +++ b/src/image.rs @@ -22,9 +22,12 @@ fn rle_bytes(val: u8, mut counter: u32) -> Vec { } impl Image { - pub fn load(path: &Path) -> std::result::Result> { + pub fn load( + path: &Path, + rotate: bool, + ) -> std::result::Result> { let image = image::open(path)?; - + let image = if rotate { image.rotate90() } else { image }; let image = image .resize( crate::protocol::PIXELS_PER_LINE as u32,