Ok(())
}
-fn decode_block8x8(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tables: &TxParams8x8, is_intra: bool, is_2d: bool, prev_dc: &mut i32, quant: u8, coeffs: &mut [i32; 64], transform: &TrFunc) -> DecoderResult<()> {
+#[allow(clippy::cast_lossless)]
+fn decode_block8x8(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tables: &TxParams8x8, is_intra: bool, is_2d: bool, prev_dc: &mut i32, quant: u8, coeffs: &mut [i32; 64], transform: TrFunc) -> DecoderResult<()> {
let mut idx: isize = -1;
let quant_mat = if is_intra { tables.quant_intra } else { tables.quant_inter };
while idx <= 64 {
}
}
idx += run;
- validate!((idx >= 0) && (idx < 64));
+ validate!((0..64).contains(&idx));
let spos = tables.scan[idx as usize];
let q = (u32::from(quant_mat[spos]) * u32::from(quant)) >> 9;
(transform)(coeffs);
Ok(())
}
-fn decode_block4x4(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tables: &TxParams4x4, is_intra: bool, is_2d: bool, prev_dc: &mut i32, quant: u8, coeffs: &mut [i32; 64], transform: &TrFunc) -> DecoderResult<()> {
+#[allow(clippy::cast_lossless)]
+fn decode_block4x4(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tables: &TxParams4x4, is_intra: bool, is_2d: bool, prev_dc: &mut i32, quant: u8, coeffs: &mut [i32; 64], transform: TrFunc) -> DecoderResult<()> {
let mut idx: isize = -1;
let quant_mat = if is_intra { tables.quant_intra } else { tables.quant_inter };
while idx <= 64 {
}
}
idx += run;
- validate!((idx >= 0) && (idx < 16));
+ validate!((0..16).contains(&idx));
let spos = tables.scan[idx as usize];
let q = (u32::from(quant_mat[spos]) * u32::from(quant)) >> 9;
bref: Option<NABufferType>,
bands: Vec<BandHeader>,
+ band_tiles: usize,
tiles: Vec<IVITile>,
num_tiles: [[usize; 4]; 4],
tile_start: [[usize; 4]; 4],
bref: None,
bands,
+ band_tiles: 0,
tiles: Vec::new(), tile_start: [[0; 4]; 4], num_tiles: [[0; 4]; 4],
}
}
fn realloc(&mut self, pic_hdr: &PictureHeader) -> DecoderResult<()> {
let planes = if pic_hdr.transparent { 4 } else { 3 };
- //self.bands.truncate(0);
- self.tiles.truncate(0);
+ //self.bands.clear();
+ self.tiles.clear();
self.num_tiles = [[0; 4]; 4];
self.tile_start = [[0; 4]; 4];
let mut tstart: usize = 0;
tile_h = (tile_h + 1) >> 1;
}
}
+ if plane == 0 {
+ self.band_tiles = ((band_w + tile_w - 1) / tile_w) * ((band_h + tile_h - 1) / tile_h);
+ }
for band in 0..bands {
self.tile_start[plane][band] = tstart;
let band_xoff = if (band & 1) == 1 { band_w } else { 0 };
}
Ok(())
}
- fn decode_band(&mut self, pic_hdr: &PictureHeader, dec: &mut IndeoXParser, br: &mut BitReader, plane_no: usize, band_no: usize) -> DecoderResult<()> {
+ fn decode_band(&mut self, pic_hdr: &PictureHeader, dec: &mut dyn IndeoXParser, br: &mut BitReader, plane_no: usize, band_no: usize) -> DecoderResult<()> {
let bidx = match plane_no {
0 => { band_no },
_ => { pic_hdr.luma_bands + plane_no - 1 },
let mb_h = (tile.h + mb_size - 1) / mb_size;
tile.mb_w = mb_w;
tile.mb_h = mb_h;
- tile.mb.truncate(0);
+ tile.mb.clear();
tile.mb.resize(mb_w * mb_h, MB::new(0, 0));
}
let (ref_tiles, cur_tiles) = self.tiles.split_at_mut(tile_no);
let tile = &mut cur_tiles[0];
if plane_no != 0 || band_no != 0 {
- let rtile = &ref_tiles[0];
+ let rtile = &ref_tiles[tile_no % self.band_tiles];
if (tile.mb_w != rtile.mb_w) || (tile.mb_h != rtile.mb_h) {
ref_tile = None;
} else {
dec.decode_mb_info(br, pic_hdr, &band, tile, ref_tile, mv_scale)?;
}
- self.decode_tile(br, &band, tile_no, &tr, &tr_dc)?;
+ self.decode_tile(br, &band, tile_no, tr, tr_dc)?;
let skip_part = tile_end - br.tell();
br.skip(skip_part as u32)?;
} else {
mb.mtype = MBType::Inter;
mb.cbp = 0;
if band.inherit_mv {
- if let Some(ref tileref) = ref_tile {
+ if let Some(tileref) = ref_tile {
let mx = tileref.mb[mb_idx].mv_x;
let my = tileref.mb[mb_idx].mv_y;
mb.mv_x = scale_mv(mx, mv_scale);
}
}
}
- self.decode_tile(br, &band, tile_no, &tr, &tr_dc)?;
+ self.decode_tile(br, &band, tile_no, tr, tr_dc)?;
}
}
self.bands[bidx] = band;
br.align();
Ok(())
}
- fn decode_tile(&mut self, br: &mut BitReader, band: &BandHeader, tile_no: usize, tr: &TrFunc, transform_dc: &TrFuncDC) -> DecoderResult<()> {
+ fn decode_tile(&mut self, br: &mut BitReader, band: &BandHeader, tile_no: usize, tr: TrFunc, transform_dc: TrFuncDC) -> DecoderResult<()> {
let mut mb_idx = 0;
let mut prev_dc: i32 = 0;
let tile = &mut self.tiles[tile_no];
let stride = frame.plane_stride[band.plane_no];
let mut dstidx = tile.pos_x + tile.pos_y * stride;
- let mut dst = &mut frame.plane_buf[band.plane_no];
+ let dst = &mut frame.plane_buf[band.plane_no];
let pos_x = tile.pos_x;
let pos_y = tile.pos_y;
let tile_w = (tile.w + 15) & !15;
if let TxType::Transform8(ref params) = band.ttype {
decode_block8x8(br, &band.blk_cb, &band.rvmap, params, is_intra, band.tr.is_2d(), &mut prev_dc, mb.q, &mut blk, tr)?;
if is_intra {
- put_block(&mut dst, dstidx + boff, stride, &blk, 8);
+ put_block(dst, dstidx + boff, stride, &blk, 8);
} else {
- add_block(&mut dst, dstidx + boff, stride, &blk, 8);
+ add_block(dst, dstidx + boff, stride, &blk, 8);
}
}
if let TxType::Transform4(ref params) = band.ttype {
decode_block4x4(br, &band.blk_cb, &band.rvmap, params, is_intra, band.tr.is_2d(), &mut prev_dc, mb.q, &mut blk, tr)?;
if is_intra {
- put_block(&mut dst, dstidx + boff, stride, &blk, 4);
+ put_block(dst, dstidx + boff, stride, &blk, 4);
} else {
- add_block(&mut dst, dstidx + boff, stride, &blk, 4);
+ add_block(dst, dstidx + boff, stride, &blk, 4);
}
}
} else {
if is_intra {
(transform_dc)(&mut blk, prev_dc);
- put_block(&mut dst, dstidx + boff, stride, &blk, band.blk_size);
+ put_block(dst, dstidx + boff, stride, &blk, band.blk_size);
}
}
cbp >>= 1;
}
if is_intra {
if band.blk_size == 8 {
- put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
+ put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
} else {
- put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
+ put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
}
} else {
if band.blk_size == 8 {
- add_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
+ add_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
} else {
- add_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
+ add_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
}
}
} else {
if is_intra {
(transform_dc)(&mut blk, prev_dc);
if band.blk_size == 8 {
- put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
+ put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
} else {
- put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
+ put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
}
}
}
unreachable!();
}
- fn decode_single_frame<'a>(&mut self, dec: &mut IndeoXParser, br: &mut BitReader<'a>) -> DecoderResult<NABufferType> {
+ fn decode_single_frame<'a>(&mut self, dec: &mut dyn IndeoXParser, br: &mut BitReader<'a>) -> DecoderResult<NABufferType> {
let pic_hdr = dec.decode_picture_header(br)?;
self.ftype = pic_hdr.ftype;
if pic_hdr.ftype.is_null() {
Ok(buftype)
}
- pub fn decode_frame<'a>(&mut self, dec: &mut IndeoXParser, br: &mut BitReader<'a>) -> DecoderResult<NABufferType> {
+ pub fn decode_frame<'a>(&mut self, dec: &mut dyn IndeoXParser, br: &mut BitReader<'a>) -> DecoderResult<NABufferType> {
let res = self.decode_single_frame(dec, br);
if res.is_err() { return res; }
if (self.ftype == IVIFrameType::Intra) && (br.left() > 16) {
let seq = br.peek(21);
if seq == 0xBFFF8 {
let res2 = self.decode_single_frame(dec, br);
- if res2.is_ok() {
- self.bref = Some(res2.unwrap());
+ if let Ok(res) = res2 {
+ self.bref = Some(res);
}
}
self.ftype = IVIFrameType::Intra;