Skip to content

Commit

Permalink
[feat] QOI image format supported
Browse files Browse the repository at this point in the history
Closes: #26

Signed-off-by: Shinyzenith <[email protected]>
  • Loading branch information
Shinyzenith committed Jul 2, 2023
1 parent 4c931b1 commit 004fdc5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/wayshot.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
4 changes: 2 additions & 2 deletions docs/wayshot.7.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion libwayshot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 13 additions & 1 deletion libwayshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use image::{
jpeg::JpegEncoder,
png::PngEncoder,
pnm::{self, PnmEncoder},
qoi::QoiEncoder,
},
ColorType, ImageEncoder,
};
Expand Down Expand Up @@ -94,8 +95,10 @@ pub enum EncodingFormat {
Jpg,
/// Png encoder.
Png,
/// Ppm encoder
/// Ppm encoder.
Ppm,
// Qoi encoder.
Qoi,
}

struct CaptureFrameState {
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion wayshot/src/wayshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ fn main() -> Result<(), Box<dyn Error>> {
"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);
}
}
Expand Down Expand Up @@ -194,6 +195,7 @@ fn main() -> Result<(), Box<dyn Error>> {
libwayshot::EncodingFormat::Png => "-wayshot.png",
libwayshot::EncodingFormat::Jpg => "-wayshot.jpg",
libwayshot::EncodingFormat::Ppm => "-wayshot.ppm",
libwayshot::EncodingFormat::Qoi => "-wayshot.qoi",
}
};

Expand Down

0 comments on commit 004fdc5

Please sign in to comment.