#[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::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(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(feature="decoder_vp7")]
mod vp7data;
#[cfg(feature="decoder_vp7")]
+#[allow(clippy::erasing_op)]
+#[allow(clippy::needless_range_loop)]
+#[allow(clippy::too_many_arguments)]
+#[allow(clippy::useless_let_if_seq)]
mod vp7dsp;
#[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")]
mod on2avcdata;
scale = br.read(7)? as i16;
first = false
} else {
- scale += br.read_cb(&self.codebooks.scale_cb)? as i16;
+ scale += i16::from(br.read_cb(&self.codebooks.scale_cb)?);
validate!((scale >= 0) && (scale < 128));
}
self.scales[cur_band] = scale as u8;
}
Ok(())
}
+ #[allow(clippy::cyclomatic_complexity)]
fn synth_channel(&mut self, chno: usize, dst: &mut [f32]) {
let coeffs = &mut self.coeffs[chno];
let delay = &mut self.delay[chno];
fn $name(src: &[f32], dst: &mut [f32], step: usize, off: usize, sp: &SynthParams) {
for i in 0..step {
for j in 0..sp.p0 {
- dst[i] += ((src[j] as f64) * $tab[sp.idx][j][i]) as f32;
+ dst[i] += (f64::from(src[j]) * $tab[sp.idx][j][i]) as f32;
}
}
for i in 0..step {
for j in 0..sp.p1 {
- dst[$size - step + i] += ((src[sp.p0 + off + j] as f64) * $tab[sp.idx][sp.p0 + j][i]) as f32;
+ dst[$size - step + i] += (f64::from(src[sp.p0 + off + j]) * $tab[sp.idx][sp.p0 + j][i]) as f32;
}
}
}
{
let mut pos = step - 1;
for _ in 0..off {
- let scale = src[p0] as f64;
+ let scale = f64::from(src[p0]);
p0 += 1;
pos &= size - 1;
for i in 0..pos.min(step) {
(&mut dst[..size]).copy_from_slice(&src[..size]);
let mut order_idx = 0;
synth_recursive(dst, tmpbuf, size, order, &mut order_idx, false);
- for i in 0..COEFFS { dst[i] *= 0.125; }
+ for el in dst.iter_mut().take(COEFFS) { *el *= 0.125; }
}
fn synth1024(dsp: &mut SynthDSP, src: &[f32], dst: &mut [f32], tmpbuf: &mut [f32; COEFFS * 2], is_40khz: bool) {
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;
for _ in 0..4 {
for x in 0..4 {
let dy = self.streams[TM2StreamType::Update as usize].get_token()?;
- ydst[yoff + x] = ((ysrc[yoff + x] as i32) + dy) as u8;
+ ydst[yoff + x] = (i32::from(ysrc[yoff + x]) + dy) as u8;
}
yoff += ystride;
}
Ok(())
}
+ #[allow(clippy::int_plus_one)]
+ #[allow(clippy::manual_memcpy)]
+ #[allow(clippy::cyclomatic_complexity)]
fn decode_frame(&mut self, src: &[u8]) -> DecoderResult<()> {
let mut mr = MemoryReader::new_read(src);
let mut br = ByteReader::new(&mut mr);
impl TMRTDecoder {
fn new() -> Self { Self::default() }
+ #[allow(clippy::too_many_arguments)]
fn decode_plane(&self, br: &mut BitReader, dst: &mut [u8], mut off: usize, stride: usize, w: usize, h: usize, hscale: bool, dbits: u8, is_chroma: bool) -> DecoderResult<()> {
let delta_tab = TMRT_DELTA_TAB[(dbits - 2) as usize];
let step = if !hscale { 1 } else { 2 };
}
}
+#[allow(clippy::large_enum_variant)]
enum Codes {
None,
VP30(VP30Codes),
let idx = br.peek(5) as usize;
let sym = (VP30_CRUN1_LUT[idx] >> 4) as usize;
let bits = VP30_CRUN1_LUT[idx] & 0xF;
- br.skip(bits as u32)?;
+ br.skip(u32::from(bits))?;
if sym < 7 {
Ok(sym)
} else if sym == 7 {
macro_rules! fill_dc_pred {
($self: expr, $ref_id: expr, $pred: expr, $pp: expr, $bit: expr, $idx: expr) => {
if $self.blocks[$idx].coded && $self.blocks[$idx].btype.get_ref_id() == $ref_id {
- $pred[$bit] = $self.blocks[$idx].coeffs[0] as i32;
+ $pred[$bit] = i32::from($self.blocks[$idx].coeffs[0]);
$pp |= 1 << $bit;
}
};
let saddr = (self.blk_addr[cur_blk] >> 2).min(self.blk_addr[cur_blk + 1] >> 2).min(self.blk_addr[cur_blk + 2] >> 2).min(self.blk_addr[cur_blk + 3] >> 2);
for i in 0..4 {
let blk = &mut self.blocks[saddr + (i & 1) + (i >> 1) * self.mb_w * 2];
- blk.mv.x = br.read_cb(x_cb)? as i16;
+ blk.mv.x = i16::from(br.read_cb(x_cb)?);
if x_sign {
blk.mv.x = -blk.mv.x;
}
- blk.mv.y = br.read_cb(y_cb)? as i16;
+ blk.mv.y = i16::from(br.read_cb(y_cb)?);
if y_sign {
blk.mv.y = -blk.mv.y;
}
let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.abs() as usize]];
let x_sign = last_mv.x < 0;
let y_sign = last_mv.y < 0;
- let x = br.read_cb(x_cb)? as i16;
- let y = br.read_cb(y_cb)? as i16;
+ let x = i16::from(br.read_cb(x_cb)?);
+ let y = i16::from(br.read_cb(y_cb)?);
cur_mv = MV { x: if !x_sign { x } else { -x }, y: if !y_sign { y } else { -y } };
last2_mv = last_mv;
last_mv = cur_mv;
let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv_g.y.abs() as usize]];
let x_sign = last_mv_g.x < 0;
let y_sign = last_mv_g.y < 0;
- let x = br.read_cb(x_cb)? as i16;
- let y = br.read_cb(y_cb)? as i16;
+ let x = i16::from(br.read_cb(x_cb)?);
+ let y = i16::from(br.read_cb(y_cb)?);
cur_mv = MV { x: if !x_sign { x } else { -x }, y: if !y_sign { y } else { -y } };
last_mv_g = cur_mv;
},
let mut pred = 0i32;
for i in 0..4 {
if (pp & (1 << i)) != 0 {
- pred += (preds[i] as i32) * (VP31_DC_WEIGHTS[pp][i] as i32);
+ pred += (preds[i] as i32) * i32::from(VP31_DC_WEIGHTS[pp][i]);
}
}
- pred /= VP31_DC_WEIGHTS[pp][4] as i32;
+ pred /= i32::from(VP31_DC_WEIGHTS[pp][4]);
if (pp & 7) == 7 {
if (pred - preds[2]).abs() > 128 { return preds[2] as i16; }
if (pred - preds[0]).abs() > 128 { return preds[0] as i16; }
}
}
}
+ #[allow(clippy::cyclomatic_complexity)]
fn output_blocks_inter(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
let mut blk_idx = 0;
let bstride = self.mb_w * 2;
fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
let myvinfo = NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, YUV420_FORMAT);
- let myinfo = NACodecTypeInfo::Video(myvinfo.clone());
+ let myinfo = NACodecTypeInfo::Video(myvinfo);
self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
self.dec.init(supp, myvinfo)?;
Ok(())
}
fn prob2weight(a: u8, b: u8) -> u8 {
- let w = (((a as u16) * (b as u16)) >> 8) as u8;
+ let w = ((u16::from(a) * u16::from(b)) >> 8) as u8;
if w == 0 {
1
} else {
let mut nlen = 0;
for w in weights.iter().rev() {
- let weight = *w as u16;
+ let weight = u16::from(*w);
let mut pos = nlen;
for i in 0..nlen {
if nodes[i].weight > weight {
fn read_huff(&mut self, huff: &VP6Huff) -> DecoderResult<u8> {
let peekval = self.peek(16);
for (i, (code, bit)) in huff.codes.iter().zip(huff.bits.iter()).enumerate() {
- if (peekval >> (16 - *bit)) == (*code as u32) {
- self.skip(*bit as u32)?;
+ if (peekval >> (16 - *bit)) == u32::from(*code) {
+ self.skip(u32::from(*bit))?;
return Ok(i as u8);
}
}
if token != 0 {
sign = bc.read_bool();
}
- level = token as i16;
+ level = i16::from(token);
} else {
let cat: usize = vp_tree!(bc, val_probs[6],
vp_tree!(bc, val_probs[7], 0, 1),
self.fstate = FrameState::new();
self.fstate.dc_quant = VP56_DC_QUANTS[hdr.quant as usize] * 4;
self.fstate.ac_quant = VP56_AC_QUANTS[hdr.quant as usize] * 4;
- self.loop_thr = VP56_FILTER_LIMITS[hdr.quant as usize] as i16;
+ self.loop_thr = i16::from(VP56_FILTER_LIMITS[hdr.quant as usize]);
self.last_mbt = VPMBType::InterNoMV;
for vec in self.top_ctx.iter_mut() {
let mut total = 0;
for i in 0..10 {
if i == mode { continue; }
- cnt[i] = 100 * (prob_xmitted[i * 2] as u32);
+ cnt[i] = 100 * u32::from(prob_xmitted[i * 2]);
total += cnt[i];
}
- let sum = (prob_xmitted[mode * 2] as u32) + (prob_xmitted[mode * 2 + 1] as u32);
- mdl.probs[9] = 255 - rescale_mb_mode_prob(prob_xmitted[mode * 2 + 1] as u32, sum);
+ let sum = u32::from(prob_xmitted[mode * 2]) + u32::from(prob_xmitted[mode * 2 + 1]);
+ mdl.probs[9] = 255 - rescale_mb_mode_prob(u32::from(prob_xmitted[mode * 2 + 1]), sum);
let inter_mv0_weight = (cnt[0] as u32) + (cnt[2] as u32);
let inter_mv1_weight = (cnt[3] as u32) + (cnt[4] as u32);
}
Ok(self.last_mbt)
}
+ #[allow(clippy::cyclomatic_complexity)]
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 ];
let prob = if mb_x == 0 {
iprob
} else if !self.ilace_mb {
- iprob + (((256 - (iprob as u16)) >> 1) as u8)
+ iprob + (((256 - u16::from(iprob)) >> 1) as u8)
} else {
iprob - (iprob >> 1)
};
if copy_mode {
let src = &tmp_blk[2 * 16 + 2..];
for (dline, sline) in dbuf.chunks_mut(dst.stride[plane]).zip(src.chunks(16)).take(8) {
- for i in 0..8 { dline[i] = sline[i]; }
+ dline[..8].copy_from_slice(&sline[..8]);
}
} else if bicubic {
let coeff_h = &VP6_BICUBIC_COEFFS[self.filter_alpha][mx as usize];
0 => Ok((0, false)),
1 | 2 | 3 | 4 => {
if !br.read_bool()? {
- Ok((tok as i16, false))
+ Ok((i16::from(tok), false))
} else {
- Ok((-(tok as i16), false))
+ Ok((-i16::from(tok), false))
}
},
5 | 6 | 7 | 8 | 9 | 10 => {
}
}
-
+#[allow(clippy::too_many_arguments)]
fn get_block(dst: &mut [u8], dstride: usize, src: NAVideoBufferRef<u8>, comp: usize,
dx: usize, dy: usize, mv_x: i16, mv_y: i16)
{
let saddr = soff + ((sx - 2) as usize) + ((sy - 2) as usize) * sstride;
let src = &sbuf[saddr..];
for (dline, sline) in dst.chunks_mut(dstride).zip(src.chunks(sstride)).take(12) {
- for i in 0..12 {
- dline[i] = sline[i];
- }
+ dline[..12].copy_from_slice(&sline[..12]);
}
}
}
let mut ssum = 0;
for line in src.chunks(stride * 2).take(4) {
for el in line.iter().take(8).step_by(2) {
- let pix = *el as u32;
+ let pix = u32::from(*el);
sum += pix;
ssum += pix * pix;
}
macro_rules! mc_filter {
(bilinear; $a: expr, $b: expr, $c: expr) => {
- ((($a as u16) * (8 - $c) + ($b as u16) * $c + 4) >> 3) as u8
+ ((u16::from($a) * (8 - $c) + u16::from($b) * $c + 4) >> 3) as u8
};
(bicubic; $src: expr, $off: expr, $step: expr, $coeffs: expr) => {
- ((($src[$off - $step] as i32) * ($coeffs[0] as i32) +
- ($src[$off] as i32) * ($coeffs[1] as i32) +
- ($src[$off + $step] as i32) * ($coeffs[2] as i32) +
- ($src[$off + $step * 2] as i32) * ($coeffs[3] as i32) + 64) >> 7).min(255).max(0) as u8
+ ((i32::from($src[$off - $step] ) * i32::from($coeffs[0]) +
+ i32::from($src[$off] ) * i32::from($coeffs[1]) +
+ i32::from($src[$off + $step] ) * i32::from($coeffs[2]) +
+ i32::from($src[$off + $step * 2]) * i32::from($coeffs[3]) + 64) >> 7).min(255).max(0) as u8
}
}
}
}
+#[allow(clippy::trivially_copy_pass_by_ref)]
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) {
VP_YUVA420_FORMAT
};
let myvinfo = NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt);
- let myinfo = NACodecTypeInfo::Video(myvinfo.clone());
+ let myinfo = NACodecTypeInfo::Video(myvinfo);
self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
self.dec.init(supp, myvinfo)?;
Ok(())
qmat: &'a [i16; 16],
}
-fn decode_subblock<'a>(bc: &mut BoolCoder, coeffs: &mut [i16; 16], ctype: usize, pctx: u8, sbparams: &SBParams) -> u8 {
+fn decode_subblock(bc: &mut BoolCoder, coeffs: &mut [i16; 16], ctype: usize, pctx: u8, sbparams: &SBParams) -> u8 {
const COEF_BANDS: [usize; 16] = [ 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7 ];
let mut has_nz = 0;
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
]];
- let edge_thr = (loop_str as i16) + 2;
- let luma_thr = loop_str as i16;
- let chroma_thr = (loop_str as i16) * 2;
+ let edge_thr = i16::from(loop_str) + 2;
+ let luma_thr = i16::from(loop_str);
+ let chroma_thr = i16::from(loop_str) * 2;
let inner_thr = if self.dstate.loop_sharpness == 0 {
- loop_str as i16
+ i16::from(loop_str)
} else {
- let bound1 = (9 - self.dstate.loop_sharpness) as i16;
+ let bound1 = i16::from(9 - self.dstate.loop_sharpness);
let shift = (self.dstate.loop_sharpness + 3) >> 2;
- ((loop_str as i16) >> shift).min(bound1)
+ (i16::from(loop_str) >> shift).min(bound1)
};
- let hev_thr = HIGH_EDGE_VAR_THR[if self.dstate.is_intra { 1 } else { 0 }][loop_str as usize] as i16;
+ let hev_thr = i16::from(HIGH_EDGE_VAR_THR[if self.dstate.is_intra { 1 } else { 0 }][loop_str as usize]);
let ystride = dframe.stride[0];
let ustride = dframe.stride[1];
if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
let fmt = YUV420_FORMAT;
let myvinfo = NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt);
- let myinfo = NACodecTypeInfo::Video(myvinfo.clone());
+ let myinfo = NACodecTypeInfo::Video(myvinfo);
self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
supp.pool_u8.set_dec_bufs(4);
Err(DecoderError::InvalidData)
}
}
+ #[allow(clippy::cyclomatic_complexity)]
fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let src = pkt.get_buffer();
pub fn idct4x4(coeffs: &mut [i16; 16]) {
let mut tmp = [0i16; 16];
for (src, dst) in coeffs.chunks(4).zip(tmp.chunks_mut(4)) {
- let s0 = src[0] as i32;
- let s1 = src[1] as i32;
- let s2 = src[2] as i32;
- let s3 = src[3] as i32;
+ let s0 = i32::from(src[0]);
+ let s1 = i32::from(src[1]);
+ let s2 = i32::from(src[2]);
+ let s3 = i32::from(src[3]);
let t0 = (s0 + s2).wrapping_mul(23170);
let t1 = (s0 - s2).wrapping_mul(23170);
dst[3] = ((t0 - t2) >> 14) as i16;
}
for i in 0..4 {
- let s0 = tmp[i + 4 * 0] as i32;
- let s1 = tmp[i + 4 * 1] as i32;
- let s2 = tmp[i + 4 * 2] as i32;
- let s3 = tmp[i + 4 * 3] as i32;
+ let s0 = i32::from(tmp[i + 4 * 0]);
+ let s1 = i32::from(tmp[i + 4 * 1]);
+ let s2 = i32::from(tmp[i + 4 * 2]);
+ let s3 = i32::from(tmp[i + 4 * 3]);
let t0 = (s0 + s2).wrapping_mul(23170) + 0x20000;
let t1 = (s0 - s2).wrapping_mul(23170) + 0x20000;
}
pub fn idct4x4_dc(coeffs: &mut [i16; 16]) {
- let dc = (((((coeffs[0] as i32) * DCT_COEFFS[0]) >> 14) * DCT_COEFFS[0] + 0x20000) >> 18) as i16;
+ let dc = ((((i32::from(coeffs[0]) * DCT_COEFFS[0]) >> 14) * DCT_COEFFS[0] + 0x20000) >> 18) as i16;
for el in coeffs.iter_mut() {
*el = dc;
}
let dst = &mut dst[off..];
for (out, src) in dst.chunks_mut(stride).zip(coeffs.chunks(4)) {
for (oel, iel) in out.iter_mut().take(4).zip(src.iter()) {
- *oel = clip_u8((*oel as i16) + *iel);
+ *oel = clip_u8(i16::from(*oel) + *iel);
}
}
}
pub fn add_coeffs16x1(dst: &mut [u8], off: usize, coeffs: &[i16; 16]) {
let dst = &mut dst[off..];
for (oel, iel) in dst.iter_mut().take(16).zip(coeffs.iter()) {
- *oel = clip_u8((*oel as i16) + *iel);
+ *oel = clip_u8(i16::from(*oel) + *iel);
}
}
};
if ipred.has_left {
for el in ipred.left.iter().take(Self::SIZE) {
- dcsum += *el as u16;
+ dcsum += u16::from(*el);
}
dcshift += 1;
}
if ipred.has_top {
for el in ipred.top.iter().take(Self::SIZE) {
- dcsum += *el as u16;
+ dcsum += u16::from(*el);
}
dcshift += 1;
}
}
}
fn ipred_tm(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
- let tl = ipred.tl as i16;
+ let tl = i16::from(ipred.tl);
for m in 0..Self::SIZE {
for n in 0..Self::SIZE {
- dst[off + n] = clip_u8((ipred.left[m] as i16) + (ipred.top[n] as i16) - tl);
+ dst[off + n] = clip_u8(i16::from(ipred.left[m]) + i16::from(ipred.top[n]) - tl);
}
off += stride;
}
macro_rules! load_pred4 {
(topleft; $ipred: expr) => {{
- let tl = $ipred.tl as u16;
- let a0 = $ipred.top[0] as u16;
- let l0 = $ipred.left[0] as u16;
+ let tl = u16::from($ipred.tl);
+ let a0 = u16::from($ipred.top[0]);
+ let l0 = u16::from($ipred.left[0]);
((l0 + tl * 2 + a0 + 2) >> 2) as u8
}};
(top; $ipred: expr) => {{
- let tl = $ipred.tl as u16;
- let a0 = $ipred.top[0] as u16;
- let a1 = $ipred.top[1] as u16;
- let a2 = $ipred.top[2] as u16;
- let a3 = $ipred.top[3] as u16;
- let a4 = $ipred.top[4] as u16;
+ let tl = u16::from($ipred.tl);
+ let a0 = u16::from($ipred.top[0]);
+ let a1 = u16::from($ipred.top[1]);
+ let a2 = u16::from($ipred.top[2]);
+ let a3 = u16::from($ipred.top[3]);
+ let a4 = u16::from($ipred.top[4]);
let p0 = ((tl + a0 * 2 + a1 + 2) >> 2) as u8;
let p1 = ((a0 + a1 * 2 + a2 + 2) >> 2) as u8;
let p2 = ((a1 + a2 * 2 + a3 + 2) >> 2) as u8;
(p0, p1, p2, p3)
}};
(top8; $ipred: expr) => {{
- let t3 = $ipred.top[3] as u16;
- let t4 = $ipred.top[4] as u16;
- let t5 = $ipred.top[5] as u16;
- let t6 = $ipred.top[6] as u16;
- let t7 = $ipred.top[7] as u16;
+ let t3 = u16::from($ipred.top[3]);
+ let t4 = u16::from($ipred.top[4]);
+ let t5 = u16::from($ipred.top[5]);
+ let t6 = u16::from($ipred.top[6]);
+ let t7 = u16::from($ipred.top[7]);
let p4 = ((t3 + t4 * 2 + t5 + 2) >> 2) as u8;
let p5 = ((t4 + t5 * 2 + t6 + 2) >> 2) as u8;
let p6 = ((t5 + t6 * 2 + t7 + 2) >> 2) as u8;
(p4, p5, p6, p7)
}};
(topavg; $ipred: expr) => {{
- let tl = $ipred.tl as u16;
- let a0 = $ipred.top[0] as u16;
- let a1 = $ipred.top[1] as u16;
- let a2 = $ipred.top[2] as u16;
- let a3 = $ipred.top[3] as u16;
+ let tl = u16::from($ipred.tl);
+ let a0 = u16::from($ipred.top[0]);
+ let a1 = u16::from($ipred.top[1]);
+ let a2 = u16::from($ipred.top[2]);
+ let a3 = u16::from($ipred.top[3]);
let p0 = ((tl + a0 + 1) >> 1) as u8;
let p1 = ((a0 + a1 + 1) >> 1) as u8;
let p2 = ((a1 + a2 + 1) >> 1) as u8;
(p0, p1, p2, p3)
}};
(left; $ipred: expr) => {{
- let tl = $ipred.tl as u16;
- let l0 = $ipred.left[0] as u16;
- let l1 = $ipred.left[1] as u16;
- let l2 = $ipred.left[2] as u16;
- let l3 = $ipred.left[3] as u16;
- let l4 = $ipred.left[4] as u16;
+ let tl = u16::from($ipred.tl);
+ let l0 = u16::from($ipred.left[0]);
+ let l1 = u16::from($ipred.left[1]);
+ let l2 = u16::from($ipred.left[2]);
+ let l3 = u16::from($ipred.left[3]);
+ let l4 = u16::from($ipred.left[4]);
let p0 = ((tl + l0 * 2 + l1 + 2) >> 2) as u8;
let p1 = ((l0 + l1 * 2 + l2 + 2) >> 2) as u8;
let p2 = ((l1 + l2 * 2 + l3 + 2) >> 2) as u8;
(p0, p1, p2, p3)
}};
(left8; $ipred: expr) => {{
- let l3 = $ipred.left[3] as u16;
- let l4 = $ipred.left[4] as u16;
- let l5 = $ipred.left[5] as u16;
- let l6 = $ipred.left[6] as u16;
- let l7 = $ipred.left[7] as u16;
+ let l3 = u16::from($ipred.left[3]);
+ let l4 = u16::from($ipred.left[4]);
+ let l5 = u16::from($ipred.left[5]);
+ let l6 = u16::from($ipred.left[6]);
+ let l7 = u16::from($ipred.left[7]);
let p4 = ((l3 + l4 * 2 + l5 + 2) >> 2) as u8;
let p5 = ((l4 + l5 * 2 + l6 + 2) >> 2) as u8;
let p6 = ((l5 + l6 * 2 + l7 + 2) >> 2) as u8;
(p4, p5, p6, p7)
}};
(leftavg; $ipred: expr) => {{
- let tl = $ipred.tl as u16;
- let l0 = $ipred.left[0] as u16;
- let l1 = $ipred.left[1] as u16;
- let l2 = $ipred.left[2] as u16;
- let l3 = $ipred.left[3] as u16;
+ let tl = u16::from($ipred.tl);
+ let l0 = u16::from($ipred.left[0]);
+ let l1 = u16::from($ipred.left[1]);
+ let l2 = u16::from($ipred.left[2]);
+ let l3 = u16::from($ipred.left[3]);
let p0 = ((tl + l0 + 1) >> 1) as u8;
let p1 = ((l0 + l1 + 1) >> 1) as u8;
let p2 = ((l1 + l2 + 1) >> 1) as u8;
let dc;
let mut dcsum = 0;
for el in ipred.left.iter().take(4) {
- dcsum += *el as u16;
+ dcsum += u16::from(*el);
}
for el in ipred.top.iter().take(4) {
- dcsum += *el as u16;
+ dcsum += u16::from(*el);
}
dc = ((dcsum + (1 << 2)) >> 3) as u8;
for _ in 0..4 {
}
}
pub fn ipred_tm(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
- let tl = ipred.tl as i16;
+ let tl = i16::from(ipred.tl);
for m in 0..4 {
for n in 0..4 {
- dst[off + n] = clip_u8((ipred.left[m] as i16) + (ipred.top[n] as i16) - tl);
+ dst[off + n] = clip_u8(i16::from(ipred.left[m]) + i16::from(ipred.top[n]) - tl);
}
off += stride;
}
}
pub fn ipred_he(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
let (p0, p1, p2, _) = load_pred4!(left; ipred);
- let p3 = (((ipred.left[2] as u16) + (ipred.left[3] as u16) * 3 + 2) >> 2) as u8;
+ 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 {
let (_, t1, t2, t3) = load_pred4!(top; ipred);
let (t4, t5, t6, _) = load_pred4!(top8; ipred);
let (_, m1, m2, m3) = load_pred4!(topavg; ipred);
- let m4 = (((ipred.top[3] as u16) + (ipred.top[4] as u16) + 1) >> 1) as u8;
+ let m4 = ((u16::from(ipred.top[3]) + u16::from(ipred.top[4]) + 1) >> 1) as u8;
dst[off + 0] = m1; dst[off + 1] = m2; dst[off + 2] = m3; dst[off + 3] = m4;
off += stride;
pub fn ipred_hu(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
let (_, m1, m2, m3) = load_pred4!(leftavg; ipred);
let (_, l1, l2, _) = load_pred4!(left; ipred);
- let l3 = (((ipred.left[2] as u16) + (ipred.left[3] as u16) * 3 + 2) >> 2) as u8;
+ let l3 = ((u16::from(ipred.left[2]) + u16::from(ipred.left[3]) * 3 + 2) >> 2) as u8;
let p3 = ipred.left[3];
dst[off + 0] = m1; dst[off + 1] = l1; dst[off + 2] = m2; dst[off + 3] = l2;
pub fn simple_loop_filter(buf: &mut [u8], mut off: usize, step: usize, stride: usize, len: usize, thr: i16, _thr_inner: i16, _thr_hev: i16) {
for _ in 0..len {
- let p1 = buf[off - step * 2] as i16;
- let p0 = buf[off - step * 1] as i16;
- let q0 = buf[off + step * 0] as i16;
- let q1 = buf[off + step * 1] as i16;
+ let p1 = i16::from(buf[off - step * 2]);
+ let p0 = i16::from(buf[off - step * 1]);
+ let q0 = i16::from(buf[off + step * 0]);
+ let q1 = i16::from(buf[off + step * 1]);
let dpq = p0 - q0;
if dpq.abs() < thr {
let diff = delta(p1, p0, q0, q1);
fn normal_loop_filter(buf: &mut [u8], mut off: usize, step: usize, stride: usize, len: usize, thr: i16, thr_inner: i16, thr_hev: i16, edge: bool) {
for _ in 0..len {
- let p0 = buf[off - step * 1] as i16;
- let q0 = buf[off + step * 0] as i16;
+ let p0 = i16::from(buf[off - step * 1]);
+ let q0 = i16::from(buf[off + step * 0]);
let dpq = p0 - q0;
if dpq.abs() <= thr {
- let p3 = buf[off - step * 4] as i16;
- let p2 = buf[off - step * 3] as i16;
- let p1 = buf[off - step * 2] as i16;
- let q1 = buf[off + step * 1] as i16;
- let q2 = buf[off + step * 2] as i16;
- let q3 = buf[off + step * 3] as i16;
+ let p3 = i16::from(buf[off - step * 4]);
+ let p2 = i16::from(buf[off - step * 3]);
+ let p1 = i16::from(buf[off - step * 2]);
+ let q1 = i16::from(buf[off + step * 1]);
+ let q2 = i16::from(buf[off + step * 2]);
+ let q3 = i16::from(buf[off + step * 3]);
let dp2 = p3 - p2;
let dp1 = p2 - p1;
let dp0 = p1 - p0;
macro_rules! interpolate {
($src: expr, $off: expr, $step: expr, $mode: expr) => {{
- let s0 = $src[$off + 0 * $step] as i32;
- let s1 = $src[$off + 1 * $step] as i32;
- let s2 = $src[$off + 2 * $step] as i32;
- let s3 = $src[$off + 3 * $step] as i32;
- let s4 = $src[$off + 4 * $step] as i32;
- let s5 = $src[$off + 5 * $step] as i32;
+ let s0 = i32::from($src[$off + 0 * $step]);
+ let s1 = i32::from($src[$off + 1 * $step]);
+ let s2 = i32::from($src[$off + 2 * $step]);
+ let s3 = i32::from($src[$off + 3 * $step]);
+ let s4 = i32::from($src[$off + 4 * $step]);
+ let s5 = i32::from($src[$off + 5 * $step]);
let filt = &VP7_BICUBIC_FILTERS[$mode];
let src = [s0, s1, s2, s3, s4, s5];
let mut val = 64;
for (s, c) in src.iter().zip(filt.iter()) {
- val += s * (*c as i32);
+ val += s * i32::from(*c);
}
clip_u8((val >> 7) as i16)
}}
impl<'a> BoolCoder<'a> {
pub fn new(src: &'a [u8]) -> DecoderResult<Self> {
if src.len() < 3 { return Err(DecoderError::ShortData); }
- let value = ((src[0] as u32) << 24) | ((src[1] as u32) << 16) | ((src[2] as u32) << 8) | (src[3] as u32);
+ let value = (u32::from(src[0]) << 24) | (u32::from(src[1]) << 16) | (u32::from(src[2]) << 8) | u32::from(src[3]);
Ok(Self { src, pos: 4, value, range: 255, bits: 8 })
}
pub fn read_bool(&mut self) -> bool {
}
pub fn read_prob(&mut self, prob: u8) -> bool {
self.renorm();
- let split = 1 + (((self.range - 1) * (prob as u32)) >> 8);
+ let split = 1 + (((self.range - 1) * u32::from(prob)) >> 8);
let bit;
if self.value < (split << 24) {
self.range = split;
self.value <<= shift;
self.bits -= shift as i32;
if (self.bits <= 0) && (self.pos < self.src.len()) {
- self.value |= (self.src[self.pos] as u32) << (-self.bits as u8);
+ self.value |= u32::from(self.src[self.pos]) << (-self.bits as u8);
self.pos += 1;
self.bits += 8;
}
self.value <<= 1;
self.bits -= 1;
if (self.bits <= 0) && (self.pos < self.src.len()) {
- self.value |= self.src[self.pos] as u32;
+ self.value |= u32::from(self.src[self.pos]);
self.pos += 1;
self.bits = 8;
}
for _ in 0..nbytes {
self.value <<= 8;
if self.pos < self.src.len() {
- self.value |= self.src[self.pos] as u32;
+ self.value |= u32::from(self.src[self.pos]);
self.pos += 1;
}
}
}
#[allow(dead_code)]
+#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn rescale_prob(prob: u8, weights: &[i16; 2], maxval: i32) -> u8 {
- ((((prob as i32) * (weights[0] as i32) + 128) >> 8) + (weights[1] as i32)).min(maxval).max(1) as u8
+ (((i32::from(prob) * i32::from(weights[0]) + 128) >> 8) + i32::from(weights[1])).min(maxval).max(1) as u8
}
macro_rules! vp_tree {
let mut off = frm.offset[plane] + bx * 8 + by * 8 * frm.stride[plane];
for y in 0..8 {
for x in 0..8 {
- frm.data[off + x] = (coeffs[x + y * 8] + (frm.data[off + x] as i16)).min(255).max(0) as u8;
+ frm.data[off + x] = (coeffs[x + y * 8] + i16::from(frm.data[off + x])).min(255).max(0) as u8;
}
off += frm.stride[plane];
}
let mut off = frm.offset[plane] + bx * 8 + ((by & !1) * 8 + (by & 1)) * frm.stride[plane];
for y in 0..8 {
for x in 0..8 {
- frm.data[off + x] = (coeffs[x + y * 8] + (frm.data[off + x] as i16)).min(255).max(0) as u8;
+ frm.data[off + x] = (coeffs[x + y * 8] + i16::from(frm.data[off + x])).min(255).max(0) as u8;
}
off += frm.stride[plane] * 2;
}
let mut off = frm.offset[plane] + bx * 8 + by * 8 * frm.stride[plane];
for _ in 0..8 {
for x in 0..8 {
- frm.data[off + x] = (dc + (frm.data[off + x] as i16)).min(255).max(0) as u8;
+ frm.data[off + x] = (dc + i16::from(frm.data[off + x])).min(255).max(0) as u8;
}
off += frm.stride[plane];
}
pub fn vp31_loop_filter(data: &mut [u8], mut off: usize, step: usize, stride: usize,
len: usize, loop_str: i16) {
for _ in 0..len {
- let a = data[off - step * 2] as i16;
- let b = data[off - step] as i16;
- let c = data[off] as i16;
- let d = data[off + step] as i16;
+ let a = i16::from(data[off - step * 2]);
+ let b = i16::from(data[off - step]);
+ let c = i16::from(data[off]);
+ let d = i16::from(data[off + step]);
let mut diff = ((a - d) + 3 * (c - b) + 4) >> 3;
if diff.abs() >= 2 * loop_str {
diff = 0;
let mut didx = 0;
let mut sidx = 0;
for _ in 0..bh {
- for x in 0..bw { dst[didx + x] = src[sidx + x]; }
+ dst[didx..][..bw].copy_from_slice(&src[sidx..][..bw]);
didx += dstride;
sidx += sstride;
}
let mut didx = 0;
let mut sidx = 0;
for _ in 0..bh {
- for x in 0..bw { dst[didx + x] = (((src[sidx + x] as u16) + (src[sidx + x + 1] as u16)) >> 1) as u8; }
+ for x in 0..bw { dst[didx + x] = ((u16::from(src[sidx + x]) + u16::from(src[sidx + x + 1])) >> 1) as u8; }
didx += dstride;
sidx += sstride;
}
let mut didx = 0;
let mut sidx = 0;
for _ in 0..bh {
- for x in 0..bw { dst[didx + x] = (((src[sidx + x] as u16) + (src[sidx + x + sstride] as u16)) >> 1) as u8; }
+ for x in 0..bw { dst[didx + x] = ((u16::from(src[sidx + x]) + u16::from(src[sidx + x + sstride])) >> 1) as u8; }
didx += dstride;
sidx += sstride;
}
let mut sidx = 0;
for _ in 0..bh {
for x in 0..bw {
- dst[didx + x] = (((src[sidx + x] as u16) +
- (src[sidx + x + sstride + 1] as u16)) >> 1) as u8;
+ dst[didx + x] = ((u16::from(src[sidx + x]) +
+ u16::from(src[sidx + x + sstride + 1])) >> 1) as u8;
}
didx += dstride;
sidx += sstride;
let mut sidx = 0;
for _ in 0..bh {
for x in 0..bw {
- dst[didx + x] = (((src[sidx + x + 1] as u16) +
- (src[sidx + x + sstride] as u16)) >> 1) as u8;
+ dst[didx + x] = ((u16::from(src[sidx + x + 1]) +
+ u16::from(src[sidx + x + sstride])) >> 1) as u8;
}
didx += dstride;
sidx += sstride;
extern crate nihav_core;
extern crate nihav_codec_support;
+#[allow(clippy::collapsible_if)]
+#[allow(clippy::excessive_precision)]
+#[allow(clippy::identity_op)]
+#[allow(clippy::unreadable_literal)]
+#[allow(clippy::verbose_bit_mask)]
mod codecs;
pub use crate::codecs::duck_register_all_codecs;