From 3687b8b3f7be0754b34c3688b5bf8f788f0864b0 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Fri, 8 Nov 2024 20:14:36 +0100 Subject: [PATCH] nihav_rad: fix or update clippy warnings --- nihav-rad/src/codecs/bink2.rs | 304 +++++++++++++------------ nihav-rad/src/codecs/binkaud.rs | 15 +- nihav-rad/src/codecs/binkauddata.rs | 8 +- nihav-rad/src/codecs/binkvid.rs | 59 +++-- nihav-rad/src/codecs/binkviddata.rs | 23 +- nihav-rad/src/codecs/binkvidenc.rs | 1 - nihav-rad/src/codecs/binkvidenc/dsp.rs | 1 + nihav-rad/src/codecs/binkvidenc/mc.rs | 1 + nihav-rad/src/codecs/mod.rs | 1 + nihav-rad/src/codecs/smacker.rs | 40 ++-- nihav-rad/src/demuxers/smacker.rs | 11 +- nihav-rad/src/lib.rs | 11 - 12 files changed, 243 insertions(+), 232 deletions(-) diff --git a/nihav-rad/src/codecs/bink2.rs b/nihav-rad/src/codecs/bink2.rs index a42b3d6..0dd66ef 100644 --- a/nihav-rad/src/codecs/bink2.rs +++ b/nihav-rad/src/codecs/bink2.rs @@ -153,6 +153,7 @@ macro_rules! avg_tree { #[allow(clippy::erasing_op)] impl Bink2DSP { + #[allow(clippy::identity_op)] fn calc_dc(src: &[u8], stride: usize) -> i32 { let mut sums = [0u16; 8]; for i in 0..8 { @@ -180,16 +181,24 @@ impl Bink2DSP { { let dout = &mut dst[off..]; for (row, (b0, b1)) in dout.chunks_mut(stride).zip(blk[0].chunks(8).zip(blk[1].chunks(8))) { - for i in 0..8 { row[i + 0] = clip8(b0[i]); } - for i in 0..8 { row[i + 8] = clip8(b1[i]); } + for (dst, &c) in row[..8].iter_mut().zip(b0.iter()) { + *dst = clip8(c); + } + for (dst, &c) in row[8..16].iter_mut().zip(b1.iter()) { + *dst = clip8(c); + } } } off += stride * 8; { let dout = &mut dst[off..]; for (row, (b2, b3)) in dout.chunks_mut(stride).zip(blk[2].chunks(8).zip(blk[3].chunks(8))) { - for i in 0..8 { row[i + 0] = clip8(b2[i]); } - for i in 0..8 { row[i + 8] = clip8(b3[i]); } + for (dst, &c) in row[..8].iter_mut().zip(b2.iter()) { + *dst = clip8(c); + } + for (dst, &c) in row[8..16].iter_mut().zip(b3.iter()) { + *dst = clip8(c); + } } } } @@ -201,16 +210,24 @@ impl Bink2DSP { { let dout = &mut dst[off..]; for (row, (b0, b1)) in dout.chunks_mut(stride).zip(blk[0].chunks(8).zip(blk[1].chunks(8))) { - for i in 0..8 { row[i + 0] = clip8((row[i + 0] as i32) + b0[i]); } - for i in 0..8 { row[i + 8] = clip8((row[i + 8] as i32) + b1[i]); } + for (dst, &add) in row[..8].iter_mut().zip(b0.iter()) { + *dst = clip8(i32::from(*dst) + add); + } + for (dst, &add) in row[8..16].iter_mut().zip(b1.iter()) { + *dst = clip8(i32::from(*dst) + add); + } } } off += stride * 8; { let dout = &mut dst[off..]; for (row, (b2, b3)) in dout.chunks_mut(stride).zip(blk[2].chunks(8).zip(blk[3].chunks(8))) { - for i in 0..8 { row[i + 0] = clip8((row[i + 0] as i32) + b2[i]); } - for i in 0..8 { row[i + 8] = clip8((row[i + 8] as i32) + b3[i]); } + for (dst, &add) in row[..8].iter_mut().zip(b2.iter()) { + *dst = clip8(i32::from(*dst) + add); + } + for (dst, &add) in row[8..16].iter_mut().zip(b3.iter()) { + *dst = clip8(i32::from(*dst) + add); + } } } } @@ -222,16 +239,24 @@ impl Bink2DSP { { let dout = &mut dst[off..]; for (row, (b0, b1)) in dout.chunks_mut(stride).zip(blk[0].chunks(8).zip(blk[1].chunks(8))) { - for i in 0..8 { row[i + 0] = clip8((b0[i] as i32) - 512); } - for i in 0..8 { row[i + 8] = clip8((b1[i] as i32) - 512); } + for (dst, &c) in row[..8].iter_mut().zip(b0.iter()) { + *dst = clip8((c as i32) - 512); + } + for (dst, &c) in row[8..16].iter_mut().zip(b1.iter()) { + *dst = clip8((c as i32) - 512); + } } } off += stride * 8; { let dout = &mut dst[off..]; for (row, (b2, b3)) in dout.chunks_mut(stride).zip(blk[2].chunks(8).zip(blk[3].chunks(8))) { - for i in 0..8 { row[i + 0] = clip8((b2[i] as i32) - 512); } - for i in 0..8 { row[i + 8] = clip8((b3[i] as i32) - 512); } + for (dst, &c) in row[..8].iter_mut().zip(b2.iter()) { + *dst = clip8((c as i32) - 512); + } + for (dst, &c) in row[8..16].iter_mut().zip(b3.iter()) { + *dst = clip8((c as i32) - 512); + } } } } @@ -243,16 +268,24 @@ impl Bink2DSP { { let dout = &mut dst[off..]; for (row, (b0, b1)) in dout.chunks_mut(stride).zip(blk[0].chunks(8).zip(blk[1].chunks(8))) { - for i in 0..8 { row[i + 0] = clip8((row[i + 0] as i32) + (b0[i] as i32) - 512); } - for i in 0..8 { row[i + 8] = clip8((row[i + 8] as i32) + (b1[i] as i32) - 512); } + for (dst, &add) in row[..8].iter_mut().zip(b0.iter()) { + *dst = clip8(i32::from(*dst) + (add as i32) - 512); + } + for (dst, &add) in row[8..16].iter_mut().zip(b1.iter()) { + *dst = clip8(i32::from(*dst) + (add as i32) - 512); + } } } off += stride * 8; { let dout = &mut dst[off..]; for (row, (b2, b3)) in dout.chunks_mut(stride).zip(blk[2].chunks(8).zip(blk[3].chunks(8))) { - for i in 0..8 { row[i + 0] = clip8((row[i + 0] as i32) + (b2[i] as i32) - 512); } - for i in 0..8 { row[i + 8] = clip8((row[i + 8] as i32) + (b3[i] as i32) - 512); } + for (dst, &add) in row[..8].iter_mut().zip(b2.iter()) { + *dst = clip8(i32::from(*dst) + (add as i32) - 512); + } + for (dst, &add) in row[8..16].iter_mut().zip(b3.iter()) { + *dst = clip8(i32::from(*dst) + (add as i32) - 512); + } } } } @@ -284,8 +317,8 @@ impl Bink2DSP { }, 1 => { for out in dst.chunks_mut(stride).take(16) { - for i in 0..16 { - out[i] = clip8(luma_filter!(ppix, poff + i, 1)); + for (i, el) in out[..16].iter_mut().enumerate() { + *el = clip8(luma_filter!(ppix, poff + i, 1)); } poff += pstride; } @@ -353,6 +386,7 @@ impl Bink2DSP { } } +#[allow(clippy::collapsible_else_if)] fn mid_pred(a: T, b: T, c: T) -> T { if a < b { if b < c { @@ -391,14 +425,12 @@ impl QuantInfo { let is_left = pos < 2; if is_top { if is_left { 16 } else { self.quants[self.qpos + pos - 2] } + } else if is_left { + self.quants[self.pqpos + pos] } else { - if is_left { - self.quants[self.pqpos + pos] - } else { - mid_pred(self.quants[self.pqpos + pos - 2], - self.quants[self.pqpos + pos], - self.quants[self.qpos + pos - 2]) - } + mid_pred(self.quants[self.pqpos + pos - 2], + self.quants[self.pqpos + pos], + self.quants[self.qpos + pos - 2]) } } fn set_quant(&mut self, pos: usize, q: u8) { @@ -482,11 +514,14 @@ fn dc_pred(a: i32, b: i32, c: i32) -> i32 { (a.max(b).max(c)).min((a.min(b).min(c)).max(b - a + c)) } +#[allow(clippy::identity_op)] impl DCInfo for YDCInfo { fn decode_dcs(&mut self, br: &mut BitReader, q: u8) -> DecoderResult { decode_dcs(br, &mut self.dc_buf, q) } #[allow(non_snake_case)] + #[allow(clippy::collapsible_else_if)] + #[allow(clippy::needless_late_init)] fn predict(&mut self, bx: usize, is_top: bool, is_left: bool, min_dc: i32, max_dc: i32) { let a0; let a1; let a2; let a3; let a4; let a5; let a6; let a7; let a8; let a9; let aA; let aB; let aC; let aD; let aE; let aF; @@ -603,29 +638,27 @@ impl DCInfo for YDCInfo { } #[allow(non_snake_case)] fn predict_inter(&mut self, min_dc: i32, max_dc: i32) { - let a0; let a1; let a2; let a3; let a4; let a5; let a6; let a7; - let a8; let a9; let aA; let aB; let aC; let aD; let aE; let aF; let dst = &mut self.dcs; let dcs = &self.dc_buf; - a0 = (dcs[ 0] + 0).max(min_dc).min(max_dc); - a1 = (dcs[ 1] + a0).max(min_dc).min(max_dc); - a2 = (dcs[ 2] + dc_pred2(a0, a1)).max(min_dc).min(max_dc); - a3 = (dcs[ 3] + dc_pred(a0, a1, a2)).max(min_dc).min(max_dc); - - a4 = (dcs[ 4] + dc_pred2(a1, a3)).max(min_dc).min(max_dc); - a5 = (dcs[ 5] + a4).max(min_dc).min(max_dc); - a6 = (dcs[ 6] + dc_pred(a1, a3, a4)).max(min_dc).min(max_dc); - a7 = (dcs[ 7] + dc_pred(a4, a5, a6)).max(min_dc).min(max_dc); - - a8 = (dcs[ 8] + dc_pred2(a2, a3)).max(min_dc).min(max_dc); - a9 = (dcs[ 9] + dc_pred(a2, a3, a8)).max(min_dc).min(max_dc); - aA = (dcs[10] + dc_pred2(a8, a9)).max(min_dc).min(max_dc); - aB = (dcs[11] + dc_pred(a8, a9, aA)).max(min_dc).min(max_dc); - - aC = (dcs[12] + dc_pred(a3, a6, a9)).max(min_dc).min(max_dc); - aD = (dcs[13] + dc_pred(a6, a7, aC)).max(min_dc).min(max_dc); - aE = (dcs[14] + dc_pred(a9, aB, aC)).max(min_dc).min(max_dc); - aF = (dcs[15] + dc_pred(aC, aD, aE)).max(min_dc).min(max_dc); + let a0 = (dcs[ 0] + 0).max(min_dc).min(max_dc); + let a1 = (dcs[ 1] + a0).max(min_dc).min(max_dc); + let a2 = (dcs[ 2] + dc_pred2(a0, a1)).max(min_dc).min(max_dc); + let a3 = (dcs[ 3] + dc_pred(a0, a1, a2)).max(min_dc).min(max_dc); + + let a4 = (dcs[ 4] + dc_pred2(a1, a3)).max(min_dc).min(max_dc); + let a5 = (dcs[ 5] + a4).max(min_dc).min(max_dc); + let a6 = (dcs[ 6] + dc_pred(a1, a3, a4)).max(min_dc).min(max_dc); + let a7 = (dcs[ 7] + dc_pred(a4, a5, a6)).max(min_dc).min(max_dc); + + let a8 = (dcs[ 8] + dc_pred2(a2, a3)).max(min_dc).min(max_dc); + let a9 = (dcs[ 9] + dc_pred(a2, a3, a8)).max(min_dc).min(max_dc); + let aA = (dcs[10] + dc_pred2(a8, a9)).max(min_dc).min(max_dc); + let aB = (dcs[11] + dc_pred(a8, a9, aA)).max(min_dc).min(max_dc); + + let aC = (dcs[12] + dc_pred(a3, a6, a9)).max(min_dc).min(max_dc); + let aD = (dcs[13] + dc_pred(a6, a7, aC)).max(min_dc).min(max_dc); + let aE = (dcs[14] + dc_pred(a9, aB, aC)).max(min_dc).min(max_dc); + let aF = (dcs[15] + dc_pred(aC, aD, aE)).max(min_dc).min(max_dc); dst[ 0] = a0; dst[ 1] = a1; @@ -686,16 +719,15 @@ impl DCInfo for CDCInfo { new_dc[0] = a2; new_dc[1] = a3; } + #[allow(clippy::identity_op)] fn predict_inter(&mut self, min_dc: i32, max_dc: i32) { let dst = &mut self.dcs; let dcs = &self.dc_buf; - let a0; let a1; let a2; let a3; - - a0 = (dcs[ 0] + 0).max(min_dc).min(max_dc); - a1 = (dcs[ 1] + a0).max(min_dc).min(max_dc); - a2 = (dcs[ 2] + dc_pred2(a0, a1)).max(min_dc).min(max_dc); - a3 = (dcs[ 3] + dc_pred(a0, a1, a2)).max(min_dc).min(max_dc); + let a0 = (dcs[ 0] + 0).max(min_dc).min(max_dc); + let a1 = (dcs[ 1] + a0).max(min_dc).min(max_dc); + let a2 = (dcs[ 2] + dc_pred2(a0, a1)).max(min_dc).min(max_dc); + let a3 = (dcs[ 3] + dc_pred(a0, a1, a2)).max(min_dc).min(max_dc); dst[0] = a0; dst[1] = a1; @@ -732,6 +764,8 @@ struct MVInfo { prev_off: usize, } +#[allow(clippy::collapsible_else_if)] +#[allow(clippy::identity_op)] impl MVInfo { fn resize(&mut self, bw: usize) { self.stride = bw * 4; @@ -846,12 +880,12 @@ impl MVInfo { } let mut mv_c: [i16; 4] = [0; 4]; if bits > 0 { - for i in 0..4 { - mv_c[i] = br.read(bits)? as i16; + for mv in mv_c.iter_mut() { + *mv = br.read(bits)? as i16; } - for i in 0..4 { - if (mv_c[i] != 0) && br.read_bool()? { - mv_c[i] = -mv_c[i]; + for mv in mv_c.iter_mut() { + if (*mv != 0) && br.read_bool()? { + *mv = -*mv; } } } @@ -1028,6 +1062,8 @@ impl Bink2Decoder { } #[allow(clippy::cognitive_complexity)] + #[allow(clippy::identity_op)] + #[allow(clippy::needless_range_loop)] fn decode_frame_new(&mut self, br: &mut BitReader, buf: &mut NAVideoBuffer, is_intra: bool) -> DecoderResult<()> { let (stride_y, stride_u, stride_v, stride_a) = (buf.get_stride(0), buf.get_stride(1), buf.get_stride(2), buf.get_stride(3)); let (mut off_y, mut off_u, mut off_v, mut off_a) = (buf.get_offset(0), buf.get_offset(1), buf.get_offset(2), buf.get_offset(3)); @@ -1042,8 +1078,8 @@ impl Bink2Decoder { let frame_flags = br.read(32)?; let mut offsets: [u32; 7] = [0; 7]; - for i in 0..self.num_slices-1 { - offsets[i] = br.read(32)?; + for offset in offsets[..self.num_slices-1].iter_mut() { + *offset = br.read(32)?; } let mut do_alpha = self.has_alpha; if (frame_flags & 0x80000) != 0 && self.has_alpha { @@ -1144,33 +1180,31 @@ impl Bink2Decoder { let btype; if is_intra { btype = 0; + } else if (blk_state & 0x2000) != 0 { + let val = br.read_code(UintCodeType::LimitedUnary(3, 1))?; + match val { + 0 => { + btype = btype_lru[0]; + }, + 1 => { + btype = btype_lru[1]; + btype_lru[1] = btype_lru[0]; + btype_lru[0] = btype; + }, + 2 => { + btype = btype_lru[3]; + btype_lru[3] = btype_lru[2]; + btype_lru[2] = btype; + }, + 3 => { + btype = btype_lru[2]; + btype_lru[2] = btype_lru[1]; + btype_lru[1] = btype; + }, + _ => unreachable!(), + }; } else { - if (blk_state & 0x2000) != 0 { - let val = br.read_code(UintCodeType::LimitedUnary(3, 1))?; - match val { - 0 => { - btype = btype_lru[0]; - }, - 1 => { - btype = btype_lru[1]; - btype_lru[1] = btype_lru[0]; - btype_lru[0] = btype; - }, - 2 => { - btype = btype_lru[3]; - btype_lru[3] = btype_lru[2]; - btype_lru[2] = btype; - }, - 3 => { - btype = btype_lru[2]; - btype_lru[2] = btype_lru[1]; - btype_lru[1] = btype; - }, - _ => unreachable!(), - }; - } else { - btype = br.read(2)? as u8; - } + btype = br.read(2)? as u8; } if !is_intra { let q = self.qinfo.pred_quant(bx * 2, is_top); @@ -1455,12 +1489,11 @@ fn get_new_quant(br: &mut BitReader, prev_q: u8) -> DecoderResult { } else if code == 4 { code = (br.read(5)? as u8) + 5; } - let ret; - if !br.read_bool()? { - ret = prev_q.checked_add(code); - } else { - ret = prev_q.checked_sub(code); - } + let ret = if !br.read_bool()? { + prev_q.checked_add(code) + } else { + prev_q.checked_sub(code) + }; validate!(ret.is_some()); let val = ret.unwrap(); validate!(val < (BINK2_QUANT_DC.len() as u8)); @@ -1514,6 +1547,7 @@ fn decode_chroma_inter(br: &mut BitReader, codes: &Bink2Codes, prev_cbp: u32, q: Ok(cbp) } +#[allow(clippy::collapsible_if)] fn decode_cbp_luma(br: &mut BitReader, prev_cbp: u32, edge_state: u32) -> DecoderResult { let cnt = (prev_cbp as u16).count_ones() as usize; let (min_count, mask) = if cnt < 8 { (cnt, 0x0000) } else { (16 - cnt, 0xFFFF) }; @@ -1561,28 +1595,21 @@ trait ReadBink2Code { impl<'a> ReadBink2Code for BitReader<'a> { fn read_bink2_code_zero(&mut self) -> DecoderResult { let pfx = self.read_code(UintCodeType::LimitedUnary(12, 0))? as i32; - if pfx > 0 { - let val: i32; - if pfx >= 4 { - let add_bits = self.read((pfx as u8) - 3)? as i32; - val = (1 << (pfx - 3)) + add_bits + 2; - } else { - val = pfx; - } - Ok(val) + if pfx < 4 { + Ok(pfx) } else { - Ok(0) + let add_bits = self.read((pfx as u8) - 3)? as i32; + Ok((1 << (pfx - 3)) + add_bits + 2) } } fn read_bink2_code_nz(&mut self) -> DecoderResult { let pfx = self.read_code(UintCodeType::LimitedUnary(12, 0))? + 1; - let val: i32; - if pfx >= 4 { - let add_bits = self.read((pfx as u8) - 3)? as i32; - val = (1 << (pfx - 3)) + add_bits + 2; - } else { - val = pfx as i32; - } + let val = if pfx >= 4 { + let add_bits = self.read((pfx as u8) - 3)? as i32; + (1 << (pfx - 3)) + add_bits + 2 + } else { + pfx as i32 + }; if self.read_bool()? { Ok(-val) } else { @@ -1595,7 +1622,7 @@ fn decode_acs_4blocks(br: &mut BitReader, codes: &Bink2Codes, dst: &mut [[i32; 6 let cb = if (cbp >> 16) != 0 { &codes.ac_cb1 } else { &codes.ac_cb2 }; let qmat = &quant_mat[(q & 3) as usize]; let shift = q >> 2; - for blk_no in 0..4 { + for (blk_no, block) in dst.iter_mut().enumerate() { if ((cbp >> blk_no) & 1) == 0 { continue; } let mut esc_len = 0; let mut idx = 1; @@ -1604,19 +1631,18 @@ fn decode_acs_4blocks(br: &mut BitReader, codes: &Bink2Codes, dst: &mut [[i32; 6 esc_len -= 1; } else { let sym = br.read_cb(cb)?; - let skip; - if sym == 11 { - skip = br.read(6)? as usize; - } else { - skip = BINK2_AC_RUNS[sym as usize]; - } + let skip = if sym == 11 { + br.read(6)? as usize + } else { + BINK2_AC_RUNS[sym as usize] + }; idx += skip; if idx > 63 { break; } esc_len = if sym == 13 { 6 } else { 0 }; } let level = br.read_bink2_code_nz()?; let pos = BINK2_ZIGZAG[idx]; - dst[blk_no][pos] = (((level * qmat[pos]) << shift) + 0x40) >> 7; + block[pos] = (((level * qmat[pos]) << shift) + 0x40) >> 7; idx += 1; } // set blk info to (dc & 0x1FFF) | (intra ? 0x8000 : 0) | (((ncoded == 0) + (ncoded < 4) + (ncoded < 8)) << 13) @@ -1686,12 +1712,11 @@ fn decode_quant_old(br: &mut BitReader, quant_cb: &Codebook, prev_quant: u8) if diff == 0 { Ok(prev_quant) } else { - let res; - if br.read_bool()? { - res = prev_quant.checked_sub(diff); - } else { - res = prev_quant.checked_add(diff); - } + let res = if br.read_bool()? { + prev_quant.checked_sub(diff) + } else { + prev_quant.checked_add(diff) + }; validate!(res.is_some()); let q = res.unwrap(); validate!(q < 16); @@ -1746,15 +1771,14 @@ fn decode_cbp_luma_old(br: &mut BitReader, prev_cbp: u32) -> DecoderResult } fn decode_cbp_chroma_old(br: &mut BitReader, prev_cbp: u32) -> DecoderResult { - let low; - if !br.read_bool()? { - low = br.read(4)?; - } else { - if br.read_bool()? { - return Ok(prev_cbp); - } - low = prev_cbp & 0xF; - } + let low = if !br.read_bool()? { + br.read(4)? + } else { + if br.read_bool()? { + return Ok(prev_cbp); + } + prev_cbp & 0xF + }; let mut high; if low.count_ones() == 0 { return Ok(low); @@ -1818,7 +1842,7 @@ fn decode_dcs_old(br: &mut BitReader, dcs: &mut [i32], q: u8, read_bias: bool) - fn decode_acs_4blocks_old(br: &mut BitReader, codes: &Bink2Codes, dst: &mut [[f32; 64]; 4], quant_mat: &[f32; 64], q: u8, cbp: u32, scan: &[usize; 64]) -> DecoderResult<()> { let quant = BINK2_OLD_QUANTS[q as usize]; - for blk_no in 0..4 { + for (blk_no, block) in dst.iter_mut().enumerate() { if ((cbp >> blk_no) & 1) == 0 { continue; } let val_cb = if ((cbp >> (16 + blk_no)) & 1) != 0 { &codes.val_cb2 } else { &codes.val_cb1 }; let skip_cb = if ((cbp >> (16 + blk_no)) & 1) != 0 { &codes.skip_cb2 } else { &codes.skip_cb1 }; @@ -1838,7 +1862,7 @@ fn decode_acs_4blocks_old(br: &mut BitReader, codes: &Bink2Codes, dst: &mut [[f3 level = -level; } let pos = scan[idx]; - dst[blk_no][pos] = (level as f32) * quant_mat[(pos & 7) * 8 + (pos >> 3)] * quant; + block[pos] = (level as f32) * quant_mat[(pos & 7) * 8 + (pos >> 3)] * quant; } idx += 1; if idx >= 64 { break; } @@ -1846,12 +1870,11 @@ fn decode_acs_4blocks_old(br: &mut BitReader, codes: &Bink2Codes, dst: &mut [[f3 esc_len -= 1; } else { let sym = br.read_cb(skip_cb)?; - let skip; - if sym == 11 { - skip = br.read(6)? as usize; - } else { - skip = BINK2_AC_RUNS[sym as usize]; - } + let skip = if sym == 11 { + br.read(6)? as usize + } else { + BINK2_AC_RUNS[sym as usize] + }; idx += skip; if idx > 63 { break; } esc_len = if sym == 13 { 6 } else { 0 }; @@ -1903,9 +1926,8 @@ impl NADecoder for Bink2Decoder { } self.slice_h[self.num_slices - 1] = height_a >> 5; - let fmt; let aplane = if self.has_alpha { Some(NAPixelChromaton::new(0, 0, false, 8, 0, 3, 1)) } else { None }; - fmt = NAPixelFormaton::new(ColorModel::YUV(YUVSubmodel::YUVJ), + let fmt = NAPixelFormaton::new(ColorModel::YUV(YUVSubmodel::YUVJ), Some(NAPixelChromaton::new(0, 0, false, 8, 0, 0, 1)), Some(NAPixelChromaton::new(1, 1, false, 8, 0, 1, 1)), Some(NAPixelChromaton::new(1, 1, false, 8, 0, 2, 1)), diff --git a/nihav-rad/src/codecs/binkaud.rs b/nihav-rad/src/codecs/binkaud.rs index b56b6d4..3880f45 100644 --- a/nihav-rad/src/codecs/binkaud.rs +++ b/nihav-rad/src/codecs/binkaud.rs @@ -87,9 +87,9 @@ impl BinkAudioDecoder { self.coeffs[1] = read_bink_float(br)? * self.scale; } let mut quants: [f32; MAX_BANDS] = [0.0; MAX_BANDS]; - for i in 0..self.num_bands { + for quant in quants[..self.num_bands].iter_mut() { let idx = br.read(8)? as usize; - quants[i] = self.quants[idx.min(self.quants.len() - 1)] * self.scale; + *quant = self.quants[idx.min(self.quants.len() - 1)] * self.scale; } let mut idx = 2; let mut band_idx = 0; @@ -97,13 +97,11 @@ impl BinkAudioDecoder { while idx < self.len { let width = if self.version_b { 16 + } else if br.read_bool()? { + let idx = br.read(4)? as usize; + RUN_TAB[idx] * 8 } else { - if br.read_bool()? { - let idx = br.read(4)? as usize; - RUN_TAB[idx] * 8 - } else { - 8 - } + 8 }; let end = (idx + width).min(self.len); let bits = br.read(4)? as u8; @@ -125,6 +123,7 @@ impl BinkAudioDecoder { } Ok(()) } + #[allow(clippy::identity_op)] #[allow(clippy::transmute_ptr_to_ptr)] fn output(&mut self, dst: &mut [f32], off0: usize, off1: usize, chno: usize) { match self.transform { diff --git a/nihav-rad/src/codecs/binkauddata.rs b/nihav-rad/src/codecs/binkauddata.rs index 1cdce60..3e61a74 100644 --- a/nihav-rad/src/codecs/binkauddata.rs +++ b/nihav-rad/src/codecs/binkauddata.rs @@ -17,16 +17,16 @@ pub fn init_bands(srate: usize, len: usize, num_bands: &mut usize, bands: &mut [ *num_bands += 1; } bands[0] = 2; - for i in 1..*num_bands { - bands[i] = (CRITICAL_FREQS[i - 1] * len / srate) & !1; + for (band, &freq) in bands[1..*num_bands].iter_mut().zip(CRITICAL_FREQS.iter()) { + *band = (freq * len / srate) & !1; } bands[*num_bands] = len; } pub fn get_quants_table() -> [f32; 96] { let mut quants: [f32; 96] = [0.0; 96]; - for i in 0..quants.len() { - quants[i] = ((i as f32) * 0.0664 / consts::LOG10_E).exp(); + for (i, quant) in quants.iter_mut().enumerate() { + *quant = ((i as f32) * 0.0664 / consts::LOG10_E).exp(); } quants } diff --git a/nihav-rad/src/codecs/binkvid.rs b/nihav-rad/src/codecs/binkvid.rs index f41d3b7..ef9aa60 100644 --- a/nihav-rad/src/codecs/binkvid.rs +++ b/nihav-rad/src/codecs/binkvid.rs @@ -24,6 +24,7 @@ struct Tree { } impl Tree { + #[allow(clippy::collapsible_else_if)] fn read_desc(&mut self, br: &mut BitReader) -> DecoderResult<()> { self.id = br.read(4)? as usize; if self.id == 0 { @@ -37,8 +38,8 @@ impl Tree { present[self.syms[i] as usize] = true; } let mut idx = len + 1; - for i in 0..16 { - if present[i] { continue; } + for (i, &present) in present.iter().enumerate() { + if present { continue; } self.syms[idx] = i as u8; idx += 1; } @@ -476,6 +477,7 @@ fn calc_len(size: usize) -> u8 { (32 - ((size + 511) as u32).leading_zeros()) as u8 } +#[allow(clippy::too_many_arguments)] impl BinkDecoder { fn new() -> Self { Self::default() @@ -561,25 +563,22 @@ impl BinkDecoder { Ok(()) } - fn put_block(&self, block: &[u8; 64], dst: &mut [u8], mut off: usize, stride: usize, scaled: bool) { + fn put_block(&self, block: &[u8; 64], dst: &mut [u8], off: usize, stride: usize, scaled: bool) { if !scaled { - for src in block.chunks_exact(8) { - let out = &mut dst[off..][..8]; - out.copy_from_slice(src); - off += stride; + for (src, dline) in block.chunks_exact(8).zip(dst[off..].chunks_mut(stride)) { + dline[..8].copy_from_slice(src); } } else { - for src in block.chunks_exact(8) { - for i in 0..8 { - dst[off + i * 2 + 0] = src[i]; - dst[off + i * 2 + 1] = src[i]; + for (src, dlines) in block.chunks_exact(8).zip(dst[off..].chunks_mut(stride * 2)) { + let (dline0, dline1) = dlines.split_at_mut(stride); + for (pair, &pix) in dline0.chunks_exact_mut(2).zip(src[..8].iter()) { + pair[0] = pix; + pair[1] = pix; } - off += stride; - for i in 0..8 { - dst[off + i * 2 + 0] = src[i]; - dst[off + i * 2 + 1] = src[i]; + for (pair, &pix) in dline1.chunks_exact_mut(2).zip(src[..8].iter()) { + pair[0] = pix; + pair[1] = pix; } - off += stride; } } } @@ -1024,9 +1023,8 @@ fn read_residue(br: &mut BitReader, block: &mut [i32; 64], mut masks_count: usiz let mut mask = 1 << br.read(3)?; while mask > 0 { - for i in 0..nz_coef_count { + for &idx in nz_coef_idx[..nz_coef_count].iter() { if !br.read_bool()? { continue; } - let idx = nz_coef_idx[i]; if block[idx] < 0 { block[idx] -= mask; } else { @@ -1127,19 +1125,18 @@ impl NADecoder for BinkDecoder { if self.has_alpha && self.is_gray { return Err(DecoderError::NotImplemented); } let aplane = if self.has_alpha { Some(NAPixelChromaton::new(0, 0, false, 8, 0, 3, 1)) } else { None }; - let fmt; - if !self.is_gray { - fmt = NAPixelFormaton::new(ColorModel::YUV(YUVSubmodel::YUVJ), - Some(NAPixelChromaton::new(0, 0, false, 8, 0, 0, 1)), - Some(NAPixelChromaton::new(1, 1, false, 8, 0, 1, 1)), - Some(NAPixelChromaton::new(1, 1, false, 8, 0, 2, 1)), - aplane, None, - 0, if self.has_alpha { 4 } else { 3 } ); - } else { - fmt = NAPixelFormaton::new(ColorModel::YUV(YUVSubmodel::YUVJ), - Some(NAPixelChromaton::new(0, 0, false, 8, 0, 0, 1)), - None, None, None, None, 0, 1); - } + let fmt = if !self.is_gray { + NAPixelFormaton::new(ColorModel::YUV(YUVSubmodel::YUVJ), + Some(NAPixelChromaton::new(0, 0, false, 8, 0, 0, 1)), + Some(NAPixelChromaton::new(1, 1, false, 8, 0, 1, 1)), + Some(NAPixelChromaton::new(1, 1, false, 8, 0, 2, 1)), + aplane, None, + 0, if self.has_alpha { 4 } else { 3 } ) + } else { + NAPixelFormaton::new(ColorModel::YUV(YUVSubmodel::YUVJ), + Some(NAPixelChromaton::new(0, 0, false, 8, 0, 0, 1)), + None, None, None, None, 0, 1) + }; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, false, fmt)); self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); diff --git a/nihav-rad/src/codecs/binkviddata.rs b/nihav-rad/src/codecs/binkviddata.rs index dee0b7a..c41147d 100644 --- a/nihav-rad/src/codecs/binkviddata.rs +++ b/nihav-rad/src/codecs/binkviddata.rs @@ -11,23 +11,26 @@ impl QuantMats { let mut mod_mat: [f32; 64] = [0.0; 64]; let base = consts::PI / 16.0; - for i in 0..64 { inv_scan[BINK_SCAN[i]] = i; } + for (i, &idx) in BINK_SCAN.iter().enumerate() { inv_scan[idx] = i; } - for j in 0..8 { + for (j, m_row) in mod_mat.chunks_exact_mut(8).enumerate() { let j_scale = if (j != 0) && (j != 4) { (base * (j as f32)).cos() * consts::SQRT_2 } else { 1.0 }; - for i in 0..8 { + for (i, mm) in m_row.iter_mut().enumerate() { let i_scale = if (i != 0) && (i != 4) { (base * (i as f32)).cos() * consts::SQRT_2 } else { 1.0 }; - mod_mat[i + j * 8] = i_scale * j_scale; + *mm = i_scale * j_scale; } } - for q in 0..16 { - let (num, den) = BINKB_REF_QUANTS[q]; + for ((iqmat, pqmat), &(num, den)) in self.intra_qmat.iter_mut() + .zip(self.inter_qmat.iter_mut()).zip(BINKB_REF_QUANTS.iter()) { let quant = (num as f32) * ((1 << 12) as f32) / (den as f32); - for c in 0..64 { - let idx = inv_scan[c]; - self.intra_qmat[q][idx] = ((BINKB_REF_INTRA_Q[c] as f32) * mod_mat[c] * quant) as i32; - self.inter_qmat[q][idx] = ((BINKB_REF_INTER_Q[c] as f32) * mod_mat[c] * quant) as i32; + for (&refq, (&idx, &modm)) in BINKB_REF_INTRA_Q.iter() + .zip(inv_scan.iter().zip(mod_mat.iter())) { + iqmat[idx] = ((refq as f32) * modm * quant) as i32; + } + for (&refq, (&idx, &modm)) in BINKB_REF_INTER_Q.iter() + .zip(inv_scan.iter().zip(mod_mat.iter())) { + pqmat[idx] = ((refq as f32) * modm * quant) as i32; } } } diff --git a/nihav-rad/src/codecs/binkvidenc.rs b/nihav-rad/src/codecs/binkvidenc.rs index c84b115..b350bd9 100644 --- a/nihav-rad/src/codecs/binkvidenc.rs +++ b/nihav-rad/src/codecs/binkvidenc.rs @@ -39,7 +39,6 @@ impl std::string::ToString for DoublingMode { } } -#[allow(dead_code)] #[derive(Clone,Copy,Debug,PartialEq)] enum BlockMode { Skip, diff --git a/nihav-rad/src/codecs/binkvidenc/dsp.rs b/nihav-rad/src/codecs/binkvidenc/dsp.rs index e780909..195388f 100644 --- a/nihav-rad/src/codecs/binkvidenc/dsp.rs +++ b/nihav-rad/src/codecs/binkvidenc/dsp.rs @@ -275,6 +275,7 @@ impl DSP { best_dist } + #[allow(clippy::too_many_arguments)] pub fn try_dct_inter(&mut self, ref_blk: &[u8; 64], cur_blk: &[u8; 64], tokens: &mut BlockTokens, tmp_tok: &mut BlockTokens, is_b: bool, rc: &RateControl, mut best_dist: u32) -> u32 { let mv_x = tokens.xoff[0]; let mv_y = tokens.yoff[0]; diff --git a/nihav-rad/src/codecs/binkvidenc/mc.rs b/nihav-rad/src/codecs/binkvidenc/mc.rs index ebaa2b4..31853ab 100644 --- a/nihav-rad/src/codecs/binkvidenc/mc.rs +++ b/nihav-rad/src/codecs/binkvidenc/mc.rs @@ -21,6 +21,7 @@ fn check_mv(x: usize, y: usize, width: usize, height: usize, mv: MV) -> bool { ypos >= 0 && (ypos + 8 <= (height as isize)) } +#[allow(clippy::too_many_arguments)] pub fn mv_search(src: &[u8], stride: usize, width: usize, height: usize, x: usize, y: usize, skip_diff: u32, ref_blk: &[u8; 64], tmp: &mut [u8; 64]) -> (MV, u32) { diff --git a/nihav-rad/src/codecs/mod.rs b/nihav-rad/src/codecs/mod.rs index 92c547a..70bb146 100644 --- a/nihav-rad/src/codecs/mod.rs +++ b/nihav-rad/src/codecs/mod.rs @@ -20,6 +20,7 @@ mod binkvid; #[cfg(any(feature="decoder_binkvid", feature="encoder_binkvid"))] mod binkviddata; #[cfg(feature="decoder_bink2")] +#[allow(clippy::too_many_arguments)] mod bink2; const RAD_CODECS: &[DecoderInfo] = &[ diff --git a/nihav-rad/src/codecs/smacker.rs b/nihav-rad/src/codecs/smacker.rs index 7ecd443..380f96c 100644 --- a/nihav-rad/src/codecs/smacker.rs +++ b/nihav-rad/src/codecs/smacker.rs @@ -138,8 +138,8 @@ impl SmackerTree16 { tree_hi.decode(br)?; let mut esc: [u32; 3] = [0; 3]; - for i in 0..esc.len() { - esc[i] = br.read(16)?; + for esc in esc.iter_mut() { + *esc = br.read(16)?; } let nsyms = (((size + 3) >> 2) + 4) as usize; @@ -249,6 +249,7 @@ impl SmackerVideoDecoder { let by = blk_no / self.bw; bx * 4 + by * 4 * self.stride } + #[allow(clippy::identity_op)] fn decode_frame(&mut self, br: &mut BitReader) -> DecoderResult { let mut is_intra = true; let blocks = self.bw * self.bh; @@ -282,12 +283,11 @@ impl SmackerVideoDecoder { } }, 1 => { // full - let mode; - if !self.is_ver4 || !br.read_bool()? { - mode = 0; - } else { - mode = 1 + br.read(1)?; - } + let mode = if !self.is_ver4 || !br.read_bool()? { + 0 + } else { + 1 + br.read(1)? + }; for i in 0..run { let mut doff = self.block_pos(block + i); match mode { @@ -511,7 +511,7 @@ impl NADecoder for SmackerAudioDecoder { Err(DecoderError::InvalidData) } } - #[allow(clippy::manual_memcpy)] + #[allow(clippy::identity_op)] fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let info = pkt.get_stream().get_info(); if let NACodecTypeInfo::Audio(_) = info.get_properties() { @@ -536,8 +536,8 @@ impl NADecoder for SmackerAudioDecoder { samples = unp_size / 2 / nch; let mask = if stereo { 1 } else { 0 }; let mut trees: [SmackerTree8; 4] = [SmackerTree8::new(), SmackerTree8::new(), SmackerTree8::new(), SmackerTree8::new()]; - for i in 0..nch*2 { - trees[i].decode(&mut br)?; + for tree in trees[..nch*2].iter_mut() { + tree.decode(&mut br)?; } let mut pred: [i16; 2] = [0; 2]; for i in 0..nch { @@ -549,16 +549,14 @@ impl NADecoder for SmackerAudioDecoder { abuf = alloc_audio_buffer(self.ainfo, samples, self.chmap.clone())?; let mut adata = abuf.get_abuf_i16().unwrap(); let dst = adata.get_data_mut().unwrap(); - for ch in 0..nch { - dst[ch] = pred[ch]; - } - for i in nch..(unp_size >> 1) { + dst[..nch].copy_from_slice(&pred[..nch]); + for (i, out) in dst[nch..(unp_size >> 1)].iter_mut().enumerate() { let idx = i & mask; let lo = br.read_tree8(&trees[idx * 2 + 0])? as u16; let hi = br.read_tree8(&trees[idx * 2 + 1])? as u16; let diff = (lo | (hi << 8)) as i16; pred[idx] = pred[idx].wrapping_add(diff); - dst[i] = pred[idx]; + *out = pred[idx]; } } else { samples = unp_size / nch; @@ -572,21 +570,21 @@ impl NADecoder for SmackerAudioDecoder { let pred0 = br.read(8)? as u8; let pred1 = br.read(8)? as u8; let mut pred: [u8; 2] = [ pred1, pred0 ]; - for ch in 0..2 { dst[ch] = pred[ch]; } - for i in 2..unp_size { + dst[..2].copy_from_slice(&pred); + for (i, out) in dst[2..unp_size].iter_mut().enumerate() { let diff = br.read_tree8(&trees[i & 1])?; pred[i & 1] = pred[i & 1].wrapping_add(diff); - dst[i] = pred[i & 1]; + *out = pred[i & 1]; } } else { let mut tree = SmackerTree8::new(); tree.decode(&mut br)?; let mut pred = br.read(8)? as u8; dst[0] = pred; - for i in 1..unp_size { + for out in dst[1..unp_size].iter_mut() { let diff = br.read_tree8(&tree)?; pred = pred.wrapping_add(diff); - dst[i] = pred; + *out = pred; } } } diff --git a/nihav-rad/src/demuxers/smacker.rs b/nihav-rad/src/demuxers/smacker.rs index 00724cf..f164349 100644 --- a/nihav-rad/src/demuxers/smacker.rs +++ b/nihav-rad/src/demuxers/smacker.rs @@ -1,4 +1,5 @@ use std::io::SeekFrom; +use std::cmp::Ordering; use nihav_core::demuxers::*; const SMK_FLAG_LOOP_FRAME: u32 = 0x01; @@ -89,13 +90,14 @@ struct SmackerVideoDemuxer<'a> { }*/ fn get_pts_inc(val: i32) -> u64 { - if val > 0 { (val as u64) * 100 } - else if val < 0 { -val as u64 } - else { 1 } + match val.cmp(&0) { + Ordering::Greater => (val as u64) * 100, + Ordering::Less => -val as u64, + Ordering::Equal => 1, + } } impl<'a> DemuxCore<'a> for SmackerVideoDemuxer<'a> { - #[allow(clippy::unreadable_literal)] fn open(&mut self, strmgr: &mut StreamManager, _seek_idx: &mut SeekIndex) -> DemuxerResult<()> { let src = &mut self.src; let mut magic: [u8; 4] = [0; 4]; @@ -166,7 +168,6 @@ impl<'a> DemuxCore<'a> for SmackerVideoDemuxer<'a> { Ok(()) } #[allow(clippy::identity_op)] - #[allow(clippy::unreadable_literal)] fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult { if !self.queued_packets.is_empty() { let pkt = self.queued_packets.pop().unwrap(); diff --git a/nihav-rad/src/lib.rs b/nihav-rad/src/lib.rs index ae2cccf..f5537d1 100644 --- a/nihav-rad/src/lib.rs +++ b/nihav-rad/src/lib.rs @@ -3,16 +3,7 @@ extern crate nihav_core; extern crate nihav_codec_support; #[cfg(feature="decoders")] -#[allow(clippy::cast_lossless)] -#[allow(clippy::collapsible_if)] -#[allow(clippy::collapsible_else_if)] #[allow(clippy::excessive_precision)] -#[allow(clippy::identity_op)] -#[allow(clippy::needless_range_loop)] -#[allow(clippy::needless_late_init)] -#[allow(clippy::too_many_arguments)] -#[allow(clippy::unreadable_literal)] -#[allow(clippy::useless_let_if_seq)] #[allow(clippy::upper_case_acronyms)] mod codecs; #[cfg(feature="decoders")] @@ -21,8 +12,6 @@ pub use crate::codecs::rad_register_all_decoders; pub use crate::codecs::rad_register_all_encoders; #[cfg(feature="demuxers")] -#[allow(clippy::comparison_chain)] -#[allow(clippy::cast_lossless)] mod demuxers; #[cfg(feature="demuxers")] pub use crate::demuxers::rad_register_all_demuxers; -- 2.39.5