video/screen: Make RGB frames without alpha
This commit is contained in:
parent
2ad43994b8
commit
bbe7f76829
|
@ -190,28 +190,25 @@ impl VideoDecoder for ScreenVideoDecoder {
|
|||
return Err(ScreenError::KeyframeInvalid.into());
|
||||
}
|
||||
|
||||
let mut rgba = vec![0u8; w * h * 4];
|
||||
let mut rgb = vec![0u8; w * h * 3];
|
||||
|
||||
// convert from BGR to RGBA and flip Y
|
||||
// convert from BGR to RGB and flip Y
|
||||
for y in 0..h {
|
||||
let data_row = &data[y * w * 3..(y + 1) * w * 3];
|
||||
let rgba_row = &mut rgba[(h - y - 1) * w * 4..(h - y) * w * 4];
|
||||
let rgb_row = &mut rgb[(h - y - 1) * w * 3..(h - y) * w * 3];
|
||||
|
||||
for (bgr, rgba) in data_row.chunks(3).zip(rgba_row.chunks_mut(4)) {
|
||||
rgba.copy_from_slice(&[bgr[2], bgr[1], bgr[0], 255]);
|
||||
for (bgr, rgb) in data_row.chunks(3).zip(rgb_row.chunks_mut(3)) {
|
||||
rgb.copy_from_slice(&[bgr[2], bgr[1], bgr[0]]);
|
||||
}
|
||||
}
|
||||
|
||||
self.last_frame = Some(data);
|
||||
|
||||
// NOTE: We could get away with only storing RGB data (saving some memory), as there is no
|
||||
// alpha support in Screen V1, but since the render backends always want RGBA right now,
|
||||
// it's better to do the pixel format conversion here, all at once.
|
||||
Ok(DecodedFrame::new(
|
||||
w as u32,
|
||||
h as u32,
|
||||
BitmapFormat::Rgba,
|
||||
rgba,
|
||||
BitmapFormat::Rgb,
|
||||
rgb,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue