From f2af8ecaeed8ec8c1fa6b3c2cfdb075d64994b7a Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Wed, 15 May 2019 12:40:37 +0200 Subject: [PATCH] indeo: fix some clippy warnings --- nihav-indeo/src/codecs/imc.rs | 48 ++++++++++++++-------------- nihav-indeo/src/codecs/indeo2.rs | 32 +++++++++---------- nihav-indeo/src/codecs/indeo3.rs | 36 ++++++++++----------- nihav-indeo/src/codecs/indeo4.rs | 24 +++++++------- nihav-indeo/src/codecs/intel263.rs | 28 ++++++++--------- nihav-indeo/src/codecs/ivi.rs | 50 ++++++++++++++---------------- nihav-indeo/src/codecs/ivibr.rs | 38 +++++++++++------------ nihav-indeo/src/codecs/ividsp.rs | 36 ++++++++++----------- nihav-indeo/src/codecs/mod.rs | 4 ++- nihav-indeo/src/lib.rs | 6 ++++ 10 files changed, 150 insertions(+), 152 deletions(-) diff --git a/nihav-indeo/src/codecs/imc.rs b/nihav-indeo/src/codecs/imc.rs index ce719e6..c895522 100644 --- a/nihav-indeo/src/codecs/imc.rs +++ b/nihav-indeo/src/codecs/imc.rs @@ -186,7 +186,7 @@ impl BitAlloc { let mut tmp: [f32; BANDS] = [BITALLOC_LIMIT; BANDS]; for band in 0..BANDS { if self.band_bits[band] != 6 { - tmp[band] = (self.band_bits[band] as f32) * -2.0 + ch_data.bit_est[band] - 0.415; + tmp[band] = f32::from(self.band_bits[band]) * -2.0 + ch_data.bit_est[band] - 0.415; } } let mut peak = 0.0; @@ -220,7 +220,7 @@ impl BitAlloc { let mut tmp: [f32; BANDS] = [BITALLOC_TOP_LIMIT; BANDS]; for band in start..BANDS { if self.band_bits[band] != 0 { - tmp[band] = (self.band_bits[band] as f32) * -2.0 + ch_data.bit_est[band] - 0.415 + 2.0; + tmp[band] = f32::from(self.band_bits[band]) * -2.0 + ch_data.bit_est[band] - 0.415 + 2.0; } } while free_bits < cur_bits { @@ -256,7 +256,7 @@ impl BitAlloc { let mut tmp: [f32; BANDS] = [BITALLOC_LIMIT; BANDS]; for band in 0..BANDS { if self.band_bits[band] != 6 { - tmp[band] = (self.band_bits[band] as f32) * -2.0 + ch_data.bit_est[band] - 0.415; + tmp[band] = f32::from(self.band_bits[band]) * -2.0 + ch_data.bit_est[band] - 0.415; } } let mut used_bits: i32 = 0; @@ -312,7 +312,7 @@ impl LUTs { sqrt_tab[i] = (i as f32).sqrt(); } - LUTs { exp_lev: exp_lev, exp_10: exp_10, sqrt_tab: sqrt_tab } + LUTs { exp_lev, exp_10, sqrt_tab } } } @@ -368,21 +368,21 @@ impl IMCDecoder { } } IMCDecoder { - is_imc: is_imc, + is_imc, chmap: NAChannelMap::new(), ainfo: NAAudioInfo::new(0, 0, SND_F32P_FORMAT, 0), info: NACodecInfo::new_dummy(), - codes: codes, + codes, ch_data: [IMCChannel::new(), IMCChannel::new()], ba: BitAlloc::new(), imdct: IMDCTContext::new(), luts: LUTs::new(), - cycle1: cycle1, - cycle2: cycle2, - weights1: weights1, - weights2: weights2, + cycle1, + cycle2, + weights1, + weights2, } } @@ -438,7 +438,7 @@ impl IMCDecoder { let maxc_pos = br.read(5)? as usize; let max_coef = br.read(7)? as u8; - let (c1, c2) = calc_maxcoef(max_coef as f32); + let (c1, c2) = calc_maxcoef(f32::from(max_coef)); for i in 0..BANDS { if i != maxc_pos { let level = br.read(4)?; @@ -466,7 +466,7 @@ impl IMCDecoder { ch_data.mask_wght[band] = 0.0; let val; if self.ba.band_width[band] > 0 { - val = (ch_data.new_floor[band] as f64).powi(2); + val = f64::from(ch_data.new_floor[band]).powi(2); ch_data.log_floor2[band] = 2.0 * ch_data.log_floor[band]; } else { val = 0.0; @@ -527,7 +527,7 @@ impl IMCDecoder { } if reset { let ch_data = &mut self.ch_data[ch]; - let (mut c1, mut c2) = calc_maxcoef(level[0] as f32); + let (mut c1, mut c2) = calc_maxcoef(f32::from(level[0])); ch_data.new_floor[0] = c1; ch_data.log_floor[0] = c2; for i in 1..BANDS { @@ -544,7 +544,7 @@ impl IMCDecoder { lval = level[i] - 16; } c1 *= self.luts.exp_10[(lval + 16) as usize]; - c2 += 0.83048 * (lval as f32); + c2 += 0.83048 * f32::from(lval); ch_data.new_floor[i] = c1; ch_data.log_floor[i] = c2; } @@ -555,7 +555,7 @@ impl IMCDecoder { if level[i] < 16 { let lval = level[i] - 7; ch_data.new_floor[i] = self.luts.exp_10[(lval + 16) as usize] * ch_data.old_floor[i]; - ch_data.log_floor[i] += (lval as f32) * 0.83048; + ch_data.log_floor[i] += f32::from(lval) * 0.83048; } else { ch_data.new_floor[i] = ch_data.old_floor[i]; } @@ -666,11 +666,11 @@ impl IMCDecoder { if !self.ba.band_present[band] { continue; } for i in IMC_BANDS[band]..IMC_BANDS[band + 1] { if self.ba.skip_flag[i] { - bits_freed += self.ba.cw_len[i] as i32; + bits_freed += i32::from(self.ba.cw_len[i]); self.ba.cw_len[i] = 0; } } - bits_freed -= self.ba.skip_flag_bits[band] as i32; + bits_freed -= i32::from(self.ba.skip_flag_bits[band]); } if bits_freed < 0 { return Err(DecoderError::Bug); } @@ -831,12 +831,12 @@ impl IMDCTContext { posttwiddle[i] = FFTComplex::exp(consts::PI / 256.0 * n).scale(1.0/32768.0); } IMDCTContext { - pretwiddle1: pretwiddle1, - pretwiddle2: pretwiddle2, - posttwiddle: posttwiddle, + pretwiddle1, + pretwiddle2, + posttwiddle, tmp: [FFTC_ZERO; COEFFS/2], fft: FFTBuilder::new_fft(COEFFS/2, false), - window: window, + window, } } fn imdct(&mut self, coeffs: &[f32; COEFFS], dst: &mut [f32], last_im: &mut [f32; COEFFS/2]) { @@ -876,7 +876,7 @@ impl NADecoder for IMCDecoder { self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), ainfo.get_channels(), SND_F32P_FORMAT, 0); - self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo.clone())); + self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo)); if !self.is_imc { self.generate_iac_tables(ainfo.get_sample_rate() as f32); @@ -935,12 +935,12 @@ pub fn get_decoder_iac() -> Box { struct IMCCodeReader { sel1: usize, sel2: usize } impl IMCCodeReader { - fn new(sel1: usize, sel2: usize) -> Self { IMCCodeReader { sel1: sel1, sel2: sel2 } } + fn new(sel1: usize, sel2: usize) -> Self { IMCCodeReader { sel1, sel2 } } } impl CodebookDescReader for IMCCodeReader { fn bits(&mut self, idx: usize) -> u8 { IMC_CODE_LENGTHS[self.sel1][self.sel2][idx] } - fn code(&mut self, idx: usize) -> u32 { IMC_CODE_CODES[self.sel1][self.sel2][idx] as u32 } + fn code(&mut self, idx: usize) -> u32 { u32::from(IMC_CODE_CODES[self.sel1][self.sel2][idx]) } fn sym (&mut self, idx: usize) -> u8 { idx as u8 } fn len(&mut self) -> usize { IMC_CODE_LENGTHS[0][0].len() } } diff --git a/nihav-indeo/src/codecs/indeo2.rs b/nihav-indeo/src/codecs/indeo2.rs index 375ffa8..a022ec4 100644 --- a/nihav-indeo/src/codecs/indeo2.rs +++ b/nihav-indeo/src/codecs/indeo2.rs @@ -176,7 +176,7 @@ struct IR2CodeReader { } impl CodebookDescReader for IR2CodeReader { fn bits(&mut self, idx: usize) -> u8 { INDEO2_CODE_LENGTHS[idx] } - fn code(&mut self, idx: usize) -> u32 { INDEO2_CODE_CODES[idx] as u32 } + fn code(&mut self, idx: usize) -> u32 { u32::from(INDEO2_CODE_CODES[idx]) } fn sym (&mut self, idx: usize) -> u8 { if idx < 0x7F { (idx + 1) as u8 } else { (idx + 2) as u8 } } @@ -194,7 +194,7 @@ impl Indeo2Decoder { let dummy_info = NACodecInfo::new_dummy(); let mut coderead = IR2CodeReader{}; let cb = Codebook::new(&mut coderead, CodebookMode::LSB).unwrap(); - Indeo2Decoder { info: dummy_info, cb: cb, frmmgr: HAMShuffler::new() } + Indeo2Decoder { info: dummy_info, cb, frmmgr: HAMShuffler::new() } } fn decode_plane_intra(&self, br: &mut BitReader, @@ -205,7 +205,7 @@ impl Indeo2Decoder { let stride = buf.get_stride(planeno); let cb = &self.cb; - let data = buf.get_data_mut().unwrap(); + let data = buf.get_data_mut().unwrap(); let framebuf: &mut [u8] = data.as_mut_slice(); let table = &INDEO2_DELTA_TABLE[tableno]; @@ -240,10 +240,10 @@ impl Indeo2Decoder { } x += run; } else { - let delta0 = (table[idx * 2 + 0] as i16) - 0x80; - let delta1 = (table[idx * 2 + 1] as i16) - 0x80; - let mut pix0 = framebuf[base + x + 0 - stride] as i16; - let mut pix1 = framebuf[base + x + 1 - stride] as i16; + let delta0 = i16::from(table[idx * 2 + 0]) - 0x80; + let delta1 = i16::from(table[idx * 2 + 1]) - 0x80; + let mut pix0 = i16::from(framebuf[base + x + 0 - stride]); + let mut pix1 = i16::from(framebuf[base + x + 1 - stride]); pix0 += delta0; pix1 += delta1; if pix0 < 0 { pix0 = 0; } @@ -283,12 +283,12 @@ impl Indeo2Decoder { if x + run > w { return Err(DecoderError::InvalidData); } x += run; } else { - let delta0 = (table[idx * 2 + 0] as i16) - 0x80; - let delta1 = (table[idx * 2 + 1] as i16) - 0x80; - let mut pix0 = framebuf[base + x + 0] as i16; - let mut pix1 = framebuf[base + x + 1] as i16; - pix0 += delta0 * 3 >> 2; - pix1 += delta1 * 3 >> 2; + let delta0 = i16::from(table[idx * 2 + 0]) - 0x80; + let delta1 = i16::from(table[idx * 2 + 1]) - 0x80; + let mut pix0 = i16::from(framebuf[base + x + 0]); + let mut pix1 = i16::from(framebuf[base + x + 1]); + pix0 += (delta0 * 3) >> 2; + pix1 += (delta1 * 3) >> 2; if pix0 < 0 { pix0 = 0; } if pix1 < 0 { pix1 = 0; } if pix0 > 255 { pix0 = 255; } @@ -331,9 +331,7 @@ impl NADecoder for Indeo2Decoder { let chroma_tab = (tabs >> 2) & 3; if interframe != 0 { let vinfo = self.info.get_properties().get_video_info().unwrap(); - let bufret = alloc_video_buffer(vinfo, 2); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let bufinfo = bufret.unwrap(); + let bufinfo = alloc_video_buffer(vinfo, 2)?; let mut buf = bufinfo.get_vbuf().unwrap(); for plane in 0..3 { let tabidx = (if plane == 0 { luma_tab } else { chroma_tab }) as usize; @@ -346,7 +344,7 @@ impl NADecoder for Indeo2Decoder { Ok(frm.into_ref()) } else { let bufret = self.frmmgr.clone_ref(); - if let None = bufret { return Err(DecoderError::MissingReference); } + if bufret.is_none() { return Err(DecoderError::MissingReference); } let mut buf = bufret.unwrap(); for plane in 0..3 { diff --git a/nihav-indeo/src/codecs/indeo3.rs b/nihav-indeo/src/codecs/indeo3.rs index 186eb4f..9687f94 100644 --- a/nihav-indeo/src/codecs/indeo3.rs +++ b/nihav-indeo/src/codecs/indeo3.rs @@ -276,7 +276,7 @@ struct IV3Cell { impl IV3Cell { fn new(w: u16, h: u16) -> Self { - IV3Cell { x: 0, y: 0, w: w, h: h, d: 20, vqt: false, mv: None } + IV3Cell { x: 0, y: 0, w, h, d: 20, vqt: false, mv: None } } fn split_h(&self) -> (Self, Self) { let h1 = if self.h > 2 { ((self.h + 2) >> 2) << 1 } else { 1 }; @@ -306,7 +306,7 @@ impl IV3Cell { cell2.d -= 1; (cell1, cell2) } - fn no_mv(&self) -> bool { match self.mv { None => true, Some(_) => false } } + fn no_mv(&self) -> bool { self.mv.is_none() } } struct CellDecParams { @@ -365,8 +365,8 @@ impl Indeo3Decoder { sidx = 0; } else { let mv = cell.mv.unwrap(); - let mx = mv.x as i16; - let my = mv.y as i16; + let mx = i16::from(mv.x); + let my = i16::from(mv.y); let l = (cell.x as i16) * 4 + mx; let t = (cell.y as i16) * 4 + my; let r = ((cell.x + cell.w) as i16) * 4 + mx; @@ -473,7 +473,7 @@ impl Indeo3Decoder { tocopy = 4 - line; } if c >= 0xFD { - let nl = 257 - (c as i16) - (line as i16); + let nl = 257 - i16::from(c) - (line as i16); validate!(nl > 0); tocopy = nl as usize; } @@ -513,8 +513,8 @@ impl Indeo3Decoder { fn copy_cell(&mut self, cell: IV3Cell, off: usize, stride: usize) -> DecoderResult<()> { if cell.no_mv() { return Err(DecoderError::InvalidData); } let mv = cell.mv.unwrap(); - let mx = mv.x as i16; - let my = mv.y as i16; + let mx = i16::from(mv.x); + let my = i16::from(mv.y); let l = (cell.x as i16) * 4 + mx; let t = (cell.y as i16) * 4 + my; let r = ((cell.x + cell.w) as i16) * 4 + mx; @@ -646,7 +646,7 @@ impl Indeo3Decoder { for _ in 0..nvec { let x = br.read_byte()? as i8; let y = br.read_byte()? as i8; - self.mvs.push(MV{ x: x, y: y }); + self.mvs.push(MV{ x, y }); } let shift = if planeno == 0 { 2 } else { 4 }; @@ -671,7 +671,7 @@ impl Indeo3Decoder { for _ in 0..nvec { let y = br.read_byte()? as i8; let x = br.read_byte()? as i8; - self.mvs.push(MV{ x: x, y: y }); + self.mvs.push(MV{ x, y }); } let shift = if planeno == 0 { 2 } else { 4 }; @@ -715,7 +715,7 @@ impl NADecoder for Indeo3Decoder { if (frameno ^ hdr_2 ^ size ^ FRMH_TAG) != check { return Err(DecoderError::InvalidData); } - if (size as i64) > br.left() { return Err(DecoderError::InvalidData); } + if i64::from(size) > br.left() { return Err(DecoderError::InvalidData); } let ver = br.read_u16le()?; if ver != 32 { return Err(DecoderError::NotImplemented); } let flags = br.read_u16le()?; @@ -759,16 +759,14 @@ impl NADecoder for Indeo3Decoder { let vinfo = self.info.get_properties().get_video_info().unwrap(); validate!((vinfo.get_width() & !3) == (self.width & !3).into()); validate!((vinfo.get_height() & !3) == (self.height & !3).into()); - let bufret = alloc_video_buffer(vinfo, 4); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let bufinfo = bufret.unwrap(); + let bufinfo = alloc_video_buffer(vinfo, 4)?; let mut buf = bufinfo.get_vbuf().unwrap(); - let ystart = data_start + (yoff as u64); - let ustart = data_start + (uoff as u64); - let vstart = data_start + (voff as u64); - let yendpos = data_start + (yend as u64); - let uendpos = data_start + (uend as u64); - let vendpos = data_start + (vend as u64); + let ystart = data_start + u64::from(yoff); + let ustart = data_start + u64::from(uoff); + let vstart = data_start + u64::from(voff); + let yendpos = data_start + u64::from(yend); + let uendpos = data_start + u64::from(uend); + let vendpos = data_start + u64::from(vend); if intraframe { self.decode_plane_intra(&mut br, 0, ystart, yendpos)?; self.decode_plane_intra(&mut br, 1, ustart, uendpos)?; diff --git a/nihav-indeo/src/codecs/indeo4.rs b/nihav-indeo/src/codecs/indeo4.rs index 78555f8..ce6bc35 100644 --- a/nihav-indeo/src/codecs/indeo4.rs +++ b/nihav-indeo/src/codecs/indeo4.rs @@ -370,10 +370,10 @@ impl IndeoXParser for Indeo4Parser { let hh = (h / 2) as isize; let mut band0 = src.as_ptr(); let mut band1 = band0.offset(hw); - let mut band2 = band0.offset(((h / 2) * sstride) as isize); + let mut band2 = band0.add((h / 2) * sstride); let mut band3 = band2.offset(hw); let mut dst0 = dst.as_mut_ptr(); - let mut dst1 = dst0.offset(dstride as isize); + let mut dst1 = dst0.add(dstride); for _ in 0..hh { let mut b0_ptr = band0; let mut b1_ptr = band1; @@ -382,10 +382,10 @@ impl IndeoXParser for Indeo4Parser { let mut d0_ptr = dst0; let mut d1_ptr = dst1; for _ in 0..hw { - let p0 = *b0_ptr as i32; - let p1 = *b1_ptr as i32; - let p2 = *b2_ptr as i32; - let p3 = *b3_ptr as i32; + let p0 = i32::from(*b0_ptr); + let p1 = i32::from(*b1_ptr); + let p2 = i32::from(*b2_ptr); + let p3 = i32::from(*b3_ptr); let s0 = p0.wrapping_add(p2); let s1 = p1.wrapping_add(p3); let d0 = p0.wrapping_sub(p2); @@ -405,12 +405,12 @@ impl IndeoXParser for Indeo4Parser { d0_ptr = d0_ptr.offset(2); d1_ptr = d1_ptr.offset(2); } - band0 = band0.offset(sstride as isize); - band1 = band1.offset(sstride as isize); - band2 = band2.offset(sstride as isize); - band3 = band3.offset(sstride as isize); - dst0 = dst0.offset((dstride * 2) as isize); - dst1 = dst1.offset((dstride * 2) as isize); + band0 = band0.add(sstride); + band1 = band1.add(sstride); + band2 = band2.add(sstride); + band3 = band3.add(sstride); + dst0 = dst0.add(dstride * 2); + dst1 = dst1.add(dstride * 2); } } } diff --git a/nihav-indeo/src/codecs/intel263.rs b/nihav-indeo/src/codecs/intel263.rs index 131f2f4..be28601 100644 --- a/nihav-indeo/src/codecs/intel263.rs +++ b/nihav-indeo/src/codecs/intel263.rs @@ -44,7 +44,7 @@ impl<'a> Intel263BR<'a> { fn new(src: &'a [u8], tables: &'a Tables) -> Self { Intel263BR { br: BitReader::new(src, src.len(), BitReaderMode::BE), - tables: tables, + tables, gob_no: 0, mb_w: 0, is_pb: false, @@ -64,8 +64,8 @@ impl<'a> Intel263BR<'a> { if !coded { return Ok(()); } let rl_cb = &self.tables.rl_cb; // could be aic too - let q_add = if quant == 0 { 0i16 } else { ((quant - 1) | 1) as i16 }; - let q = (quant * 2) as i16; + let q_add = if quant == 0 { 0i16 } else { i16::from((quant - 1) | 1) }; + let q = i16::from(quant * 2); while idx < 64 { let code = br.read_cb(rl_cb)?; let run; @@ -102,7 +102,7 @@ impl<'a> Intel263BR<'a> { } fn decode_mv_component(br: &mut BitReader, mv_cb: &Codebook) -> DecoderResult { - let code = br.read_cb(mv_cb)? as i16; + let code = i16::from(br.read_cb(mv_cb)?); if code == 0 { return Ok(0) } if !br.read_bool()? { Ok(code) @@ -249,7 +249,7 @@ impl<'a> BlockDecoder for Intel263BR<'a> { let dquant = (cbpc & 4) != 0; if dquant { let idx = br.read(2)? as usize; - q = ((q as i16) + (H263_DQUANT_TAB[idx] as i16)) as u8; + q = (i16::from(q) + i16::from(H263_DQUANT_TAB[idx])) as u8; } Ok(BlockInfo::new(Type::I, cbp, q)) }, @@ -267,7 +267,7 @@ impl<'a> BlockDecoder for Intel263BR<'a> { let cbp = (cbpy << 2) | (cbpc & 3); if dquant { let idx = br.read(2)? as usize; - q = ((q as i16) + (H263_DQUANT_TAB[idx] as i16)) as u8; + q = (i16::from(q) + i16::from(H263_DQUANT_TAB[idx])) as u8; } let mut binfo = BlockInfo::new(Type::I, cbp, q); binfo.set_bpart(bbinfo); @@ -288,7 +288,7 @@ impl<'a> BlockDecoder for Intel263BR<'a> { let cbp = (cbpy << 2) | (cbpc & 3); if dquant { let idx = br.read(2)? as usize; - q = ((q as i16) + (H263_DQUANT_TAB[idx] as i16)) as u8; + q = (i16::from(q) + i16::from(H263_DQUANT_TAB[idx])) as u8; } let mut binfo = BlockInfo::new(Type::P, cbp, q); binfo.set_bpart(bbinfo); @@ -346,18 +346,18 @@ impl Intel263Decoder { let mut coderead = H263ShortCodeReader::new(H263_MV); let mv_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); let tables = Tables { - intra_mcbpc_cb: intra_mcbpc_cb, - inter_mcbpc_cb: inter_mcbpc_cb, - cbpy_cb: cbpy_cb, - rl_cb: rl_cb, - aic_rl_cb: aic_rl_cb, - mv_cb: mv_cb, + intra_mcbpc_cb, + inter_mcbpc_cb, + cbpy_cb, + rl_cb, + aic_rl_cb, + mv_cb, }; Intel263Decoder{ info: NACodecInfo::new_dummy(), dec: H263BaseDecoder::new(true), - tables: tables, + tables, bdsp: H263BlockDSP::new(), } } diff --git a/nihav-indeo/src/codecs/ivi.rs b/nihav-indeo/src/codecs/ivi.rs index 064da0b..612572a 100644 --- a/nihav-indeo/src/codecs/ivi.rs +++ b/nihav-indeo/src/codecs/ivi.rs @@ -46,16 +46,16 @@ pub struct PictureHeader { impl PictureHeader { pub fn new(ftype: IVIFrameType, width: usize, height: usize, slice_w: usize, slice_h: usize, transparent: bool, luma_bands: usize, chroma_bands: usize, in_q: bool) -> Self { PictureHeader { - ftype: ftype, - width: width, height: height, slice_w: slice_w, slice_h: slice_h, - transparent: transparent, - luma_bands: luma_bands, chroma_bands: chroma_bands, - in_q: in_q, + ftype, + width, height, slice_w, slice_h, + transparent, + luma_bands, chroma_bands, + in_q, } } pub fn new_null(ftype: IVIFrameType) -> Self { PictureHeader { - ftype: ftype, + ftype, width: 0, height: 0, slice_w: 0, slice_h: 0, transparent: false, luma_bands: 0, chroma_bands: 0, @@ -89,16 +89,16 @@ pub type TrFunc = fn (&mut [i32; 64]); pub type TrFuncDC = fn (&mut [i32; 64], i32); impl IVITransformType { - pub fn is_8x8(&self) -> bool { - match *self { + pub fn is_8x8(self) -> bool { + match self { IVITransformType::Haar (ref sz, _) => { *sz == TSize::T8x8 }, IVITransformType::Slant(ref sz, _) => { *sz == TSize::T8x8 }, IVITransformType::DCT (ref sz, _) => { *sz == TSize::T8x8 }, IVITransformType::None (ref sz) => { *sz == TSize::T8x8 }, } } - pub fn is_2d(&self) -> bool { - match *self { + pub fn is_2d(self) -> bool { + match self { IVITransformType::Haar (_, ref dir) => { *dir == TDir::TwoD }, IVITransformType::Slant(_, ref dir) => { *dir == TDir::TwoD }, IVITransformType::DCT (_, ref dir) => { *dir == TDir::TwoD }, @@ -118,7 +118,7 @@ pub struct TxParams4x4 { impl TxParams4x4 { pub fn new(quant_intra: &'static [u16; 16], quant_inter: &'static [u16; 16], scan: &'static [usize; 16]) -> Self { TxParams4x4 { - quant_intra: quant_intra, quant_inter: quant_inter, scan: scan, + quant_intra, quant_inter, scan, } } } @@ -134,7 +134,7 @@ pub struct TxParams8x8 { impl TxParams8x8 { pub fn new(quant_intra: &'static [u16; 64], quant_inter: &'static [u16; 64], scan: &'static [usize; 64]) -> Self { TxParams8x8 { - quant_intra: quant_intra, quant_inter: quant_inter, scan: scan, + quant_intra, quant_inter, scan, } } } @@ -172,26 +172,22 @@ impl BandHeader { for i in 0..num_corr { let pos1 = corr_map[i * 2 + 0] as usize; let pos2 = corr_map[i * 2 + 1] as usize; - let t = rvmap.runtab[pos1]; - rvmap.runtab[pos1] = rvmap.runtab[pos2]; - rvmap.runtab[pos2] = t; - let t = rvmap.valtab[pos1]; - rvmap.valtab[pos1] = rvmap.valtab[pos2]; - rvmap.valtab[pos2] = t; + rvmap.runtab.swap(pos1, pos2); + rvmap.valtab.swap(pos1, pos2); } BandHeader { - plane_no: plane_no, band_no: band_no, - empty: false, halfpel: halfpel, - inherit_mv: inherit_mv, - has_qdelta: has_qdelta, inherit_qd: inherit_qd, quant: quant, - mb_size: mb_size, blk_size: blk_size, - rvmap: rvmap, blk_cb: blk_cb, - tr: tr, ttype: ttype, + plane_no, band_no, + empty: false, halfpel, + inherit_mv, + has_qdelta, inherit_qd, quant, + mb_size, blk_size, + rvmap, blk_cb, + tr, ttype, } } pub fn new_empty(plane_no: usize, band_no: usize) -> Self { BandHeader { - plane_no: plane_no, band_no: band_no, + plane_no, band_no, empty: true, halfpel: true, inherit_mv: false, has_qdelta: false, inherit_qd: false, quant: 0, mb_size: 0, blk_size: 0, @@ -248,7 +244,7 @@ pub struct IVITile { impl IVITile { pub fn new(pos_x: usize, pos_y: usize, w: usize, h: usize) -> Self { IVITile { - pos_x: pos_x, pos_y: pos_y, w: w, h: h, + pos_x, pos_y, w, h, mb_w: 0, mb_h: 0, mb: Vec::new(), } } diff --git a/nihav-indeo/src/codecs/ivibr.rs b/nihav-indeo/src/codecs/ivibr.rs index edeec46..029b815 100644 --- a/nihav-indeo/src/codecs/ivibr.rs +++ b/nihav-indeo/src/codecs/ivibr.rs @@ -8,7 +8,7 @@ use super::ivi::*; use super::ividsp::*; pub fn scale_mv(val: i32, scale: u8) -> i32 { - (val + (if val > 0 { 1 } else { 0 }) + (scale as i32) - 1) >> scale + (val + (if val > 0 { 1 } else { 0 }) + i32::from(scale) - 1) >> scale } #[derive(Clone,Copy)] @@ -103,7 +103,7 @@ impl<'a> IVICodebookReader for BitReader<'a> { Ok(base + add) } else { let nbits = cb.bits[0]; - return Ok(IVI_REVS[nbits as usize][self.read(nbits)? as usize]); + Ok(IVI_REVS[nbits as usize][self.read(nbits)? as usize]) } } #[inline(always)] @@ -146,6 +146,7 @@ pub const IVI_BLK_CB: &[IVICodebook; 8] = &[ ]; #[allow(unused_variables)] +#[allow(clippy::many_single_char_names)] fn read_trans_band_header(br: &mut BitReader, w: usize, h: usize, dst: &mut [i16], dstride: usize) -> DecoderResult<()> { let color_plane = br.read(2)?; let bit_depth = br.read(3)?; @@ -259,7 +260,7 @@ fn decode_block8x8(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tabl validate!((idx >= 0) && (idx < 64)); let spos = tables.scan[idx as usize]; - let q = ((quant_mat[spos] as u32) * (quant as u32)) >> 9; + let q = (u32::from(quant_mat[spos]) * u32::from(quant)) >> 9; if q > 1 { let qq = q as i32; let bias = (((q ^ 1) - 1) >> 1) as i32; @@ -308,7 +309,7 @@ fn decode_block4x4(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tabl validate!((idx >= 0) && (idx < 16)); let spos = tables.scan[idx as usize]; - let q = ((quant_mat[spos] as u32) * (quant as u32)) >> 9; + let q = (u32::from(quant_mat[spos]) * u32::from(quant)) >> 9; if q > 1 { let qq = q as i32; let bias = (((q ^ 1) - 1) >> 1) as i32; @@ -329,24 +330,24 @@ fn decode_block4x4(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tabl fn put_block(frame: &mut [i16], offs: usize, stride: usize, blk: &[i32], blk_size: usize) { unsafe { - let mut dptr = frame.as_mut_ptr().offset(offs as isize); + let mut dptr = frame.as_mut_ptr().add(offs); for y in 0..blk_size { for x in 0..blk_size { - *dptr.offset(x as isize) = blk[x + y * blk_size] as i16; + *dptr.add(x) = blk[x + y * blk_size] as i16; } - dptr = dptr.offset(stride as isize); + dptr = dptr.add(stride); } } } fn add_block(frame: &mut [i16], offs: usize, stride: usize, blk: &[i32], blk_size: usize) { unsafe { - let mut dptr = frame.as_mut_ptr().offset(offs as isize); + let mut dptr = frame.as_mut_ptr().add(offs); for y in 0..blk_size { for x in 0..blk_size { - *dptr.offset(x as isize) = (*dptr.offset(x as isize)).wrapping_add(blk[x + y * blk_size] as i16); + *dptr.add(x) = (*dptr.add(x)).wrapping_add(blk[x + y * blk_size] as i16); } - dptr = dptr.offset(stride as isize); + dptr = dptr.add(stride); } } } @@ -407,6 +408,7 @@ impl FrameData { } } +#[allow(clippy::many_single_char_names)] fn do_mc(dst: &mut [i16], dstride: usize, src: &[i16], sstride: usize, x: usize, y: usize, l: usize, r: usize, t: usize, b: usize, mv_x: i32, mv_y: i32, is_hpel: bool, blk_size: usize) { let (xoff, yoff, mv_mode) = if is_hpel { (mv_x >> 1, mv_y >> 1, ((mv_x & 1) + (mv_y & 1) * 2) as u8) @@ -428,6 +430,7 @@ fn do_mc(dst: &mut [i16], dstride: usize, src: &[i16], sstride: usize, x: usize, } } +#[allow(clippy::many_single_char_names)] fn do_mc_b(dst: &mut [i16], dstride: usize, src1: &[i16], sstride1: usize, src2: &[i16], sstride2: usize, x: usize, y: usize, l: usize, r: usize, t: usize, b: usize, mv_x: i32, mv_y: i32, mv2_x: i32, mv2_y: i32, is_hpel: bool, blk_size: usize) { let (xoff1, yoff1, mv_mode1) = if is_hpel { (mv_x >> 1, mv_y >> 1, ((mv_x & 1) + (mv_y & 1) * 2) as u8) @@ -497,7 +500,7 @@ impl IVIDecoder { vinfoa: NAVideoInfo::new(0, 0, false, YUVA410_FORMAT), bref: None, - bands: bands, + bands, tiles: Vec::new(), tile_start: [[0; 4]; 4], num_tiles: [[0; 4]; 4], } } @@ -857,12 +860,7 @@ br.skip(skip_part as u32)?; _ => {}, }; - let mut vinfo; - if pic_hdr.transparent { - vinfo = self.vinfoa.clone(); - } else { - vinfo = self.vinfo.clone(); - } + let mut vinfo = if pic_hdr.transparent { self.vinfoa } else { self.vinfo }; vinfo.set_width(pic_hdr.width); vinfo.set_height(pic_hdr.height); let mut buftype = alloc_video_buffer(vinfo, 0)?; @@ -947,10 +945,10 @@ br.skip(skip_part as u32)?; res } - pub fn is_intra(&mut self) -> bool { + pub fn is_intra(&self) -> bool { self.ftype.is_intra() } - pub fn get_frame_type(&mut self) -> FrameType { + pub fn get_frame_type(&self) -> FrameType { match self.ftype { IVIFrameType::Intra => { FrameType::I }, IVIFrameType::Intra1 => { FrameType::I }, @@ -976,7 +974,7 @@ impl Clone for RVMap { let mut valtab: [i8; 256] = [0; 256]; runtab.copy_from_slice(&self.runtab); valtab.copy_from_slice(&self.valtab); - RVMap { eob_sym: self.eob_sym, esc_sym: self.esc_sym, runtab: runtab, valtab: valtab } + RVMap { eob_sym: self.eob_sym, esc_sym: self.esc_sym, runtab, valtab } } } diff --git a/nihav-indeo/src/codecs/ividsp.rs b/nihav-indeo/src/codecs/ividsp.rs index 88bc8cc..0c5274d 100644 --- a/nihav-indeo/src/codecs/ividsp.rs +++ b/nihav-indeo/src/codecs/ividsp.rs @@ -333,12 +333,12 @@ pub fn ivi_mc_put(dst: &mut [i16], dstride: usize, src: &[i16], sstride: usize, for _ in 0..h { let mut last = *sptr; for x in 0..w { - let nv = *sptr.offset((x + 1) as isize); - *dptr.offset(x as isize) = nv.wrapping_add(last) >> 1; + let nv = *sptr.add(x + 1); + *dptr.add(x) = nv.wrapping_add(last) >> 1; last = nv; } - sptr = sptr.offset(sstride as isize); - dptr = dptr.offset(dstride as isize); + sptr = sptr.add(sstride); + dptr = dptr.add(dstride); } } }, @@ -353,17 +353,17 @@ pub fn ivi_mc_put(dst: &mut [i16], dstride: usize, src: &[i16], sstride: usize, }*/ unsafe { let mut sptr0 = src.as_ptr(); - let mut sptr1 = sptr0.offset(sstride as isize); + let mut sptr1 = sptr0.add(sstride); let mut dptr = dst.as_mut_ptr(); for _ in 0..h { for x in 0..w { - let a = *sptr0.offset(x as isize); - let b = *sptr1.offset(x as isize); - *dptr.offset(x as isize) = a.wrapping_add(b) >> 1; + let a = *sptr0.add(x); + let b = *sptr1.add(x); + *dptr.add(x) = a.wrapping_add(b) >> 1; } - sptr0 = sptr0.offset(sstride as isize); - sptr1 = sptr1.offset(sstride as isize); - dptr = dptr.offset(sstride as isize); + sptr0 = sptr0.add(sstride); + sptr1 = sptr1.add(sstride); + dptr = dptr.add(sstride); } } }, @@ -379,23 +379,23 @@ pub fn ivi_mc_put(dst: &mut [i16], dstride: usize, src: &[i16], sstride: usize, }*/ unsafe { let mut sptr0 = src.as_ptr(); - let mut sptr1 = sptr0.offset(sstride as isize); + let mut sptr1 = sptr0.add(sstride); let mut dptr = dst.as_mut_ptr(); let mut la = *sptr0; let mut lb = *sptr1; for _ in 0..h { for x in 0..w { - let a = *sptr0.offset((x + 1) as isize); - let b = *sptr1.offset((x + 1) as isize); + let a = *sptr0.add(x + 1); + let b = *sptr1.add(x + 1); let aas = a.wrapping_add(la); let bbs = b.wrapping_add(lb); - *dptr.offset(x as isize) = aas.wrapping_add(bbs) >> 2; + *dptr.add(x) = aas.wrapping_add(bbs) >> 2; la = a; lb = b; } - sptr0 = sptr0.offset(sstride as isize); - sptr1 = sptr1.offset(sstride as isize); - dptr = dptr.offset(dstride as isize); + sptr0 = sptr0.add(sstride); + sptr1 = sptr1.add(sstride); + dptr = dptr.add(dstride); } } }, diff --git a/nihav-indeo/src/codecs/mod.rs b/nihav-indeo/src/codecs/mod.rs index a5d2f5c..bc343fe 100644 --- a/nihav-indeo/src/codecs/mod.rs +++ b/nihav-indeo/src/codecs/mod.rs @@ -24,6 +24,8 @@ mod ivibr; mod ividsp; #[cfg(feature="decoder_imc")] +#[allow(clippy::excessive_precision)] +#[allow(clippy::unreadable_literal)] mod imc; const INDEO_CODECS: &[DecoderInfo] = &[ @@ -45,7 +47,7 @@ const INDEO_CODECS: &[DecoderInfo] = &[ ]; pub fn indeo_register_all_codecs(rd: &mut RegisteredDecoders) { - for decoder in INDEO_CODECS.into_iter() { + for decoder in INDEO_CODECS.iter() { rd.add_decoder(decoder.clone()); } } diff --git a/nihav-indeo/src/lib.rs b/nihav-indeo/src/lib.rs index ccc3595..78bb060 100644 --- a/nihav-indeo/src/lib.rs +++ b/nihav-indeo/src/lib.rs @@ -1,5 +1,11 @@ extern crate nihav_core; +#[allow(clippy::collapsible_if)] +#[allow(clippy::identity_op)] +#[allow(clippy::needless_range_loop)] +#[allow(clippy::too_many_arguments)] +#[allow(clippy::useless_let_if_seq)] +#[allow(clippy::verbose_bit_mask)] pub mod codecs; #[cfg(test)] -- 2.39.5