2 use super::kernel::Kernel;
7 fn new() -> Self { Self{} }
10 fn scale_line<T:Copy>(src: &[T], dst: &mut [T], src_w: usize, dst_w: usize) {
12 (&mut dst[..dst_w]).copy_from_slice(&src[..dst_w]);
13 } else if src_w < dst_w {
14 if dst_w % src_w == 0 {
15 let step = dst_w / src_w;
16 for (out, srcv) in dst.chunks_exact_mut(step).take(src_w).zip(src.iter()) {
17 for el in out.iter_mut() {
23 for out in dst.iter_mut().take(dst_w) {
24 *out = src[pos / dst_w];
29 if dst_w % src_w == 0 {
30 let step = src_w / dst_w;
31 for (out, srcv) in dst.iter_mut().take(dst_w).zip(src.iter().step_by(step)) {
36 for out in dst.iter_mut().take(dst_w) {
37 *out = src[pos / dst_w];
44 macro_rules! scale_loop {
45 ($sbuf:expr, $dbuf:expr) => {
46 let fmt = $sbuf.get_info().get_format();
47 let ncomp = fmt.get_num_comp();
48 for comp in 0..ncomp {
49 let istride = $sbuf.get_stride(comp);
50 let dstride = $dbuf.get_stride(comp);
51 let (sw, sh) = $sbuf.get_dimensions(comp);
52 let (dw, dh) = $dbuf.get_dimensions(comp);
53 let ioff = $sbuf.get_offset(comp);
54 let mut doff = $dbuf.get_offset(comp);
55 let src = $sbuf.get_data();
56 let dst = $dbuf.get_data_mut().unwrap();
59 let soff = ioff + sy * istride;
60 scale_line(&src[soff..], &mut dst[doff..], sw, dw);
67 impl Kernel for NNResampler {
68 fn init(&mut self, in_fmt: &ScaleInfo, dest_fmt: &ScaleInfo) -> ScaleResult<NABufferType> {
69 let res = alloc_video_buffer(NAVideoInfo::new(dest_fmt.width, dest_fmt.height, false, in_fmt.fmt), 3);
70 if res.is_err() { return Err(ScaleError::AllocError); }
73 fn process(&mut self, pic_in: &NABufferType, pic_out: &mut NABufferType) {
74 if let (Some(ref sbuf), Some(ref mut dbuf)) = (pic_in.get_vbuf(), pic_out.get_vbuf()) {
75 scale_loop!(sbuf, dbuf);
76 } else if let (Some(ref sbuf), Some(ref mut dbuf)) = (pic_in.get_vbuf16(), pic_out.get_vbuf16()) {
77 scale_loop!(sbuf, dbuf);
78 } else if let (Some(ref sbuf), Some(ref mut dbuf)) = (pic_in.get_vbuf32(), pic_out.get_vbuf32()) {
79 scale_loop!(sbuf, dbuf);
86 pub fn create_scale() -> Box<dyn Kernel> {
87 Box::new(NNResampler::new())