re-encode image to work with png

This commit is contained in:
Michael Zhang 2020-12-23 22:58:39 -06:00
parent eca99edb41
commit 39d80bddf7
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 7 additions and 12 deletions

2
Cargo.lock generated
View file

@ -250,7 +250,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "leanshot"
version = "0.4.0"
version = "0.4.0-rc"
dependencies = [
"anyhow",
"image",

View file

@ -1,7 +1,7 @@
[package]
name = "leanshot"
description = "Screenshot capture for Linux."
version = "0.4.0"
version = "0.4.0-rc"
repository = "https://git.mzhang.io/michael/leanshot"
license-file = "LICENSE"
edition = "2018"

View file

@ -30,7 +30,6 @@ impl Gui {
// get the dimensions of the screen
let screen = self.get_default_screen();
let (width, height) = (screen.width_in_pixels(), screen.height_in_pixels());
println!("width, height = {:?}", (width, height));
let image = xcb_image::get(
&self.conn,
@ -102,7 +101,7 @@ impl Gui {
.request_check()?;
info!("Grabbing keyboard...");
let result = xproto::grab_keyboard(
xproto::grab_keyboard(
&self.conn,
false,
id,
@ -111,11 +110,10 @@ impl Gui {
xcb::GRAB_MODE_ASYNC as u8,
)
.get_reply()?;
println!("result: {:?}", result.status());
info!("Grabbing pointer...");
let cursor = xcb_util::cursor::create_font_cursor(&self.conn, xcb_util::cursor::CROSSHAIR);
let result = xproto::grab_pointer(
xproto::grab_pointer(
&self.conn,
false,
id,
@ -129,7 +127,6 @@ impl Gui {
xcb::CURRENT_TIME,
)
.get_reply()?;
println!("result: {:?}", result.status());
let gc = self.conn.generate_id();
xproto::create_gc(
@ -251,7 +248,8 @@ impl ScreenCapture {
self.image.data().to_vec(),
)
.unwrap();
let mut image = DynamicImage::ImageBgra8(image);
let image = DynamicImage::ImageBgra8(image);
let mut image = DynamicImage::ImageRgb8(image.into_rgb8());
// TODO: compare the rectangles to see if we can skip the crop
// crop the image

View file

@ -32,7 +32,6 @@ fn main() -> Result<()> {
let rectangle = gui.interactive_select(&capture)?;
capture.save_cropped_to(&opt.outfile, rectangle)?;
}
_ => todo!("TODO"),
}
Ok(())
@ -58,7 +57,6 @@ pub struct Options {
#[allow(missing_docs)]
pub enum Region {
Fullscreen,
ActiveWindow,
Selection,
}
@ -66,9 +64,8 @@ impl Region {
pub fn from_str(x: &str) -> Result<Self> {
match x {
"fullscreen" => Ok(Region::Fullscreen),
"window" => Ok(Region::ActiveWindow),
"select" | "selection" => Ok(Region::Selection),
_ => bail!("expected {fullscreen|window|selection}"),
_ => bail!("expected {fullscreen|selection}"),
}
}
}