This commit is contained in:
rustdesk 2023-03-03 15:34:57 +08:00
parent 1633d93b59
commit 876fb26a67

View File

@ -539,15 +539,17 @@ impl Image {
self.inner().stride[iplane]
}
pub fn to(&self, fmt: ImageFormat, stride_align: usize, dst: &mut Vec<u8>) {
pub fn to(&self, fmt: ImageFormat, stride: usize, dst: &mut Vec<u8>) {
let h = self.height();
let mut w = self.width();
let bps = match fmt {
let w = self.width();
let bytes_per_pixel = match fmt {
ImageFormat::Raw => 3,
ImageFormat::ARGB | ImageFormat::ABGR => 4,
};
w = (w + stride_align - 1) & !(stride_align - 1);
dst.resize(h * w * bps, 0);
// https://github.com/lemenkov/libyuv/blob/6900494d90ae095d44405cd4cc3f346971fa69c9/source/convert_argb.cc#L128
// https://github.com/lemenkov/libyuv/blob/6900494d90ae095d44405cd4cc3f346971fa69c9/source/convert_argb.cc#L129
let bytes_per_row = (w * bytes_per_pixel + stride - 1) & !(stride - 1);
dst.resize(h * bytes_per_row, 0);
let img = self.inner();
unsafe {
match fmt {
@ -560,7 +562,7 @@ impl Image {
img.planes[2],
img.stride[2],
dst.as_mut_ptr(),
(w * bps) as _,
bytes_per_row as _,
self.width() as _,
self.height() as _,
);
@ -574,7 +576,7 @@ impl Image {
img.planes[2],
img.stride[2],
dst.as_mut_ptr(),
(w * bps) as _,
bytes_per_row as _,
self.width() as _,
self.height() as _,
);
@ -588,7 +590,7 @@ impl Image {
img.planes[2],
img.stride[2],
dst.as_mut_ptr(),
(w * bps) as _,
bytes_per_row as _,
self.width() as _,
self.height() as _,
);