CapSoftware / scap

High-performance, cross-platform screen capture library in Rust.
https://crates.io/crates/scap
Other
225 stars 43 forks source link

Default FrameType Causes BGRA Frame Output RGBA #98

Open MrAdhit opened 4 months ago

MrAdhit commented 4 months ago

When I set output_type to default, the frame format is in RGBA even tho it uses the BGRA enum, this doesn't happen if I specify the output_type to BGRA explicitly

here's the reproducible code https://gist.github.com/MrAdhit/12a35dec29741703173263717724b5a5

https://github.com/helmerapp/scap/assets/47937950/c6bded9f-9e8c-4e71-b920-ed319ad3a286

RohanPunjani commented 4 months ago

Hey, thank you for pointing out the issue!

This behavior occurs because of the ColorFormat being set here

let color_format = match options.output_type {
        FrameType::BGRAFrame => ColorFormat::Bgra8,
        _ => ColorFormat::Rgba8,
};

which sets the color format of any other frameType as Rgba8 which was causing the issue as the default FrameType is set as YUV frame as you can see here

#[derive(Debug, Clone, Copy, Default)]
pub enum FrameType {
    #[default]
    YUVFrame,
    BGR0,
    RGB, // Prefer BGR0 because RGB is slower
    BGRAFrame,
}
MAlba124 commented 4 months ago

@RohanPunjani I think the problem is that only BGRA frames are sent from the capturer: https://github.com/helmerapp/scap/blob/1b7c70df754ee9c2c4e040266f45d16354367bd7/src/capturer/engine/win/mod.rs#L82-L84 https://github.com/helmerapp/scap/blob/1b7c70df754ee9c2c4e040266f45d16354367bd7/src/capturer/engine/win/mod.rs#L102-L104

valenotary commented 3 months ago

I think I might be ahving a similar issue with #110