re-encode image to work with png
This commit is contained in:
parent
eca99edb41
commit
39d80bddf7
4 changed files with 7 additions and 12 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -250,7 +250,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "leanshot"
|
name = "leanshot"
|
||||||
version = "0.4.0"
|
version = "0.4.0-rc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"image",
|
"image",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "leanshot"
|
name = "leanshot"
|
||||||
description = "Screenshot capture for Linux."
|
description = "Screenshot capture for Linux."
|
||||||
version = "0.4.0"
|
version = "0.4.0-rc"
|
||||||
repository = "https://git.mzhang.io/michael/leanshot"
|
repository = "https://git.mzhang.io/michael/leanshot"
|
||||||
license-file = "LICENSE"
|
license-file = "LICENSE"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
10
src/gui.rs
10
src/gui.rs
|
@ -30,7 +30,6 @@ impl Gui {
|
||||||
// get the dimensions of the screen
|
// get the dimensions of the screen
|
||||||
let screen = self.get_default_screen();
|
let screen = self.get_default_screen();
|
||||||
let (width, height) = (screen.width_in_pixels(), screen.height_in_pixels());
|
let (width, height) = (screen.width_in_pixels(), screen.height_in_pixels());
|
||||||
println!("width, height = {:?}", (width, height));
|
|
||||||
|
|
||||||
let image = xcb_image::get(
|
let image = xcb_image::get(
|
||||||
&self.conn,
|
&self.conn,
|
||||||
|
@ -102,7 +101,7 @@ impl Gui {
|
||||||
.request_check()?;
|
.request_check()?;
|
||||||
|
|
||||||
info!("Grabbing keyboard...");
|
info!("Grabbing keyboard...");
|
||||||
let result = xproto::grab_keyboard(
|
xproto::grab_keyboard(
|
||||||
&self.conn,
|
&self.conn,
|
||||||
false,
|
false,
|
||||||
id,
|
id,
|
||||||
|
@ -111,11 +110,10 @@ impl Gui {
|
||||||
xcb::GRAB_MODE_ASYNC as u8,
|
xcb::GRAB_MODE_ASYNC as u8,
|
||||||
)
|
)
|
||||||
.get_reply()?;
|
.get_reply()?;
|
||||||
println!("result: {:?}", result.status());
|
|
||||||
|
|
||||||
info!("Grabbing pointer...");
|
info!("Grabbing pointer...");
|
||||||
let cursor = xcb_util::cursor::create_font_cursor(&self.conn, xcb_util::cursor::CROSSHAIR);
|
let cursor = xcb_util::cursor::create_font_cursor(&self.conn, xcb_util::cursor::CROSSHAIR);
|
||||||
let result = xproto::grab_pointer(
|
xproto::grab_pointer(
|
||||||
&self.conn,
|
&self.conn,
|
||||||
false,
|
false,
|
||||||
id,
|
id,
|
||||||
|
@ -129,7 +127,6 @@ impl Gui {
|
||||||
xcb::CURRENT_TIME,
|
xcb::CURRENT_TIME,
|
||||||
)
|
)
|
||||||
.get_reply()?;
|
.get_reply()?;
|
||||||
println!("result: {:?}", result.status());
|
|
||||||
|
|
||||||
let gc = self.conn.generate_id();
|
let gc = self.conn.generate_id();
|
||||||
xproto::create_gc(
|
xproto::create_gc(
|
||||||
|
@ -251,7 +248,8 @@ impl ScreenCapture {
|
||||||
self.image.data().to_vec(),
|
self.image.data().to_vec(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.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
|
// TODO: compare the rectangles to see if we can skip the crop
|
||||||
// crop the image
|
// crop the image
|
||||||
|
|
|
@ -32,7 +32,6 @@ fn main() -> Result<()> {
|
||||||
let rectangle = gui.interactive_select(&capture)?;
|
let rectangle = gui.interactive_select(&capture)?;
|
||||||
capture.save_cropped_to(&opt.outfile, rectangle)?;
|
capture.save_cropped_to(&opt.outfile, rectangle)?;
|
||||||
}
|
}
|
||||||
_ => todo!("TODO"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -58,7 +57,6 @@ pub struct Options {
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub enum Region {
|
pub enum Region {
|
||||||
Fullscreen,
|
Fullscreen,
|
||||||
ActiveWindow,
|
|
||||||
Selection,
|
Selection,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +64,8 @@ impl Region {
|
||||||
pub fn from_str(x: &str) -> Result<Self> {
|
pub fn from_str(x: &str) -> Result<Self> {
|
||||||
match x {
|
match x {
|
||||||
"fullscreen" => Ok(Region::Fullscreen),
|
"fullscreen" => Ok(Region::Fullscreen),
|
||||||
"window" => Ok(Region::ActiveWindow),
|
|
||||||
"select" | "selection" => Ok(Region::Selection),
|
"select" | "selection" => Ok(Region::Selection),
|
||||||
_ => bail!("expected {fullscreen|window|selection}"),
|
_ => bail!("expected {fullscreen|selection}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue