From 720c4ef35dc0f8cf021377fccd89560e7733badb Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 9 Nov 2024 17:59:24 +0100 Subject: [PATCH] core/scale: handle mismatching number of components on frame copy --- nihav-core/src/scale/mod.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/nihav-core/src/scale/mod.rs b/nihav-core/src/scale/mod.rs index c11d875..8054523 100644 --- a/nihav-core/src/scale/mod.rs +++ b/nihav-core/src/scale/mod.rs @@ -184,8 +184,9 @@ fn copy(pic_in: &NABufferType, pic_out: &mut NABufferType) return; } let mut same = true; - let num_components = sbuf.get_info().get_format().get_num_comp(); - for i in 0..num_components { + let src_components = sbuf.get_info().get_format().get_num_comp(); + let dst_components = dbuf.get_info().get_format().get_num_comp(); + for i in 0..src_components.max(dst_components) { if sbuf.get_stride(i) != dbuf.get_stride(i) { same = false; break; @@ -201,7 +202,7 @@ fn copy(pic_in: &NABufferType, pic_out: &mut NABufferType) ddata.copy_from_slice(&sdata[0..]); } else { let sdata = sbuf.get_data(); - for comp in 0..num_components { + for comp in 0..src_components.min(dst_components) { let (_, h) = sbuf.get_dimensions(comp); let src = &sdata[sbuf.get_offset(comp)..]; let sstride = sbuf.get_stride(comp); @@ -217,8 +218,9 @@ fn copy(pic_in: &NABufferType, pic_out: &mut NABufferType) } } else if let (Some(ref sbuf), Some(ref mut dbuf)) = (pic_in.get_vbuf16(), pic_out.get_vbuf16()) { let mut same = true; - let num_components = sbuf.get_info().get_format().get_num_comp(); - for i in 0..num_components { + let src_components = sbuf.get_info().get_format().get_num_comp(); + let dst_components = dbuf.get_info().get_format().get_num_comp(); + for i in 0..src_components.max(dst_components) { if sbuf.get_stride(i) != dbuf.get_stride(i) { same = false; break; @@ -234,7 +236,7 @@ fn copy(pic_in: &NABufferType, pic_out: &mut NABufferType) ddata.copy_from_slice(&sdata[0..]); } else { let sdata = sbuf.get_data(); - for comp in 0..num_components { + for comp in 0..src_components.min(dst_components) { let (_, h) = sbuf.get_dimensions(comp); let src = &sdata[sbuf.get_offset(comp)..]; let sstride = sbuf.get_stride(comp); -- 2.39.5