]> git.nihav.org Git - nihav.git/commitdiff
fix some clippy warnings
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 2 Oct 2025 17:08:52 +0000 (19:08 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 2 Oct 2025 17:08:52 +0000 (19:08 +0200)
Mostly it is using clamp() where appropriate and using "static"
instead of "const" for large tables.

84 files changed:
nihav-acorn/src/codecs/escape.rs
nihav-acorn/src/codecs/supermovingblocks.rs
nihav-acorn/src/codecs/yuvtab.rs
nihav-commonfmt/src/codecs/cinepakenc.rs
nihav-commonfmt/src/codecs/clearvideo.rs
nihav-commonfmt/src/codecs/gif.rs
nihav-commonfmt/src/codecs/jpeg.rs
nihav-commonfmt/src/codecs/sipro.rs
nihav-commonfmt/src/codecs/ts102366.rs
nihav-core/src/scale/colorcvt.rs
nihav-core/src/scale/palette/neuquant.rs
nihav-core/src/scale/scale/mod.rs
nihav-core/src/soundcvt/mod.rs
nihav-core/src/soundcvt/resample.rs
nihav-duck/src/codecs/truemotion2.rs
nihav-duck/src/codecs/truemotion2x.rs
nihav-duck/src/codecs/truemotionrt.rs
nihav-duck/src/codecs/truemotionrtenc.rs
nihav-duck/src/codecs/vp3.rs
nihav-duck/src/codecs/vp6.rs
nihav-duck/src/codecs/vp6enc/mb.rs
nihav-duck/src/codecs/vp78dsp.rs
nihav-duck/src/codecs/vp7dsp.rs
nihav-duck/src/codecs/vp7enc/blocks.rs
nihav-duck/src/codecs/vp7enc/mb_coding.rs
nihav-duck/src/codecs/vp7enc/models.rs
nihav-duck/src/codecs/vp7enc/rdo.rs
nihav-duck/src/codecs/vp8.rs
nihav-duck/src/codecs/vp8dsp.rs
nihav-duck/src/codecs/vpcommon.rs
nihav-flash/src/codecs/adpcmenc.rs
nihav-flash/src/codecs/asao.rs
nihav-flash/src/codecs/flv263.rs
nihav-game/src/codecs/ipma.rs
nihav-game/src/codecs/midivid3.rs
nihav-game/src/codecs/smush/vima.rs
nihav-indeo/src/codecs/imc.rs
nihav-indeo/src/codecs/intel263.rs
nihav-indeo/src/codecs/yv92.rs
nihav-itu/src/codecs/h264/cabac.rs
nihav-itu/src/codecs/h264/cabac_coder.rs
nihav-itu/src/codecs/h264/decoder_mt.rs
nihav-itu/src/codecs/h264/decoder_st.rs
nihav-itu/src/codecs/h264/dsp/mc/mod.rs
nihav-itu/src/codecs/h264/dsp/mod.rs
nihav-itu/src/codecs/h264/loopfilter.rs
nihav-itu/src/codecs/h264/mb_recon.rs
nihav-itu/src/codecs/h264/test/conformance.rs
nihav-itu/src/codecs/h264/test/raw_demux.rs
nihav-itu/src/codecs/h264/types.rs
nihav-llaudio/src/codecs/apepred.rs
nihav-llaudio/src/codecs/flacenc.rs
nihav-misc/src/codecs/motionpixels/data.rs
nihav-misc/src/codecs/mwv1.rs
nihav-misc/src/codecs/pgvv.rs
nihav-misc/src/codecs/tealvid.rs
nihav-mpeg/src/codecs/aac/mod.rs
nihav-mpeg/src/codecs/aac/sbr/synth.rs
nihav-mpeg/src/codecs/mpeg4asp/dsp.rs
nihav-mpeg/src/codecs/mpeg4asp/types.rs
nihav-mpeg/src/codecs/mpegaudio/mp3code.rs
nihav-ms/src/codecs/msadpcm.rs
nihav-qt/src/codecs/mace.rs
nihav-qt/src/codecs/svq1.rs
nihav-qt/src/codecs/svq3.rs
nihav-qt/src/codecs/svq3dsp.rs
nihav-rad/src/codecs/bink2.rs
nihav-rad/src/codecs/binkaudenc.rs
nihav-realmedia/src/codecs/cook.rs
nihav-realmedia/src/codecs/cookenc.rs
nihav-realmedia/src/codecs/ra144.rs
nihav-realmedia/src/codecs/ra288.rs
nihav-realmedia/src/codecs/ralf.rs
nihav-realmedia/src/codecs/rv10.rs
nihav-realmedia/src/codecs/rv20.rs
nihav-realmedia/src/codecs/rv40enc/dsp/blk.rs
nihav-realmedia/src/codecs/rv40enc/dsp/ipred.rs
nihav-realmedia/src/codecs/rv40enc/mb_coding.rs
nihav-realmedia/src/codecs/rv40enc/mod.rs
nihav-realmedia/src/codecs/rv60dsp.rs
nihav-vivo/src/codecs/g723_1.rs
nihav-vivo/src/codecs/siren.rs
nihav-vivo/src/codecs/vivo.rs
nihav-vivo/src/demuxers/vivo.rs

index efe8ca583fb0fa98a2abaed9da544d9e59d2442f..f37bca911b91e5c9d307a4a243d4c8bc62ec7156 100644 (file)
@@ -616,7 +616,7 @@ impl NADecoder for Escape130Decoder {
                 let step_idx = br.read(2)? as usize;
                 blk.y_avg = br.read(5)? as u8 * 2;
                 for (dst, &sign) in blk.y.iter_mut().zip(E130_Y_SIGNS[sign_idx].iter()) {
-                    *dst = (i16::from(blk.y_avg) + i16::from(sign) * Y_STEPS[step_idx]).max(0).min(0x3F) as u8;
+                    *dst = (i16::from(blk.y_avg) + i16::from(sign) * Y_STEPS[step_idx]).clamp(0, 0x3F) as u8;
                 }
             } else if br.read_bool()? {
                 blk.y_avg = if br.read_bool()? {
index 9df1ae69f283d9a0b336e7f093005e167f6fd8ab..e4fc8c3f63113403182032c0cec98714f3ac4387 100644 (file)
@@ -607,7 +607,7 @@ const MV_TAB_SELF_2X2: [(i8, i8); 8] = [
 ];
 
 // generated the same way as 15-bit YUV2RGB table but with an additional bit of luma
-const YUV655TAB: [u16; 65536] = [
+static YUV655TAB: [u16; 65536] = [
     0x0000, 0x0000, 0x0421, 0x0421, 0x0842, 0x0842, 0x0C63, 0x0C63,
     0x1084, 0x1084, 0x14A5, 0x14A5, 0x18C6, 0x18C6, 0x1CE7, 0x1CE7,
     0x2108, 0x2108, 0x2529, 0x2529, 0x294A, 0x294A, 0x2D6B, 0x2D6B,
index f2d6558709eefd6e1cf629549c7242ad0d0c7bed..def12184165d902b9a7ff914f4d4b0354100f382 100644 (file)
@@ -15,7 +15,7 @@
         *el = r | (g << 5) | (b << 10);
     }
 */
-pub const YUV2RGB: [u16; 32768] = [
+pub static YUV2RGB: [u16; 32768] = [
     0x0000, 0x0421, 0x0842, 0x0C63, 0x1084, 0x14A5, 0x18C6, 0x1CE7,
     0x2108, 0x2529, 0x294A, 0x2D6B, 0x318C, 0x35AD, 0x39CE, 0x3DEF,
     0x4210, 0x4631, 0x4A52, 0x4E73, 0x5294, 0x56B5, 0x5AD6, 0x5EF7,
index baff7b73a782a58d43244afdfbee597234285ba7..8d78fb311c2e70e6521ff689c423e857a1b48930 100644 (file)
@@ -44,7 +44,7 @@ impl VQElement for YUVCode {
         let mut counts = [0; 256];
         for entry in arr.iter() {
             let idx = match component {
-                    0 | 1 | 2 | 3 => entry.y[component],
+                    0..=3 => entry.y[component],
                     4 => entry.u,
                     _ => entry.v,
                 } as usize;
@@ -57,7 +57,7 @@ impl VQElement for YUVCode {
         let mut dst = vec![YUVCode::default(); arr.len()];
         for entry in arr.iter() {
             let idx = match component {
-                    0 | 1 | 2 | 3 => entry.y[component],
+                    0..=3 => entry.y[component],
                     4 => entry.u,
                     _ => entry.v,
                 } as usize;
@@ -1211,7 +1211,7 @@ impl NAEncoder for CinepakEncoder {
         if let Some(ref vbuf) = buf.get_vbuf() {
             if self.nstrips == 0 {
                 let (w, h) = vbuf.get_dimensions(0);
-                self.nstrips = ((((w * h) >> 4) + 1200) / 2400).max(1).min(3);
+                self.nstrips = ((((w * h) >> 4) + 1200) / 2400).clamp(1, 3);
                 let strip_h = ((h + self.nstrips - 1) / self.nstrips + 3) & !3;
                 self.nstrips = (h + strip_h - 1) / strip_h;
             }
index 0abdeace22a783b1a6a396f855f4a7d31d5a4cec..e6aa568b08e563d5fa5af66efabf2a756090bed0 100644 (file)
@@ -214,41 +214,29 @@ fn put_blocks(buf: &mut NAVideoBuffer<u8>, xpos: usize, ypos: usize, blk: &[[i32
 
     for j in 0..8 {
         for k in 0..8 {
-            let mut v = blk[0][k + j * 8] + 128;
-            if v < 0 { v = 0; } else if v > 255 { v = 255; }
-            framebuf[idxy + k] = v as u8;
+            framebuf[idxy + k] = (blk[0][k + j * 8] + 128).clamp(0, 255) as u8;
         }
         for k in 0..8 {
-            let mut v = blk[1][k + j * 8] + 128;
-            if v < 0 { v = 0; } else if v > 255 { v = 255; }
-            framebuf[idxy + k + 8] = v as u8;
+            framebuf[idxy + k + 8] = (blk[1][k + j * 8] + 128).clamp(0, 255) as u8;
         }
         idxy += stridey;
     }
     for j in 0..8 {
         for k in 0..8 {
-            let mut v = blk[2][k + j * 8] + 128;
-            if v < 0 { v = 0; } else if v > 255 { v = 255; }
-            framebuf[idxy + k] = v as u8;
+            framebuf[idxy + k] = (blk[2][k + j * 8] + 128).clamp(0, 255) as u8;
         }
         for k in 0..8 {
-            let mut v = blk[3][k + j * 8] + 128;
-            if v < 0 { v = 0; } else if v > 255 { v = 255; }
-            framebuf[idxy + k + 8] = v as u8;
+            framebuf[idxy + k + 8] = (blk[3][k + j * 8] + 128).clamp(0, 255) as u8;
         }
         idxy += stridey;
     }
 
     for j in 0..8 {
         for k in 0..8 {
-            let mut v = blk[4][k + j * 8] + 128;
-            if v < 0 { v = 0; } else if v > 255 { v = 255; }
-            framebuf[idxu + k] = v as u8;
+            framebuf[idxu + k] = (blk[4][k + j * 8] + 128).clamp(0, 255) as u8;
         }
         for k in 0..8 {
-            let mut v = blk[5][k + j * 8] + 128;
-            if v < 0 { v = 0; } else if v > 255 { v = 255; }
-            framebuf[idxv + k] = v as u8;
+            framebuf[idxv + k] = (blk[5][k + j * 8] + 128).clamp(0, 255) as u8;
         }
         idxu += strideu;
         idxv += stridev;
@@ -382,7 +370,7 @@ fn copyadd_block_w(dst: &mut WFrame, src: &NAVideoBuffer<u8>,
     for _y in 0..blk_h {
         for x in 0..blk_w {
             let scale = u32::from(*cur_w.next().unwrap());
-            let val = (i16::from(sbuf[soff + x]) + bias).max(0).min(255) as u32;
+            let val = (i16::from(sbuf[soff + x]) + bias).clamp(0, 255) as u32;
             dbuf[doff + x] += scale | ((val * scale) << 8);
         }
         soff += sstride;
index e29c275108264b81f647be94a7eedd3eb110b40b..2810db3745370ed2e989c8b119d17f7dfb8a8e63 100644 (file)
@@ -210,7 +210,7 @@ impl NADecoder for GIFDecoder {
     }
     fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
         let src = pkt.get_buffer();
-        validate!(src.len() > 0);
+        validate!(!src.is_empty());
 
         for sd in pkt.side_data.iter() {
             if let NASideData::Palette(true, ref pal) = sd {
index b63068c3c1fb5e4d4b39e43871259d73050426aa..b90c99990f35d8ce83968d13f71ee316c8cd60b1 100644 (file)
@@ -117,7 +117,7 @@ fn idct(blk: &mut [i16; 64]) {
 fn put_block(blk: &[i16; 64], dst: &mut [u8], stride: usize) {
     for (drow, srow) in dst.chunks_mut(stride).zip(blk.chunks(8)) {
         for (del, &pix) in drow.iter_mut().zip(srow.iter()) {
-            *del = pix.max(0).min(255) as u8;
+            *del = pix.clamp(0, 255) as u8;
         }
     }
 }
index 9626e04005d50fb6ed62df99e8b20e0195b11530..276cf75f490ae4bababf504927705bb60af6635d 100644 (file)
@@ -241,7 +241,7 @@ impl SiproDecoder {
                 }
             } else {
                 if idx < 62 {
-                    (self.prev_pitch - 10).max(30).min(281 - 19) * 3 + idx - 2
+                    (self.prev_pitch - 10).clamp(30, 281 - 19) * 3 + idx - 2
                 } else {
                     self.prev_pitch * 3
                 }
@@ -270,7 +270,7 @@ impl SiproDecoder {
                     idx * 3 - 335
                 }
             } else {
-                idx + (self.prev_pitch - 5).max(20).min(134) * 3 - 1
+                idx + (self.prev_pitch - 5).clamp(20, 134) * 3 - 1
             };
         self.pitch_int = (pitch_idx * 10923) >> 15;
         let pitch_frac = (pitch_idx as i32) - (self.pitch_int as i32) * 3 - 1;
index 85f8b0ea281880726be6b68cc2eaa0200512d6b5..7fd70fe736e1ee7cda48586f380d7d4d9d641a55 100644 (file)
@@ -668,7 +668,7 @@ impl ChannelData {
             mask[band] = (mask[band] - self.snroffset - i32::from(floor)).max(0) & 0x1FE0;
             mask[band] += i32::from(floor);
             while bin < lastbin {
-                let addr = ((i32::from(self.psd[bin]) - mask[band]) >> 5).min(63).max(0) as usize;
+                let addr = ((i32::from(self.psd[bin]) - mask[band]) >> 5).clamp(0, 63) as usize;
                 self.bap[bin] = TS102366_BAPTAB[addr];
                 bin += 1;
             }
index 4b076d65342e121071f36d956784cef9a14fd3a2..f1422c738ca99d49ef4464989eb565bb6692dcf3 100644 (file)
@@ -264,9 +264,9 @@ impl Kernel for RgbToYuv {
                     let b = f32::from(src[boff + x]);
                     let (y, u, v) = matrix_mul(&self.matrix, r, g, b);
 
-                    dst[yoff + x] = (y as i16).max(0).min(255) as u8;
-                    dst[uoff + x] = ((u as i16).max(-128).min(127) + 128) as u8;
-                    dst[voff + x] = ((v as i16).max(-128).min(127) + 128) as u8;
+                    dst[yoff + x] = (y as i16).clamp(0, 255) as u8;
+                    dst[uoff + x] = ((u as i16).clamp(-128, 127) + 128) as u8;
+                    dst[voff + x] = ((v as i16).clamp(-128, 127) + 128) as u8;
                 }
                 roff += istrides[0];
                 goff += istrides[1];
@@ -298,7 +298,7 @@ impl RgbToYuv {
                 let b = f32::from(src[boff + x]);
                 let (y, _u, _v) = matrix_mul(&self.matrix, r, g, b);
 
-                dst[yoff + x] = (y as i16).max(0).min(255) as u8;
+                dst[yoff + x] = (y as i16).clamp(0, 255) as u8;
             }
             roff += istrides[0];
             goff += istrides[1];
@@ -439,9 +439,9 @@ impl Kernel for YuvToRgb {
                         let r = y + self.r_chr[v];
                         let g = y + self.g_u[u] + self.g_v[v];
                         let b = y + self.b_chr[u];
-                        dst[roff + x] = r.max(0).min(255) as u8;
-                        dst[goff + x] = g.max(0).min(255) as u8;
-                        dst[boff + x] = b.max(0).min(255) as u8;
+                        dst[roff + x] = r.clamp(0, 255) as u8;
+                        dst[goff + x] = g.clamp(0, 255) as u8;
+                        dst[boff + x] = b.clamp(0, 255) as u8;
                     }
                     roff += dstrides[0];
                     goff += dstrides[1];
@@ -463,9 +463,9 @@ impl Kernel for YuvToRgb {
                     let v = f32::from(i16::from(src[voff + (x >> sv1)]) - 128);
 
                     let (r, g, b) = matrix_mul(&self.matrix, y, u, v);
-                    dst[roff + x] = (r as i16).max(0).min(255) as u8;
-                    dst[goff + x] = (g as i16).max(0).min(255) as u8;
-                    dst[boff + x] = (b as i16).max(0).min(255) as u8;
+                    dst[roff + x] = (r as i16).clamp(0, 255) as u8;
+                    dst[goff + x] = (g as i16).clamp(0, 255) as u8;
+                    dst[boff + x] = (b as i16).clamp(0, 255) as u8;
                 }
                 roff += dstrides[0];
                 goff += dstrides[1];
@@ -500,9 +500,9 @@ impl YuvToRgb {
                     let r = y + self.r_chr[128];
                     let g = y + self.g_u[128] + self.g_v[128];
                     let b = y + self.b_chr[128];
-                    dst[roff + x] = r.max(0).min(255) as u8;
-                    dst[goff + x] = g.max(0).min(255) as u8;
-                    dst[boff + x] = b.max(0).min(255) as u8;
+                    dst[roff + x] = r.clamp(0, 255) as u8;
+                    dst[goff + x] = g.clamp(0, 255) as u8;
+                    dst[boff + x] = b.clamp(0, 255) as u8;
                 }
                 roff += dstrides[0];
                 goff += dstrides[1];
@@ -514,9 +514,9 @@ impl YuvToRgb {
                 for x in 0..w {
                     let y = f32::from(src[yoff + x]);
                     let (r, g, b) = matrix_mul(&self.matrix, y, 0.0, 0.0);
-                    dst[roff + x] = (r as i16).max(0).min(255) as u8;
-                    dst[goff + x] = (g as i16).max(0).min(255) as u8;
-                    dst[boff + x] = (b as i16).max(0).min(255) as u8;
+                    dst[roff + x] = (r as i16).clamp(0, 255) as u8;
+                    dst[goff + x] = (g as i16).clamp(0, 255) as u8;
+                    dst[boff + x] = (b as i16).clamp(0, 255) as u8;
                 }
                 roff += dstrides[0];
                 goff += dstrides[1];
index 787f340cbdcb5a73bb1d958f5fed4aec7a3bbf99..c28b17907ab363f3e639f3f3d8200247d1d012cb 100644 (file)
@@ -127,9 +127,9 @@ impl NeuQuantQuantiser {
     }
     pub fn make_pal(&self, pal: &mut [[u8; 3]; 256]) {
         for (pal, node) in pal.iter_mut().zip(self.weights.iter()) {
-            pal[0] = (node[0] + 0.5).max(0.0).min(255.0) as u8;
-            pal[1] = (node[1] + 0.5).max(0.0).min(255.0) as u8;
-            pal[2] = (node[2] + 0.5).max(0.0).min(255.0) as u8;
+            pal[0] = (node[0] + 0.5).clamp(0.0, 255.0) as u8;
+            pal[1] = (node[1] + 0.5).clamp(0.0, 255.0) as u8;
+            pal[2] = (node[2] + 0.5).clamp(0.0, 255.0) as u8;
         }
     }
 }
index 67c0be31a4a8659d6e9c740fae7852f7a0676f56..29a91b026fdde2fa44c9a6dba6cc8338170d4bca 100644 (file)
@@ -92,10 +92,10 @@ impl CustomFrom<u16> for usize {
     fn cvt_from(val: u16) -> Self { usize::from(val) }
 }
 impl CustomFrom<f32> for u8 {
-    fn cvt_from(val: f32) -> Self { val.max(0.0).min(255.0) as u8 }
+    fn cvt_from(val: f32) -> Self { val.clamp(0.0, 255.0) as u8 }
 }
 impl CustomFrom<f32> for u16 {
-    fn cvt_from(val: f32) -> Self { val.max(0.0).min(65535.0) as u16 }
+    fn cvt_from(val: f32) -> Self { val.clamp(0.0, 65535.0) as u16 }
 }
 impl CustomFrom<u8> for f32 {
     fn cvt_from(val: u8) -> Self { val as f32 }
index b8fda80c8d5eb8fea7bc3d0fa4fd858b47621152..242e96a303b19edf4bc3508b205ead7f49ed6cd8 100644 (file)
@@ -107,7 +107,7 @@ impl FromFmt<u8> for f32 {
 }
 
 impl FromFmt<i16> for u8 {
-    fn cvt_from(val: i16) -> u8 { ((val >> 8) + 128).min(255).max(0) as u8 }
+    fn cvt_from(val: i16) -> u8 { ((val >> 8) + 128).clamp(0, 255) as u8 }
 }
 impl FromFmt<i16> for i16 {
     fn cvt_from(val: i16) -> i16 { val }
@@ -120,7 +120,7 @@ impl FromFmt<i16> for f32 {
 }
 
 impl FromFmt<i32> for u8 {
-    fn cvt_from(val: i32) -> u8 { ((val >> 24) + 128).min(255).max(0) as u8 }
+    fn cvt_from(val: i32) -> u8 { ((val >> 24) + 128).clamp(0, 255) as u8 }
 }
 impl FromFmt<i32> for i16 {
     fn cvt_from(val: i32) -> i16 { (val >> 16) as i16 }
@@ -133,10 +133,10 @@ impl FromFmt<i32> for f32 {
 }
 
 impl FromFmt<f32> for u8 {
-    fn cvt_from(val: f32) -> u8 { ((val * 128.0) + 128.0).min(255.0).max(0.0) as u8 }
+    fn cvt_from(val: f32) -> u8 { ((val * 128.0) + 128.0).clamp(0.0, 255.0) as u8 }
 }
 impl FromFmt<f32> for i16 {
-    fn cvt_from(val: f32) -> i16 { (val * 32768.0).min(32767.0).max(-32768.0) as i16 }
+    fn cvt_from(val: f32) -> i16 { (val * 32768.0).clamp(-32768.0, 32767.0) as i16 }
 }
 impl FromFmt<f32> for i32 {
     fn cvt_from(val: f32) -> i32 {
index dc2f1789e5f16ee4fcdae6ce795883672ae5971a..df7baf5cda24d94dc88f1b53b3ce7f6e1c123e7b 100644 (file)
@@ -79,7 +79,7 @@ fn gen_sinc_coeffs(order: usize, num: usize, den: usize, norm: f32) -> Vec<f32>
             *coef = norm;
             continue;
         }
-        let wval = f64::from((pos * win_scale).max(-1.0).min(1.0));
+        let wval = f64::from((pos * win_scale).clamp(-1.0, 1.0));
         let win = bessel_i0(BESSEL_BETA - (1.0 - wval * wval).sqrt()) as f32;
         *coef = norm * (pos * sinc_scale).sinc() * win;
     }
index 1bdb0dd644b0ef4a4e3ada0af9ed89642328cf57..2c4c1738ed67648d239b25c779b4ab6ab6fb2713 100644 (file)
@@ -233,7 +233,7 @@ impl DeltaState {
             for x in 0..4 {
                 d += ydeltas[x + y * 4];
                 last[x] += d;
-                dst[yoff + x] = last[x].max(0).min(255) as u8;
+                dst[yoff + x] = last[x].clamp(0, 255) as u8;
             }
             self.dy[y] = d;
             yoff += ystride;
@@ -516,9 +516,9 @@ impl TM2Decoder {
                 let y = i16::from(self.cur_frame.ydata[ysrc + x]);
                 let u = self.cur_frame.udata[csrc + (x >> 1)];
                 let v = self.cur_frame.vdata[csrc + (x >> 1)];
-                pic[offs[0]] = (y + u).max(0).min(255) as u8;
-                pic[offs[1]] = y.max(0).min(255) as u8;
-                pic[offs[2]] = (y + v).max(0).min(255) as u8;
+                pic[offs[0]] = (y + u).clamp(0, 255) as u8;
+                pic[offs[1]] = y.clamp(0, 255) as u8;
+                pic[offs[2]] = (y + v).clamp(0, 255) as u8;
             }
             off += stride;
             ysrc += self.cur_frame.ystride;
index be776efb47447b09d308e1b468e2fe47eb0057bd..a8d84e23fc78564a3215930b3410f1b40d31b63f 100644 (file)
@@ -189,9 +189,9 @@ impl TM2XDecoder {
                 let y = self.cur_frame.ydata[pos + x];
                 let u = self.cur_frame.udata[pos + x];
                 let v = self.cur_frame.vdata[pos + x];
-                dst[offs[0] + x] = y.max(0).min(255) as u8;
-                dst[offs[1] + x] = u.max(0).min(255) as u8;
-                dst[offs[2] + x] = v.max(0).min(255) as u8;
+                dst[offs[0] + x] = y.clamp(0, 255) as u8;
+                dst[offs[1] + x] = u.clamp(0, 255) as u8;
+                dst[offs[2] + x] = v.clamp(0, 255) as u8;
             }
             for c in 0..3 {
                 offs[c] += strides[c];
index 182cf05b36781141171c4b6198b5e1c1c51d5883..26a34647d540342402e52305b51cb6b49f872ff6 100644 (file)
@@ -24,7 +24,7 @@ impl TMRTDecoder {
                 let delta                       = delta_tab[br.read(dbits)? as usize];
                 diff += delta;
                 let pred = if y > 0 { dst[off + x - stride].into() } else if !is_chroma { 0 } else { 0x80 };
-                dst[off + x] = (pred + diff).min(255).max(0) as u8;
+                dst[off + x] = (pred + diff).clamp(0, 255) as u8;
                 if hscale {
                     dst[off + x + 1] = dst[off + x];
                 }
index da02ba844983cb18863449540c69d531f86a0df8..03e057e8ccd94c4c92d32eea6a3eb793d63ea284 100644 (file)
@@ -79,7 +79,7 @@ impl TMRTEncoder {
 
                 bw.write(idx as u32, self.dbits);
                 hor_pred += ndelta;
-                *pred = (i16::from(*pred) + hor_pred).max(0).min(255) as u8;
+                *pred = (i16::from(*pred) + hor_pred).clamp(0, 255) as u8;
             }
         }
 
@@ -119,7 +119,7 @@ impl TMRTEncoder {
                         if src.err == ERR_MAX {
                             continue;
                         }
-                        let nval = i32::from((top_val + src.hpred + delta).max(0).min(255));
+                        let nval = i32::from((top_val + src.hpred + delta).clamp(0, 255));
                         let new_err = src.err + (((nval - pix_val) * (nval - pix_val)) as u32);
                         if new_err < dst.err {
                             dst.err = new_err;
@@ -154,7 +154,7 @@ impl TMRTEncoder {
             for (pred, &idx) in self.top_line.iter_mut().step_by(step).zip(self.indices.iter()) {
                 bw.write(u32::from(idx), self.dbits);
                 hor_pred += delta_tab[usize::from(idx)];
-                *pred = (i16::from(*pred) + hor_pred).max(0).min(255) as u8;
+                *pred = (i16::from(*pred) + hor_pred).clamp(0, 255) as u8;
             }
         }
 
index ba5db75d109f804c96be67acc399da831d27be27..7eea0737bae37c5d7b241588d013e1818019dc74 100644 (file)
@@ -450,8 +450,8 @@ fn rescale_qmat_vp4(dst_qmat: &mut [i16; 64], base_qmat: &[i16; 64], dc_quant: i
 fn expand_token(blk: &mut Block, br: &mut BitReader, eob_run: &mut usize, token: u8) -> DecoderResult<()> {
     match token {
         // EOBs
-        0 | 1 | 2 => { *eob_run = (token as usize) + 1; },
-        3 | 4 | 5 => {
+        0..=2 => { *eob_run = (token as usize) + 1; },
+        3..=5 => {
             let bits = token - 1;
             *eob_run                            = (br.read(bits)? as usize) + (1 << bits);
         },
@@ -464,7 +464,7 @@ fn expand_token(blk: &mut Block, br: &mut BitReader, eob_run: &mut usize, token:
             validate!(blk.idx <= 64);
         },
         // single coefficients
-        9 | 10 | 11 | 12 => {
+        9..=12 => {
             let val = (i16::from(token) - 7) >> 1;
             if (token & 1) == 1 {
                 blk.coeffs[ZIGZAG[blk.idx]] = val;
@@ -473,7 +473,7 @@ fn expand_token(blk: &mut Block, br: &mut BitReader, eob_run: &mut usize, token:
             }
             blk.idx += 1;
         },
-        13 | 14 | 15 | 16 => {
+        13..= 16 => {
             let val = i16::from(token) - 10;
             if !br.read_bool()? {
                 blk.coeffs[ZIGZAG[blk.idx]] = val;
@@ -482,7 +482,7 @@ fn expand_token(blk: &mut Block, br: &mut BitReader, eob_run: &mut usize, token:
             }
             blk.idx += 1;
         },
-        17 | 18 | 19 | 20 | 21 | 22 => {
+        17..=22 => {
             let add_bits = if token == 22 { 9 } else { token - 16 };
             let sign                            = br.read_bool()?;
             let val                             = (br.read(add_bits)? as i16) + VP3_LITERAL_BASE[(token - 17) as usize];
@@ -494,7 +494,7 @@ fn expand_token(blk: &mut Block, br: &mut BitReader, eob_run: &mut usize, token:
             blk.idx += 1;
         }
         // zero run plus coefficient
-        23 | 24 | 25 | 26 | 27 => {
+        23..=27 => {
             blk.idx += (token - 22) as usize;
             validate!(blk.idx < 64);
             if !br.read_bool()? {
@@ -1841,7 +1841,7 @@ impl NADecoder for VP34Decoder {
     #[allow(clippy::collapsible_else_if)]
     fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
         let src = pkt.get_buffer();
-        validate!(src.len() > 0);
+        validate!(!src.is_empty());
         let mut br = BitReader::new(&src, BitReaderMode::BE);
 
         self.parse_header(&mut br)?;
index 131e26e78097824dad298b24c927b6ecab89e1f7..8d2ef47c21ffb130e2c27e1a472cabdfb76602ca 100644 (file)
@@ -423,14 +423,14 @@ fn decode_token_huff(br: &mut BitReader, huff: &VP6Huff) -> DecoderResult<(i16,
     let tok                                     = br.read_huff(huff)?;
     match tok {
         0   => Ok((0, false)),
-        1 | 2 | 3 | 4 => {
+        1..=4 => {
             if !br.read_bool()? {
                 Ok((i16::from(tok), false))
             } else {
                 Ok((-i16::from(tok), false))
             }
         },
-        5 | 6 | 7 | 8 | 9 | 10 => {
+        5..=10 => {
             let base = (tok - 5) as usize;
             let add_bits                        = br.read(VP6_COEF_ADD_BITS[base])? as i16;
             let val = VP56_COEF_BASE[base] + add_bits;
index cece9d10067cdd0c2a384cefbd582cca12258d01..4dd7d489fa8e91870f312f1175f611ecb53c1fa4 100644 (file)
@@ -255,7 +255,7 @@ impl FrameEncoder {
                 if mb_type.is_intra() {
                     for (dblk, sblk) in blocks.iter_mut().zip(mb.coeffs.iter()) {
                         for (dcoef, &scoef) in dblk.iter_mut().zip(sblk.iter()) {
-                            *dcoef = (scoef + 128).max(0).min(255) as u8;
+                            *dcoef = (scoef + 128).clamp(0, 255) as u8;
                         }
                     }
                 } else {
@@ -271,7 +271,7 @@ impl FrameEncoder {
 
                     for (dblk, (sblk1, sblk2)) in blocks.iter_mut().zip(mb.coeffs.iter().zip(res_mb.iter())) {
                         for (dcoef, (&scoef1, &scoef2)) in dblk.iter_mut().zip(sblk1.iter().zip(sblk2.iter())) {
-                            *dcoef = (scoef1 + scoef2).max(0).min(255) as u8;
+                            *dcoef = (scoef1 + scoef2).clamp(0, 255) as u8;
                         }
                     }
                 }
@@ -440,7 +440,7 @@ impl FrameEncoder {
             tmp_mb.idct();
             for blk in tmp_mb.coeffs.iter_mut() {
                 for coef in blk.iter_mut() {
-                    *coef = (*coef + 128).max(0).min(255);
+                    *coef = (*coef + 128).clamp(0, 255);
                 }
             }
             let intra_dist = calc_mb_dist(&self.src_mbs[mb_idx], &tmp_mb);
@@ -451,7 +451,7 @@ impl FrameEncoder {
             tmp_mb.idct();
             for (blk, res) in tmp_mb.coeffs.iter_mut().zip(self.inter_mbs[mb_idx].reference.iter()) {
                 for (coef, add) in blk.iter_mut().zip(res.iter()) {
-                    *coef = (*coef + add).max(0).min(255);
+                    *coef = (*coef + add).clamp(0, 255);
                 }
             }
             let inter_dist = calc_mb_dist(&self.src_mbs[mb_idx], &tmp_mb);
@@ -473,7 +473,7 @@ impl FrameEncoder {
                     tmp_mb.idct();
                     for (blk, res) in tmp_mb.coeffs.iter_mut().zip(self.fourmv_mbs[mb_idx].reference.iter()) {
                         for (coef, add) in blk.iter_mut().zip(res.iter()) {
-                            *coef = (*coef + add).max(0).min(255);
+                            *coef = (*coef + add).clamp(0, 255);
                         }
                     }
                     let fourmv_dist = calc_mb_dist(&self.src_mbs[mb_idx], &tmp_mb);
@@ -491,7 +491,7 @@ impl FrameEncoder {
                 tmp_mb.idct();
                 for (blk, res) in tmp_mb.coeffs.iter_mut().zip(self.golden_mbs[mb_idx].reference.iter()) {
                     for (coef, add) in blk.iter_mut().zip(res.iter()) {
-                        *coef = (*coef + add).max(0).min(255);
+                        *coef = (*coef + add).clamp(0, 255);
                     }
                 }
                 let golden_dist = calc_mb_dist(&self.src_mbs[mb_idx], &tmp_mb);
@@ -567,7 +567,7 @@ impl FrameEncoder {
                 tmp_mb.idct();
                 for (blk, res) in tmp_mb.coeffs.iter_mut().zip(inter_mb.reference.iter()) {
                     for (coef, add) in blk.iter_mut().zip(res.iter()) {
-                        *coef = (*coef + add).max(0).min(255);
+                        *coef = (*coef + add).clamp(0, 255);
                     }
                 }
                 let mut best_dist = calc_mb_dist(smb, &tmp_mb);
@@ -586,7 +586,7 @@ impl FrameEncoder {
                     tmp_mb.idct();
                     for (blk, res) in tmp_mb.coeffs.iter_mut().zip(self.fourmv_mbs[mb_idx].reference.iter()) {
                         for (coef, add) in blk.iter_mut().zip(res.iter()) {
-                            *coef = (*coef + add).max(0).min(255);
+                            *coef = (*coef + add).clamp(0, 255);
                         }
                     }
                     let fourmv_dist = calc_mb_dist(smb, &tmp_mb);
@@ -610,7 +610,7 @@ impl FrameEncoder {
                         tmp_mb.idct();
                         for (blk, res) in tmp_mb.coeffs.iter_mut().zip(gold_mb.reference.iter()) {
                             for (coef, add) in blk.iter_mut().zip(res.iter()) {
-                                *coef = (*coef + add).max(0).min(255);
+                                *coef = (*coef + add).clamp(0, 255);
                             }
                         }
                         let golden_dist = calc_mb_dist(smb, &tmp_mb);
@@ -636,7 +636,7 @@ impl FrameEncoder {
                     tmp_mb.idct();
                     for blk in tmp_mb.coeffs.iter_mut() {
                         for coef in blk.iter_mut() {
-                            *coef = (*coef + 128).max(0).min(255);
+                            *coef = (*coef + 128).clamp(0, 255);
                         }
                     }
                     let intra_dist = calc_mb_dist(smb, &tmp_mb);
index 9487c1693932ecda2dddebe7ebd78569027f3e50..df18adf579b453494e640011b4aa8a379fe9090a 100644 (file)
@@ -3,7 +3,7 @@ use nihav_core::frame::*;
 use nihav_codec_support::codecs::blockdsp::edge_emu;
 
 fn clip_u8(val: i16) -> u8 {
-    val.max(0).min(255) as u8
+    val.clamp(0, 255) as u8
 }
 
 pub struct IPredContext {
index 090eadad799c3c48d1ac7b9055c661949a5a867f..76fe663f657ec3e71976e40051d2f292b835cd71 100644 (file)
@@ -1,7 +1,7 @@
 use nihav_core::frame::*;
 
 fn clip_u8(val: i16) -> u8 {
-    val.max(0).min(255) as u8
+    val.clamp(0, 255) as u8
 }
 
 const DCT_COEFFS: [i32; 16] = [
@@ -145,7 +145,7 @@ pub fn fade_frame(srcfrm: NAVideoBufferRef<u8>, dstfrm: &mut NASimpleVideoFrame<
     let mut fade_lut = [0u8; 256];
     for (i, el) in fade_lut.iter_mut().enumerate() {
         let y = i as u16;
-        *el = (y + ((y * beta) >> 8) + alpha).max(0).min(255) as u8;
+        *el = (y + ((y * beta) >> 8) + alpha).clamp(0, 255) as u8;
     }
 
     let (w, h)  = srcfrm.get_dimensions(0);
index 4f4b4510698321681e7ab507145897d12cf64f53..1cf4939f20ecd794772df4bd4be1e6d3cbcfb31b 100644 (file)
@@ -46,7 +46,7 @@ pub fn get_block_difference(dst: &mut [i16; 16], src1: &[u8; 16], src2: &[u8; 16
 pub fn get_difference_dist(old: &[u8; 16], new: &[u8; 16], diff: &[i16; 16]) -> u32 {
     let mut dist = 0;
     for ((&old, &new), &diff) in old.iter().zip(new.iter()).zip(diff.iter()) {
-        let nval = (i16::from(new) + diff).max(0).min(255);
+        let nval = (i16::from(new) + diff).clamp(0, 255);
         let oval = i16::from(old);
         dist += (i32::from(nval - oval) * i32::from(nval - oval)) as u32;
     }
@@ -324,7 +324,7 @@ impl Residue {
             for (x, blk) in src.iter().enumerate() {
                 for (drow, srow) in dst[x * 4..].chunks_mut(16).zip(blk.chunks(4)) {
                     for (del, &sel) in drow.iter_mut().zip(srow.iter()) {
-                        *del = (i16::from(*del) + sel).max(0).min(255) as u8;
+                        *del = (i16::from(*del) + sel).clamp(0, 255) as u8;
                     }
                 }
             }
@@ -334,7 +334,7 @@ impl Residue {
                 for (x, blk) in src.iter().enumerate() {
                     for (drow, srow) in dst[x * 4..].chunks_mut(8).zip(blk.chunks(4)) {
                         for (del, &sel) in drow.iter_mut().zip(srow.iter()) {
-                            *del = (i16::from(*del) + sel).max(0).min(255) as u8;
+                            *del = (i16::from(*del) + sel).clamp(0, 255) as u8;
                         }
                     }
                 }
@@ -355,7 +355,7 @@ impl Residue {
                     blk.idct();
                     for (drow, srow) in dst[x * 4..].chunks_mut(8).zip(blk.chunks(4)) {
                         for (del, &sel) in drow.iter_mut().zip(srow.iter()) {
-                            *del = (i16::from(*del) + sel).max(0).min(255) as u8;
+                            *del = (i16::from(*del) + sel).clamp(0, 255) as u8;
                         }
                     }
                 }
index 8fc79ffde0c69629f6e8fa8c6093b044c7353851..05b305887f919cfb4c291a42c51e96ebdef4d574 100644 (file)
@@ -112,7 +112,7 @@ pub fn try_i4x4_pred(mut src: LumaIterator, modes: &mut [PredMode; 16], res: &mu
             let nblk = &mut new[x * 4 + y * 4 * 16..];
             for (dst, (src, res)) in nblk.chunks_mut(16).zip(yblk.chunks(4).zip(diff.chunks(4))) {
                 for (del, (&sel, &rel)) in dst.iter_mut().zip(src.iter().zip(res.iter())) {
-                    *del = (i16::from(sel) + rel).max(0).min(255) as u8;
+                    *del = (i16::from(sel) + rel).clamp(0, 255) as u8;
                 }
             }
 
index 8b83301d418049a265ef111b61dcab5d6042d50a..986d2248ba27d66b3a15c999804b0294a7c90cde 100644 (file)
@@ -36,7 +36,7 @@ pub trait VP7ProbCounter {
 impl VP7ProbCounter for ProbCounter {
     fn to_prob8(self) -> u8 {
         if self.total > 0 {
-            ((self.zeroes << 8) / self.total).min(255).max(1) as u8
+            ((self.zeroes << 8) / self.total).clamp(1, 255) as u8
         } else {
             128
         }
index 4dc7cea80ead1f73f4c1002ea888fd8609d068a3..9189b1538445c06cfefe564ad305eb74afd2e967 100644 (file)
@@ -184,7 +184,7 @@ impl BitRateControl {
                     }
                     q
                 } else {
-                    ((((800.0 - nits_per_mb) / 155.0).exp() + 6.0) as usize).max(10).min(127)
+                    ((((800.0 - nits_per_mb) / 155.0).exp() + 6.0) as usize).clamp(10, 127)
                 }
             }
         }
index 83539b6aa6ea1bf16e1c2f095a2b2da8be768354..465474f63c9772dc03ac711472c0e7e5794e0886 100644 (file)
@@ -416,7 +416,7 @@ impl VP8Decoder {
         let loop_str = if self.dstate.seg_feature_mode {
                 segment.lf as u8
             } else {
-                (i16::from(self.dstate.loop_filter_level) + i16::from(segment.lf)).max(0).min(63) as u8
+                (i16::from(self.dstate.loop_filter_level) + i16::from(segment.lf)).clamp(0, 63) as u8
             };
         self.dstate.force_loop_str = Some(loop_str);
     }
@@ -536,7 +536,7 @@ impl VP8Decoder {
                 let q = if self.dstate.seg_feature_mode {
                         seg.quant.max(0) as usize
                     } else {
-                        ((y_ac_q as i16) + i16::from(seg.quant)).max(0).min(127) as usize
+                        ((y_ac_q as i16) + i16::from(seg.quant)).clamp(0, 127) as usize
                     };
                 Self::set_single_qmat(qmat, q, q, q, q, q, q);
             }
@@ -1452,7 +1452,7 @@ impl NADecoder for VP8Decoder {
                         if self.mb_info[mb_idx].mb_type != VPMBType::Intra || self.mb_info[mb_idx].ymode == PredMode::BPred {
                             loop_str += self.dstate.lf_mode_delta[idx];
                         }
-                        self.mb_info[mb_idx].loop_str = loop_str.max(0).min(63) as u8;
+                        self.mb_info[mb_idx].loop_str = loop_str.clamp(0, 63) as u8;
                     }
                     self.mb_info[mb_idx].inner_filt = has_coeffs || (self.mb_info[mb_idx].ymode == PredMode::BPred) || (self.mb_info[mb_idx].mb_type == VPMBType::InterFourMV);
                 }
index fa7aa0928b21c42c60715344854b0cf39e1a60df..17a78c156dc644800acff54f2bb7eb83746f2390 100644 (file)
@@ -2,11 +2,11 @@ use nihav_core::frame::NAVideoBufferRef;
 use nihav_codec_support::codecs::blockdsp::edge_emu;
 
 fn clip_u8(val: i16) -> u8 {
-    val.max(0).min(255) as u8
+    val.clamp(0, 255) as u8
 }
 
 fn delta(p1: i16, p0: i16, q0: i16, q1: i16) -> i16 {
-    ((p1 - q1).max(-128).min(127) + 3 * (q0 - p0)).max(-128).min(127)
+    ((p1 - q1).clamp(-128, 127) + 3 * (q0 - p0)).clamp(-128, 127)
 }
 
 pub type LoopFilterFunc = fn(buf: &mut [u8], off: usize, step: usize, stride: usize, len: usize, thr: i16, thr_inner: i16, thr_hev: i16);
@@ -71,7 +71,7 @@ fn normal_loop_filter(buf: &mut [u8], mut off: usize, step: usize, stride: usize
                     buf[off - step * 3] = clip_u8(p2 + diff2);
                     buf[off + step * 2] = clip_u8(q2 - diff2);
                 } else {
-                    let diff = (3 * (q0 - p0)).max(-128).min(127);
+                    let diff = (3 * (q0 - p0)).clamp(-128, 127);
                     let diffq0 = (diff + 4).min(127) >> 3;
                     let diffp0 = (diff + 3).min(127) >> 3;
                     buf[off - step * 1] = clip_u8(p0 + diffp0);
@@ -167,7 +167,7 @@ macro_rules! interpolate {
         let s1 = i32::from($src[$off + 1 * $step]);
         let a = (8 - $mode) as i32;
         let b = $mode as i32;
-        ((a * s0 + b * s1 + 4) >> 3).max(0).min(255) as u8
+        ((a * s0 + b * s1 + 4) >> 3).clamp(0, 255) as u8
     }}
 }
 
index 7ab7a074d442a46230edf3e3a41e0846bffd2f3d..6d4a53a2413837a161029097870ad8b419bf069a 100644 (file)
@@ -274,7 +274,7 @@ pub fn vp_put_block(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: usize,
     let mut off = frm.offset[plane] + bx * 8 + by * 8 * frm.stride[plane];
     for y in 0..8 {
         for x in 0..8 {
-            frm.data[off + x] = (coeffs[x + y * 8] + 128).min(255).max(0) as u8;
+            frm.data[off + x] = (coeffs[x + y * 8] + 128).clamp(0, 255) as u8;
         }
         off += frm.stride[plane];
     }
@@ -285,7 +285,7 @@ pub fn vp_put_block_ilace(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: u
     let mut off = frm.offset[plane] + bx * 8 + ((by & !1) * 8 + (by & 1)) * frm.stride[plane];
     for y in 0..8 {
         for x in 0..8 {
-            frm.data[off + x] = (coeffs[x + y * 8] + 128).min(255).max(0) as u8;
+            frm.data[off + x] = (coeffs[x + y * 8] + 128).clamp(0, 255) as u8;
         }
         off += frm.stride[plane] * 2;
     }
@@ -293,7 +293,7 @@ pub fn vp_put_block_ilace(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: u
 
 pub fn vp_put_block_dc(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: usize, frm: &mut NASimpleVideoFrame<u8>) {
     vp_idct_dc(coeffs);
-    let dc = (coeffs[0] + 128).min(255).max(0) as u8;
+    let dc = (coeffs[0] + 128).clamp(0, 255) as u8;
     let mut off = frm.offset[plane] + bx * 8 + by * 8 * frm.stride[plane];
     for _ in 0..8 {
         for x in 0..8 {
@@ -308,7 +308,7 @@ pub fn vp_add_block(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: usize,
     let mut off = frm.offset[plane] + bx * 8 + by * 8 * frm.stride[plane];
     for y in 0..8 {
         for x in 0..8 {
-            frm.data[off + x] = (coeffs[x + y * 8] + i16::from(frm.data[off + x])).min(255).max(0) as u8;
+            frm.data[off + x] = (coeffs[x + y * 8] + i16::from(frm.data[off + x])).clamp(0, 255) as u8;
         }
         off += frm.stride[plane];
     }
@@ -319,7 +319,7 @@ pub fn vp_add_block_ilace(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: u
     let mut off = frm.offset[plane] + bx * 8 + ((by & !1) * 8 + (by & 1)) * frm.stride[plane];
     for y in 0..8 {
         for x in 0..8 {
-            frm.data[off + x] = (coeffs[x + y * 8] + i16::from(frm.data[off + x])).min(255).max(0) as u8;
+            frm.data[off + x] = (coeffs[x + y * 8] + i16::from(frm.data[off + x])).clamp(0, 255) as u8;
         }
         off += frm.stride[plane] * 2;
     }
@@ -331,7 +331,7 @@ pub fn vp_add_block_dc(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: usiz
     let mut off = frm.offset[plane] + bx * 8 + by * 8 * frm.stride[plane];
     for _ in 0..8 {
         for x in 0..8 {
-            frm.data[off + x] = (dc + i16::from(frm.data[off + x])).min(255).max(0) as u8;
+            frm.data[off + x] = (dc + i16::from(frm.data[off + x])).clamp(0, 255) as u8;
         }
         off += frm.stride[plane];
     }
@@ -355,8 +355,8 @@ pub fn vp31_loop_filter(data: &mut [u8], mut off: usize, step: usize, stride: us
             }
         }
         if diff != 0 {
-            data[off - step] = (b + diff).max(0).min(255) as u8;
-            data[off]        = (c - diff).max(0).min(255) as u8;
+            data[off - step] = (b + diff).clamp(0, 255) as u8;
+            data[off]        = (c - diff).clamp(0, 255) as u8;
         }
 
         off += stride;
index c7bf3aad6293e6999e85e35a9a2d713e161b4395..ae86546194e9f535194c94e542bc977fde376b3f 100644 (file)
@@ -70,7 +70,7 @@ impl NAEncoder for ADPCMEncoder {
             NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError),
             NACodecTypeInfo::Audio(ainfo) => {
                 let mut outinfo = ainfo;
-                outinfo.channels = outinfo.channels.max(1).min(2);
+                outinfo.channels = outinfo.channels.clamp(1, 2);
                 if outinfo.format != SND_S16P_FORMAT && outinfo.format != SND_S16_FORMAT {
                     outinfo.format = SND_S16_FORMAT;
                 }
index ca717921d790e28c2df9282e31d860ffd6825a27..fd92c8d8014209a1b1ce27cd38b0bdf82bcb5d15 100644 (file)
@@ -71,7 +71,7 @@ fn sum_bits(src: &[i32; 128], shift: i8, off: i32) -> i32 {
     let mut sum = 0;
     for &el in src[..CODED_LEN].iter() {
         let val = (((el - off) >> (shift - 1)) + 1) >> 1;
-        sum += val.max(0).min(MAX_CBITS);
+        sum += val.clamp(0, MAX_CBITS);
     }
     sum
 }
@@ -151,7 +151,7 @@ fn bitalloc(bits: &mut [i8; 128], scales: &[i32; 128]) {
     }
 
     for (bits, &val) in bits.iter_mut().zip(tmp.iter()).take(CODED_LEN) {
-        *bits = ((((val - offset) >> (ref_shift - 1)) + 1) >> 1).max(0).min(MAX_CBITS) as i8;
+        *bits = ((((val - offset) >> (ref_shift - 1)) + 1) >> 1).clamp(0, MAX_CBITS) as i8;
     }
     if bitsum > SUBPART_BITS {
         let mut sum = 0;
index c4b55c4a24d1a4392cd0472304f40df1bc506879..fd8dbd9aca9fbbee278deaff2938dc9b7a6274d8 100644 (file)
@@ -104,8 +104,7 @@ impl<'a> SparkBR<'a> {
                 } else {
                     level = (level * q) - q_add;
                 }
-                if level < -2048 { level = -2048; }
-                if level >  2047 { level =  2047; }
+                level = level.clamp(-2048, 2047);
             } else {
                 let fmt_bit = br.read_bool()?;
                 last  = br.read_bool()?;
@@ -122,8 +121,7 @@ impl<'a> SparkBR<'a> {
                 } else {
                     level = (level * q) - q_add;
                 }
-                if level < -2048 { level = -2048; }
-                if level >  2047 { level =  2047; }
+                level = level.clamp(-2048, 2047);
             }
             idx += run;
             validate!(idx < 64);
index 99d41221f100b67515dc70294e4b4e76d51df5bd..9f735dec88ff23a963a8acd21a9dd115176340a3 100644 (file)
@@ -155,7 +155,7 @@ impl NADecoder for IPMADecoder {
     }
     fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
         let src = pkt.get_buffer();
-        validate!(src.len() > 0);
+        validate!(!src.is_empty());
 
         for sd in pkt.side_data.iter() {
             if let NASideData::Palette(true, ref pal) = sd {
index 910688b8cdedba6f1df4c00c1408460461b7aa82..5a49794fe72af1cedfe3446242e6fa1c3cc5aa9c 100644 (file)
@@ -353,7 +353,7 @@ fn decode_block_intra(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16
     match btype {
         0 | 1 => {
             let fill_val = if btype == 0 { 0x80 } else {
-                    ((dequant(coeffs[0], qmat[0]) >> 5) + 128).max(0).min(255) as u8
+                    ((dequant(coeffs[0], qmat[0]) >> 5) + 128).clamp(0, 255) as u8
                 };
             for line in dst.chunks_mut(stride).take(8) {
                 for el in line.iter_mut().take(8) {
@@ -370,7 +370,7 @@ fn decode_block_intra(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16
             idct(&mut blk);
             for (line, row) in dst.chunks_mut(stride).zip(blk.chunks(8)).take(8) {
                 for (dst, coef) in line.iter_mut().zip(row.iter()).take(8) {
-                    *dst = (*coef + 128).max(0).min(255) as u8;
+                    *dst = (*coef + 128).clamp(0, 255) as u8;
                 }
             }
         },
@@ -382,7 +382,7 @@ fn decode_block_intra(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16
             idct(&mut blk);
             for (line, row) in dst.chunks_mut(stride).zip(blk.chunks(8)).take(8) {
                 for (dst, coef) in line.iter_mut().zip(row.iter()).take(8) {
-                    *dst = (*coef + 128).max(0).min(255) as u8;
+                    *dst = (*coef + 128).clamp(0, 255) as u8;
                 }
             }
         },
@@ -396,7 +396,7 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16
             let dc = dequant(coeffs[0], qmat[0]) >> 5;
             for line in dst.chunks_mut(stride).take(8) {
                 for el in line.iter_mut().take(8) {
-                    *el = (i32::from(*el) + dc).max(0).min(255) as u8;
+                    *el = (i32::from(*el) + dc).clamp(0, 255) as u8;
                 }
             }
         },
@@ -409,7 +409,7 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16
             idct(&mut blk);
             for (line, row) in dst.chunks_mut(stride).zip(blk.chunks(8)).take(8) {
                 for (dst, coef) in line.iter_mut().zip(row.iter()).take(8) {
-                    *dst = (i32::from(*dst) + *coef).max(0).min(255) as u8;
+                    *dst = (i32::from(*dst) + *coef).clamp(0, 255) as u8;
                 }
             }
         },
@@ -421,7 +421,7 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16
             idct(&mut blk);
             for (line, row) in dst.chunks_mut(stride).zip(blk.chunks(8)).take(8) {
                 for (dst, coef) in line.iter_mut().zip(row.iter()).take(8) {
-                    *dst = (i32::from(*dst) + *coef).max(0).min(255) as u8;
+                    *dst = (i32::from(*dst) + *coef).clamp(0, 255) as u8;
                 }
             }
         },
@@ -435,7 +435,7 @@ fn init_quant(qmat: &mut [i16; 64], base_qmat: &[u8; 64], quant: u8) {
             i32::from((100 - quant.min(100)) * 2)
         };
     for (inq, (outq, scale)) in base_qmat.iter().zip(qmat.iter_mut().zip(QUANT_MATRIX.iter())) {
-        let val = ((i32::from(*inq) * q + 50) / 100).max(1).min(0x7FFF);
+        let val = ((i32::from(*inq) * q + 50) / 100).clamp(1, 0x7FFF);
         *outq = ((val * i32::from(*scale) + 0x800) >> 12) as i16;
     }
 }
index f473be3d6f0ace5c529dafc0606affb969abe835..879438a57dfe3242fb797e2b84192fa402e60226 100644 (file)
@@ -113,7 +113,7 @@ impl NADecoder for VIMADecoder {
                                 diff = -diff;
                             }
 
-                            (sample + diff).max(-32768).min(32767)
+                            (sample + diff).clamp(-32768, 32767)
                         } else {
                                           br.read_s(16)?
                         };
index 79c8dfd555c380f80b57224a0c56055293a995ab..d44cd27a3854851fae203da820ff7df8381f3626 100644 (file)
@@ -157,9 +157,7 @@ impl BitAlloc {
             cur_bits = 0;
             let mut acc = 0;
             for band in start..BANDS {
-                let mut len = (ch_data.bit_est[band] * 0.5 - pool + 0.5) as i32;
-                if len < 0 { len = 0; }
-                if len > 6 { len = 6; }
+                let len = ((ch_data.bit_est[band] * 0.5 - pool + 0.5) as i32).clamp(0, 6);
                 self.band_bits[band] = len as u8;
                 cur_bits += (self.band_width[band] as i32) * len;
                 if len > 0 {
index 9131dbaa86a109b505b49881dbc1489bc5f2ecaa..91aa7d281274ca5c6f4568d35d4c76da68abeb91 100644 (file)
@@ -165,8 +165,8 @@ fn deblock_hor(buf: &mut NAVideoBuffer<u8>, comp: usize, strength: u8, off: usiz
             let d1a = (diff.abs() - 2 * (diff.abs() - i16::from(strength)).max(0)).max(0);
             let d1  = if diff < 0 { -d1a } else { d1a };
 
-            buf[off - 1 * stride + x] = (b + d1).max(0).min(255) as u8;
-            buf[off + 0 * stride + x] = (c - d1).max(0).min(255) as u8;
+            buf[off - 1 * stride + x] = (b + d1).clamp(0, 255) as u8;
+            buf[off + 0 * stride + x] = (c - d1).clamp(0, 255) as u8;
         }
     }
 }
@@ -186,8 +186,8 @@ fn deblock_ver(buf: &mut NAVideoBuffer<u8>, comp: usize, strength: u8, off: usiz
             let d1a = (diff.abs() - 2 * (diff.abs() - i16::from(strength)).max(0)).max(0);
             let d1  = if diff < 0 { -d1a } else { d1a };
 
-            buf[off - 1 + y * stride] = (b + d1).max(0).min(255) as u8;
-            buf[off     + y * stride] = (c - d1).max(0).min(255) as u8;
+            buf[off - 1 + y * stride] = (b + d1).clamp(0, 255) as u8;
+            buf[off     + y * stride] = (c - d1).clamp(0, 255) as u8;
         }
     }
 }
@@ -390,8 +390,7 @@ impl<'a> Intel263BR<'a> {
                 } else {
                     level = (level * q) - q_add;
                 }
-                if level < -2048 { level = -2048; }
-                if level >  2047 { level =  2047; }
+                level = level.clamp(-2048, 2047);
             }
             idx += run;
             validate!(idx < 64);
index 22de5b0fcada20197ee204d8112f1324136a1070..c38ca35a9a02b5893a52b0a820ee8b00a6e077c6 100644 (file)
@@ -75,7 +75,7 @@ impl YV92Decoder {
                 if delta == ESCAPE {
                     delta = br.read(8)? as u8;
                 }
-                pred = ((i16::from(*top) - last_top + i16::from(pred)).max(0).min(255) as u8).wrapping_add(delta << 1);
+                pred = ((i16::from(*top) - last_top + i16::from(pred)).clamp(0, 255) as u8).wrapping_add(delta << 1);
                 last_top = i16::from(*top);
                 *dst = pred;
                 *top = pred;
index ae0d435d3145c4f35bdfd8f5b4b59730c51c7c92..ac9398218f705b4a48a70a61aa4367a478429e6d 100644 (file)
@@ -634,7 +634,7 @@ fn decode_block(cabac: &mut CABAC, coeffs: &mut [i16], cat: usize, ctx_off: usiz
                         1
                     } else {
                         let cur_ctx = 227 + coef_off + (coef_ctx + 2).max(5);
-                        coef_ctx = (coef_ctx + 1).max(4).min(7);
+                        coef_ctx = (coef_ctx + 1).clamp(4, 7);
 
                         let mut coef = 2;
                         while coef < 15 && cabac.decode_bit(cur_ctx) {
@@ -703,7 +703,7 @@ fn decode_block8x8(cabac: &mut CABAC, coeffs: &mut [i16; 64], _cat: usize) {
                     1
                 } else {
                     let cur_ctx = 426 + coef_off + (coef_ctx + 2).max(5);
-                    coef_ctx = (coef_ctx + 1).max(4).min(7);
+                    coef_ctx = (coef_ctx + 1).clamp(4, 7);
 
                     let mut coef = 2;
                     while coef < 15 && cabac.decode_bit(cur_ctx) {
index c41928b9a128a7aef0944618e4dfb6afbf9ab5c0..8e6127248d830bfc24f43bd9158ee2290b2488e0 100644 (file)
@@ -20,7 +20,7 @@ pub struct CABAC<'a> {
 
 impl<'a> CABAC<'a> {
     fn calc_state(qp: u8, m: i8, n: i8) -> u8 {
-        let pre_ctx_state = (((i16::from(m) * i16::from(qp)) >> 4) + i16::from(n)).max(1).min(126) as u8;
+        let pre_ctx_state = (((i16::from(m) * i16::from(qp)) >> 4) + i16::from(n)).clamp(1, 126) as u8;
         if pre_ctx_state < 64 {
             63 - pre_ctx_state
         } else {
index e5a8cb5440a5a84deb519cf1e4b7fd3a472c0047..1c2cb5220e28b640d18116f63417a61499ed9cc6 100644 (file)
@@ -268,9 +268,9 @@ impl FrameDecoder {
     #[allow(clippy::cognitive_complexity)]
     fn handle_macroblock(&mut self, slice_hdr: &SliceHeader, mb_info: &mut CurrentMBInfo, refs: &SimplifiedSliceRefs, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<()> {
         let qp_y = mb_info.qp_y;
-        let qpr = ((qp_y as i8) + self.pps.chroma_qp_index_offset).max(0).min(51) as usize;
+        let qpr = ((qp_y as i8) + self.pps.chroma_qp_index_offset).clamp(0, 51) as usize;
         let qp_u = CHROMA_QUANTS[qpr];
-        let qpb = ((qp_y as i8) + self.pps.second_chroma_qp_index_offset).max(0).min(51) as usize;
+        let qpb = ((qp_y as i8) + self.pps.second_chroma_qp_index_offset).clamp(0, 51) as usize;
         let qp_v = CHROMA_QUANTS[qpb];
 
         let tx_bypass = qp_y == 0 && self.sps.qpprime_y_zero_transform_bypass;
index ce36d2ae8e65fbaf7da0bc80b7de1a841487d01e..dd57832e108311e316adfb735d76784845383aca 100644 (file)
@@ -356,9 +356,9 @@ println!("PAFF?");
         let pps = &self.pps[self.cur_pps];
 
         let qp_y = mb_info.qp_y;
-        let qpr = ((qp_y as i8) + pps.chroma_qp_index_offset).max(0).min(51) as usize;
+        let qpr = ((qp_y as i8) + pps.chroma_qp_index_offset).clamp(0, 51) as usize;
         let qp_u = CHROMA_QUANTS[qpr];
-        let qpb = ((qp_y as i8) + pps.second_chroma_qp_index_offset).max(0).min(51) as usize;
+        let qpb = ((qp_y as i8) + pps.second_chroma_qp_index_offset).clamp(0, 51) as usize;
         let qp_v = CHROMA_QUANTS[qpb];
 
         let tx_bypass = qp_y == 0 && self.sps[self.cur_sps].qpprime_y_zero_transform_bypass;
index 44f8a515fa0ccad6aa619f51d263176bcfd605ae..7f0451846dd52eaf507820e93ab0b348d1291d9c 100644 (file)
@@ -30,7 +30,7 @@ module_selector! (
 
 type MCFunc = fn (dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, h: usize);
 
-fn clip_u8(val: i16) -> u8 { val.max(0).min(255) as u8 }
+fn clip_u8(val: i16) -> u8 { val.clamp(0, 255) as u8 }
 
 trait RegisterSIMD {
     fn register_simd(&mut self);
index 16af6dee97f7b9d8e7c65d248afd78c39964bc0b..3642d0f8f3cd8bb6265e9a1215d44e8e59b6aeb9 100644 (file)
@@ -264,7 +264,7 @@ pub fn add_coeffs(dst: &mut [u8], offset: usize, stride: usize, coeffs: &[i16])
     let out = &mut dst[offset..][..stride * 3 + 4];
     for (line, src) in out.chunks_mut(stride).take(4).zip(coeffs.chunks_exact(4)) {
         for (dst, src) in line.iter_mut().take(4).zip(src.iter()) {
-            *dst = (i32::from(*dst) + i32::from(*src)).max(0).min(255) as u8;
+            *dst = (i32::from(*dst) + i32::from(*src)).clamp(0, 255) as u8;
         }
     }
 }
@@ -273,12 +273,12 @@ pub fn add_coeffs8(dst: &mut [u8], offset: usize, stride: usize, coeffs: &[i16;
     let out = &mut dst[offset..];
     for (line, src) in out.chunks_mut(stride).take(8).zip(coeffs.chunks_exact(8)) {
         for (dst, src) in line.iter_mut().take(8).zip(src.iter()) {
-            *dst = (i32::from(*dst) + i32::from(*src)).max(0).min(255) as u8;
+            *dst = (i32::from(*dst) + i32::from(*src)).clamp(0, 255) as u8;
         }
     }
 }
 
-fn clip8(val: i16) -> u8 { val.max(0).min(255) as u8 }
+fn clip8(val: i16) -> u8 { val.clamp(0, 255) as u8 }
 
 fn ipred_dc128(buf: &mut [u8], stride: usize, bsize: usize) {
     for row in buf.chunks_mut(stride).take(bsize) {
index 0890f30fa0a0eb761136524aca9777e515b18820..feba5e1bba442a60cc92de88dc886ba6c30abb76 100644 (file)
@@ -32,7 +32,7 @@ const TC0: [[u8; 3]; 52] = [
 ];
 
 fn get_lf_idx(qp0: u8, qp1: u8, off: i8) -> usize {
-    (i16::from((qp0 + qp1 + 1) >> 1) + i16::from(off)).max(0).min(51) as usize
+    (i16::from((qp0 + qp1 + 1) >> 1) + i16::from(off)).clamp(0, 51) as usize
 }
 
 macro_rules! filter_edge_func {
index d8e51f3fbab7bbf13353b8335b39c40f52709509..4cafcbb8b3c439e6d82fa211231f18ba9945ae26 100644 (file)
@@ -436,10 +436,10 @@ fn get_weights(slice_hdr: &SliceHeader, frame_refs: &SimplifiedSliceRefs, mode:
             return (DEF_WEIGHT_INFO, DEF_WEIGHT_INFO);
         }
 
-        let td = (i32::from(r1_poc) - i32::from(r0_poc)).max(-128).min(127);
+        let td = (i32::from(r1_poc) - i32::from(r0_poc)).clamp(-128, 127);
         let tx = (16384 + (td / 2).abs()) / td;
-        let tb = (i32::from(cur_id) - i32::from(r0_poc)).max(-128).min(127);
-        let scale = ((tb * tx + 32) >> 6).max(-1024).min(1023);
+        let tb = (i32::from(cur_id) - i32::from(r0_poc)).clamp(-128, 127);
+        let scale = ((tb * tx + 32) >> 6).clamp(-1024, 1023);
         if scale == 128 || (scale >> 2) < -64 || (scale >> 2) > 128 {
             return (DEF_WEIGHT_INFO, DEF_WEIGHT_INFO);
         }
index 9cd70880eea965e601bfc92b1b0fae5463aa372e..0e28914066086aabe26df6da874e8349a5458c99 100644 (file)
@@ -78,7 +78,7 @@ const MMCO_TEST_STREAMS: &[(&str, [u32; 4])] = &[
     ("MR1_BT_A.h264", [0x617BF915, 0x48E89440, 0xC899A917, 0xC73CF171]),
     ("MR2_TANDBERG_E.264", [0x69C17B20, 0xDF6E89E6, 0x82BD82F1, 0x93B6D282]),
     ("MR3_TANDBERG_B.264", [0xC8AAC175, 0xE5E73C68, 0x87EE02FF, 0x6DEA0F64]),
-    ("MR4_TANDBERG_C.264", [0xA40042BC, 0xAB00C341, 0xA9651725, 0x46d31A2C]),
+    ("MR4_TANDBERG_C.264", [0xA40042BC, 0xAB00C341, 0xA9651725, 0x46D31A2C]),
     ("MR5_TANDBERG_C.264", [0x999EAE2E, 0x016DB374, 0x708B00E4, 0x335AE723]),
     ("MR1_MW_A.264", [0xDD56DC8E, 0x403B18EC, 0x57EB5B3A, 0xD834FFDE]),
     ("MR2_MW_A.264", [0xE1E93E65, 0x96AF2EFD, 0x0E7D0FE5, 0x94D5BE85]),
index ba6ff6e5bc0a307623a30d6487fc5b16b6905feb..0e92a9565e54b86f2963575f697d31d9cfbdffe1 100644 (file)
@@ -112,7 +112,7 @@ impl<'a> DemuxCore<'a> for RawH264Demuxer<'a> {
 
         let vhdr = NAVideoInfo::new(width, height, false, YUV420_FORMAT);
         let vinfo = NACodecInfo::new("h264", NACodecTypeInfo::Video(vhdr), Some(edata));
-        if let None = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, 25, 0)) {
+        if strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, 25, 0)).is_none() {
             return Err(DemuxerError::InvalidData);
         }
         self.cur_frame = 0;
index 577cefe93685843413861115bb3c036749db9b38..9619e068005e765f6fd01f20c70a8f1da37f53bb 100644 (file)
@@ -843,13 +843,13 @@ impl SliceState {
             };
         let (col_ref, r0_long) = frame_refs.map_ref0(r0_poc);
         if temporal_mv {
-            let td = (i32::from(r1_poc) - i32::from(r0_poc)).max(-128).min(127);
+            let td = (i32::from(r1_poc) - i32::from(r0_poc)).clamp(-128, 127);
             if r0_long || td == 0 {
                 (col_mv, col_ref, ZERO_MV, ZERO_REF)
             } else {
                 let tx = (16384 + (td / 2).abs()) / td;
-                let tb = (i32::from(cur_id) - i32::from(r0_poc)).max(-128).min(127);
-                let scale = ((tb * tx + 32) >> 6).max(-1024).min(1023);
+                let tb = (i32::from(cur_id) - i32::from(r0_poc)).clamp(-128, 127);
+                let scale = ((tb * tx + 32) >> 6).clamp(-1024, 1023);
                 let mv0 = MV {
                         x: ((i32::from(col_mv.x) * scale + 128) >> 8) as i16,
                         y: ((i32::from(col_mv.y) * scale + 128) >> 8) as i16,
index c63505911d4d6f5c33ec6af3a3e1320cdef19b3c..95b4b8858ccaa956e733bc3934ca990421040457 100644 (file)
@@ -196,7 +196,7 @@ impl NFilterContext {
             let pred = (sum + (1 << (self.bits - 1))) >> self.bits;
             let val = *el + pred;
             *el = val;
-            self.buf[delay_pos] = val.min(32767).max(-32768) as i16;
+            self.buf[delay_pos] = val.clamp(-32768, 32767) as i16;
             if self.new {
                 let aval = val.abs();
                 let sign = val2sign(val) as i16;
index 3b992941c6841b681ba4d520bb7cdb0e83a2af7a..e1e895804f7432f1cf4570c884ed7380b84af972 100644 (file)
@@ -403,14 +403,14 @@ impl NAEncoder for FLACEncoder {
             NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError),
             NACodecTypeInfo::Audio(ainfo) => {
                 let mut outinfo = ainfo;
-                outinfo.channels = outinfo.channels.max(1).min(8);
+                outinfo.channels = outinfo.channels.clamp(1, 8);
                 if outinfo.format != SND_S16P_FORMAT && outinfo.format != SND_S16_FORMAT {
                     outinfo.format = SND_S16P_FORMAT;
                 }
                 if outinfo.block_len == 0 {
                     outinfo.block_len = DEFAULT_BLOCK_LEN;
                 }
-                outinfo.block_len = outinfo.block_len.max(2).min(65535);
+                outinfo.block_len = outinfo.block_len.clamp(2, 65535);
                 let mut ofmt = *encinfo;
                 ofmt.format = NACodecTypeInfo::Audio(outinfo);
                 Ok(ofmt)
index 2cdaf7715a0524babd73a2c673311fb2100432dc..e16b15707dc9730546eeaa4c92046d9ae31ce4aa 100644 (file)
@@ -4,18 +4,18 @@ pub trait MVClipPixel {
 }
 
 impl MVClipPixel for i8 {
-    fn clip_y(self) -> Self { self.max(0).min(31) }
-    fn clip_c(self) -> Self { self.max(-31).min(31) }
+    fn clip_y(self) -> Self { self.clamp(0, 31) }
+    fn clip_c(self) -> Self { self.clamp(-31, 31) }
 }
 
 impl MVClipPixel for i16 {
-    fn clip_y(self) -> Self { self.max(0).min(31) }
-    fn clip_c(self) -> Self { self.max(-31).min(31) }
+    fn clip_y(self) -> Self { self.clamp(0, 31) }
+    fn clip_c(self) -> Self { self.clamp(-31, 31) }
 }
 
 impl MVClipPixel for i32 {
-    fn clip_y(self) -> Self { self.max(0).min(31) }
-    fn clip_c(self) -> Self { self.max(-31).min(31) }
+    fn clip_y(self) -> Self { self.clamp(0, 31) }
+    fn clip_c(self) -> Self { self.clamp(-31, 31) }
 }
 
 #[derive(Clone,Copy,Debug,Default)]
@@ -102,7 +102,7 @@ void main() {
     printf("];\n");
 }
 */
-const RGB2YUV: [YuvPixel; 32768] = [
+static RGB2YUV: [YuvPixel; 32768] = [
  pix!( 0, -1, -1), pix!( 0,  2, -1), pix!( 0,  3, -1), pix!( 0,  4, -1),
  pix!( 0,  5, -1), pix!( 0,  6, -1), pix!( 0,  7, -1), pix!( 1,  7, -2),
  pix!( 1,  8, -2), pix!( 1, 10, -2), pix!( 1, 11, -2), pix!( 1, 12, -2),
index 532b892d113595588d4e9ab607dad672da7f4e29..ac1e25ac0448bf8bfec2ce0ac12831e15efa941d 100644 (file)
@@ -88,7 +88,7 @@ fn decode_band(br: &mut BitReader, cb: &Codebook<u8>, dst: &mut [f32], w: usize,
                             esc + 0x8FC
                         }
                     },
-                    0xFC | 0xFD | 0xFE | 0xFF => {
+                    0xFC..=0xFF => {
                         zero_run = u32::from(val - 0xFC);
                         if zero_skip {
                             continue;
@@ -242,7 +242,7 @@ impl MWV1Decoder {
             let dst = &mut frm.data[frm.offset[plane]..];
             for (drow, srow) in dst.chunks_mut(frm.stride[plane]).zip(self.plane[plane].chunks(self.stride[plane])) {
                 for (dst, &src) in drow.iter_mut().zip(srow.iter()) {
-                    *dst = (src + 128.0).max(0.0).min(255.0) as u8;
+                    *dst = (src + 128.0).clamp(0.0, 255.0) as u8;
                 }
             }
         }
index 21e15bd71da79cf954da3431a0742537b6470cf7..7d27fe2d77a38685530a524a329f23cc1a8092c3 100644 (file)
@@ -121,7 +121,7 @@ fn idct(blk: &mut [i16; 64]) {
 fn put_block(blk: &[i16; 64], dst: &mut [u8], stride: usize) {
     for (drow, srow) in dst.chunks_mut(stride).zip(blk.chunks(8)) {
         for (del, &pix) in drow.iter_mut().zip(srow.iter()) {
-            *del = pix.max(0).min(255) as u8;
+            *del = pix.clamp(0, 255) as u8;
         }
     }
 }
@@ -449,8 +449,8 @@ impl NADecoder for RadiusStudioDecoder {
         ];
 
         for (i, (&luma_q, &chroma_q)) in DEF_LUMA_QUANT.iter().zip(DEF_CHROMA_QUANT.iter()).enumerate() {
-            self.quant[0][ZIGZAG[i]] = ((i16::from(quant) * i16::from(luma_q) + 25) / 50).max(1).min(255);
-            self.quant[1][ZIGZAG[i]] = ((i16::from(quant) * i16::from(chroma_q) + 25) / 50).max(1).min(255);
+            self.quant[0][ZIGZAG[i]] = ((i16::from(quant) * i16::from(luma_q) + 25) / 50).clamp(1, 255);
+            self.quant[1][ZIGZAG[i]] = ((i16::from(quant) * i16::from(chroma_q) + 25) / 50).clamp(1, 255);
         }
 
         if let Some(buf) = bufinfo.get_vbuf() {
index e37ec8def72785136952ecfd0c9392f6b4dd4db4..a301753e613ba6df796e13efa3e39ebd25067b85 100644 (file)
@@ -572,7 +572,7 @@ mod test {
     }
 }
 
-const MVS: [(i8, i8); 225] = [
+static MVS: [(i8, i8); 225] = [
     (  0,-16), (  3,-16),
     ( -6,-14), (  6,-14),
     ( -2,-13), (  0,-13), (  2,-13),
@@ -606,7 +606,7 @@ const MVS: [(i8, i8); 225] = [
     ( -3, 16)
 ];
 
-const PATTERNS: [u64; 256] = [
+static PATTERNS: [u64; 256] = [
     0x0000000080808000, 0x0000008080808000, 0x0000808080808000, 0x0080808080808000,
     0xC080808080808000, 0xE0C0C0C080808000, 0xF0E0E0C0C0808000, 0xF8F0E0E0C0808000,
     0xFCF8F0E0C0808000, 0xFEFCF8F0E0C08000, 0xFFFFFEFCF8E0C000, 0xFFFFFFFEFCF0C000,
@@ -673,7 +673,7 @@ const PATTERNS: [u64; 256] = [
     0x0000000000000070, 0x55AA55AA55AA55AA, 0xE7E7E7E7E7E7E7E7, 0xFFFFFF0000FFFFFF
 ];
 
-const BLOCK4_PATTERNS: [u16; 256] = [
+static BLOCK4_PATTERNS: [u16; 256] = [
     0x0008, 0x00FF, 0x0FFF, 0x7FFF, 0x37FF, 0xFEC8, 0xFFEC, 0xFFFE,
     0xEEEE, 0xCCCC, 0xCCC8, 0x07FF, 0xEEC8, 0xEEEC, 0x0088, 0x0080,
     0x0FF0, 0xFFF0, 0x7FF0, 0xEC80, 0xFEC0, 0xFFE0, 0xFFF0, 0xFFF1,
@@ -708,7 +708,7 @@ const BLOCK4_PATTERNS: [u16; 256] = [
     0x0066, 0x0466, 0x0EE0, 0x0020, 0xA954, 0x6561, 0x6C50, 0x6E74
 ];
 
-const RGB_TAB: [[u16; 32768]; 2] = [
+static RGB_TAB: [[u16; 32768]; 2] = [
   [
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
index 5adbc07779827ade37713575e87c6a58ff426298..0dd7a897ae52eb8c625c91e6bd580da2a8541004 100644 (file)
@@ -276,7 +276,7 @@ impl ICS {
                 let mut bottom = self.get_num_bands();
                 for f in 0..tns_data.n_filt[w] {
                     let top = bottom;
-                    bottom = if top >= tns_data.coeffs[w][f].length { top - tns_data.coeffs[w][f].length } else { 0 };
+                    bottom = top.saturating_sub(tns_data.coeffs[w][f].length);
                     let order = tns_data.coeffs[w][f].order;
                     if order == 0 { continue; }
                     let start = w * 128 + self.get_band_start(tns_max_bands.min(bottom));
index 6d326bdea57d8944b0b661eefed6117c8e52a21a..f6ee371c215fa06599c9772ca04c9fe4347e6356 100644 (file)
@@ -349,7 +349,6 @@ impl SBRChannel {
         match self.qmode {
             QuantMode::Single => {
                 for (env_no, &env_end) in self.env_border[1..=self.num_env].iter().enumerate() {
-                    let env_end = env_end;
                     let mut noise_env_no = 0;
                     for nenv in 0..self.num_noise {
                         if (start >= noise_env[nenv]) && (env_end <= noise_env[nenv + 1]) {
@@ -370,7 +369,6 @@ impl SBRChannel {
             },
             QuantMode::Left => {
                 for (env_no, &env_end) in self.env_border[1..=self.num_env].iter().enumerate() {
-                    let env_end = env_end;
                     let mut noise_env_no = 0;
                     for nenv in 0..self.num_noise {
                         if (start >= noise_env[nenv]) && (env_end <= noise_env[nenv + 1]) {
@@ -391,7 +389,6 @@ impl SBRChannel {
             },
             QuantMode::Right => {
                 for (env_no, &env_end) in self.env_border[1..=self.num_env].iter().enumerate() {
-                    let env_end = env_end;
                     let mut noise_env_no = 0;
                     for nenv in 0..self.num_noise {
                         if (start >= noise_env[nenv]) && (env_end <= noise_env[nenv + 1]) {
index 80d8ef2351b58c77331c4126d73ddd422178b0a5..7db0b74e480b236e3667f5d547b43b75afc82026 100644 (file)
@@ -93,7 +93,7 @@ trait Clip8 {
 }
 
 impl Clip8 for i16 {
-    fn clip8(self) -> u8 { self.max(0).min(255) as u8 }
+    fn clip8(self) -> u8 { self.clamp(0, 255) as u8 }
 }
 
 trait ClipCoef {
@@ -101,7 +101,7 @@ trait ClipCoef {
 }
 
 impl ClipCoef for i32 {
-    fn clip_coef(self) -> i16 { self.max(-2048).min(2047) as i16 }
+    fn clip_coef(self) -> i16 { self.clamp(-2048, 2047) as i16 }
 }
 
 pub fn get_dc_scales(quant: u8) -> [u8; 2] {
index ddb9e26579b7f99e54bbf664dbe1eb18368900e8..28ff0c31d9be60f80347b339c7e9fe485b833209 100644 (file)
@@ -290,19 +290,19 @@ impl PredState {
             0..=3 => {
                 let cur_addr = mb_x * 2 + (n & 1) + (n / 2) * self.y_dc.stride;
                 let (diff, dir) = Self::dc_pred(&self.y_dc, cur_addr);
-                let dc = ((cur_dc + (diff + i16::from(dc_scale >> 1)) / i16::from(dc_scale)) * i16::from(dc_scale)).max(-2048).min(2047);
+                let dc = ((cur_dc + (diff + i16::from(dc_scale >> 1)) / i16::from(dc_scale)) * i16::from(dc_scale)).clamp(-2048, 2047);
                 self.y_dc.data[self.y_dc.xpos + cur_addr] = dc;
                 (dc, dir)
             },
             4 => {
                 let (diff, dir) = Self::dc_pred(&self.u_dc, mb_x);
-                let dc = ((cur_dc + (diff + i16::from(dc_scale >> 1)) / i16::from(dc_scale)) * i16::from(dc_scale)).max(-2048).min(2047);
+                let dc = ((cur_dc + (diff + i16::from(dc_scale >> 1)) / i16::from(dc_scale)) * i16::from(dc_scale)).clamp(-2048, 2047);
                 self.u_dc.data[self.u_dc.xpos + mb_x] = dc;
                 (dc, dir)
             },
             5 => {
                 let (diff, dir) = Self::dc_pred(&self.v_dc, mb_x);
-                let dc = ((cur_dc + (diff + i16::from(dc_scale >> 1)) / i16::from(dc_scale)) * i16::from(dc_scale)).max(-2048).min(2047);
+                let dc = ((cur_dc + (diff + i16::from(dc_scale >> 1)) / i16::from(dc_scale)) * i16::from(dc_scale)).clamp(-2048, 2047);
                 self.v_dc.data[self.v_dc.xpos + mb_x] = dc;
                 (dc, dir)
             },
index 2ee78e51acfd0dc0fe8fc2a736b0f3c9ca3793cf..a3e77cdb65cc84332a2a12c211f336b893bd2a3b 100644 (file)
@@ -263,7 +263,7 @@ impl MP3Data {
             - 8 * i32::from(sblk_gain)
             - if gr.scalefac_scale { 4 } else { 2 } * (i32::from(gr.scalefac[ssb])
                 + if gr.preflag { i32::from(MP3_PREEMP_SCALES[sb]) } else { 0 })
-        ).min(127).max(-124) as i8
+        ).clamp(-124, 127) as i8
     }
     fn read_mp3_coeffs(&mut self, br: &mut BitReader, end: usize, gr_no: usize, ch: usize, coeffs: &mut [f32]) -> DecoderResult<()> {
         let mut scales = [0; SAMPLES / 2];
index 7cb6a784f24d3bdcce6400e44df7a5b5dec1c8ce..e37b6f8b416c5273312917732c435357027c4d3a 100644 (file)
@@ -24,7 +24,7 @@ impl Predictor {
     fn expand_nibble(&mut self, nibble: u8) -> i16 {
         let mul = if (nibble & 8) == 0 { i32::from(nibble) } else { i32::from(nibble) - 16 };
         let pred = self.calc_pred() + self.delta.wrapping_mul(mul);
-        self.update(pred.max(-0x8000).min(0x7FFF));
+        self.update(pred.clamp(-0x8000, 0x7FFF));
         self.delta = (ADAPT_TABLE[nibble as usize].wrapping_mul(self.delta) >> 8).max(16);
         self.sample1 as i16
     }
@@ -294,7 +294,7 @@ impl MSADPCMEncoder {
         dist
     }
     fn calculate_mul(delta: i32, diff: i32) -> u8 {
-        ((diff / delta).max(-8).min(7) & 0xF) as u8
+        ((diff / delta).clamp(-8, 7) & 0xF) as u8
     }
     fn calc_block_size(nsamps: usize, channels: usize) -> usize {
         (nsamps - 2) * channels / 2 + 7 * channels
index 460dca9711c150fb9bb66b0946c0c20b8507e690..6ee1ad9f4712e56180881080c13a11a770b0d424 100644 (file)
@@ -19,7 +19,7 @@ fn clip(val: i32) -> i16 {
 }
 
 fn to_sample(val: i32) -> u8 {
-    ((val >> 8) + 128).max(0).min(255) as u8
+    ((val >> 8) + 128).clamp(0, 255) as u8
 }
 
 impl ChannelPredictor {
index 1fd52e3cf4588d6ca86a0a4e0334e1ae5b909c12..431a04992b9ca70f7fbc114d98f6b78df92808d1 100644 (file)
@@ -226,7 +226,7 @@ impl SVQ1Decoder {
                     }
                     for (dline, sline) in dst[off..].chunks_mut(dstride).zip(blk.chunks_exact(w)).take(h) {
                         for (dst, &src) in dline.iter_mut().zip(sline.iter()) {
-                            *dst = src.max(0).min(255) as u8;
+                            *dst = src.clamp(0, 255) as u8;
                         }
                     }
                 } else {
@@ -295,7 +295,7 @@ impl SVQ1Decoder {
 
                     for (dline, sline) in dst[off..].chunks_mut(dstride).zip(blk.chunks_exact(w)).take(h) {
                         for (dst, &src) in dline.iter_mut().zip(sline.iter()) {
-                            *dst = src.max(0).min(255) as u8;
+                            *dst = src.clamp(0, 255) as u8;
                         }
                     }
                 }
index 9951cd29cf2125a0eea6741239e70bfd2abc2ad9..e7733495190e64d18ce8ca6088beaef0afa4bfca 100644 (file)
@@ -1090,7 +1090,7 @@ impl NADecoder for SVQ3Decoder {
     }
     fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
         let src = pkt.get_buffer();
-        validate!(src.len() > 0);
+        validate!(!src.is_empty());
 
         if src.len() == 1 {
             validate!(src[0] == 0xFF);
index b97ea16b4b266732c8d11ddd79f54dbbd2790150..002d11720c16f59963dedd6c66c8a6a8726aebcf 100644 (file)
@@ -128,7 +128,7 @@ pub fn add_coeffs(dst: &mut [u8], offset: usize, stride: usize, coeffs: &[i16])
     let out = &mut dst[offset..][..stride * 3 + 4];
     for (line, src) in out.chunks_mut(stride).take(4).zip(coeffs.chunks(4)) {
         for (dst, src) in line.iter_mut().take(4).zip(src.iter()) {
-            *dst = (i32::from(*dst) + i32::from(*src)).max(0).min(255) as u8;
+            *dst = (i32::from(*dst) + i32::from(*src)).clamp(0, 255) as u8;
         }
     }
 }
@@ -142,7 +142,7 @@ pub fn avg(dst: &mut [u8], dstride: usize,
     }
 }
 
-fn clip8(val: i16) -> u8 { val.max(0).min(255) as u8 }
+fn clip8(val: i16) -> u8 { val.clamp(0, 255) as u8 }
 
 fn ipred_dc128(buf: &mut [u8], mut idx: usize, stride: usize, bsize: usize) {
     for _ in 0..bsize {
index 69d3c46e4057913fdaecc2034c641215e5aaf8c7..eb1c0b4eb91ccd6a4aff1e397acbfae34353d692 100644 (file)
@@ -109,7 +109,7 @@ fn bink2_idct_old(coeffs: &mut [f32; 64]) {
 struct Bink2DSP { }
 
 fn clip8(val: i32) -> u8 {
-    val.min(255).max(0) as u8
+    val.clamp(0, 255) as u8
 }
 
 macro_rules! el {
index b8a03ab498a6934581c57f0b98a95d17bfcb90d5..7ee54ee28852f943aa47399d1910fe5475df58f5 100644 (file)
@@ -388,7 +388,7 @@ impl NAEncoder for BinkAudioEncoder {
             NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError),
             NACodecTypeInfo::Audio(ainfo) => {
                 let mut outinfo = ainfo;
-                outinfo.channels = if !self.use_dct { 2 } else { ainfo.channels.min(2).max(1) };
+                outinfo.channels = if !self.use_dct { 2 } else { ainfo.channels.clamp(1, 2) };
                 outinfo.format = SND_F32P_FORMAT;
                 let mut ofmt = *encinfo;
                 ofmt.format = NACodecTypeInfo::Audio(outinfo);
index 405b3fb0b883d3db49a22d49df9a45bf4c982b7c..c360145f2aa41d2496d55c36c7e2b33c3c560650 100644 (file)
@@ -356,7 +356,7 @@ impl CookChannelPair {
             } else {
                 pos >>= 1;
             }
-            let ipos = ((pos as i8) - 1).max(0).min(12);
+            let ipos = ((pos as i8) - 1).clamp(0, 12);
             let cb = &codebooks.quant_cb[ipos as usize];
             self.qindex[i]                              = (br.read_cb(cb)? as i8) + self.qindex[i - 1] - 12;
             validate!((self.qindex[i] >= -63) && (self.qindex[i] <= 63));
index 19f1a8891068650eef2b326a564b49b301f45e83..fa26ad2971b2d7ee42c9321b690c75781ac7b050 100644 (file)
@@ -298,7 +298,7 @@ fn calc_qindex(nrg: f32) -> i8 {
     } else {
         nrg0 *= std::f32::consts::SQRT_2;
     }
-    nrg0.log2().max(-31.0).min(47.0) as i8
+    nrg0.log2().clamp(-31.0, 47.0) as i8
 }
 
 impl CookChannelPair {
@@ -357,7 +357,7 @@ impl CookChannelPair {
         if params.js_bits == 0 {
             for (i, qscale) in qindex[..total_bands].iter_mut().enumerate().skip(1) {
                 let cb_idx = (i - 1).min(12);
-                let diff = (*qscale - last_q).max(-12).min(11);
+                let diff = (*qscale - last_q).clamp(-12, 11);
                 *qscale = last_q + diff;
                 last_q = *qscale;
 
@@ -368,7 +368,7 @@ impl CookChannelPair {
             for (i, qscale) in qindex[..total_bands].iter_mut().enumerate().skip(1) {
                 let band_no = if i < params.js_start * 2 { i >> 1 } else { i - params.js_start };
                 let cb_idx = band_no.saturating_sub(1).min(12);
-                let diff = (*qscale - last_q).max(-12).min(11);
+                let diff = (*qscale - last_q).clamp(-12, 11);
                 *qscale = last_q + diff;
                 last_q = *qscale;
 
index f3237e73965da0246f6bf24b495879633287dd02..ffe847c25b7039636f741ab0d310f952effcef5c 100644 (file)
@@ -232,7 +232,7 @@ fn eval_reflection(coeffs: &[i16; LPC_ORDER]) -> Option<u32> {
 }
 
 fn clip_out(sample: i16) -> i16 {
-    sample.max(-16384 >> 2).min(16383 >> 2)
+    sample.clamp(-16384 >> 2, 16383 >> 2)
 }
 
 impl NADecoder for RA144Decoder {
index 1774ff571cb7588864b786cb7983c5e3898ee2af..aab218051d749d4792f6384ca4c4570ec9f2dfd9 100644 (file)
@@ -129,7 +129,7 @@ impl RA288Decoder {
         let sum = self.gain_hist[GAIN_START..].iter().rev()
                 .zip(self.gain_lpc.iter())
                 .fold(32.0f32, |acc, (&a, &b)| acc - a * b)
-                .max(0.0).min(60.0);
+                .clamp(0.0, 60.0);
 
         let scale = (sum * 0.1151292546497).exp() * gain * (1.0 / ((1 << 23) as f32));
         let mut buf: [f32; BLOCKSIZE] = [0.0; BLOCKSIZE];
index ac3479773fdb8a1804e5032851c93428b9c7f48a..420365532284bc141775335f5cd1057fa5d2f5b4 100644 (file)
@@ -207,7 +207,7 @@ impl Channel {
 
         let code_params                                 = br.read_cb(&cset.coding_mode_cb).unwrap();
         let (add_bits, range, range2, codes_cb) = if code_params >= 15 {
-                let mut add_bits = ((code_params / 5 - 3) / 2).max(0).min(10) as u8;
+                let mut add_bits = ((code_params / 5 - 3) / 2).clamp(0, 10) as u8;
                 if add_bits > 9 && ((code_params % 5) != 2) {
                     add_bits -= 1;
                 }
@@ -507,7 +507,7 @@ const RALF_FILTER_COEFFS_LEN: usize =  43;
 const RALF_SHORT_CODES_LEN: usize =   169;
 const RALF_LONG_CODES_LEN: usize =    441;
 
-const RALF_FILTER_PARAM_TAB: [[u8; 324]; 3] = [
+static RALF_FILTER_PARAM_TAB: [[u8; 324]; 3] = [
   [
     0x48, 0x86, 0x66, 0x8A, 0xBB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
@@ -595,7 +595,7 @@ const RALF_FILTER_PARAM_TAB: [[u8; 324]; 3] = [
   ]
 ];
 
-const RALF_BIAS_TAB: [[u8; 128]; 3] = [
+static RALF_BIAS_TAB: [[u8; 128]; 3] = [
   [
     0x4A, 0xAA, 0xAA, 0xAA, 0xBA, 0xBA, 0xBA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
     0xAA, 0xAA, 0xAA, 0xAB, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x9A, 0xA9, 0xA9,
@@ -635,7 +635,7 @@ const RALF_BIAS_TAB: [[u8; 128]; 3] = [
   ]
 ];
 
-const RALF_CODING_MODE_TAB: [[u8; 72]; 3] = [
+static RALF_CODING_MODE_TAB: [[u8; 72]; 3] = [
   [
     0xAA, 0x99, 0xAC, 0xB9, 0xBD, 0xAA, 0x7A, 0xA8, 0xA8, 0xA8, 0x79, 0x79,
     0x77, 0xA8, 0x97, 0x79, 0x89, 0x77, 0x87, 0x87, 0x68, 0x78, 0x66, 0x86,
@@ -660,7 +660,7 @@ const RALF_CODING_MODE_TAB: [[u8; 72]; 3] = [
   ]
 ];
 
-const RALF_FILTER_COEFFS_TAB: [[[[u8; 24]; 11]; 10]; 3] = [
+static RALF_FILTER_COEFFS_TAB: [[[[u8; 24]; 11]; 10]; 3] = [
  [
   [
    [
@@ -2049,7 +2049,7 @@ const RALF_FILTER_COEFFS_TAB: [[[[u8; 24]; 11]; 10]; 3] = [
  ],
 ];
 
-const RALF_SHORT_CODES_TAB: [[[u8; 88]; 15]; 3] = [
+static RALF_SHORT_CODES_TAB: [[[u8; 88]; 15]; 3] = [
  [
   [
     0xDF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xCF, 0xFF,
@@ -2508,7 +2508,7 @@ const RALF_SHORT_CODES_TAB: [[[u8; 88]; 15]; 3] = [
  ],
 ];
 
-const RALF_LONG_CODES_TAB: [[[u8; 224]; 125]; 3] = [
+static RALF_LONG_CODES_TAB: [[[u8; 224]; 125]; 3] = [
  [
   [
     0xBE, 0xED, 0xDD, 0xDD, 0xDD, 0xDD, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF, 0xFF,
index 9eca2a98c3b9926e62d304c2275dd111f38f284b..8992a13066bc6ca9e4f33415ef0c72a64a505c8c 100644 (file)
@@ -187,8 +187,7 @@ impl<'a> RealVideo10BR<'a> {
                 } else {
                     level = (level * q) - q_add;
                 }
-                if level < -2048 { level = -2048; }
-                if level >  2047 { level =  2047; }
+                level = level.clamp(-2048, 2047);
             }
             idx += run;
             validate!(idx < 64);
index 8c837602111b2812737372e9782b92628b74aaf4..be4fdba13df851b8801c27a810d09d6aebe213e6 100644 (file)
@@ -287,8 +287,7 @@ impl<'a> RealVideo20BR<'a> {
                 } else {
                     level = (level * q) - q_add;
                 }
-                if level < -2048 { level = -2048; }
-                if level >  2047 { level =  2047; }
+                level = level.clamp(-2048, 2047);
             }
             idx += run;
             validate!(idx < 64);
index 192cf726542f119e265e102f864c971ae1c84462..e72d466ddb5ae5f60330d0a4a38ceb1046b26a4c 100644 (file)
@@ -62,7 +62,7 @@ impl BlockOps for Block {
         for (i, el) in self.coeffs.iter_mut().enumerate() {
             if *el != 0 {
                 let q = if matches!(i, 0 | 1 | 4) { q_dc } else { q_ac };
-                *el = (i32::from(*el) * 16 / q).max(-511).min(511) as i16;
+                *el = (i32::from(*el) * 16 / q).clamp(-511, 511) as i16;
             }
         }
     }
index aac1c1b9f1c67bc4bfc494eba88455064fd583bb..f63d6c92b846b0b7325b28e944acdc1f448b674e 100644 (file)
@@ -50,7 +50,7 @@ impl IntraPred16x16 {
                 for line in dst.chunks_mut(stride).take(16) {
                     let mut oval = a;
                     for el in line[..16].iter_mut() {
-                        *el = (oval >> 5).max(0).min(255) as u8;
+                        *el = (oval >> 5).clamp(0, 255) as u8;
                         oval += b;
                     }
                     a += c;
index b3b3025b4af61805c10c06f61b52bbea222ba264..605f2ebb6c7167838cd07c30bc45ea391591714b 100644 (file)
@@ -755,7 +755,7 @@ impl MacroblockDecider {
         let mut dist = 0u32;
         for (diffs, (pred, refsrc)) in blk.coeffs.chunks(4).zip(pred.chunks(stride).zip(refsrc.chunks(stride))) {
             for (&diff, (&p, &r)) in diffs.iter().zip(pred.iter().zip(refsrc.iter())) {
-                let new = (i32::from(p) + i32::from(diff)).max(0).min(255);
+                let new = (i32::from(p) + i32::from(diff)).clamp(0, 255);
                 let expected = i32::from(r);
                 dist += ((new - expected) * (new - expected)) as u32;
             }
index 80966970ad8fcf3e12a91cac76c7adb2a5eaa587..402cf3dd67e6e6eab430653a702108e6f87ddc6c 100644 (file)
@@ -687,7 +687,7 @@ fn calc_psnr(pic1: &NAVideoBuffer<u8>, pic2: &NAVideoBuffer<u8>) -> f64 {
     if size > 0 {
         48.13080360867910341240 - 10.0 * ((sum as f64) / (size as f64)).log10()
     } else {
-        std::f64::INFINITY
+        f64::INFINITY
     }
 }
 
index 84fdeff83bfe6dd22428c68691ed6f5d3eb85d39..e5315bcb803fd5dd841df482bb502ff281fd2d9c 100644 (file)
@@ -2,7 +2,7 @@ use nihav_core::frame::{NAVideoBuffer, NASimpleVideoFrame};
 use nihav_codec_support::codecs::MV;
 use nihav_codec_support::codecs::blockdsp::edge_emu;
 
-fn clip8(val: i16) -> u8 { val.min(255).max(0) as u8 }
+fn clip8(val: i16) -> u8 { val.clamp(0, 255) as u8 }
 
 macro_rules! el {
     ($s: ident, $o: expr) => ( $s[$o] as i16 )
index ea229fb37a21e18aa63fdbf8a542864f12d5600e..a27ed63200566521eb13daddde73dca48396615e 100644 (file)
@@ -619,7 +619,7 @@ impl G7231Decoder {
                     }
                 };
             let shift = shift + 1;
-            let x = (if shift >= 0 { x << shift } else { x >> -shift }).min(10000).max(-10000);
+            let x = (if shift >= 0 { x << shift } else { x >> -shift }).clamp(-10000, 10000);
             for j in 0..11 {
                 let val = (x * signs[i / 2][j]) >> 15;
                 buf[pos[i / 2 * 11 + j]] = buf[pos[i / 2 * 11 + j]].saturating_add(val as i16);
@@ -838,7 +838,7 @@ impl G7231Decoder {
             let bits2 = norm_bits(den, 31);
             num = num << bits1 >> 1;
             den <<= bits2;
-            let shift = (5 + bits1 - bits2).max(0);
+            let shift = (5 + bits1).saturating_sub(bits2);
 
             gain = square_root_i32(((num >> 1) / (den >> 16)) << 16 >> shift);
         } else {
index 89cb97dfeb5d30dafdb7fd460af3965920569677..868b4d46bda670645ae6d44ce8f43c530b6391aa 100644 (file)
@@ -115,7 +115,7 @@ impl SirenDecoder {
 
         for i in 1..NUM_REGIONS {
             let diff                    = br.read_cb(&self.diff_cb[i - 1])?;
-            self.pow_index[i] = (self.pow_index[i - 1] + i32::from(diff)).max(-24).min(39);
+            self.pow_index[i] = (self.pow_index[i - 1] + i32::from(diff)).clamp(-24, 39);
         }
         for i in 0..NUM_REGIONS {
             self.region_quant[i]        = self.quant_tab[(self.pow_index[i] + 24) as usize];
@@ -132,7 +132,7 @@ impl SirenDecoder {
         while delta > 0 {
             let mut bitpool = 0;
             for reg in 0..NUM_REGIONS {
-                let cat = ((delta + offset - self.pow_index[reg]) >> 1).max(0).min(7) as usize;
+                let cat = ((delta + offset - self.pow_index[reg]) >> 1).clamp(0, 7) as usize;
                 //self.power_cat[reg] = cat;
                 bitpool += CATEGORY_BITS[cat];
             }
@@ -146,7 +146,7 @@ impl SirenDecoder {
         let mut max_rate_cat = [0; NUM_REGIONS];
         let mut min_rate_cat = [0; NUM_REGIONS];
         for reg in 0..NUM_REGIONS {
-            let cat = ((offset - self.pow_index[reg]) >> 1).max(0).min(7) as usize;
+            let cat = ((offset - self.pow_index[reg]) >> 1).clamp(0, 7) as usize;
             max_rate_cat[reg] = cat;
             min_rate_cat[reg] = cat;
             self.power_cat[reg] = cat;
index 2b44a2e026916f3a10a613b79fc11c6da17b099c..b6de0bbb3a112625d075474b994d2861064887e4 100644 (file)
@@ -63,8 +63,8 @@ fn deblock_hor(buf: &mut [u8], stride: usize, off: usize, clip_tab: &[i16; 64])
         let diff = (3 * (p1 - q1) + 8 * (q0 - p0)) >> 4;
         if (diff != 0) && (diff > -32) && (diff < 32) {
             let delta = clip_tab[(diff + 32) as usize];
-            buf[off - 1 * stride + x] = (p0 + delta).max(0).min(255) as u8;
-            buf[off + 0 * stride + x] = (q0 - delta).max(0).min(255) as u8;
+            buf[off - 1 * stride + x] = (p0 + delta).clamp(0, 255) as u8;
+            buf[off + 0 * stride + x] = (q0 - delta).clamp(0, 255) as u8;
         }
     }
 }
@@ -79,8 +79,8 @@ fn deblock_ver(buf: &mut [u8], stride: usize, off: usize, clip_tab: &[i16; 64])
         let diff = (3 * (p1 - q1) + 8 * (q0 - p0)) >> 4;
         if (diff != 0) && (diff > -32) && (diff < 32) {
             let delta = clip_tab[(diff + 32) as usize];
-            buf[off - 1 + y * stride] = (p0 + delta).max(0).min(255) as u8;
-            buf[off     + y * stride] = (q0 - delta).max(0).min(255) as u8;
+            buf[off - 1 + y * stride] = (p0 + delta).clamp(0, 255) as u8;
+            buf[off     + y * stride] = (q0 - delta).clamp(0, 255) as u8;
         }
     }
 }
@@ -342,8 +342,7 @@ impl<'a> VivoBR<'a> {
                     } else {
                         level = (level * q) - q_add;
                     }
-                    if level < -2048 { level = -2048; }
-                    if level >  2047 { level =  2047; }
+                    level = level.clamp(-2048, 2047);
                 }
             }
             idx += run;
@@ -653,7 +652,7 @@ impl NADecoder for VivoDecoder {
     fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
         let src = pkt.get_buffer();
 
-        if src.len() == 0 {
+        if src.is_empty() {
             let buftype;
             let ftype;
             if self.lastframe.is_none() {
index d5d186140e1b7d38eea03e4148ae00d757bda730..c718cb72ece63329d2c0d99fd5dd91fd68e5ba44 100644 (file)
@@ -217,9 +217,7 @@ impl<'a> VivoDemuxer<'a> {
                     };
                 },
                 b"Duration" => {
-                    self.duration = if let Ok(val) = valstr.parse() {
-                            val
-                        } else { 0 };
+                    self.duration = valstr.parse().unwrap_or_default();
                 },
 /*                b"TimeUnitNumerator" => {
                     self.v_num = if let Ok(val) = valstr.parse() {