Err(DecoderError::InvalidData)
}
}
+ #[allow(clippy::identity_op)]
fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let info = pkt.get_stream().get_info();
if let NACodecTypeInfo::Audio(_) = info.get_properties() {
#[cfg(feature="decoder_truemotionrt")]
mod truemotionrt;
#[cfg(feature="decoder_truemotion2")]
-#[allow(clippy::needless_range_loop)]
mod truemotion2;
#[cfg(feature="decoder_truemotion2x")]
mod truemotion2x;
#[cfg(any(feature="decoder_vp3", feature="decoder_vp4", feature="decoder_vp5", feature="decoder_vp6", feature="decoder_vp7"))]
#[macro_use]
#[allow(clippy::erasing_op)]
-#[allow(clippy::needless_range_loop)]
+#[allow(clippy::identity_op)]
#[allow(clippy::too_many_arguments)]
-#[allow(clippy::useless_let_if_seq)]
mod vpcommon;
#[cfg(any(feature="decoder_vp3", feature="decoder_vp4"))]
-#[allow(clippy::needless_range_loop)]
#[allow(clippy::too_many_arguments)]
mod vp3;
#[cfg(any(feature="decoder_vp5", feature="decoder_vp6"))]
-#[allow(clippy::needless_range_loop)]
-#[allow(clippy::useless_let_if_seq)]
#[allow(clippy::too_many_arguments)]
mod vp56;
#[cfg(feature="decoder_vp5")]
-#[allow(clippy::needless_range_loop)]
mod vp5;
#[cfg(any(feature="decoder_vp6", feature="encoder_vp6"))]
mod vp6data;
#[cfg(any(feature="decoder_vp6", feature="encoder_vp6"))]
mod vp6dsp;
#[cfg(feature="decoder_vp6")]
-#[allow(clippy::needless_range_loop)]
mod vp6;
#[cfg(feature="decoder_vp7")]
-#[allow(clippy::needless_range_loop)]
-#[allow(clippy::useless_let_if_seq)]
mod vp7;
#[cfg(any(feature="decoder_vp7", feature="encoder_vp7"))]
mod vp7data;
mod vp78data;
#[cfg(feature="decoder_vp7")]
#[allow(clippy::erasing_op)]
-#[allow(clippy::needless_range_loop)]
+#[allow(clippy::identity_op)]
#[allow(clippy::too_many_arguments)]
-#[allow(clippy::useless_let_if_seq)]
mod vp7dsp;
#[cfg(any(feature="decoder_vp7", feature="decoder_vp8", feature="encoder_vp7"))]
#[allow(clippy::needless_range_loop)]
-#[allow(clippy::useless_let_if_seq)]
mod vp78;
#[cfg(any(feature="decoder_vp7", feature="decoder_vp8", feature="encoder_vp7"))]
#[allow(clippy::erasing_op)]
-#[allow(clippy::needless_range_loop)]
+#[allow(clippy::identity_op)]
#[allow(clippy::too_many_arguments)]
-#[allow(clippy::useless_let_if_seq)]
mod vp78dsp;
#[cfg(feature="decoder_vp8")]
-#[allow(clippy::needless_range_loop)]
-#[allow(clippy::useless_let_if_seq)]
mod vp8;
#[cfg(feature="decoder_vp8")]
#[allow(clippy::erasing_op)]
-#[allow(clippy::needless_range_loop)]
+#[allow(clippy::identity_op)]
#[allow(clippy::too_many_arguments)]
mod vp8dsp;
#[cfg(any(feature="decoder_dk3_adpcm", feature="decoder_dk4_adpcm"))]
mod dkadpcm;
#[cfg(feature="decoder_on2avc")]
-#[allow(clippy::manual_memcpy)]
-#[allow(clippy::needless_range_loop)]
#[allow(clippy::too_many_arguments)]
mod on2avc;
#[cfg(feature="decoder_on2avc")]
+#[allow(clippy::excessive_precision)]
mod on2avcdata;
const DUCK_CODECS: &[DecoderInfo] = &[
#[macro_use]
mod vpenc;
#[cfg(feature="encoder_vp6")]
-#[allow(clippy::needless_range_loop)]
mod vp6enc;
#[cfg(feature="encoder_vp7")]
-#[allow(clippy::needless_range_loop)]
mod vp7enc;
const DUCK_ENCODERS: &[EncoderInfo] = &[
self.imdct_short.imdct(ain, aout);
}
self.ew_buf = [0.0; 1152];
- for i in 0..128 {
- self.ew_buf[i] = self.tmp[i];
- }
+ self.ew_buf[..128].copy_from_slice(&self.tmp[..128]);
for w in 0..7 {
overlap(&mut self.ew_buf[(w + 1) * 128..][..128],
&self.tmp[(w + 1) * 256..][..128],
&self.tmp[w * 256 + 128..][..128],
AVC_WIN_SHORT);
}
- for i in 0..128 {
- self.ew_buf[1024 + i] = self.tmp[7 * 256 + 128 + i];
- }
- for i in 0..SHORT_WIN_POINT0 {
- dst[i] = delay[i];
- }
+ self.ew_buf[1024..][..128].copy_from_slice(&self.tmp[7 * 256 + 128..][..128]);
+ dst[..SHORT_WIN_POINT0].copy_from_slice(&delay[..SHORT_WIN_POINT0]);
overlap(&mut dst[SHORT_WIN_POINT0..SHORT_WIN_POINT1],
&self.ew_buf[0..128],
&delay[SHORT_WIN_POINT0..SHORT_WIN_POINT1], AVC_WIN_SHORT);
- for i in SHORT_WIN_POINT1..COEFFS {
- dst[i] = self.ew_buf[i - SHORT_WIN_POINT1 + 128];
- }
- for i in 0..SHORT_WIN_POINT1 {
- delay[i] = self.ew_buf[SHORT_WIN_POINT1 + i];
- }
+ dst[SHORT_WIN_POINT1..COEFFS].copy_from_slice(&self.ew_buf[128..][..COEFFS-SHORT_WIN_POINT1]);
+ delay[..SHORT_WIN_POINT1].copy_from_slice(&self.ew_buf[SHORT_WIN_POINT1..][..SHORT_WIN_POINT1]);
for i in COEFFS/2..COEFFS {
delay[i] = delay[COEFFS - 1 - i];
}
_ => unreachable!(),
};
if (self.cur_win == 2) || (self.cur_win >= 4) {
- for i in 0..SHORT_WIN_POINT0 {
- dst[i] = delay[i];
- }
+ dst[..SHORT_WIN_POINT0].copy_from_slice(&delay[..SHORT_WIN_POINT0]);
overlap_half(&mut dst[SHORT_WIN_POINT0..SHORT_WIN_POINT1],
&self.ew_buf[0..64],
&delay[SHORT_WIN_POINT0..SHORT_WIN_POINT1], AVC_WIN_SHORT);
- for i in SHORT_WIN_POINT1..COEFFS {
- dst[i] = self.ew_buf[i - SHORT_WIN_POINT1 + 64];
- }
- for i in 0..COEFFS/2 {
- delay[i] = self.ew_buf[COEFFS/2 + i];
- }
+ dst[SHORT_WIN_POINT1..COEFFS].copy_from_slice(&self.ew_buf[64..][..COEFFS-SHORT_WIN_POINT1]);
+ delay[..COEFFS/2].copy_from_slice(&self.ew_buf[COEFFS/2..COEFFS]);
for i in COEFFS/2..COEFFS {
delay[i] = delay[COEFFS - 1 - i];
}
}
}
+#[allow(clippy::identity_op)]
fn merge_bands(src: &[FFTComplex], dst: &mut [FFTComplex], size: usize) {
let step = if size == 512 { 2 } else { 4 };
let (s01, s23) = src.split_at(size / 2);
lastframe: FrameBuf,
}
+#[allow(clippy::identity_op)]
impl TM1Decoder {
fn new() -> Self { Self::default() }
fn set_delta_tables(&mut self, delta_set: usize, table_idx: usize, is_24bit: bool) {
}
// fat deltas for 15-bit mode
+#[allow(clippy::identity_op)]
#[allow(clippy::neg_multiply)]
const DUCK_Y_DELTAS_5: [[i32; 8]; 4] = [
[ 0, -1 * 5, 1 * 5, -3 * 5, 3 * 5, -6 * 5, 6 * 5, -6 * 5 ],
[ 2 * 5, -3 * 5, 10 * 5, -10 * 5, 23 * 5, -23 * 5, 47 * 5, -47 * 5 ],
[ 0, -2 * 5, 2 * 5, -8 * 5, 8 * 5, -18 * 5, 18 * 5, -40 * 5 ]
];
+#[allow(clippy::identity_op)]
#[allow(clippy::neg_multiply)]
const DUCK_C_DELTAS_5: [[i32; 8]; 4] = [
[ 0, -1 * 5, 1 * 5, -2 * 5, 3 * 5, -4 * 5, 5 * 5, -4 * 5 ],
}
impl HuffDef {
+ #[allow(clippy::identity_op)]
fn read(&mut self, br: &mut BitReader, codes: &mut Vec<FullCodebookDesc<u8>>, prefix: u32, len: u8) -> DecoderResult<()> {
validate!(len <= self.max_bits);
if !br.read_bool()? {
}
#[allow(clippy::erasing_op)]
+#[allow(clippy::identity_op)]
impl DeltaState {
fn apply_y(&mut self, dst: &mut [u8], mut yoff: usize, ystride: usize, ydeltas: &[i32; 16], last: &mut [i32]) {
for y in 0..4 {
impl TM2Decoder {
fn new() -> Self { Self::default() }
- #[allow(clippy::manual_memcpy)]
fn decode_blocks(&mut self) -> DecoderResult<bool> {
let ydst = &mut self.cur_frame.ydata;
let udst = &mut self.cur_frame.udata;
}
dstate.apply_c(udst, offs[1] + bx * 2, cstride, &cdeltas[0], 0, &mut lastu[bx*2+1..]);
dstate.apply_c(vdst, offs[1] + bx * 2, cstride, &cdeltas[1], 1, &mut lastv[bx*2+1..]);
- for i in 0..4*4 {
- ydeltas[i] = self.streams[TM2StreamType::LHigh as usize].get_token()?;
+ for yd in ydeltas.iter_mut() {
+ *yd = self.streams[TM2StreamType::LHigh as usize].get_token()?;
}
dstate.apply_y(ydst, offs[0] + bx * 4, ystride, &ydeltas, &mut lasty[bx*4+1..]);
},
dstate.apply_c(udst, offs[1] + bx * 2, cstride, &cdeltas[0], 0, &mut lastu[bx*2+1..]);
dstate.interpolate_c(1, &mut lastv[bx*2..]);
dstate.apply_c(vdst, offs[1] + bx * 2, cstride, &cdeltas[1], 1, &mut lastv[bx*2+1..]);
- for i in 0..4*4 {
- ydeltas[i] = self.streams[TM2StreamType::LHigh as usize].get_token()?;
+ for yd in ydeltas.iter_mut() {
+ *yd = self.streams[TM2StreamType::LHigh as usize].get_token()?;
}
dstate.apply_y(ydst, offs[0] + bx * 4, ystride, &ydeltas, &mut lasty[bx*4+1..]);
},
TM2BlockType::Still => {
is_intra = false;
- let mut coff = offs[1] + bx * 2;
- let usrc = &self.prev_frame.udata;
- let vsrc = &self.prev_frame.vdata;
- for _ in 0..2 {
- for x in 0..2 {
- udst[coff + x] = usrc[coff + x];
- vdst[coff + x] = vsrc[coff + x];
- }
- coff += cstride;
+ let coff = offs[1] + bx * 2;
+ for (dline, sline) in udst[coff..].chunks_mut(cstride)
+ .zip(self.prev_frame.udata[coff..].chunks(cstride)).take(2) {
+ dline[..2].copy_from_slice(&sline[..2]);
}
- dstate.recalc_c(udst, offs[1] + bx * 2, cstride, 0, &mut lastu[bx*2+1..]);
- dstate.recalc_c(vdst, offs[1] + bx * 2, cstride, 1, &mut lastv[bx*2+1..]);
- let mut yoff = offs[0] + bx * 4;
- let ysrc = &self.prev_frame.ydata;
- for _ in 0..4 {
- for x in 0..4 {
- ydst[yoff + x] = ysrc[yoff + x];
- }
- yoff += ystride;
+ for (dline, sline) in vdst[coff..].chunks_mut(cstride)
+ .zip(self.prev_frame.vdata[coff..].chunks(cstride)).take(2) {
+ dline[..2].copy_from_slice(&sline[..2]);
}
- dstate.recalc_y(ydst, offs[0] + bx * 4, ystride, &mut lasty[bx*4+1..]);
+ dstate.recalc_c(udst, coff, cstride, 0, &mut lastu[bx*2+1..]);
+ dstate.recalc_c(vdst, coff, cstride, 1, &mut lastv[bx*2+1..]);
+ let yoff = offs[0] + bx * 4;
+ for (dline, sline) in ydst[yoff..].chunks_mut(ystride)
+ .zip(self.prev_frame.ydata[yoff..].chunks(ystride)).take(4) {
+ dline[..4].copy_from_slice(&sline[..4]);
+ }
+ dstate.recalc_y(ydst, yoff, ystride, &mut lasty[bx*4+1..]);
},
TM2BlockType::Motion => {
is_intra = false;
let my = self.streams[TM2StreamType::Motion as usize].get_token()?;
let xpos = (((bx as i32) * 4) + mx).max(0).min((self.width - 4) as i32) as usize;
let ypos = (((by as i32) * 4) + my).max(0).min((self.height - 4) as i32) as usize;
- let mut coff = offs[1] + bx * 2;
- let mut csoff = (xpos >> 1) + (ypos >> 1) * cstride;
- let usrc = &self.prev_frame.udata;
- let vsrc = &self.prev_frame.vdata;
- for _ in 0..2 {
- for x in 0..2 {
- udst[coff + x] = usrc[csoff + x];
- vdst[coff + x] = vsrc[csoff + x];
- }
- coff += cstride;
- csoff += cstride;
+ let coff = offs[1] + bx * 2;
+ let csoff = (xpos >> 1) + (ypos >> 1) * cstride;
+ for (dline, sline) in udst[coff..].chunks_mut(cstride)
+ .zip(self.prev_frame.udata[csoff..].chunks(cstride)).take(2) {
+ dline[..2].copy_from_slice(&sline[..2]);
}
- dstate.recalc_c(udst, offs[1] + bx * 2, cstride, 0, &mut lastu[bx*2+1..]);
- dstate.recalc_c(vdst, offs[1] + bx * 2, cstride, 1, &mut lastv[bx*2+1..]);
- let mut yoff = offs[0] + bx * 4;
- let mut ysoff = xpos + ypos * ystride;
- let ysrc = &self.prev_frame.ydata;
- for _ in 0..4 {
- for x in 0..4 {
- ydst[yoff + x] = ysrc[ysoff + x];
- }
- yoff += ystride;
- ysoff += ystride;
+ for (dline, sline) in vdst[coff..].chunks_mut(cstride)
+ .zip(self.prev_frame.vdata[csoff..].chunks(cstride)).take(2) {
+ dline[..2].copy_from_slice(&sline[..2]);
}
- dstate.recalc_y(ydst, offs[0] + bx * 4, ystride, &mut lasty[bx*4+1..]);
+ dstate.recalc_c(udst, coff, cstride, 0, &mut lastu[bx*2+1..]);
+ dstate.recalc_c(vdst, coff, cstride, 1, &mut lastv[bx*2+1..]);
+ let yoff = offs[0] + bx * 4;
+ let ysoff = xpos + ypos * ystride;
+ for (dline, sline) in ydst[yoff..].chunks_mut(ystride)
+ .zip(self.prev_frame.ydata[ysoff..].chunks(ystride)).take(4) {
+ dline[..4].copy_from_slice(&sline[..4]);
+ }
+ dstate.recalc_y(ydst, yoff, ystride, &mut lasty[bx*4+1..]);
},
};
}
Ok(())
}
- #[allow(clippy::int_plus_one)]
- #[allow(clippy::manual_memcpy)]
#[allow(clippy::cognitive_complexity)]
+ #[allow(clippy::identity_op)]
fn decode_frame(&mut self, src: &[u8]) -> DecoderResult<()> {
let mut mr = MemoryReader::new_read(src);
let mut br = ByteReader::new(&mut mr);
upred = 0;
vpred = 0;
},
+ #[allow(clippy::int_plus_one)]
CPARAM_MV => {
let src_x = (bx as i16) * 8 + self.blk_info[x].mv_x;
let src_y = ((by * 8 + line) as i16) + self.blk_info[x].mv_y;
validate!(src_x >= 0 && (src_x as usize) + 8 <= self.width);
validate!(src_y >= 0 && (src_y as usize) + 1 <= self.height);
let ref_off = (src_x as usize) + ((src_y + 1) as usize) * stride;
- for i in 0..8 {
- ydata[cur_off + i] = self.ref_frame.ydata[ref_off + i];
- udata[cur_off + i] = self.ref_frame.udata[ref_off + i];
- vdata[cur_off + i] = self.ref_frame.vdata[ref_off + i];
- }
+ ydata[cur_off..][..8].copy_from_slice(&self.ref_frame.ydata[ref_off..][..8]);
+ udata[cur_off..][..8].copy_from_slice(&self.ref_frame.udata[ref_off..][..8]);
+ vdata[cur_off..][..8].copy_from_slice(&self.ref_frame.vdata[ref_off..][..8]);
ypred = ydata[cur_off + 7] - ydata[cur_off + 7 - stride];
upred = udata[cur_off + 7] - udata[cur_off + 7 - stride];
vpred = vdata[cur_off + 7] - vdata[cur_off + 7 - stride];
hdr[i - 1] = src[i] ^ src[i + 1];
}
let dbits = hdr[1];
- validate!(dbits >= 2 && dbits <= 4);
+ validate!((2..=4).contains(&dbits));
let hscale = hdr[3] != 0;
let width = (hdr[7] as usize) | ((hdr[8] as usize) << 8);
let height = (hdr[5] as usize) | ((hdr[6] as usize) << 8);
let sym = (VP30_CRUN1_LUT[idx] >> 4) as usize;
let bits = VP30_CRUN1_LUT[idx] & 0xF;
br.skip(u32::from(bits))?;
- if sym < 7 {
- Ok(sym)
- } else if sym == 7 {
- Ok(7 + (br.read(3)? as usize))
- } else {
- let len = br.read_code(UintCodeType::Unary012)?;
- match len {
- 0 => Ok(15 + (br.read(5)? as usize)),
- 1 => Ok(47 + (br.read(8)? as usize)),
- _ => Ok(303 + (br.read(16)? as usize)),
+ match sym {
+ 0..=6 => Ok(sym),
+ 7 => Ok(7 + (br.read(3)? as usize)),
+ _ => {
+ let len = br.read_code(UintCodeType::Unary012)?;
+ match len {
+ 0 => Ok(15 + (br.read(5)? as usize)),
+ 1 => Ok(47 + (br.read(8)? as usize)),
+ _ => Ok(303 + (br.read(16)? as usize)),
+ }
}
}
}
let nblks = *nblk as usize;
if *coded {
let mut cb = [false; 4];
- for j in 0..nblks {
+ for cb in cb[..nblks].iter_mut() {
if run == 0 {
bit = !bit;
run = if bit { vp30_read_coded_run1(br)? } else { vp30_read_coded_run0(br)? };
}
run -= 1;
- cb[j] = bit;
+ *cb = bit;
}
- for j in 0..nblks {
- let addr = self.blk_addr[cur_blk + j] >> 2;
- self.blocks[addr].coded = cb[j];
+ for (&cb, &blk_addr) in cb.iter()
+ .zip(self.blk_addr[cur_blk..].iter()).take(nblks) {
+ self.blocks[blk_addr >> 2].coded = cb;
}
}
cur_blk += nblks;
}
Ok(())
}
+ #[allow(clippy::identity_op)]
fn vp31_unpack_mv_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
let mut last_mv = ZERO_MV;
let mut last2_mv = ZERO_MV;
}
}
}
- for i in 0..nblks {
- self.blocks[addrs[i]].coded = (pat & 8) != 0;
+ for &addr in addrs[..nblks].iter() {
+ self.blocks[addr].coded = (pat & 8) != 0;
pat <<= 1;
cur_blk += 1;
}
}
if pp == 0 { return self.last_dc[ref_id as usize]; }
let mut pred = 0i32;
- for i in 0..4 {
+ for (i, (&pred_val, &dc_weight)) in preds.iter().zip(VP31_DC_WEIGHTS[pp].iter()).enumerate() {
if (pp & (1 << i)) != 0 {
- pred += preds[i] * i32::from(VP31_DC_WEIGHTS[pp][i]);
+ pred += pred_val * i32::from(dc_weight);
}
}
pred /= i32::from(VP31_DC_WEIGHTS[pp][4]);
}
pred as i16
}
+ #[allow(clippy::identity_op)]
fn vp40_predict_dc(&self, bx: usize, by: usize, bw: usize, bh: usize, blk_idx: usize, mask: usize, is_luma: bool) -> i16 {
let mut preds = [0i32; 4];
let mut pp: usize = 0;
if pp == 0 { return self.last_dc[ref_id as usize]; }
let mut pred = 0i32;
let mut npred = 0;
- for i in 0..4 {
+ for (i, &pred_val) in preds.iter().enumerate() {
if (pp & (1 << i)) != 0 {
- pred += preds[i];
+ pred += pred_val;
npred += 1;
if npred == 2 {
return (pred / 2) as i16;
}
}
#[allow(clippy::cognitive_complexity)]
+ #[allow(clippy::collapsible_else_if)]
fn output_blocks_inter(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
let mut blk_idx = 0;
let bstride = self.mb_w * 2;
mv_sum.y = (mv_sum.y + 2) >> 2;
let src = self.shuf.get_last().unwrap();
- for i in 0..4 {
+ for (i, mv) in mvs.iter().enumerate() {
let xoff = (i & 1) * 8;
let yoff = (i >> 1) * 8;
- let mode = vp3_mv_mode(mvs[i].x, mvs[i].y);
+ let mode = vp3_mv_mode(mv.x, mv.y);
if self.version != 4 {
copy_block(frm, src.clone(), 0, bx * 8 + xoff, by * 8 + yoff,
- mvs[i].x >> 1, mvs[i].y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
+ mv.x >> 1, mv.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
} else {
vp_copy_block(frm, src.clone(), 0, bx * 8 + xoff, by * 8 + yoff,
- mvs[i].x >> 1, mvs[i].y >> 1, 0, 1, self.loop_str,
+ mv.x >> 1, mv.y >> 1, 0, 1, self.loop_str,
mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
}
}
self.sb_mbs.push(nmbs);
let mut nblocks = 0;
- for blk_no in 0..16 {
- let bx = x * 4 + HILBERT_ORDER[blk_no][0];
- let by = y * 4 + HILBERT_ORDER[blk_no][1];
+ for (blk_no, order) in HILBERT_ORDER.iter().enumerate() {
+ let bx = x * 4 + order[0];
+ let by = y * 4 + order[1];
if (bx >= blk_w) || (by >= blk_h) { continue; }
let idx = base_idx + bx + by * blk_w;
self.blk_addr.push(idx * 4 + plane);
Err(DecoderError::InvalidData)
}
}
+ #[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);
}
Ok(())
}
+ #[allow(clippy::needless_range_loop)]
fn decode_coeff_models(&self, bc: &mut BoolCoder, models: &mut VP56Models, is_intra: bool) -> DecoderResult<()> {
const COEF_PROBS: [[u8; 11]; 2] = [
[ 146, 197, 181, 207, 232, 243, 238, 251, 244, 250, 249 ],
];
let mut def_prob = [128u8; 11];
- for plane in 0..2 {
- for i in 0..11 {
- if bc.read_prob(COEF_PROBS[plane][i]) {
- def_prob[i] = bc.read_probability();
- models.coeff_models[plane].dc_value_probs[i] = def_prob[i];
+ for (coef_mdl, coef_probs) in models.coeff_models.iter_mut().zip(COEF_PROBS.iter()) {
+ for ((dc_prob, def_prob), &coef_prob) in coef_mdl.dc_value_probs.iter_mut()
+ .zip(def_prob.iter_mut()).zip(coef_probs.iter()) {
+ if bc.read_prob(coef_prob) {
+ *def_prob = bc.read_probability();
+ *dc_prob = *def_prob;
} else if is_intra {
- models.coeff_models[plane].dc_value_probs[i] = def_prob[i];
+ *dc_prob = *def_prob;
}
}
}
}
}
}
- for plane in 0..2 {
- let mdl = &mut models.coeff_models[plane];
+ for mdl in models.coeff_models.iter_mut() {
for i in 0..6 {
for j in 0..6 {
for k in 0..5 {
pub const TOKEN_EOB: u8 = 42;
#[derive(Clone,Copy,Debug,Default)]
-#[allow(dead_code)]
pub struct VP56Header {
pub is_intra: bool,
pub is_golden: bool,
}
}
+#[allow(clippy::identity_op)]
impl VP6Huff {
fn build_codes(&mut self, probs: &[u8; 11]) {
let mut weights = [0u8; 12];
for w in weights.iter().rev() {
let weight = u16::from(*w);
let mut pos = nlen;
- for i in 0..nlen {
- if nodes[i].weight > weight {
+ for (i, node) in nodes[..nlen].iter().enumerate() {
+ if node.weight > weight {
pos = i;
break;
}
pub fn flush(&mut self) {
self.shuf.clear();
}
+ #[allow(clippy::collapsible_else_if)]
pub fn decode_frame(&mut self, supp: &mut NADecoderSupport, src: &[u8], br: &mut dyn VP56Parser) -> DecoderResult<(NABufferType, FrameType)> {
let aoffset;
let mut bc;
self.models.prob_xmitted.copy_from_slice(&DEFAULT_XMITTED_PROBS);
}
fn decode_mode_prob_models(&mut self, bc: &mut BoolCoder) -> DecoderResult<()> {
- for ctx in 0..3 {
+ for (prob_xmitted, vq_modes) in self.models.prob_xmitted.iter_mut().zip(VP56_MODE_VQ.iter()) {
if bc.read_prob(174) {
let idx = bc.read_bits(4) as usize;
- for i in 0..20 {
- self.models.prob_xmitted[ctx][i ^ 1] = VP56_MODE_VQ[ctx][idx][i];
+ for (i, &vq_mode) in vq_modes[idx].iter().enumerate() {
+ prob_xmitted[i ^ 1] = vq_mode;
}
}
if bc.read_prob(254) {
validate!(diff < 256);
let diff = diff as u8;
if !sign {
- validate!(self.models.prob_xmitted[ctx][set ^ 1] <= 255 - diff);
- self.models.prob_xmitted[ctx][set ^ 1] += diff;
+ validate!(prob_xmitted[set ^ 1] <= 255 - diff);
+ prob_xmitted[set ^ 1] += diff;
} else {
- validate!(self.models.prob_xmitted[ctx][set ^ 1] >= diff);
- self.models.prob_xmitted[ctx][set ^ 1] -= diff;
+ validate!(prob_xmitted[set ^ 1] >= diff);
+ prob_xmitted[set ^ 1] -= diff;
}
}
}
}
}
- for ctx in 0..3 {
- let prob_xmitted = &self.models.prob_xmitted[ctx];
- for mode in 0..10 {
- let mdl = &mut self.models.mbtype_models[ctx][mode];
+ for (prob_xmitted, mbtype_models) in self.models.prob_xmitted.iter()
+ .zip(self.models.mbtype_models.iter_mut()) {
+ for (mode, mdl) in mbtype_models.iter_mut().enumerate() {
let mut cnt = [0u32; 10];
let mut total = 0;
for i in 0..10 {
Ok(self.last_mbt)
}
#[allow(clippy::cognitive_complexity)]
+ #[allow(clippy::collapsible_else_if)]
fn decode_mb(&mut self, frm: &mut NASimpleVideoFrame<u8>, bc: &mut BoolCoder, cr: &mut CoeffReader, br: &mut dyn VP56Parser, hdr: &VP56Header, alpha: bool) -> DecoderResult<()> {
const FOURMV_SUB_TYPE: [VPMBType; 4] = [ VPMBType::InterNoMV, VPMBType::InterMV, VPMBType::InterNearest, VPMBType::InterNear ];
self.mb_info[mb_pos].mv = near_mv;
},
VPMBType::InterFourMV => {
- for i in 0..4 {
- four_mbt[i] = FOURMV_SUB_TYPE[bc.read_bits(2) as usize];
+ for mbt in four_mbt.iter_mut() {
+ *mbt = FOURMV_SUB_TYPE[bc.read_bits(2) as usize];
}
- for i in 0..4 {
- match four_mbt[i] {
+ for (&mbt, mv) in four_mbt.iter().zip(four_mv.iter_mut()) {
+ match mbt {
VPMBType::InterNoMV => {},
VPMBType::InterMV => {
let diff_mv = self.decode_mv(bc, br);
- four_mv[i] = pred_mv + diff_mv;
+ *mv = pred_mv + diff_mv;
},
VPMBType::InterNearest => {
- four_mv[i] = nearest_mv;
+ *mv = nearest_mv;
},
VPMBType::InterNear => {
- four_mv[i] = near_mv;
+ *mv = near_mv;
},
_ => unreachable!(),
};
}
Ok(())
}
+ #[allow(clippy::identity_op)]
fn do_mc(&mut self, br: &dyn VP56Parser, frm: &mut NASimpleVideoFrame<u8>, mb_type: VPMBType, mv: MV, alpha: bool) {
let x = self.fstate.mb_x * 16;
let y = self.fstate.mb_y * 16;
let y = self.fstate.mb_y * 16;
let plane = if !alpha { 0 } else { 3 };
let src = self.shuf.get_last().unwrap();
- for blk_no in 0..4 {
+ for (blk_no, &mv) in mvs.iter().enumerate() {
br.mc_block(frm, self.mc_buf.clone(), src.clone(),
plane, x + (blk_no & 1) * 8, y + (blk_no & 2) * 4,
- mvs[blk_no], self.loop_thr);
+ mv, self.loop_thr);
}
if !alpha {
let x = self.fstate.mb_x * 8;
}
Ok(())
}
+ #[allow(clippy::needless_range_loop)]
fn decode_coeff_models(&self, bc: &mut BoolCoder, models: &mut VP56Models, is_intra: bool) -> DecoderResult<()> {
let mut def_prob = [128u8; 11];
for plane in 0..2 {
}
}
}
- for plane in 0..2 {
- let mdl = &mut models.coeff_models[plane];
+ for mdl in models.coeff_models.iter_mut() {
for i in 0..3 {
for k in 0..5 {
mdl.dc_token_probs[0][i][k] = rescale_prob(mdl.dc_value_probs[k], &VP6_DC_WEIGHTS[k][i], 255);
}
}
-//#[allow(snake_case)]
#[cfg(not(target_arch = "x86_64"))]
pub fn mc_bilinear(dst: &mut [u8], dstride: usize, src: &[u8], mut soff: usize, sstride: usize, mx: u16, my: u16) {
if my == 0 {
}
}
-#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn mc_bicubic(dst: &mut [u8], dstride: usize, src: &[u8], mut soff: usize, sstride: usize, coeffs_w: &[i16; 4], coeffs_h: &[i16; 4]) {
if coeffs_h[1] == 128 {
for dline in dst.chunks_mut(dstride).take(8) {
Ok(())
}
+#[allow(clippy::needless_range_loop)]
pub fn encode_coeff_models(bc: &mut BoolEncoder, models: &mut VP56Models, pmodels: &VP56Models, is_intra: bool, interlaced: bool) -> EncoderResult<()> {
let mut def_prob = [128u8; 11];
for plane in 0..2 {
const MAX_DIST: u32 = std::u32::MAX;
const DIST_THRESH: u32 = 256;
+#[allow(clippy::wrong_self_convention)]
trait FromPixels {
fn from_pixels(self) -> Self;
}
mod coder;
use coder::*;
+#[allow(clippy::identity_op)]
+#[allow(clippy::needless_range_loop)]
mod dsp;
use dsp::MVSearchMode;
mod huff;
use huff::*;
+#[allow(clippy::needless_range_loop)]
mod mb;
use mb::*;
mod models;
fn determine_coeff_runs_luma(&self, hstate: &mut HuffState, mb_pos: usize, blk: usize) {
let mb = self.fenc.get_mb(mb_pos);
- if !hstate.dc_zr_coded[0] {
- if mb.coeffs[blk].no_dc() {
- hstate.dc_zero_run[0] = 0;
- let mut blk_no = (blk + 1) & 3;
- let mut mb_no = mb_pos + ((blk + 1) >> 2);
- let mut cmb = mb;
- let mut last_mb_no = mb_pos;
- while (hstate.dc_zero_run[0] < MAX_EOB_RUN) && (mb_no < self.mb_w * self.mb_h) {
- if mb_no != last_mb_no {
- cmb = self.fenc.get_mb(mb_no);
- last_mb_no = mb_no;
- }
- if !cmb.coeffs[blk_no].no_dc() {
- break;
- }
- hstate.dc_zero_run[0] += 1;
- blk_no += 1;
- if blk_no == 4 {
- blk_no = 0;
- mb_no += 1;
- }
+ if !hstate.dc_zr_coded[0] && mb.coeffs[blk].no_dc() {
+ hstate.dc_zero_run[0] = 0;
+ let mut blk_no = (blk + 1) & 3;
+ let mut mb_no = mb_pos + ((blk + 1) >> 2);
+ let mut cmb = mb;
+ let mut last_mb_no = mb_pos;
+ while (hstate.dc_zero_run[0] < MAX_EOB_RUN) && (mb_no < self.mb_w * self.mb_h) {
+ if mb_no != last_mb_no {
+ cmb = self.fenc.get_mb(mb_no);
+ last_mb_no = mb_no;
+ }
+ if !cmb.coeffs[blk_no].no_dc() {
+ break;
+ }
+ hstate.dc_zero_run[0] += 1;
+ blk_no += 1;
+ if blk_no == 4 {
+ blk_no = 0;
+ mb_no += 1;
}
}
}
- if !hstate.ac_zr_coded[0] {
- if mb.coeffs[blk].no_ac() {
- hstate.ac_zero_run[0] = 0;
- let mut blk_no = (blk + 1) & 3;
- let mut mb_no = mb_pos + ((blk + 1) >> 2);
- let mut cmb = mb;
- let mut last_mb_no = mb_pos;
- while (hstate.ac_zero_run[0] < MAX_EOB_RUN) && (mb_no < self.mb_w * self.mb_h) {
- if mb_no != last_mb_no {
- cmb = self.fenc.get_mb(mb_no);
- last_mb_no = mb_no;
- }
- if !cmb.coeffs[blk_no].no_ac() {
- break;
- }
- hstate.ac_zero_run[0] += 1;
- blk_no += 1;
- if blk_no == 4 {
- blk_no = 0;
- mb_no += 1;
- }
+ if !hstate.ac_zr_coded[0] && mb.coeffs[blk].no_ac() {
+ hstate.ac_zero_run[0] = 0;
+ let mut blk_no = (blk + 1) & 3;
+ let mut mb_no = mb_pos + ((blk + 1) >> 2);
+ let mut cmb = mb;
+ let mut last_mb_no = mb_pos;
+ while (hstate.ac_zero_run[0] < MAX_EOB_RUN) && (mb_no < self.mb_w * self.mb_h) {
+ if mb_no != last_mb_no {
+ cmb = self.fenc.get_mb(mb_no);
+ last_mb_no = mb_no;
+ }
+ if !cmb.coeffs[blk_no].no_ac() {
+ break;
+ }
+ hstate.ac_zero_run[0] += 1;
+ blk_no += 1;
+ if blk_no == 4 {
+ blk_no = 0;
+ mb_no += 1;
}
}
}
let mb = self.fenc.get_mb(mb_pos);
let blk = plane + 3;
- if !hstate.dc_zr_coded[1] {
- if mb.coeffs[blk].no_dc() {
- hstate.dc_zero_run[1] = 0;
- let mut blk_no = if blk == 4 { 5 } else { 4 };
- let mut mb_no = mb_pos + if blk == 4 { 0 } else { 1 };
- while (hstate.dc_zero_run[1] < MAX_EOB_RUN) && (mb_no < self.mb_w * self.mb_h) {
- let mb = self.fenc.get_mb(mb_no);
- if !mb.coeffs[blk_no].no_dc() {
- break;
- }
- hstate.dc_zero_run[1] += 1;
- blk_no += 1;
- if blk_no == 6 {
- blk_no = 4;
- mb_no += 1;
- }
+ if !hstate.dc_zr_coded[1] && mb.coeffs[blk].no_dc() {
+ hstate.dc_zero_run[1] = 0;
+ let mut blk_no = if blk == 4 { 5 } else { 4 };
+ let mut mb_no = mb_pos + if blk == 4 { 0 } else { 1 };
+ while (hstate.dc_zero_run[1] < MAX_EOB_RUN) && (mb_no < self.mb_w * self.mb_h) {
+ let mb = self.fenc.get_mb(mb_no);
+ if !mb.coeffs[blk_no].no_dc() {
+ break;
+ }
+ hstate.dc_zero_run[1] += 1;
+ blk_no += 1;
+ if blk_no == 6 {
+ blk_no = 4;
+ mb_no += 1;
}
}
}
- if !hstate.ac_zr_coded[1] {
- if mb.coeffs[blk].no_ac() {
- hstate.ac_zero_run[1] = 0;
- let mut blk_no = if blk == 4 { 5 } else { 4 };
- let mut mb_no = mb_pos + if blk == 4 { 0 } else { 1 };
- while (hstate.ac_zero_run[1] < MAX_EOB_RUN) && (mb_no < self.mb_w * self.mb_h) {
- let mb = self.fenc.get_mb(mb_no);
- if !mb.coeffs[blk_no].no_ac() {
- break;
- }
- hstate.ac_zero_run[1] += 1;
- blk_no += 1;
- if blk_no == 6 {
- blk_no = 4;
- mb_no += 1;
- }
+ if !hstate.ac_zr_coded[1] && mb.coeffs[blk].no_ac() {
+ hstate.ac_zero_run[1] = 0;
+ let mut blk_no = if blk == 4 { 5 } else { 4 };
+ let mut mb_no = mb_pos + if blk == 4 { 0 } else { 1 };
+ while (hstate.ac_zero_run[1] < MAX_EOB_RUN) && (mb_no < self.mb_w * self.mb_h) {
+ let mb = self.fenc.get_mb(mb_no);
+ if !mb.coeffs[blk_no].no_ac() {
+ break;
+ }
+ hstate.ac_zero_run[1] += 1;
+ blk_no += 1;
+ if blk_no == 6 {
+ blk_no = 4;
+ mb_no += 1;
}
}
}
}
}
+#[allow(clippy::identity_op)]
impl VP6Huff {
pub fn build_codes(&mut self, probs: &[u8; 11]) {
let mut weights = [0u8; 12];
for w in weights.iter().rev() {
let weight = u16::from(*w);
let mut pos = nlen;
- for i in 0..nlen {
- if nodes[i].weight > weight {
+ for (i, node) in nodes[..nlen].iter().enumerate() {
+ if node.weight > weight {
pos = i;
break;
}
Ok(())
}
fn read_dct_coef_prob_upd(&mut self, bc: &mut BoolCoder) -> DecoderResult<()> {
- for i in 0..4 {
- for j in 0..8 {
- for k in 0..3 {
- for l in 0..11 {
- if bc.read_prob(DCT_UPDATE_PROBS[i][j][k][l]) {
- self.dstate.coef_probs[i][j][k][l] = bc.read_byte();
+ for (probs, upd_probs) in self.dstate.coef_probs.iter_mut().zip(DCT_UPDATE_PROBS.iter()) {
+ for (probs, upd_probs) in probs.iter_mut().zip(upd_probs.iter()) {
+ for (probs, upd_probs) in probs.iter_mut().zip(upd_probs.iter()) {
+ for (prob, &upd_prob) in probs.iter_mut().zip(upd_probs.iter()) {
+ if bc.read_prob(upd_prob) {
+ *prob = bc.read_byte();
}
}
}
Ok(())
}
fn read_mv_prob_upd(&mut self, bc: &mut BoolCoder) -> DecoderResult<()> {
- for comp in 0..2 {
- for i in 0..17 {
- if bc.read_prob(MV_UPDATE_PROBS[comp][i]) {
- self.dstate.mv_probs[comp][i] = bc.read_probability();
+ for (probs, upd_probs) in self.dstate.mv_probs.iter_mut().zip(MV_UPDATE_PROBS.iter()) {
+ for (prob, &upd_prob) in probs.iter_mut().zip(upd_probs.iter()) {
+ if bc.read_prob(upd_prob) {
+ *prob = bc.read_probability();
}
}
}
}
sbparams.scan = &self.scan;
sbparams.qmat = &self.qmat[qmat_idx][0];
- for i in 0..16 {
+ let (y_coeffs, c_coeffs) = self.coeffs.split_at_mut(16);
+ for (i, (coeffs, y_has_ac)) in y_coeffs.iter_mut().zip(has_ac.iter_mut()).enumerate() {
let bx = i & 3;
let by = i >> 2;
let pred = &self.pcache.y_pred;
let pidx = pred.xpos + mb_x * 4 + bx + by * pred.stride;
let pctx = self.pcache.y_pred_left[by] + pred.data[pidx - pred.stride];
- let has_nz = decode_subblock(bc, &mut self.coeffs[i], ytype, pctx, &sbparams);
+ let has_nz = decode_subblock(bc, coeffs, ytype, pctx, &sbparams);
self.pcache.y_pred.data[pidx] = has_nz;
self.pcache.y_pred_left[by] = has_nz;
- has_ac[i] = has_nz > 0;
+ *y_has_ac = has_nz > 0;
}
sbparams.qmat = &self.qmat[qmat_idx][1];
- for i in 16..20 {
+ let (u_coeffs, v_coeffs) = c_coeffs.split_at_mut(4);
+ let (u_has_ac, v_has_ac) = has_ac[16..24].split_at_mut(4);
+ for (i, (coeffs, u_has_ac)) in u_coeffs.iter_mut().zip(u_has_ac.iter_mut()).enumerate() {
let bx = i & 1;
let by = (i >> 1) & 1;
let pred = &self.pcache.u_pred;
let pidx = pred.xpos + mb_x * 2 + bx + by * pred.stride;
let pctx = self.pcache.u_pred_left[by] + pred.data[pidx - pred.stride];
- let has_nz = decode_subblock(bc, &mut self.coeffs[i], 2, pctx, &sbparams);
+ let has_nz = decode_subblock(bc, coeffs, 2, pctx, &sbparams);
self.pcache.u_pred.data[pidx] = has_nz;
self.pcache.u_pred_left[by] = has_nz;
- has_ac[i] = has_nz > 0;
+ *u_has_ac = has_nz > 0;
}
- for i in 20..24 {
+ for (i, (coeffs, v_has_ac)) in v_coeffs.iter_mut().zip(v_has_ac.iter_mut()).enumerate() {
let bx = i & 1;
let by = (i >> 1) & 1;
let pred = &self.pcache.v_pred;
let pidx = pred.xpos + mb_x * 2 + bx + by * pred.stride;
let pctx = self.pcache.v_pred_left[by] + pred.data[pidx - pred.stride];
- let has_nz = decode_subblock(bc, &mut self.coeffs[i], 2, pctx, &sbparams);
+ let has_nz = decode_subblock(bc, coeffs, 2, pctx, &sbparams);
self.pcache.v_pred.data[pidx] = has_nz;
self.pcache.v_pred_left[by] = has_nz;
- has_ac[i] = has_nz > 0;
+ *v_has_ac = has_nz > 0;
}
if self.dstate.has_y2 {
self.coeffs[i][0] = self.coeffs[24][i];
}
}
- for i in 0..24 {
- if has_ac[i] {
- idct4x4(&mut self.coeffs[i]);
- } else if self.coeffs[i][0] != 0 {
- idct4x4_dc(&mut self.coeffs[i]);
+ for (&has_ac, coeffs) in has_ac.iter().zip(self.coeffs.iter_mut()).take(24) {
+ if has_ac {
+ idct4x4(coeffs);
+ } else if coeffs[0] != 0 {
+ idct4x4_dc(coeffs);
}
}
}
}
ct[idx] += weight;
}
+ #[allow(clippy::collapsible_else_if)]
let pred_mv = if ct[1] > ct[2] {
if ct[1] >= ct[0] { nearest_mv } else { ZERO_MV }
} else {
mvidx += self.mv_stride;
}
},
+ #[allow(clippy::identity_op)]
MVSplitMode::LeftRight => {
let left_mv = self.get_split_mv(bc, mb_x, mb_y, 0, 0, pred_mv);
self.mvs[mvidx + 1] = left_mv;
let oidx = x + y * 4 + 4;
for i in 0..4 {
for j in 0..4 {
- tmpblock[i * 8 + 0 + j] = self.coeffs[eidx][i * 4 + j];
+ tmpblock[i * 8 + j] = self.coeffs[eidx][i * 4 + j];
tmpblock[i * 8 + 4 + j] = self.coeffs[oidx][i * 4 + j];
}
}
self.add_residue(dframe, mb_x, mb_y, is_normal, pitch_mode);
Ok(())
}
+ #[allow(clippy::collapsible_else_if)]
fn recon_inter_mb(&mut self, dframe: &mut NASimpleVideoFrame<u8>, mb_x: usize, mb_y: usize, use_last: bool) {
let pitch = self.dstate.force_pitch.unwrap_or(0);
let pitch_dmode = (pitch >> 3) & 3;
}
}
#[allow(clippy::cognitive_complexity)]
+ #[allow(clippy::collapsible_else_if)]
fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let src = pkt.get_buffer();
}
#[derive(Clone,Copy,PartialEq)]
+#[allow(clippy::upper_case_acronyms)]
pub enum DCTToken {
Zero,
One,
}
pub fn expand_token(bc: &mut BoolCoder, token: DCTToken) -> i16 {
- let cat;
- match token {
- DCTToken::Zero => return 0,
- DCTToken::One => return if bc.read_bool() { -1 } else { 1 },
- DCTToken::Two => return if bc.read_bool() { -2 } else { 2 },
- DCTToken::Three => return if bc.read_bool() { -3 } else { 3 },
- DCTToken::Four => return if bc.read_bool() { -4 } else { 4 },
- DCTToken::Cat1 => cat = 0,
- DCTToken::Cat2 => cat = 1,
- DCTToken::Cat3 => cat = 2,
- DCTToken::Cat4 => cat = 3,
- DCTToken::Cat5 => cat = 4,
- DCTToken::Cat6 => cat = 5,
- _ => unreachable!(),
- };
+ let cat = match token {
+ DCTToken::Zero => return 0,
+ DCTToken::One => return if bc.read_bool() { -1 } else { 1 },
+ DCTToken::Two => return if bc.read_bool() { -2 } else { 2 },
+ DCTToken::Three => return if bc.read_bool() { -3 } else { 3 },
+ DCTToken::Four => return if bc.read_bool() { -4 } else { 4 },
+ DCTToken::Cat1 => 0,
+ DCTToken::Cat2 => 1,
+ DCTToken::Cat3 => 2,
+ DCTToken::Cat4 => 3,
+ DCTToken::Cat5 => 4,
+ DCTToken::Cat6 => 5,
+ _ => unreachable!(),
+ };
let mut add = 0i16;
let add_probs = &VP56_COEF_ADD_PROBS[cat];
for prob in add_probs.iter() {
+use std::cmp::Ordering;
use nihav_core::frame::*;
use nihav_codec_support::codecs::blockdsp::edge_emu;
pub trait IntraPred {
const SIZE: usize;
+ #[allow(clippy::needless_late_init)]
fn ipred_dc(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
let dc;
if !ipred.has_left && !ipred.has_top {
off += stride;
}
}
- pub fn ipred_he(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
+ pub fn ipred_he(dst: &mut [u8], off: usize, stride: usize, ipred: &IPredContext) {
let (p0, p1, p2, _) = load_pred4!(left; ipred);
let p3 = ((u16::from(ipred.left[2]) + u16::from(ipred.left[3]) * 3 + 2) >> 2) as u8;
let hor_pred = [p0, p1, p2, p3];
- for m in 0..4 {
- for n in 0..4 {
- dst[off + n] = hor_pred[m];
+ for (dline, &pred) in dst[off..].chunks_mut(stride).zip(hor_pred.iter()) {
+ for el in dline[..4].iter_mut() {
+ *el = pred;
}
- off += stride;
}
}
pub fn ipred_ld(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
let ha = if plane == 0 { (h + 15) & !15 } else { (h + 7) & !7 } as isize;
let mut start_x = (xpos as isize) + ((mvx >> 3) as isize) - (EDGE_PRE as isize);
let mut end_x = (xpos as isize) + ((mvx >> 3) as isize) + ((size + EDGE_POST) as isize);
- if xstep < 0 {
- start_x -= (size + EDGE_POST) as isize;
- } else if xstep > 0 {
- end_x += (size as isize) * xstep;
+ match xstep.cmp(&0) {
+ Ordering::Less => start_x -= (size + EDGE_POST) as isize,
+ Ordering::Greater => end_x += (size as isize) * xstep,
+ Ordering::Equal => {},
}
let mut start_y = (ypos as isize) + ((mvy >> 3) as isize) - (EDGE_PRE as isize) * ymul;
let mut end_y = (ypos as isize) + ((mvy >> 3) as isize) + ((size + EDGE_POST) as isize) * ymul;
self.dc_last_saved = self.dc_last;
self.dc_count_saved = self.dc_count;
}
- #[allow(dead_code)]
- pub fn restore_dc_pred(&mut self) {
+ /*pub fn restore_dc_pred(&mut self) {
self.dc_last = self.dc_last_saved;
self.dc_count = self.dc_count_saved;
- }
+ }*/
pub fn update_mb_row(&mut self) {
self.left_y = [0x80; 16];
self.left_u = [0x80; 16];
}
ct[idx] += weight;
}
+ #[allow(clippy::collapsible_else_if)]
let pred_mv = if ct[1] > ct[2] {
if ct[1] >= ct[0] { nearest_mv } else { ZERO_MV }
} else {
JustEncode,
}
-#[allow(dead_code)]
struct VP7Encoder {
stream: Option<NAStreamRef>,
pkt: Option<NAPacket>,
const DIST_THRESH: u32 = 256;
pub const LARGE_BLK8_DIST: u32 = 256;
+#[allow(clippy::wrong_self_convention)]
trait FromPixels {
fn from_pixels(self) -> Self;
}
}
}
let mut chroma_avg = [0; 2];
- for chroma in 0..1 {
+ for (chroma, avg_val) in chroma_avg.iter_mut().enumerate() {
for row in self.msa[chroma + 1][chroma_off..].chunks(self.stride[1]).take(8).step_by(Self::BLOCK_SIZE) {
for &el in row.iter().take(8).step_by(Self::BLOCK_SIZE) {
- chroma_avg[chroma] += el;
+ *avg_val += el;
}
}
}
count: usize,
}
-#[allow(dead_code)]
impl MVEstimator {
pub fn new(ref_frame: NAVideoBufferRef<u8>, mc_buf: NAVideoBufferRef<u8>, mv_range: i16) -> Self {
Self {
mc_block8x8(&mut dst.chroma[0], 0, 8, mb_x * 8, mb_y * 8, cur_mv.x, cur_mv.y, self.ref_frame.clone(), 1, tmp_blk);
mc_block8x8(&mut dst.chroma[1], 0, 8, mb_x * 8, mb_y * 8, cur_mv.x, cur_mv.y, self.ref_frame.clone(), 2, tmp_blk);
}
- pub fn get_blk8(&mut self, dst: &mut [u8; 64], plane: usize, x: usize, y: usize, mut cur_mv: MV) {
+ /*pub fn get_blk8(&mut self, dst: &mut [u8; 64], plane: usize, x: usize, y: usize, mut cur_mv: MV) {
if plane == 0 {
cur_mv.x *= 2;
cur_mv.y *= 2;
}
mc_block8x8(dst, 0, 8, x, y, cur_mv.x, cur_mv.y, self.ref_frame.clone(), plane, self.mc_buf.get_data_mut().unwrap());
- }
+ }*/
fn sad_blk8(&mut self, refblk: &[u8; 64], x: usize, y: usize, cur_mv: MV, _best_dist: u32) -> u32 {
mc_block8x8(&mut self.blk8, 0, 8, x, y, cur_mv.x * 2, cur_mv.y * 2, self.ref_frame.clone(), 0, self.mc_buf.get_data_mut().unwrap());
self.count += 1;
(false, _) => 800.0 - (fq - 8.0).ln() * 155.0,
}
}
- #[allow(dead_code)]
// todo use for refining maybe
- pub fn predict_size(&self, is_intra: bool, q: usize) -> u32 {
+ /*pub fn predict_size(&self, is_intra: bool, q: usize) -> u32 {
let min_size = if is_intra { 200 * 8 } else { 50 * 8 };
let nits_per_mb = Self::pred_nits_per_mb(is_intra, q);
((nits_per_mb * (self.num_mb as f32) / 8.0) as u32).max(min_size)
- }
+ }*/
+ #[allow(clippy::collapsible_else_if)]
pub fn get_frame_quant(&self, is_intra: bool) -> usize {
if let Some(q) = self.force_q {
q
}
Ok(())
}
+ #[allow(clippy::collapsible_if)]
fn mb_lf_adjustments(&mut self, bc: &mut BoolCoder) -> DecoderResult<()> {
self.dstate.lf_delta = bc.read_bool();
if self.dstate.lf_delta {
Ok(())
}
fn read_dct_coef_prob_upd(&mut self, bc: &mut BoolCoder) -> DecoderResult<()> {
- for i in 0..4 {
- for j in 0..8 {
- for k in 0..3 {
- for l in 0..11 {
- if bc.read_prob(DCT_UPDATE_PROBS[i][j][k][l]) {
- self.dstate.coef_probs[i][j][k][l] = bc.read_byte();
+ for (probs, upd_probs) in self.dstate.coef_probs.iter_mut().zip(DCT_UPDATE_PROBS.iter()) {
+ for (probs, upd_probs) in probs.iter_mut().zip(upd_probs.iter()) {
+ for (probs, upd_probs) in probs.iter_mut().zip(upd_probs.iter()) {
+ for (prob, &upd_prob) in probs.iter_mut().zip(upd_probs.iter()) {
+ if bc.read_prob(upd_prob) {
+ *prob = bc.read_byte();
}
}
}
[ 237, 246, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 250, 250, 252, 254, 254 ],
[ 231, 243, 245, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 251, 251, 254, 254, 254 ]
];
- for comp in 0..2 {
- for i in 0..19 {
- if bc.read_prob(MV_UPDATE_PROBS[comp][i]) {
- self.dstate.mv_probs[comp][i] = bc.read_probability();
+ for (prob_row, upd_row) in self.dstate.mv_probs.iter_mut()
+ .zip(MV_UPDATE_PROBS.iter()) {
+ for (prob, &upd_prob) in prob_row.iter_mut().zip(upd_row.iter()) {
+ if bc.read_prob(upd_prob) {
+ *prob = bc.read_probability();
}
}
}
ytype = 3;
}
sbparams.qmat = &self.qmat[qmat_idx][0];
- for i in 0..16 {
+ let (y_coeffs, c_coeffs) = self.coeffs.split_at_mut(16);
+ for (i, (coeffs, y_has_ac)) in y_coeffs.iter_mut().zip(has_ac.iter_mut()).enumerate() {
let bx = i & 3;
let by = i >> 2;
let pred = &self.pcache.y_pred;
let pidx = pred.xpos + mb_x * 4 + bx + by * pred.stride;
let pctx = self.pcache.y_pred_left[by] + pred.data[pidx - pred.stride];
- let has_nz = decode_subblock(bc, &mut self.coeffs[i], ytype, pctx, &sbparams);
+ let has_nz = decode_subblock(bc, coeffs, ytype, pctx, &sbparams);
self.pcache.y_pred.data[pidx] = has_nz;
self.pcache.y_pred_left[by] = has_nz;
- has_ac[i] = has_nz > 0;
- coded |= has_ac[i] | (self.coeffs[i][0] != 0);
+ *y_has_ac = has_nz > 0;
+ coded |= *y_has_ac | (coeffs[0] != 0);
}
sbparams.qmat = &self.qmat[qmat_idx][1];
- for i in 16..20 {
+ let (u_coeffs, v_coeffs) = c_coeffs.split_at_mut(4);
+ let (u_has_ac, v_has_ac) = has_ac[16..24].split_at_mut(4);
+ for (i, (coeffs, u_has_ac)) in u_coeffs.iter_mut().zip(u_has_ac.iter_mut()).enumerate() {
let bx = i & 1;
let by = (i >> 1) & 1;
let pred = &self.pcache.u_pred;
let pidx = pred.xpos + mb_x * 2 + bx + by * pred.stride;
let pctx = self.pcache.u_pred_left[by] + pred.data[pidx - pred.stride];
- let has_nz = decode_subblock(bc, &mut self.coeffs[i], 2, pctx, &sbparams);
+ let has_nz = decode_subblock(bc, coeffs, 2, pctx, &sbparams);
self.pcache.u_pred.data[pidx] = has_nz;
self.pcache.u_pred_left[by] = has_nz;
- has_ac[i] = has_nz > 0;
- coded |= has_ac[i] | (self.coeffs[i][0] != 0);
+ *u_has_ac = has_nz > 0;
+ coded |= *u_has_ac | (coeffs[0] != 0);
}
- for i in 20..24 {
+ for (i, (coeffs, v_has_ac)) in v_coeffs.iter_mut().zip(v_has_ac.iter_mut()).enumerate() {
let bx = i & 1;
let by = (i >> 1) & 1;
let pred = &self.pcache.v_pred;
let pidx = pred.xpos + mb_x * 2 + bx + by * pred.stride;
let pctx = self.pcache.v_pred_left[by] + pred.data[pidx - pred.stride];
- let has_nz = decode_subblock(bc, &mut self.coeffs[i], 2, pctx, &sbparams);
+ let has_nz = decode_subblock(bc, coeffs, 2, pctx, &sbparams);
self.pcache.v_pred.data[pidx] = has_nz;
self.pcache.v_pred_left[by] = has_nz;
- has_ac[i] = has_nz > 0;
- coded |= has_ac[i] | (self.coeffs[i][0] != 0);
+ *v_has_ac = has_nz > 0;
+ coded |= *v_has_ac | (coeffs[0] != 0);
}
if self.dstate.has_y2 {
self.coeffs[i][0] = self.coeffs[24][i];
}
}
- for i in 0..24 {
- if has_ac[i] {
- idct4x4(&mut self.coeffs[i]);
- } else if self.coeffs[i][0] != 0 {
- idct4x4_dc(&mut self.coeffs[i]);
+ for (&has_ac, coeffs) in has_ac.iter().zip(self.coeffs.iter_mut()).take(24) {
+ if has_ac {
+ idct4x4(coeffs);
+ } else if coeffs[0] != 0 {
+ idct4x4_dc(coeffs);
}
}
},
}
}
+ #[allow(clippy::identity_op)]
fn do_split_mv(&mut self, bc: &mut BoolCoder, mb_x: usize, mb_y: usize, pred_mv: MV) -> DecoderResult<()> {
let split_mode = bc.read_tree(MV_SPLIT_MODE_TREE, &MV_SPLIT_MODE_PROBS);
let mut mvidx = mb_x * 4 + mb_y * 4 * self.mv_stride;
}
}
#[allow(clippy::cognitive_complexity)]
+ #[allow(clippy::collapsible_else_if)]
fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let src = pkt.get_buffer();
validate!(src.len() > 4);
};
#[derive(Clone,Copy,Debug,PartialEq,Default)]
-#[allow(dead_code)]
pub enum VPMBType {
#[default]
Intra,
pub const VP_REF_INTER: u8 = 1;
pub const VP_REF_GOLDEN: u8 = 2;
-#[allow(dead_code)]
impl VPMBType {
pub fn is_intra(self) -> bool { self == VPMBType::Intra }
pub fn get_ref_id(self) -> u8 {
[ 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 128 ],
];
-#[allow(dead_code)]
pub struct BoolCoder<'a> {
pub src: &'a [u8],
pos: usize,
bits: i32,
}
-#[allow(dead_code)]
impl<'a> BoolCoder<'a> {
pub fn new(src: &'a [u8]) -> DecoderResult<Self> {
if src.len() < 3 { return Err(DecoderError::ShortData); }
}
#[allow(dead_code)]
-#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn rescale_prob(prob: u8, weights: &[i16; 2], maxval: i32) -> u8 {
(((i32::from(prob) * i32::from(weights[0]) + 128) >> 8) + i32::from(weights[1])).min(maxval).max(1) as u8
}
pub fn vp_idct_dc(coeffs: &mut [i16; 64]) {
let dc = ((mul16(C4S4, mul16(C4S4, i32::from(coeffs[0]))) + 8) >> 4) as i16;
- for i in 0..64 {
- coeffs[i] = dc;
+ for coef in coeffs.iter_mut() {
+ *coef = dc;
}
}
pub struct Estimator {}
-#[allow(dead_code)]
impl Estimator {
pub fn new() -> Self { Self{} }
pub fn write_el<T: PartialEq>(&self, el: T, tree: &[TokenSeq<T>], probs: &mut [ProbCounter]) {
pub mod coder;
pub mod models;
#[macro_use]
+#[allow(clippy::upper_case_acronyms)]
pub mod motion_est;
128
}
}
- pub fn to_prob_worthy(&self, old_prob: u8) -> u8 {
+ pub fn to_prob_worthy(self, old_prob: u8) -> u8 {
if self.total > 0 {
let new_prob = self.to_prob();
let new_bits = Self::est_bits(new_prob, self.zeroes, self.total);
use std::str::FromStr;
#[derive(Debug,Clone,Copy,PartialEq,Default)]
-#[allow(dead_code)]
pub enum MVSearchMode {
Full,
SEA,
impl FromStr for MVSearchMode {
type Err = ParseError;
- #[allow(clippy::single_match)]
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"full" => Ok(MVSearchMode::Full),
}
}
+#[allow(clippy::wrong_self_convention)]
trait FromPixels {
fn from_pixels(self) -> Self;
}