mirror of
https://github.com/Devolutions/IronRDP.git
synced 2025-08-04 07:08:17 +00:00
example: replace bmp with image/png
bmp is a small crate, but it is not popular, and apparently unmaintained. Use the ubiquitous image crate and the PNG format instead. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
0ee5bfc561
commit
fe0d9e9773
4 changed files with 28 additions and 26 deletions
|
@ -53,7 +53,7 @@ ironrdp-blocking.workspace = true
|
|||
ironrdp-cliprdr-native.workspace = true
|
||||
anyhow = "1"
|
||||
async-trait = "0.1"
|
||||
bmp = "0.5"
|
||||
image = { version = "0.25.5", default-features = false, features = ["png"] }
|
||||
pico-args = "0.5"
|
||||
x509-cert = { version = "0.2", default-features = false, features = ["std"] }
|
||||
sspi = { workspace = true, features = ["network_client"] }
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
//!
|
||||
//! In this basic client implementation, the client establishes a connection
|
||||
//! with the destination server, decodes incoming graphics updates, and saves the
|
||||
//! resulting output as a BMP image file on the disk.
|
||||
//! resulting output as a PNG image file on the disk.
|
||||
//!
|
||||
//! # Usage example
|
||||
//!
|
||||
//! ```shell
|
||||
//! cargo run --example=screenshot -- --host <HOSTNAME> -u <USERNAME> -p <PASSWORD> -o out.bmp
|
||||
//! cargo run --example=screenshot -- --host <HOSTNAME> -u <USERNAME> -p <PASSWORD> -o out.png
|
||||
//! ```
|
||||
|
||||
#![allow(unused_crate_dependencies)] // false positives because there is both a library and a binary
|
||||
|
@ -99,7 +99,7 @@ fn parse_args() -> anyhow::Result<Action> {
|
|||
let password = args.value_from_str(["-p", "--password"])?;
|
||||
let output = args
|
||||
.opt_value_from_str(["-o", "--output"])?
|
||||
.unwrap_or_else(|| PathBuf::from("out.bmp"));
|
||||
.unwrap_or_else(|| PathBuf::from("out.png"));
|
||||
let domain = args.opt_value_from_str(["-d", "--domain"])?;
|
||||
|
||||
Action::Run {
|
||||
|
@ -156,27 +156,11 @@ fn run(
|
|||
|
||||
active_stage(connection_result, framed, &mut image).context("active stage")?;
|
||||
|
||||
let mut bmp = bmp::Image::new(u32::from(image.width()), u32::from(image.height()));
|
||||
let img: image::ImageBuffer<image::Rgba<u8>, _> =
|
||||
image::ImageBuffer::from_raw(u32::from(image.width()), u32::from(image.height()), image.data())
|
||||
.context("invalid image")?;
|
||||
|
||||
image
|
||||
.data()
|
||||
.chunks_exact(usize::from(image.width()).checked_mul(4).expect("never overflow"))
|
||||
.enumerate()
|
||||
.for_each(|(y, row)| {
|
||||
row.chunks_exact(4).enumerate().for_each(|(x, pixel)| {
|
||||
let r = pixel[0];
|
||||
let g = pixel[1];
|
||||
let b = pixel[2];
|
||||
let _a = pixel[3];
|
||||
bmp.set_pixel(
|
||||
u32::try_from(x).unwrap(),
|
||||
u32::try_from(y).unwrap(),
|
||||
bmp::Pixel::new(r, g, b),
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
bmp.save(output).context("save BMP image to disk")?;
|
||||
img.save(output).context("save image to disk")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#[cfg(test)]
|
||||
use {
|
||||
anyhow as _, async_trait as _, bmp as _, ironrdp_blocking as _, ironrdp_cliprdr_native as _, pico_args as _,
|
||||
anyhow as _, async_trait as _, image as _, ironrdp_blocking as _, ironrdp_cliprdr_native as _, pico_args as _,
|
||||
rand as _, sspi as _, tokio_rustls as _, tracing as _, tracing_subscriber as _, x509_cert as _,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue