bryal / captrs

Cross-platform screen capture in Rust
GNU Affero General Public License v3.0
150 stars 16 forks source link

Added method for capture to Vec<u8> #12

Closed TommyGymer closed 1 year ago

TommyGymer commented 1 year ago

Added capture_frame_components method which returns the captured image as a Vec with bgr format. Also added tests for checking if the frame data length matches the expected length based on the width and height of the frame. The lib has also been linted with clippy.

TommyGymer commented 1 year ago

Tests sometimes failing on Windows

not tested if this also affects Linux

Some resolutions seem to result in the incorrect number of pixels being captured:

On 2560 x 1440

test captrs_tests::test_capture ... ok
test captrs_tests::test_capture_components ... ok

On 3440 x 1440

test captrs_tests::test_capture_components ... FAILED
test captrs_tests::test_capture ... FAILED

failures:

---- captrs_tests::test_capture_components stdout ----
thread 'captrs_tests::test_capture_components' panicked at 'assertion failed: `(left == right)`
  left: `19814400`,
 right: `19906560`', src\lib.rs:237:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- captrs_tests::test_capture stdout ----
thread 'captrs_tests::test_capture' panicked at 'assertion failed: `(left == right)`
  left: `4953600`,
 right: `4976640`', src\lib.rs:250:9

failures:
    captrs_tests::test_capture
    captrs_tests::test_capture_components

The discrepency is usually an integer multiple of one of either the width or height of the frame, e.g.: the test_capture fails with 4976640 which, when divided by 1440 (the height of the frame) gives 3456. This is 16 pixels more than the actual 3440 width. Screenshot 2023-05-15 131323 The additional pixels (on the right of the frame) are transparent.

Cause

This appears to be caused by an issue in the dxgcap crate; more investigation needed

edit This issue appears to originate somewhere in either the winapi crate or in the windows api itself

TommyGymer commented 1 year ago

I've reverted those changes; I've been working on an issue I found in your dxgcap crate (the archived one) which is why I'd changed to captrs2, though I'll probably submit another merge request once I've made those changes and remove the captrs2 crate I published earlier: keeps things simpler.

TommyGymer commented 1 year ago

@bryal , all the reverts should have been made. I've managed to build on windows while targeting linux-gnu, though my WSL install didn't build (seemed to be because it thought it was windows) and I have no way of testing if it builds on linux directly.

bryal commented 1 year ago

Looks good, thank you