core/scale: add conversion into paletted format
[nihav.git] / nihav-core / src / scale / repack.rs
index 4f2ce999b8f20fcde54da118932072a45aed6e4c..faa5fe72dc58270376c943d5c455087f44b03817 100644 (file)
@@ -61,7 +61,7 @@ impl Kernel for PackKernel {
                     let ddata = dbuf.get_data_mut().unwrap();
                     for (src, dst) in sdata.chunks(istride).zip(ddata.chunks_mut(dstride)).take(h) {
                         for x in 0..w {
-                            dst[x * step + self.ooff[comp]] = convert_depth(src[x] as u32, self.depths[comp], self.osize[comp]) as u8;
+                            dst[x * step + self.ooff[comp]] = convert_depth(u32::from(src[x]), self.depths[comp], self.osize[comp]) as u8;
                         }
                     }
                 }
@@ -80,7 +80,7 @@ impl Kernel for PackKernel {
                     for x in 0..w {
                         let mut elem: u32 = 0;
                         for comp in 0..self.ncomps {
-                            let c = src[ioff[comp] + x] as u32;
+                            let c = u32::from(src[ioff[comp] + x]);
                             elem |= convert_depth(c, self.depths[comp], self.osize[comp]) << self.shifts[comp];
                         }
                         dst[x] = elem as u16;
@@ -102,7 +102,7 @@ unimplemented!();
     }
 }
 
-pub fn create_pack() -> Box<Kernel> {
+pub fn create_pack() -> Box<dyn Kernel> {
     Box::new(PackKernel::new())
 }
 
@@ -146,6 +146,7 @@ impl Kernel for UnpackKernel {
         for i in 0..self.ncomps {
             df.comp_info[i] = chr[i];
         }
+        df.palette = false;
 println!(" [intermediate format {}]", df);
         let res = alloc_video_buffer(NAVideoInfo::new(in_fmt.width, in_fmt.height, false, df), 3);
         if res.is_err() { return Err(ScaleError::AllocError); }
@@ -198,7 +199,7 @@ unimplemented!();
                 let dst = dbuf.get_data_mut().unwrap();
                 for src in sdata.chunks(istride).take(h) {
                     for x in 0..w {
-                        let elem = src[x] as u32;
+                        let elem = u32::from(src[x]);
                         for i in 0..self.ncomps {
                             dst[offs[i] + x] = convert_depth((elem >> self.shifts[i]) & self.masks[i], self.depths[i], self.osize[i]) as u8;
                         }
@@ -216,7 +217,7 @@ unimplemented!();
     }
 }
 
-pub fn create_unpack() -> Box<Kernel> {
+pub fn create_unpack() -> Box<dyn Kernel> {
     Box::new(UnpackKernel::new())
 }
 
@@ -281,7 +282,7 @@ println!(" [intermediate format {}]", df);
                 for x in 0..w {
                     let palidx = src[x] as usize;
                     for i in 0..self.ncomps {
-                        let elem = pal[palidx * self.palstep + self.coffs[i]] as u32;
+                        let elem = u32::from(pal[palidx * self.palstep + self.coffs[i]]);
                         dst[offs[i] + x] = convert_depth(elem, self.depths[i], 8) as u8;
                     }
                 }
@@ -293,6 +294,6 @@ println!(" [intermediate format {}]", df);
     }
 }
 
-pub fn create_depal() -> Box<Kernel> {
+pub fn create_depal() -> Box<dyn Kernel> {
     Box::new(DepalKernel::new())
 }