From: Kostya Shishkov Date: Wed, 5 Jun 2019 17:17:46 +0000 (+0200) Subject: VP4 decoder X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=8e4b2f445d2c3e530e5fa517e19f9639142479cf;p=nihav.git VP4 decoder --- diff --git a/nihav-duck/Cargo.toml b/nihav-duck/Cargo.toml index 97870fe..cecf251 100644 --- a/nihav-duck/Cargo.toml +++ b/nihav-duck/Cargo.toml @@ -14,7 +14,7 @@ nihav_commonfmt = { path = "../nihav-commonfmt" } [features] default = ["all_decoders"] -all_decoders = ["decoder_truemotion1", "decoder_truemotionrt", "decoder_dk3_adpcm", "decoder_dk4_adpcm", "decoder_truemotion2", "decoder_truemotion2x", "decoder_vp3"]#, "decoder_vp4", "decoder_vp5", "decoder_vp6", "decoder_vp7", "decoder_on2avc"] +all_decoders = ["decoder_truemotion1", "decoder_truemotionrt", "decoder_dk3_adpcm", "decoder_dk4_adpcm", "decoder_truemotion2", "decoder_truemotion2x", "decoder_vp3", "decoder_vp4"]#, "decoder_vp5", "decoder_vp6", "decoder_vp7", "decoder_on2avc"] decoders = [] decoder_truemotion1 = ["decoders"] diff --git a/nihav-duck/src/codecs/vp3.rs b/nihav-duck/src/codecs/vp3.rs index 2e6137f..698d623 100644 --- a/nihav-duck/src/codecs/vp3.rs +++ b/nihav-duck/src/codecs/vp3.rs @@ -98,6 +98,73 @@ impl VP31Codes { } Self { dc_cb, ac0_cb, ac1_cb, ac2_cb, ac3_cb } } + fn new_vp4() -> VP31Codes { + let mut dc_cb: [Codebook; 16]; + let mut ac0_cb: [Codebook; 16]; + let mut ac1_cb: [Codebook; 16]; + let mut ac2_cb: [Codebook; 16]; + let mut ac3_cb: [Codebook; 16]; + unsafe { + dc_cb = mem::uninitialized(); + ac0_cb = mem::uninitialized(); + ac1_cb = mem::uninitialized(); + ac2_cb = mem::uninitialized(); + ac3_cb = mem::uninitialized(); + for i in 0..16 { + let mut cr = TableCodebookDescReader::new(&VP40_DC_CODES[i], &VP40_DC_BITS[i], map_idx); + let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); + ptr::write(&mut dc_cb[i], cb); + + let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT0_CODES[i], &VP40_AC_CAT0_BITS[i], map_idx); + let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); + ptr::write(&mut ac0_cb[i], cb); + let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT1_CODES[i], &VP40_AC_CAT1_BITS[i], map_idx); + let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); + ptr::write(&mut ac1_cb[i], cb); + let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT2_CODES[i], &VP40_AC_CAT2_BITS[i], map_idx); + let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); + ptr::write(&mut ac2_cb[i], cb); + let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT3_CODES[i], &VP40_AC_CAT3_BITS[i], map_idx); + let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); + ptr::write(&mut ac3_cb[i], cb); + } + } + VP31Codes { dc_cb, ac0_cb, ac1_cb, ac2_cb, ac3_cb } + } +} + +struct VP40AuxCodes { + mv_x_cb: [Codebook; 7], + mv_y_cb: [Codebook; 7], + mbpat_cb: [Codebook; 2], +} + +fn map_mv(idx: usize) -> i8 { + (idx as i8) - 31 +} + +impl VP40AuxCodes { + fn new() -> Self { + let mut mv_x_cb: [Codebook; 7]; + let mut mv_y_cb: [Codebook; 7]; + unsafe { + mv_x_cb = mem::uninitialized(); + mv_y_cb = mem::uninitialized(); + for i in 0..7 { + let mut cr = TableCodebookDescReader::new(&VP40_MV_X_CODES[i], &VP40_MV_X_BITS[i], map_mv); + let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); + ptr::write(&mut mv_x_cb[i], cb); + let mut cr = TableCodebookDescReader::new(&VP40_MV_Y_CODES[i], &VP40_MV_Y_BITS[i], map_mv); + let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap(); + ptr::write(&mut mv_y_cb[i], cb); + } + } + let mut cr0 = TableCodebookDescReader::new(&VP40_MBPAT_CODES[0], &VP40_MBPAT_BITS[0], map_idx); + let mut cr1 = TableCodebookDescReader::new(&VP40_MBPAT_CODES[1], &VP40_MBPAT_BITS[1], map_idx); + let mbpat_cb = [Codebook::new(&mut cr0, CodebookMode::MSB).unwrap(), + Codebook::new(&mut cr1, CodebookMode::MSB).unwrap()]; + Self { mv_x_cb, mv_y_cb, mbpat_cb } + } } enum Codes { @@ -146,6 +213,19 @@ fn read_short_run(br: &mut BitReader) -> DecoderResult { Ok(VP31_SHORT_RUN_BASE[pfx] + (br.read(VP31_SHORT_RUN_BITS[pfx])? as usize)) } +fn read_mb_run(br: &mut BitReader) -> DecoderResult { + let pfx = br.read_code(UintCodeType::LimitedUnary(10, 0))? as usize; + if pfx == 10 { unimplemented!(); } + if pfx < 2 { + Ok(pfx + 1) + } else { + let base = (1 << (pfx - 1)) + 1; + let bits = (pfx - 1) as u8; + let add_bits = br.read(bits)? as usize; + Ok(base + add_bits) + } +} + struct BitRunDecoder { value: bool, run: usize, @@ -235,20 +315,25 @@ struct VP34Decoder { quant: usize, shuf: VPShuffler, codes: Codes, + aux_codes: Option, loop_str: i16, + mc_buf: NAVideoBufferRef, blocks: Vec, mb_coded: Vec, + mb_partial: Vec, y_blocks: usize, y_sbs: usize, qmat_y: [i16; 64], qmat_c: [i16; 64], - qmat_inter: [i16; 64], + qmat_y_p: [i16; 64], + qmat_c_p: [i16; 64], eob_run: usize, last_dc: [i16; 3], blk_addr: Vec, + blk_sub: Vec, sb_info: Vec, sb_blocks: Vec, sb_mbs: Vec, @@ -520,6 +605,8 @@ pub const VP3_INTERP_FUNCS: &[blockdsp::BlkInterpFunc] = &[ vp3_interp00, vp3_in impl VP34Decoder { fn new(version: u8) -> Self { + let vt = alloc_video_buffer(NAVideoInfo::new(24, 24, false, YUV420_FORMAT), 4).unwrap(); + let mc_buf = vt.get_vbuf().unwrap(); Self { info: NACodecInfoRef::default(), width: 0, @@ -531,21 +618,26 @@ impl VP34Decoder { quant: 0, shuf: VPShuffler::new(), codes: Codes::None, + aux_codes: None, loop_str: 0, + mc_buf, blocks: Vec::new(), mb_coded: Vec::new(), + mb_partial: Vec::new(), y_blocks: 0, y_sbs: 0, qmat_y: [0; 64], qmat_c: [0; 64], - qmat_inter: [0; 64], + qmat_y_p: [0; 64], + qmat_c_p: [0; 64], eob_run: 0, last_dc: [0; 3], blk_addr: Vec::new(), + blk_sub: Vec::new(), sb_info: Vec::new(), sb_blocks: Vec::new(), sb_mbs: Vec::new(), @@ -556,7 +648,6 @@ impl VP34Decoder { self.is_intra = !br.read_bool()?; br.skip(1)?; self.quant = br.read(6)? as usize; - self.loop_str = VP31_LOOP_STRENGTH[self.quant]; if self.is_intra { if br.peek(8) != 0 { validate!(self.version == 3 || self.version == 30); @@ -580,14 +671,29 @@ println!("intra, ver {} (self {})", version, self.version); self.version = 31; self.codes = Codes::VP31(VP31Codes::new()); } - } else if version == 2 { + } else if version == 3 { validate!(self.version == 4); - unimplemented!(); + let mb_h = br.read(8)? as usize; + let mb_w = br.read(8)? as usize; +//println!(" VP40 {}x{} ({}x{})", mb_w, mb_h, self.mb_w, self.mb_h); + validate!(mb_w == self.mb_w && mb_h == self.mb_h); + let fact1 = br.read(5)?; + let fact2 = br.read(3)?; + validate!(fact1 == 1 && fact2 == 1); + let fact1 = br.read(5)?; + let fact2 = br.read(3)?; + validate!(fact1 == 1 && fact2 == 1); + br.skip(2)?; } else { return Err(DecoderError::InvalidData); } } } + self.loop_str = if self.version != 4 { + VP31_LOOP_STRENGTH[self.quant] + } else { + VP40_LOOP_STRENGTH[self.quant] + }; //println!("decode frame({},{},{})", self.is_intra as u8, self.is_intra as u8, self.quant); Ok(()) } @@ -965,6 +1071,220 @@ println!("intra, ver {} (self {})", version, self.version); Err(DecoderError::Bug) } } + fn vp40_unpack_sb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> { + let mut has_uncoded = false; + + if let Some(ref aux_codes) = self.aux_codes { + for el in self.sb_info.iter_mut() { + *el = SBState::Partial; + } + { + let mut mbiter = self.mb_coded.iter_mut(); + let mut brun = BitRunDecoder::new(br, read_mb_run)?; + for nmb in self.sb_mbs.iter() { + let nmbs = *nmb as usize; + for _ in 0..nmbs { + let coded = brun.get_val(br)?; + *mbiter.next().unwrap() = coded; + has_uncoded |= !coded; + } + } + } + if has_uncoded { + let mut mbiter = self.mb_coded.iter().zip(self.mb_partial.iter_mut()); + let mut brun = BitRunDecoder::new(br, read_mb_run)?; + for nmb in self.sb_mbs.iter() { + let nmbs = *nmb as usize; + for _ in 0..nmbs { + let (coded, partial) = mbiter.next().unwrap(); + if *coded { + *partial = false; + } else { + *partial = brun.get_val(br)?; + } + } + } + + let mut bpmode = 0; + let mut cur_blk = 0; + for ((coded, partial), nblk) in self.mb_coded.iter().zip(self.mb_partial.iter()).zip(self.mb_blocks.iter()) { + let nblks = *nblk as usize; + if *coded { + for _ in 0..nblks { + let addr = self.blk_addr[cur_blk] >> 2; + self.blocks[addr].coded = true; + cur_blk += 1; + } + } else if !*partial { + for _ in 0..nblks { + let addr = self.blk_addr[cur_blk] >> 2; + self.blocks[addr].coded = false; + cur_blk += 1; + } + } else { + let mut pat = br.read_cb(&aux_codes.mbpat_cb[bpmode])? + 1; + bpmode = VP40_BP_PREDICTOR[pat as usize] as usize; + + let mut addrs = [0; 4]; + for i in 0..nblks { + addrs[i] = self.blk_addr[cur_blk + i] >> 2; + for j in (0..i).rev() { + if addrs[j] > addrs[j + 1] { + addrs.swap(j, j + 1); + } + } + } + for i in 0..nblks { + self.blocks[addrs[i]].coded = (pat & 8) != 0; + pat <<= 1; + cur_blk += 1; + } + } + } + } + Ok(()) + } else { + Err(DecoderError::Bug) + } + } + fn vp40_unpack_mv_info(&mut self, br: &mut BitReader) -> DecoderResult<()> { + let mut last_mv = ZERO_MV; + let mut last2_mv = ZERO_MV; + let mut last_mv_g = ZERO_MV; + + let mut cur_blk = 0; + if let Some(ref codes) = self.aux_codes { + for _ in 0..self.y_blocks/4 { + if self.blocks[self.blk_addr[cur_blk] >> 2].btype == VPMBType::InterFourMV { + let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.abs() as usize]]; + 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; + last2_mv = last_mv; + 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]; + blk.mv.x = br.read_cb(x_cb)? as i16; + if x_sign { + blk.mv.x = -blk.mv.x; + } + blk.mv.y = br.read_cb(y_cb)? as i16; + if y_sign { + blk.mv.y = -blk.mv.y; + } + last_mv = blk.mv; + cur_blk += 1; + } + } else { + let cur_mv; + match self.blocks[self.blk_addr[cur_blk] >> 2].btype { + VPMBType::Intra | VPMBType::InterNoMV | VPMBType::GoldenNoMV => { + cur_mv = ZERO_MV; + }, + VPMBType::InterMV => { + let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.abs() as usize]]; + 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; + 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; + }, + VPMBType::InterNearest => { + cur_mv = last_mv; + }, + VPMBType::InterNear => { + cur_mv = last2_mv; + std::mem::swap(&mut last_mv, &mut last2_mv); + }, + _ => { // GoldenMV + let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv_g.x.abs() as usize]]; + 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; + cur_mv = MV { x: if !x_sign { x } else { -x }, y: if !y_sign { y } else { -y } }; + last_mv_g = cur_mv; + }, + }; + for _ in 0..4 { + self.blocks[self.blk_addr[cur_blk] >> 2].mv = cur_mv; + cur_blk += 1; + } + } + } + Ok(()) + } else { + Err(DecoderError::Bug) + } + } + fn vp40_unpack_coeffs(&mut self, br: &mut BitReader, dc_table_y: usize, dc_table_c: usize, ac_table_y: usize, ac_table_c: usize) -> DecoderResult<()> { + const VP40_PRED_MASKS: [usize; 16] = [ // top, bottom, left, right + 0b1010, 0b1010, 0b1000, 0b1011, + 0b1010, 0b1010, 0b0010, 0b1111, + 0b0010, 0b1010, 0b0010, 0b0110, + 0b0100, 0b0111, 0b1110, 0b1110 + ]; + self.last_dc = [0; 3]; + if let Codes::VP31(ref codes) = self.codes { + let mut coef_eob: [usize; 64] = [0; 64]; + for (blkaddr, bsub) in self.blk_addr.iter().zip(self.blk_sub.iter()) { + let blk: &mut Block = &mut self.blocks[blkaddr >> 2]; + if !blk.coded { continue; } + let mut idx = blkaddr >> 2; + let (bx, by) = if (blkaddr & 3) == 0 { + (idx % (self.mb_w * 2), idx / (self.mb_w * 2)) + } else { + idx -= self.mb_w * self.mb_h * 4; + if idx >= self.mb_w * self.mb_h { + idx -= self.mb_w * self.mb_h; + } + (idx % self.mb_w, idx / self.mb_w) + }; + while blk.idx < 64 { + if coef_eob[blk.idx] > 0 { + coef_eob[blk.idx] -= 1; + blk.idx = 64; + continue; + } + let cbs = if blk.idx == 0 { + [&codes.dc_cb[dc_table_y], &codes.dc_cb[dc_table_c]] + } else if blk.idx < 6 { + [&codes.ac0_cb[ac_table_y], &codes.ac0_cb[ac_table_c]] + } else if blk.idx < 15 { + [&codes.ac1_cb[ac_table_y], &codes.ac1_cb[ac_table_c]] + } else if blk.idx < 28 { + [&codes.ac2_cb[ac_table_y], &codes.ac2_cb[ac_table_c]] + } else { + [&codes.ac3_cb[ac_table_y], &codes.ac3_cb[ac_table_c]] + }; + let cb = if (blkaddr & 3) == 0 { cbs[0] } else { cbs[1] }; + let token = br.read_cb(cb)?; + expand_token(blk, br, &mut coef_eob[blk.idx], blk.idx, token)?; + if blk.idx == 64 { break; } + } + let idx = blkaddr >> 2; + let mask = VP40_PRED_MASKS[*bsub as usize]; + if (blkaddr & 3) == 0 { + let pred_dc = self.vp40_predict_dc(bx, by, self.mb_w * 2, self.mb_h * 2, idx, mask, true); + let blk: &mut Block = &mut self.blocks[blkaddr >> 2]; + blk.coeffs[0] += pred_dc; + self.last_dc[blk.btype.get_ref_id() as usize] = blk.coeffs[0]; + } else { + let pred_dc = self.vp40_predict_dc(bx, by, self.mb_w, self.mb_h, idx, mask, false); + let blk: &mut Block = &mut self.blocks[blkaddr >> 2]; + blk.coeffs[0] += pred_dc; + self.last_dc[blk.btype.get_ref_id() as usize] = blk.coeffs[0]; + } + } + Ok(()) + } else { + Err(DecoderError::Bug) + } + } fn decode_vp30(&mut self, br: &mut BitReader, frm: &mut NASimpleVideoFrame) -> DecoderResult<()> { for blk in self.blocks.iter_mut() { blk.coeffs = [0; 64]; @@ -990,7 +1310,7 @@ println!("intra, ver {} (self {})", version, self.version); let ac_quant = VP30_AC_SCALES[self.quant]; rescale_qmat(&mut self.qmat_y, VP3_QMAT_Y, dc_quant, ac_quant, 2); rescale_qmat(&mut self.qmat_c, VP3_QMAT_C, dc_quant, ac_quant, 2); - rescale_qmat(&mut self.qmat_inter, VP3_QMAT_INTER, dc_quant, ac_quant, 4); + rescale_qmat(&mut self.qmat_y_p, VP3_QMAT_INTER, dc_quant, ac_quant, 4); if self.quant == 10 { self.qmat_y[29] = 980; self.qmat_y[58] = 1636; @@ -1000,6 +1320,7 @@ println!("intra, ver {} (self {})", version, self.version); } else if self.quant == 44 { self.qmat_y[58] = 224; } + self.qmat_c_p.copy_from_slice(&self.qmat_y_p); let table = if ac_quant <= 50 { 0 @@ -1066,7 +1387,8 @@ println!("intra, ver {} (self {})", version, self.version); let ac_quant = VP31_AC_SCALES[self.quant]; rescale_qmat(&mut self.qmat_y, VP3_QMAT_Y, dc_quant, ac_quant, 2); rescale_qmat(&mut self.qmat_c, VP3_QMAT_C, dc_quant, ac_quant, 2); - rescale_qmat(&mut self.qmat_inter, VP3_QMAT_INTER, dc_quant, ac_quant, 4); + rescale_qmat(&mut self.qmat_y_p, VP3_QMAT_INTER, dc_quant, ac_quant, 4); + rescale_qmat(&mut self.qmat_c_p, VP3_QMAT_INTER, dc_quant, ac_quant, 4); self.eob_run = 0; let dc_table_y = br.read(4)? as usize; @@ -1091,10 +1413,51 @@ println!("intra, ver {} (self {})", version, self.version); Ok(()) } - fn decode_vp4(&mut self) -> DecoderResult<()> { -unimplemented!(); + fn decode_vp4(&mut self, br: &mut BitReader, frm: &mut NASimpleVideoFrame) -> DecoderResult<()> { + for blk in self.blocks.iter_mut() { + blk.coeffs = [0; 64]; + blk.idx = 0; + blk.coded = false; + blk.has_ac = false; + } + if self.is_intra { + for sb in self.sb_info.iter_mut() { *sb = SBState::Coded; } + for blk in self.blocks.iter_mut() { + blk.btype = VPMBType::Intra; + blk.coded = true; + } + } else { + if self.shuf.get_last().is_none() || self.shuf.get_golden().is_none() { + return Err(DecoderError::MissingReference); + } + self.vp40_unpack_sb_info(br)?; + self.vp31_unpack_mb_info(br)?; + self.vp40_unpack_mv_info(br)?; + } + let dc_y_quant = VP40_DC_Y_SCALES[self.quant]; + let dc_c_quant = VP40_DC_C_SCALES[self.quant]; + let ac_quant = VP40_AC_SCALES[self.quant]; + rescale_qmat(&mut self.qmat_y, VP40_QMAT, dc_y_quant, ac_quant, 2); + rescale_qmat(&mut self.qmat_c, VP40_QMAT, dc_c_quant, ac_quant, 2); + self.qmat_y_p.copy_from_slice(&self.qmat_y); + self.qmat_c_p.copy_from_slice(&self.qmat_c); + + self.eob_run = 0; + let dc_table_y = br.read(4)? as usize; + let dc_table_c = br.read(4)? as usize; + let ac_table_y = br.read(4)? as usize; + let ac_table_c = br.read(4)? as usize; + self.vp40_unpack_coeffs(br, dc_table_y, dc_table_c, ac_table_y, ac_table_c)?; + + if self.is_intra { + self.output_blocks_intra(frm); + } else { + self.output_blocks_inter(frm); + } + + Ok(()) } - fn predict_dc(&self, bx: usize, by: usize, bw: usize, blk_idx: usize) -> i16 { + fn vp31_predict_dc(&self, bx: usize, by: usize, bw: usize, blk_idx: usize) -> i16 { let mut preds = [0i32; 4]; let mut pp: usize = 0; let ref_id = self.blocks[blk_idx].btype.get_ref_id(); @@ -1126,6 +1489,39 @@ unimplemented!(); } pred as i16 } + 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; + let ref_id = self.blocks[blk_idx].btype.get_ref_id(); + if (by > 0) && (((mask >> 3) & 1) == 1) { //top + fill_dc_pred!(self, ref_id, preds, pp, 0, blk_idx - bw); + } + if (by < bh - 1) && (((mask >> 2) & 1) == 1) { //bottom + fill_dc_pred!(self, ref_id, preds, pp, 1, blk_idx + bw); + } + if (bx > 0) && (((mask >> 1) & 1) == 1) { //left + fill_dc_pred!(self, ref_id, preds, pp, 2, blk_idx - 1); + } + if (is_luma && bx == 0 && (by >= 4)) && (((mask >> 1) & 1) == 1) { //left wrap + fill_dc_pred!(self, ref_id, preds, pp, 2, blk_idx - 1 - 3 * bw); + } + if (bx < bw - 1) && (((mask >> 0) & 1) == 1) { //right + fill_dc_pred!(self, ref_id, preds, pp, 3, blk_idx + 1); + } + if pp == 0 { return self.last_dc[ref_id as usize]; } + let mut pred = 0i32; + let mut npred = 0; + for i in 0..4 { + if (pp & (1 << i)) != 0 { + pred += preds[i] as i32; + npred += 1; + if npred == 2 { + return (pred / 2) as i16; + } + } + } + self.last_dc[ref_id as usize] + } fn restore_dcs(&mut self) { let blk_stride = self.mb_w * 2; let mut blk_idx = 0; @@ -1133,7 +1529,7 @@ unimplemented!(); for by in 0..self.mb_h*2 { for bx in 0..self.mb_w*2 { if !self.blocks[blk_idx + bx].coded { continue; } - let dc = self.predict_dc(bx, by, self.mb_w*2, blk_idx + bx); + let dc = self.vp31_predict_dc(bx, by, self.mb_w*2, blk_idx + bx); self.blocks[blk_idx + bx].coeffs[0] += dc; self.last_dc[self.blocks[blk_idx + bx].btype.get_ref_id() as usize] = self.blocks[blk_idx + bx].coeffs[0]; } @@ -1145,7 +1541,7 @@ unimplemented!(); for by in 0..self.mb_h { for bx in 0..self.mb_w { if !self.blocks[blk_idx + bx].coded { continue; } - let dc = self.predict_dc(bx, by, self.mb_w, blk_idx + bx); + let dc = self.vp31_predict_dc(bx, by, self.mb_w, blk_idx + bx); self.blocks[blk_idx + bx].coeffs[0] += dc; self.last_dc[self.blocks[blk_idx + bx].btype.get_ref_id() as usize] = self.blocks[blk_idx + bx].coeffs[0]; } @@ -1158,7 +1554,7 @@ unimplemented!(); for by in 0..self.mb_h*2 { for bx in 0..self.mb_w*2 { let mut blk = biter.next().unwrap(); - let qmat = if blk.btype == VPMBType::Intra { &self.qmat_y } else { &self.qmat_inter }; + let qmat = &self.qmat_y; blk.coeffs[0] *= qmat[0]; if blk.has_ac { unquant(&mut blk.coeffs, qmat); @@ -1172,7 +1568,7 @@ unimplemented!(); for by in 0..self.mb_h { for bx in 0..self.mb_w { let mut blk = biter.next().unwrap(); - let qmat = if blk.btype == VPMBType::Intra { &self.qmat_c } else { &self.qmat_inter }; + let qmat = &self.qmat_c; blk.coeffs[0] *= qmat[0]; if blk.has_ac { unquant(&mut blk.coeffs, qmat); @@ -1202,13 +1598,41 @@ unimplemented!(); let src = self.shuf.get_last().unwrap(); let mode = ((mv_a.x & 1) + (mv_a.y & 1) * 2) as usize; - copy_block(frm, src.clone(), 0, bx * 8, by * 8, mv_a.x >> 1, mv_a.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + if self.version != 4 { + copy_block(frm, src.clone(), 0, bx * 8, by * 8, + mv_a.x >> 1, mv_a.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + } else { + vp_copy_block(frm, src.clone(), 0, bx * 8, by * 8, + mv_a.x >> 1, mv_a.y >> 1, 0, 1, self.loop_str, + mode, VP3_INTERP_FUNCS, self.mc_buf.clone()); + } let mode = ((mv_b.x & 1) + (mv_b.y & 1) * 2) as usize; - copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8, mv_b.x >> 1, mv_b.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + if self.version != 4 { + copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8, + mv_b.x >> 1, mv_b.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + } else { + vp_copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8, + mv_b.x >> 1, mv_b.y >> 1, 0, 1, self.loop_str, + mode, VP3_INTERP_FUNCS, self.mc_buf.clone()); + } let mode = ((mv_c.x & 1) + (mv_c.y & 1) * 2) as usize; - copy_block(frm, src.clone(), 0, bx * 8, by * 8 + 8, mv_c.x >> 1, mv_c.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + if self.version != 4 { + copy_block(frm, src.clone(), 0, bx * 8, by * 8 + 8, + mv_c.x >> 1, mv_c.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + } else { + vp_copy_block(frm, src.clone(), 0, bx * 8, by * 8 + 8, + mv_c.x >> 1, mv_c.y >> 1, 0, 1, self.loop_str, + mode, VP3_INTERP_FUNCS, self.mc_buf.clone()); + } let mode = ((mv_d.x & 1) + (mv_d.y & 1) * 2) as usize; - copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8 + 8, mv_d.x >> 1, mv_d.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + if self.version != 4 { + copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8 + 8, + mv_d.x >> 1, mv_d.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + } else { + vp_copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8 + 8, + mv_d.x >> 1, mv_d.y >> 1, 0, 1, self.loop_str, + mode, VP3_INTERP_FUNCS, self.mc_buf.clone()); + } let mx = (mv_sum.x >> 1) | (mv_sum.x & 1); let my = (mv_sum.y >> 1) | (mv_sum.y & 1); @@ -1231,14 +1655,41 @@ unimplemented!(); self.shuf.get_golden().unwrap() }; let mode = ((blk.mv.x & 1) + (blk.mv.y & 1) * 2) as usize; - copy_block(frm, src.clone(), 0, bx * 8, by * 8, blk.mv.x >> 1, blk.mv.y >> 1, 16, 16, 0, 1, mode, VP3_INTERP_FUNCS); + if self.version != 4 { + copy_block(frm, src.clone(), 0, bx * 8, by * 8, + blk.mv.x >> 1, blk.mv.y >> 1, 16, 16, 0, 1, mode, VP3_INTERP_FUNCS); + } else { + vp_copy_block(frm, src.clone(), 0, bx * 8, by * 8, + blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str, + mode, VP3_INTERP_FUNCS, self.mc_buf.clone()); + vp_copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8, + blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str, + mode, VP3_INTERP_FUNCS, self.mc_buf.clone()); + vp_copy_block(frm, src.clone(), 0, bx * 8, by * 8 + 8, + blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str, + mode, VP3_INTERP_FUNCS, self.mc_buf.clone()); + vp_copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8 + 8, + blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str, + mode, VP3_INTERP_FUNCS, self.mc_buf.clone()); + } let mx = (blk.mv.x >> 1) | (blk.mv.x & 1); let my = (blk.mv.y >> 1) | (blk.mv.y & 1); let mode = ((mx & 1) + (my & 1) * 2) as usize; - copy_block(frm, src.clone(), 1, bx * 4, by * 4, mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); - copy_block(frm, src.clone(), 2, bx * 4, by * 4, mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + if self.version != 4 { + copy_block(frm, src.clone(), 1, bx * 4, by * 4, + mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + copy_block(frm, src.clone(), 2, bx * 4, by * 4, + mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS); + } else { + vp_copy_block(frm, src.clone(), 1, bx * 4, by * 4, + mx >> 1, my >> 1, 0, 1, self.loop_str, + mode, VP3_INTERP_FUNCS, self.mc_buf.clone()); + vp_copy_block(frm, src.clone(), 2, bx * 4, by * 4, + mx >> 1, my >> 1, 0, 1, self.loop_str, + mode, VP3_INTERP_FUNCS, self.mc_buf.clone()); + } } - let qmat = if blk.btype.is_intra() { &self.qmat_y } else { &self.qmat_inter }; + let qmat = if blk.btype.is_intra() { &self.qmat_y } else { &self.qmat_y_p }; blk.coeffs[0] *= qmat[0]; if blk.has_ac { unquant(&mut blk.coeffs, qmat); @@ -1264,7 +1715,7 @@ unimplemented!(); for by in 0..self.mb_h { for bx in 0..self.mb_w { let mut blk = biter.next().unwrap(); - let qmat = if blk.btype.is_intra() { &self.qmat_c } else { &self.qmat_inter }; + let qmat = if blk.btype.is_intra() { &self.qmat_c } else { &self.qmat_c_p }; blk.coeffs[0] *= qmat[0]; if blk.has_ac { unquant(&mut blk.coeffs, qmat); @@ -1332,6 +1783,7 @@ unimplemented!(); self.mb_blocks = Vec::with_capacity(tot_mb); self.sb_mbs = Vec::with_capacity(tot_sb); self.blk_addr = Vec::with_capacity(tot_blk); + self.blk_sub = Vec::with_capacity(tot_blk); self.y_blocks = bw * bh; let mut base_idx = 0; for plane in 0..3 { @@ -1367,6 +1819,7 @@ unimplemented!(); if (bx >= blk_w) || (by >= blk_h) { continue; } let idx = base_idx + bx + by * blk_w; self.blk_addr.push(idx * 4 + plane); + self.blk_sub.push(blk_no as u8); nblocks += 1; } self.sb_blocks.push(nblocks); @@ -1376,6 +1829,7 @@ unimplemented!(); } self.blocks.resize(tot_blk, Block::new()); self.mb_coded.resize(tot_mb, false); + self.mb_partial.resize(tot_mb, false); } } @@ -1393,8 +1847,10 @@ impl NADecoder for VP34Decoder { supp.pool_u8.set_dec_bufs(3); supp.pool_u8.prealloc_video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt), 4)?; - if self.version == 3 { - self.generate_block_addr(); + self.generate_block_addr(); + if self.version == 4 { + self.codes = Codes::VP31(VP31Codes::new_vp4()); + self.aux_codes = Some(VP40AuxCodes::new()); } Ok(()) } else { @@ -1420,7 +1876,7 @@ impl NADecoder for VP34Decoder { match self.version { 30 => self.decode_vp30(&mut br, &mut dframe)?, 31 => self.decode_vp31(&mut br, &mut dframe)?, - 4 => self.decode_vp4()?, + 4 => self.decode_vp4(&mut br, &mut dframe)?, _ => return Err(DecoderError::Bug), } @@ -1440,9 +1896,9 @@ pub fn get_decoder_vp3() -> Box { Box::new(VP34Decoder::new(3)) } -/*pub fn get_decoder_vp4() -> Box { +pub fn get_decoder_vp4() -> Box { Box::new(VP34Decoder::new(4)) -}*/ +} #[cfg(test)] mod test { @@ -1460,7 +1916,7 @@ mod test { duck_register_all_codecs(&mut dec_reg); let file = "assets/Duck/vp30-logo.avi"; - test_file_decoding("avi", file, Some(23), true, false, Some("vp30"), &dmx_reg, &dec_reg); + test_file_decoding("avi", file, Some(23), true, false, None/*Some("vp30")*/, &dmx_reg, &dec_reg); } #[test] @@ -1473,7 +1929,7 @@ mod test { let file = "assets/Duck/vp31.avi"; // let file = "assets/Duck/vp31_crash.avi"; // let file = "assets/Duck/01-vp31-0500.avi"; - test_file_decoding("avi", file, Some(3), true, false, Some("vp31"), &dmx_reg, &dec_reg); + test_file_decoding("avi", file, Some(3), true, false, None/*Some("vp31")*/, &dmx_reg, &dec_reg); //panic!("end"); } @@ -1485,7 +1941,8 @@ mod test { duck_register_all_codecs(&mut dec_reg); let file = "assets/Duck/ot171_vp40.avi"; - test_file_decoding("avi", file, Some(16), true, false, Some("vp4"), &dmx_reg, &dec_reg); + test_file_decoding("avi", file, Some(16), true, false, None/*Some("vp4")*/, &dmx_reg, &dec_reg); +//panic!("end"); } } @@ -2470,3 +2927,950 @@ const VP30_MBTYPE_SYMS: [VPMBType; 7] = [ VPMBType::InterNoMV, VPMBType::Intra, VPMBType::InterMV, VPMBType::InterNearest, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV ]; + +const VP40_DC_CODES: [[u32; 32]; 16] = [ + [ + 0x000C, 0x0070, 0x01CA, 0x01CB, 0x0391, 0x1C9B, 0x3935, 0x0071, + 0x3934, 0x000B, 0x000F, 0x0019, 0x0002, 0x0009, 0x0003, 0x001D, + 0x0018, 0x0007, 0x000D, 0x0002, 0x0000, 0x000A, 0x0008, 0x001A, + 0x0073, 0x006F, 0x0E4C, 0x0727, 0x0392, 0x0390, 0x0036, 0x006E + ], [ + 0x0011, 0x007A, 0x0083, 0x0040, 0x0105, 0x0413, 0x0410, 0x007B, + 0x0822, 0x000E, 0x0002, 0x0002, 0x0006, 0x000A, 0x0007, 0x001F, + 0x0017, 0x0009, 0x000D, 0x0000, 0x000C, 0x0003, 0x003C, 0x002C, + 0x0021, 0x0169, 0x0412, 0x02D0, 0x02D1, 0x0823, 0x005B, 0x00B5 + ], [ + 0x0017, 0x0010, 0x00B6, 0x0022, 0x016A, 0x02D0, 0x0B48, 0x0077, + 0x1692, 0x0000, 0x0003, 0x0003, 0x0009, 0x000C, 0x0005, 0x0002, + 0x001C, 0x0008, 0x000D, 0x000F, 0x000A, 0x0009, 0x0023, 0x003A, + 0x002C, 0x016B, 0x05A5, 0x02D3, 0x02D1, 0x1693, 0x0076, 0x00B7 + ], [ + 0x001E, 0x0013, 0x00FB, 0x007C, 0x0046, 0x07D6, 0x0FA9, 0x0012, + 0x1F50, 0x0001, 0x0004, 0x0005, 0x000A, 0x000E, 0x0007, 0x0000, + 0x0017, 0x0006, 0x000D, 0x000C, 0x0001, 0x002C, 0x008F, 0x003F, + 0x002D, 0x01F4, 0x07D5, 0x008E, 0x07D7, 0x1F51, 0x0010, 0x0022 + ], [ + 0x0001, 0x002B, 0x0012, 0x0055, 0x0027, 0x03B0, 0x0762, 0x0077, + 0x0261, 0x0002, 0x0006, 0x0007, 0x000B, 0x000F, 0x0008, 0x0000, + 0x001C, 0x0003, 0x0009, 0x0006, 0x0014, 0x0054, 0x0131, 0x0005, + 0x003A, 0x01D9, 0x0099, 0x004D, 0x0763, 0x0260, 0x0008, 0x00ED + ], [ + 0x0004, 0x0033, 0x0060, 0x0065, 0x00C2, 0x030D, 0x0619, 0x0064, + 0x1862, 0x0004, 0x0007, 0x000A, 0x000B, 0x000D, 0x0006, 0x0000, + 0x000F, 0x0003, 0x0005, 0x0002, 0x0002, 0x0077, 0x0C30, 0x0003, + 0x0031, 0x0187, 0x01D9, 0x00ED, 0x01D8, 0x1863, 0x001C, 0x003A + ], [ + 0x0008, 0x000A, 0x006A, 0x0016, 0x001E, 0x034E, 0x069F, 0x0068, + 0x0D28, 0x0005, 0x0007, 0x0007, 0x000C, 0x0000, 0x0006, 0x001B, + 0x0012, 0x0002, 0x0004, 0x0013, 0x000E, 0x034B, 0x1A53, 0x0006, + 0x0017, 0x01A6, 0x069E, 0x01A4, 0x0695, 0x1A52, 0x006B, 0x001F + ], [ + 0x000E, 0x000F, 0x0017, 0x0025, 0x009F, 0x0138, 0x024B, 0x0093, + 0x092A, 0x0005, 0x0000, 0x0008, 0x000D, 0x000F, 0x0006, 0x0004, + 0x000E, 0x0019, 0x0018, 0x000A, 0x009E, 0x0494, 0x1256, 0x0026, + 0x0016, 0x0124, 0x04E5, 0x0273, 0x04E4, 0x1257, 0x0048, 0x009D + ], [ + 0x0004, 0x002C, 0x0050, 0x001E, 0x0071, 0x00E1, 0x00E0, 0x001D, + 0x0006, 0x0007, 0x0006, 0x0007, 0x0005, 0x0006, 0x0015, 0x0000, + 0x0029, 0x0002, 0x0006, 0x0001, 0x0023, 0x001F, 0x0039, 0x0009, + 0x0002, 0x0010, 0x0007, 0x002D, 0x002F, 0x002E, 0x0022, 0x0051 + ], [ + 0x0008, 0x002F, 0x0051, 0x0050, 0x02ED, 0x05D9, 0x05D8, 0x00BA, + 0x005C, 0x0007, 0x0006, 0x0009, 0x0006, 0x0007, 0x0016, 0x0005, + 0x002B, 0x0006, 0x000A, 0x0001, 0x000F, 0x001D, 0x0177, 0x0004, + 0x0001, 0x0004, 0x0001, 0x002A, 0x000B, 0x0029, 0x0000, 0x001C + ], [ + 0x000A, 0x003C, 0x0074, 0x004E, 0x026D, 0x04D9, 0x04D8, 0x009A, + 0x004C, 0x0000, 0x0006, 0x0008, 0x0007, 0x0006, 0x0016, 0x0008, + 0x002E, 0x000A, 0x000B, 0x003D, 0x0024, 0x00EB, 0x0137, 0x001F, + 0x001C, 0x003B, 0x0012, 0x0025, 0x002F, 0x0013, 0x004F, 0x00EA + ], [ + 0x000A, 0x000A, 0x0003, 0x0016, 0x0009, 0x0021, 0x0020, 0x00B3, + 0x0058, 0x0007, 0x0006, 0x0007, 0x0006, 0x0004, 0x0013, 0x0002, + 0x0025, 0x0000, 0x0003, 0x002D, 0x005D, 0x00B2, 0x0011, 0x0008, + 0x0002, 0x0006, 0x0017, 0x002F, 0x0007, 0x0024, 0x005C, 0x0005 + ], [ + 0x000B, 0x0013, 0x001F, 0x0031, 0x0021, 0x0295, 0x0528, 0x00A4, + 0x003C, 0x0000, 0x0007, 0x0006, 0x0005, 0x001B, 0x0012, 0x0032, + 0x001D, 0x002B, 0x0030, 0x001C, 0x003D, 0x014B, 0x0529, 0x0008, + 0x001A, 0x0033, 0x0011, 0x002A, 0x0009, 0x0028, 0x0053, 0x0020 + ], [ + 0x000E, 0x0015, 0x0029, 0x003F, 0x004D, 0x02F1, 0x05E0, 0x0092, + 0x0048, 0x0000, 0x0006, 0x0006, 0x0005, 0x0004, 0x000F, 0x002E, + 0x001D, 0x0028, 0x0027, 0x005F, 0x00BD, 0x0179, 0x05E1, 0x0008, + 0x001E, 0x002D, 0x001C, 0x002C, 0x003E, 0x0025, 0x004C, 0x0093 + ], [ + 0x000C, 0x0017, 0x0035, 0x0013, 0x0021, 0x00AD, 0x06F1, 0x01BD, + 0x00D9, 0x0000, 0x0007, 0x0007, 0x0006, 0x0004, 0x0011, 0x002A, + 0x006E, 0x0025, 0x0024, 0x0057, 0x00D8, 0x0379, 0x06F0, 0x0005, + 0x0016, 0x0029, 0x006D, 0x0028, 0x0034, 0x0020, 0x00DF, 0x00AC + ], [ + 0x0000, 0x001A, 0x0006, 0x0019, 0x0030, 0x005A, 0x018A, 0x02DD, + 0x018B, 0x0001, 0x0007, 0x000A, 0x0009, 0x0002, 0x0010, 0x002E, + 0x006E, 0x002C, 0x000E, 0x005E, 0x00C4, 0x05B9, 0x05B8, 0x0011, + 0x0036, 0x005F, 0x001E, 0x0063, 0x006F, 0x001F, 0x00B6, 0x016F + ] +]; +const VP40_DC_BITS: [[u8; 32]; 16] = [ + [ + 5, 7, 9, 9, 10, 13, 14, 7, 14, 4, 4, 5, 4, 4, 4, 5, + 5, 4, 4, 3, 3, 4, 4, 6, 7, 8, 12, 11, 10, 10, 7, 8 + ], [ + 5, 7, 8, 7, 9, 11, 11, 7, 12, 4, 3, 4, 4, 4, 4, 5, + 5, 4, 4, 3, 4, 4, 6, 6, 6, 9, 11, 10, 10, 12, 7, 8 + ], [ + 5, 6, 8, 7, 9, 10, 12, 7, 13, 3, 3, 4, 4, 4, 4, 4, + 5, 4, 4, 4, 4, 5, 7, 6, 6, 9, 11, 10, 10, 13, 7, 8 + ], [ + 5, 6, 8, 7, 8, 11, 12, 6, 13, 3, 3, 4, 4, 4, 4, 4, + 5, 4, 4, 4, 4, 6, 9, 6, 6, 9, 11, 9, 11, 13, 6, 7 + ], [ + 4, 6, 7, 7, 8, 10, 11, 7, 12, 3, 3, 4, 4, 4, 4, 4, + 5, 4, 4, 4, 5, 7, 11, 5, 6, 9, 10, 9, 11, 12, 6, 8 + ], [ + 4, 6, 7, 7, 8, 10, 11, 7, 13, 3, 3, 4, 4, 4, 4, 4, + 5, 4, 4, 4, 5, 8, 12, 5, 6, 9, 10, 9, 10, 13, 6, 7 + ], [ + 4, 5, 7, 6, 7, 10, 11, 7, 12, 3, 3, 4, 4, 3, 4, 5, + 5, 4, 4, 5, 6, 10, 13, 5, 6, 9, 11, 9, 11, 13, 7, 7 + ], [ + 4, 5, 6, 6, 8, 9, 10, 8, 12, 3, 2, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 8, 11, 13, 6, 6, 9, 11, 10, 11, 13, 7, 8 + ], [ + 4, 6, 7, 7, 9, 10, 10, 7, 6, 3, 3, 4, 4, 4, 5, 5, + 6, 5, 5, 5, 6, 7, 8, 4, 4, 5, 6, 6, 6, 6, 6, 7 + ], [ + 4, 6, 7, 7, 10, 11, 11, 8, 7, 3, 3, 4, 4, 4, 5, 5, + 6, 5, 5, 5, 6, 7, 9, 4, 4, 5, 6, 6, 5, 6, 6, 7 + ], [ + 4, 6, 7, 7, 10, 11, 11, 8, 7, 2, 3, 4, 4, 4, 5, 5, + 6, 5, 5, 6, 6, 8, 9, 5, 5, 6, 6, 6, 6, 6, 7, 8 + ], [ + 4, 5, 6, 6, 8, 10, 10, 8, 7, 3, 3, 4, 4, 4, 5, 5, + 6, 5, 5, 6, 7, 8, 9, 4, 4, 5, 6, 6, 5, 6, 7, 7 + ], [ + 4, 5, 6, 6, 7, 10, 11, 8, 7, 2, 3, 4, 4, 5, 5, 6, + 6, 6, 6, 6, 7, 9, 11, 4, 5, 6, 6, 6, 5, 6, 7, 7 + ], [ + 4, 5, 6, 6, 7, 10, 11, 8, 7, 2, 3, 4, 4, 4, 5, 6, + 6, 6, 6, 7, 8, 9, 11, 4, 5, 6, 6, 6, 6, 6, 7, 8 + ], [ + 4, 5, 6, 5, 6, 8, 11, 9, 8, 2, 3, 4, 4, 4, 5, 6, + 7, 6, 6, 7, 8, 10, 11, 4, 5, 6, 7, 6, 6, 6, 8, 8 + ], [ + 3, 5, 5, 5, 6, 7, 9, 10, 9, 2, 3, 4, 4, 4, 5, 6, + 7, 6, 6, 7, 8, 11, 11, 5, 6, 7, 7, 7, 7, 7, 8, 9 + ] +]; +const VP40_AC_CAT0_CODES: [[u32; 32]; 16] = [ + [ + 0x0006, 0x001E, 0x01CC, 0x01CE, 0x0734, 0x1CD5, 0x1CD4, 0x0018, + 0x0E6B, 0x0000, 0x000F, 0x0006, 0x0007, 0x000D, 0x0008, 0x0002, + 0x0019, 0x0005, 0x000B, 0x000A, 0x001D, 0x0027, 0x01CF, 0x0004, + 0x0038, 0x000E, 0x004C, 0x001F, 0x004D, 0x039B, 0x0012, 0x0072 + ], [ + 0x0009, 0x004B, 0x0090, 0x0091, 0x0745, 0x1D11, 0x1D10, 0x0019, + 0x0E89, 0x0000, 0x000F, 0x0008, 0x0007, 0x000D, 0x000B, 0x0002, + 0x001C, 0x0003, 0x000A, 0x0005, 0x0018, 0x0010, 0x01D0, 0x0006, + 0x003B, 0x0011, 0x004A, 0x0049, 0x00E9, 0x03A3, 0x0013, 0x0075 + ], [ + 0x0019, 0x0074, 0x001D, 0x00EA, 0x0073, 0x01CA, 0x0396, 0x001C, + 0x00E4, 0x0002, 0x0001, 0x0007, 0x0008, 0x000D, 0x0009, 0x001F, + 0x0018, 0x0000, 0x0006, 0x001E, 0x003B, 0x00EB, 0x0397, 0x000A, + 0x0002, 0x002C, 0x005B, 0x005A, 0x000F, 0x0038, 0x0017, 0x0006 + ], [ + 0x001E, 0x006F, 0x00AE, 0x00AF, 0x0187, 0x061B, 0x0C35, 0x001A, + 0x030C, 0x0002, 0x0001, 0x0007, 0x0008, 0x000E, 0x0009, 0x001F, + 0x0014, 0x0000, 0x0001, 0x0019, 0x002A, 0x0060, 0x0C34, 0x000B, + 0x000D, 0x0036, 0x006E, 0x0056, 0x0031, 0x00C2, 0x0018, 0x0019 + ], [ + 0x0001, 0x002C, 0x0005, 0x0015, 0x0008, 0x0097, 0x012D, 0x0017, + 0x004A, 0x0003, 0x0002, 0x0009, 0x000A, 0x000E, 0x0008, 0x001F, + 0x0007, 0x001E, 0x001B, 0x0004, 0x005A, 0x0024, 0x012C, 0x000C, + 0x0006, 0x0000, 0x0003, 0x005B, 0x0014, 0x0013, 0x001A, 0x000B + ], [ + 0x0004, 0x0000, 0x0017, 0x0063, 0x018B, 0x0310, 0x0C44, 0x0019, + 0x0623, 0x0004, 0x0003, 0x000A, 0x000B, 0x000D, 0x0003, 0x001C, + 0x0003, 0x000A, 0x0004, 0x0003, 0x018A, 0x188B, 0x188A, 0x000F, + 0x000B, 0x0002, 0x000A, 0x0002, 0x0016, 0x0189, 0x001D, 0x0030 + ], [ + 0x000D, 0x0003, 0x0077, 0x000D, 0x0082, 0x020D, 0x0830, 0x0019, + 0x0419, 0x0003, 0x0002, 0x000A, 0x0009, 0x000B, 0x0002, 0x0011, + 0x0039, 0x0002, 0x0021, 0x0040, 0x1063, 0x20C5, 0x20C4, 0x000F, + 0x0018, 0x0007, 0x0038, 0x000C, 0x0076, 0x0107, 0x0000, 0x003A + ], [ + 0x000F, 0x001C, 0x0036, 0x0008, 0x0061, 0x0091, 0x0243, 0x0009, + 0x0120, 0x0005, 0x0003, 0x0008, 0x0005, 0x0001, 0x0013, 0x0031, + 0x0076, 0x0060, 0x0093, 0x0909, 0x0908, 0x090B, 0x090A, 0x0001, + 0x001A, 0x0019, 0x003A, 0x0025, 0x0077, 0x0092, 0x0000, 0x0037 + ], [ + 0x001F, 0x0079, 0x00F1, 0x00F0, 0x011B, 0x0469, 0x0468, 0x003B, + 0x0022, 0x0005, 0x0004, 0x0007, 0x0005, 0x0006, 0x001C, 0x0001, + 0x0035, 0x003D, 0x003A, 0x0010, 0x0047, 0x008C, 0x0235, 0x0001, + 0x0001, 0x0019, 0x0000, 0x0030, 0x0009, 0x0031, 0x001B, 0x0034 + ], [ + 0x0003, 0x001B, 0x00F3, 0x00FD, 0x03C9, 0x0F20, 0x1E42, 0x003D, + 0x00FC, 0x0006, 0x0004, 0x0002, 0x0000, 0x0001, 0x0017, 0x003E, + 0x001A, 0x0039, 0x002B, 0x0078, 0x01E5, 0x0791, 0x1E43, 0x0002, + 0x0007, 0x001D, 0x000C, 0x0038, 0x0014, 0x007F, 0x0016, 0x002A + ], [ + 0x0007, 0x0039, 0x0051, 0x0078, 0x03CB, 0x0F29, 0x1E51, 0x003D, + 0x00F3, 0x0006, 0x0004, 0x0002, 0x0000, 0x0001, 0x0017, 0x003E, + 0x007F, 0x002B, 0x007E, 0x0050, 0x01E4, 0x0795, 0x1E50, 0x0002, + 0x0006, 0x001D, 0x0006, 0x0038, 0x0007, 0x0029, 0x0016, 0x002A + ], [ + 0x0008, 0x003B, 0x001D, 0x0072, 0x01CC, 0x0734, 0x1CD5, 0x003A, + 0x001C, 0x0006, 0x0005, 0x0002, 0x0001, 0x0000, 0x0012, 0x003E, + 0x007F, 0x001E, 0x007E, 0x00E7, 0x039B, 0x0E6B, 0x1CD4, 0x0002, + 0x0006, 0x001E, 0x000E, 0x0038, 0x0006, 0x000F, 0x0013, 0x001F + ], [ + 0x000D, 0x003F, 0x0073, 0x000C, 0x00E4, 0x072B, 0x0E54, 0x003A, + 0x001A, 0x0005, 0x0004, 0x0002, 0x0001, 0x0000, 0x0007, 0x0038, + 0x0076, 0x0077, 0x001B, 0x01CB, 0x0394, 0x1CAB, 0x1CAA, 0x0002, + 0x0006, 0x001E, 0x000E, 0x003E, 0x0019, 0x001F, 0x0018, 0x001E + ], [ + 0x000E, 0x0007, 0x000C, 0x001C, 0x00BD, 0x02F3, 0x0BC9, 0x001F, + 0x00BF, 0x0006, 0x0004, 0x0002, 0x0001, 0x001E, 0x0001, 0x000D, + 0x003A, 0x003B, 0x00BE, 0x0178, 0x05E5, 0x1791, 0x1790, 0x0002, + 0x0006, 0x001F, 0x0016, 0x0000, 0x0015, 0x002E, 0x0014, 0x001E + ], [ + 0x0000, 0x001B, 0x0031, 0x003A, 0x0060, 0x006F, 0x01B9, 0x000E, + 0x001A, 0x0005, 0x0003, 0x0002, 0x001F, 0x001A, 0x0039, 0x000C, + 0x00C3, 0x00C2, 0x0036, 0x00DD, 0x0370, 0x06E3, 0x06E2, 0x0002, + 0x0008, 0x001E, 0x0019, 0x003B, 0x0012, 0x000F, 0x0013, 0x0038 + ], [ + 0x0002, 0x0000, 0x0003, 0x001C, 0x0032, 0x001C, 0x0199, 0x0004, + 0x00CD, 0x0004, 0x0003, 0x001B, 0x001A, 0x003D, 0x0067, 0x003B, + 0x0198, 0x0075, 0x00E9, 0x03A1, 0x03A0, 0x03A3, 0x03A2, 0x0005, + 0x0002, 0x001F, 0x001D, 0x003C, 0x0018, 0x000F, 0x0006, 0x0005 + ] +]; +const VP40_AC_CAT0_BITS: [[u8; 32]; 16] = [ + [ + 5, 7, 9, 9, 11, 13, 13, 5, 12, 3, 4, 4, 4, 4, 4, 4, + 5, 4, 4, 4, 5, 6, 9, 4, 6, 6, 7, 7, 7, 10, 5, 7 + ], [ + 5, 7, 8, 8, 11, 13, 13, 5, 12, 3, 4, 4, 4, 4, 4, 4, + 5, 4, 4, 4, 5, 6, 9, 4, 6, 6, 7, 7, 8, 10, 5, 7 + ], [ + 5, 7, 8, 8, 10, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5, + 5, 4, 4, 5, 6, 8, 13, 4, 5, 6, 7, 7, 7, 9, 5, 6 + ], [ + 5, 7, 8, 8, 10, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5, + 5, 4, 4, 5, 6, 8, 13, 4, 5, 6, 7, 7, 7, 9, 5, 6 + ], [ + 4, 6, 7, 7, 8, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5, + 5, 5, 5, 5, 7, 10, 13, 4, 5, 5, 6, 7, 7, 9, 5, 6 + ], [ + 4, 5, 7, 7, 9, 10, 12, 5, 11, 3, 3, 4, 4, 4, 4, 5, + 5, 5, 5, 6, 9, 13, 13, 4, 5, 5, 6, 6, 7, 9, 5, 6 + ], [ + 4, 5, 7, 6, 8, 10, 12, 5, 11, 3, 3, 4, 4, 4, 4, 5, + 6, 5, 6, 7, 13, 14, 14, 4, 5, 5, 6, 6, 7, 9, 4, 6 + ], [ + 4, 5, 6, 5, 7, 8, 10, 5, 9, 3, 3, 4, 4, 4, 5, 6, + 7, 7, 8, 12, 12, 12, 12, 3, 5, 5, 6, 6, 7, 8, 4, 6 + ], [ + 5, 7, 8, 8, 10, 12, 12, 6, 7, 3, 3, 4, 4, 4, 5, 5, + 6, 6, 6, 6, 8, 9, 11, 3, 4, 5, 5, 6, 5, 6, 5, 6 + ], [ + 4, 6, 8, 8, 10, 12, 13, 6, 8, 3, 3, 4, 4, 4, 5, 6, + 6, 6, 6, 7, 9, 11, 13, 3, 4, 5, 5, 6, 5, 7, 5, 6 + ], [ + 4, 6, 7, 7, 10, 12, 13, 6, 8, 3, 3, 4, 4, 4, 5, 6, + 7, 6, 7, 7, 9, 11, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6 + ], [ + 4, 6, 7, 7, 9, 11, 13, 6, 7, 3, 3, 4, 4, 4, 5, 6, + 7, 6, 7, 8, 10, 12, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6 + ], [ + 4, 6, 7, 6, 8, 11, 12, 6, 7, 3, 3, 4, 4, 4, 5, 6, + 7, 7, 7, 9, 10, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6 + ], [ + 4, 5, 6, 6, 8, 10, 12, 6, 8, 3, 3, 4, 4, 5, 5, 6, + 7, 7, 8, 9, 11, 13, 13, 3, 4, 5, 5, 5, 5, 6, 5, 6 + ], [ + 3, 5, 6, 6, 7, 9, 11, 6, 7, 3, 3, 4, 5, 5, 6, 6, + 8, 8, 8, 10, 12, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6 + ], [ + 3, 4, 5, 5, 6, 7, 9, 6, 8, 3, 3, 5, 5, 6, 7, 8, + 9, 9, 10, 12, 12, 12, 12, 3, 4, 5, 5, 6, 5, 6, 5, 6 + ] +]; +const VP40_AC_CAT1_CODES: [[u32; 32]; 16] = [ + [ + 0x0004, 0x00F5, 0x0182, 0x060F, 0x1839, 0x1838, 0x183B, 0x0013, + 0x00C0, 0x0003, 0x0002, 0x000B, 0x000A, 0x000E, 0x0008, 0x0001, + 0x0012, 0x001F, 0x0000, 0x0006, 0x007B, 0x0306, 0x183A, 0x000D, + 0x0007, 0x0031, 0x000A, 0x0061, 0x003C, 0x00F4, 0x0019, 0x000B + ], [ + 0x000A, 0x001A, 0x01D8, 0x03B3, 0x0ECA, 0x1D96, 0x3B2F, 0x0014, + 0x0036, 0x0004, 0x0003, 0x000C, 0x000B, 0x0000, 0x0004, 0x001C, + 0x0005, 0x0015, 0x0007, 0x0017, 0x0037, 0x0764, 0x3B2E, 0x000F, + 0x001A, 0x003A, 0x000C, 0x0077, 0x0004, 0x00ED, 0x001B, 0x0016 + ], [ + 0x001A, 0x002D, 0x0058, 0x01F4, 0x07D4, 0x1F55, 0x1F54, 0x0014, + 0x0059, 0x0004, 0x0003, 0x000B, 0x000C, 0x000E, 0x0004, 0x0015, + 0x0005, 0x0007, 0x0004, 0x007C, 0x03EB, 0x1F57, 0x1F56, 0x0000, + 0x001B, 0x003F, 0x000D, 0x000C, 0x000A, 0x00FB, 0x001E, 0x0017 + ], [ + 0x0000, 0x0075, 0x004A, 0x0097, 0x025B, 0x0969, 0x0968, 0x000B, + 0x00E8, 0x0005, 0x0004, 0x0007, 0x000C, 0x000D, 0x0001, 0x000A, + 0x0039, 0x003B, 0x0018, 0x00E9, 0x012C, 0x096B, 0x096A, 0x0001, + 0x001F, 0x0008, 0x0019, 0x0013, 0x000D, 0x0024, 0x001E, 0x0038 + ], [ + 0x0004, 0x0014, 0x006E, 0x0057, 0x0159, 0x0562, 0x0AC7, 0x000B, + 0x006F, 0x0006, 0x0005, 0x0008, 0x0009, 0x0007, 0x001E, 0x0002, + 0x0007, 0x0006, 0x002A, 0x00AD, 0x0AC6, 0x0561, 0x0560, 0x0001, + 0x001F, 0x000C, 0x0039, 0x001A, 0x0000, 0x0036, 0x001D, 0x0038 + ], [ + 0x0007, 0x001B, 0x000E, 0x000D, 0x03E1, 0x1F06, 0x3E0F, 0x0002, + 0x00F9, 0x0005, 0x0006, 0x0008, 0x0009, 0x0004, 0x000C, 0x001A, + 0x000F, 0x000C, 0x01F1, 0x07C0, 0x3E0E, 0x1F05, 0x1F04, 0x0001, + 0x0000, 0x001C, 0x003F, 0x003D, 0x0005, 0x007D, 0x001D, 0x003C + ], [ + 0x000F, 0x000A, 0x0071, 0x0006, 0x01C2, 0x0702, 0x1C0E, 0x0002, + 0x000E, 0x0005, 0x0004, 0x0006, 0x0007, 0x001D, 0x0017, 0x000F, + 0x01C3, 0x01C1, 0x0380, 0x381F, 0x381E, 0x1C0D, 0x1C0C, 0x0001, + 0x0004, 0x0018, 0x0001, 0x0000, 0x000D, 0x0016, 0x0019, 0x0039 + ], [ + 0x0002, 0x001E, 0x003B, 0x000D, 0x0061, 0x01FA, 0x1FB5, 0x0031, + 0x00FC, 0x0004, 0x0005, 0x0001, 0x0007, 0x003A, 0x0060, 0x03F7, + 0x07EC, 0x1FB7, 0x3F6C, 0x7EDB, 0x7EDA, 0x3F69, 0x3F68, 0x0001, + 0x0000, 0x0019, 0x003E, 0x0039, 0x000D, 0x0038, 0x000C, 0x007F + ], [ + 0x001E, 0x0070, 0x0127, 0x0126, 0x0492, 0x124D, 0x124C, 0x0001, + 0x007F, 0x0006, 0x0005, 0x0005, 0x0004, 0x0001, 0x0007, 0x0025, + 0x0071, 0x007E, 0x0048, 0x0125, 0x0248, 0x124F, 0x124E, 0x0003, + 0x0008, 0x001D, 0x0006, 0x003E, 0x0002, 0x0000, 0x0013, 0x0039 + ], [ + 0x0001, 0x0001, 0x00E7, 0x0091, 0x0240, 0x120D, 0x120C, 0x003C, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0004, 0x001F, 0x0004, 0x0025, + 0x0072, 0x0049, 0x00E6, 0x0121, 0x0482, 0x120F, 0x120E, 0x0003, + 0x0008, 0x001D, 0x0005, 0x003D, 0x0003, 0x0001, 0x0013, 0x0038 + ], [ + 0x0004, 0x000F, 0x00F4, 0x005B, 0x02D3, 0x0B4A, 0x1697, 0x003C, + 0x000E, 0x0006, 0x0005, 0x0002, 0x0001, 0x001D, 0x0000, 0x007B, + 0x002C, 0x00F5, 0x00B5, 0x0168, 0x1696, 0x0B49, 0x0B48, 0x0003, + 0x0009, 0x001F, 0x000A, 0x0001, 0x0008, 0x0006, 0x001C, 0x0017 + ], [ + 0x0008, 0x0039, 0x001A, 0x0003, 0x00DB, 0x06D6, 0x0DAF, 0x003C, + 0x000C, 0x0006, 0x0005, 0x0002, 0x0001, 0x001D, 0x003D, 0x0000, + 0x0002, 0x0037, 0x006C, 0x01B4, 0x0DAE, 0x06D5, 0x06D4, 0x0002, + 0x0007, 0x001F, 0x0007, 0x0001, 0x0009, 0x000D, 0x000C, 0x0038 + ], [ + 0x000F, 0x0004, 0x002F, 0x002E, 0x0054, 0x0555, 0x0554, 0x0016, + 0x000E, 0x0006, 0x0005, 0x0001, 0x0000, 0x0009, 0x000B, 0x0014, + 0x0057, 0x0056, 0x00AB, 0x0557, 0x0556, 0x02A9, 0x02A8, 0x0003, + 0x0008, 0x0013, 0x000A, 0x0008, 0x000E, 0x0012, 0x0006, 0x000F + ], [ + 0x0001, 0x000E, 0x0006, 0x0004, 0x00DA, 0x0DBE, 0x1B7E, 0x0007, + 0x001A, 0x0005, 0x0004, 0x001C, 0x001B, 0x003A, 0x0037, 0x006C, + 0x01B6, 0x036E, 0x0DBD, 0x36FF, 0x36FE, 0x1B79, 0x1B78, 0x0002, + 0x000C, 0x0000, 0x000F, 0x000C, 0x000F, 0x001A, 0x003B, 0x0005 + ], [ + 0x0005, 0x001E, 0x003A, 0x003E, 0x00FC, 0x0FD7, 0x3F55, 0x0077, + 0x0030, 0x0003, 0x0004, 0x001A, 0x0019, 0x007F, 0x01FB, 0x03F4, + 0x0FD6, 0x1FA9, 0x3F54, 0x3F57, 0x3F56, 0x3F51, 0x3F50, 0x0001, + 0x0004, 0x001C, 0x000B, 0x000A, 0x0000, 0x001B, 0x0031, 0x0076 + ], [ + 0x0005, 0x000C, 0x001B, 0x0008, 0x0038, 0x0015, 0x00A3, 0x00E6, + 0x0004, 0x0001, 0x0002, 0x0012, 0x0003, 0x000B, 0x0029, 0x00A0, + 0x0142, 0x0287, 0x0286, 0x0289, 0x0288, 0x028B, 0x028A, 0x000F, + 0x001D, 0x0013, 0x0001, 0x0000, 0x0003, 0x001A, 0x0072, 0x00E7 + ] +]; +const VP40_AC_CAT1_BITS: [[u8; 32]; 16] = [ + [ + 5, 8, 9, 11, 13, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 4, + 5, 5, 4, 5, 7, 10, 13, 4, 5, 6, 6, 7, 6, 8, 5, 6 + ], [ + 5, 7, 9, 10, 12, 13, 14, 5, 8, 3, 3, 4, 4, 3, 4, 5, + 5, 5, 5, 6, 8, 11, 14, 4, 5, 6, 6, 7, 5, 8, 5, 6 + ], [ + 5, 7, 8, 9, 11, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 5, + 5, 5, 5, 7, 10, 13, 13, 3, 5, 6, 6, 6, 5, 8, 5, 6 + ], [ + 4, 7, 8, 9, 11, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 5, + 6, 6, 6, 8, 10, 13, 13, 3, 5, 5, 6, 6, 5, 7, 5, 6 + ], [ + 4, 6, 8, 8, 10, 12, 13, 5, 8, 3, 3, 4, 4, 4, 5, 5, + 6, 6, 7, 9, 13, 12, 12, 3, 5, 5, 6, 6, 4, 7, 5, 6 + ], [ + 4, 6, 7, 7, 10, 13, 14, 5, 8, 3, 3, 4, 4, 4, 5, 6, + 7, 7, 9, 11, 14, 13, 13, 3, 4, 5, 6, 6, 4, 7, 5, 6 + ], [ + 4, 5, 7, 6, 9, 11, 13, 5, 7, 3, 3, 4, 4, 5, 6, 7, + 9, 9, 10, 14, 14, 13, 13, 3, 4, 5, 5, 5, 4, 6, 5, 6 + ], [ + 3, 5, 6, 5, 7, 9, 13, 6, 8, 3, 3, 4, 4, 6, 7, 10, + 11, 13, 14, 15, 15, 14, 14, 3, 4, 5, 6, 6, 4, 6, 5, 7 + ], [ + 5, 7, 9, 9, 11, 13, 13, 5, 7, 3, 3, 4, 4, 4, 5, 6, + 7, 7, 7, 9, 10, 13, 13, 3, 4, 5, 5, 6, 4, 5, 5, 6 + ], [ + 4, 6, 8, 8, 10, 13, 13, 6, 6, 3, 3, 4, 4, 5, 5, 6, + 7, 7, 8, 9, 11, 13, 13, 3, 4, 5, 5, 6, 4, 5, 5, 6 + ], [ + 4, 6, 8, 8, 11, 13, 14, 6, 6, 3, 3, 4, 4, 5, 5, 7, + 7, 8, 9, 10, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6 + ], [ + 4, 6, 7, 7, 10, 13, 14, 6, 6, 3, 3, 4, 4, 5, 6, 6, + 7, 8, 9, 11, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6 + ], [ + 4, 5, 7, 7, 9, 13, 13, 6, 6, 3, 3, 4, 4, 5, 6, 7, + 9, 9, 10, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6 + ], [ + 3, 5, 6, 6, 9, 13, 14, 6, 6, 3, 3, 5, 5, 6, 7, 8, + 10, 11, 13, 15, 15, 14, 14, 3, 4, 4, 5, 5, 4, 5, 6, 6 + ], [ + 3, 5, 6, 6, 8, 12, 14, 7, 6, 3, 3, 5, 5, 7, 9, 10, + 12, 13, 14, 14, 14, 14, 14, 3, 4, 5, 5, 5, 3, 5, 6, 7 + ], [ + 3, 4, 5, 4, 6, 8, 11, 8, 6, 3, 3, 5, 5, 7, 9, 11, + 12, 13, 13, 13, 13, 13, 13, 4, 5, 5, 5, 5, 3, 5, 7, 8 + ] +]; +const VP40_AC_CAT2_CODES: [[u32; 32]; 16] = [ + [ + 0x0009, 0x0015, 0x0028, 0x0052, 0x029A, 0x0537, 0x0536, 0x000A, + 0x0054, 0x0004, 0x0003, 0x000C, 0x000B, 0x000D, 0x0003, 0x0014, + 0x003A, 0x0004, 0x0038, 0x0055, 0x00A7, 0x0299, 0x0298, 0x0000, + 0x001E, 0x0008, 0x002B, 0x000B, 0x000B, 0x003B, 0x001F, 0x0039 + ], [ + 0x001D, 0x002F, 0x0002, 0x0007, 0x0019, 0x0035, 0x0034, 0x0009, + 0x002E, 0x0006, 0x0005, 0x0009, 0x0008, 0x0007, 0x001F, 0x0008, + 0x0018, 0x0019, 0x0001, 0x0000, 0x0018, 0x0037, 0x0036, 0x0001, + 0x0001, 0x000A, 0x0039, 0x0016, 0x000D, 0x0001, 0x001E, 0x0038 + ], [ + 0x0001, 0x0071, 0x00E0, 0x01C3, 0x0708, 0x1C26, 0x384F, 0x0001, + 0x0031, 0x0006, 0x0005, 0x0009, 0x0008, 0x0005, 0x000F, 0x0039, + 0x0077, 0x0076, 0x0030, 0x0385, 0x384E, 0x1C25, 0x1C24, 0x0001, + 0x0004, 0x000D, 0x0000, 0x0019, 0x001F, 0x000E, 0x001E, 0x003A + ], [ + 0x0006, 0x000C, 0x00D6, 0x007B, 0x01E8, 0x07A4, 0x0F4B, 0x0036, + 0x006A, 0x0007, 0x0005, 0x0008, 0x0009, 0x0001, 0x0007, 0x000D, + 0x003C, 0x00D7, 0x00F5, 0x07A7, 0x0F4A, 0x0F4D, 0x0F4C, 0x0002, + 0x0002, 0x000E, 0x0037, 0x0034, 0x0000, 0x0019, 0x0018, 0x001F + ], [ + 0x000A, 0x0027, 0x00BF, 0x00BE, 0x0224, 0x225D, 0x225C, 0x0026, + 0x005E, 0x0007, 0x0006, 0x0006, 0x0007, 0x0016, 0x002E, 0x0045, + 0x0088, 0x0113, 0x044A, 0x225F, 0x225E, 0x112D, 0x112C, 0x0002, + 0x0002, 0x0012, 0x0003, 0x0002, 0x0003, 0x0000, 0x0010, 0x0023 + ], [ + 0x000F, 0x0006, 0x0075, 0x0074, 0x000A, 0x00BF, 0x00B9, 0x0022, + 0x0003, 0x0005, 0x0006, 0x0001, 0x0002, 0x0007, 0x0000, 0x0004, + 0x0016, 0x005E, 0x00B8, 0x00BB, 0x00BA, 0x017D, 0x017C, 0x0002, + 0x0006, 0x001C, 0x0010, 0x003B, 0x0009, 0x0007, 0x0001, 0x0023 + ], [ + 0x0001, 0x001C, 0x0036, 0x003B, 0x00EA, 0x075B, 0x1D65, 0x0019, + 0x0074, 0x0004, 0x0005, 0x0000, 0x0001, 0x0037, 0x01D7, 0x075A, + 0x1D64, 0x1D67, 0x1D66, 0x1D61, 0x1D60, 0x1D63, 0x1D62, 0x0002, + 0x001F, 0x001A, 0x000D, 0x003D, 0x000C, 0x0007, 0x003C, 0x0018 + ], [ + 0x0002, 0x0001, 0x0014, 0x0000, 0x002F, 0x00BB, 0x02E4, 0x007D, + 0x00BA, 0x0003, 0x0004, 0x0016, 0x001A, 0x00B8, 0x172E, 0x2E5F, + 0x2E5E, 0x1729, 0x1728, 0x172B, 0x172A, 0x172D, 0x172C, 0x0001, + 0x001E, 0x0015, 0x001B, 0x003F, 0x000C, 0x000E, 0x007C, 0x0173 + ], [ + 0x0003, 0x007B, 0x0058, 0x01EA, 0x1EB1, 0x1EB0, 0x1EB3, 0x0013, + 0x0012, 0x0005, 0x0006, 0x0002, 0x0001, 0x0013, 0x003C, 0x002D, + 0x00F4, 0x0059, 0x03D7, 0x0F5B, 0x1EB2, 0x1EB5, 0x1EB4, 0x0003, + 0x000E, 0x001F, 0x0012, 0x0008, 0x0008, 0x0000, 0x000A, 0x0017 + ], [ + 0x0008, 0x003C, 0x00F5, 0x00F4, 0x1EF7, 0x3DE9, 0x3DE8, 0x001C, + 0x000D, 0x0005, 0x0006, 0x0001, 0x0000, 0x0007, 0x000C, 0x00F6, + 0x01EE, 0x03DF, 0x07BC, 0x3DEB, 0x3DEA, 0x3DED, 0x3DEC, 0x0002, + 0x0009, 0x001F, 0x000F, 0x0005, 0x000E, 0x0006, 0x0004, 0x001D + ], [ + 0x0009, 0x0039, 0x0019, 0x0018, 0x0706, 0x383D, 0x383C, 0x000D, + 0x000F, 0x0005, 0x0006, 0x0000, 0x001D, 0x0003, 0x0071, 0x00E1, + 0x01C0, 0x0382, 0x1C1D, 0x383F, 0x383E, 0x3839, 0x3838, 0x0002, + 0x0008, 0x0002, 0x000D, 0x000C, 0x000F, 0x0007, 0x0002, 0x000E + ], [ + 0x0000, 0x0006, 0x0035, 0x0034, 0x0777, 0x1DD4, 0x3BAB, 0x000E, + 0x000F, 0x0005, 0x0004, 0x001C, 0x0019, 0x003A, 0x00EF, 0x01DC, + 0x0776, 0x0774, 0x3BAA, 0x3BAD, 0x3BAC, 0x3BAF, 0x3BAE, 0x0002, + 0x0007, 0x0002, 0x0018, 0x000C, 0x000F, 0x000D, 0x001B, 0x0076 + ], [ + 0x0002, 0x0011, 0x0006, 0x004F, 0x0130, 0x1319, 0x1318, 0x004E, + 0x0007, 0x0006, 0x0005, 0x0010, 0x000D, 0x0005, 0x0099, 0x0262, + 0x098E, 0x131B, 0x131A, 0x263D, 0x263C, 0x263F, 0x263E, 0x0001, + 0x0007, 0x0000, 0x0012, 0x000C, 0x000E, 0x000F, 0x0004, 0x004D + ], [ + 0x0003, 0x0000, 0x0002, 0x0037, 0x01B7, 0x0DB5, 0x36DD, 0x006C, + 0x0016, 0x0005, 0x0004, 0x0003, 0x000A, 0x002E, 0x036C, 0x0DB4, + 0x36DC, 0x36DF, 0x36DE, 0x36D9, 0x36D8, 0x36DB, 0x36DA, 0x000E, + 0x0004, 0x001A, 0x0019, 0x0018, 0x000F, 0x0001, 0x002F, 0x00DA + ], [ + 0x0006, 0x0006, 0x000F, 0x0000, 0x0075, 0x03B8, 0x1DCA, 0x0074, + 0x0076, 0x0004, 0x0005, 0x0003, 0x0002, 0x01DE, 0x0EE6, 0x3B97, + 0x3B96, 0x3B9D, 0x3B9C, 0x3B9F, 0x3B9E, 0x1DC9, 0x1DC8, 0x0005, + 0x001C, 0x0009, 0x000E, 0x0008, 0x000F, 0x0001, 0x01DF, 0x01DD + ], [ + 0x0004, 0x000B, 0x001D, 0x000C, 0x0014, 0x00E0, 0x3875, 0x0386, + 0x01C2, 0x0000, 0x0001, 0x0071, 0x0072, 0x1C3F, 0x3874, 0x3877, + 0x3876, 0x3871, 0x3870, 0x3873, 0x3872, 0x3879, 0x3878, 0x003C, + 0x0073, 0x002A, 0x003D, 0x002B, 0x001F, 0x000D, 0x1C3E, 0x1C3D + ] +]; +const VP40_AC_CAT2_BITS: [[u8; 32]; 16] = [ + [ + 5, 7, 8, 9, 12, 13, 13, 5, 7, 3, 3, 4, 4, 4, 4, 5, + 6, 5, 6, 7, 10, 12, 12, 3, 5, 5, 6, 6, 5, 6, 5, 6 + ], [ + 5, 7, 8, 9, 11, 12, 12, 5, 7, 3, 3, 4, 4, 4, 5, 5, + 6, 6, 6, 7, 11, 12, 12, 3, 4, 5, 6, 6, 5, 5, 5, 6 + ], [ + 4, 7, 8, 9, 11, 13, 14, 5, 7, 3, 3, 4, 4, 4, 5, 6, + 7, 7, 7, 10, 14, 13, 13, 3, 4, 5, 5, 6, 5, 5, 5, 6 + ], [ + 4, 6, 8, 8, 10, 12, 13, 6, 7, 3, 3, 4, 4, 4, 5, 6, + 7, 8, 9, 12, 13, 13, 13, 3, 4, 5, 6, 6, 4, 5, 5, 6 + ], [ + 4, 6, 8, 8, 10, 14, 14, 6, 7, 3, 3, 4, 4, 5, 6, 7, + 8, 9, 11, 14, 14, 13, 13, 3, 4, 5, 5, 5, 4, 4, 5, 6 + ], [ + 4, 5, 7, 7, 9, 13, 13, 6, 7, 3, 3, 4, 4, 5, 6, 8, + 10, 12, 13, 13, 13, 14, 14, 3, 4, 5, 5, 6, 4, 4, 5, 6 + ], [ + 3, 5, 6, 6, 8, 11, 13, 6, 7, 3, 3, 4, 4, 6, 9, 11, + 13, 13, 13, 13, 13, 13, 13, 3, 5, 5, 5, 6, 4, 4, 6, 6 + ], [ + 3, 4, 5, 4, 6, 8, 10, 7, 8, 3, 3, 5, 5, 8, 13, 14, + 14, 13, 13, 13, 13, 13, 13, 3, 5, 5, 5, 6, 4, 4, 7, 9 + ], [ + 4, 7, 8, 9, 13, 13, 13, 6, 6, 3, 3, 4, 4, 5, 6, 7, + 8, 8, 10, 12, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 5, 6 + ], [ + 4, 6, 8, 8, 13, 14, 14, 6, 6, 3, 3, 4, 4, 5, 6, 8, + 9, 10, 11, 14, 14, 14, 14, 3, 4, 5, 5, 5, 4, 4, 5, 6 + ], [ + 4, 6, 7, 7, 11, 14, 14, 6, 6, 3, 3, 4, 5, 5, 7, 8, + 9, 10, 13, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 5, 6 + ], [ + 3, 5, 7, 7, 11, 13, 14, 6, 6, 3, 3, 5, 5, 6, 8, 9, + 11, 11, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7 + ], [ + 3, 5, 6, 7, 9, 13, 13, 7, 6, 3, 3, 5, 5, 6, 8, 10, + 12, 13, 13, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7 + ], [ + 3, 4, 5, 6, 9, 12, 14, 7, 6, 3, 3, 5, 5, 7, 10, 12, + 14, 14, 14, 14, 14, 14, 14, 4, 4, 5, 5, 5, 4, 3, 7, 8 + ], [ + 3, 4, 5, 4, 7, 10, 13, 7, 7, 3, 3, 5, 5, 9, 12, 14, + 14, 14, 14, 14, 14, 13, 13, 4, 5, 5, 5, 5, 4, 3, 9, 9 + ], [ + 3, 4, 5, 4, 5, 8, 14, 10, 9, 2, 2, 7, 7, 13, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 6, 7, 6, 6, 6, 5, 4, 13, 13 + ] +]; +const VP40_AC_CAT3_CODES: [[u32; 32]; 16] = [ + [ + 0x0007, 0x000F, 0x00BB, 0x00BA, 0x05CF, 0x173A, 0x2E77, 0x0029, + 0x0172, 0x0007, 0x0006, 0x0009, 0x0008, 0x0001, 0x0005, 0x000D, + 0x001D, 0x001C, 0x00B8, 0x02E6, 0x2E76, 0x1739, 0x1738, 0x0002, + 0x0006, 0x0016, 0x0004, 0x0028, 0x0015, 0x000C, 0x0000, 0x002F + ], [ + 0x000B, 0x0002, 0x0054, 0x002F, 0x02AC, 0x156B, 0x1568, 0x0016, + 0x0154, 0x0007, 0x0006, 0x0004, 0x0003, 0x0013, 0x0028, 0x002E, + 0x0157, 0x0155, 0x055B, 0x2AD3, 0x2AD2, 0x2AD5, 0x2AD4, 0x0003, + 0x0008, 0x0000, 0x000A, 0x0003, 0x0002, 0x002B, 0x0012, 0x0029 + ], [ + 0x000F, 0x0007, 0x0001, 0x0000, 0x01C4, 0x0703, 0x0E02, 0x0011, + 0x00E1, 0x0005, 0x0006, 0x0002, 0x0001, 0x0009, 0x0010, 0x00E3, + 0x01C5, 0x01C1, 0x0702, 0x1C07, 0x1C06, 0x0E01, 0x0E00, 0x0004, + 0x0007, 0x001D, 0x000D, 0x0001, 0x0005, 0x0006, 0x000C, 0x0039 + ], [ + 0x0001, 0x001C, 0x0011, 0x0013, 0x0042, 0x0207, 0x0815, 0x0075, + 0x0041, 0x0005, 0x0006, 0x0000, 0x001F, 0x003B, 0x0074, 0x0043, + 0x0080, 0x0206, 0x0814, 0x0817, 0x0816, 0x0409, 0x0408, 0x0003, + 0x0009, 0x001E, 0x0011, 0x0003, 0x0005, 0x0010, 0x0002, 0x0012 + ], [ + 0x0001, 0x001F, 0x0027, 0x0001, 0x004B, 0x0123, 0x0915, 0x0000, + 0x0049, 0x0005, 0x0006, 0x001D, 0x001C, 0x0013, 0x004A, 0x0090, + 0x0914, 0x0917, 0x0916, 0x0911, 0x0910, 0x0913, 0x0912, 0x0003, + 0x0005, 0x0001, 0x0012, 0x0008, 0x0008, 0x001E, 0x0026, 0x0001 + ], [ + 0x0003, 0x0001, 0x003F, 0x000B, 0x004E, 0x0132, 0x099A, 0x004F, + 0x0098, 0x0006, 0x0005, 0x001D, 0x001C, 0x007C, 0x0267, 0x1331, + 0x1330, 0x1333, 0x1332, 0x266D, 0x266C, 0x266F, 0x266E, 0x0001, + 0x0004, 0x001E, 0x0012, 0x000A, 0x0008, 0x0000, 0x007D, 0x004D + ], [ + 0x0002, 0x0007, 0x0015, 0x0003, 0x0004, 0x00A7, 0x0536, 0x0028, + 0x029A, 0x0006, 0x0004, 0x001C, 0x0017, 0x00A4, 0x29BE, 0x537F, + 0x537E, 0x29B9, 0x29B8, 0x29BB, 0x29BA, 0x29BD, 0x29BC, 0x000F, + 0x0000, 0x0005, 0x0016, 0x001D, 0x0006, 0x0001, 0x00A5, 0x014C + ], [ + 0x0004, 0x0007, 0x001A, 0x000C, 0x0006, 0x0029, 0x01BD, 0x1BE3, + 0x1BE0, 0x0000, 0x0007, 0x006E, 0x01BC, 0x37C3, 0x37C2, 0x37CD, + 0x37CC, 0x37CF, 0x37CE, 0x37C9, 0x37C8, 0x37CB, 0x37CA, 0x0015, + 0x01BF, 0x037D, 0x0036, 0x0002, 0x000B, 0x0028, 0x37C5, 0x37C4 + ], [ + 0x0001, 0x0009, 0x0003, 0x0002, 0x011F, 0x08E9, 0x08E8, 0x002D, + 0x0022, 0x0006, 0x0007, 0x0010, 0x0011, 0x0017, 0x002C, 0x0046, + 0x011E, 0x011C, 0x0477, 0x08EB, 0x08EA, 0x08ED, 0x08EC, 0x0003, + 0x000B, 0x0001, 0x0014, 0x000A, 0x0009, 0x0015, 0x0000, 0x0010 + ], [ + 0x0001, 0x001D, 0x0022, 0x0013, 0x011E, 0x08FC, 0x23F5, 0x0023, + 0x0022, 0x0005, 0x0006, 0x0010, 0x000B, 0x0010, 0x008E, 0x023E, + 0x08FF, 0x11FD, 0x23F4, 0x23F7, 0x23F6, 0x23F9, 0x23F8, 0x0003, + 0x0009, 0x0000, 0x001C, 0x000A, 0x000F, 0x0001, 0x0012, 0x0046 + ], [ + 0x0003, 0x001F, 0x003C, 0x003D, 0x0086, 0x0877, 0x10E8, 0x0041, + 0x0040, 0x0005, 0x0006, 0x0007, 0x0006, 0x0004, 0x010F, 0x021C, + 0x0875, 0x21D3, 0x21D2, 0x21D9, 0x21D8, 0x21DB, 0x21DA, 0x0002, + 0x0009, 0x0000, 0x0011, 0x0003, 0x000E, 0x0002, 0x0005, 0x0042 + ], [ + 0x0004, 0x0001, 0x003D, 0x0009, 0x00F3, 0x0793, 0x1E45, 0x0000, + 0x0002, 0x0005, 0x0006, 0x0008, 0x0001, 0x0003, 0x01E5, 0x0792, + 0x1E44, 0x1E47, 0x1E46, 0x1E41, 0x1E40, 0x1E43, 0x1E42, 0x0001, + 0x0006, 0x001F, 0x000F, 0x000E, 0x000E, 0x0005, 0x0078, 0x0001 + ], [ + 0x0004, 0x0005, 0x000E, 0x0017, 0x003E, 0x00F0, 0x0F1E, 0x007A, + 0x007F, 0x0006, 0x0007, 0x0005, 0x0004, 0x007B, 0x01E2, 0x1E3F, + 0x1E3E, 0x0F19, 0x0F18, 0x0F1B, 0x0F1A, 0x0F1D, 0x0F1C, 0x0000, + 0x0003, 0x0016, 0x0009, 0x0008, 0x000A, 0x0006, 0x007E, 0x0079 + ], [ + 0x0005, 0x000C, 0x001A, 0x0004, 0x001A, 0x00DE, 0x0DF4, 0x00DD, + 0x006D, 0x0000, 0x0007, 0x0025, 0x0024, 0x00DC, 0x0DF7, 0x1BEB, + 0x1BEA, 0x0DF1, 0x0DF0, 0x0DF3, 0x0DF2, 0x1BED, 0x1BEC, 0x0008, + 0x0013, 0x000C, 0x0037, 0x0036, 0x0005, 0x0007, 0x006C, 0x01BF + ], [ + 0x0005, 0x000D, 0x001F, 0x000C, 0x003B, 0x0040, 0x041A, 0x0104, + 0x0107, 0x0001, 0x0000, 0x0024, 0x0021, 0x020B, 0x106E, 0x20DF, + 0x20DE, 0x1055, 0x1054, 0x1057, 0x1056, 0x106D, 0x106C, 0x0011, + 0x003A, 0x0025, 0x0038, 0x0039, 0x0013, 0x001E, 0x020C, 0x0414 + ], [ + 0x0000, 0x0007, 0x000D, 0x0005, 0x0009, 0x0022, 0x0CD1, 0x0CD0, + 0x0CD3, 0x0003, 0x0002, 0x008D, 0x00CC, 0x066B, 0x0CD2, 0x19B5, + 0x19B4, 0x19B7, 0x19B6, 0x19B1, 0x19B0, 0x19B3, 0x19B2, 0x0047, + 0x008C, 0x0337, 0x0067, 0x0018, 0x0010, 0x0032, 0x0CD5, 0x0CD4 + ] +]; +const VP40_AC_CAT3_BITS: [[u8; 32]; 16] = [ + [ + 4, 6, 8, 8, 11, 13, 14, 6, 9, 3, 3, 4, 4, 4, 5, 6, + 7, 7, 8, 10, 14, 13, 13, 3, 4, 5, 5, 6, 5, 6, 4, 6 + ], [ + 4, 5, 7, 7, 10, 13, 13, 6, 9, 3, 3, 4, 4, 5, 6, 7, + 9, 9, 11, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 6, 5, 6 + ], [ + 4, 5, 6, 6, 9, 11, 12, 6, 8, 3, 3, 4, 4, 5, 6, 8, + 9, 9, 11, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6 + ], [ + 3, 5, 6, 6, 8, 11, 13, 7, 8, 3, 3, 4, 5, 6, 7, 8, + 9, 11, 13, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6 + ], [ + 3, 5, 6, 5, 8, 10, 13, 6, 8, 3, 3, 5, 5, 6, 8, 9, + 13, 13, 13, 13, 13, 13, 13, 3, 4, 4, 5, 5, 4, 5, 6, 6 + ], [ + 3, 4, 6, 5, 7, 9, 12, 7, 8, 3, 3, 5, 5, 7, 10, 13, + 13, 13, 13, 14, 14, 14, 14, 3, 4, 5, 5, 5, 4, 4, 7, 7 + ], [ + 3, 4, 5, 4, 5, 8, 11, 6, 10, 3, 3, 5, 5, 8, 14, 15, + 15, 14, 14, 14, 14, 14, 14, 4, 4, 5, 5, 5, 4, 4, 8, 9 + ], [ + 3, 4, 5, 4, 4, 6, 9, 13, 13, 2, 3, 7, 9, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 5, 9, 10, 6, 3, 4, 6, 14, 14 + ], [ + 3, 5, 6, 6, 10, 13, 13, 7, 7, 3, 3, 5, 5, 6, 7, 8, + 10, 10, 12, 13, 13, 13, 13, 3, 4, 4, 5, 5, 4, 5, 5, 6 + ], [ + 3, 5, 6, 6, 9, 12, 14, 7, 7, 3, 3, 5, 5, 6, 8, 10, + 12, 13, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7 + ], [ + 3, 5, 6, 6, 8, 12, 13, 7, 7, 3, 3, 5, 5, 6, 9, 10, + 12, 14, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7 + ], [ + 3, 4, 6, 5, 8, 11, 13, 7, 7, 3, 3, 5, 5, 7, 9, 11, + 13, 13, 13, 13, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 7, 7 + ], [ + 3, 4, 5, 5, 7, 9, 13, 8, 8, 3, 3, 5, 5, 8, 10, 14, + 14, 13, 13, 13, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 8, 8 + ], [ + 3, 4, 5, 4, 6, 9, 13, 9, 8, 2, 3, 6, 6, 9, 13, 14, + 14, 13, 13, 13, 13, 14, 14, 4, 5, 5, 6, 6, 4, 4, 8, 10 + ], [ + 3, 4, 5, 4, 6, 7, 11, 9, 9, 2, 2, 6, 6, 10, 13, 14, + 14, 13, 13, 13, 13, 13, 13, 5, 6, 6, 6, 6, 5, 5, 10, 11 + ], [ + 2, 4, 5, 4, 5, 7, 13, 13, 13, 2, 2, 9, 9, 12, 13, 14, + 14, 14, 14, 14, 14, 14, 14, 8, 9, 11, 8, 6, 6, 7, 13, 13 + ] +]; + +const VP40_QMAT: &[i16; 64] = &[ + 16, 17, 18, 20, 22, 24, 26, 28, + 17, 18, 20, 22, 24, 26, 28, 32, + 18, 20, 22, 24, 26, 28, 32, 36, + 20, 22, 24, 26, 28, 32, 36, 40, + 22, 24, 26, 28, 32, 36, 40, 44, + 24, 26, 28, 32, 36, 40, 44, 48, + 26, 28, 32, 36, 40, 44, 48, 52, + 28, 32, 36, 40, 44, 48, 52, 56 +]; +const VP40_DC_Y_SCALES: [i16; 64] = [ + 180, 180, 180, 180, 180, 180, 175, 170, + 165, 160, 157, 155, 152, 150, 147, 145, + 142, 140, 137, 135, 132, 130, 127, 125, + 122, 120, 117, 115, 112, 110, 107, 105, + 102, 100, 97, 95, 92, 90, 87, 85, + 82, 80, 77, 75, 72, 70, 67, 65, + 62, 60, 57, 55, 52, 50, 47, 45, + 42, 40, 37, 35, 32, 30, 27, 25 +]; +const VP40_DC_C_SCALES: [i16; 64] = [ + 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 147, 145, + 142, 140, 137, 135, 132, 130, 127, 125, + 122, 120, 117, 115, 112, 110, 107, 105, + 102, 100, 97, 95, 92, 90, 87, 85, + 82, 80, 77, 75, 72, 70, 67, 65, + 62, 60, 57, 55, 52, 50, 47, 45, + 42, 40, 37, 35, 32, 30, 27, 25 +]; +const VP40_AC_SCALES: [i16; 64] = [ + 500, 475, 450, 430, 410, 390, 370, 350, + 330, 315, 300, 285, 270, 260, 250, 240, + 230, 220, 210, 200, 190, 185, 180, 170, + 160, 150, 143, 135, 128, 120, 113, 106, + 100, 94, 90, 85, 80, 75, 70, 66, + 62, 57, 52, 49, 45, 41, 38, 35, + 33, 30, 27, 24, 22, 20, 18, 16, + 14, 12, 10, 9, 7, 6, 4, 1 +]; + +const VP40_MBPAT_CODES: [[u8; 14]; 2] = [ + [ 0b000, 0b1111, 0b1001, 0b010, 0b1101, 0b01110, 0b1011, 0b001, 0b01111, 0b1000, 0b0110, 0b1110, 0b1100, 0b1010 ], + [ 0b0111, 0b1010, 0b1001, 0b1100, 0b1000, 0b01101, 0b000, 0b1110, 0b01100, 0b1101, 0b001, 0b1011, 0b1111, 0b010 ] +]; +const VP40_MBPAT_BITS: [[u8; 14]; 2] = [ + [ 3, 4, 4, 3, 4, 5, 4, 3, 5, 4, 4, 4, 4, 4 ], + [ 4, 4, 4, 4, 4, 5, 3, 4, 5, 4, 3, 4, 4, 3 ] +]; +const VP40_BP_PREDICTOR: [u8; 15] = [ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1 ]; +const VP40_MV_X_CODES: [[u32; 63]; 7] = [ + [ + 0x06A, 0x11A, 0x18E, 0x237, 0x04A, 0x236, 0x07A, 0x0D6, + 0x07E, 0x1FD, 0x08C, 0x0D7, 0x087, 0x183, 0x03C, 0x061, + 0x047, 0x069, 0x040, 0x048, 0x049, 0x086, 0x013, 0x0D2, + 0x01C, 0x042, 0x025, 0x01B, 0x013, 0x005, 0x000, 0x007, + 0x005, 0x01B, 0x019, 0x019, 0x008, 0x045, 0x01D, 0x0C6, + 0x068, 0x090, 0x041, 0x04B, 0x031, 0x18F, 0x062, 0x03E, + 0x044, 0x068, 0x030, 0x182, 0x0C0, 0x1A7, 0x091, 0x092, + 0x07B, 0x0FF, 0x1A6, 0x1FC, 0x06A, 0x093, 0x06B + ], [ + 0x039, 0x259, 0x01B, 0x1D1, 0x137, 0x1D0, 0x01A, 0x1B5, + 0x01D, 0x4BC, 0x06C, 0x038, 0x071, 0x02D, 0x07D, 0x075, + 0x019, 0x0E9, 0x037, 0x015, 0x01E, 0x0DB, 0x04C, 0x070, + 0x00D, 0x00C, 0x027, 0x004, 0x002, 0x000, 0x005, 0x007, + 0x006, 0x002, 0x008, 0x024, 0x00C, 0x03B, 0x01E, 0x09A, + 0x00E, 0x069, 0x04A, 0x12D, 0x035, 0x0F9, 0x018, 0x07F, + 0x00F, 0x0F8, 0x07E, 0x25F, 0x068, 0x02C, 0x014, 0x258, + 0x136, 0x4BD, 0x12E, 0x1B4, 0x017, 0x039, 0x01F + ], [ + 0x029, 0x3CB, 0x1F5, 0x263, 0x1F4, 0x3DA, 0x050, 0x260, + 0x1EC, 0x3D3, 0x109, 0x3D2, 0x051, 0x792, 0x0F3, 0x09A, + 0x0F7, 0x132, 0x0C1, 0x1E8, 0x02A, 0x085, 0x061, 0x1F7, + 0x078, 0x0C7, 0x023, 0x07C, 0x012, 0x00B, 0x00E, 0x00D, + 0x000, 0x005, 0x003, 0x004, 0x019, 0x020, 0x03F, 0x043, + 0x062, 0x09F, 0x04E, 0x181, 0x02B, 0x137, 0x0F5, 0x089, + 0x0C6, 0x262, 0x088, 0x3C8, 0x1F6, 0x3CA, 0x09E, 0x261, + 0x136, 0x108, 0x133, 0x793, 0x180, 0x3DB, 0x045 + ], [ + 0x001, 0x1C7, 0x067, 0x0B5, 0x066, 0x139, 0x099, 0x0B4, + 0x0C3, 0x130, 0x000, 0x131, 0x09E, 0x0B7, 0x02C, 0x001, + 0x028, 0x138, 0x04B, 0x031, 0x060, 0x091, 0x003, 0x09D, + 0x017, 0x04D, 0x031, 0x070, 0x007, 0x03A, 0x007, 0x002, + 0x00B, 0x001, 0x00F, 0x008, 0x00D, 0x004, 0x00A, 0x00D, + 0x019, 0x002, 0x03B, 0x04A, 0x015, 0x0C2, 0x018, 0x032, + 0x072, 0x1C6, 0x029, 0x1C5, 0x049, 0x121, 0x01B, 0x030, + 0x01A, 0x1C4, 0x09F, 0x0B6, 0x019, 0x120, 0x073 + ], [ + 0x023, 0x1C8, 0x043, 0x110, 0x00C, 0x153, 0x022, 0x111, + 0x00F, 0x042, 0x023, 0x1C9, 0x02A, 0x01B, 0x073, 0x045, + 0x06E, 0x089, 0x06C, 0x01A, 0x06F, 0x0B6, 0x00B, 0x0E5, + 0x025, 0x020, 0x029, 0x04D, 0x002, 0x014, 0x01A, 0x017, + 0x01E, 0x027, 0x018, 0x028, 0x01F, 0x000, 0x006, 0x010, + 0x007, 0x00B, 0x003, 0x004, 0x01D, 0x02C, 0x019, 0x02B, + 0x009, 0x055, 0x038, 0x00E, 0x024, 0x0A8, 0x00A, 0x099, + 0x05A, 0x098, 0x06D, 0x152, 0x02B, 0x0B7, 0x001 + ], [ + 0x03D, 0x0B1, 0x0DD, 0x1F6, 0x0C5, 0x188, 0x037, 0x03F, + 0x01E, 0x189, 0x00F, 0x03E, 0x06A, 0x1F7, 0x061, 0x079, + 0x018, 0x0B0, 0x00E, 0x0B3, 0x00C, 0x0DF, 0x006, 0x0DC, + 0x019, 0x0DE, 0x027, 0x00E, 0x01A, 0x063, 0x00F, 0x00E, + 0x014, 0x07C, 0x036, 0x06B, 0x03F, 0x060, 0x008, 0x074, + 0x009, 0x078, 0x012, 0x00D, 0x015, 0x02D, 0x002, 0x01C, + 0x005, 0x03B, 0x000, 0x034, 0x019, 0x026, 0x010, 0x075, + 0x002, 0x036, 0x023, 0x0B2, 0x022, 0x0FA, 0x017 + ], [ + 0x015, 0x0DD, 0x03E, 0x16E, 0x04C, 0x012, 0x05D, 0x0B6, + 0x06F, 0x1F1, 0x069, 0x1F0, 0x01D, 0x16F, 0x002, 0x06B, + 0x00C, 0x0DC, 0x068, 0x09B, 0x07D, 0x09A, 0x00D, 0x013, + 0x008, 0x0F9, 0x02C, 0x012, 0x033, 0x04F, 0x00D, 0x005, + 0x012, 0x03F, 0x032, 0x013, 0x03B, 0x005, 0x02F, 0x05A, + 0x03F, 0x01C, 0x03A, 0x008, 0x036, 0x05C, 0x010, 0x000, + 0x00C, 0x04E, 0x003, 0x06A, 0x00E, 0x003, 0x014, 0x01E, + 0x01C, 0x00F, 0x018, 0x023, 0x01E, 0x022, 0x002 + ] +]; +const VP40_MV_X_BITS: [[u8; 63]; 7] = [ + [ + 7, 9, 9, 10, 8, 10, 8, 9, 8, 10, 8, 9, 8, 9, 7, 7, + 7, 8, 7, 8, 7, 8, 6, 8, 6, 7, 6, 6, 5, 4, 2, 3, + 3, 5, 5, 6, 5, 7, 6, 8, 7, 8, 7, 8, 7, 9, 7, 7, + 7, 8, 7, 9, 8, 9, 8, 9, 8, 9, 9, 10, 8, 9, 7 + ], [ + 7, 10, 8, 10, 9, 10, 8, 10, 8, 11, 8, 9, 8, 9, 8, 8, + 7, 9, 7, 8, 7, 9, 7, 8, 6, 7, 6, 6, 4, 4, 3, 3, + 3, 3, 4, 6, 5, 7, 6, 8, 6, 8, 7, 9, 7, 9, 7, 8, + 7, 9, 8, 10, 8, 9, 8, 10, 9, 11, 9, 10, 8, 9, 7 + ], [ + 7, 10, 9, 10, 9, 10, 8, 10, 9, 10, 9, 10, 8, 11, 8, 8, + 8, 9, 8, 9, 7, 8, 7, 9, 7, 8, 6, 7, 5, 5, 4, 4, + 2, 3, 3, 4, 5, 6, 6, 7, 7, 8, 7, 9, 7, 9, 8, 8, + 8, 10, 8, 10, 9, 10, 8, 10, 9, 9, 9, 11, 9, 10, 7 + ], [ + 6, 9, 8, 9, 8, 9, 8, 9, 8, 9, 7, 9, 8, 9, 7, 7, + 7, 9, 7, 8, 7, 8, 6, 8, 6, 7, 6, 7, 5, 6, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 5, 5, 6, 6, 7, 6, 8, 6, 7, + 7, 9, 7, 9, 7, 9, 7, 8, 7, 9, 8, 9, 7, 9, 7 + ], [ + 6, 9, 8, 9, 7, 9, 7, 9, 7, 8, 7, 9, 7, 8, 7, 7, + 7, 8, 7, 8, 7, 8, 6, 8, 6, 7, 6, 7, 5, 6, 5, 5, + 5, 6, 5, 6, 5, 5, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, + 5, 7, 6, 7, 6, 8, 6, 8, 7, 8, 7, 9, 7, 8, 5 + ], [ + 6, 8, 8, 9, 8, 9, 7, 8, 7, 9, 7, 8, 7, 9, 7, 7, + 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 7, 6, 7, 5, 5, + 5, 7, 6, 7, 6, 7, 5, 7, 5, 7, 5, 6, 5, 6, 4, 5, + 4, 6, 4, 6, 5, 6, 5, 7, 5, 7, 6, 8, 6, 8, 5 + ], [ + 5, 8, 7, 9, 7, 8, 7, 8, 7, 9, 7, 9, 7, 9, 6, 7, + 6, 8, 7, 8, 7, 8, 6, 8, 6, 8, 6, 7, 6, 7, 5, 5, + 5, 7, 6, 7, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 5, 5, + 5, 7, 5, 7, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 3 + ] +]; +const VP40_MV_Y_CODES: [[u32; 63]; 7] = [ + [ + 0x052, 0x14C, 0x1FA, 0x124, 0x082, 0x29E, 0x08E, 0x24B, + 0x09C, 0x3F7, 0x086, 0x114, 0x083, 0x3A5, 0x0FA, 0x04F, + 0x0FB, 0x13B, 0x0FC, 0x172, 0x044, 0x173, 0x051, 0x087, + 0x05F, 0x0BA, 0x026, 0x05E, 0x016, 0x015, 0x006, 0x001, + 0x000, 0x01C, 0x01E, 0x075, 0x03B, 0x0FF, 0x025, 0x0BB, + 0x07C, 0x08B, 0x048, 0x171, 0x042, 0x14E, 0x046, 0x0FE, + 0x040, 0x13A, 0x093, 0x115, 0x08F, 0x3F6, 0x170, 0x29F, + 0x1D1, 0x24A, 0x1D3, 0x3A4, 0x1D0, 0x14D, 0x050 + ], [ + 0x0DE, 0x223, 0x136, 0x7C5, 0x12F, 0x4A1, 0x3D7, 0x7AC, + 0x133, 0x7C4, 0x1B8, 0x222, 0x096, 0x251, 0x095, 0x1F0, + 0x0DA, 0x110, 0x09A, 0x360, 0x0DD, 0x12E, 0x048, 0x092, + 0x078, 0x098, 0x027, 0x045, 0x01A, 0x010, 0x005, 0x000, + 0x001, 0x00E, 0x00C, 0x023, 0x03F, 0x0F4, 0x07D, 0x089, + 0x07B, 0x1BE, 0x0F9, 0x3E3, 0x0F3, 0x127, 0x0DB, 0x1EA, + 0x0D9, 0x6E7, 0x1BF, 0x4A0, 0x1B1, 0x6E6, 0x137, 0x7AD, + 0x126, 0x6C2, 0x132, 0x6C3, 0x129, 0x372, 0x0F2 + ], [ + 0x016, 0x09C, 0x13C, 0x09E, 0x12B, 0x0BA, 0x181, 0x317, + 0x084, 0x04E, 0x026, 0x316, 0x180, 0x05C, 0x0C1, 0x02F, + 0x010, 0x045, 0x012, 0x189, 0x024, 0x13D, 0x066, 0x023, + 0x067, 0x0C6, 0x024, 0x04B, 0x011, 0x032, 0x00D, 0x000, + 0x007, 0x005, 0x003, 0x003, 0x005, 0x020, 0x008, 0x025, + 0x026, 0x04F, 0x061, 0x02B, 0x04E, 0x18A, 0x043, 0x09F, + 0x014, 0x254, 0x094, 0x310, 0x085, 0x311, 0x02A, 0x0BB, + 0x18F, 0x255, 0x09D, 0x09F, 0x18E, 0x044, 0x026 + ], [ + 0x061, 0x12A, 0x00D, 0x3BD, 0x089, 0x109, 0x18E, 0x210, + 0x1D3, 0x211, 0x088, 0x019, 0x085, 0x018, 0x0E8, 0x0CE, + 0x040, 0x119, 0x045, 0x1D2, 0x04B, 0x1DD, 0x062, 0x094, + 0x075, 0x00C, 0x027, 0x00D, 0x002, 0x026, 0x006, 0x01E, + 0x00D, 0x01F, 0x001, 0x00A, 0x002, 0x007, 0x00B, 0x000, + 0x01C, 0x076, 0x032, 0x007, 0x024, 0x0C0, 0x007, 0x041, + 0x002, 0x18F, 0x047, 0x1DC, 0x043, 0x12B, 0x0CF, 0x118, + 0x0C6, 0x3BC, 0x08D, 0x3BF, 0x0C1, 0x3BE, 0x066 + ], [ + 0x007, 0x14D, 0x0A0, 0x09E, 0x0CF, 0x39C, 0x0A1, 0x39D, + 0x0AB, 0x1C5, 0x026, 0x14C, 0x025, 0x19C, 0x03F, 0x0E1, + 0x066, 0x1CF, 0x03E, 0x1C4, 0x072, 0x04E, 0x006, 0x0AA, + 0x01C, 0x0E6, 0x032, 0x051, 0x03B, 0x005, 0x01F, 0x018, + 0x002, 0x03A, 0x000, 0x036, 0x005, 0x008, 0x008, 0x016, + 0x009, 0x00D, 0x003, 0x02F, 0x01E, 0x02E, 0x01A, 0x02B, + 0x00C, 0x024, 0x01E, 0x0E0, 0x004, 0x0A7, 0x054, 0x1C7, + 0x052, 0x19D, 0x03A, 0x09F, 0x03B, 0x1C6, 0x037 + ], [ + 0x02A, 0x039, 0x025, 0x115, 0x024, 0x1FA, 0x02F, 0x114, + 0x075, 0x038, 0x0FC, 0x036, 0x01E, 0x1FB, 0x07F, 0x068, + 0x016, 0x037, 0x01F, 0x05C, 0x013, 0x08B, 0x001, 0x0FB, + 0x021, 0x044, 0x02B, 0x06B, 0x03B, 0x00C, 0x01C, 0x019, + 0x001, 0x020, 0x016, 0x07C, 0x00C, 0x074, 0x00A, 0x01C, + 0x012, 0x069, 0x00F, 0x06A, 0x014, 0x011, 0x01E, 0x017, + 0x002, 0x031, 0x01B, 0x030, 0x00D, 0x000, 0x001, 0x01D, + 0x023, 0x01A, 0x01D, 0x05D, 0x010, 0x0FA, 0x013 + ], [ + 0x012, 0x026, 0x041, 0x022, 0x01A, 0x0A9, 0x04C, 0x1B2, + 0x05C, 0x0A8, 0x058, 0x1B3, 0x040, 0x079, 0x00C, 0x055, + 0x01F, 0x0D8, 0x076, 0x023, 0x05F, 0x078, 0x00B, 0x01B, + 0x02D, 0x010, 0x037, 0x06D, 0x032, 0x00A, 0x01A, 0x01E, + 0x01F, 0x02B, 0x00D, 0x077, 0x031, 0x05D, 0x038, 0x027, + 0x00C, 0x0E9, 0x033, 0x05E, 0x030, 0x04D, 0x00A, 0x021, + 0x007, 0x03D, 0x039, 0x0E8, 0x00B, 0x059, 0x014, 0x027, + 0x011, 0x075, 0x00E, 0x009, 0x008, 0x012, 0x000 + ] +]; +const VP40_MV_Y_BITS: [[u8; 63]; 7] = [ + [ + 7, 9, 9, 9, 8, 10, 8, 10, 8, 10, 8, 9, 8, 10, 8, 7, + 8, 9, 8, 9, 7, 9, 7, 8, 7, 8, 6, 7, 5, 5, 3, 2, + 2, 5, 5, 7, 6, 8, 6, 8, 7, 8, 7, 9, 7, 9, 7, 8, + 7, 9, 8, 9, 8, 10, 9, 10, 9, 10, 9, 10, 9, 9, 7 + ], [ + 8, 10, 9, 11, 9, 11, 10, 11, 9, 11, 9, 10, 8, 10, 8, 9, + 8, 9, 8, 10, 8, 9, 7, 8, 7, 8, 6, 7, 5, 5, 3, 2, + 2, 4, 4, 6, 6, 8, 7, 8, 7, 9, 8, 10, 8, 9, 8, 9, + 8, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 10, 8 + ], [ + 7, 9, 9, 10, 9, 10, 9, 10, 8, 9, 8, 10, 9, 9, 8, 8, + 7, 9, 7, 9, 7, 9, 7, 8, 7, 8, 6, 7, 5, 6, 4, 3, + 3, 3, 3, 4, 4, 6, 5, 7, 6, 8, 7, 8, 7, 9, 7, 8, + 7, 10, 8, 10, 8, 10, 8, 10, 9, 10, 9, 10, 9, 9, 7 + ], [ + 7, 9, 8, 10, 8, 9, 9, 10, 9, 10, 8, 9, 8, 9, 8, 8, + 7, 9, 7, 9, 7, 9, 7, 8, 7, 7, 6, 7, 5, 6, 4, 5, + 4, 5, 3, 4, 3, 4, 4, 5, 5, 7, 6, 7, 6, 8, 6, 7, + 6, 9, 7, 9, 7, 9, 8, 9, 8, 10, 8, 10, 8, 10, 7 + ], [ + 6, 9, 8, 9, 8, 10, 8, 10, 8, 9, 7, 9, 7, 9, 7, 8, + 7, 9, 7, 9, 7, 8, 6, 8, 6, 8, 6, 7, 6, 6, 5, 5, + 4, 6, 4, 6, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, + 5, 7, 6, 8, 6, 8, 7, 9, 7, 9, 7, 9, 7, 9, 6 + ], [ + 6, 8, 7, 9, 7, 9, 7, 9, 7, 8, 8, 8, 7, 9, 7, 7, + 6, 8, 7, 8, 6, 8, 6, 8, 6, 7, 6, 7, 6, 6, 5, 5, + 4, 6, 5, 7, 5, 7, 5, 6, 5, 7, 5, 7, 5, 6, 5, 5, + 4, 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 8, 6, 8, 5 + ], [ + 5, 7, 7, 8, 7, 8, 7, 9, 7, 8, 7, 9, 7, 8, 6, 7, + 6, 8, 7, 8, 7, 8, 6, 7, 6, 7, 6, 7, 6, 6, 5, 5, + 5, 6, 5, 7, 6, 7, 6, 7, 5, 8, 6, 7, 6, 7, 5, 6, + 5, 7, 6, 8, 5, 7, 5, 6, 5, 7, 5, 6, 5, 6, 3 + ] +]; + +const VP40_LOOP_STRENGTH: [i16; 64] = [ + 30, 25, 20, 20, 15, 15, 14, 14, + 13, 13, 12, 12, 11, 11, 10, 10, + 9, 9, 8, 8, 7, 7, 7, 7, + 6, 6, 6, 6, 5, 5, 5, 5, + 4, 4, 4, 4, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1 +]; +const VP40_MV_LUT_INDEX: [usize; 32] = [ + 0, 1, 2, 2, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6 +]; diff --git a/nihav-duck/src/codecs/vpcommon.rs b/nihav-duck/src/codecs/vpcommon.rs index 8ea6a47..05b07d1 100644 --- a/nihav-duck/src/codecs/vpcommon.rs +++ b/nihav-duck/src/codecs/vpcommon.rs @@ -1,4 +1,5 @@ use nihav_core::codecs::*; +use nihav_core::codecs::blockdsp::*; #[derive(Clone,Copy,Debug,PartialEq)] #[allow(dead_code)] @@ -213,3 +214,38 @@ pub fn vp31_loop_filter(data: &mut [u8], mut off: usize, step: usize, stride: us } } +pub fn vp_copy_block(dst: &mut NASimpleVideoFrame, src: NAVideoBufferRef, comp: usize, + dx: usize, dy: usize, mv_x: i16, mv_y: i16, + preborder: usize, postborder: usize, loop_str: i16, + mode: usize, interp: &[BlkInterpFunc], mut mc_buf: NAVideoBufferRef) +{ + let sx = (dx as isize) + (mv_x as isize); + let sy = (dy as isize) + (mv_y as isize); + if ((sx | sy) & 7) == 0 { + copy_block(dst, src, comp, dx, dy, mv_x, mv_y, 8, 8, preborder, postborder, mode, interp); + return; + } + let pre = preborder.max(2); + let post = postborder.max(1); + let bsize = 8 + pre + post; + let src_x = sx - (pre as isize); + let src_y = sy - (pre as isize); + { + let mut tmp_buf = NASimpleVideoFrame::from_video_buf(&mut mc_buf).unwrap(); + copy_block(&mut tmp_buf, src, comp, 0, 0, src_x as i16, src_y as i16, + bsize, bsize, 0, 0, 0, interp); + if (sy & 7) != 0 { + let foff = (8 - (sy & 7)) as usize; + let off = (pre + foff) * tmp_buf.stride[comp]; + vp31_loop_filter(tmp_buf.data, off, tmp_buf.stride[comp], 1, bsize, loop_str); + } + if (sx & 7) != 0 { + let foff = (8 - (sx & 7)) as usize; + let off = pre + foff; + vp31_loop_filter(tmp_buf.data, off, 1, tmp_buf.stride[comp], bsize, loop_str); + } + } + let dxoff = (pre as i16) - (dx as i16); + let dyoff = (pre as i16) - (dy as i16); + copy_block(dst, mc_buf, comp, dx, dy, dxoff, dyoff, 8, 8, preborder, postborder, 0/* mode*/, interp); +}