Skip to content

Commit

Permalink
feat: test
Browse files Browse the repository at this point in the history
  • Loading branch information
nashaofu committed Jan 21, 2024
1 parent ff514c6 commit 5013b63
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/monitor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::time::Instant;
use syscap::Monitor;
use xcap::Monitor;

fn main() {
let start = Instant::now();
Expand Down
2 changes: 1 addition & 1 deletion examples/monitor_capture.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use xcap::Monitor;
use std::time::Instant;
use xcap::Monitor;

fn normalized(filename: &str) -> String {
filename
Expand Down
2 changes: 1 addition & 1 deletion examples/window.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use xcap::Window;
use std::time::Instant;
use xcap::Window;

fn main() {
let start = Instant::now();
Expand Down
2 changes: 1 addition & 1 deletion examples/window_capture.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use xcap::Window;
use std::time::Instant;
use xcap::Window;

fn normalized(filename: &str) -> String {
filename
Expand Down
4 changes: 1 addition & 3 deletions src/linux/impl_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ fn get_scale_factor(conn: &Connection, screen: &Screen) -> XCapResult<f32> {
.strip_prefix(xft_dpi_prefix)
.ok_or_else(|| XCapError::new("Xft.dpi parse failed"))?;

let dpi = xft_dpi
.parse::<f32>()
.map_err(|err| XCapError::new(err))?;
let dpi = xft_dpi.parse::<f32>().map_err(|err| XCapError::new(err))?;

Ok(dpi / 96.0)
}
Expand Down
7 changes: 1 addition & 6 deletions src/linux/xorg_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ pub fn xorg_capture(
16 => get_pixel16_rgba,
24 => get_pixel24_32_rgba,
32 => get_pixel24_32_rgba,
_ => {
return Err(XCapError::new(format!(
"Unsupported {} depth",
depth
)))
}
_ => return Err(XCapError::new(format!("Unsupported {} depth", depth))),
};

for y in 0..height {
Expand Down
4 changes: 1 addition & 3 deletions src/macos/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ pub fn capture(
window_id: CGWindowID,
) -> XCapResult<RgbaImage> {
let cg_image = create_image(cg_rect, list_option, window_id, kCGWindowImageDefault)
.ok_or_else(|| {
XCapError::new(format!("Capture failed {} {:?}", window_id, cg_rect))
})?;
.ok_or_else(|| XCapError::new(format!("Capture failed {} {:?}", window_id, cg_rect)))?;

let width = cg_image.width();
let height = cg_image.height();
Expand Down
3 changes: 1 addition & 2 deletions src/utils/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use image::RgbaImage;
use crate::error::{XCapError, XCapResult};

pub fn vec_to_rgba_image(width: u32, height: u32, buf: Vec<u8>) -> XCapResult<RgbaImage> {
RgbaImage::from_vec(width, height, buf)
.ok_or_else(|| XCapError::new("buffer not big enough"))
RgbaImage::from_vec(width, height, buf).ok_or_else(|| XCapError::new("buffer not big enough"))
}

#[cfg(any(target_os = "windows", target_os = "macos", test))]
Expand Down
6 changes: 1 addition & 5 deletions src/windows/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ pub fn capture_monitor(
}

#[allow(unused)]
pub fn capture_window(
impl_window: &ImplWindow,
width: i32,
height: i32,
) -> XCapResult<RgbaImage> {
pub fn capture_window(impl_window: &ImplWindow, width: i32, height: i32) -> XCapResult<RgbaImage> {
unsafe {
let box_hdc_window: BoxHDC = BoxHDC::from(impl_window);
// 内存中的HDC
Expand Down
4 changes: 1 addition & 3 deletions src/windows/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ pub(super) fn wide_string_to_string(wide_string: &[u16]) -> XCapResult<String> {
return Ok(string);
}

Err(XCapError::new(
"Convert wide string to string failed",
))
Err(XCapError::new("Convert wide string to string failed"))
}

0 comments on commit 5013b63

Please sign in to comment.