From: Kostya Shishkov Date: Tue, 16 Jun 2020 10:40:52 +0000 (+0200) Subject: indeo: fix or silence clippy warnings X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=5a6dec5fd53a92cc8696655084f986a69dc6a230;p=nihav.git indeo: fix or silence clippy warnings --- diff --git a/nihav-indeo/src/codecs/imc.rs b/nihav-indeo/src/codecs/imc.rs index c766861..6840739 100644 --- a/nihav-indeo/src/codecs/imc.rs +++ b/nihav-indeo/src/codecs/imc.rs @@ -103,6 +103,7 @@ impl BitAlloc { self.skip_flag[i] = false; } } + #[allow(clippy::cyclomatic_complexity)] fn calculate_bit_allocation(&mut self, ch_data: &mut IMCChannel, bits: usize, fixed_head: bool, adj_idx: usize) -> DecoderResult<()> { let mut peak = 0.0; diff --git a/nihav-indeo/src/codecs/indeo3.rs b/nihav-indeo/src/codecs/indeo3.rs index 224c3ec..1705a43 100644 --- a/nihav-indeo/src/codecs/indeo3.rs +++ b/nihav-indeo/src/codecs/indeo3.rs @@ -76,7 +76,7 @@ impl Buffers { let mut sidx = soff; let mut didx = doff; for _ in 0..h { - for i in 0..w { self.dbuf[didx + i] = self.sbuf[sidx + i]; } + self.dbuf[didx..][..w].copy_from_slice(&self.sbuf[sidx..][..w]); sidx += stride; didx += stride; } @@ -92,7 +92,7 @@ impl Buffers { } else { for i in 0..w { buf[i] = self.dbuf[didx - stride + i]; } for _ in 0..h { - for i in 0..w { self.dbuf[didx + i] = buf[i]; } + self.dbuf[didx..][..w].copy_from_slice(&buf[..w]); didx += stride; } } @@ -153,12 +153,12 @@ fn copy_line_top(bufs: &mut Buffers, off: usize, stride: usize, bw: usize, topli let mut buf: [u8; 8] = [0; 8]; if !topline { let src = &bufs.dbuf[(off - stride)..(off - stride + bw)]; - for i in 0..bw { buf[i] = src[i]; } + buf[..bw].copy_from_slice(&src[..bw]); } else { for i in 0..bw { buf[i] = DEFAULT_PIXEL; } } let dst = &mut bufs.dbuf[off..][..bw]; - for i in 0..bw { dst[i] = buf[i]; } + dst.copy_from_slice(&buf[..bw]); } fn copy_line_top4x4(bufs: &mut Buffers, off: usize, stride: usize, topline: bool) { @@ -179,7 +179,7 @@ fn copy_line_top8x8(bufs: &mut Buffers, off: usize, stride: usize, topline: bool for i in 0..8 { buf[i] = DEFAULT_PIXEL; } } let dst = &mut bufs.dbuf[off..][..8]; - for i in 0..8 {dst[i] = buf[i]; } + dst.copy_from_slice(&buf[..8]); } fn fill_block8x8(bufs: &mut Buffers, doff: usize, stride: usize, h: usize, topline: bool, firstline: bool) { @@ -200,7 +200,7 @@ fn fill_block8x8(bufs: &mut Buffers, doff: usize, stride: usize, h: usize, topli didx += stride; } for _ in start..h { - for i in 0..8 { bufs.dbuf[didx + i] = buf[i]; } + bufs.dbuf[didx..][..8].copy_from_slice(&buf[..8]); didx += stride; } } @@ -325,6 +325,7 @@ impl Indeo3Decoder { Ok((self.bbuf >> self.bpos) & 0x3) } + #[allow(clippy::cyclomatic_complexity)] fn decode_cell_data(&mut self, br: &mut ByteReader, cell: IV3Cell, off: usize, stride: usize, params: CellDecParams, vq_idx: u8) -> DecoderResult<()> { let blk_w = cell.w * 4 / params.bw; diff --git a/nihav-indeo/src/codecs/indeo5.rs b/nihav-indeo/src/codecs/indeo5.rs index c1c7cb5..5eedd14 100644 --- a/nihav-indeo/src/codecs/indeo5.rs +++ b/nihav-indeo/src/codecs/indeo5.rs @@ -265,6 +265,7 @@ impl IndeoXParser for Indeo5Parser { Ok(BandHeader::new(plane_no, band_no, self.mb_size[band_id], self.blk_size[band_id], self.is_hpel[band_id], inherit_mv, has_qdelta, inherit_qd, band_q, rvmap_idx, num_corr, corr_map, blk_cb, tr, txtype)) } + #[allow(clippy::cyclomatic_complexity)] fn decode_mb_info(&mut self, br: &mut BitReader, pic_hdr: &PictureHeader, band: &BandHeader, tile: &mut IVITile, ref_tile: Option<&IVITile>, mv_scale: u8) -> DecoderResult<()> { let mut mv_x = 0; let mut mv_y = 0; diff --git a/nihav-indeo/src/codecs/intel263.rs b/nihav-indeo/src/codecs/intel263.rs index e74f684..acedfb4 100644 --- a/nihav-indeo/src/codecs/intel263.rs +++ b/nihav-indeo/src/codecs/intel263.rs @@ -157,13 +157,13 @@ fn deblock_hor(buf: &mut NAVideoBuffer, comp: usize, strength: u8, off: usiz let dptr = buf.get_data_mut().unwrap(); let buf = dptr.as_mut_slice(); for x in 0..8 { - let a = buf[off - 2 * stride + x] as i16; - let b = buf[off - 1 * stride + x] as i16; - let c = buf[off + 0 * stride + x] as i16; - let d = buf[off + 1 * stride + x] as i16; + let a = i16::from(buf[off - 2 * stride + x]); + let b = i16::from(buf[off - 1 * stride + x]); + let c = i16::from(buf[off + 0 * stride + x]); + let d = i16::from(buf[off + 1 * stride + x]); let diff = (3 * (a - d) + 8 * (c - b)) / 16; if (diff != 0) && (diff > -24) && (diff < 24) { - let d1a = (diff.abs() - 2 * (diff.abs() - (strength as i16)).max(0)).max(0); + 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; @@ -177,13 +177,13 @@ fn deblock_ver(buf: &mut NAVideoBuffer, comp: usize, strength: u8, off: usiz let dptr = buf.get_data_mut().unwrap(); let buf = dptr.as_mut_slice(); for y in 0..8 { - let a = buf[off - 2 + y * stride] as i16; - let b = buf[off - 1 + y * stride] as i16; - let c = buf[off + 0 + y * stride] as i16; - let d = buf[off + 1 + y * stride] as i16; + let a = i16::from(buf[off - 2 + y * stride]); + let b = i16::from(buf[off - 1 + y * stride]); + let c = i16::from(buf[off + 0 + y * stride]); + let d = i16::from(buf[off + 1 + y * stride]); let diff = (3 * (a - d) + 8 * (c - b)) / 16; if (diff != 0) && (diff > -24) && (diff < 24) { - let d1a = (diff.abs() - 2 * (diff.abs() - (strength as i16)).max(0)).max(0); + 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; @@ -448,6 +448,7 @@ fn decode_b_info(br: &mut BitReader, is_pb: bool, is_ipb: bool, is_intra: bool) impl<'a> BlockDecoder for Intel263BR<'a> { #[allow(unused_variables)] +#[allow(clippy::unreadable_literal)] fn decode_pichdr(&mut self) -> DecoderResult { let br = &mut self.br; let syncw = br.read(22)?; diff --git a/nihav-indeo/src/codecs/ivibr.rs b/nihav-indeo/src/codecs/ivibr.rs index 8ccd3b0..2169b69 100644 --- a/nihav-indeo/src/codecs/ivibr.rs +++ b/nihav-indeo/src/codecs/ivibr.rs @@ -228,7 +228,8 @@ let tile_end = tile_start + len * 8; Ok(()) } -fn decode_block8x8(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tables: &TxParams8x8, is_intra: bool, is_2d: bool, prev_dc: &mut i32, quant: u8, coeffs: &mut [i32; 64], transform: &TrFunc) -> DecoderResult<()> { +#[allow(clippy::cast_lossless)] +fn decode_block8x8(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tables: &TxParams8x8, is_intra: bool, is_2d: bool, prev_dc: &mut i32, quant: u8, coeffs: &mut [i32; 64], transform: TrFunc) -> DecoderResult<()> { let mut idx: isize = -1; let quant_mat = if is_intra { tables.quant_intra } else { tables.quant_inter }; while idx <= 64 { @@ -278,7 +279,8 @@ fn decode_block8x8(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tabl (transform)(coeffs); Ok(()) } -fn decode_block4x4(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tables: &TxParams4x4, is_intra: bool, is_2d: bool, prev_dc: &mut i32, quant: u8, coeffs: &mut [i32; 64], transform: &TrFunc) -> DecoderResult<()> { +#[allow(clippy::cast_lossless)] +fn decode_block4x4(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tables: &TxParams4x4, is_intra: bool, is_2d: bool, prev_dc: &mut i32, quant: u8, coeffs: &mut [i32; 64], transform: TrFunc) -> DecoderResult<()> { let mut idx: isize = -1; let quant_mat = if is_intra { tables.quant_intra } else { tables.quant_inter }; while idx <= 64 { @@ -620,7 +622,7 @@ impl IVIDecoder { dec.decode_mb_info(br, pic_hdr, &band, tile, ref_tile, mv_scale)?; } - self.decode_tile(br, &band, tile_no, &tr, &tr_dc)?; + self.decode_tile(br, &band, tile_no, tr, tr_dc)?; let skip_part = tile_end - br.tell(); br.skip(skip_part as u32)?; } else { @@ -663,14 +665,14 @@ br.skip(skip_part as u32)?; } } } - self.decode_tile(br, &band, tile_no, &tr, &tr_dc)?; + self.decode_tile(br, &band, tile_no, tr, tr_dc)?; } } self.bands[bidx] = band; br.align(); Ok(()) } - fn decode_tile(&mut self, br: &mut BitReader, band: &BandHeader, tile_no: usize, tr: &TrFunc, transform_dc: &TrFuncDC) -> DecoderResult<()> { + fn decode_tile(&mut self, br: &mut BitReader, band: &BandHeader, tile_no: usize, tr: TrFunc, transform_dc: TrFuncDC) -> DecoderResult<()> { let mut mb_idx = 0; let mut prev_dc: i32 = 0; let tile = &mut self.tiles[tile_no];