diff --git a/Cargo.lock b/Cargo.lock index 65437c69..54c3f8dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -173,6 +173,7 @@ dependencies = [ "num-rational", "num-traits", "png", + "qoi", ] [[package]] @@ -358,6 +359,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "qoi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +dependencies = [ + "bytemuck", +] + [[package]] name = "quick-xml" version = "0.23.1" diff --git a/docs/wayshot.1.scd b/docs/wayshot.1.scd index c45b5819..7f01aa01 100644 --- a/docs/wayshot.1.scd +++ b/docs/wayshot.1.scd @@ -29,6 +29,7 @@ Wayshot - Screenshot tool for compositors implementing zwlr_screencopy_v1 such a - jpg - png (Default encoder) - ppm + - qoi *-f*, *--file* Set a custom file path. The default path is `./{current_unix_timestamp}-wayshot.{encoder}` diff --git a/docs/wayshot.7.scd b/docs/wayshot.7.scd index 6ac3f114..ca204fac 100644 --- a/docs/wayshot.7.scd +++ b/docs/wayshot.7.scd @@ -9,7 +9,7 @@ Wayshot - Screenshot tool for compositors implementing zwlr_screencopy_v1 such a *wayshot* [_options_] # REGION SELECTION -wayshot -s "$(slurp -f '%x %y %w %h')" +wayshot -s "$(slurp)" # FULLSCREEN @@ -30,7 +30,7 @@ wayshot -o eDP-1 # PICK A HEX COLOR CODE, USING IMAGEMAGICk -wayshot -s "$(slurp -p -f '%x %y %w %h')" --stdout | convert - -format '%[pixel:p{0,0}]' txt:-|egrep "#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})" -o +wayshot -s "$(slurp -p -f '%x %y %w %h')" --stdout | convert - -format '%[pixel:p{0,0}]' txt:-|grep -E "#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})" -o # PICK A HEX COLOR CODE WITHOUT USING IMAGEMAGICK diff --git a/libwayshot/Cargo.toml b/libwayshot/Cargo.toml index 8b8b2a4d..6c2d3dce 100644 --- a/libwayshot/Cargo.toml +++ b/libwayshot/Cargo.toml @@ -9,7 +9,7 @@ version = "0.1.0" edition = "2021" [dependencies] -image = { version = "0.24", default-features = false, features = ["jpeg", "png", "pnm"] } +image = { version = "0.24", default-features = false, features = ["jpeg", "png", "pnm", "qoi"] } log = "0.4.17" memmap2 = "0.5.10" nix = "0.26.2" diff --git a/libwayshot/src/lib.rs b/libwayshot/src/lib.rs index a0adbf99..2f9ccbcf 100644 --- a/libwayshot/src/lib.rs +++ b/libwayshot/src/lib.rs @@ -23,6 +23,7 @@ use image::{ jpeg::JpegEncoder, png::PngEncoder, pnm::{self, PnmEncoder}, + qoi::QoiEncoder, }, ColorType, ImageEncoder, }; @@ -94,8 +95,10 @@ pub enum EncodingFormat { Jpg, /// Png encoder. Png, - /// Ppm encoder + /// Ppm encoder. Ppm, + // Qoi encoder. + Qoi, } struct CaptureFrameState { @@ -405,6 +408,15 @@ pub fn write_to_file( )?; output_file.flush()?; } + EncodingFormat::Qoi => { + QoiEncoder::new(&mut output_file).write_image( + &frame_copy.frame_mmap, + frame_copy.frame_format.width, + frame_copy.frame_format.height, + frame_copy.frame_color_type, + )?; + output_file.flush()?; + } EncodingFormat::Ppm => { let rgb8_data = if let ColorType::Rgba8 = frame_copy.frame_color_type { let mut data = Vec::with_capacity( diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index f8458cd8..b5162ebc 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -161,8 +161,9 @@ fn main() -> Result<(), Box> { "jpeg" | "jpg" => libwayshot::EncodingFormat::Jpg, "png" => libwayshot::EncodingFormat::Png, "ppm" => libwayshot::EncodingFormat::Ppm, + "qoi" => libwayshot::EncodingFormat::Qoi, _ => { - log::error!("Invalid extension provided.\nValid extensions:\n1) jpeg\n2) jpg\n3) png\n4) ppm"); + log::error!("Invalid extension provided.\nValid extensions:\n1) jpeg\n2) jpg\n3) png\n4) ppm\n5) qoi"); exit(1); } } @@ -194,6 +195,7 @@ fn main() -> Result<(), Box> { libwayshot::EncodingFormat::Png => "-wayshot.png", libwayshot::EncodingFormat::Jpg => "-wayshot.jpg", libwayshot::EncodingFormat::Ppm => "-wayshot.ppm", + libwayshot::EncodingFormat::Qoi => "-wayshot.qoi", } };