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

Feature: add capturing into raw BGR buffer #85

Open
konstantinzolotarev opened this issue Nov 24, 2023 · 3 comments
Open

Feature: add capturing into raw BGR buffer #85

konstantinzolotarev opened this issue Nov 24, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@konstantinzolotarev
Copy link

konstantinzolotarev commented Nov 24, 2023

First of all,, thank you very much for a great work.

Is it possible to add ability to make screenshots into raw buffer rather than Result<ImageRgba> ?

it's very useful for work with opencv, but right now your lib does conversion from bgr into rgba and then to work properly with images in opencv code have to do backward conversion from rgba into bgr.

Just a side note. Result might be something like

pub struct RawImage {
    pub width: u32,
    pub height: u32,
    pub data: Vec<u8>, // even BGRA works very well in here. 
}

Then it's very easy to convert it into opencv::Mat

unsafe {
        Mat::new_rows_cols_with_data(
            image.height as i32,
            image.width as i32,
            core::CV_8UC4,
            image.data.as_mut_ptr().cast::<c_void>(),
            core::Mat_AUTO_STEP,
        )
        .unwrap()
    }
@nashaofu nashaofu added the enhancement New feature or request label Nov 25, 2023
@nashaofu
Copy link
Owner

The current return value is RgbaImage, you see if you meet the need,By the way, the latest crate name is xcap

@hakoptak
Copy link

hakoptak commented Jun 1, 2024

Hi, I have the same request.

Also: isn't it a bit strange to save a screen capture with transparancy while the screenshot itself only contains pixels without transparancy? Getting a RGB buffer would save cpu some cycles and memory. Good for the environment ;)

Thanks for this nice library.

@konstantinzolotarev
Copy link
Author

@nashaofu Thank you very much !
Yep I already upgraded to new lib and tried working with RgbaImage, it has exactly same issue for me, to build RgbaImage lib have to walk through all pixels and swap R and B values (BGRA -> RGBA):

for bgra in buffer.chunks_exact_mut(4) {
        bgra.swap(0, 2);
}

And to convert it correctly into opencv.Mat format I have to swap it back form RGBA into BGRA.
So every screenshot have to be processed twice.
And because I have to read screen with max FPS possible, it's very costly for my case.

But don't worry I think it's very specific problem and I can easily solve it by just using parts of code from your lib in my experiments.

I can close issue if you want.

Anyway thank you very much for your hard work and help ! Very much appreciate all you have done !

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

No branches or pull requests

3 participants