From: Kostya Shishkov Date: Wed, 21 Oct 2020 16:22:18 +0000 (+0200) Subject: core/scale: fill absent planes during scale process X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=c17489b831959f6543a506a21b4f333e629b47f5;p=nihav.git core/scale: fill absent planes during scale process --- diff --git a/nihav-core/src/scale/scale.rs b/nihav-core/src/scale/scale.rs index b0415c9..eb8ff6c 100644 --- a/nihav-core/src/scale/scale.rs +++ b/nihav-core/src/scale/scale.rs @@ -41,6 +41,14 @@ fn scale_line(src: &[T], dst: &mut [T], src_w: usize, dst_w: usize) { } } +fn fill_plane(dst: &mut [T], w: usize, h: usize, stride: usize, val: T) { + for row in dst.chunks_mut(stride).take(h) { + for el in row.iter_mut().take(w) { + *el = val; + } + } +} + macro_rules! scale_loop { ($sbuf:expr, $dbuf:expr) => { let fmt = $sbuf.get_info().get_format(); @@ -61,6 +69,32 @@ macro_rules! scale_loop { doff += dstride; } } + let dfmt = $dbuf.get_info().get_format(); + let ndcomp = dfmt.get_num_comp(); + if ndcomp > ncomp { + if !fmt.alpha && dfmt.alpha { + let acomp = ndcomp - 1; + let dstride = $dbuf.get_stride(acomp); + let (dw, dh) = $dbuf.get_dimensions(acomp); + let doff = $dbuf.get_offset(acomp); + let dst = $dbuf.get_data_mut().unwrap(); + fill_plane(&mut dst[doff..], dw, dh, dstride, 0); + } + if fmt.model.is_yuv() && ((!fmt.alpha && ncomp == 1) || (fmt.alpha && ncomp == 2)) && ndcomp >= 3 { + let uval = 1 << (dfmt.comp_info[1].unwrap().depth - 1); + let vval = 1 << (dfmt.comp_info[2].unwrap().depth - 1); + + let ustride = $dbuf.get_stride(1); + let vstride = $dbuf.get_stride(2); + let (uw, uh) = $dbuf.get_dimensions(1); + let (vw, vh) = $dbuf.get_dimensions(2); + let uoff = $dbuf.get_offset(1); + let voff = $dbuf.get_offset(2); + let dst = $dbuf.get_data_mut().unwrap(); + fill_plane(&mut dst[uoff..], uw, uh, ustride, uval); + fill_plane(&mut dst[voff..], vw, vh, vstride, vval); + } + } }; }