]> git.nihav.org Git - nihav.git/commitdiff
nihav_core: fix or update clippy warnings
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 9 Nov 2024 13:16:32 +0000 (14:16 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 9 Nov 2024 14:34:05 +0000 (15:34 +0100)
14 files changed:
nihav-core/src/compr/deflate.rs
nihav-core/src/compr/mod.rs
nihav-core/src/formats.rs
nihav-core/src/io/bitwriter.rs
nihav-core/src/io/byteio.rs
nihav-core/src/io/codebook.rs
nihav-core/src/io/intcode.rs
nihav-core/src/lib.rs
nihav-core/src/scale/palette/elbg.rs
nihav-core/src/scale/palette/mediancut.rs
nihav-core/src/scale/palette/neuquant.rs
nihav-core/src/scale/palette/palettise.rs
nihav-core/src/scale/repack.rs
nihav-core/src/scale/scale/mod.rs

index c0a2d5fe765d234f493bde606236cc5b40672f5d..052043d8833ea40c5df8c4846b53520df382a4d6 100644 (file)
@@ -368,9 +368,9 @@ impl Inflate {
             return Err(DecompressError::InvalidData);
         }
         let cstart = (self.bpos.wrapping_sub(offset)) & mask;
-        for i in 0..len {
+        for (i, out) in dst[..len].iter_mut().enumerate() {
             self.buf[(self.bpos + i) & mask] = self.buf[(cstart + i) & mask];
-            dst[i] = self.buf[(cstart + i) & mask];
+            *out = self.buf[(cstart + i) & mask];
         }
         self.bpos = (self.bpos + len) & mask;
         self.full_pos += len;
@@ -1041,10 +1041,9 @@ struct GzipCRC32 {
 }
 
 impl GzipCRC32 {
-    #[allow(clippy::unreadable_literal)]
     fn new() -> Self {
         let mut tab = [0u32; 256];
-        for i in 0..256 {
+        for (i, el) in tab.iter_mut().enumerate() {
             let mut c = i as u32;
             for _ in 0..8 {
                 if (c & 1) != 0 {
@@ -1053,7 +1052,7 @@ impl GzipCRC32 {
                     c >>= 1;
                 }
             }
-            tab[i] = c;
+            *el = c;
         }
         Self { tab, crc: 0 }
     }
@@ -1159,9 +1158,7 @@ pub fn gzip_decode(br: &mut ByteReader, skip_crc: bool) -> DecompressResult<Vec<
             for i in 0..shift_len {
                 tail[i] = tail[i + inlen];
             }
-            for i in shift_len..8 {
-                tail[i] = inblk[i - shift_len];
-            }
+            tail[shift_len..8].copy_from_slice(&inblk[..8 - shift_len]);
         }
     }
     if !skip_crc {
@@ -1385,7 +1382,7 @@ impl DeflateWriter {
     }
     fn write_len_bits(&mut self, len: u16) {
         let llen = len - 3;
-        if llen >= 8 && llen < 255 {
+        if (8..255).contains(&llen) {
             let bits = (16 - llen.leading_zeros() - 3) as u8;
             self.write(llen & ((1 << bits) - 1), bits);
         }
index a2062d497be3246ac92bb2b56b6b4c6ebab0abed..6e2f7821a3b064d5440f0cb8f940c2bc743b759b 100644 (file)
@@ -1,6 +1,5 @@
 //! Various compression formats support.
 #[cfg(feature="deflate")]
-#[allow(clippy::manual_range_contains)]
 pub mod deflate;
 
 use crate::io::byteio::ByteIOError;
index fdb7a1b7640a303d17a7552970ec3ad2fc2d151f..bdb0f40b4d908ea750974c97b2563798cc767ec6 100644 (file)
@@ -713,16 +713,16 @@ impl NAPixelFormaton {
                     start_shift = start_shift.min(comp.shift);
                     if comp.comp_offs != 0 { use_shift = false; }
                 }
-                for component in 0..(self.components as usize) {
+                for dname in name[..(self.components as usize)].iter_mut() {
                     for (comp, cname) in self.comp_info.iter().zip(b"rgba".iter()) {
                         if let Some(comp) = comp {
                             if use_shift {
                                 if comp.shift == start_shift {
-                                    name[component] = *cname;
+                                    *dname = *cname;
                                     start_shift += comp.depth;
                                 }
                             } else if comp.comp_offs == start_off {
-                                name[component] = *cname;
+                                *dname = *cname;
                                 if planar {
                                     start_off += 1;
                                 } else {
@@ -909,13 +909,12 @@ fn parse_rgb_format(s: &str) -> Result<NAPixelFormaton, FormatParseError> {
             },
             5551 => {
                 let mut offs = [0; 4];
-                let depth = [ 5, 5, 5, 1 ];
                 let mut cur_off = 0;
-                for comp in 0..4 {
+                for (comp, &depth) in [ 5, 5, 5, 1 ].iter().enumerate() {
                     for (off, ord) in offs.iter_mut().zip(order.iter()) {
                         if *ord == comp {
                             *off = cur_off;
-                            cur_off += depth[comp];
+                            cur_off += depth;
                             break;
                         }
                     }
index 4f3c39c25d5e618dbc41c54a3a25f703044507e7..e11a7cf8349533d3c2c2e2edb1e9be5a8a918928 100644 (file)
@@ -76,7 +76,6 @@ impl BitWriter {
         self.flush();
     }
     /// Writes `bits` bits of `val` value to the output.
-    #[allow(clippy::collapsible_if)]
     #[allow(clippy::collapsible_else_if)]
     pub fn write(&mut self, val: u32, bits: u8) {
         if bits == 0 {
index 61b8816f2dd78ae2d7bc0db5f1f2bcad3fa244e8..3642422b4c62e9d0fab2734da8b7df4c1ec961e7 100644 (file)
@@ -517,8 +517,7 @@ impl<'a> ByteIO for MemoryReader<'a> {
         Ok(read_size)
     }
 
-    #[allow(unused_variables)]
-    fn write_buf(&mut self, buf: &[u8]) -> ByteIOResult<()> {
+    fn write_buf(&mut self, _buf: &[u8]) -> ByteIOResult<()> {
         Err(ByteIOError::NotImplemented)
     }
 
@@ -618,8 +617,7 @@ impl<T: Read+Seek> ByteIO for FileReader<T> {
         Ok(size)
     }
 
-    #[allow(unused_variables)]
-    fn write_buf(&mut self, buf: &[u8]) -> ByteIOResult<()> {
+    fn write_buf(&mut self, _buf: &[u8]) -> ByteIOResult<()> {
         Err(ByteIOError::NotImplemented)
     }
 
@@ -773,8 +771,7 @@ impl<T: Read+Seek> ByteIO for BoundedFileReader<T> {
         Ok(size)
     }
 
-    #[allow(unused_variables)]
-    fn write_buf(&mut self, buf: &[u8]) -> ByteIOResult<()> {
+    fn write_buf(&mut self, _buf: &[u8]) -> ByteIOResult<()> {
         Err(ByteIOError::NotImplemented)
     }
 
@@ -1006,28 +1003,23 @@ impl<'a> MemoryWriter<'a> {
 }
 
 impl<'a> ByteIO for MemoryWriter<'a> {
-    #[allow(unused_variables)]
     fn read_byte(&mut self) -> ByteIOResult<u8> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
     fn peek_byte(&mut self) -> ByteIOResult<u8> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
-    fn read_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+    fn read_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
-    fn read_buf_some(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+    fn read_buf_some(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
-    fn peek_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+    fn peek_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
         Err(ByteIOError::NotImplemented)
     }
 
@@ -1084,28 +1076,23 @@ impl<'a> GrowableMemoryWriter<'a> {
 }
 
 impl<'a> ByteIO for GrowableMemoryWriter<'a> {
-    #[allow(unused_variables)]
     fn read_byte(&mut self) -> ByteIOResult<u8> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
     fn peek_byte(&mut self) -> ByteIOResult<u8> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
-    fn read_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+    fn read_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
-    fn read_buf_some(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+    fn read_buf_some(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
-    fn peek_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+    fn peek_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
         Err(ByteIOError::NotImplemented)
     }
 
@@ -1155,28 +1142,23 @@ impl<T: Write+Seek> FileWriter<T> {
 }
 
 impl<T: Write+Seek> ByteIO for FileWriter<T> {
-    #[allow(unused_variables)]
     fn read_byte(&mut self) -> ByteIOResult<u8> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
     fn peek_byte(&mut self) -> ByteIOResult<u8> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
-    fn read_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+    fn read_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
-    fn read_buf_some(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+    fn read_buf_some(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
         Err(ByteIOError::NotImplemented)
     }
 
-    #[allow(unused_variables)]
-    fn peek_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+    fn peek_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
         Err(ByteIOError::NotImplemented)
     }
 
index f533cb263abe8abf76dfe67143f4100b979470b4..bd7bb1e8ce24f90111cfc480d0c6d9f1fa88c193 100644 (file)
@@ -360,7 +360,6 @@ impl<S: Copy> Codebook<S> {
 }
 
 impl<'a, S: Copy> CodebookReader<S> for BitReader<'a> {
-    #[allow(unused_variables)]
     fn read_cb(&mut self, cb: &Codebook<S>) -> CodebookResult<S> {
         let mut esc = true;
         let mut idx = 0;
index 6b45b77588f33327083d84b9dfe14d484bd02856..b66afdbddf2adb8ce32f2a1a5e9553083120de76 100644 (file)
@@ -168,7 +168,6 @@ impl<'a> IntCodeReader for BitReader<'a> {
             UintCodeType::GammaP                  => read_gammap(self),
         }
     }
-    #[allow(unused_variables)]
     fn read_code_signed(&mut self, t: IntCodeType) -> BitReaderResult<i32> {
         let uval =
             match t {
@@ -178,8 +177,8 @@ impl<'a> IntCodeReader for BitReader<'a> {
                 IntCodeType::GammaP                  => read_gammap(self)?,
             };
         match t {
-            IntCodeType::Golomb(m)               => Ok(uval_to_sval0mp(uval)),
-            IntCodeType::Rice(k)                 => Ok(uval_to_sval0mp(uval)),
+            IntCodeType::Golomb(_)               => Ok(uval_to_sval0mp(uval)),
+            IntCodeType::Rice(_)                 => Ok(uval_to_sval0mp(uval)),
             IntCodeType::Gamma                   => Ok(uval_to_sval0pm(uval)),
             IntCodeType::GammaP                  => Ok(uval_to_sval0pm(uval)),
         }
index b6e1690370e82c975f0e049ffec4f7ed088050e7..bb803bc910fc767c2b35b2e09b4af5798eb90241 100644 (file)
@@ -1,15 +1,10 @@
 //! Core functionality of NihAV intended to be used by both crates implementing format support and users.
 #[cfg(feature="decoders")]
 #[allow(clippy::upper_case_acronyms)]
-#[allow(clippy::cast_lossless)]
-#[allow(clippy::identity_op)]
 #[allow(clippy::too_many_arguments)]
-#[allow(clippy::unreadable_literal)]
 pub mod codecs;
 
 #[cfg(feature="compr")]
-#[allow(clippy::manual_memcpy)]
-#[allow(clippy::needless_range_loop)]
 pub mod compr;
 
 #[cfg(feature="muxers")]
@@ -18,7 +13,6 @@ pub mod muxers;
 #[cfg(feature="demuxers")]
 pub mod demuxers;
 
-#[allow(clippy::needless_range_loop)]
 #[allow(clippy::too_many_arguments)]
 pub mod formats;
 pub mod frame;
@@ -28,10 +22,5 @@ pub mod options;
 pub mod refs;
 pub mod reorder;
 #[allow(clippy::upper_case_acronyms)]
-#[allow(clippy::collapsible_if)]
-#[allow(clippy::many_single_char_names)]
-#[allow(clippy::needless_range_loop)]
-#[allow(clippy::trivially_copy_pass_by_ref)]
 pub mod scale;
-#[allow(clippy::unreadable_literal)]
 pub mod soundcvt;
index 9a7d96701e764e38729778da71daa7af6c6c61a2..1ec3edd341a53d72b88f2237f6668bbf799899f8 100644 (file)
@@ -77,8 +77,8 @@ impl ELBG {
     #[allow(dead_code)]
     pub fn new(initial_pal: &[[u8; 3]; 256]) -> Self {
         let mut clusters = Vec::with_capacity(256);
-        for i in 0..256 {
-            let pix = Pixel { r: initial_pal[i][0], g: initial_pal[i][1], b: initial_pal[i][2] };
+        for clr in initial_pal.iter() {
+            let pix = Pixel { r: clr[0], g: clr[1], b: clr[2] };
             let cluster = Cluster::new(pix);
             clusters.push(cluster);
         }
@@ -231,9 +231,9 @@ impl ELBG {
         let mut do_elbg_step = true;
         while (iterations < 10) && (dist < prev_dist - prev_dist / 100) {
             prev_dist = dist;
-            for i in 0..256 {
-                old_cb[i] = self.clusters[i].centroid;
-                self.clusters[i].reset();
+            for (cb, cluster) in old_cb.iter_mut().zip(self.clusters.iter_mut()) {
+                *cb = cluster.centroid;
+                cluster.reset();
             }
             // put pixels into the nearest clusters
             indices.clear();
@@ -290,11 +290,11 @@ impl ELBG {
                     let mut closest_idx = *low_idx;
                     let mut closest_dist = std::u32::MAX;
                     let low_centr = self.clusters[*low_idx].centroid;
-                    for i in 0..256 {//low_u.iter() {
-                        if i == *low_idx || used[i] {
+                    for (i, (cluster, &used)) in self.clusters.iter().zip(used.iter()).enumerate() {//low_u.iter() {
+                        if i == *low_idx || used {
                             continue;
                         }
-                        let dist = self.clusters[i].centroid.dist(low_centr);
+                        let dist = cluster.centroid.dist(low_centr);
                         if closest_dist > dist {
                             closest_dist = dist;
                             closest_idx  = i;
@@ -329,8 +329,8 @@ impl ELBG {
             iterations += 1;
         }
         if dist < prev_dist {
-            for i in 0..256 {
-                old_cb[i] = self.clusters[i].centroid;
+            for (cb, cluster) in old_cb.iter_mut().zip(self.clusters.iter()) {
+                *cb = cluster.centroid;
             }
         }
         for i in 0..256 {
index b8fb7d65296f6d27a02cd222270df187d8d5cbc0..0910328ed4f76d84aea7fa942871506cfcd3bfa0 100644 (file)
@@ -32,8 +32,8 @@ impl<'a> VQBox<'a> {
         for pix in arr.iter() {
             counts[idx(pix)] += 1;
         }
-        for i in 0..256 {
-            buckets.push(Vec::with_capacity(counts[i]));
+        for &count in counts.iter() {
+            buckets.push(Vec::with_capacity(count));
         }
         for pix in arr.iter() {
             buckets[idx(pix)].push(*pix);
index 09745000150c19c2c2a20e65cbdd365040f9e7f8..2168b6829924a8dbddd294715cb7259a3c767b45 100644 (file)
@@ -9,6 +9,7 @@ pub struct NeuQuantQuantiser {
 
 const SPECIAL_NODES: usize = 2;
 impl NeuQuantQuantiser {
+    #[allow(clippy::needless_range_loop)]
     pub fn new(factor: usize) -> Self {
         let mut weights = [[0.0; 3]; 256];
         if SPECIAL_NODES > 1 {
index 54467d3f9c4f95c055c39df25dcda4cdc923e647..ab82d2f00feeaadbd3a7e13993bf9442e92e380c 100644 (file)
@@ -122,10 +122,10 @@ impl KDTree {
         }
         let mut min = [255u8; 3];
         let mut max = [0u8; 3];
-        for i in start..end {
-            for comp in 0..3 {
-                min[comp] = min[comp].min(pal[i][comp]);
-                max[comp] = max[comp].max(pal[i][comp]);
+        for clr in pal[start..end].iter() {
+            for ((mi, ma), &c) in min.iter_mut().zip(max.iter_mut()).zip(clr.iter()) {
+                *mi = (*mi).min(c);
+                *ma = (*ma).max(c);
             }
         }
         let dr = max[0] - min[0];
index 8cdb8ea91b164df63ecb22409fd196bdef12b4cf..506e396430f2c6dbe9dd4dddb9f4846ebe4ca424 100644 (file)
@@ -166,8 +166,8 @@ impl Kernel for UnpackKernel {
         if let Some(ref buf) = pic_in.get_vbuf() {
             let step = buf.get_info().get_format().elem_size as usize;
             let mut soff: [usize; MAX_CHROMATONS] = [0; MAX_CHROMATONS];
-            for i in 0..self.ncomps {
-                soff[i] = buf.get_info().get_format().get_chromaton(i).unwrap().get_offset() as usize;
+            for (i, off) in soff[..self.ncomps].iter_mut().enumerate() {
+                *off = buf.get_info().get_format().get_chromaton(i).unwrap().get_offset() as usize;
             }
             let (w, h) = buf.get_dimensions(0);
             let ioff = buf.get_offset(0);
@@ -186,16 +186,18 @@ impl Kernel for UnpackKernel {
                 if ychr.next_elem == 0 || usize::from(ychr.next_elem) == step {
                     for src in sdata.chunks(istride).take(h) {
                         for x in 0..w {
-                            for i in 0..self.ncomps {
-                                dst[offs[i] + x] = src[x * step + soff[i]];
+                            for (&doff, &soff) in offs[..self.ncomps].iter().zip(soff.iter()) {
+                                dst[doff + x] = src[x * step + soff];
                             }
                         }
-                        for i in 0..self.ncomps { offs[i] += ostride[i]; }
+                        for (off, &stride) in offs[..self.ncomps].iter_mut().zip(ostride.iter()) {
+                            *off += stride;
+                        }
                     }
                 } else {
                     let mut steps: [usize; MAX_CHROMATONS] = [0; MAX_CHROMATONS];
-                    for i in 0..self.ncomps {
-                        steps[i] = buf.get_info().get_format().get_chromaton(i).unwrap().next_elem as usize;
+                    for (i, step) in steps[..self.ncomps].iter_mut().enumerate() {
+                        *step = buf.get_info().get_format().get_chromaton(i).unwrap().next_elem as usize;
                     }
 
                     for src in sdata.chunks(istride).take(h) {
index 5d0776d0ed3caf44851044315816ab6681818ce1..59bfc64999fd79134fc829c54729495cf2bd2543 100644 (file)
@@ -219,10 +219,10 @@ impl LanczosResize {
         let norm = std::f32::consts::PI * std::f32::consts::PI;
         let frac = (num as f32) / (den as f32);
         let a = order as f32;
-        for i in 0..(order * 2) {
+        for (i, coef) in coeffs[..order * 2].iter_mut().enumerate() {
             let x = frac - ((i as f32) + 1.0 - a);
             let fp = std::f32::consts::PI * x;
-            coeffs[i] = a * fp.sin() * (fp / a).sin() / (norm * x * x);
+            *coef = a * fp.sin() * (fp / a).sin() / (norm * x * x);
         }
     }
     fn create_cache(order: usize, den: usize) -> Vec<Vec<f32>> {