fix clippy warnings
[nihav.git] / nihav-indeo / src / codecs / imc.rs
index cb89b8ee403d198460080715a0f5c204aa411679..ea4d0b02d700c12eeb2375ebd1658b92aee655e3 100644 (file)
@@ -161,7 +161,7 @@ impl BitAlloc {
                 if len < 0 { len = 0; }
                 if len > 6 { len = 6; }
                 self.band_bits[band] = len as u8;
-                cur_bits += (self.band_width[band] as i32) * (len as i32);
+                cur_bits += (self.band_width[band] as i32) * len;
                 if len > 0 {
                     acc += self.band_width[band] as i32;
                 }
@@ -348,7 +348,6 @@ fn calc_maxcoef(coef: f32) -> (f32, f32) {
 
 impl IMCDecoder {
     fn new(is_imc: bool) -> Self {
-        let mut codes: [[Codebook<u8>; 4]; 4];
         let mut cycle1: [usize; BANDS] = [0; BANDS];
         let mut cycle2: [usize; BANDS] = [0; BANDS];
         let mut weights1: [f32; BANDS-1] = [0.0; BANDS-1];
@@ -359,15 +358,16 @@ impl IMCDecoder {
             weights1.copy_from_slice(&IMC_WEIGHTS1);
             weights2.copy_from_slice(&IMC_WEIGHTS2);
         }
-        unsafe {
-            codes = mem::MaybeUninit::uninit().assume_init();
-            for i in 0..4 {
-                for j in 0..4 {
-                    let mut cr = IMCCodeReader::new(i, j);
-                    ptr::write(&mut codes[i][j], Codebook::new(&mut cr, CodebookMode::MSB).unwrap());
+        let codes = unsafe {
+                let mut ucodes: mem::MaybeUninit::<[[Codebook<u8>; 4]; 4]> = mem::MaybeUninit::uninit();
+                for i in 0..4 {
+                    for j in 0..4 {
+                        let mut cr = IMCCodeReader::new(i, j);
+                        ptr::write(&mut (*ucodes.as_mut_ptr())[i][j], Codebook::new(&mut cr, CodebookMode::MSB).unwrap());
+                    }
                 }
-            }
-        }
+                ucodes.assume_init()
+            };
         IMCDecoder {
             is_imc,
             chmap:      NAChannelMap::new(),
@@ -643,7 +643,7 @@ impl IMCDecoder {
             }
             if self.ba.band_present[band] {
                 let band_w = IMC_BANDS[band + 1] - IMC_BANDS[band];
-                let bitsum = self.ba.band_bitsum[band] as usize;
+                let bitsum = self.ba.band_bitsum[band];
                 if (bitsum > 0) && (((band_w * 3) >> 1) > bitsum) {
                     self.ba.band_skip[band] = true;
                 }
@@ -652,7 +652,7 @@ impl IMCDecoder {
 
         self.read_skip_flags(br)?;
 
-        let mut ch_data = &mut self.ch_data[ch];
+        let ch_data = &mut self.ch_data[ch];
         for band in 0..BANDS {
             ch_data.adj_floor[band] = ch_data.new_floor[band];
             let band_w = IMC_BANDS[band + 1] - IMC_BANDS[band];
@@ -675,7 +675,7 @@ impl IMCDecoder {
         }
 
         if bits_freed < 0 { return Err(DecoderError::Bug); }
-        self.ba.adjust_bit_allocation(&mut ch_data, bits_freed);
+        self.ba.adjust_bit_allocation(ch_data, bits_freed);
 
         Ok(())
     }
@@ -903,8 +903,8 @@ impl NADecoder for IMCDecoder {
         let channels = self.ainfo.get_channels() as usize;
         for chunk in pktbuf.chunks(BLOCK_SIZE * channels) {
             for ch in 0..channels {
-                let off = abuf.get_offset(ch as usize) + start;
-                self.decode_block(chunk, ch as usize, &mut dst[off..off+COEFFS])?;
+                let off = abuf.get_offset(ch) + start;
+                self.decode_block(chunk, ch, &mut dst[off..off+COEFFS])?;
             }
             if (channels == 2) && ((chunk[1] & 0x20) != 0) {
                 let off1 = abuf.get_offset(0) + start;
@@ -1130,6 +1130,7 @@ mod test {
 
 //        let file = "assets/Indeo/neal73_saber.avi";
 //        let file = "assets/Indeo/IMC/hvalen.avi";
+        // sample from a private collection
         let file = "assets/Indeo/IMC/8khz.avi";
 //        let file = "assets/Indeo/STsKlassFist-1a.avi";
 //        let file = "assets/Indeo/IMC/Angel Bday.avi";