From: Kostya Shishkov Date: Fri, 13 Nov 2026 13:50:07 +0000 (+0100) Subject: janitorial: fix clippy warnings/update code style X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=8b7c5b7abf5b03979d0730fb4a9e807f754e0d98;p=nihav.git janitorial: fix clippy warnings/update code style --- diff --git a/nihav-realmedia/src/codecs/ralf.rs b/nihav-realmedia/src/codecs/ralf.rs index 4203655..1ebad04 100644 --- a/nihav-realmedia/src/codecs/ralf.rs +++ b/nihav-realmedia/src/codecs/ralf.rs @@ -65,23 +65,23 @@ impl CodebookSet { let coding_mode_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap(); let mut filter_coeffs_cb: Vec>> = Vec::with_capacity(10); - for i in 0..10 { + for cb_set in RALF_FILTER_COEFFS_TAB[idx].iter() { let mut fcb: Vec> = Vec::with_capacity(11); - for j in 0..11 { - let mut cbr = RALFCodebookDescReader::new(&RALF_FILTER_COEFFS_TAB[idx][i][j], RALF_FILTER_COEFFS_LEN); + for cb in cb_set.iter() { + let mut cbr = RALFCodebookDescReader::new(cb, RALF_FILTER_COEFFS_LEN); fcb.push(Codebook::new(&mut cbr, CodebookMode::MSB).unwrap()); } filter_coeffs_cb.push(fcb); } let mut short_codes_cb: Vec> = Vec::with_capacity(15); - for i in 0..15 { - let mut cbr = RALFCodebookDescReader::new(&RALF_SHORT_CODES_TAB[idx][i], RALF_SHORT_CODES_LEN); + for cb in RALF_SHORT_CODES_TAB[idx].iter() { + let mut cbr = RALFCodebookDescReader::new(cb, RALF_SHORT_CODES_LEN); short_codes_cb.push(Codebook::new(&mut cbr, CodebookMode::MSB).unwrap()); } let mut long_codes_cb: Vec> = Vec::with_capacity(125); - for i in 0..125 { - let mut cbr = RALFCodebookDescReader::new(&RALF_LONG_CODES_TAB[idx][i], RALF_LONG_CODES_LEN); + for cb in RALF_LONG_CODES_TAB[idx].iter() { + let mut cbr = RALFCodebookDescReader::new(cb, RALF_LONG_CODES_LEN); long_codes_cb.push(Codebook::new(&mut cbr, CodebookMode::MSB).unwrap()); } diff --git a/nihav-realmedia/src/codecs/rv3040.rs b/nihav-realmedia/src/codecs/rv3040.rs index 62a258d..bce8d0d 100644 --- a/nihav-realmedia/src/codecs/rv3040.rs +++ b/nihav-realmedia/src/codecs/rv3040.rs @@ -349,14 +349,13 @@ impl MVInfo { let left_mv = if has_left { self.get_mv_by_idx(idx - 1, fwd) } else { ZERO_MV }; let top_mv = if has_top { self.get_mv_by_idx(idx - self.w, fwd) } else { left_mv }; let tr_add = if is16 { 2 } else { 1 }; - let tr_mv; - if has_tr { - tr_mv = self.get_mv_by_idx(idx - self.w + tr_add, fwd); - } else if has_tl { - tr_mv = self.get_mv_by_idx(idx - self.w - 1, fwd); - } else { - tr_mv = left_mv; - } + let tr_mv = if has_tr { + self.get_mv_by_idx(idx - self.w + tr_add, fwd) + } else if has_tl { + self.get_mv_by_idx(idx - self.w - 1, fwd) + } else { + left_mv + }; MV::pred(left_mv, top_mv, tr_mv) } pub fn pred_mb_mv(&self, mb_x: usize, mb_y: usize, fwd: bool, has_top: bool, has_left: bool, has_tr: bool, has_tl: bool) -> MV { diff --git a/nihav-realmedia/src/codecs/rv30dsp.rs b/nihav-realmedia/src/codecs/rv30dsp.rs index 4ec44bd..f750e4d 100644 --- a/nihav-realmedia/src/codecs/rv30dsp.rs +++ b/nihav-realmedia/src/codecs/rv30dsp.rs @@ -270,17 +270,15 @@ impl RV34DSP for RV30DSP { let yoff = offs[0] + mb_x * 16 + y * 4 * stride[0]; for x in xstart..4 { let cs = x + y*4; - let loc_lim; - - if test_bit!(cur_dbk, cs) { - loc_lim = cur_lim; - } else if (x == 0) && test_bit!(left_dbk, cs + 3) { - loc_lim = left_lim; - } else if (x != 0) && test_bit!(cur_dbk, cs - 1) { - loc_lim = cur_lim; - } else { - loc_lim = 0; - } + let loc_lim = if test_bit!(cur_dbk, cs) { + cur_lim + } else if (x == 0) && test_bit!(left_dbk, cs + 3) { + left_lim + } else if (x != 0) && test_bit!(cur_dbk, cs - 1) { + cur_lim + } else { + 0 + }; if loc_lim != 0 { rv30_loop_filter4(dst, yoff + x * 4, 1, stride[0], loc_lim); } @@ -292,17 +290,15 @@ impl RV34DSP for RV30DSP { let coff = offs[comp] + mb_x * 8 + y * 4 * stride[comp]; for x in xstart..2 { let cs = x + y * 2 + (comp - 1) * 4; - let loc_lim; - - if test_bit!(cur_cbp, cs) { - loc_lim = cur_lim; - } else if (x == 0) && test_bit!(left_cbp, cs + 1) { - loc_lim = left_lim; - } else if (x != 0) && test_bit!(cur_cbp, cs - 1) { - loc_lim = cur_lim; - } else { - loc_lim = 0; - } + let loc_lim = if test_bit!(cur_cbp, cs) { + cur_lim + } else if (x == 0) && test_bit!(left_cbp, cs + 1) { + left_lim + } else if (x != 0) && test_bit!(cur_cbp, cs - 1) { + cur_lim + } else { + 0 + }; if loc_lim != 0 { rv30_loop_filter4(dst, coff + x * 4, 1, stride[comp], loc_lim); } @@ -323,33 +319,24 @@ impl RV34DSP for RV30DSP { let cur_dbk = mbinfo[mb_pos].deblock; let cur_cbp = mbinfo[mb_pos].cbp_c; let ystart = if row == 0 { 1 } else { 0 }; - let top_lim; - let top_dbk; - let top_cbp; - if row > 0 { - top_lim = RV30_LOOP_FILTER_STRENGTH[mbinfo[mb_pos - mb_w].q as usize]; - top_dbk = mbinfo[mb_pos - mb_w].deblock; - top_cbp = mbinfo[mb_pos - mb_w].cbp_c; - } else { - top_lim = 0; - top_dbk = 0; - top_cbp = 0; - } + let (top_lim, top_dbk, top_cbp) = if row > 0 { + (RV30_LOOP_FILTER_STRENGTH[mbinfo[mb_pos - mb_w].q as usize], + mbinfo[mb_pos - mb_w].deblock, + mbinfo[mb_pos - mb_w].cbp_c) + } else { (0, 0, 0) }; for y in ystart..4 { let yoff = offs[0] + mb_x * 16 + y * 4 * stride[0]; for x in 0..4 { let cs = x + y*4; - let loc_lim; - - if test_bit!(cur_dbk, cs) { - loc_lim = cur_lim; - } else if (y == 0) && test_bit!(top_dbk, cs + 12) { - loc_lim = top_lim; - } else if (y != 0) && test_bit!(cur_dbk, cs - 4) { - loc_lim = cur_lim; - } else { - loc_lim = 0; - } + let loc_lim = if test_bit!(cur_dbk, cs) { + cur_lim + } else if (y == 0) && test_bit!(top_dbk, cs + 12) { + top_lim + } else if (y != 0) && test_bit!(cur_dbk, cs - 4) { + cur_lim + } else { + 0 + }; if loc_lim != 0 { rv30_loop_filter4(dst, yoff + x * 4, stride[0], 1, loc_lim); } @@ -361,17 +348,15 @@ impl RV34DSP for RV30DSP { let coff = offs[comp] + mb_x * 8 + y * 4 * stride[comp]; for x in 0..2 { let cs = x + y * 2 + (comp - 1) * 4; - let loc_lim; - - if test_bit!(cur_cbp, cs) { - loc_lim = cur_lim; - } else if (y == 0) && test_bit!(top_cbp, cs + 2) { - loc_lim = top_lim; - } else if (y != 0) && test_bit!(cur_cbp, cs - 2) { - loc_lim = cur_lim; - } else { - loc_lim = 0; - } + let loc_lim = if test_bit!(cur_cbp, cs) { + cur_lim + } else if (y == 0) && test_bit!(top_cbp, cs + 2) { + top_lim + } else if (y != 0) && test_bit!(cur_cbp, cs - 2) { + cur_lim + } else { + 0 + }; if loc_lim != 0 { rv30_loop_filter4(dst, coff + x * 4, stride[comp], 1, loc_lim); } diff --git a/nihav-realmedia/src/codecs/rv40.rs b/nihav-realmedia/src/codecs/rv40.rs index a80b481..bca36ee 100644 --- a/nihav-realmedia/src/codecs/rv40.rs +++ b/nihav-realmedia/src/codecs/rv40.rs @@ -182,15 +182,11 @@ impl RV34BitstreamDecoder for RealVideo40BR { let set_idx = br.read(2)? as usize; let deblock = !br.read_bool()?; let pts = br.read(13)? as u16; - let w; - let h; - if (ftype == FrameType::I) || !br.read_bool()? { - w = get_dimension(br, &RV40_STANDARD_WIDTHS)?; - h = get_dimension(br, &RV40_STANDARD_HEIGHTS)?; - } else { - w = old_w; - h = old_h; - } + let (w, h) = if (ftype == FrameType::I) || !br.read_bool()? { + (get_dimension(br, &RV40_STANDARD_WIDTHS)?, get_dimension(br, &RV40_STANDARD_HEIGHTS)?) + } else { + (old_w, old_h) + }; let start = br.read(get_slice_start_offset_bits(w, h))? as usize; self.had_skip_run = false; diff --git a/nihav-realmedia/src/codecs/rv40dsp.rs b/nihav-realmedia/src/codecs/rv40dsp.rs index 466a88d..9826181 100644 --- a/nihav-realmedia/src/codecs/rv40dsp.rs +++ b/nihav-realmedia/src/codecs/rv40dsp.rs @@ -653,77 +653,73 @@ impl RV34DSP for RV40DSP { let bpos = x + y * 4; let ver_strong = (x == 0) && (mb_x > 0) && (is_strong || left_is_strong); - let cur_strength: usize; - if is_strong { - cur_strength = 2; - } else if test_bit!(cur_dbk, bpos) { - cur_strength = 1; - } else { - cur_strength = 0; - } - - let left_strength: usize; - if x > 0 { - if is_strong { - left_strength = 2; - } else if test_bit!(cur_dbk, bpos - 1) { - left_strength = 1; - } else { - left_strength = 0; - } - } else if mb_x > 0 { - if left_is_strong { - left_strength = 2; - } else if test_bit!(left_dbk, bpos + 3) { - left_strength = 1; + let cur_strength = if is_strong { + 2 + } else if test_bit!(cur_dbk, bpos) { + 1 } else { - left_strength = 0; - } - } else { - left_strength = 0; - } + 0 + }; - let bot_strength: usize; - if y < 3 { - if is_strong { - bot_strength = 2; - } else if test_bit!(cur_dbk, bpos + 4) { - bot_strength = 1; - } else { - bot_strength = 0; - } - } else if !is_last_row { - if mbinfo[mb_pos + mb_w].mbtype.is_intra_or_16() { - bot_strength = 2; - } else if test_bit!(bot_dbk, x) { - bot_strength = 1; + let left_strength = if x > 0 { + if is_strong { + 2 + } else if test_bit!(cur_dbk, bpos - 1) { + 1 + } else { + 0 + } + } else if mb_x > 0 { + if left_is_strong { + 2 + } else if test_bit!(left_dbk, bpos + 3) { + 1 + } else { + 0 + } } else { - bot_strength = 0; - } - } else { - bot_strength = 0; - } + 0 + }; - let top_strength: usize; - if y > 0 { - if is_strong { - top_strength = 2; - } else if test_bit!(cur_dbk, bpos - 4) { - top_strength = 1; + let bot_strength = if y < 3 { + if is_strong { + 2 + } else if test_bit!(cur_dbk, bpos + 4) { + 1 + } else { + 0 + } + } else if !is_last_row { + if mbinfo[mb_pos + mb_w].mbtype.is_intra_or_16() { + 2 + } else if test_bit!(bot_dbk, x) { + 1 + } else { + 0 + } } else { - top_strength = 0; - } - } else if row > 0 { - if top_is_strong { - top_strength = 2; - } else if test_bit!(top_dbk, bpos + 12) { - top_strength = 1; + 0 + }; + + let top_strength = if y > 0 { + if is_strong { + 2 + } else if test_bit!(cur_dbk, bpos - 4) { + 1 + } else { + 0 + } + } else if row > 0 { + if top_is_strong { + 2 + } else if test_bit!(top_dbk, bpos + 12) { + 1 + } else { + 0 + } } else { - top_strength = 0; - } - } else { - top_strength = 0; - } + 0 + }; let l_q = if x > 0 { q } else { left_q }; let top_q = if row > 0 { mbinfo[mb_pos - mb_w].q as usize } else { 0 }; @@ -781,77 +777,73 @@ impl RV34DSP for RV40DSP { let ver_strong = (x == 0) && (is_strong || left_is_strong); - let cur_strength: usize; - if is_strong { - cur_strength = 2; - } else if test_bit!(c_cur_cbp, bpos) { - cur_strength = 1; - } else { - cur_strength = 0; - } - - let left_strength: usize; - if x > 0 { - if is_strong { - left_strength = 2; - } else if test_bit!(c_cur_cbp, bpos - 1) { - left_strength = 1; + let cur_strength = if is_strong { + 2 + } else if test_bit!(c_cur_cbp, bpos) { + 1 } else { - left_strength = 0; - } - } else if mb_x > 0 { - if left_is_strong { - left_strength = 2; - } else if test_bit!(c_left_cbp, bpos + 1) { - left_strength = 1; + 0 + }; + + let left_strength = if x > 0 { + if is_strong { + 2 + } else if test_bit!(c_cur_cbp, bpos - 1) { + 1 + } else { + 0 + } + } else if mb_x > 0 { + if left_is_strong { + 2 + } else if test_bit!(c_left_cbp, bpos + 1) { + 1 + } else { + 0 + } } else { - left_strength = 0; - } - } else { - left_strength = 0; - } - - let bot_strength: usize; - if y != 3 { - if is_strong { - bot_strength = 2; - } else if test_bit!(c_cur_cbp, bpos + 2) { - bot_strength = 1; + 0 + }; + + let bot_strength = if y != 3 { + if is_strong { + 2 + } else if test_bit!(c_cur_cbp, bpos + 2) { + 1 + } else { + 0 + } + } else if !is_last_row { + if mbinfo[mb_pos + mb_w].mbtype.is_intra_or_16() { + 2 + } else if test_bit!(c_bot_cbp, x) { + 1 + } else { + 0 + } } else { - bot_strength = 0; - } - } else if !is_last_row { - if mbinfo[mb_pos + mb_w].mbtype.is_intra_or_16() { - bot_strength = 2; - } else if test_bit!(c_bot_cbp, x) { - bot_strength = 1; - } else { - bot_strength = 0; - } - } else { - bot_strength = 0; - } - - let top_strength: usize; - if y > 0 { - if is_strong { - top_strength = 2; - } else if test_bit!(c_cur_cbp, bpos - 2) { - top_strength = 1; + 0 + }; + + let top_strength = if y > 0 { + if is_strong { + 2 + } else if test_bit!(c_cur_cbp, bpos - 2) { + 1 + } else { + 0 + } + } else if row > 0 { + if top_is_strong { + 2 + } else if test_bit!(c_top_cbp, bpos + 2) { + 1 + } else { + 0 + } } else { - top_strength = 0; - } - } else if row > 0 { - if top_is_strong { - top_strength = 2; - } else if test_bit!(c_top_cbp, bpos + 2) { - top_strength = 1; - } else { - top_strength = 0; - } - } else { - top_strength = 0; - } + 0 + }; let l_q = if x > 0 { q } else { left_q }; let top_q = if row > 0 { mbinfo[mb_pos - mb_w].q as usize } else { 0 }; diff --git a/nihav-realmedia/src/codecs/rv40enc/dsp/loopfilt.rs b/nihav-realmedia/src/codecs/rv40enc/dsp/loopfilt.rs index aa9bfbc..b38c4f0 100644 --- a/nihav-realmedia/src/codecs/rv40enc/dsp/loopfilt.rs +++ b/nihav-realmedia/src/codecs/rv40enc/dsp/loopfilt.rs @@ -72,77 +72,73 @@ pub fn loop_filter_frame(dst: &mut NASimpleVideoFrame, dblk: &[DeblockInfo], let bpos = x + y * 4; let ver_strong = (x == 0) && (mb_x > 0) && (is_strong || left_is_strong); - let cur_strength: usize; - if is_strong { - cur_strength = 2; - } else if test_bit!(cur_dbk_y, bpos) { - cur_strength = 1; - } else { - cur_strength = 0; - } - - let left_strength: usize; - if x > 0 { - if is_strong { - left_strength = 2; - } else if test_bit!(cur_dbk_y, bpos - 1) { - left_strength = 1; - } else { - left_strength = 0; - } - } else if mb_x > 0 { - if left_is_strong { - left_strength = 2; - } else if test_bit!(left_dbk_y, bpos + 3) { - left_strength = 1; + let cur_strength = if is_strong { + 2 + } else if test_bit!(cur_dbk_y, bpos) { + 1 } else { - left_strength = 0; - } - } else { - left_strength = 0; - } + 0 + }; - let bot_strength: usize; - if y < 3 { - if is_strong { - bot_strength = 2; - } else if test_bit!(cur_dbk_y, bpos + 4) { - bot_strength = 1; - } else { - bot_strength = 0; - } - } else if !is_last_row { - if dblk[mb_pos + mb_w].is_strong { - bot_strength = 2; - } else if test_bit!(bot_dbk_y, x) { - bot_strength = 1; + let left_strength = if x > 0 { + if is_strong { + 2 + } else if test_bit!(cur_dbk_y, bpos - 1) { + 1 + } else { + 0 + } + } else if mb_x > 0 { + if left_is_strong { + 2 + } else if test_bit!(left_dbk_y, bpos + 3) { + 1 + } else { + 0 + } } else { - bot_strength = 0; - } - } else { - bot_strength = 0; - } + 0 + }; - let top_strength: usize; - if y > 0 { - if is_strong { - top_strength = 2; - } else if test_bit!(cur_dbk_y, bpos - 4) { - top_strength = 1; + let bot_strength = if y < 3 { + if is_strong { + 2 + } else if test_bit!(cur_dbk_y, bpos + 4) { + 1 + } else { + 0 + } + } else if !is_last_row { + if dblk[mb_pos + mb_w].is_strong { + 2 + } else if test_bit!(bot_dbk_y, x) { + 1 + } else { + 0 + } } else { - top_strength = 0; - } - } else if mb_y > 0 { - if top_is_strong { - top_strength = 2; - } else if test_bit!(top_dbk_y, bpos + 12) { - top_strength = 1; + 0 + }; + + let top_strength = if y > 0 { + if is_strong { + 2 + } else if test_bit!(cur_dbk_y, bpos - 4) { + 1 + } else { + 0 + } + } else if mb_y > 0 { + if top_is_strong { + 2 + } else if test_bit!(top_dbk_y, bpos + 12) { + 1 + } else { + 0 + } } else { - top_strength = 0; - } - } else { - top_strength = 0; - } + 0 + }; let l_q = if x > 0 { q } else { left_q }; let top_q = if mb_y > 0 { usize::from(dblk[mb_pos - mb_w].q) } else { 0 }; @@ -211,77 +207,73 @@ pub fn loop_filter_frame(dst: &mut NASimpleVideoFrame, dblk: &[DeblockInfo], let ver_strong = (x == 0) && (is_strong || left_is_strong); - let cur_strength: usize; - if is_strong { - cur_strength = 2; - } else if test_bit!(c_cur_cbp, bpos) { - cur_strength = 1; - } else { - cur_strength = 0; - } - - let left_strength: usize; - if x > 0 { - if is_strong { - left_strength = 2; - } else if test_bit!(c_cur_cbp, bpos - 1) { - left_strength = 1; + let cur_strength = if is_strong { + 2 + } else if test_bit!(c_cur_cbp, bpos) { + 1 } else { - left_strength = 0; - } - } else if mb_x > 0 { - if left_is_strong { - left_strength = 2; - } else if test_bit!(c_left_cbp, bpos + 1) { - left_strength = 1; + 0 + }; + + let left_strength = if x > 0 { + if is_strong { + 2 + } else if test_bit!(c_cur_cbp, bpos - 1) { + 1 + } else { + 0 + } + } else if mb_x > 0 { + if left_is_strong { + 2 + } else if test_bit!(c_left_cbp, bpos + 1) { + 1 + } else { + 0 + } } else { - left_strength = 0; - } - } else { - left_strength = 0; - } - - let bot_strength: usize; - if y != 3 { - if is_strong { - bot_strength = 2; - } else if test_bit!(c_cur_cbp, bpos + 2) { - bot_strength = 1; + 0 + }; + + let bot_strength = if y != 3 { + if is_strong { + 2 + } else if test_bit!(c_cur_cbp, bpos + 2) { + 1 + } else { + 0 + } + } else if !is_last_row { + if dblk[mb_pos + mb_w].is_strong { + 2 + } else if test_bit!(c_bot_cbp, x) { + 1 + } else { + 0 + } } else { - bot_strength = 0; - } - } else if !is_last_row { - if dblk[mb_pos + mb_w].is_strong { - bot_strength = 2; - } else if test_bit!(c_bot_cbp, x) { - bot_strength = 1; - } else { - bot_strength = 0; - } - } else { - bot_strength = 0; - } - - let top_strength: usize; - if y > 0 { - if is_strong { - top_strength = 2; - } else if test_bit!(c_cur_cbp, bpos - 2) { - top_strength = 1; + 0 + }; + + let top_strength = if y > 0 { + if is_strong { + 2 + } else if test_bit!(c_cur_cbp, bpos - 2) { + 1 + } else { + 0 + } + } else if mb_y > 0 { + if top_is_strong { + 2 + } else if test_bit!(c_top_cbp, bpos + 2) { + 1 + } else { + 0 + } } else { - top_strength = 0; - } - } else if mb_y > 0 { - if top_is_strong { - top_strength = 2; - } else if test_bit!(c_top_cbp, bpos + 2) { - top_strength = 1; - } else { - top_strength = 0; - } - } else { - top_strength = 0; - } + 0 + }; let l_q = if x > 0 { q } else { left_q }; let top_q = if mb_y > 0 { usize::from(dblk[mb_pos - mb_w].q) } else { 0 }; diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index cf247fe..215b18d 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -1203,88 +1203,86 @@ println!(" left {} bits", br.left()); } fn predict_mv(&self, hdr: &FrameHeader, mv_x: usize, mv_y: usize, mv_w: usize, mvi: &MVInfo) -> MVInfo { let mv_pos = mv_x + mv_y * self.blk_stride; - let f_mv: MV; - let b_mv: MV; - if mvi.mvref.is_fwd() { - let mut mv_cand: [MV; 3] = [ZERO_MV; 3]; - let mut mv_cand_size: usize = 0; - if mv_x > 0 { - let ref_mv = &self.blk_info[mv_pos - 1].mv; - if ref_mv.matches_fwd(mvi.mvref) { - mv_cand[mv_cand_size] = ref_mv.f_mv; - mv_cand_size += 1; + let f_mv = if mvi.mvref.is_fwd() { + let mut mv_cand: [MV; 3] = [ZERO_MV; 3]; + let mut mv_cand_size: usize = 0; + if mv_x > 0 { + let ref_mv = &self.blk_info[mv_pos - 1].mv; + if ref_mv.matches_fwd(mvi.mvref) { + mv_cand[mv_cand_size] = ref_mv.f_mv; + mv_cand_size += 1; + } } - } - if mv_y > 0 { - let ref_mv = &self.blk_info[mv_pos - self.blk_stride].mv; - if ref_mv.matches_fwd(mvi.mvref) { - mv_cand[mv_cand_size] = ref_mv.f_mv; - mv_cand_size += 1; + if mv_y > 0 { + let ref_mv = &self.blk_info[mv_pos - self.blk_stride].mv; + if ref_mv.matches_fwd(mvi.mvref) { + mv_cand[mv_cand_size] = ref_mv.f_mv; + mv_cand_size += 1; + } } - } - if hdr.has_top_block(mv_x << 2, mv_y << 2, mv_w << 2, 0, 4) { - let ref_mv = &self.blk_info[mv_pos - self.blk_stride + mv_w].mv; - if ref_mv.matches_fwd(mvi.mvref) { - mv_cand[mv_cand_size] = ref_mv.f_mv; - mv_cand_size += 1; + if hdr.has_top_block(mv_x << 2, mv_y << 2, mv_w << 2, 0, 4) { + let ref_mv = &self.blk_info[mv_pos - self.blk_stride + mv_w].mv; + if ref_mv.matches_fwd(mvi.mvref) { + mv_cand[mv_cand_size] = ref_mv.f_mv; + mv_cand_size += 1; + } } - } - f_mv = match mv_cand_size { - 1 | 2 => { - let x = mv_cand[0].x + mv_cand[1].x + mv_cand[2].x; - let y = mv_cand[0].y + mv_cand[1].y + mv_cand[2].y; - if mv_cand_size == 1 { - MV { x, y } - } else { - MV { x: x >> 1, y: y >> 1 } - } - }, - 3 => MV::pred(mv_cand[0], mv_cand[1], mv_cand[2]), - _ => ZERO_MV, + match mv_cand_size { + 1 | 2 => { + let x = mv_cand[0].x + mv_cand[1].x + mv_cand[2].x; + let y = mv_cand[0].y + mv_cand[1].y + mv_cand[2].y; + if mv_cand_size == 1 { + MV { x, y } + } else { + MV { x: x >> 1, y: y >> 1 } + } + }, + 3 => MV::pred(mv_cand[0], mv_cand[1], mv_cand[2]), + _ => ZERO_MV, + } + } else { + ZERO_MV }; - } else { - f_mv = ZERO_MV; - } - if mvi.mvref.is_bwd() { - let mut mv_cand: [MV; 3] = [ZERO_MV; 3]; - let mut mv_cand_size: usize = 0; - if mv_x > 0 { - let ref_mv = &self.blk_info[mv_pos - 1].mv; - if ref_mv.matches_bwd(mvi.mvref) { - mv_cand[mv_cand_size] = ref_mv.b_mv; - mv_cand_size += 1; + let b_mv = if mvi.mvref.is_bwd() { + let mut mv_cand: [MV; 3] = [ZERO_MV; 3]; + let mut mv_cand_size: usize = 0; + if mv_x > 0 { + let ref_mv = &self.blk_info[mv_pos - 1].mv; + if ref_mv.matches_bwd(mvi.mvref) { + mv_cand[mv_cand_size] = ref_mv.b_mv; + mv_cand_size += 1; + } } - } - if mv_y > 0 { - let ref_mv = &self.blk_info[mv_pos - self.blk_stride].mv; - if ref_mv.matches_bwd(mvi.mvref) { - mv_cand[mv_cand_size] = ref_mv.b_mv; - mv_cand_size += 1; + if mv_y > 0 { + let ref_mv = &self.blk_info[mv_pos - self.blk_stride].mv; + if ref_mv.matches_bwd(mvi.mvref) { + mv_cand[mv_cand_size] = ref_mv.b_mv; + mv_cand_size += 1; + } } - } - if hdr.has_top_block(mv_x << 2, mv_y << 2, mv_w << 2, 0, 4) { - let ref_mv = &self.blk_info[mv_pos - self.blk_stride + mv_w].mv; - if ref_mv.matches_bwd(mvi.mvref) { - mv_cand[mv_cand_size] = ref_mv.b_mv; - mv_cand_size += 1; + if hdr.has_top_block(mv_x << 2, mv_y << 2, mv_w << 2, 0, 4) { + let ref_mv = &self.blk_info[mv_pos - self.blk_stride + mv_w].mv; + if ref_mv.matches_bwd(mvi.mvref) { + mv_cand[mv_cand_size] = ref_mv.b_mv; + mv_cand_size += 1; + } } - } - b_mv = match mv_cand_size { - 1 | 2 => { - let x = mv_cand[0].x + mv_cand[1].x + mv_cand[2].x; - let y = mv_cand[0].y + mv_cand[1].y + mv_cand[2].y; - if mv_cand_size == 1 { - MV { x, y } - } else { - MV { x: x >> 1, y: y >> 1 } - } - }, - 3 => MV::pred(mv_cand[0], mv_cand[1], mv_cand[2]), - _ => ZERO_MV, + match mv_cand_size { + 1 | 2 => { + let x = mv_cand[0].x + mv_cand[1].x + mv_cand[2].x; + let y = mv_cand[0].y + mv_cand[1].y + mv_cand[2].y; + if mv_cand_size == 1 { + MV { x, y } + } else { + MV { x: x >> 1, y: y >> 1 } + } + }, + 3 => MV::pred(mv_cand[0], mv_cand[1], mv_cand[2]), + _ => ZERO_MV, + } + } else { + ZERO_MV }; - } else { - b_mv = ZERO_MV; - } MVInfo { f_mv: mvi.f_mv + f_mv, b_mv: mvi.b_mv + b_mv, mvref: mvi.mvref } } @@ -1341,7 +1339,7 @@ println!(" left {} bits", br.left()); match log_size { 3 => 3, 4 if (cu_type != CUType::Intra) && (self.pu_info[pu_pos].pu_type != PUType::Full) => 3, - 4 | 5 | 6 => 4, + 4..=6 => 4, _ => unreachable!(), } } diff --git a/nihav-realmedia/src/codecs/rv60codes.rs b/nihav-realmedia/src/codecs/rv60codes.rs index a8f36fb..4c1a278 100644 --- a/nihav-realmedia/src/codecs/rv60codes.rs +++ b/nihav-realmedia/src/codecs/rv60codes.rs @@ -1,8 +1,6 @@ use nihav_core::codecs::*; use nihav_core::io::bitreader::BitReader; use nihav_core::io::codebook::*; -use std::mem; -use std::ptr; const NUM_INTRA_SETS: usize = 5; const NUM_INTER_SETS: usize = 7; @@ -47,9 +45,9 @@ impl RV60CodebookDescReader { for i in 1..17 { prefixes[i + 1] = (prefixes[i] + (counts[i] as u32)) << 1; } - for i in 0..len { - codes[i] = prefixes[bits[i] as usize]; - prefixes[bits[i] as usize] += 1; + for (code, &bits) in codes.iter_mut().zip(bits.iter()).take(len) { + *code = prefixes[usize::from(bits)]; + prefixes[usize::from(bits)] += 1; } Self { len, codes, bits } @@ -98,38 +96,18 @@ pub struct RV60Codebooks { impl RV60Codebooks { pub fn init() -> Self { - let cbp8_cb; - let cbp16_cb; - unsafe { - let mut ucbp8_cb: mem::MaybeUninit::<[[Codebook; 4]; NUM_INTER_SETS]> = mem::MaybeUninit::uninit(); - let mut ucbp16_cb: mem::MaybeUninit::<[[Codebook; 12]; NUM_INTER_SETS]> = mem::MaybeUninit::uninit(); - for set_no in 0..NUM_INTER_SETS { - for i in 0..4 { - let mut cbr = RV60CodebookDescReader::new(&RV60_CBP8_TABS[set_no][i], NUM_CBP_ENTRIES, false); - ptr::write(&mut (*ucbp8_cb.as_mut_ptr())[set_no][i], Codebook::new(&mut cbr, CodebookMode::MSB).unwrap()); - } - for i in 0..12 { - let mut cbr = RV60CodebookDescReader::new(&RV60_CBP16_TABS[set_no][i], NUM_CBP_ENTRIES, false); - ptr::write(&mut (*ucbp16_cb.as_mut_ptr())[set_no][i], Codebook::new(&mut cbr, CodebookMode::MSB).unwrap()); - } - } - cbp8_cb = ucbp8_cb.assume_init(); - cbp16_cb = ucbp16_cb.assume_init(); - } - let intra_coeff_cb; - let inter_coeff_cb; - unsafe { - let mut uintra_coeff_cb: mem::MaybeUninit::<[CoeffCodebooks; NUM_INTRA_SETS]> = mem::MaybeUninit::uninit(); - for set_no in 0..NUM_INTRA_SETS { - ptr::write(&mut (*uintra_coeff_cb.as_mut_ptr())[set_no], CoeffCodebooks::init(set_no, true)); - } - let mut uinter_coeff_cb: mem::MaybeUninit::<[CoeffCodebooks; NUM_INTER_SETS]> = mem::MaybeUninit::uninit(); - for set_no in 0..NUM_INTER_SETS { - ptr::write(&mut (*uinter_coeff_cb.as_mut_ptr())[set_no], CoeffCodebooks::init(set_no, false)); - } - intra_coeff_cb = uintra_coeff_cb.assume_init(); - inter_coeff_cb = uinter_coeff_cb.assume_init(); - } + let cbp8_cb = std::array::from_fn(|set_no| + std::array::from_fn(|i| { + let mut cbr = RV60CodebookDescReader::new(&RV60_CBP8_TABS[set_no][i], NUM_CBP_ENTRIES, false); + Codebook::new(&mut cbr, CodebookMode::MSB).unwrap() + })); + let cbp16_cb = std::array::from_fn(|set_no| + std::array::from_fn(|i| { + let mut cbr = RV60CodebookDescReader::new(&RV60_CBP16_TABS[set_no][i], NUM_CBP_ENTRIES, false); + Codebook::new(&mut cbr, CodebookMode::MSB).unwrap() + })); + let intra_coeff_cb = std::array::from_fn(|set_no| CoeffCodebooks::init(set_no, true)); + let inter_coeff_cb = std::array::from_fn(|set_no| CoeffCodebooks::init(set_no, false)); Self { cbp8_cb, cbp16_cb, intra_coeff_cb, inter_coeff_cb } } fn get_c4x4_set(qp: u8, is_intra: bool) -> usize {