Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Captured buffer has strange 1920x1920 length when capturing portrait screen #36

Open
lowleveldata opened this issue Nov 14, 2020 · 1 comment

Comments

@lowleveldata
Copy link

The following log was printed when I tried to capture from a portrait screen (1080 x 1920):

w: 1080, h: 1920, buffer_len: 14745600
pixels: 3686400, pixels / 1920: 1920
stride:4320
RGB-len:6220800

I have hard coded stride to 4320 so the final buffer would be the correct length. (The saved image is pure distorted noise nevertheless) It seems that the captured buffer would use a strange 1920x1920 resolution?

Code for reproduce:

fn cap_and_save(file_name: &str) -> () {
    let one_second = Duration::new(1, 0);
    let one_frame = one_second / 60;
    let display = Display::all().expect("Couldn't find any display.");
    let second = display
        .into_iter()
        .nth(1)
        .expect("Couldn't find second display.");
    let mut capturer = Capturer::new(second).expect("Couldn't begin capture.");
    let (w, h) = (capturer.width(), capturer.height());

    loop {
        // Wait until there's a frame.

        let buffer = match capturer.frame() {
            Ok(buffer) => buffer,
            Err(error) => {
                if error.kind() == WouldBlock {
                    // Keep spinning.
                    thread::sleep(one_frame);
                    continue;
                } else {
                    panic!("Error: {}", error);
                }
            }
        };

        println!("Captured! Saving...");

        // Flip the ARGB image into a RGB image.

        let mut bitflipped = Vec::with_capacity(w * h * 4);
        //let stride = buffer.len() / h;
        let stride = 4320;
        println!("w: {}, h: {}, buffer_len: {}", w, h, buffer.len());
        println!("pixels: {}, pixels / 1920: {}", buffer.len()/4, (buffer.len() / 4) / 1920);
        println!("stride:{}", stride);
        for y in 0..h {
            for x in 0..w {
                let i = stride * y + 4 * x;
                bitflipped.extend_from_slice(&[buffer[i + 1], buffer[i + 2], buffer[i + 3]]);
            }
        }

        println!("RGB-len:{}", bitflipped.len());
        ...
        break;
}

Env:
Windows 10, scrap = "0.5"

@Luz
Copy link

Luz commented Mar 29, 2021

Your code looks similar to the example in the example folder. I think the bitflipping is different?
bitflipped.extend_from_slice(&[buffer[i + 1], buffer[i + 2], buffer[i + 3]]);
might require to be
bitflipped.extend_from_slice(&[buffer[i + 2], buffer[i + 1], buffer[i + 0], 255]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants