mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-23 21:21:05 +03:00
set width,height,stride together with the rgba data for rendering
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
codec::{EncoderApi, EncoderCfg},
|
||||
hw, ImageFormat, HW_STRIDE_ALIGN,
|
||||
hw, ImageFormat, ImageRgb, HW_STRIDE_ALIGN,
|
||||
};
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
@@ -227,30 +227,28 @@ pub struct HwDecoderImage<'a> {
|
||||
}
|
||||
|
||||
impl HwDecoderImage<'_> {
|
||||
// take dst_stride into account when you convert
|
||||
pub fn to_fmt(
|
||||
&self,
|
||||
(fmt, dst_stride): (ImageFormat, usize),
|
||||
fmt_data: &mut Vec<u8>,
|
||||
i420: &mut Vec<u8>,
|
||||
) -> ResultType<()> {
|
||||
pub fn to_fmt(&self, rgb: &mut ImageRgb, i420: &mut Vec<u8>) -> ResultType<()> {
|
||||
let frame = self.frame;
|
||||
rgb.w = frame.width as _;
|
||||
rgb.h = frame.height as _;
|
||||
// take dst_stride into account when you convert
|
||||
let dst_stride = rgb.stride;
|
||||
match frame.pixfmt {
|
||||
AVPixelFormat::AV_PIX_FMT_NV12 => hw::hw_nv12_to(
|
||||
fmt,
|
||||
rgb.fmt,
|
||||
frame.width as _,
|
||||
frame.height as _,
|
||||
&frame.data[0],
|
||||
&frame.data[1],
|
||||
frame.linesize[0] as _,
|
||||
frame.linesize[1] as _,
|
||||
fmt_data,
|
||||
&mut rgb.raw as _,
|
||||
i420,
|
||||
HW_STRIDE_ALIGN,
|
||||
),
|
||||
AVPixelFormat::AV_PIX_FMT_YUV420P => {
|
||||
hw::hw_i420_to(
|
||||
fmt,
|
||||
rgb.fmt,
|
||||
frame.width as _,
|
||||
frame.height as _,
|
||||
&frame.data[0],
|
||||
@@ -259,7 +257,7 @@ impl HwDecoderImage<'_> {
|
||||
frame.linesize[0] as _,
|
||||
frame.linesize[1] as _,
|
||||
frame.linesize[2] as _,
|
||||
fmt_data,
|
||||
&mut rgb.raw as _,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
@@ -267,11 +265,17 @@ impl HwDecoderImage<'_> {
|
||||
}
|
||||
|
||||
pub fn bgra(&self, bgra: &mut Vec<u8>, i420: &mut Vec<u8>) -> ResultType<()> {
|
||||
self.to_fmt((ImageFormat::ARGB, 1), bgra, i420)
|
||||
let mut rgb = ImageRgb::new(ImageFormat::ARGB, 1);
|
||||
self.to_fmt(&mut rgb, i420)?;
|
||||
*bgra = rgb.raw;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn rgba(&self, rgba: &mut Vec<u8>, i420: &mut Vec<u8>) -> ResultType<()> {
|
||||
self.to_fmt((ImageFormat::ABGR, 1), rgba, i420)
|
||||
let mut rgb = ImageRgb::new(ImageFormat::ABGR, 1);
|
||||
self.to_fmt(&mut rgb, i420)?;
|
||||
*rgba = rgb.raw;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user