3 use nihav_core::codecs::*;
4 use nihav_core::codecs::blockdsp::*;
5 use nihav_core::io::bitreader::*;
6 use nihav_core::io::codebook::*;
7 use nihav_core::io::intcode::*;
8 use super::vpcommon::*;
10 #[derive(Clone,Copy,Debug,PartialEq)]
17 fn map_idx(idx: usize) -> u8 {
22 dc_cb: [Codebook<u8>; 5],
23 ac_i_cb: [Codebook<u8>; 5],
24 ac_p_cb: [Codebook<u8>; 5],
25 mbtype_cb: Codebook<VPMBType>,
28 fn map_mbt(idx: usize) -> VPMBType {
34 let mut dc_cb: [Codebook<u8>; 5];
35 let mut ac_i_cb: [Codebook<u8>; 5];
36 let mut ac_p_cb: [Codebook<u8>; 5];
37 let mut cr = TableCodebookDescReader::new(&VP30_MBTYPE_CODES, &VP30_MBTYPE_BITS, map_mbt);
38 let mbtype_cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
40 dc_cb = mem::uninitialized();
41 ac_i_cb = mem::uninitialized();
42 ac_p_cb = mem::uninitialized();
44 let mut cr = TableCodebookDescReader::new(&VP30_DC_CODES[i], &VP30_DC_BITS[i], map_idx);
45 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
46 ptr::write(&mut dc_cb[i], cb);
47 let mut cr = TableCodebookDescReader::new(&VP30_AC_INTRA_CODES[i], &VP30_AC_INTRA_BITS[i], map_idx);
48 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
49 ptr::write(&mut ac_i_cb[i], cb);
50 let mut cr = TableCodebookDescReader::new(&VP30_AC_INTER_CODES[i], &VP30_AC_INTER_BITS[i], map_idx);
51 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
52 ptr::write(&mut ac_p_cb[i], cb);
55 Self { dc_cb, ac_i_cb, ac_p_cb, mbtype_cb }
60 dc_cb: [Codebook<u8>; 16],
61 ac0_cb: [Codebook<u8>; 16],
62 ac1_cb: [Codebook<u8>; 16],
63 ac2_cb: [Codebook<u8>; 16],
64 ac3_cb: [Codebook<u8>; 16],
69 let mut dc_cb: [Codebook<u8>; 16];
70 let mut ac0_cb: [Codebook<u8>; 16];
71 let mut ac1_cb: [Codebook<u8>; 16];
72 let mut ac2_cb: [Codebook<u8>; 16];
73 let mut ac3_cb: [Codebook<u8>; 16];
75 dc_cb = mem::uninitialized();
76 ac0_cb = mem::uninitialized();
77 ac1_cb = mem::uninitialized();
78 ac2_cb = mem::uninitialized();
79 ac3_cb = mem::uninitialized();
81 let mut cr = TableCodebookDescReader::new(&VP31_DC_CODES[i], &VP31_DC_BITS[i], map_idx);
82 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
83 ptr::write(&mut dc_cb[i], cb);
85 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT0_CODES[i], &VP31_AC_CAT0_BITS[i], map_idx);
86 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
87 ptr::write(&mut ac0_cb[i], cb);
88 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT1_CODES[i], &VP31_AC_CAT1_BITS[i], map_idx);
89 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
90 ptr::write(&mut ac1_cb[i], cb);
91 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT2_CODES[i], &VP31_AC_CAT2_BITS[i], map_idx);
92 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
93 ptr::write(&mut ac2_cb[i], cb);
94 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT3_CODES[i], &VP31_AC_CAT3_BITS[i], map_idx);
95 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
96 ptr::write(&mut ac3_cb[i], cb);
99 Self { dc_cb, ac0_cb, ac1_cb, ac2_cb, ac3_cb }
101 fn new_vp4() -> VP31Codes {
102 let mut dc_cb: [Codebook<u8>; 16];
103 let mut ac0_cb: [Codebook<u8>; 16];
104 let mut ac1_cb: [Codebook<u8>; 16];
105 let mut ac2_cb: [Codebook<u8>; 16];
106 let mut ac3_cb: [Codebook<u8>; 16];
108 dc_cb = mem::uninitialized();
109 ac0_cb = mem::uninitialized();
110 ac1_cb = mem::uninitialized();
111 ac2_cb = mem::uninitialized();
112 ac3_cb = mem::uninitialized();
114 let mut cr = TableCodebookDescReader::new(&VP40_DC_CODES[i], &VP40_DC_BITS[i], map_idx);
115 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
116 ptr::write(&mut dc_cb[i], cb);
118 let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT0_CODES[i], &VP40_AC_CAT0_BITS[i], map_idx);
119 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
120 ptr::write(&mut ac0_cb[i], cb);
121 let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT1_CODES[i], &VP40_AC_CAT1_BITS[i], map_idx);
122 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
123 ptr::write(&mut ac1_cb[i], cb);
124 let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT2_CODES[i], &VP40_AC_CAT2_BITS[i], map_idx);
125 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
126 ptr::write(&mut ac2_cb[i], cb);
127 let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT3_CODES[i], &VP40_AC_CAT3_BITS[i], map_idx);
128 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
129 ptr::write(&mut ac3_cb[i], cb);
132 VP31Codes { dc_cb, ac0_cb, ac1_cb, ac2_cb, ac3_cb }
136 struct VP40AuxCodes {
137 mv_x_cb: [Codebook<i8>; 7],
138 mv_y_cb: [Codebook<i8>; 7],
139 mbpat_cb: [Codebook<u8>; 2],
142 fn map_mv(idx: usize) -> i8 {
148 let mut mv_x_cb: [Codebook<i8>; 7];
149 let mut mv_y_cb: [Codebook<i8>; 7];
151 mv_x_cb = mem::uninitialized();
152 mv_y_cb = mem::uninitialized();
154 let mut cr = TableCodebookDescReader::new(&VP40_MV_X_CODES[i], &VP40_MV_X_BITS[i], map_mv);
155 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
156 ptr::write(&mut mv_x_cb[i], cb);
157 let mut cr = TableCodebookDescReader::new(&VP40_MV_Y_CODES[i], &VP40_MV_Y_BITS[i], map_mv);
158 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
159 ptr::write(&mut mv_y_cb[i], cb);
162 let mut cr0 = TableCodebookDescReader::new(&VP40_MBPAT_CODES[0], &VP40_MBPAT_BITS[0], map_idx);
163 let mut cr1 = TableCodebookDescReader::new(&VP40_MBPAT_CODES[1], &VP40_MBPAT_BITS[1], map_idx);
164 let mbpat_cb = [Codebook::new(&mut cr0, CodebookMode::MSB).unwrap(),
165 Codebook::new(&mut cr1, CodebookMode::MSB).unwrap()];
166 Self { mv_x_cb, mv_y_cb, mbpat_cb }
189 btype: VPMBType::Intra,
199 type ReadRunFunc = fn (&mut BitReader) -> DecoderResult<usize>;
201 const VP31_LONG_RUN_BASE: [usize; 7] = [ 1, 2, 4, 6, 10, 18, 34 ];
202 const VP31_LONG_RUN_BITS: [u8; 7] = [ 0, 1, 1, 2, 3, 4, 12 ];
203 fn read_long_run(br: &mut BitReader) -> DecoderResult<usize> {
204 let pfx = br.read_code(UintCodeType::LimitedUnary(6, 0))? as usize;
205 if pfx == 0 { return Ok(1); }
206 Ok(VP31_LONG_RUN_BASE[pfx] + (br.read(VP31_LONG_RUN_BITS[pfx])? as usize))
209 const VP31_SHORT_RUN_BASE: [usize; 6] = [ 1, 3, 5, 7, 11, 15 ];
210 const VP31_SHORT_RUN_BITS: [u8; 6] = [ 1, 1, 1, 2, 2, 4 ];
211 fn read_short_run(br: &mut BitReader) -> DecoderResult<usize> {
212 let pfx = br.read_code(UintCodeType::LimitedUnary(5, 0))? as usize;
213 Ok(VP31_SHORT_RUN_BASE[pfx] + (br.read(VP31_SHORT_RUN_BITS[pfx])? as usize))
216 fn read_mb_run(br: &mut BitReader) -> DecoderResult<usize> {
217 let pfx = br.read_code(UintCodeType::LimitedUnary(10, 0))? as usize;
218 if pfx == 10 { unimplemented!(); }
222 let base = (1 << (pfx - 1)) + 1;
223 let bits = (pfx - 1) as u8;
224 let add_bits = br.read(bits)? as usize;
229 struct BitRunDecoder {
232 read_run: ReadRunFunc,
236 fn new(br: &mut BitReader, read_run: ReadRunFunc) -> DecoderResult<Self> {
237 let value = !br.read_bool()?; // it will be flipped before run decoding
238 Ok(Self { value, run: 0, read_run })
240 fn get_val(&mut self, br: &mut BitReader) -> DecoderResult<bool> {
242 self.value = !self.value;
243 self.run = (self.read_run)(br)?;
250 const VP30_NE0_BITS: [u8; 5] = [ 2, 2, 3, 4, 8 ];
251 const VP30_NE0_BASE: [usize; 5] = [ 1, 5, 9, 17, 33 ];
252 fn vp30_read_ne_run0(br: &mut BitReader) -> DecoderResult<usize> {
253 let len = br.read_code(UintCodeType::LimitedUnary(4, 0))? as usize;
254 Ok(VP30_NE0_BASE[len] + (br.read(VP30_NE0_BITS[len])? as usize))
256 fn vp30_read_ne_run1(br: &mut BitReader) -> DecoderResult<usize> {
257 let len = br.read_code(UintCodeType::LimitedUnary(6, 0))? as usize;
259 Ok((br.read(1)? as usize) + 1)
263 Ok((br.read(8)? as usize) + 8)
266 fn vp30_read_coded_run0(br: &mut BitReader) -> DecoderResult<usize> {
267 let len = br.read_code(UintCodeType::LimitedUnary(5, 0))? as usize;
277 10010 - 7 + get_bits(3)
278 101100 - 15 + get_bits(5)
279 1011010 - 47 + get_bits(8)
280 1011011 - 303 + get_bits(16)
282 const VP30_CRUN1_LUT: [u8; 32] = [
283 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
284 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
285 0x34, 0x34, 0x75, 0x55, 0x44, 0x44, 0x85, 0x65,
286 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22
288 fn vp30_read_coded_run1(br: &mut BitReader) -> DecoderResult<usize> {
289 let idx = br.peek(5) as usize;
290 let sym = (VP30_CRUN1_LUT[idx] >> 4) as usize;
291 let bits = VP30_CRUN1_LUT[idx] & 0xF;
292 br.skip(bits as u32)?;
296 Ok(7 + (br.read(3)? as usize))
298 let len = br.read_code(UintCodeType::Unary012)?;
300 0 => Ok(15 + (br.read(5)? as usize)),
301 1 => Ok(47 + (br.read(8)? as usize)),
302 _ => Ok(303 + (br.read(16)? as usize)),
308 info: NACodecInfoRef,
318 aux_codes: Option<VP40AuxCodes>,
320 mc_buf: NAVideoBufferRef<u8>,
324 mb_partial: Vec<bool>,
335 blk_addr: Vec<usize>,
337 sb_info: Vec<SBState>,
343 fn vp30_read_mv_comp(br: &mut BitReader) -> DecoderResult<i16> {
344 let mode = br.read(2)?;
345 if mode == 0 { return Ok(0); }
346 let sign = br.read_bool()?;
347 let val = match mode - 1 {
349 1 => 2 + (br.read(2)? as i16),
350 _ => br.read(5)? as i16,
359 fn vp30_read_mv(br: &mut BitReader) -> DecoderResult<MV> {
360 let x = vp30_read_mv_comp(br)?;
361 let y = vp30_read_mv_comp(br)?;
365 fn read_mv_comp_packed(br: &mut BitReader) -> DecoderResult<i16> {
366 let code = br.read(3)?;
371 3 => if br.read_bool()? { Ok(-2) } else { Ok(2) },
372 4 => if br.read_bool()? { Ok(-3) } else { Ok(3) },
374 let val = (br.read(2)? as i16) + 4;
382 let val = (br.read(3)? as i16) + 8;
390 let val = (br.read(4)? as i16) + 16;
400 fn read_mv_packed(br: &mut BitReader) -> DecoderResult<MV> {
401 let x = read_mv_comp_packed(br)?;
402 let y = read_mv_comp_packed(br)?;
406 fn read_mv_comp_raw(br: &mut BitReader) -> DecoderResult<i16> {
407 let val = br.read(5)? as i16;
415 fn read_mv_raw(br: &mut BitReader) -> DecoderResult<MV> {
416 let x = read_mv_comp_raw(br)?;
417 let y = read_mv_comp_raw(br)?;
421 fn rescale_qmat(dst_qmat: &mut [i16; 64], base_qmat: &[i16; 64], dc_quant: i16, ac_quant: i16, minval: i16) {
422 for (dst, src) in dst_qmat.iter_mut().zip(base_qmat.iter()) {
423 *dst = (src.wrapping_mul(ac_quant) / 100).max(minval) << 2;
425 dst_qmat[0] = (base_qmat[0] * dc_quant / 100).max(minval * 2) << 2;
428 fn expand_token(blk: &mut Block, br: &mut BitReader, eob_run: &mut usize, coef_no: usize, token: u8) -> DecoderResult<()> {
431 0 | 1 | 2 => { *eob_run = (token as usize) + 1; },
433 let bits = token - 1;
434 *eob_run = (br.read(bits)? as usize) + (1 << bits);
436 6 => { *eob_run = br.read(12)? as usize; },
439 let bits = if token == 7 { 3 } else { 6 };
440 let run = (br.read(bits)? as usize) + 1;
442 validate!(blk.idx <= 64);
444 // single coefficients
445 9 | 10 | 11 | 12 => {
446 let val = (i16::from(token) - 7) >> 1;
447 if (token & 1) == 1 {
448 blk.coeffs[ZIGZAG[blk.idx]] = val;
450 blk.coeffs[ZIGZAG[blk.idx]] = -val;
454 13 | 14 | 15 | 16 => {
455 let val = i16::from(token) - 10;
456 if !br.read_bool()? {
457 blk.coeffs[ZIGZAG[blk.idx]] = val;
459 blk.coeffs[ZIGZAG[blk.idx]] = -val;
463 17 | 18 | 19 | 20 | 21 | 22 => {
464 let add_bits = if token == 22 { 9 } else { token - 16 };
465 let sign = br.read_bool()?;
466 let val = (br.read(add_bits)? as i16) + VP3_LITERAL_BASE[(token - 17) as usize];
468 blk.coeffs[ZIGZAG[blk.idx]] = val;
470 blk.coeffs[ZIGZAG[blk.idx]] = -val;
474 // zero run plus coefficient
475 23 | 24 | 25 | 26 | 27 => {
476 blk.idx += (token - 22) as usize;
477 validate!(blk.idx < 64);
478 if !br.read_bool()? {
479 blk.coeffs[ZIGZAG[blk.idx]] = 1;
481 blk.coeffs[ZIGZAG[blk.idx]] = -1;
486 let run_bits = token - 26;
492 let sign = br.read_bool()?;
493 blk.idx += br.read(run_bits)? as usize;
494 validate!(blk.idx < 64);
496 blk.coeffs[ZIGZAG[blk.idx]] = 1;
498 blk.coeffs[ZIGZAG[blk.idx]] = -1;
504 validate!(blk.idx < 64);
505 let sign = br.read_bool()?;
506 let val = (br.read(1)? as i16) + 2;
508 blk.coeffs[ZIGZAG[blk.idx]] = val;
510 blk.coeffs[ZIGZAG[blk.idx]] = -val;
515 let sign = br.read_bool()?;
516 let val = (br.read(1)? as i16) + 2;
517 blk.idx += (br.read(1)? as usize) + 2;
518 validate!(blk.idx < 64);
520 blk.coeffs[ZIGZAG[blk.idx]] = val;
522 blk.coeffs[ZIGZAG[blk.idx]] = -val;
530 } else if coef_no > 0 {
536 macro_rules! fill_dc_pred {
537 ($self: expr, $ref_id: expr, $pred: expr, $pp: expr, $bit: expr, $idx: expr) => {
538 if $self.blocks[$idx].coded && $self.blocks[$idx].btype.get_ref_id() == $ref_id {
539 $pred[$bit] = $self.blocks[$idx].coeffs[0] as i32;
545 fn vp31_loop_filter_v(frm: &mut NASimpleVideoFrame<u8>, x: usize, y: usize, plane: usize, loop_str: i16) {
546 let off = frm.offset[plane] + x + y * frm.stride[plane];
547 vp31_loop_filter(frm.data, off, 1, frm.stride[plane], 8, loop_str);
550 fn vp31_loop_filter_h(frm: &mut NASimpleVideoFrame<u8>, x: usize, y: usize, plane: usize, loop_str: i16) {
551 let off = frm.offset[plane] + x + y * frm.stride[plane];
552 vp31_loop_filter(frm.data, off, frm.stride[plane], 1, 8, loop_str);
556 fn new(version: u8) -> Self {
557 let vt = alloc_video_buffer(NAVideoInfo::new(24, 24, false, YUV420_FORMAT), 4).unwrap();
558 let mc_buf = vt.get_vbuf().unwrap();
560 info: NACodecInfoRef::default(),
568 shuf: VPShuffler::new(),
575 mb_coded: Vec::new(),
576 mb_partial: Vec::new(),
588 blk_addr: Vec::new(),
591 sb_blocks: Vec::new(),
593 mb_blocks: Vec::new(),
596 fn parse_header(&mut self, br: &mut BitReader) -> DecoderResult<()> {
597 self.is_intra = !br.read_bool()?;
599 self.quant = br.read(6)? as usize;
602 validate!(self.version == 3 || self.version == 30);
603 let mb_w = br.read(8)? as usize;
604 let mb_h = br.read(8)? as usize;
605 println!(" VP30 {}x{} ({}x{})", mb_w, mb_h, self.mb_w, self.mb_h);
606 validate!(mb_w == self.mb_w && mb_h == self.mb_h);
607 if self.version == 3 {
609 self.codes = Codes::VP30(VP30Codes::new());
612 let version = br.read(13)?;
613 println!("intra, ver {} (self {})", version, self.version);
614 let coding_type = br.read(1)?;
615 validate!(coding_type == 0);
618 validate!(self.version == 3 || self.version == 31);
619 if self.version == 3 {
621 self.codes = Codes::VP31(VP31Codes::new());
623 } else if version == 3 {
624 validate!(self.version == 4);
625 let mb_h = br.read(8)? as usize;
626 let mb_w = br.read(8)? as usize;
627 //println!(" VP40 {}x{} ({}x{})", mb_w, mb_h, self.mb_w, self.mb_h);
628 validate!(mb_w == self.mb_w && mb_h == self.mb_h);
629 let fact1 = br.read(5)?;
630 let fact2 = br.read(3)?;
631 validate!(fact1 == 1 && fact2 == 1);
632 let fact1 = br.read(5)?;
633 let fact2 = br.read(3)?;
634 validate!(fact1 == 1 && fact2 == 1);
637 return Err(DecoderError::InvalidData);
641 self.loop_str = if self.version != 4 {
642 VP31_LOOP_STRENGTH[self.quant]
644 VP40_LOOP_STRENGTH[self.quant]
646 //println!("decode frame({},{},{})", self.is_intra as u8, self.is_intra as u8, self.quant);
649 fn vp30_unpack_sb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
650 let mut has_nonempty = false;
652 let mut bit = !br.read_bool()?;
654 for sb in self.sb_info.iter_mut() {
657 run = if bit { vp30_read_ne_run1(br)? } else { vp30_read_ne_run0(br)? };
659 *sb = if bit { has_nonempty = true; SBState::Partial } else { SBState::Uncoded };
665 for el in self.mb_coded.iter_mut() { *el = false; }
666 let mut bit = !br.read_bool()?;
668 let mut mbiter = self.mb_coded.iter_mut();
669 for (sb, nmb) in self.sb_info.iter_mut().zip(self.sb_mbs.iter()) {
670 let nmbs = *nmb as usize;
671 if *sb == SBState::Partial {
675 run = if bit { vp30_read_coded_run1(br)? } else { vp30_read_coded_run0(br)? };
678 *mbiter.next().unwrap() = bit;
682 mbiter.next().unwrap();
687 let mut bit = !br.read_bool()?;
690 for (coded, nblk) in self.mb_coded.iter().zip(self.mb_blocks.iter()) {
691 let nblks = *nblk as usize;
693 let mut cb = [false; 4];
697 run = if bit { vp30_read_coded_run1(br)? } else { vp30_read_coded_run0(br)? };
703 let addr = self.blk_addr[cur_blk + j] >> 2;
704 self.blocks[addr].coded = cb[j];
713 fn vp30_unpack_mb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
715 if let Codes::VP30(ref codes) = self.codes {
716 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()).take(self.y_sbs) {
717 let nblks = *nblk as usize;
718 if *sb == SBState::Uncoded {
720 self.blocks[self.blk_addr[cur_blk] >> 2].btype = VPMBType::InterNoMV;
724 for _ in 0..nblks/4 {
725 let mut coded = *sb == SBState::Coded;
728 if self.blocks[self.blk_addr[cur_blk + blk] >> 2].coded {
734 let mode = if !coded {
737 br.read_cb(&codes.mbtype_cb)?
740 self.blocks[self.blk_addr[cur_blk] >> 2].btype = mode;
747 return Err(DecoderError::Bug);
749 // replicate types for chroma
751 let mut off_u = self.y_blocks;
752 let mut off_v = off_u + self.mb_w * self.mb_h;
753 for _blk_y in 0..self.mb_h {
754 for blk_x in 0..self.mb_w {
755 let btype = self.blocks[off_y + blk_x * 2].btype;
756 self.blocks[off_u + blk_x].btype = btype;
757 self.blocks[off_v + blk_x].btype = btype;
759 off_y += self.mb_w * 2 * 2;
765 fn vp30_unpack_mv_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
766 let mut last_mv = ZERO_MV;
769 for _ in 0..self.y_blocks/4 {
770 let baddr = self.blk_addr[cur_blk] >> 2;
771 if self.blocks[baddr].btype == VPMBType::InterFourMV {
772 let saddr = baddr.min(self.blk_addr[cur_blk + 1] >> 2).min(self.blk_addr[cur_blk + 2] >> 2).min(self.blk_addr[cur_blk + 3] >> 2);
774 let blk = &mut self.blocks[saddr + (i & 1) + (i & 2) * self.mb_w];
776 blk.mv = vp30_read_mv(br)?;
782 match self.blocks[baddr].btype {
783 VPMBType::Intra | VPMBType::InterNoMV | VPMBType::GoldenNoMV => {
786 VPMBType::InterMV => {
787 cur_mv = vp30_read_mv(br)?;
790 VPMBType::InterNearest => {
794 cur_mv = vp30_read_mv(br)?;
798 self.blocks[self.blk_addr[cur_blk] >> 2].mv = cur_mv;
805 fn vp30_unpack_coeffs(&mut self, br: &mut BitReader, coef_no: usize, table: usize) -> DecoderResult<()> {
806 if let Codes::VP30(ref codes) = self.codes {
807 for blkaddr in self.blk_addr.iter() {
808 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
809 if !blk.coded || blk.idx != coef_no { continue; }
810 if self.eob_run > 0 {
815 let cb = if coef_no == 0 {
817 } else if blk.btype.is_intra() {
818 &codes.ac_i_cb[table]
820 &codes.ac_p_cb[table]
822 let token = br.read_cb(cb)?;
823 expand_token(blk, br, &mut self.eob_run, coef_no, token)?;
827 Err(DecoderError::Bug)
830 fn vp31_unpack_sb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
831 let mut has_uncoded = false;
832 let mut has_partial = false;
834 let mut brun = BitRunDecoder::new(br, read_long_run)?;
835 for sb in self.sb_info.iter_mut() {
836 if brun.get_val(br)? {
837 *sb = SBState::Partial;
840 *sb = SBState::Uncoded;
846 let mut brun = BitRunDecoder::new(br, read_long_run)?;
848 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()) {
849 let nblks = *nblk as usize;
850 if *sb != SBState::Partial && brun.get_val(br)? {
851 *sb = SBState::Coded;
853 let blk_idx = self.blk_addr[cur_blk] >> 2;
854 self.blocks[blk_idx].coded = true;
859 let blk_idx = self.blk_addr[cur_blk] >> 2;
860 self.blocks[blk_idx].coded = false;
867 let mut brun = BitRunDecoder::new(br, read_short_run)?;
869 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()) {
870 let nblks = *nblk as usize;
871 if *sb == SBState::Partial {
873 let blk_idx = self.blk_addr[cur_blk] >> 2;
874 self.blocks[blk_idx].coded = brun.get_val(br)?;
884 fn vp31_unpack_mb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
885 let mut modes = [VPMBType::InterNoMV; 8];
886 let alphabet = br.read(3)? as usize;
887 let raw_modes = alphabet >= 7;
889 for mode in VP31_DEFAULT_MB_MODES.iter() {
890 modes[br.read(3)? as usize] = *mode;
892 } else if alphabet < 7 {
893 modes.copy_from_slice(&VP31_MB_MODES[alphabet - 1]);
897 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()).take(self.y_sbs) {
898 let nblks = *nblk as usize;
899 if *sb == SBState::Uncoded {
901 self.blocks[self.blk_addr[cur_blk] >> 2].btype = VPMBType::InterNoMV;
905 for _ in 0..nblks/4 {
906 let mut coded = *sb == SBState::Coded;
909 if self.blocks[self.blk_addr[cur_blk + blk] >> 2].coded {
915 let mode = if !coded {
917 } else if !raw_modes {
918 let code = br.read_code(UintCodeType::LimitedUnary(7, 0))?;
921 VP31_DEFAULT_MB_MODES[br.read(3)? as usize]
924 self.blocks[self.blk_addr[cur_blk] >> 2].btype = mode;
930 // replicate types for chroma
932 let mut off_u = self.y_blocks;
933 let mut off_v = off_u + self.mb_w * self.mb_h;
934 for _blk_y in 0..self.mb_h {
935 for blk_x in 0..self.mb_w {
936 let btype = self.blocks[off_y + blk_x * 2].btype;
937 self.blocks[off_u + blk_x].btype = btype;
938 self.blocks[off_v + blk_x].btype = btype;
940 off_y += self.mb_w * 2 * 2;
946 fn vp31_unpack_mv_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
947 let mut last_mv = ZERO_MV;
948 let mut last2_mv = ZERO_MV;
949 let read_mv = if br.read_bool()? { read_mv_raw } else { read_mv_packed };
952 for _ in 0..self.y_blocks/4 {
953 if self.blocks[self.blk_addr[cur_blk] >> 2].btype == VPMBType::InterFourMV {
955 let blk = &mut self.blocks[self.blk_addr[cur_blk] >> 2];
957 blk.mv = (read_mv)(br)?;
965 match self.blocks[self.blk_addr[cur_blk] >> 2].btype {
966 VPMBType::Intra | VPMBType::InterNoMV | VPMBType::GoldenNoMV => {
969 VPMBType::InterMV => {
970 cur_mv = (read_mv)(br)?;
974 VPMBType::InterNearest => {
977 VPMBType::InterNear => {
979 std::mem::swap(&mut last_mv, &mut last2_mv);
982 cur_mv = (read_mv)(br)?;
986 self.blocks[self.blk_addr[cur_blk] >> 2].mv = cur_mv;
993 fn vp31_unpack_coeffs(&mut self, br: &mut BitReader, coef_no: usize, table_y: usize, table_c: usize) -> DecoderResult<()> {
994 if let Codes::VP31(ref codes) = self.codes {
995 let cbs = if coef_no == 0 {
996 [&codes.dc_cb[table_y], &codes.dc_cb[table_c]]
997 } else if coef_no < 6 {
998 [&codes.ac0_cb[table_y], &codes.ac0_cb[table_c]]
999 } else if coef_no < 15 {
1000 [&codes.ac1_cb[table_y], &codes.ac1_cb[table_c]]
1001 } else if coef_no < 28 {
1002 [&codes.ac2_cb[table_y], &codes.ac2_cb[table_c]]
1004 [&codes.ac3_cb[table_y], &codes.ac3_cb[table_c]]
1006 for blkaddr in self.blk_addr.iter() {
1007 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
1008 if !blk.coded || blk.idx != coef_no { continue; }
1009 if self.eob_run > 0 {
1014 let cb = if (blkaddr & 3) == 0 { cbs[0] } else { cbs[1] };
1015 let token = br.read_cb(cb)?;
1016 expand_token(blk, br, &mut self.eob_run, coef_no, token)?;
1020 Err(DecoderError::Bug)
1023 fn vp40_unpack_sb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
1024 let mut has_uncoded = false;
1026 if let Some(ref aux_codes) = self.aux_codes {
1027 for el in self.sb_info.iter_mut() {
1028 *el = SBState::Partial;
1031 let mut mbiter = self.mb_coded.iter_mut();
1032 let mut brun = BitRunDecoder::new(br, read_mb_run)?;
1033 for nmb in self.sb_mbs.iter() {
1034 let nmbs = *nmb as usize;
1036 let coded = brun.get_val(br)?;
1037 *mbiter.next().unwrap() = coded;
1038 has_uncoded |= !coded;
1043 let mut mbiter = self.mb_coded.iter().zip(self.mb_partial.iter_mut());
1044 let mut brun = BitRunDecoder::new(br, read_mb_run)?;
1045 for nmb in self.sb_mbs.iter() {
1046 let nmbs = *nmb as usize;
1048 let (coded, partial) = mbiter.next().unwrap();
1052 *partial = brun.get_val(br)?;
1058 let mut cur_blk = 0;
1059 for ((coded, partial), nblk) in self.mb_coded.iter().zip(self.mb_partial.iter()).zip(self.mb_blocks.iter()) {
1060 let nblks = *nblk as usize;
1063 let addr = self.blk_addr[cur_blk] >> 2;
1064 self.blocks[addr].coded = true;
1067 } else if !*partial {
1069 let addr = self.blk_addr[cur_blk] >> 2;
1070 self.blocks[addr].coded = false;
1074 let mut pat = br.read_cb(&aux_codes.mbpat_cb[bpmode])? + 1;
1075 bpmode = VP40_BP_PREDICTOR[pat as usize] as usize;
1077 let mut addrs = [0; 4];
1079 addrs[i] = self.blk_addr[cur_blk + i] >> 2;
1080 for j in (0..i).rev() {
1081 if addrs[j] > addrs[j + 1] {
1082 addrs.swap(j, j + 1);
1087 self.blocks[addrs[i]].coded = (pat & 8) != 0;
1096 Err(DecoderError::Bug)
1099 fn vp40_unpack_mv_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
1100 let mut last_mv = ZERO_MV;
1101 let mut last2_mv = ZERO_MV;
1102 let mut last_mv_g = ZERO_MV;
1104 let mut cur_blk = 0;
1105 if let Some(ref codes) = self.aux_codes {
1106 for _ in 0..self.y_blocks/4 {
1107 if self.blocks[self.blk_addr[cur_blk] >> 2].btype == VPMBType::InterFourMV {
1108 let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.abs() as usize]];
1109 let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.abs() as usize]];
1110 let x_sign = last_mv.x < 0;
1111 let y_sign = last_mv.y < 0;
1113 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);
1115 let blk = &mut self.blocks[saddr + (i & 1) + (i >> 1) * self.mb_w];
1116 blk.mv.x = br.read_cb(x_cb)? as i16;
1118 blk.mv.x = -blk.mv.x;
1120 blk.mv.y = br.read_cb(y_cb)? as i16;
1122 blk.mv.y = -blk.mv.y;
1129 match self.blocks[self.blk_addr[cur_blk] >> 2].btype {
1130 VPMBType::Intra | VPMBType::InterNoMV | VPMBType::GoldenNoMV => {
1133 VPMBType::InterMV => {
1134 let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.abs() as usize]];
1135 let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.abs() as usize]];
1136 let x_sign = last_mv.x < 0;
1137 let y_sign = last_mv.y < 0;
1138 let x = br.read_cb(x_cb)? as i16;
1139 let y = br.read_cb(y_cb)? as i16;
1140 cur_mv = MV { x: if !x_sign { x } else { -x }, y: if !y_sign { y } else { -y } };
1144 VPMBType::InterNearest => {
1147 VPMBType::InterNear => {
1149 std::mem::swap(&mut last_mv, &mut last2_mv);
1152 let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv_g.x.abs() as usize]];
1153 let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv_g.y.abs() as usize]];
1154 let x_sign = last_mv_g.x < 0;
1155 let y_sign = last_mv_g.y < 0;
1156 let x = br.read_cb(x_cb)? as i16;
1157 let y = br.read_cb(y_cb)? as i16;
1158 cur_mv = MV { x: if !x_sign { x } else { -x }, y: if !y_sign { y } else { -y } };
1163 self.blocks[self.blk_addr[cur_blk] >> 2].mv = cur_mv;
1170 Err(DecoderError::Bug)
1173 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<()> {
1174 const VP40_PRED_MASKS: [usize; 16] = [ // top, bottom, left, right
1175 0b1010, 0b1010, 0b1000, 0b1011,
1176 0b1010, 0b1010, 0b0010, 0b1111,
1177 0b0010, 0b1010, 0b0010, 0b0110,
1178 0b0100, 0b0111, 0b1110, 0b1110
1180 self.last_dc = [0; 3];
1181 if let Codes::VP31(ref codes) = self.codes {
1182 let mut coef_eob: [usize; 64] = [0; 64];
1183 for (blkaddr, bsub) in self.blk_addr.iter().zip(self.blk_sub.iter()) {
1184 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
1185 if !blk.coded { continue; }
1186 let mut idx = blkaddr >> 2;
1187 let (bx, by) = if (blkaddr & 3) == 0 {
1188 (idx % (self.mb_w * 2), idx / (self.mb_w * 2))
1190 idx -= self.mb_w * self.mb_h * 4;
1191 if idx >= self.mb_w * self.mb_h {
1192 idx -= self.mb_w * self.mb_h;
1194 (idx % self.mb_w, idx / self.mb_w)
1196 while blk.idx < 64 {
1197 if coef_eob[blk.idx] > 0 {
1198 coef_eob[blk.idx] -= 1;
1202 let cbs = if blk.idx == 0 {
1203 [&codes.dc_cb[dc_table_y], &codes.dc_cb[dc_table_c]]
1204 } else if blk.idx < 6 {
1205 [&codes.ac0_cb[ac_table_y], &codes.ac0_cb[ac_table_c]]
1206 } else if blk.idx < 15 {
1207 [&codes.ac1_cb[ac_table_y], &codes.ac1_cb[ac_table_c]]
1208 } else if blk.idx < 28 {
1209 [&codes.ac2_cb[ac_table_y], &codes.ac2_cb[ac_table_c]]
1211 [&codes.ac3_cb[ac_table_y], &codes.ac3_cb[ac_table_c]]
1213 let cb = if (blkaddr & 3) == 0 { cbs[0] } else { cbs[1] };
1214 let token = br.read_cb(cb)?;
1215 expand_token(blk, br, &mut coef_eob[blk.idx], blk.idx, token)?;
1216 if blk.idx == 64 { break; }
1218 let idx = blkaddr >> 2;
1219 let mask = VP40_PRED_MASKS[*bsub as usize];
1220 if (blkaddr & 3) == 0 {
1221 let pred_dc = self.vp40_predict_dc(bx, by, self.mb_w * 2, self.mb_h * 2, idx, mask, true);
1222 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
1223 blk.coeffs[0] += pred_dc;
1224 self.last_dc[blk.btype.get_ref_id() as usize] = blk.coeffs[0];
1226 let pred_dc = self.vp40_predict_dc(bx, by, self.mb_w, self.mb_h, idx, mask, false);
1227 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
1228 blk.coeffs[0] += pred_dc;
1229 self.last_dc[blk.btype.get_ref_id() as usize] = blk.coeffs[0];
1234 Err(DecoderError::Bug)
1237 fn decode_vp30(&mut self, br: &mut BitReader, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<()> {
1238 for blk in self.blocks.iter_mut() {
1239 blk.coeffs = [0; 64];
1245 for sb in self.sb_info.iter_mut() { *sb = SBState::Coded; }
1246 for blk in self.blocks.iter_mut() {
1247 blk.btype = VPMBType::Intra;
1251 if self.shuf.get_last().is_none() || self.shuf.get_golden().is_none() {
1252 return Err(DecoderError::MissingReference);
1254 self.vp30_unpack_sb_info(br)?;
1255 self.vp30_unpack_mb_info(br)?;
1256 self.vp30_unpack_mv_info(br)?;
1258 let dc_quant = VP30_DC_SCALES[self.quant] * 10;
1259 let ac_quant = VP30_AC_SCALES[self.quant];
1260 rescale_qmat(&mut self.qmat_y, VP3_QMAT_Y, dc_quant, ac_quant, 2);
1261 rescale_qmat(&mut self.qmat_c, VP3_QMAT_C, dc_quant, ac_quant, 2);
1262 rescale_qmat(&mut self.qmat_y_p, VP3_QMAT_INTER, dc_quant, ac_quant, 4);
1263 if self.quant == 10 {
1264 self.qmat_y[29] = 980;
1265 self.qmat_y[58] = 1636;
1266 self.qmat_y[59] = 1964;
1267 } else if self.quant == 31 {
1268 self.qmat_y[58] = 456;
1269 } else if self.quant == 44 {
1270 self.qmat_y[58] = 224;
1272 self.qmat_c_p.copy_from_slice(&self.qmat_y_p);
1274 let table = if ac_quant <= 50 {
1276 } else if ac_quant <= 150 {
1278 } else if ac_quant <= 300 {
1280 } else if ac_quant <= 600 {
1287 self.vp30_unpack_coeffs(br, 0, table)?;
1288 let mut last_dc_i = 0;
1289 let mut last_dc_p = 0;
1290 for blkaddr in self.blk_addr.iter() {
1291 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
1292 if !blk.coded { continue; }
1293 if blk.btype.is_intra() {
1294 blk.coeffs[0] += last_dc_i;
1295 last_dc_i = blk.coeffs[0];
1297 blk.coeffs[0] += last_dc_p;
1298 last_dc_p = blk.coeffs[0];
1302 for coef_no in 1..64 {
1303 self.vp30_unpack_coeffs(br, coef_no, table)?;
1307 self.output_blocks_intra(frm);
1309 self.output_blocks_inter(frm);
1314 fn decode_vp31(&mut self, br: &mut BitReader, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<()> {
1315 for blk in self.blocks.iter_mut() {
1316 blk.coeffs = [0; 64];
1322 for sb in self.sb_info.iter_mut() { *sb = SBState::Coded; }
1323 for blk in self.blocks.iter_mut() {
1324 blk.btype = VPMBType::Intra;
1328 if self.shuf.get_last().is_none() || self.shuf.get_golden().is_none() {
1329 return Err(DecoderError::MissingReference);
1331 self.vp31_unpack_sb_info(br)?;
1332 self.vp31_unpack_mb_info(br)?;
1333 self.vp31_unpack_mv_info(br)?;
1335 let dc_quant = VP31_DC_SCALES[self.quant];
1336 let ac_quant = VP31_AC_SCALES[self.quant];
1337 rescale_qmat(&mut self.qmat_y, VP3_QMAT_Y, dc_quant, ac_quant, 2);
1338 rescale_qmat(&mut self.qmat_c, VP3_QMAT_C, dc_quant, ac_quant, 2);
1339 rescale_qmat(&mut self.qmat_y_p, VP3_QMAT_INTER, dc_quant, ac_quant, 4);
1340 rescale_qmat(&mut self.qmat_c_p, VP3_QMAT_INTER, dc_quant, ac_quant, 4);
1343 let dc_table_y = br.read(4)? as usize;
1344 let dc_table_c = br.read(4)? as usize;
1345 self.vp31_unpack_coeffs(br, 0, dc_table_y, dc_table_c)?;
1348 let ac_table_y = br.read(4)? as usize;
1349 let ac_table_c = br.read(4)? as usize;
1350 for coef_no in 1..64 {
1351 self.vp31_unpack_coeffs(br, coef_no, ac_table_y, ac_table_c)?;
1355 self.output_blocks_intra(frm);
1357 self.output_blocks_inter(frm);
1359 if self.loop_str > 0 {
1360 self.vp31_loop_filter(frm);
1365 fn decode_vp4(&mut self, br: &mut BitReader, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<()> {
1366 for blk in self.blocks.iter_mut() {
1367 blk.coeffs = [0; 64];
1373 for sb in self.sb_info.iter_mut() { *sb = SBState::Coded; }
1374 for blk in self.blocks.iter_mut() {
1375 blk.btype = VPMBType::Intra;
1379 if self.shuf.get_last().is_none() || self.shuf.get_golden().is_none() {
1380 return Err(DecoderError::MissingReference);
1382 self.vp40_unpack_sb_info(br)?;
1383 self.vp31_unpack_mb_info(br)?;
1384 self.vp40_unpack_mv_info(br)?;
1386 let dc_y_quant = VP40_DC_Y_SCALES[self.quant];
1387 let dc_c_quant = VP40_DC_C_SCALES[self.quant];
1388 let ac_quant = VP40_AC_SCALES[self.quant];
1389 rescale_qmat(&mut self.qmat_y, VP40_QMAT, dc_y_quant, ac_quant, 2);
1390 rescale_qmat(&mut self.qmat_c, VP40_QMAT, dc_c_quant, ac_quant, 2);
1391 self.qmat_y_p.copy_from_slice(&self.qmat_y);
1392 self.qmat_c_p.copy_from_slice(&self.qmat_c);
1395 let dc_table_y = br.read(4)? as usize;
1396 let dc_table_c = br.read(4)? as usize;
1397 let ac_table_y = br.read(4)? as usize;
1398 let ac_table_c = br.read(4)? as usize;
1399 self.vp40_unpack_coeffs(br, dc_table_y, dc_table_c, ac_table_y, ac_table_c)?;
1402 self.output_blocks_intra(frm);
1404 self.output_blocks_inter(frm);
1409 fn vp31_predict_dc(&self, bx: usize, by: usize, bw: usize, blk_idx: usize) -> i16 {
1410 let mut preds = [0i32; 4];
1411 let mut pp: usize = 0;
1412 let ref_id = self.blocks[blk_idx].btype.get_ref_id();
1413 let is_right = bx == bw - 1;
1415 fill_dc_pred!(self, ref_id, preds, pp, 0, blk_idx - 1);
1417 fill_dc_pred!(self, ref_id, preds, pp, 1, blk_idx - 1 - bw);
1421 fill_dc_pred!(self, ref_id, preds, pp, 2, blk_idx - bw);
1423 fill_dc_pred!(self, ref_id, preds, pp, 3, blk_idx + 1 - bw);
1426 if pp == 0 { return self.last_dc[ref_id as usize]; }
1427 let mut pred = 0i32;
1429 if (pp & (1 << i)) != 0 {
1430 pred += (preds[i] as i32) * (VP31_DC_WEIGHTS[pp][i] as i32);
1433 pred /= VP31_DC_WEIGHTS[pp][4] as i32;
1435 if (pred - preds[2]).abs() > 128 { return preds[2] as i16; }
1436 if (pred - preds[0]).abs() > 128 { return preds[0] as i16; }
1437 if (pred - preds[1]).abs() > 128 { return preds[1] as i16; }
1441 fn vp40_predict_dc(&self, bx: usize, by: usize, bw: usize, bh: usize, blk_idx: usize, mask: usize, is_luma: bool) -> i16 {
1442 let mut preds = [0i32; 4];
1443 let mut pp: usize = 0;
1444 let ref_id = self.blocks[blk_idx].btype.get_ref_id();
1445 if (by > 0) && (((mask >> 3) & 1) == 1) { //top
1446 fill_dc_pred!(self, ref_id, preds, pp, 0, blk_idx - bw);
1448 if (by < bh - 1) && (((mask >> 2) & 1) == 1) { //bottom
1449 fill_dc_pred!(self, ref_id, preds, pp, 1, blk_idx + bw);
1451 if (bx > 0) && (((mask >> 1) & 1) == 1) { //left
1452 fill_dc_pred!(self, ref_id, preds, pp, 2, blk_idx - 1);
1454 if (is_luma && bx == 0 && (by >= 4)) && (((mask >> 1) & 1) == 1) { //left wrap
1455 fill_dc_pred!(self, ref_id, preds, pp, 2, blk_idx - 1 - 3 * bw);
1457 if (bx < bw - 1) && (((mask >> 0) & 1) == 1) { //right
1458 fill_dc_pred!(self, ref_id, preds, pp, 3, blk_idx + 1);
1460 if pp == 0 { return self.last_dc[ref_id as usize]; }
1461 let mut pred = 0i32;
1464 if (pp & (1 << i)) != 0 {
1465 pred += preds[i] as i32;
1468 return (pred / 2) as i16;
1472 self.last_dc[ref_id as usize]
1474 fn restore_dcs(&mut self) {
1475 let blk_stride = self.mb_w * 2;
1476 let mut blk_idx = 0;
1477 self.last_dc = [0; 3];
1478 for by in 0..self.mb_h*2 {
1479 for bx in 0..self.mb_w*2 {
1480 if !self.blocks[blk_idx + bx].coded { continue; }
1481 let dc = self.vp31_predict_dc(bx, by, self.mb_w*2, blk_idx + bx);
1482 self.blocks[blk_idx + bx].coeffs[0] += dc;
1483 self.last_dc[self.blocks[blk_idx + bx].btype.get_ref_id() as usize] = self.blocks[blk_idx + bx].coeffs[0];
1485 blk_idx += blk_stride;
1487 let blk_stride = self.mb_w;
1488 for _plane in 1..3 {
1489 self.last_dc = [0; 3];
1490 for by in 0..self.mb_h {
1491 for bx in 0..self.mb_w {
1492 if !self.blocks[blk_idx + bx].coded { continue; }
1493 let dc = self.vp31_predict_dc(bx, by, self.mb_w, blk_idx + bx);
1494 self.blocks[blk_idx + bx].coeffs[0] += dc;
1495 self.last_dc[self.blocks[blk_idx + bx].btype.get_ref_id() as usize] = self.blocks[blk_idx + bx].coeffs[0];
1497 blk_idx += blk_stride;
1501 fn output_blocks_intra(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
1502 let mut biter = self.blocks.iter_mut();
1503 for by in 0..self.mb_h*2 {
1504 for bx in 0..self.mb_w*2 {
1505 let mut blk = biter.next().unwrap();
1506 let qmat = &self.qmat_y;
1507 blk.coeffs[0] *= qmat[0];
1509 unquant(&mut blk.coeffs, qmat);
1510 vp_put_block(&mut blk.coeffs, bx, by, 0, frm);
1512 vp_put_block_dc(&mut blk.coeffs, bx, by, 0, frm);
1517 for by in 0..self.mb_h {
1518 for bx in 0..self.mb_w {
1519 let mut blk = biter.next().unwrap();
1520 let qmat = &self.qmat_c;
1521 blk.coeffs[0] *= qmat[0];
1523 unquant(&mut blk.coeffs, qmat);
1524 vp_put_block(&mut blk.coeffs, bx, by, plane, frm);
1526 vp_put_block_dc(&mut blk.coeffs, bx, by, plane, frm);
1532 fn output_blocks_inter(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
1533 let mut blk_idx = 0;
1534 let bstride = self.mb_w * 2;
1535 for by in (0..self.mb_h*2).step_by(2) {
1536 for bx in (0..self.mb_w*2).step_by(2) {
1537 if self.blocks[blk_idx + bx].btype != VPMBType::InterFourMV {
1540 let mv_a = self.blocks[blk_idx + bx].mv;
1541 let mv_b = self.blocks[blk_idx + bx + 1].mv;
1542 let mv_c = self.blocks[blk_idx + bx + bstride].mv;
1543 let mv_d = self.blocks[blk_idx + bx + 1 + bstride].mv;
1544 let mut mv_sum = mv_a + mv_b + mv_c + mv_d;
1545 mv_sum.x = (mv_sum.x + 2) >> 2;
1546 mv_sum.y = (mv_sum.y + 2) >> 2;
1548 let src = self.shuf.get_last().unwrap();
1549 let mode = ((mv_a.x & 1) + (mv_a.y & 1) * 2) as usize;
1550 if self.version != 4 {
1551 copy_block(frm, src.clone(), 0, bx * 8, by * 8,
1552 mv_a.x >> 1, mv_a.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1554 vp_copy_block(frm, src.clone(), 0, bx * 8, by * 8,
1555 mv_a.x >> 1, mv_a.y >> 1, 0, 1, self.loop_str,
1556 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1558 let mode = ((mv_b.x & 1) + (mv_b.y & 1) * 2) as usize;
1559 if self.version != 4 {
1560 copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8,
1561 mv_b.x >> 1, mv_b.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1563 vp_copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8,
1564 mv_b.x >> 1, mv_b.y >> 1, 0, 1, self.loop_str,
1565 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1567 let mode = ((mv_c.x & 1) + (mv_c.y & 1) * 2) as usize;
1568 if self.version != 4 {
1569 copy_block(frm, src.clone(), 0, bx * 8, by * 8 + 8,
1570 mv_c.x >> 1, mv_c.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1572 vp_copy_block(frm, src.clone(), 0, bx * 8, by * 8 + 8,
1573 mv_c.x >> 1, mv_c.y >> 1, 0, 1, self.loop_str,
1574 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1576 let mode = ((mv_d.x & 1) + (mv_d.y & 1) * 2) as usize;
1577 if self.version != 4 {
1578 copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8 + 8,
1579 mv_d.x >> 1, mv_d.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1581 vp_copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8 + 8,
1582 mv_d.x >> 1, mv_d.y >> 1, 0, 1, self.loop_str,
1583 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1586 let mx = (mv_sum.x >> 1) | (mv_sum.x & 1);
1587 let my = (mv_sum.y >> 1) | (mv_sum.y & 1);
1588 let mode = ((mx & 1) + (my & 1) * 2) as usize;
1589 copy_block(frm, src.clone(), 1, bx * 4, by * 4, mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1590 copy_block(frm, src.clone(), 2, bx * 4, by * 4, mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1592 blk_idx += bstride * 2;
1595 let mut biter = self.blocks.iter_mut();
1596 for by in 0..self.mb_h*2 {
1597 for bx in 0..self.mb_w*2 {
1598 let mut blk = biter.next().unwrap();
1599 // do MC for whole macroblock
1600 if !blk.btype.is_intra() && (((bx | by) & 1) == 0) && (blk.btype != VPMBType::InterFourMV) {
1601 let src = if blk.btype.get_ref_id() == 1 {
1602 self.shuf.get_last().unwrap()
1604 self.shuf.get_golden().unwrap()
1606 let mode = ((blk.mv.x & 1) + (blk.mv.y & 1) * 2) as usize;
1607 if self.version != 4 {
1608 copy_block(frm, src.clone(), 0, bx * 8, by * 8,
1609 blk.mv.x >> 1, blk.mv.y >> 1, 16, 16, 0, 1, mode, VP3_INTERP_FUNCS);
1611 vp_copy_block(frm, src.clone(), 0, bx * 8, by * 8,
1612 blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str,
1613 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1614 vp_copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8,
1615 blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str,
1616 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1617 vp_copy_block(frm, src.clone(), 0, bx * 8, by * 8 + 8,
1618 blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str,
1619 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1620 vp_copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8 + 8,
1621 blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str,
1622 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1624 let mx = (blk.mv.x >> 1) | (blk.mv.x & 1);
1625 let my = (blk.mv.y >> 1) | (blk.mv.y & 1);
1626 let mode = ((mx & 1) + (my & 1) * 2) as usize;
1627 if self.version != 4 {
1628 copy_block(frm, src.clone(), 1, bx * 4, by * 4,
1629 mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1630 copy_block(frm, src.clone(), 2, bx * 4, by * 4,
1631 mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1633 vp_copy_block(frm, src.clone(), 1, bx * 4, by * 4,
1634 mx >> 1, my >> 1, 0, 1, self.loop_str,
1635 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1636 vp_copy_block(frm, src.clone(), 2, bx * 4, by * 4,
1637 mx >> 1, my >> 1, 0, 1, self.loop_str,
1638 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1641 let qmat = if blk.btype.is_intra() { &self.qmat_y } else { &self.qmat_y_p };
1642 blk.coeffs[0] *= qmat[0];
1644 unquant(&mut blk.coeffs, qmat);
1646 if blk.btype.is_intra() {
1648 copy_block(frm, self.shuf.get_last().unwrap(), 0, bx * 8, by * 8, 0, 0, 8, 8, 0, 1, 0, VP3_INTERP_FUNCS);
1649 } else if blk.has_ac {
1650 vp_put_block(&mut blk.coeffs, bx, by, 0, frm);
1652 vp_put_block_dc(&mut blk.coeffs, bx, by, 0, frm);
1654 } else if blk.coded {
1656 vp_add_block(&mut blk.coeffs, bx, by, 0, frm);
1658 vp_add_block_dc(&mut blk.coeffs, bx, by, 0, frm);
1664 for by in 0..self.mb_h {
1665 for bx in 0..self.mb_w {
1666 let mut blk = biter.next().unwrap();
1667 let qmat = if blk.btype.is_intra() { &self.qmat_c } else { &self.qmat_c_p };
1668 blk.coeffs[0] *= qmat[0];
1670 unquant(&mut blk.coeffs, qmat);
1672 if blk.btype.is_intra() {
1674 copy_block(frm, self.shuf.get_last().unwrap(), plane, bx * 8, by * 8, 0, 0, 8, 8, 0, 1, 0, VP3_INTERP_FUNCS);
1675 } else if blk.has_ac {
1676 vp_put_block(&mut blk.coeffs, bx, by, plane, frm);
1678 vp_put_block_dc(&mut blk.coeffs, bx, by, plane, frm);
1680 } else if blk.coded {
1682 vp_add_block(&mut blk.coeffs, bx, by, plane, frm);
1684 vp_add_block_dc(&mut blk.coeffs, bx, by, plane, frm);
1691 fn vp31_loop_filter(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
1692 let mut blk_idx = 0;
1693 let blk_w = self.mb_w * 2;
1694 for by in 0..self.mb_h*2 {
1695 for bx in 0..blk_w {
1696 let blk = &self.blocks[blk_idx + bx];
1697 if (bx > 0) && blk.coded {
1698 vp31_loop_filter_v(frm, bx * 8, by * 8, 0, self.loop_str);
1700 if (by > 0) && blk.coded {
1701 vp31_loop_filter_h(frm, bx * 8, by * 8, 0, self.loop_str);
1703 if (bx < blk_w - 1) && !self.blocks[blk_idx + bx + 1].coded {
1704 vp31_loop_filter_v(frm, bx * 8 + 8, by * 8, 0, self.loop_str);
1706 if (by < self.mb_h * 2 - 1) && !self.blocks[blk_idx + bx + blk_w].coded {
1707 vp31_loop_filter_h(frm, bx * 8, by * 8 + 8, 0, self.loop_str);
1712 /* for plane in 1..3 {
1713 for by in 0..self.mb_h {
1714 for bx in 0..self.mb_w {
1719 fn generate_block_addr(&mut self) {
1720 let sb_w_y = (self.width + 31) >> 5;
1721 let sb_h_y = (self.height + 31) >> 5;
1722 let sb_w_c = ((self.width >> 1) + 31) >> 5;
1723 let sb_h_c = ((self.height >> 1) + 31) >> 5;
1724 self.y_sbs = sb_w_y * sb_h_y;
1725 let tot_sb = sb_w_y * sb_h_y + 2 * sb_w_c * sb_h_c;
1726 let tot_mb = self.mb_w * self.mb_h * 2 + ((self.mb_w + 1) & !1) * ((self.mb_h + 1) & !1) * 2;
1727 let bw = self.width >> 3;
1728 let bh = self.height >> 3;
1729 let tot_blk = bw * bh * 3 / 2;
1730 self.sb_info.resize(tot_sb, SBState::Uncoded);
1731 self.sb_blocks = Vec::with_capacity(tot_sb);
1732 self.mb_blocks = Vec::with_capacity(tot_mb);
1733 self.sb_mbs = Vec::with_capacity(tot_sb);
1734 self.blk_addr = Vec::with_capacity(tot_blk);
1735 self.blk_sub = Vec::with_capacity(tot_blk);
1736 self.y_blocks = bw * bh;
1737 let mut base_idx = 0;
1739 let w = if plane > 0 { self.width >> 1 } else { self.width };
1740 let h = if plane > 0 { self.height >> 1 } else { self.height };
1741 let sb_w = (w + 31) >> 5;
1742 let sb_h = (h + 31) >> 5;
1749 let bx = x * 4 + HILBERT_ORDER[mb_no * 4][0];
1750 let by = y * 4 + HILBERT_ORDER[mb_no * 4][1];
1751 if (bx >= blk_w) || (by >= blk_h) { continue; }
1752 let mut nblocks = 0;
1753 for blk_no in 0..4 {
1754 let bx = x * 4 + HILBERT_ORDER[mb_no * 4 + blk_no][0];
1755 let by = y * 4 + HILBERT_ORDER[mb_no * 4 + blk_no][1];
1756 if (bx >= blk_w) || (by >= blk_h) { continue; }
1759 self.mb_blocks.push(nblocks);
1762 self.sb_mbs.push(nmbs);
1764 let mut nblocks = 0;
1765 for blk_no in 0..16 {
1766 let bx = x * 4 + HILBERT_ORDER[blk_no][0];
1767 let by = y * 4 + HILBERT_ORDER[blk_no][1];
1768 if (bx >= blk_w) || (by >= blk_h) { continue; }
1769 let idx = base_idx + bx + by * blk_w;
1770 self.blk_addr.push(idx * 4 + plane);
1771 self.blk_sub.push(blk_no as u8);
1774 self.sb_blocks.push(nblocks);
1777 base_idx += blk_w * blk_h;
1779 self.blocks.resize(tot_blk, Block::new());
1780 self.mb_coded.resize(tot_mb, false);
1781 self.mb_partial.resize(tot_mb, false);
1785 impl NADecoder for VP34Decoder {
1786 fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
1787 if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
1788 let fmt = YUV420_FORMAT;
1789 self.width = vinfo.get_width();
1790 self.height = vinfo.get_height();
1791 validate!(((self.width | self.height) & 15) == 0);
1792 self.mb_w = self.width >> 4;
1793 self.mb_h = self.height >> 4;
1794 let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), true, fmt));
1795 self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
1796 supp.pool_u8.set_dec_bufs(3);
1797 supp.pool_u8.prealloc_video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt), 4)?;
1799 self.generate_block_addr();
1800 if self.version == 4 {
1801 self.codes = Codes::VP31(VP31Codes::new_vp4());
1802 self.aux_codes = Some(VP40AuxCodes::new());
1806 Err(DecoderError::InvalidData)
1809 fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
1810 let src = pkt.get_buffer();
1811 validate!(src.len() > 0);
1812 let mut br = BitReader::new(&src, src.len(), BitReaderMode::BE);
1814 self.parse_header(&mut br)?;
1818 if !self.shuf.has_refs() {
1819 return Err(DecoderError::MissingReference);
1823 let ret = supp.pool_u8.get_free();
1825 return Err(DecoderError::AllocError);
1827 let mut buf = ret.unwrap();
1828 let mut dframe = NASimpleVideoFrame::from_video_buf(&mut buf).unwrap();
1829 match self.version {
1830 30 => self.decode_vp30(&mut br, &mut dframe)?,
1831 31 => self.decode_vp31(&mut br, &mut dframe)?,
1832 4 => self.decode_vp4(&mut br, &mut dframe)?,
1833 _ => return Err(DecoderError::Bug),
1837 self.shuf.add_golden_frame(buf.clone());
1839 self.shuf.add_frame(buf.clone());
1841 let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), NABufferType::Video(buf));
1842 frm.set_keyframe(self.is_intra);
1843 frm.set_frame_type(if self.is_intra { FrameType::I } else { FrameType::P });
1846 fn flush(&mut self) {
1851 pub fn get_decoder_vp3() -> Box<NADecoder> {
1852 Box::new(VP34Decoder::new(3))
1855 pub fn get_decoder_vp4() -> Box<NADecoder> {
1856 Box::new(VP34Decoder::new(4))
1861 use nihav_core::codecs::RegisteredDecoders;
1862 use nihav_core::demuxers::RegisteredDemuxers;
1863 use nihav_core::test::dec_video::*;
1864 use crate::codecs::duck_register_all_codecs;
1865 use nihav_commonfmt::demuxers::generic_register_all_demuxers;
1869 let mut dmx_reg = RegisteredDemuxers::new();
1870 generic_register_all_demuxers(&mut dmx_reg);
1871 let mut dec_reg = RegisteredDecoders::new();
1872 duck_register_all_codecs(&mut dec_reg);
1874 let file = "assets/Duck/vp30-logo.avi";
1875 test_file_decoding("avi", file, Some(23), true, false, None/*Some("vp30")*/, &dmx_reg, &dec_reg);
1880 let mut dmx_reg = RegisteredDemuxers::new();
1881 generic_register_all_demuxers(&mut dmx_reg);
1882 let mut dec_reg = RegisteredDecoders::new();
1883 duck_register_all_codecs(&mut dec_reg);
1885 let file = "assets/Duck/vp31.avi";
1886 // let file = "assets/Duck/vp31_crash.avi";
1887 // let file = "assets/Duck/01-vp31-0500.avi";
1888 test_file_decoding("avi", file, Some(3), true, false, None/*Some("vp31")*/, &dmx_reg, &dec_reg);
1894 let mut dmx_reg = RegisteredDemuxers::new();
1895 generic_register_all_demuxers(&mut dmx_reg);
1896 let mut dec_reg = RegisteredDecoders::new();
1897 duck_register_all_codecs(&mut dec_reg);
1899 let file = "assets/Duck/ot171_vp40.avi";
1900 test_file_decoding("avi", file, Some(16), true, false, None/*Some("vp4")*/, &dmx_reg, &dec_reg);
1905 const HILBERT_ORDER: [[usize; 2]; 16] = [
1906 [ 0, 0 ], [ 1, 0 ], [ 1, 1 ], [ 0, 1 ],
1907 [ 0, 2 ], [ 0, 3 ], [ 1, 3 ], [ 1, 2 ],
1908 [ 2, 2 ], [ 2, 3 ], [ 3, 3 ], [ 3, 2 ],
1909 [ 3, 1 ], [ 2, 1 ], [ 2, 0 ], [ 3, 0 ]
1912 const VP31_LOOP_STRENGTH: [i16; 64] = [
1913 30, 25, 20, 20, 15, 15, 14, 14,
1914 13, 13, 12, 12, 11, 11, 10, 10,
1915 9, 9, 8, 8, 7, 7, 7, 7,
1916 6, 6, 6, 6, 5, 5, 5, 5,
1917 4, 4, 4, 4, 3, 3, 3, 3,
1918 2, 2, 2, 2, 2, 2, 2, 2,
1919 0, 0, 0, 0, 0, 0, 0, 0,
1920 0, 0, 0, 0, 0, 0, 0, 0
1923 const VP31_DEFAULT_MB_MODES: [VPMBType; 8] = [
1924 VPMBType::InterNoMV, VPMBType::Intra, VPMBType::InterMV, VPMBType::InterNearest,
1925 VPMBType::InterNear, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1928 const VP31_MB_MODES: [[VPMBType; 8]; 6] = [
1930 VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterMV, VPMBType::InterNoMV,
1931 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1933 VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterNoMV, VPMBType::InterMV,
1934 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1936 VPMBType::InterNearest, VPMBType::InterMV, VPMBType::InterNear, VPMBType::InterNoMV,
1937 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1939 VPMBType::InterNearest, VPMBType::InterMV, VPMBType::InterNoMV, VPMBType::InterNear,
1940 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1942 VPMBType::InterNoMV, VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterMV,
1943 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1945 VPMBType::InterNoMV, VPMBType::GoldenNoMV, VPMBType::InterNearest, VPMBType::InterNear,
1946 VPMBType::InterMV, VPMBType::Intra, VPMBType::GoldenMV, VPMBType::InterFourMV
1950 const VP3_LITERAL_BASE: [i16; 6] = [ 7, 9, 13, 21, 37, 69 ];
1952 const VP31_AC_SCALES: [i16; 64] = [
1953 500, 450, 400, 370, 340, 310, 285, 265,
1954 245, 225, 210, 195, 185, 180, 170, 160,
1955 150, 145, 135, 130, 125, 115, 110, 107,
1956 100, 96, 93, 89, 85, 82, 75, 74,
1957 70, 68, 64, 60, 57, 56, 52, 50,
1958 49, 45, 44, 43, 40, 38, 37, 35,
1959 33, 32, 30, 29, 28, 25, 24, 22,
1960 21, 19, 18, 17, 15, 13, 12, 10
1963 const VP31_DC_SCALES: [i16; 64] = [
1964 220, 200, 190, 180, 170, 170, 160, 160,
1965 150, 150, 140, 140, 130, 130, 120, 120,
1966 110, 110, 100, 100, 90, 90, 90, 80,
1967 80, 80, 70, 70, 70, 60, 60, 60,
1968 60, 50, 50, 50, 50, 40, 40, 40,
1969 40, 40, 30, 30, 30, 30, 30, 30,
1970 30, 20, 20, 20, 20, 20, 20, 20,
1971 20, 10, 10, 10, 10, 10, 10, 10
1974 const VP3_QMAT_Y: &[i16; 64] = &[
1975 16, 11, 10, 16, 24, 40, 51, 61,
1976 12, 12, 14, 19, 26, 58, 60, 55,
1977 14, 13, 16, 24, 40, 57, 69, 56,
1978 14, 17, 22, 29, 51, 87, 80, 62,
1979 18, 22, 37, 58, 68, 109, 103, 77,
1980 24, 35, 55, 64, 81, 104, 113, 92,
1981 49, 64, 78, 87, 103, 121, 120, 101,
1982 72, 92, 95, 98, 112, 100, 103, 99
1985 const VP3_QMAT_C: &[i16; 64] = &[
1986 17, 18, 24, 47, 99, 99, 99, 99,
1987 18, 21, 26, 66, 99, 99, 99, 99,
1988 24, 26, 56, 99, 99, 99, 99, 99,
1989 47, 66, 99, 99, 99, 99, 99, 99,
1990 99, 99, 99, 99, 99, 99, 99, 99,
1991 99, 99, 99, 99, 99, 99, 99, 99,
1992 99, 99, 99, 99, 99, 99, 99, 99,
1993 99, 99, 99, 99, 99, 99, 99, 99
1996 const VP3_QMAT_INTER: &[i16; 64] = &[
1997 16, 16, 16, 20, 24, 28, 32, 40,
1998 16, 16, 20, 24, 28, 32, 40, 48,
1999 16, 20, 24, 28, 32, 40, 48, 64,
2000 20, 24, 28, 32, 40, 48, 64, 64,
2001 24, 28, 32, 40, 48, 64, 64, 64,
2002 28, 32, 40, 48, 64, 64, 64, 96,
2003 32, 40, 48, 64, 64, 64, 96, 128,
2004 40, 48, 64, 64, 64, 96, 128, 128
2007 const VP31_DC_CODES: [[u16; 32]; 16] = [
2009 0x002D, 0x0026, 0x0166, 0x004E, 0x02CE, 0x059E, 0x027D, 0x0008,
2010 0x04F9, 0x000F, 0x000E, 0x001B, 0x0006, 0x0008, 0x0005, 0x001A,
2011 0x0015, 0x0007, 0x000C, 0x0001, 0x0000, 0x0009, 0x0017, 0x0029,
2012 0x0028, 0x00B2, 0x04F8, 0x059F, 0x009E, 0x013F, 0x0012, 0x0058,
2014 0x0010, 0x0047, 0x01FF, 0x008C, 0x03FC, 0x046A, 0x0469, 0x0022,
2015 0x11A1, 0x000E, 0x000D, 0x0004, 0x0005, 0x0009, 0x0006, 0x001E,
2016 0x0016, 0x0007, 0x000C, 0x0001, 0x0000, 0x000A, 0x0017, 0x007D,
2017 0x007E, 0x011B, 0x08D1, 0x03FD, 0x046B, 0x11A0, 0x007C, 0x00FE,
2019 0x0016, 0x0020, 0x0086, 0x0087, 0x0367, 0x06CC, 0x06CB, 0x006E,
2020 0x366D, 0x000F, 0x000E, 0x0004, 0x0005, 0x000A, 0x0006, 0x001A,
2021 0x0011, 0x0007, 0x000C, 0x0001, 0x0000, 0x0009, 0x0017, 0x006F,
2022 0x006D, 0x0364, 0x0D9A, 0x06CA, 0x1B37, 0x366C, 0x0042, 0x00D8,
2024 0x0000, 0x002D, 0x00F7, 0x0058, 0x0167, 0x02CB, 0x02CA, 0x000E,
2025 0x1661, 0x0003, 0x0002, 0x0008, 0x0009, 0x000D, 0x0002, 0x001F,
2026 0x0017, 0x0001, 0x000C, 0x000E, 0x000A, 0x0006, 0x0078, 0x000F,
2027 0x007A, 0x0164, 0x0599, 0x02CD, 0x0B31, 0x1660, 0x0079, 0x00F6,
2029 0x0003, 0x003C, 0x000F, 0x007A, 0x001D, 0x0020, 0x0072, 0x0006,
2030 0x0399, 0x0004, 0x0005, 0x0005, 0x0006, 0x000E, 0x0004, 0x0000,
2031 0x0019, 0x0002, 0x000D, 0x0007, 0x001F, 0x0030, 0x0011, 0x0031,
2032 0x0005, 0x0021, 0x00E7, 0x0038, 0x01CD, 0x0398, 0x007B, 0x0009,
2034 0x0009, 0x0002, 0x0074, 0x0007, 0x00EC, 0x00D1, 0x01A6, 0x0006,
2035 0x0D21, 0x0005, 0x0006, 0x0008, 0x0007, 0x000F, 0x0004, 0x0000,
2036 0x001C, 0x0002, 0x0005, 0x0003, 0x000C, 0x0035, 0x01A7, 0x001B,
2037 0x0077, 0x01A5, 0x0349, 0x00D0, 0x0691, 0x0D20, 0x0075, 0x00ED,
2039 0x000A, 0x000C, 0x0012, 0x001B, 0x00B7, 0x016C, 0x0099, 0x005A,
2040 0x16D8, 0x0007, 0x0006, 0x0009, 0x0008, 0x0000, 0x0005, 0x0017,
2041 0x000E, 0x0002, 0x0003, 0x000F, 0x001A, 0x004D, 0x2DB3, 0x002C,
2042 0x0011, 0x02DA, 0x05B7, 0x0098, 0x0B6D, 0x2DB2, 0x0010, 0x0027,
2044 0x000D, 0x000F, 0x001D, 0x0008, 0x0051, 0x0056, 0x00AF, 0x002A,
2045 0x148A, 0x0007, 0x0000, 0x0008, 0x0009, 0x000C, 0x0006, 0x0017,
2046 0x000B, 0x0016, 0x0015, 0x0009, 0x0050, 0x00AE, 0x2917, 0x001C,
2047 0x0014, 0x0290, 0x0523, 0x0149, 0x0A44, 0x2916, 0x0053, 0x00A5,
2049 0x0001, 0x001D, 0x00F5, 0x00F4, 0x024D, 0x0499, 0x0498, 0x0001,
2050 0x0021, 0x0006, 0x0005, 0x0006, 0x0005, 0x0002, 0x0007, 0x0025,
2051 0x007B, 0x001C, 0x0020, 0x000D, 0x0048, 0x0092, 0x0127, 0x000E,
2052 0x0004, 0x0011, 0x000C, 0x003C, 0x000F, 0x0000, 0x001F, 0x0013,
2054 0x0005, 0x003C, 0x0040, 0x000D, 0x0031, 0x0061, 0x0060, 0x0002,
2055 0x00F5, 0x0006, 0x0005, 0x0007, 0x0006, 0x0002, 0x0009, 0x0025,
2056 0x0007, 0x0021, 0x0024, 0x0010, 0x0041, 0x00F4, 0x0019, 0x000E,
2057 0x0003, 0x0011, 0x0011, 0x003F, 0x003E, 0x007B, 0x0000, 0x0013,
2059 0x000A, 0x0007, 0x0001, 0x0009, 0x0131, 0x0261, 0x0260, 0x0015,
2060 0x0001, 0x0007, 0x0006, 0x0008, 0x0007, 0x0006, 0x0012, 0x002F,
2061 0x0014, 0x0027, 0x002D, 0x0016, 0x004D, 0x0099, 0x0000, 0x0004,
2062 0x0001, 0x0005, 0x0017, 0x002E, 0x002C, 0x0008, 0x0006, 0x0001,
2064 0x0000, 0x000E, 0x0017, 0x002A, 0x0010, 0x00F9, 0x00F8, 0x001E,
2065 0x003F, 0x0007, 0x0006, 0x0009, 0x0008, 0x0006, 0x000F, 0x0005,
2066 0x0016, 0x0029, 0x002B, 0x0015, 0x0050, 0x0011, 0x007D, 0x0004,
2067 0x0017, 0x0006, 0x0014, 0x002C, 0x002D, 0x000E, 0x0009, 0x0051,
2069 0x0002, 0x0018, 0x002F, 0x000D, 0x0053, 0x0295, 0x0294, 0x00A4,
2070 0x007C, 0x0000, 0x0007, 0x0009, 0x0008, 0x001B, 0x000C, 0x0028,
2071 0x006A, 0x001E, 0x001D, 0x0069, 0x00D7, 0x007D, 0x014B, 0x0019,
2072 0x0016, 0x002E, 0x001C, 0x002B, 0x002A, 0x0068, 0x003F, 0x00D6,
2074 0x0002, 0x001B, 0x000C, 0x0018, 0x0029, 0x007F, 0x02F0, 0x0198,
2075 0x0179, 0x0000, 0x0007, 0x0009, 0x0008, 0x001A, 0x000D, 0x002A,
2076 0x0064, 0x001E, 0x0067, 0x005F, 0x00CD, 0x007E, 0x02F1, 0x0016,
2077 0x000E, 0x002E, 0x0065, 0x002B, 0x0028, 0x003E, 0x00BD, 0x0199,
2079 0x0002, 0x0007, 0x0016, 0x0006, 0x0036, 0x005C, 0x015D, 0x015C,
2080 0x02BF, 0x0000, 0x0007, 0x0009, 0x0008, 0x0018, 0x0034, 0x002A,
2081 0x005E, 0x006A, 0x0064, 0x005D, 0x00CB, 0x00AD, 0x02BE, 0x0014,
2082 0x0033, 0x006E, 0x005F, 0x006F, 0x006B, 0x00CA, 0x00AC, 0x015E,
2084 0x000F, 0x001D, 0x0018, 0x000B, 0x0019, 0x0029, 0x00D6, 0x0551,
2085 0x0AA1, 0x0001, 0x0000, 0x0009, 0x0008, 0x001B, 0x0038, 0x0028,
2086 0x0057, 0x006A, 0x0068, 0x0056, 0x00E5, 0x0155, 0x0AA0, 0x0073,
2087 0x0069, 0x00D7, 0x00AB, 0x00E4, 0x00A9, 0x0151, 0x0150, 0x02A9,
2091 const VP31_DC_BITS: [[u8; 32]; 16] = [
2093 6, 7, 9, 8, 10, 11, 11, 5, 12, 4, 4, 5, 4, 4, 4, 5,
2094 5, 4, 4, 3, 3, 4, 5, 6, 6, 8, 12, 11, 9, 10, 6, 7,
2096 5, 7, 9, 8, 10, 11, 11, 6, 13, 4, 4, 4, 4, 4, 4, 5,
2097 5, 4, 4, 3, 3, 4, 5, 7, 7, 9, 12, 10, 11, 13, 7, 8,
2099 5, 6, 8, 8, 10, 11, 11, 7, 14, 4, 4, 4, 4, 4, 4, 5,
2100 5, 4, 4, 3, 3, 4, 5, 7, 7, 10, 12, 11, 13, 14, 7, 8,
2102 4, 6, 8, 7, 9, 10, 10, 6, 13, 3, 3, 4, 4, 4, 4, 5,
2103 5, 4, 4, 4, 4, 5, 7, 6, 7, 9, 11, 10, 12, 13, 7, 8,
2105 4, 6, 7, 7, 8, 9, 10, 6, 13, 3, 3, 4, 4, 4, 4, 4,
2106 5, 4, 4, 4, 5, 6, 8, 6, 6, 9, 11, 9, 12, 13, 7, 7,
2108 4, 5, 7, 6, 8, 9, 10, 6, 13, 3, 3, 4, 4, 4, 4, 4,
2109 5, 4, 4, 4, 5, 7, 10, 6, 7, 10, 11, 9, 12, 13, 7, 8,
2111 4, 5, 6, 6, 8, 9, 9, 7, 13, 3, 3, 4, 4, 3, 4, 5,
2112 5, 4, 4, 5, 6, 8, 14, 6, 6, 10, 11, 9, 12, 14, 6, 7,
2114 4, 5, 6, 5, 7, 8, 9, 7, 13, 3, 2, 4, 4, 4, 4, 5,
2115 5, 5, 5, 5, 7, 9, 14, 6, 6, 10, 11, 9, 12, 14, 7, 8,
2117 4, 6, 8, 8, 10, 11, 11, 5, 6, 3, 3, 4, 4, 4, 5, 6,
2118 7, 6, 6, 6, 7, 8, 9, 4, 4, 5, 6, 6, 5, 5, 5, 5,
2120 4, 6, 7, 7, 9, 10, 10, 5, 8, 3, 3, 4, 4, 4, 5, 6,
2121 6, 6, 6, 6, 7, 8, 8, 4, 4, 5, 6, 6, 6, 7, 4, 5,
2123 4, 5, 6, 6, 9, 10, 10, 6, 7, 3, 3, 4, 4, 4, 5, 6,
2124 6, 6, 6, 6, 7, 8, 7, 4, 4, 5, 6, 6, 6, 6, 5, 5,
2126 3, 5, 6, 6, 7, 10, 10, 7, 8, 3, 3, 4, 4, 4, 5, 5,
2127 6, 6, 6, 6, 7, 7, 9, 4, 5, 5, 6, 6, 6, 6, 6, 7,
2129 3, 5, 6, 5, 7, 10, 10, 8, 8, 2, 3, 4, 4, 5, 5, 6,
2130 7, 6, 6, 7, 8, 8, 9, 5, 5, 6, 6, 6, 6, 7, 7, 8,
2132 3, 5, 5, 5, 6, 8, 10, 9, 9, 2, 3, 4, 4, 5, 5, 6,
2133 7, 6, 7, 7, 8, 8, 10, 5, 5, 6, 7, 6, 6, 7, 8, 9,
2135 3, 4, 5, 4, 6, 7, 9, 9, 10, 2, 3, 4, 4, 5, 6, 6,
2136 7, 7, 7, 7, 8, 8, 10, 5, 6, 7, 7, 7, 7, 8, 8, 9,
2138 4, 5, 5, 4, 5, 6, 8, 11, 12, 2, 2, 4, 4, 5, 6, 6,
2139 7, 7, 7, 7, 8, 9, 12, 7, 7, 8, 8, 8, 8, 9, 9, 10,
2143 const VP31_AC_CAT0_CODES: [[u16; 32]; 16] = [
2145 0x0008, 0x0025, 0x017A, 0x02F7, 0x0BDB, 0x17B4, 0x2F6B, 0x001D,
2146 0x2F6A, 0x0008, 0x0007, 0x0001, 0x0002, 0x000A, 0x0006, 0x0000,
2147 0x001C, 0x0009, 0x000D, 0x000F, 0x000C, 0x0003, 0x000A, 0x0016,
2148 0x0013, 0x005D, 0x0024, 0x00BC, 0x005C, 0x05EC, 0x000B, 0x005F,
2150 0x000F, 0x0010, 0x004B, 0x00C6, 0x031D, 0x0C71, 0x0C70, 0x0001,
2151 0x0C73, 0x0008, 0x0009, 0x0002, 0x0003, 0x000B, 0x0006, 0x0000,
2152 0x001C, 0x0005, 0x000D, 0x000F, 0x000A, 0x0019, 0x0013, 0x001D,
2153 0x0030, 0x0062, 0x0024, 0x004A, 0x018F, 0x0C72, 0x000E, 0x0011,
2155 0x001B, 0x0003, 0x008D, 0x0040, 0x0239, 0x0471, 0x08E0, 0x0003,
2156 0x11C3, 0x000A, 0x0009, 0x0004, 0x0005, 0x000E, 0x0007, 0x0001,
2157 0x001E, 0x0006, 0x000C, 0x000B, 0x0002, 0x0000, 0x0041, 0x001F,
2158 0x0022, 0x0002, 0x008F, 0x008C, 0x011D, 0x11C2, 0x001A, 0x0021,
2160 0x001F, 0x0003, 0x0003, 0x0043, 0x000B, 0x0015, 0x0051, 0x0003,
2161 0x0050, 0x000D, 0x000C, 0x0004, 0x0006, 0x000E, 0x000A, 0x0001,
2162 0x001E, 0x0005, 0x0009, 0x0007, 0x0011, 0x0002, 0x0004, 0x0002,
2163 0x002D, 0x0020, 0x0042, 0x0001, 0x0000, 0x0029, 0x0017, 0x002C,
2165 0x0003, 0x001F, 0x003A, 0x005D, 0x0173, 0x02E4, 0x172D, 0x0004,
2166 0x172C, 0x000F, 0x000E, 0x0009, 0x0008, 0x000C, 0x000A, 0x0001,
2167 0x0016, 0x0002, 0x0005, 0x001A, 0x002F, 0x0038, 0x05CA, 0x0006,
2168 0x0037, 0x001E, 0x003B, 0x0039, 0x00B8, 0x0B97, 0x0000, 0x0036,
2170 0x0006, 0x0037, 0x005D, 0x000C, 0x00B9, 0x02E3, 0x05C4, 0x0004,
2171 0x1715, 0x0000, 0x000F, 0x0008, 0x0007, 0x000C, 0x0009, 0x001D,
2172 0x0016, 0x001C, 0x001A, 0x000B, 0x005E, 0x0170, 0x1714, 0x000A,
2173 0x000A, 0x0036, 0x005F, 0x001B, 0x001A, 0x0B8B, 0x0002, 0x0007,
2175 0x000C, 0x000B, 0x0079, 0x0022, 0x00F0, 0x0119, 0x0230, 0x001D,
2176 0x08C4, 0x0001, 0x0000, 0x000A, 0x0009, 0x000B, 0x0007, 0x001C,
2177 0x003D, 0x000D, 0x0008, 0x0015, 0x008D, 0x118B, 0x118A, 0x000D,
2178 0x0010, 0x0009, 0x0014, 0x0047, 0x00F1, 0x0463, 0x001F, 0x000C,
2180 0x0000, 0x001A, 0x0033, 0x000C, 0x0046, 0x01E3, 0x03C5, 0x0017,
2181 0x1E21, 0x0002, 0x0001, 0x0009, 0x000A, 0x0007, 0x001B, 0x003D,
2182 0x001B, 0x0022, 0x0079, 0x00F0, 0x1E20, 0x1E23, 0x1E22, 0x000E,
2183 0x0016, 0x0018, 0x0032, 0x001A, 0x0047, 0x0789, 0x001F, 0x0010,
2185 0x001D, 0x0061, 0x004E, 0x009E, 0x027C, 0x09F5, 0x09F4, 0x0003,
2186 0x0060, 0x0000, 0x000F, 0x000B, 0x000A, 0x0009, 0x0005, 0x000D,
2187 0x0031, 0x0008, 0x0038, 0x0012, 0x0026, 0x013F, 0x04FB, 0x000D,
2188 0x0002, 0x000C, 0x0039, 0x001C, 0x000F, 0x001D, 0x0008, 0x0019,
2190 0x0007, 0x0019, 0x00AB, 0x00AA, 0x0119, 0x0461, 0x0460, 0x001B,
2191 0x0047, 0x0001, 0x0000, 0x000C, 0x000B, 0x0009, 0x0005, 0x000D,
2192 0x0035, 0x003D, 0x003C, 0x0018, 0x0022, 0x008D, 0x0231, 0x000E,
2193 0x001F, 0x0009, 0x002B, 0x0010, 0x0034, 0x0054, 0x0008, 0x0014,
2195 0x000C, 0x0005, 0x0008, 0x005B, 0x004D, 0x0131, 0x0261, 0x001A,
2196 0x0012, 0x0000, 0x000F, 0x000A, 0x0009, 0x0006, 0x001B, 0x0006,
2197 0x001C, 0x002C, 0x0015, 0x005A, 0x0027, 0x0099, 0x0260, 0x000E,
2198 0x0004, 0x000F, 0x0007, 0x001D, 0x000B, 0x0014, 0x0008, 0x0017,
2200 0x000F, 0x0013, 0x0075, 0x0024, 0x0095, 0x0251, 0x04A0, 0x0010,
2201 0x00C8, 0x0002, 0x0001, 0x0001, 0x0000, 0x001A, 0x0011, 0x002C,
2202 0x0065, 0x0074, 0x004B, 0x00C9, 0x0129, 0x0943, 0x0942, 0x0003,
2203 0x000A, 0x001C, 0x0018, 0x0033, 0x0017, 0x002D, 0x001B, 0x003B,
2205 0x0003, 0x001A, 0x002D, 0x0038, 0x0028, 0x0395, 0x0E51, 0x0037,
2206 0x00E4, 0x0001, 0x0000, 0x001F, 0x001E, 0x0017, 0x003A, 0x0073,
2207 0x002A, 0x002B, 0x0029, 0x01CB, 0x0729, 0x1CA1, 0x1CA0, 0x0004,
2208 0x000A, 0x0004, 0x0018, 0x0036, 0x000B, 0x002C, 0x0019, 0x003B,
2210 0x0004, 0x0004, 0x003F, 0x0017, 0x0075, 0x01F5, 0x07D1, 0x0017,
2211 0x01F6, 0x0001, 0x0000, 0x001B, 0x001A, 0x000A, 0x0032, 0x0074,
2212 0x00F8, 0x00F9, 0x01F7, 0x03E9, 0x0FA0, 0x1F43, 0x1F42, 0x0003,
2213 0x000A, 0x001E, 0x001C, 0x003B, 0x0018, 0x0016, 0x0016, 0x0033,
2215 0x0004, 0x0007, 0x0018, 0x001E, 0x0036, 0x0031, 0x0177, 0x0077,
2216 0x0176, 0x0001, 0x0000, 0x001A, 0x0019, 0x003A, 0x0019, 0x005C,
2217 0x00BA, 0x0061, 0x00C1, 0x0180, 0x0302, 0x0607, 0x0606, 0x0002,
2218 0x000A, 0x001F, 0x001C, 0x0037, 0x0016, 0x0076, 0x000D, 0x002F,
2220 0x0000, 0x000A, 0x001A, 0x000C, 0x001D, 0x0039, 0x0078, 0x005E,
2221 0x0393, 0x0002, 0x0001, 0x0016, 0x000F, 0x002E, 0x005F, 0x0073,
2222 0x00E5, 0x01C8, 0x0E4A, 0x1C97, 0x1C96, 0x0E49, 0x0E48, 0x0004,
2223 0x0006, 0x001F, 0x001B, 0x001D, 0x0038, 0x0038, 0x003D, 0x0079,
2227 const VP31_AC_CAT0_BITS: [[u8; 32]; 16] = [
2229 5, 7, 9, 10, 12, 13, 14, 5, 14, 4, 4, 4, 4, 4, 4, 4,
2230 5, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 8, 7, 11, 5, 7,
2232 5, 6, 8, 8, 10, 12, 12, 4, 12, 4, 4, 4, 4, 4, 4, 4,
2233 5, 4, 4, 4, 4, 5, 6, 5, 6, 7, 7, 8, 9, 12, 5, 6,
2235 5, 6, 8, 7, 10, 11, 12, 4, 13, 4, 4, 4, 4, 4, 4, 4,
2236 5, 4, 4, 4, 4, 5, 7, 5, 6, 6, 8, 8, 9, 13, 5, 6,
2238 5, 6, 7, 7, 9, 10, 12, 4, 12, 4, 4, 4, 4, 4, 4, 4,
2239 5, 4, 4, 4, 5, 6, 8, 4, 6, 6, 7, 7, 7, 11, 5, 6,
2241 4, 6, 7, 7, 9, 10, 13, 4, 13, 4, 4, 4, 4, 4, 4, 4,
2242 5, 4, 4, 5, 6, 7, 11, 4, 6, 6, 7, 7, 8, 12, 4, 6,
2244 4, 6, 7, 6, 8, 10, 11, 4, 13, 3, 4, 4, 4, 4, 4, 5,
2245 5, 5, 5, 5, 7, 9, 13, 4, 5, 6, 7, 7, 7, 12, 4, 5,
2247 4, 5, 7, 6, 8, 9, 10, 5, 12, 3, 3, 4, 4, 4, 4, 5,
2248 6, 5, 5, 6, 8, 13, 13, 4, 5, 5, 6, 7, 8, 11, 5, 5,
2250 3, 5, 6, 5, 7, 9, 10, 5, 13, 3, 3, 4, 4, 4, 5, 6,
2251 6, 6, 7, 8, 13, 13, 13, 4, 5, 5, 6, 6, 7, 11, 5, 5,
2253 5, 7, 8, 9, 11, 13, 13, 4, 7, 3, 4, 4, 4, 4, 4, 5,
2254 6, 5, 6, 6, 7, 10, 12, 4, 4, 5, 6, 6, 5, 6, 4, 5,
2256 4, 6, 8, 8, 10, 12, 12, 5, 8, 3, 3, 4, 4, 4, 4, 5,
2257 6, 6, 6, 6, 7, 9, 11, 4, 5, 5, 6, 6, 6, 7, 4, 5,
2259 4, 5, 6, 7, 9, 11, 12, 5, 7, 3, 4, 4, 4, 4, 5, 5,
2260 6, 6, 6, 7, 8, 10, 12, 4, 4, 5, 5, 6, 5, 6, 4, 5,
2262 4, 5, 7, 6, 8, 10, 11, 5, 8, 3, 3, 4, 4, 5, 5, 6,
2263 7, 7, 7, 8, 9, 12, 12, 3, 4, 5, 5, 6, 5, 6, 5, 6,
2265 3, 5, 6, 6, 7, 10, 12, 6, 8, 3, 3, 5, 5, 5, 6, 7,
2266 7, 7, 7, 9, 11, 13, 13, 3, 4, 4, 5, 6, 5, 6, 5, 6,
2268 3, 4, 6, 5, 7, 9, 11, 6, 9, 3, 3, 5, 5, 5, 6, 7,
2269 8, 8, 9, 10, 12, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6,
2271 3, 4, 5, 5, 6, 7, 9, 7, 9, 3, 3, 5, 5, 6, 6, 7,
2272 8, 8, 9, 10, 11, 12, 12, 3, 4, 5, 5, 6, 5, 7, 5, 6,
2274 3, 4, 5, 4, 5, 6, 7, 7, 11, 3, 3, 5, 5, 6, 7, 8,
2275 9, 10, 13, 14, 14, 13, 13, 3, 4, 5, 5, 6, 6, 7, 6, 7,
2279 const VP31_AC_CAT1_CODES: [[u16; 32]; 16] = [
2281 0x000B, 0x002B, 0x0054, 0x01B7, 0x06D9, 0x0DB1, 0x0DB0, 0x0002,
2282 0x00AB, 0x0009, 0x000A, 0x0007, 0x0008, 0x000F, 0x000C, 0x0003,
2283 0x001D, 0x0004, 0x000B, 0x0006, 0x001A, 0x0003, 0x00AA, 0x0001,
2284 0x0000, 0x0014, 0x006C, 0x00DA, 0x0002, 0x036D, 0x001C, 0x0037,
2286 0x001D, 0x0004, 0x00B6, 0x006A, 0x05B9, 0x16E1, 0x16E0, 0x0007,
2287 0x016F, 0x000C, 0x000D, 0x0009, 0x0008, 0x000F, 0x000A, 0x0003,
2288 0x0017, 0x0002, 0x0004, 0x001C, 0x002C, 0x006B, 0x0B71, 0x0005,
2289 0x0003, 0x001B, 0x005A, 0x0034, 0x0005, 0x02DD, 0x0000, 0x000C,
2291 0x0003, 0x007F, 0x00A1, 0x00A0, 0x020C, 0x0834, 0x106B, 0x0007,
2292 0x0082, 0x000E, 0x000D, 0x000B, 0x000C, 0x0000, 0x0009, 0x0002,
2293 0x0011, 0x001E, 0x0015, 0x003E, 0x0040, 0x041B, 0x106A, 0x0006,
2294 0x000A, 0x0029, 0x007E, 0x0051, 0x0021, 0x0107, 0x0004, 0x000B,
2296 0x0007, 0x001B, 0x00F6, 0x00E9, 0x03A1, 0x0740, 0x0E82, 0x001F,
2297 0x01EF, 0x0001, 0x0002, 0x000B, 0x000C, 0x000D, 0x0008, 0x001C,
2298 0x0003, 0x0012, 0x0002, 0x0075, 0x01D1, 0x1D07, 0x1D06, 0x000A,
2299 0x0013, 0x003B, 0x001A, 0x007A, 0x003C, 0x01EE, 0x0000, 0x000C,
2301 0x000D, 0x003D, 0x0042, 0x0037, 0x00D9, 0x0362, 0x06C6, 0x001F,
2302 0x0086, 0x0001, 0x0002, 0x000C, 0x000B, 0x000A, 0x0001, 0x000F,
2303 0x0025, 0x003C, 0x001A, 0x0087, 0x01B0, 0x0D8F, 0x0D8E, 0x000E,
2304 0x0013, 0x000C, 0x0024, 0x0020, 0x0011, 0x006D, 0x0000, 0x000E,
2306 0x0000, 0x0012, 0x0076, 0x0077, 0x014D, 0x0533, 0x14C9, 0x0013,
2307 0x00A5, 0x0002, 0x0003, 0x000B, 0x000C, 0x0008, 0x001A, 0x002B,
2308 0x0075, 0x0074, 0x00A7, 0x0298, 0x14C8, 0x14CB, 0x14CA, 0x000F,
2309 0x001C, 0x0007, 0x002A, 0x0028, 0x001B, 0x00A4, 0x0002, 0x0006,
2311 0x0002, 0x001A, 0x002B, 0x003A, 0x00ED, 0x0283, 0x0A0A, 0x0004,
2312 0x00A1, 0x0004, 0x0003, 0x000B, 0x000C, 0x001F, 0x0006, 0x0077,
2313 0x00A3, 0x00A2, 0x0140, 0x1417, 0x1416, 0x0A09, 0x0A08, 0x0000,
2314 0x001E, 0x0007, 0x002A, 0x0029, 0x001C, 0x00EC, 0x001B, 0x0005,
2316 0x0002, 0x0002, 0x0018, 0x001D, 0x0035, 0x00E4, 0x01CF, 0x001D,
2317 0x0072, 0x0004, 0x0005, 0x0006, 0x0007, 0x0006, 0x0073, 0x0038,
2318 0x01CE, 0x039B, 0x0398, 0x0733, 0x0732, 0x0735, 0x0734, 0x0000,
2319 0x001F, 0x001B, 0x0034, 0x000F, 0x001E, 0x00E5, 0x0019, 0x0038,
2321 0x0016, 0x0050, 0x0172, 0x02E7, 0x1732, 0x2E67, 0x2E66, 0x0006,
2322 0x0051, 0x0001, 0x0000, 0x000D, 0x000C, 0x0009, 0x001C, 0x0009,
2323 0x001C, 0x001D, 0x005D, 0x00B8, 0x05CD, 0x1731, 0x1730, 0x000F,
2324 0x0005, 0x000F, 0x0008, 0x0029, 0x001D, 0x002F, 0x0008, 0x0015,
2326 0x0009, 0x0021, 0x0040, 0x00AD, 0x02B0, 0x1589, 0x1588, 0x001C,
2327 0x005F, 0x0000, 0x000F, 0x000D, 0x000C, 0x0006, 0x0011, 0x002A,
2328 0x0057, 0x005E, 0x0041, 0x0159, 0x0563, 0x158B, 0x158A, 0x0001,
2329 0x0005, 0x0014, 0x003B, 0x002E, 0x0004, 0x003A, 0x0007, 0x0016,
2331 0x000E, 0x0007, 0x0046, 0x0045, 0x0064, 0x032A, 0x0657, 0x0018,
2332 0x000D, 0x0000, 0x000F, 0x000A, 0x000B, 0x001A, 0x0036, 0x0047,
2333 0x0044, 0x0018, 0x0033, 0x00CB, 0x0656, 0x0329, 0x0328, 0x0002,
2334 0x0006, 0x0019, 0x000E, 0x0037, 0x0009, 0x000F, 0x0002, 0x0010,
2336 0x0003, 0x0018, 0x0023, 0x0077, 0x0194, 0x1956, 0x32AF, 0x003A,
2337 0x0076, 0x0002, 0x0001, 0x001F, 0x001E, 0x0014, 0x0022, 0x0064,
2338 0x0197, 0x0196, 0x032B, 0x0654, 0x32AE, 0x1955, 0x1954, 0x0000,
2339 0x0009, 0x001C, 0x0015, 0x0010, 0x000D, 0x0017, 0x0016, 0x0033,
2341 0x0005, 0x0006, 0x003E, 0x0010, 0x0048, 0x093F, 0x24FA, 0x0032,
2342 0x0067, 0x0002, 0x0001, 0x001B, 0x001E, 0x0034, 0x0066, 0x0092,
2343 0x0126, 0x024E, 0x049E, 0x49F7, 0x49F6, 0x24F9, 0x24F8, 0x0000,
2344 0x0007, 0x0018, 0x0011, 0x003F, 0x000E, 0x0013, 0x0035, 0x0025,
2346 0x0005, 0x0008, 0x0012, 0x001C, 0x001C, 0x00EA, 0x1D75, 0x001E,
2347 0x0066, 0x0001, 0x0002, 0x001B, 0x001A, 0x001F, 0x003B, 0x0074,
2348 0x01D6, 0x03AF, 0x1D74, 0x1D77, 0x1D76, 0x0EB9, 0x0EB8, 0x000F,
2349 0x0006, 0x0013, 0x003B, 0x003A, 0x0000, 0x0018, 0x0032, 0x0067,
2351 0x0004, 0x000A, 0x001B, 0x000C, 0x000D, 0x00E6, 0x0684, 0x0072,
2352 0x00E7, 0x0002, 0x0001, 0x0017, 0x0016, 0x0018, 0x00D1, 0x01A0,
2353 0x0686, 0x0D0F, 0x0D0A, 0x1A17, 0x1A16, 0x1A1D, 0x1A1C, 0x000F,
2354 0x001D, 0x000E, 0x0035, 0x0038, 0x0000, 0x000F, 0x0019, 0x0069,
2356 0x0003, 0x000C, 0x001B, 0x0000, 0x0003, 0x002E, 0x0051, 0x00BC,
2357 0x0053, 0x0004, 0x0002, 0x0016, 0x0015, 0x0015, 0x0050, 0x00A4,
2358 0x0294, 0x052B, 0x052A, 0x052D, 0x052C, 0x052F, 0x052E, 0x000E,
2359 0x001A, 0x0004, 0x0028, 0x0029, 0x000F, 0x000B, 0x005F, 0x00BD,
2363 const VP31_AC_CAT1_BITS: [[u8; 32]; 16] = [
2365 5, 7, 8, 9, 11, 12, 12, 4, 9, 4, 4, 4, 4, 4, 4, 4,
2366 5, 4, 4, 4, 5, 6, 9, 4, 5, 6, 7, 8, 6, 10, 5, 6,
2368 5, 6, 8, 8, 11, 13, 13, 4, 9, 4, 4, 4, 4, 4, 4, 4,
2369 5, 4, 4, 5, 6, 8, 12, 4, 5, 6, 7, 7, 6, 10, 4, 5,
2371 4, 7, 8, 8, 10, 12, 13, 4, 8, 4, 4, 4, 4, 3, 4, 4,
2372 5, 5, 5, 6, 7, 11, 13, 4, 5, 6, 7, 7, 6, 9, 4, 5,
2374 4, 6, 8, 8, 10, 11, 12, 5, 9, 3, 3, 4, 4, 4, 4, 5,
2375 5, 5, 5, 7, 9, 13, 13, 4, 5, 6, 6, 7, 6, 9, 4, 5,
2377 4, 6, 7, 7, 9, 11, 12, 5, 8, 3, 3, 4, 4, 4, 4, 5,
2378 6, 6, 6, 8, 10, 13, 13, 4, 5, 5, 6, 6, 5, 8, 4, 5,
2380 3, 5, 7, 7, 9, 11, 13, 5, 8, 3, 3, 4, 4, 4, 5, 6,
2381 7, 7, 8, 10, 13, 13, 13, 4, 5, 5, 6, 6, 5, 8, 4, 5,
2383 3, 5, 6, 6, 8, 10, 12, 5, 8, 3, 3, 4, 4, 5, 5, 7,
2384 8, 8, 9, 13, 13, 12, 12, 3, 5, 5, 6, 6, 5, 8, 5, 5,
2386 3, 4, 5, 5, 6, 8, 11, 7, 9, 3, 3, 4, 4, 5, 7, 8,
2387 11, 12, 12, 13, 13, 13, 13, 3, 5, 5, 6, 6, 5, 8, 5, 6,
2389 5, 7, 9, 10, 13, 14, 14, 4, 7, 3, 3, 4, 4, 4, 5, 5,
2390 6, 6, 7, 8, 11, 13, 13, 4, 4, 5, 5, 6, 5, 6, 4, 5,
2392 4, 6, 7, 8, 10, 13, 13, 5, 7, 3, 4, 4, 4, 4, 5, 6,
2393 7, 7, 7, 9, 11, 13, 13, 3, 4, 5, 6, 6, 4, 6, 4, 5,
2395 4, 5, 7, 7, 9, 12, 13, 5, 6, 3, 4, 4, 4, 5, 6, 7,
2396 7, 7, 8, 10, 13, 12, 12, 3, 4, 5, 5, 6, 4, 5, 4, 5,
2398 3, 5, 6, 7, 9, 13, 14, 6, 7, 3, 3, 5, 5, 5, 6, 7,
2399 9, 9, 10, 11, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6,
2401 3, 4, 6, 5, 7, 12, 14, 6, 7, 3, 3, 5, 5, 6, 7, 8,
2402 9, 10, 11, 15, 15, 14, 14, 3, 4, 5, 5, 6, 4, 5, 6, 6,
2404 3, 4, 5, 5, 6, 9, 14, 6, 7, 3, 3, 5, 5, 6, 7, 8,
2405 10, 11, 14, 14, 14, 13, 13, 4, 4, 5, 6, 6, 3, 5, 6, 7,
2407 3, 4, 5, 4, 5, 8, 11, 7, 8, 3, 3, 5, 5, 6, 8, 9,
2408 11, 12, 12, 13, 13, 13, 13, 4, 5, 5, 6, 6, 3, 5, 6, 7,
2410 3, 4, 5, 3, 4, 6, 9, 8, 9, 3, 3, 5, 5, 7, 9, 10,
2411 12, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 6, 7, 8,
2415 const VP31_AC_CAT2_CODES: [[u16; 32]; 16] = [
2417 0x0003, 0x0009, 0x00D0, 0x01A3, 0x0344, 0x0D14, 0x1A2B, 0x0004,
2418 0x0015, 0x0000, 0x000F, 0x000B, 0x000C, 0x000E, 0x0009, 0x001B,
2419 0x000A, 0x0014, 0x000D, 0x002A, 0x0014, 0x068B, 0x1A2A, 0x0008,
2420 0x000B, 0x002B, 0x000B, 0x0069, 0x0035, 0x0008, 0x0007, 0x000C,
2422 0x000A, 0x003C, 0x0032, 0x0030, 0x00C5, 0x0621, 0x0620, 0x001F,
2423 0x0033, 0x0001, 0x0000, 0x000E, 0x000D, 0x000C, 0x0004, 0x000D,
2424 0x0026, 0x0027, 0x0014, 0x0063, 0x0189, 0x0623, 0x0622, 0x000B,
2425 0x0012, 0x003D, 0x0022, 0x0015, 0x000B, 0x0023, 0x0007, 0x0010,
2427 0x000F, 0x000C, 0x0043, 0x0010, 0x0044, 0x0114, 0x0455, 0x0018,
2428 0x0023, 0x0001, 0x0000, 0x000E, 0x000D, 0x0009, 0x0019, 0x0009,
2429 0x0017, 0x0016, 0x0042, 0x008B, 0x0454, 0x0457, 0x0456, 0x000B,
2430 0x0015, 0x000A, 0x0029, 0x0020, 0x000D, 0x0028, 0x0007, 0x0011,
2432 0x0001, 0x001A, 0x0029, 0x002A, 0x00A0, 0x0285, 0x1425, 0x0002,
2433 0x0000, 0x0002, 0x0003, 0x000C, 0x000B, 0x0008, 0x0012, 0x0001,
2434 0x0051, 0x0001, 0x0143, 0x0508, 0x1424, 0x1427, 0x1426, 0x000F,
2435 0x001C, 0x0003, 0x0037, 0x002B, 0x0013, 0x0036, 0x001D, 0x0001,
2437 0x0004, 0x001F, 0x003D, 0x0006, 0x0016, 0x0053, 0x014A, 0x0034,
2438 0x002A, 0x0002, 0x0003, 0x000B, 0x000C, 0x001C, 0x0037, 0x0017,
2439 0x002B, 0x0028, 0x00A4, 0x052D, 0x052C, 0x052F, 0x052E, 0x0000,
2440 0x001D, 0x0007, 0x0004, 0x0035, 0x0014, 0x0036, 0x0015, 0x003C,
2442 0x0004, 0x000A, 0x0007, 0x001D, 0x0009, 0x01F3, 0x07C7, 0x0008,
2443 0x01F0, 0x0003, 0x0002, 0x000D, 0x000C, 0x0017, 0x007D, 0x01F2,
2444 0x07C6, 0x07C5, 0x1F12, 0x3E27, 0x3E26, 0x1F11, 0x1F10, 0x0000,
2445 0x001E, 0x0006, 0x0039, 0x0038, 0x003F, 0x002C, 0x0005, 0x002D,
2447 0x0002, 0x0007, 0x0018, 0x0003, 0x0005, 0x0035, 0x004F, 0x0012,
2448 0x04E5, 0x0005, 0x0004, 0x000D, 0x000E, 0x0033, 0x0026, 0x009D,
2449 0x04E4, 0x04E7, 0x04E6, 0x04E1, 0x04E0, 0x04E3, 0x04E2, 0x0000,
2450 0x001F, 0x000C, 0x003D, 0x003C, 0x0032, 0x0034, 0x001B, 0x0008,
2452 0x0000, 0x0004, 0x001C, 0x000F, 0x0002, 0x0007, 0x0075, 0x00E8,
2453 0x1D2A, 0x0005, 0x0004, 0x000D, 0x000C, 0x0077, 0x0E96, 0x3A57,
2454 0x3A56, 0x3A5D, 0x3A5C, 0x3A5F, 0x3A5E, 0x1D29, 0x1D28, 0x0003,
2455 0x0006, 0x000A, 0x002C, 0x0017, 0x0076, 0x01D3, 0x03A4, 0x002D,
2457 0x000A, 0x0024, 0x00BF, 0x0085, 0x0211, 0x0842, 0x1087, 0x0018,
2458 0x0020, 0x0001, 0x0002, 0x000E, 0x000D, 0x0007, 0x0013, 0x0025,
2459 0x005E, 0x0043, 0x00BE, 0x0109, 0x1086, 0x0841, 0x0840, 0x000F,
2460 0x0001, 0x0011, 0x0000, 0x002E, 0x0019, 0x0001, 0x0006, 0x0016,
2462 0x0002, 0x000F, 0x006F, 0x0061, 0x0374, 0x1BA8, 0x3753, 0x0012,
2463 0x0036, 0x0000, 0x0001, 0x000A, 0x000B, 0x001A, 0x0031, 0x0060,
2464 0x00DC, 0x01BB, 0x06EB, 0x1BAB, 0x3752, 0x3755, 0x3754, 0x000E,
2465 0x0006, 0x0013, 0x000E, 0x003E, 0x0008, 0x001E, 0x0019, 0x003F,
2467 0x0003, 0x001C, 0x0025, 0x0024, 0x01DA, 0x1DBD, 0x3B7C, 0x003C,
2468 0x003D, 0x0000, 0x0001, 0x000B, 0x000A, 0x000B, 0x0077, 0x00EC,
2469 0x03B6, 0x076E, 0x1DBF, 0x76FB, 0x76FA, 0x3B79, 0x3B78, 0x000D,
2470 0x001F, 0x0013, 0x000A, 0x0008, 0x000C, 0x0008, 0x0009, 0x003A,
2472 0x0005, 0x0003, 0x0004, 0x0010, 0x008F, 0x0475, 0x11D1, 0x0079,
2473 0x0027, 0x0002, 0x0003, 0x0001, 0x0000, 0x0026, 0x0046, 0x011C,
2474 0x0477, 0x08ED, 0x11D0, 0x11D3, 0x11D2, 0x11D9, 0x11D8, 0x000D,
2475 0x001F, 0x0012, 0x0005, 0x003D, 0x000C, 0x000E, 0x0022, 0x0078,
2477 0x0005, 0x000C, 0x001B, 0x0000, 0x0006, 0x03E2, 0x3E3D, 0x000F,
2478 0x0034, 0x0003, 0x0002, 0x001E, 0x001D, 0x007D, 0x01F0, 0x07C6,
2479 0x3E3C, 0x3E3F, 0x3E3E, 0x3E39, 0x3E38, 0x3E3B, 0x3E3A, 0x0008,
2480 0x001C, 0x0002, 0x003F, 0x0035, 0x0009, 0x0001, 0x000E, 0x00F9,
2482 0x0004, 0x000B, 0x0001, 0x000A, 0x001E, 0x00E0, 0x0E1E, 0x0071,
2483 0x0039, 0x0007, 0x0006, 0x000D, 0x000C, 0x0020, 0x01C2, 0x1C3F,
2484 0x1C3E, 0x0E19, 0x0E18, 0x0E1B, 0x0E1A, 0x0E1D, 0x0E1C, 0x0000,
2485 0x0009, 0x001D, 0x001F, 0x0011, 0x0005, 0x0001, 0x0043, 0x0042,
2487 0x0004, 0x000D, 0x0007, 0x0002, 0x0014, 0x016C, 0x16D1, 0x02DF,
2488 0x016E, 0x0000, 0x0007, 0x002C, 0x002B, 0x02DE, 0x16D0, 0x16D3,
2489 0x16D2, 0x2DB5, 0x2DB4, 0x2DB7, 0x2DB6, 0x16D9, 0x16D8, 0x000C,
2490 0x002A, 0x005A, 0x001B, 0x001A, 0x0017, 0x000C, 0x05B7, 0x05B5,
2492 0x0002, 0x000F, 0x001C, 0x000C, 0x003B, 0x01AC, 0x1AD8, 0x35B3,
2493 0x35B2, 0x0001, 0x0000, 0x0069, 0x0068, 0x35BD, 0x35BC, 0x35BF,
2494 0x35BE, 0x35B9, 0x35B8, 0x35BB, 0x35BA, 0x35B5, 0x35B4, 0x01A9,
2495 0x01A8, 0x035A, 0x00D7, 0x00D5, 0x003A, 0x001B, 0x35B7, 0x35B6,
2499 const VP31_AC_CAT2_BITS: [[u8; 32]; 16] = [
2501 4, 6, 8, 9, 10, 12, 13, 4, 7, 3, 4, 4, 4, 4, 4, 5,
2502 5, 5, 5, 6, 7, 11, 13, 4, 5, 6, 6, 7, 6, 6, 4, 5,
2504 4, 6, 7, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 4, 4, 5,
2505 6, 6, 6, 8, 10, 12, 12, 4, 5, 6, 6, 6, 5, 6, 4, 5,
2507 4, 5, 7, 6, 8, 10, 12, 5, 7, 3, 3, 4, 4, 4, 5, 5,
2508 6, 6, 7, 9, 12, 12, 12, 4, 5, 5, 6, 6, 5, 6, 4, 5,
2510 3, 5, 6, 6, 8, 10, 13, 5, 7, 3, 3, 4, 4, 4, 5, 6,
2511 7, 7, 9, 11, 13, 13, 13, 4, 5, 5, 6, 6, 5, 6, 5, 5,
2513 3, 5, 6, 5, 7, 9, 11, 6, 8, 3, 3, 4, 4, 5, 6, 7,
2514 8, 8, 10, 13, 13, 13, 13, 3, 5, 5, 5, 6, 5, 6, 5, 6,
2516 3, 4, 5, 5, 6, 9, 11, 6, 9, 3, 3, 4, 4, 5, 7, 9,
2517 11, 11, 13, 14, 14, 13, 13, 3, 5, 5, 6, 6, 6, 6, 5, 6,
2519 3, 4, 5, 4, 5, 7, 9, 7, 13, 3, 3, 4, 4, 6, 8, 10,
2520 13, 13, 13, 13, 13, 13, 13, 3, 5, 5, 6, 6, 6, 7, 6, 6,
2522 3, 4, 5, 4, 4, 5, 7, 8, 13, 3, 3, 4, 4, 7, 12, 14,
2523 14, 14, 14, 14, 14, 13, 13, 3, 5, 5, 7, 6, 7, 9, 10, 7,
2525 4, 6, 8, 8, 10, 12, 13, 5, 6, 3, 3, 4, 4, 4, 5, 6,
2526 7, 7, 8, 9, 13, 12, 12, 4, 4, 5, 5, 6, 5, 5, 4, 5,
2528 3, 5, 7, 7, 10, 13, 14, 5, 6, 3, 3, 4, 4, 5, 6, 7,
2529 8, 9, 11, 13, 14, 14, 14, 4, 4, 5, 5, 6, 4, 5, 5, 6,
2531 3, 5, 6, 6, 9, 13, 14, 6, 6, 3, 3, 4, 4, 5, 7, 8,
2532 10, 11, 13, 15, 15, 14, 14, 4, 5, 5, 5, 5, 4, 4, 5, 6,
2534 3, 4, 5, 5, 8, 11, 13, 7, 6, 3, 3, 4, 4, 6, 7, 9,
2535 11, 12, 13, 13, 13, 13, 13, 4, 5, 5, 5, 6, 4, 4, 6, 7,
2537 3, 4, 5, 4, 6, 10, 14, 7, 6, 3, 3, 5, 5, 7, 9, 11,
2538 14, 14, 14, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 3, 7, 8,
2540 3, 4, 4, 4, 6, 9, 13, 8, 7, 3, 3, 5, 5, 7, 10, 14,
2541 14, 13, 13, 13, 13, 13, 13, 4, 5, 6, 6, 6, 4, 3, 8, 8,
2543 3, 4, 4, 3, 5, 9, 13, 10, 9, 2, 3, 6, 6, 10, 13, 13,
2544 13, 14, 14, 14, 14, 13, 13, 5, 6, 7, 6, 6, 5, 4, 11, 11,
2546 2, 4, 5, 4, 6, 9, 13, 14, 14, 2, 2, 7, 7, 14, 14, 14,
2547 14, 14, 14, 14, 14, 14, 14, 9, 9, 10, 8, 8, 6, 5, 14, 14,
2551 const VP31_AC_CAT3_CODES: [[u16; 32]; 16] = [
2553 0x0000, 0x0010, 0x0072, 0x0071, 0x0154, 0x0AAB, 0x0AA8, 0x0014,
2554 0x0070, 0x0002, 0x0003, 0x000C, 0x000B, 0x0003, 0x0011, 0x0073,
2555 0x0054, 0x00AB, 0x02AB, 0x1553, 0x1552, 0x1555, 0x1554, 0x000D,
2556 0x001E, 0x0012, 0x003E, 0x002B, 0x0002, 0x003F, 0x001D, 0x0013,
2558 0x0003, 0x001F, 0x0029, 0x003D, 0x000C, 0x0069, 0x0345, 0x0002,
2559 0x0028, 0x0002, 0x0001, 0x000E, 0x000C, 0x0015, 0x0007, 0x001B,
2560 0x006B, 0x006A, 0x0344, 0x0347, 0x0346, 0x01A1, 0x01A0, 0x000B,
2561 0x001A, 0x0012, 0x0000, 0x003C, 0x0008, 0x001B, 0x0013, 0x0001,
2563 0x0004, 0x0004, 0x003F, 0x0014, 0x0056, 0x015C, 0x15D5, 0x003C,
2564 0x002A, 0x0000, 0x0001, 0x000E, 0x000D, 0x000C, 0x00AF, 0x02BB,
2565 0x15D4, 0x15D7, 0x15D6, 0x15D1, 0x15D0, 0x15D3, 0x15D2, 0x000B,
2566 0x0019, 0x000D, 0x003E, 0x0031, 0x0007, 0x0005, 0x003D, 0x0030,
2568 0x0005, 0x0008, 0x001A, 0x0000, 0x0036, 0x0011, 0x0106, 0x000A,
2569 0x006E, 0x0002, 0x0003, 0x0003, 0x0002, 0x006F, 0x0021, 0x020F,
2570 0x020E, 0x0101, 0x0100, 0x0103, 0x0102, 0x0105, 0x0104, 0x000C,
2571 0x001E, 0x0003, 0x003E, 0x003F, 0x0009, 0x000E, 0x000B, 0x0009,
2573 0x0002, 0x000E, 0x001E, 0x000C, 0x001F, 0x006E, 0x00AD, 0x00AF,
2574 0x0014, 0x0004, 0x0003, 0x001A, 0x0017, 0x002A, 0x0576, 0x0AEF,
2575 0x0AEE, 0x0571, 0x0570, 0x0573, 0x0572, 0x0575, 0x0574, 0x0003,
2576 0x0016, 0x0004, 0x0036, 0x000B, 0x000A, 0x0000, 0x006F, 0x00AC,
2578 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
2579 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
2580 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
2581 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
2583 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
2584 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
2585 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
2586 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
2588 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
2589 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
2590 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
2591 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
2593 0x0003, 0x0011, 0x0020, 0x0074, 0x010D, 0x0863, 0x0860, 0x000A,
2594 0x0075, 0x0001, 0x0000, 0x000B, 0x000A, 0x0018, 0x0038, 0x0042,
2595 0x010F, 0x010E, 0x0219, 0x10C3, 0x10C2, 0x10C5, 0x10C4, 0x000F,
2596 0x0004, 0x0019, 0x000B, 0x0039, 0x0009, 0x001B, 0x001A, 0x003B,
2598 0x0005, 0x0001, 0x003E, 0x0001, 0x00E2, 0x1C6F, 0x38D9, 0x0039,
2599 0x001F, 0x0002, 0x0001, 0x0009, 0x0008, 0x0000, 0x0070, 0x01C7,
2600 0x038C, 0x071A, 0x38D8, 0x38DB, 0x38DA, 0x38DD, 0x38DC, 0x000D,
2601 0x001D, 0x000E, 0x003F, 0x003C, 0x000C, 0x0006, 0x003D, 0x001E,
2603 0x0006, 0x000B, 0x0011, 0x001E, 0x0074, 0x03AA, 0x1D5C, 0x0001,
2604 0x0021, 0x0001, 0x0002, 0x0007, 0x0006, 0x003E, 0x00EB, 0x01D4,
2605 0x0EAF, 0x3ABB, 0x3ABA, 0x1D59, 0x1D58, 0x1D5B, 0x1D5A, 0x000A,
2606 0x001C, 0x0001, 0x003F, 0x003B, 0x0001, 0x0009, 0x0020, 0x0000,
2608 0x0004, 0x000A, 0x0017, 0x0004, 0x0016, 0x016A, 0x16B1, 0x0017,
2609 0x005B, 0x0006, 0x0007, 0x0001, 0x0000, 0x000A, 0x02D7, 0x0B5A,
2610 0x16B0, 0x16B3, 0x16B2, 0x2D6D, 0x2D6C, 0x2D6F, 0x2D6E, 0x0006,
2611 0x000A, 0x0004, 0x002C, 0x0017, 0x0003, 0x0007, 0x0016, 0x00B4,
2613 0x0005, 0x000D, 0x0005, 0x0009, 0x0033, 0x0193, 0x192C, 0x0061,
2614 0x0031, 0x0000, 0x0007, 0x0010, 0x0011, 0x00C8, 0x192F, 0x325B,
2615 0x325A, 0x1929, 0x1928, 0x192B, 0x192A, 0x325D, 0x325C, 0x0018,
2616 0x001A, 0x001B, 0x0065, 0x0019, 0x0004, 0x0007, 0x0060, 0x0324,
2618 0x0006, 0x0000, 0x0002, 0x000F, 0x0039, 0x01D9, 0x1D82, 0x0761,
2619 0x03BE, 0x0001, 0x0002, 0x000F, 0x000E, 0x0762, 0x3B07, 0x3B06,
2620 0x3B1D, 0x3B1C, 0x3B1F, 0x3B1E, 0x3B19, 0x3B18, 0x3B1B, 0x0038,
2621 0x01DE, 0x00ED, 0x03BF, 0x00EE, 0x003A, 0x0006, 0x0EC0, 0x3B1A,
2623 0x0000, 0x0002, 0x000F, 0x0006, 0x001C, 0x01D0, 0x0E8C, 0x1D1B,
2624 0x1D1A, 0x0003, 0x0002, 0x00EA, 0x00E9, 0x0E89, 0x0E88, 0x0E8B,
2625 0x0E8A, 0x1D65, 0x1D64, 0x1D67, 0x1D66, 0x1D61, 0x1D60, 0x03AD,
2626 0x1D63, 0x1D62, 0x1D1D, 0x1D1C, 0x003B, 0x01D7, 0x1D1F, 0x1D1E,
2628 0x0002, 0x000F, 0x001C, 0x000C, 0x003B, 0x01AC, 0x1AD8, 0x35B3,
2629 0x35B2, 0x0001, 0x0000, 0x0069, 0x0068, 0x35BD, 0x35BC, 0x35BF,
2630 0x35BE, 0x35B9, 0x35B8, 0x35BB, 0x35BA, 0x35B5, 0x35B4, 0x01A9,
2631 0x01A8, 0x035A, 0x00D7, 0x00D5, 0x003A, 0x001B, 0x35B7, 0x35B6,
2635 const VP31_AC_CAT3_BITS: [[u8; 32]; 16] = [
2637 3, 5, 7, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 4, 5, 7,
2638 7, 8, 10, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 6, 5, 5,
2640 3, 5, 6, 6, 7, 10, 13, 5, 6, 3, 3, 4, 4, 5, 6, 8,
2641 10, 10, 13, 13, 13, 12, 12, 4, 5, 5, 5, 6, 4, 5, 5, 5,
2643 3, 4, 6, 5, 7, 9, 13, 6, 6, 3, 3, 4, 4, 5, 8, 10,
2644 13, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 4, 6, 6,
2646 3, 4, 5, 4, 6, 8, 12, 7, 7, 3, 3, 4, 4, 7, 9, 13,
2647 13, 12, 12, 12, 12, 12, 12, 4, 5, 5, 6, 6, 4, 4, 7, 7,
2649 3, 4, 5, 4, 5, 7, 10, 10, 7, 3, 3, 5, 5, 8, 13, 14,
2650 14, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 3, 7, 10,
2652 3, 4, 3, 3, 4, 6, 11, 13, 8, 3, 3, 6, 6, 13, 13, 13,
2653 13, 13, 13, 13, 14, 14, 14, 3, 6, 8, 9, 8, 6, 5, 12, 14,
2655 3, 4, 3, 3, 4, 6, 11, 13, 8, 3, 3, 6, 6, 13, 13, 13,
2656 13, 13, 13, 13, 14, 14, 14, 3, 6, 8, 9, 8, 6, 5, 12, 14,
2658 3, 4, 3, 3, 4, 6, 11, 13, 8, 3, 3, 6, 6, 13, 13, 13,
2659 13, 13, 13, 13, 14, 14, 14, 3, 6, 8, 9, 8, 6, 5, 12, 14,
2661 3, 5, 6, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 5, 6, 7,
2662 9, 9, 10, 13, 13, 13, 13, 4, 4, 5, 5, 6, 4, 5, 5, 6,
2664 3, 4, 6, 5, 8, 13, 14, 6, 6, 3, 3, 4, 4, 5, 7, 9,
2665 10, 11, 14, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 4, 6, 6,
2667 3, 4, 5, 5, 7, 10, 13, 6, 6, 3, 3, 4, 4, 6, 8, 9,
2668 12, 14, 14, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 4, 6, 6,
2670 3, 4, 5, 4, 6, 9, 13, 7, 7, 3, 3, 4, 4, 6, 10, 12,
2671 13, 13, 13, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 4, 7, 8,
2673 3, 4, 4, 4, 6, 9, 13, 8, 7, 2, 3, 5, 5, 8, 13, 14,
2674 14, 13, 13, 13, 13, 14, 14, 5, 6, 6, 7, 6, 4, 4, 8, 10,
2676 3, 3, 4, 4, 6, 9, 13, 11, 10, 2, 2, 6, 6, 11, 14, 14,
2677 14, 14, 14, 14, 14, 14, 14, 6, 9, 8, 10, 8, 6, 5, 12, 14,
2679 2, 3, 5, 4, 6, 10, 13, 14, 14, 2, 2, 9, 9, 13, 13, 13,
2680 13, 14, 14, 14, 14, 14, 14, 11, 14, 14, 14, 14, 7, 10, 14, 14,
2682 2, 4, 5, 4, 6, 9, 13, 14, 14, 2, 2, 7, 7, 14, 14, 14,
2683 14, 14, 14, 14, 14, 14, 14, 9, 9, 10, 8, 8, 6, 5, 14, 14,
2687 const VP31_DC_WEIGHTS: [[i16; 5]; 16] = [
2696 [ 29, -26, 29, 0, 32 ],
2699 [ 75, 0, 0, 53, 128 ],
2701 [ 75, 0, 0, 53, 128 ],
2704 [ 75, 0, 0, 53, 128 ],
2705 [ 0, 3, 10, 3, 16 ],
2706 [ 29, -26, 29, 0, 32 ],
2709 const VP30_DC_SCALES: [i16; 64] = [
2710 24, 20, 20, 20, 20, 20, 20, 20,
2711 19, 19, 19, 19, 18, 18, 18, 18,
2712 17, 17, 17, 17, 16, 16, 15, 15,
2713 14, 14, 13, 13, 12, 12, 11, 11,
2714 10, 10, 9, 9, 8, 8, 7, 7,
2715 6, 6, 6, 6, 5, 5, 5, 5,
2716 4, 4, 4, 4, 3, 3, 3, 3,
2717 2, 2, 2, 2, 1, 1, 1, 1
2720 const VP30_AC_SCALES: [i16; 64] = [
2721 3000, 2500, 2000, 1500, 1200, 1000, 900, 800,
2722 750, 700, 650, 630, 600, 550, 500, 450,
2723 410, 380, 350, 320, 290, 260, 240, 220,
2724 200, 180, 165, 150, 140, 130, 120, 115,
2725 110, 100, 95, 90, 85, 80, 75, 70,
2726 67, 65, 63, 61, 57, 55, 53, 50,
2727 49, 46, 44, 42, 39, 36, 33, 30,
2728 27, 24, 21, 19, 17, 15, 12, 10
2731 const VP30_DC_CODES: [[u16; 32]; 5] = [
2733 0x0005, 0x002D, 0x0004, 0x0009, 0x0088, 0x0225, 0x0224, 0x0005,
2734 0x0011, 0x0007, 0x0006, 0x0009, 0x000A, 0x0007, 0x0017, 0x000C,
2735 0x002C, 0x0005, 0x0008, 0x0003, 0x0012, 0x0010, 0x0113, 0x0003,
2736 0x0010, 0x0000, 0x0013, 0x001A, 0x0023, 0x0045, 0x0001, 0x001B
2738 0x000B, 0x0012, 0x0029, 0x0010, 0x000D, 0x00A2, 0x0020, 0x0009,
2739 0x0050, 0x0007, 0x0006, 0x0006, 0x0005, 0x0002, 0x0008, 0x0027,
2740 0x0005, 0x0022, 0x0023, 0x0057, 0x00A3, 0x0011, 0x0021, 0x0007,
2741 0x0000, 0x0009, 0x002A, 0x0003, 0x0007, 0x0026, 0x000C, 0x0056
2743 0x000D, 0x0018, 0x0009, 0x0017, 0x0033, 0x0056, 0x00F7, 0x00F1,
2744 0x007A, 0x0000, 0x0007, 0x0009, 0x0008, 0x0005, 0x000D, 0x002D,
2745 0x0010, 0x001D, 0x001C, 0x0057, 0x00CB, 0x00F6, 0x00F0, 0x0014,
2746 0x000C, 0x002C, 0x0011, 0x001F, 0x002A, 0x0064, 0x00CA, 0x0079
2748 0x000F, 0x001A, 0x0013, 0x001B, 0x003B, 0x0072, 0x01D3, 0x0707,
2749 0x0E0D, 0x0001, 0x0000, 0x000C, 0x000B, 0x0008, 0x0012, 0x002A,
2750 0x0073, 0x0028, 0x0075, 0x0056, 0x0052, 0x01C0, 0x0E0C, 0x0071,
2751 0x0057, 0x00E1, 0x00A6, 0x00E8, 0x00A7, 0x03A5, 0x03A4, 0x0382
2753 0x000F, 0x001B, 0x0014, 0x001D, 0x0010, 0x0073, 0x00E2, 0x023C,
2754 0x11C9, 0x0001, 0x0000, 0x000C, 0x000B, 0x0009, 0x0015, 0x0035,
2755 0x0072, 0x0034, 0x0022, 0x0070, 0x0046, 0x011D, 0x11C8, 0x01C7,
2756 0x01C6, 0x0238, 0x047E, 0x023E, 0x0473, 0x08E5, 0x023D, 0x047F
2759 const VP30_DC_BITS: [[u8; 32]; 5] = [
2761 4, 6, 6, 6, 8, 10, 10, 6, 7, 3, 3, 4, 4, 4, 5, 5,
2762 6, 5, 5, 5, 6, 7, 9, 4, 5, 5, 6, 6, 6, 7, 5, 6
2764 4, 5, 6, 5, 6, 8, 9, 7, 7, 3, 3, 4, 4, 4, 5, 6,
2765 6, 6, 6, 7, 8, 8, 9, 4, 4, 5, 6, 5, 5, 6, 6, 7
2767 4, 5, 5, 5, 6, 7, 9, 9, 8, 2, 3, 4, 4, 4, 5, 6,
2768 6, 6, 6, 7, 8, 9, 9, 5, 5, 6, 6, 6, 6, 7, 8, 8
2770 4, 5, 5, 5, 6, 7, 9, 11, 12, 2, 2, 4, 4, 4, 5, 6,
2771 7, 6, 7, 7, 7, 9, 12, 7, 7, 8, 8, 8, 8, 10, 10, 10
2773 4, 5, 5, 5, 5, 7, 8, 10, 13, 2, 2, 4, 4, 4, 5, 6,
2774 7, 6, 6, 7, 7, 9, 13, 9, 9, 10, 11, 10, 11, 12, 10, 11
2777 const VP30_AC_INTRA_CODES: [[u16; 32]; 5] = [
2779 0x0008, 0x0033, 0x0008, 0x004B, 0x0089, 0x0221, 0x0220, 0x001F,
2780 0x0045, 0x0000, 0x000E, 0x000B, 0x000A, 0x000D, 0x0006, 0x001E,
2781 0x000A, 0x0018, 0x0013, 0x0005, 0x0009, 0x0046, 0x0111, 0x0007,
2782 0x000B, 0x0032, 0x0010, 0x004A, 0x0024, 0x0047, 0x0003, 0x0009
2784 0x000E, 0x000E, 0x007B, 0x001E, 0x007E, 0x03EF, 0x07DD, 0x0018,
2785 0x00FA, 0x0002, 0x0000, 0x000A, 0x0008, 0x000B, 0x0003, 0x0012,
2786 0x0033, 0x000C, 0x003C, 0x001A, 0x007F, 0x01F6, 0x07DC, 0x000D,
2787 0x0013, 0x0004, 0x001B, 0x007A, 0x0032, 0x007C, 0x001F, 0x0005
2789 0x0000, 0x0018, 0x0034, 0x000C, 0x006A, 0x01F9, 0x07EA, 0x0016,
2790 0x0FD7, 0x0002, 0x0001, 0x000A, 0x0009, 0x0007, 0x001B, 0x003E,
2791 0x0020, 0x0021, 0x006B, 0x01FB, 0x03F4, 0x1FAD, 0x1FAC, 0x000E,
2792 0x0019, 0x0011, 0x002F, 0x007F, 0x002E, 0x01F8, 0x001E, 0x000D
2794 0x000E, 0x0016, 0x002E, 0x0003, 0x006E, 0x008B, 0x0113, 0x0018,
2795 0x0221, 0x0001, 0x0002, 0x000A, 0x0009, 0x0007, 0x001A, 0x0002,
2796 0x001B, 0x0023, 0x006F, 0x008A, 0x0111, 0x0441, 0x0440, 0x000F,
2797 0x0019, 0x0010, 0x0036, 0x001A, 0x002F, 0x0112, 0x0000, 0x000C
2799 0x000E, 0x000F, 0x001B, 0x0033, 0x005A, 0x00B6, 0x0008, 0x001A,
2800 0x004D, 0x0001, 0x0002, 0x000A, 0x0009, 0x0008, 0x001B, 0x0003,
2801 0x002C, 0x002E, 0x0005, 0x00B7, 0x0027, 0x0099, 0x0098, 0x000F,
2802 0x0018, 0x000E, 0x002F, 0x001A, 0x0032, 0x0012, 0x0000, 0x000C
2805 const VP30_AC_INTRA_BITS: [[u8; 32]; 5] = [
2807 4, 6, 6, 7, 9, 11, 11, 5, 8, 3, 4, 4, 4, 4, 4, 5,
2808 5, 5, 5, 5, 6, 8, 10, 4, 5, 6, 6, 7, 6, 8, 4, 5
2810 4, 5, 7, 6, 8, 11, 12, 5, 9, 3, 3, 4, 4, 4, 4, 5,
2811 6, 5, 6, 6, 8, 10, 12, 4, 5, 5, 6, 7, 6, 8, 5, 5
2813 3, 5, 6, 5, 7, 9, 11, 5, 12, 3, 3, 4, 4, 4, 5, 6,
2814 6, 6, 7, 9, 10, 13, 13, 4, 5, 5, 6, 7, 6, 9, 5, 5
2816 4, 5, 6, 5, 7, 8, 9, 5, 10, 3, 3, 4, 4, 4, 5, 5,
2817 6, 6, 7, 8, 9, 11, 11, 4, 5, 5, 6, 6, 6, 9, 4, 5
2819 4, 5, 6, 6, 7, 8, 7, 5, 10, 3, 3, 4, 4, 4, 5, 5,
2820 6, 6, 6, 8, 9, 11, 11, 4, 5, 5, 6, 6, 6, 8, 4, 5
2823 const VP30_AC_INTER_CODES: [[u16; 32]; 5] = [
2825 0x000D, 0x0038, 0x0061, 0x0060, 0x0393, 0x1C95, 0x1C94, 0x0014,
2826 0x0073, 0x0001, 0x0000, 0x000B, 0x0009, 0x001D, 0x000E, 0x0022,
2827 0x0046, 0x0047, 0x00E5, 0x01C8, 0x0724, 0x1C97, 0x1C96, 0x000F,
2828 0x0006, 0x0019, 0x000F, 0x0031, 0x0004, 0x0010, 0x0005, 0x0015
2830 0x0004, 0x001B, 0x0030, 0x0034, 0x00D5, 0x06B3, 0x3595, 0x0031,
2831 0x001A, 0x0002, 0x0001, 0x001F, 0x001E, 0x000C, 0x001B, 0x00D7,
2832 0x00D4, 0x01AD, 0x0358, 0x0D64, 0x3594, 0x3597, 0x3596, 0x0000,
2833 0x000A, 0x001D, 0x0017, 0x0039, 0x0007, 0x0019, 0x0016, 0x0038
2835 0x0005, 0x0009, 0x001A, 0x001E, 0x001F, 0x00E2, 0x038E, 0x0070,
2836 0x003B, 0x0001, 0x0000, 0x0019, 0x0018, 0x001E, 0x003A, 0x01C6,
2837 0x071E, 0x0E3E, 0x1C7E, 0x71FD, 0x71FC, 0x71FF, 0x71FE, 0x0002,
2838 0x0008, 0x001D, 0x001B, 0x0039, 0x001F, 0x000D, 0x000C, 0x001C
2840 0x0003, 0x000B, 0x001C, 0x000D, 0x0004, 0x000A, 0x0076, 0x00E8,
2841 0x01DC, 0x0001, 0x0000, 0x0033, 0x0032, 0x00E9, 0x03BB, 0x0774,
2842 0x1DD5, 0x3BAD, 0x3BAC, 0x3BAF, 0x3BAE, 0x3BA9, 0x3BA8, 0x0004,
2843 0x000A, 0x001F, 0x001E, 0x0030, 0x000B, 0x0075, 0x0031, 0x00EF
2845 0x0009, 0x001E, 0x000F, 0x000E, 0x000C, 0x0008, 0x0001, 0x00E3,
2846 0x00E2, 0x0002, 0x0000, 0x003A, 0x0039, 0x0070, 0x01DC, 0x0776,
2847 0x0775, 0x0EEF, 0x0EE8, 0x1DD3, 0x1DD2, 0x1DDD, 0x1DDC, 0x0005,
2848 0x001F, 0x001B, 0x0006, 0x006A, 0x0034, 0x0076, 0x006B, 0x00EF
2851 const VP30_AC_INTER_BITS: [[u8; 32]; 5] = [
2853 4, 6, 7, 7, 10, 13, 13, 5, 7, 3, 3, 4, 4, 5, 5, 6,
2854 7, 7, 8, 9, 11, 13, 13, 4, 4, 5, 5, 6, 4, 5, 4, 5
2856 3, 5, 6, 6, 8, 11, 14, 6, 6, 3, 3, 5, 5, 5, 6, 8,
2857 8, 9, 10, 12, 14, 14, 14, 3, 4, 5, 5, 6, 4, 5, 5, 6
2859 3, 4, 5, 5, 6, 8, 10, 7, 7, 3, 3, 5, 5, 6, 7, 9,
2860 11, 12, 13, 15, 15, 15, 15, 3, 4, 5, 5, 6, 5, 5, 5, 6
2862 3, 4, 5, 4, 4, 5, 7, 8, 9, 3, 3, 6, 6, 8, 10, 11,
2863 13, 14, 14, 14, 14, 14, 14, 3, 4, 5, 5, 6, 5, 7, 6, 8
2865 4, 5, 5, 4, 4, 4, 3, 9, 9, 3, 3, 7, 7, 8, 10, 12,
2866 12, 13, 13, 14, 14, 14, 14, 3, 5, 5, 4, 7, 6, 8, 7, 9
2869 const VP30_MBTYPE_CODES: [u8; 7] = [ 0x00, 0x08, 0x0A, 0x03, 0x0B, 0x13, 0x12 ];
2870 const VP30_MBTYPE_BITS: [u8; 7] = [ 1, 4, 4, 2, 4, 5, 5 ];
2871 const VP30_MBTYPE_SYMS: [VPMBType; 7] = [
2872 VPMBType::InterNoMV, VPMBType::Intra, VPMBType::InterMV, VPMBType::InterNearest,
2873 VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
2876 const VP40_DC_CODES: [[u32; 32]; 16] = [
2878 0x000C, 0x0070, 0x01CA, 0x01CB, 0x0391, 0x1C9B, 0x3935, 0x0071,
2879 0x3934, 0x000B, 0x000F, 0x0019, 0x0002, 0x0009, 0x0003, 0x001D,
2880 0x0018, 0x0007, 0x000D, 0x0002, 0x0000, 0x000A, 0x0008, 0x001A,
2881 0x0073, 0x006F, 0x0E4C, 0x0727, 0x0392, 0x0390, 0x0036, 0x006E
2883 0x0011, 0x007A, 0x0083, 0x0040, 0x0105, 0x0413, 0x0410, 0x007B,
2884 0x0822, 0x000E, 0x0002, 0x0002, 0x0006, 0x000A, 0x0007, 0x001F,
2885 0x0017, 0x0009, 0x000D, 0x0000, 0x000C, 0x0003, 0x003C, 0x002C,
2886 0x0021, 0x0169, 0x0412, 0x02D0, 0x02D1, 0x0823, 0x005B, 0x00B5
2888 0x0017, 0x0010, 0x00B6, 0x0022, 0x016A, 0x02D0, 0x0B48, 0x0077,
2889 0x1692, 0x0000, 0x0003, 0x0003, 0x0009, 0x000C, 0x0005, 0x0002,
2890 0x001C, 0x0008, 0x000D, 0x000F, 0x000A, 0x0009, 0x0023, 0x003A,
2891 0x002C, 0x016B, 0x05A5, 0x02D3, 0x02D1, 0x1693, 0x0076, 0x00B7
2893 0x001E, 0x0013, 0x00FB, 0x007C, 0x0046, 0x07D6, 0x0FA9, 0x0012,
2894 0x1F50, 0x0001, 0x0004, 0x0005, 0x000A, 0x000E, 0x0007, 0x0000,
2895 0x0017, 0x0006, 0x000D, 0x000C, 0x0001, 0x002C, 0x008F, 0x003F,
2896 0x002D, 0x01F4, 0x07D5, 0x008E, 0x07D7, 0x1F51, 0x0010, 0x0022
2898 0x0001, 0x002B, 0x0012, 0x0055, 0x0027, 0x03B0, 0x0762, 0x0077,
2899 0x0261, 0x0002, 0x0006, 0x0007, 0x000B, 0x000F, 0x0008, 0x0000,
2900 0x001C, 0x0003, 0x0009, 0x0006, 0x0014, 0x0054, 0x0131, 0x0005,
2901 0x003A, 0x01D9, 0x0099, 0x004D, 0x0763, 0x0260, 0x0008, 0x00ED
2903 0x0004, 0x0033, 0x0060, 0x0065, 0x00C2, 0x030D, 0x0619, 0x0064,
2904 0x1862, 0x0004, 0x0007, 0x000A, 0x000B, 0x000D, 0x0006, 0x0000,
2905 0x000F, 0x0003, 0x0005, 0x0002, 0x0002, 0x0077, 0x0C30, 0x0003,
2906 0x0031, 0x0187, 0x01D9, 0x00ED, 0x01D8, 0x1863, 0x001C, 0x003A
2908 0x0008, 0x000A, 0x006A, 0x0016, 0x001E, 0x034E, 0x069F, 0x0068,
2909 0x0D28, 0x0005, 0x0007, 0x0007, 0x000C, 0x0000, 0x0006, 0x001B,
2910 0x0012, 0x0002, 0x0004, 0x0013, 0x000E, 0x034B, 0x1A53, 0x0006,
2911 0x0017, 0x01A6, 0x069E, 0x01A4, 0x0695, 0x1A52, 0x006B, 0x001F
2913 0x000E, 0x000F, 0x0017, 0x0025, 0x009F, 0x0138, 0x024B, 0x0093,
2914 0x092A, 0x0005, 0x0000, 0x0008, 0x000D, 0x000F, 0x0006, 0x0004,
2915 0x000E, 0x0019, 0x0018, 0x000A, 0x009E, 0x0494, 0x1256, 0x0026,
2916 0x0016, 0x0124, 0x04E5, 0x0273, 0x04E4, 0x1257, 0x0048, 0x009D
2918 0x0004, 0x002C, 0x0050, 0x001E, 0x0071, 0x00E1, 0x00E0, 0x001D,
2919 0x0006, 0x0007, 0x0006, 0x0007, 0x0005, 0x0006, 0x0015, 0x0000,
2920 0x0029, 0x0002, 0x0006, 0x0001, 0x0023, 0x001F, 0x0039, 0x0009,
2921 0x0002, 0x0010, 0x0007, 0x002D, 0x002F, 0x002E, 0x0022, 0x0051
2923 0x0008, 0x002F, 0x0051, 0x0050, 0x02ED, 0x05D9, 0x05D8, 0x00BA,
2924 0x005C, 0x0007, 0x0006, 0x0009, 0x0006, 0x0007, 0x0016, 0x0005,
2925 0x002B, 0x0006, 0x000A, 0x0001, 0x000F, 0x001D, 0x0177, 0x0004,
2926 0x0001, 0x0004, 0x0001, 0x002A, 0x000B, 0x0029, 0x0000, 0x001C
2928 0x000A, 0x003C, 0x0074, 0x004E, 0x026D, 0x04D9, 0x04D8, 0x009A,
2929 0x004C, 0x0000, 0x0006, 0x0008, 0x0007, 0x0006, 0x0016, 0x0008,
2930 0x002E, 0x000A, 0x000B, 0x003D, 0x0024, 0x00EB, 0x0137, 0x001F,
2931 0x001C, 0x003B, 0x0012, 0x0025, 0x002F, 0x0013, 0x004F, 0x00EA
2933 0x000A, 0x000A, 0x0003, 0x0016, 0x0009, 0x0021, 0x0020, 0x00B3,
2934 0x0058, 0x0007, 0x0006, 0x0007, 0x0006, 0x0004, 0x0013, 0x0002,
2935 0x0025, 0x0000, 0x0003, 0x002D, 0x005D, 0x00B2, 0x0011, 0x0008,
2936 0x0002, 0x0006, 0x0017, 0x002F, 0x0007, 0x0024, 0x005C, 0x0005
2938 0x000B, 0x0013, 0x001F, 0x0031, 0x0021, 0x0295, 0x0528, 0x00A4,
2939 0x003C, 0x0000, 0x0007, 0x0006, 0x0005, 0x001B, 0x0012, 0x0032,
2940 0x001D, 0x002B, 0x0030, 0x001C, 0x003D, 0x014B, 0x0529, 0x0008,
2941 0x001A, 0x0033, 0x0011, 0x002A, 0x0009, 0x0028, 0x0053, 0x0020
2943 0x000E, 0x0015, 0x0029, 0x003F, 0x004D, 0x02F1, 0x05E0, 0x0092,
2944 0x0048, 0x0000, 0x0006, 0x0006, 0x0005, 0x0004, 0x000F, 0x002E,
2945 0x001D, 0x0028, 0x0027, 0x005F, 0x00BD, 0x0179, 0x05E1, 0x0008,
2946 0x001E, 0x002D, 0x001C, 0x002C, 0x003E, 0x0025, 0x004C, 0x0093
2948 0x000C, 0x0017, 0x0035, 0x0013, 0x0021, 0x00AD, 0x06F1, 0x01BD,
2949 0x00D9, 0x0000, 0x0007, 0x0007, 0x0006, 0x0004, 0x0011, 0x002A,
2950 0x006E, 0x0025, 0x0024, 0x0057, 0x00D8, 0x0379, 0x06F0, 0x0005,
2951 0x0016, 0x0029, 0x006D, 0x0028, 0x0034, 0x0020, 0x00DF, 0x00AC
2953 0x0000, 0x001A, 0x0006, 0x0019, 0x0030, 0x005A, 0x018A, 0x02DD,
2954 0x018B, 0x0001, 0x0007, 0x000A, 0x0009, 0x0002, 0x0010, 0x002E,
2955 0x006E, 0x002C, 0x000E, 0x005E, 0x00C4, 0x05B9, 0x05B8, 0x0011,
2956 0x0036, 0x005F, 0x001E, 0x0063, 0x006F, 0x001F, 0x00B6, 0x016F
2959 const VP40_DC_BITS: [[u8; 32]; 16] = [
2961 5, 7, 9, 9, 10, 13, 14, 7, 14, 4, 4, 5, 4, 4, 4, 5,
2962 5, 4, 4, 3, 3, 4, 4, 6, 7, 8, 12, 11, 10, 10, 7, 8
2964 5, 7, 8, 7, 9, 11, 11, 7, 12, 4, 3, 4, 4, 4, 4, 5,
2965 5, 4, 4, 3, 4, 4, 6, 6, 6, 9, 11, 10, 10, 12, 7, 8
2967 5, 6, 8, 7, 9, 10, 12, 7, 13, 3, 3, 4, 4, 4, 4, 4,
2968 5, 4, 4, 4, 4, 5, 7, 6, 6, 9, 11, 10, 10, 13, 7, 8
2970 5, 6, 8, 7, 8, 11, 12, 6, 13, 3, 3, 4, 4, 4, 4, 4,
2971 5, 4, 4, 4, 4, 6, 9, 6, 6, 9, 11, 9, 11, 13, 6, 7
2973 4, 6, 7, 7, 8, 10, 11, 7, 12, 3, 3, 4, 4, 4, 4, 4,
2974 5, 4, 4, 4, 5, 7, 11, 5, 6, 9, 10, 9, 11, 12, 6, 8
2976 4, 6, 7, 7, 8, 10, 11, 7, 13, 3, 3, 4, 4, 4, 4, 4,
2977 5, 4, 4, 4, 5, 8, 12, 5, 6, 9, 10, 9, 10, 13, 6, 7
2979 4, 5, 7, 6, 7, 10, 11, 7, 12, 3, 3, 4, 4, 3, 4, 5,
2980 5, 4, 4, 5, 6, 10, 13, 5, 6, 9, 11, 9, 11, 13, 7, 7
2982 4, 5, 6, 6, 8, 9, 10, 8, 12, 3, 2, 4, 4, 4, 4, 4,
2983 5, 5, 5, 5, 8, 11, 13, 6, 6, 9, 11, 10, 11, 13, 7, 8
2985 4, 6, 7, 7, 9, 10, 10, 7, 6, 3, 3, 4, 4, 4, 5, 5,
2986 6, 5, 5, 5, 6, 7, 8, 4, 4, 5, 6, 6, 6, 6, 6, 7
2988 4, 6, 7, 7, 10, 11, 11, 8, 7, 3, 3, 4, 4, 4, 5, 5,
2989 6, 5, 5, 5, 6, 7, 9, 4, 4, 5, 6, 6, 5, 6, 6, 7
2991 4, 6, 7, 7, 10, 11, 11, 8, 7, 2, 3, 4, 4, 4, 5, 5,
2992 6, 5, 5, 6, 6, 8, 9, 5, 5, 6, 6, 6, 6, 6, 7, 8
2994 4, 5, 6, 6, 8, 10, 10, 8, 7, 3, 3, 4, 4, 4, 5, 5,
2995 6, 5, 5, 6, 7, 8, 9, 4, 4, 5, 6, 6, 5, 6, 7, 7
2997 4, 5, 6, 6, 7, 10, 11, 8, 7, 2, 3, 4, 4, 5, 5, 6,
2998 6, 6, 6, 6, 7, 9, 11, 4, 5, 6, 6, 6, 5, 6, 7, 7
3000 4, 5, 6, 6, 7, 10, 11, 8, 7, 2, 3, 4, 4, 4, 5, 6,
3001 6, 6, 6, 7, 8, 9, 11, 4, 5, 6, 6, 6, 6, 6, 7, 8
3003 4, 5, 6, 5, 6, 8, 11, 9, 8, 2, 3, 4, 4, 4, 5, 6,
3004 7, 6, 6, 7, 8, 10, 11, 4, 5, 6, 7, 6, 6, 6, 8, 8
3006 3, 5, 5, 5, 6, 7, 9, 10, 9, 2, 3, 4, 4, 4, 5, 6,
3007 7, 6, 6, 7, 8, 11, 11, 5, 6, 7, 7, 7, 7, 7, 8, 9
3010 const VP40_AC_CAT0_CODES: [[u32; 32]; 16] = [
3012 0x0006, 0x001E, 0x01CC, 0x01CE, 0x0734, 0x1CD5, 0x1CD4, 0x0018,
3013 0x0E6B, 0x0000, 0x000F, 0x0006, 0x0007, 0x000D, 0x0008, 0x0002,
3014 0x0019, 0x0005, 0x000B, 0x000A, 0x001D, 0x0027, 0x01CF, 0x0004,
3015 0x0038, 0x000E, 0x004C, 0x001F, 0x004D, 0x039B, 0x0012, 0x0072
3017 0x0009, 0x004B, 0x0090, 0x0091, 0x0745, 0x1D11, 0x1D10, 0x0019,
3018 0x0E89, 0x0000, 0x000F, 0x0008, 0x0007, 0x000D, 0x000B, 0x0002,
3019 0x001C, 0x0003, 0x000A, 0x0005, 0x0018, 0x0010, 0x01D0, 0x0006,
3020 0x003B, 0x0011, 0x004A, 0x0049, 0x00E9, 0x03A3, 0x0013, 0x0075
3022 0x0019, 0x0074, 0x001D, 0x00EA, 0x0073, 0x01CA, 0x0396, 0x001C,
3023 0x00E4, 0x0002, 0x0001, 0x0007, 0x0008, 0x000D, 0x0009, 0x001F,
3024 0x0018, 0x0000, 0x0006, 0x001E, 0x003B, 0x00EB, 0x0397, 0x000A,
3025 0x0002, 0x002C, 0x005B, 0x005A, 0x000F, 0x0038, 0x0017, 0x0006
3027 0x001E, 0x006F, 0x00AE, 0x00AF, 0x0187, 0x061B, 0x0C35, 0x001A,
3028 0x030C, 0x0002, 0x0001, 0x0007, 0x0008, 0x000E, 0x0009, 0x001F,
3029 0x0014, 0x0000, 0x0001, 0x0019, 0x002A, 0x0060, 0x0C34, 0x000B,
3030 0x000D, 0x0036, 0x006E, 0x0056, 0x0031, 0x00C2, 0x0018, 0x0019
3032 0x0001, 0x002C, 0x0005, 0x0015, 0x0008, 0x0097, 0x012D, 0x0017,
3033 0x004A, 0x0003, 0x0002, 0x0009, 0x000A, 0x000E, 0x0008, 0x001F,
3034 0x0007, 0x001E, 0x001B, 0x0004, 0x005A, 0x0024, 0x012C, 0x000C,
3035 0x0006, 0x0000, 0x0003, 0x005B, 0x0014, 0x0013, 0x001A, 0x000B
3037 0x0004, 0x0000, 0x0017, 0x0063, 0x018B, 0x0310, 0x0C44, 0x0019,
3038 0x0623, 0x0004, 0x0003, 0x000A, 0x000B, 0x000D, 0x0003, 0x001C,
3039 0x0003, 0x000A, 0x0004, 0x0003, 0x018A, 0x188B, 0x188A, 0x000F,
3040 0x000B, 0x0002, 0x000A, 0x0002, 0x0016, 0x0189, 0x001D, 0x0030
3042 0x000D, 0x0003, 0x0077, 0x000D, 0x0082, 0x020D, 0x0830, 0x0019,
3043 0x0419, 0x0003, 0x0002, 0x000A, 0x0009, 0x000B, 0x0002, 0x0011,
3044 0x0039, 0x0002, 0x0021, 0x0040, 0x1063, 0x20C5, 0x20C4, 0x000F,
3045 0x0018, 0x0007, 0x0038, 0x000C, 0x0076, 0x0107, 0x0000, 0x003A
3047 0x000F, 0x001C, 0x0036, 0x0008, 0x0061, 0x0091, 0x0243, 0x0009,
3048 0x0120, 0x0005, 0x0003, 0x0008, 0x0005, 0x0001, 0x0013, 0x0031,
3049 0x0076, 0x0060, 0x0093, 0x0909, 0x0908, 0x090B, 0x090A, 0x0001,
3050 0x001A, 0x0019, 0x003A, 0x0025, 0x0077, 0x0092, 0x0000, 0x0037
3052 0x001F, 0x0079, 0x00F1, 0x00F0, 0x011B, 0x0469, 0x0468, 0x003B,
3053 0x0022, 0x0005, 0x0004, 0x0007, 0x0005, 0x0006, 0x001C, 0x0001,
3054 0x0035, 0x003D, 0x003A, 0x0010, 0x0047, 0x008C, 0x0235, 0x0001,
3055 0x0001, 0x0019, 0x0000, 0x0030, 0x0009, 0x0031, 0x001B, 0x0034
3057 0x0003, 0x001B, 0x00F3, 0x00FD, 0x03C9, 0x0F20, 0x1E42, 0x003D,
3058 0x00FC, 0x0006, 0x0004, 0x0002, 0x0000, 0x0001, 0x0017, 0x003E,
3059 0x001A, 0x0039, 0x002B, 0x0078, 0x01E5, 0x0791, 0x1E43, 0x0002,
3060 0x0007, 0x001D, 0x000C, 0x0038, 0x0014, 0x007F, 0x0016, 0x002A
3062 0x0007, 0x0039, 0x0051, 0x0078, 0x03CB, 0x0F29, 0x1E51, 0x003D,
3063 0x00F3, 0x0006, 0x0004, 0x0002, 0x0000, 0x0001, 0x0017, 0x003E,
3064 0x007F, 0x002B, 0x007E, 0x0050, 0x01E4, 0x0795, 0x1E50, 0x0002,
3065 0x0006, 0x001D, 0x0006, 0x0038, 0x0007, 0x0029, 0x0016, 0x002A
3067 0x0008, 0x003B, 0x001D, 0x0072, 0x01CC, 0x0734, 0x1CD5, 0x003A,
3068 0x001C, 0x0006, 0x0005, 0x0002, 0x0001, 0x0000, 0x0012, 0x003E,
3069 0x007F, 0x001E, 0x007E, 0x00E7, 0x039B, 0x0E6B, 0x1CD4, 0x0002,
3070 0x0006, 0x001E, 0x000E, 0x0038, 0x0006, 0x000F, 0x0013, 0x001F
3072 0x000D, 0x003F, 0x0073, 0x000C, 0x00E4, 0x072B, 0x0E54, 0x003A,
3073 0x001A, 0x0005, 0x0004, 0x0002, 0x0001, 0x0000, 0x0007, 0x0038,
3074 0x0076, 0x0077, 0x001B, 0x01CB, 0x0394, 0x1CAB, 0x1CAA, 0x0002,
3075 0x0006, 0x001E, 0x000E, 0x003E, 0x0019, 0x001F, 0x0018, 0x001E
3077 0x000E, 0x0007, 0x000C, 0x001C, 0x00BD, 0x02F3, 0x0BC9, 0x001F,
3078 0x00BF, 0x0006, 0x0004, 0x0002, 0x0001, 0x001E, 0x0001, 0x000D,
3079 0x003A, 0x003B, 0x00BE, 0x0178, 0x05E5, 0x1791, 0x1790, 0x0002,
3080 0x0006, 0x001F, 0x0016, 0x0000, 0x0015, 0x002E, 0x0014, 0x001E
3082 0x0000, 0x001B, 0x0031, 0x003A, 0x0060, 0x006F, 0x01B9, 0x000E,
3083 0x001A, 0x0005, 0x0003, 0x0002, 0x001F, 0x001A, 0x0039, 0x000C,
3084 0x00C3, 0x00C2, 0x0036, 0x00DD, 0x0370, 0x06E3, 0x06E2, 0x0002,
3085 0x0008, 0x001E, 0x0019, 0x003B, 0x0012, 0x000F, 0x0013, 0x0038
3087 0x0002, 0x0000, 0x0003, 0x001C, 0x0032, 0x001C, 0x0199, 0x0004,
3088 0x00CD, 0x0004, 0x0003, 0x001B, 0x001A, 0x003D, 0x0067, 0x003B,
3089 0x0198, 0x0075, 0x00E9, 0x03A1, 0x03A0, 0x03A3, 0x03A2, 0x0005,
3090 0x0002, 0x001F, 0x001D, 0x003C, 0x0018, 0x000F, 0x0006, 0x0005
3093 const VP40_AC_CAT0_BITS: [[u8; 32]; 16] = [
3095 5, 7, 9, 9, 11, 13, 13, 5, 12, 3, 4, 4, 4, 4, 4, 4,
3096 5, 4, 4, 4, 5, 6, 9, 4, 6, 6, 7, 7, 7, 10, 5, 7
3098 5, 7, 8, 8, 11, 13, 13, 5, 12, 3, 4, 4, 4, 4, 4, 4,
3099 5, 4, 4, 4, 5, 6, 9, 4, 6, 6, 7, 7, 8, 10, 5, 7
3101 5, 7, 8, 8, 10, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3102 5, 4, 4, 5, 6, 8, 13, 4, 5, 6, 7, 7, 7, 9, 5, 6
3104 5, 7, 8, 8, 10, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3105 5, 4, 4, 5, 6, 8, 13, 4, 5, 6, 7, 7, 7, 9, 5, 6
3107 4, 6, 7, 7, 8, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3108 5, 5, 5, 5, 7, 10, 13, 4, 5, 5, 6, 7, 7, 9, 5, 6
3110 4, 5, 7, 7, 9, 10, 12, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3111 5, 5, 5, 6, 9, 13, 13, 4, 5, 5, 6, 6, 7, 9, 5, 6
3113 4, 5, 7, 6, 8, 10, 12, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3114 6, 5, 6, 7, 13, 14, 14, 4, 5, 5, 6, 6, 7, 9, 4, 6
3116 4, 5, 6, 5, 7, 8, 10, 5, 9, 3, 3, 4, 4, 4, 5, 6,
3117 7, 7, 8, 12, 12, 12, 12, 3, 5, 5, 6, 6, 7, 8, 4, 6
3119 5, 7, 8, 8, 10, 12, 12, 6, 7, 3, 3, 4, 4, 4, 5, 5,
3120 6, 6, 6, 6, 8, 9, 11, 3, 4, 5, 5, 6, 5, 6, 5, 6
3122 4, 6, 8, 8, 10, 12, 13, 6, 8, 3, 3, 4, 4, 4, 5, 6,
3123 6, 6, 6, 7, 9, 11, 13, 3, 4, 5, 5, 6, 5, 7, 5, 6
3125 4, 6, 7, 7, 10, 12, 13, 6, 8, 3, 3, 4, 4, 4, 5, 6,
3126 7, 6, 7, 7, 9, 11, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3128 4, 6, 7, 7, 9, 11, 13, 6, 7, 3, 3, 4, 4, 4, 5, 6,
3129 7, 6, 7, 8, 10, 12, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3131 4, 6, 7, 6, 8, 11, 12, 6, 7, 3, 3, 4, 4, 4, 5, 6,
3132 7, 7, 7, 9, 10, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3134 4, 5, 6, 6, 8, 10, 12, 6, 8, 3, 3, 4, 4, 5, 5, 6,
3135 7, 7, 8, 9, 11, 13, 13, 3, 4, 5, 5, 5, 5, 6, 5, 6
3137 3, 5, 6, 6, 7, 9, 11, 6, 7, 3, 3, 4, 5, 5, 6, 6,
3138 8, 8, 8, 10, 12, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3140 3, 4, 5, 5, 6, 7, 9, 6, 8, 3, 3, 5, 5, 6, 7, 8,
3141 9, 9, 10, 12, 12, 12, 12, 3, 4, 5, 5, 6, 5, 6, 5, 6
3144 const VP40_AC_CAT1_CODES: [[u32; 32]; 16] = [
3146 0x0004, 0x00F5, 0x0182, 0x060F, 0x1839, 0x1838, 0x183B, 0x0013,
3147 0x00C0, 0x0003, 0x0002, 0x000B, 0x000A, 0x000E, 0x0008, 0x0001,
3148 0x0012, 0x001F, 0x0000, 0x0006, 0x007B, 0x0306, 0x183A, 0x000D,
3149 0x0007, 0x0031, 0x000A, 0x0061, 0x003C, 0x00F4, 0x0019, 0x000B
3151 0x000A, 0x001A, 0x01D8, 0x03B3, 0x0ECA, 0x1D96, 0x3B2F, 0x0014,
3152 0x0036, 0x0004, 0x0003, 0x000C, 0x000B, 0x0000, 0x0004, 0x001C,
3153 0x0005, 0x0015, 0x0007, 0x0017, 0x0037, 0x0764, 0x3B2E, 0x000F,
3154 0x001A, 0x003A, 0x000C, 0x0077, 0x0004, 0x00ED, 0x001B, 0x0016
3156 0x001A, 0x002D, 0x0058, 0x01F4, 0x07D4, 0x1F55, 0x1F54, 0x0014,
3157 0x0059, 0x0004, 0x0003, 0x000B, 0x000C, 0x000E, 0x0004, 0x0015,
3158 0x0005, 0x0007, 0x0004, 0x007C, 0x03EB, 0x1F57, 0x1F56, 0x0000,
3159 0x001B, 0x003F, 0x000D, 0x000C, 0x000A, 0x00FB, 0x001E, 0x0017
3161 0x0000, 0x0075, 0x004A, 0x0097, 0x025B, 0x0969, 0x0968, 0x000B,
3162 0x00E8, 0x0005, 0x0004, 0x0007, 0x000C, 0x000D, 0x0001, 0x000A,
3163 0x0039, 0x003B, 0x0018, 0x00E9, 0x012C, 0x096B, 0x096A, 0x0001,
3164 0x001F, 0x0008, 0x0019, 0x0013, 0x000D, 0x0024, 0x001E, 0x0038
3166 0x0004, 0x0014, 0x006E, 0x0057, 0x0159, 0x0562, 0x0AC7, 0x000B,
3167 0x006F, 0x0006, 0x0005, 0x0008, 0x0009, 0x0007, 0x001E, 0x0002,
3168 0x0007, 0x0006, 0x002A, 0x00AD, 0x0AC6, 0x0561, 0x0560, 0x0001,
3169 0x001F, 0x000C, 0x0039, 0x001A, 0x0000, 0x0036, 0x001D, 0x0038
3171 0x0007, 0x001B, 0x000E, 0x000D, 0x03E1, 0x1F06, 0x3E0F, 0x0002,
3172 0x00F9, 0x0005, 0x0006, 0x0008, 0x0009, 0x0004, 0x000C, 0x001A,
3173 0x000F, 0x000C, 0x01F1, 0x07C0, 0x3E0E, 0x1F05, 0x1F04, 0x0001,
3174 0x0000, 0x001C, 0x003F, 0x003D, 0x0005, 0x007D, 0x001D, 0x003C
3176 0x000F, 0x000A, 0x0071, 0x0006, 0x01C2, 0x0702, 0x1C0E, 0x0002,
3177 0x000E, 0x0005, 0x0004, 0x0006, 0x0007, 0x001D, 0x0017, 0x000F,
3178 0x01C3, 0x01C1, 0x0380, 0x381F, 0x381E, 0x1C0D, 0x1C0C, 0x0001,
3179 0x0004, 0x0018, 0x0001, 0x0000, 0x000D, 0x0016, 0x0019, 0x0039
3181 0x0002, 0x001E, 0x003B, 0x000D, 0x0061, 0x01FA, 0x1FB5, 0x0031,
3182 0x00FC, 0x0004, 0x0005, 0x0001, 0x0007, 0x003A, 0x0060, 0x03F7,
3183 0x07EC, 0x1FB7, 0x3F6C, 0x7EDB, 0x7EDA, 0x3F69, 0x3F68, 0x0001,
3184 0x0000, 0x0019, 0x003E, 0x0039, 0x000D, 0x0038, 0x000C, 0x007F
3186 0x001E, 0x0070, 0x0127, 0x0126, 0x0492, 0x124D, 0x124C, 0x0001,
3187 0x007F, 0x0006, 0x0005, 0x0005, 0x0004, 0x0001, 0x0007, 0x0025,
3188 0x0071, 0x007E, 0x0048, 0x0125, 0x0248, 0x124F, 0x124E, 0x0003,
3189 0x0008, 0x001D, 0x0006, 0x003E, 0x0002, 0x0000, 0x0013, 0x0039
3191 0x0001, 0x0001, 0x00E7, 0x0091, 0x0240, 0x120D, 0x120C, 0x003C,
3192 0x0000, 0x0006, 0x0005, 0x0005, 0x0004, 0x001F, 0x0004, 0x0025,
3193 0x0072, 0x0049, 0x00E6, 0x0121, 0x0482, 0x120F, 0x120E, 0x0003,
3194 0x0008, 0x001D, 0x0005, 0x003D, 0x0003, 0x0001, 0x0013, 0x0038
3196 0x0004, 0x000F, 0x00F4, 0x005B, 0x02D3, 0x0B4A, 0x1697, 0x003C,
3197 0x000E, 0x0006, 0x0005, 0x0002, 0x0001, 0x001D, 0x0000, 0x007B,
3198 0x002C, 0x00F5, 0x00B5, 0x0168, 0x1696, 0x0B49, 0x0B48, 0x0003,
3199 0x0009, 0x001F, 0x000A, 0x0001, 0x0008, 0x0006, 0x001C, 0x0017
3201 0x0008, 0x0039, 0x001A, 0x0003, 0x00DB, 0x06D6, 0x0DAF, 0x003C,
3202 0x000C, 0x0006, 0x0005, 0x0002, 0x0001, 0x001D, 0x003D, 0x0000,
3203 0x0002, 0x0037, 0x006C, 0x01B4, 0x0DAE, 0x06D5, 0x06D4, 0x0002,
3204 0x0007, 0x001F, 0x0007, 0x0001, 0x0009, 0x000D, 0x000C, 0x0038
3206 0x000F, 0x0004, 0x002F, 0x002E, 0x0054, 0x0555, 0x0554, 0x0016,
3207 0x000E, 0x0006, 0x0005, 0x0001, 0x0000, 0x0009, 0x000B, 0x0014,
3208 0x0057, 0x0056, 0x00AB, 0x0557, 0x0556, 0x02A9, 0x02A8, 0x0003,
3209 0x0008, 0x0013, 0x000A, 0x0008, 0x000E, 0x0012, 0x0006, 0x000F
3211 0x0001, 0x000E, 0x0006, 0x0004, 0x00DA, 0x0DBE, 0x1B7E, 0x0007,
3212 0x001A, 0x0005, 0x0004, 0x001C, 0x001B, 0x003A, 0x0037, 0x006C,
3213 0x01B6, 0x036E, 0x0DBD, 0x36FF, 0x36FE, 0x1B79, 0x1B78, 0x0002,
3214 0x000C, 0x0000, 0x000F, 0x000C, 0x000F, 0x001A, 0x003B, 0x0005
3216 0x0005, 0x001E, 0x003A, 0x003E, 0x00FC, 0x0FD7, 0x3F55, 0x0077,
3217 0x0030, 0x0003, 0x0004, 0x001A, 0x0019, 0x007F, 0x01FB, 0x03F4,
3218 0x0FD6, 0x1FA9, 0x3F54, 0x3F57, 0x3F56, 0x3F51, 0x3F50, 0x0001,
3219 0x0004, 0x001C, 0x000B, 0x000A, 0x0000, 0x001B, 0x0031, 0x0076
3221 0x0005, 0x000C, 0x001B, 0x0008, 0x0038, 0x0015, 0x00A3, 0x00E6,
3222 0x0004, 0x0001, 0x0002, 0x0012, 0x0003, 0x000B, 0x0029, 0x00A0,
3223 0x0142, 0x0287, 0x0286, 0x0289, 0x0288, 0x028B, 0x028A, 0x000F,
3224 0x001D, 0x0013, 0x0001, 0x0000, 0x0003, 0x001A, 0x0072, 0x00E7
3227 const VP40_AC_CAT1_BITS: [[u8; 32]; 16] = [
3229 5, 8, 9, 11, 13, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 4,
3230 5, 5, 4, 5, 7, 10, 13, 4, 5, 6, 6, 7, 6, 8, 5, 6
3232 5, 7, 9, 10, 12, 13, 14, 5, 8, 3, 3, 4, 4, 3, 4, 5,
3233 5, 5, 5, 6, 8, 11, 14, 4, 5, 6, 6, 7, 5, 8, 5, 6
3235 5, 7, 8, 9, 11, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 5,
3236 5, 5, 5, 7, 10, 13, 13, 3, 5, 6, 6, 6, 5, 8, 5, 6
3238 4, 7, 8, 9, 11, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 5,
3239 6, 6, 6, 8, 10, 13, 13, 3, 5, 5, 6, 6, 5, 7, 5, 6
3241 4, 6, 8, 8, 10, 12, 13, 5, 8, 3, 3, 4, 4, 4, 5, 5,
3242 6, 6, 7, 9, 13, 12, 12, 3, 5, 5, 6, 6, 4, 7, 5, 6
3244 4, 6, 7, 7, 10, 13, 14, 5, 8, 3, 3, 4, 4, 4, 5, 6,
3245 7, 7, 9, 11, 14, 13, 13, 3, 4, 5, 6, 6, 4, 7, 5, 6
3247 4, 5, 7, 6, 9, 11, 13, 5, 7, 3, 3, 4, 4, 5, 6, 7,
3248 9, 9, 10, 14, 14, 13, 13, 3, 4, 5, 5, 5, 4, 6, 5, 6
3250 3, 5, 6, 5, 7, 9, 13, 6, 8, 3, 3, 4, 4, 6, 7, 10,
3251 11, 13, 14, 15, 15, 14, 14, 3, 4, 5, 6, 6, 4, 6, 5, 7
3253 5, 7, 9, 9, 11, 13, 13, 5, 7, 3, 3, 4, 4, 4, 5, 6,
3254 7, 7, 7, 9, 10, 13, 13, 3, 4, 5, 5, 6, 4, 5, 5, 6
3256 4, 6, 8, 8, 10, 13, 13, 6, 6, 3, 3, 4, 4, 5, 5, 6,
3257 7, 7, 8, 9, 11, 13, 13, 3, 4, 5, 5, 6, 4, 5, 5, 6
3259 4, 6, 8, 8, 11, 13, 14, 6, 6, 3, 3, 4, 4, 5, 5, 7,
3260 7, 8, 9, 10, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6
3262 4, 6, 7, 7, 10, 13, 14, 6, 6, 3, 3, 4, 4, 5, 6, 6,
3263 7, 8, 9, 11, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6
3265 4, 5, 7, 7, 9, 13, 13, 6, 6, 3, 3, 4, 4, 5, 6, 7,
3266 9, 9, 10, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6
3268 3, 5, 6, 6, 9, 13, 14, 6, 6, 3, 3, 5, 5, 6, 7, 8,
3269 10, 11, 13, 15, 15, 14, 14, 3, 4, 4, 5, 5, 4, 5, 6, 6
3271 3, 5, 6, 6, 8, 12, 14, 7, 6, 3, 3, 5, 5, 7, 9, 10,
3272 12, 13, 14, 14, 14, 14, 14, 3, 4, 5, 5, 5, 3, 5, 6, 7
3274 3, 4, 5, 4, 6, 8, 11, 8, 6, 3, 3, 5, 5, 7, 9, 11,
3275 12, 13, 13, 13, 13, 13, 13, 4, 5, 5, 5, 5, 3, 5, 7, 8
3278 const VP40_AC_CAT2_CODES: [[u32; 32]; 16] = [
3280 0x0009, 0x0015, 0x0028, 0x0052, 0x029A, 0x0537, 0x0536, 0x000A,
3281 0x0054, 0x0004, 0x0003, 0x000C, 0x000B, 0x000D, 0x0003, 0x0014,
3282 0x003A, 0x0004, 0x0038, 0x0055, 0x00A7, 0x0299, 0x0298, 0x0000,
3283 0x001E, 0x0008, 0x002B, 0x000B, 0x000B, 0x003B, 0x001F, 0x0039
3285 0x001D, 0x002F, 0x0002, 0x0007, 0x0019, 0x0035, 0x0034, 0x0009,
3286 0x002E, 0x0006, 0x0005, 0x0009, 0x0008, 0x0007, 0x001F, 0x0008,
3287 0x0018, 0x0019, 0x0001, 0x0000, 0x0018, 0x0037, 0x0036, 0x0001,
3288 0x0001, 0x000A, 0x0039, 0x0016, 0x000D, 0x0001, 0x001E, 0x0038
3290 0x0001, 0x0071, 0x00E0, 0x01C3, 0x0708, 0x1C26, 0x384F, 0x0001,
3291 0x0031, 0x0006, 0x0005, 0x0009, 0x0008, 0x0005, 0x000F, 0x0039,
3292 0x0077, 0x0076, 0x0030, 0x0385, 0x384E, 0x1C25, 0x1C24, 0x0001,
3293 0x0004, 0x000D, 0x0000, 0x0019, 0x001F, 0x000E, 0x001E, 0x003A
3295 0x0006, 0x000C, 0x00D6, 0x007B, 0x01E8, 0x07A4, 0x0F4B, 0x0036,
3296 0x006A, 0x0007, 0x0005, 0x0008, 0x0009, 0x0001, 0x0007, 0x000D,
3297 0x003C, 0x00D7, 0x00F5, 0x07A7, 0x0F4A, 0x0F4D, 0x0F4C, 0x0002,
3298 0x0002, 0x000E, 0x0037, 0x0034, 0x0000, 0x0019, 0x0018, 0x001F
3300 0x000A, 0x0027, 0x00BF, 0x00BE, 0x0224, 0x225D, 0x225C, 0x0026,
3301 0x005E, 0x0007, 0x0006, 0x0006, 0x0007, 0x0016, 0x002E, 0x0045,
3302 0x0088, 0x0113, 0x044A, 0x225F, 0x225E, 0x112D, 0x112C, 0x0002,
3303 0x0002, 0x0012, 0x0003, 0x0002, 0x0003, 0x0000, 0x0010, 0x0023
3305 0x000F, 0x0006, 0x0075, 0x0074, 0x000A, 0x00BF, 0x00B9, 0x0022,
3306 0x0003, 0x0005, 0x0006, 0x0001, 0x0002, 0x0007, 0x0000, 0x0004,
3307 0x0016, 0x005E, 0x00B8, 0x00BB, 0x00BA, 0x017D, 0x017C, 0x0002,
3308 0x0006, 0x001C, 0x0010, 0x003B, 0x0009, 0x0007, 0x0001, 0x0023
3310 0x0001, 0x001C, 0x0036, 0x003B, 0x00EA, 0x075B, 0x1D65, 0x0019,
3311 0x0074, 0x0004, 0x0005, 0x0000, 0x0001, 0x0037, 0x01D7, 0x075A,
3312 0x1D64, 0x1D67, 0x1D66, 0x1D61, 0x1D60, 0x1D63, 0x1D62, 0x0002,
3313 0x001F, 0x001A, 0x000D, 0x003D, 0x000C, 0x0007, 0x003C, 0x0018
3315 0x0002, 0x0001, 0x0014, 0x0000, 0x002F, 0x00BB, 0x02E4, 0x007D,
3316 0x00BA, 0x0003, 0x0004, 0x0016, 0x001A, 0x00B8, 0x172E, 0x2E5F,
3317 0x2E5E, 0x1729, 0x1728, 0x172B, 0x172A, 0x172D, 0x172C, 0x0001,
3318 0x001E, 0x0015, 0x001B, 0x003F, 0x000C, 0x000E, 0x007C, 0x0173
3320 0x0003, 0x007B, 0x0058, 0x01EA, 0x1EB1, 0x1EB0, 0x1EB3, 0x0013,
3321 0x0012, 0x0005, 0x0006, 0x0002, 0x0001, 0x0013, 0x003C, 0x002D,
3322 0x00F4, 0x0059, 0x03D7, 0x0F5B, 0x1EB2, 0x1EB5, 0x1EB4, 0x0003,
3323 0x000E, 0x001F, 0x0012, 0x0008, 0x0008, 0x0000, 0x000A, 0x0017
3325 0x0008, 0x003C, 0x00F5, 0x00F4, 0x1EF7, 0x3DE9, 0x3DE8, 0x001C,
3326 0x000D, 0x0005, 0x0006, 0x0001, 0x0000, 0x0007, 0x000C, 0x00F6,
3327 0x01EE, 0x03DF, 0x07BC, 0x3DEB, 0x3DEA, 0x3DED, 0x3DEC, 0x0002,
3328 0x0009, 0x001F, 0x000F, 0x0005, 0x000E, 0x0006, 0x0004, 0x001D
3330 0x0009, 0x0039, 0x0019, 0x0018, 0x0706, 0x383D, 0x383C, 0x000D,
3331 0x000F, 0x0005, 0x0006, 0x0000, 0x001D, 0x0003, 0x0071, 0x00E1,
3332 0x01C0, 0x0382, 0x1C1D, 0x383F, 0x383E, 0x3839, 0x3838, 0x0002,
3333 0x0008, 0x0002, 0x000D, 0x000C, 0x000F, 0x0007, 0x0002, 0x000E
3335 0x0000, 0x0006, 0x0035, 0x0034, 0x0777, 0x1DD4, 0x3BAB, 0x000E,
3336 0x000F, 0x0005, 0x0004, 0x001C, 0x0019, 0x003A, 0x00EF, 0x01DC,
3337 0x0776, 0x0774, 0x3BAA, 0x3BAD, 0x3BAC, 0x3BAF, 0x3BAE, 0x0002,
3338 0x0007, 0x0002, 0x0018, 0x000C, 0x000F, 0x000D, 0x001B, 0x0076
3340 0x0002, 0x0011, 0x0006, 0x004F, 0x0130, 0x1319, 0x1318, 0x004E,
3341 0x0007, 0x0006, 0x0005, 0x0010, 0x000D, 0x0005, 0x0099, 0x0262,
3342 0x098E, 0x131B, 0x131A, 0x263D, 0x263C, 0x263F, 0x263E, 0x0001,
3343 0x0007, 0x0000, 0x0012, 0x000C, 0x000E, 0x000F, 0x0004, 0x004D
3345 0x0003, 0x0000, 0x0002, 0x0037, 0x01B7, 0x0DB5, 0x36DD, 0x006C,
3346 0x0016, 0x0005, 0x0004, 0x0003, 0x000A, 0x002E, 0x036C, 0x0DB4,
3347 0x36DC, 0x36DF, 0x36DE, 0x36D9, 0x36D8, 0x36DB, 0x36DA, 0x000E,
3348 0x0004, 0x001A, 0x0019, 0x0018, 0x000F, 0x0001, 0x002F, 0x00DA
3350 0x0006, 0x0006, 0x000F, 0x0000, 0x0075, 0x03B8, 0x1DCA, 0x0074,
3351 0x0076, 0x0004, 0x0005, 0x0003, 0x0002, 0x01DE, 0x0EE6, 0x3B97,
3352 0x3B96, 0x3B9D, 0x3B9C, 0x3B9F, 0x3B9E, 0x1DC9, 0x1DC8, 0x0005,
3353 0x001C, 0x0009, 0x000E, 0x0008, 0x000F, 0x0001, 0x01DF, 0x01DD
3355 0x0004, 0x000B, 0x001D, 0x000C, 0x0014, 0x00E0, 0x3875, 0x0386,
3356 0x01C2, 0x0000, 0x0001, 0x0071, 0x0072, 0x1C3F, 0x3874, 0x3877,
3357 0x3876, 0x3871, 0x3870, 0x3873, 0x3872, 0x3879, 0x3878, 0x003C,
3358 0x0073, 0x002A, 0x003D, 0x002B, 0x001F, 0x000D, 0x1C3E, 0x1C3D
3361 const VP40_AC_CAT2_BITS: [[u8; 32]; 16] = [
3363 5, 7, 8, 9, 12, 13, 13, 5, 7, 3, 3, 4, 4, 4, 4, 5,
3364 6, 5, 6, 7, 10, 12, 12, 3, 5, 5, 6, 6, 5, 6, 5, 6
3366 5, 7, 8, 9, 11, 12, 12, 5, 7, 3, 3, 4, 4, 4, 5, 5,
3367 6, 6, 6, 7, 11, 12, 12, 3, 4, 5, 6, 6, 5, 5, 5, 6
3369 4, 7, 8, 9, 11, 13, 14, 5, 7, 3, 3, 4, 4, 4, 5, 6,
3370 7, 7, 7, 10, 14, 13, 13, 3, 4, 5, 5, 6, 5, 5, 5, 6
3372 4, 6, 8, 8, 10, 12, 13, 6, 7, 3, 3, 4, 4, 4, 5, 6,
3373 7, 8, 9, 12, 13, 13, 13, 3, 4, 5, 6, 6, 4, 5, 5, 6
3375 4, 6, 8, 8, 10, 14, 14, 6, 7, 3, 3, 4, 4, 5, 6, 7,
3376 8, 9, 11, 14, 14, 13, 13, 3, 4, 5, 5, 5, 4, 4, 5, 6
3378 4, 5, 7, 7, 9, 13, 13, 6, 7, 3, 3, 4, 4, 5, 6, 8,
3379 10, 12, 13, 13, 13, 14, 14, 3, 4, 5, 5, 6, 4, 4, 5, 6
3381 3, 5, 6, 6, 8, 11, 13, 6, 7, 3, 3, 4, 4, 6, 9, 11,
3382 13, 13, 13, 13, 13, 13, 13, 3, 5, 5, 5, 6, 4, 4, 6, 6
3384 3, 4, 5, 4, 6, 8, 10, 7, 8, 3, 3, 5, 5, 8, 13, 14,
3385 14, 13, 13, 13, 13, 13, 13, 3, 5, 5, 5, 6, 4, 4, 7, 9
3387 4, 7, 8, 9, 13, 13, 13, 6, 6, 3, 3, 4, 4, 5, 6, 7,
3388 8, 8, 10, 12, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 5, 6
3390 4, 6, 8, 8, 13, 14, 14, 6, 6, 3, 3, 4, 4, 5, 6, 8,
3391 9, 10, 11, 14, 14, 14, 14, 3, 4, 5, 5, 5, 4, 4, 5, 6
3393 4, 6, 7, 7, 11, 14, 14, 6, 6, 3, 3, 4, 5, 5, 7, 8,
3394 9, 10, 13, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 5, 6
3396 3, 5, 7, 7, 11, 13, 14, 6, 6, 3, 3, 5, 5, 6, 8, 9,
3397 11, 11, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3399 3, 5, 6, 7, 9, 13, 13, 7, 6, 3, 3, 5, 5, 6, 8, 10,
3400 12, 13, 13, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3402 3, 4, 5, 6, 9, 12, 14, 7, 6, 3, 3, 5, 5, 7, 10, 12,
3403 14, 14, 14, 14, 14, 14, 14, 4, 4, 5, 5, 5, 4, 3, 7, 8
3405 3, 4, 5, 4, 7, 10, 13, 7, 7, 3, 3, 5, 5, 9, 12, 14,
3406 14, 14, 14, 14, 14, 13, 13, 4, 5, 5, 5, 5, 4, 3, 9, 9
3408 3, 4, 5, 4, 5, 8, 14, 10, 9, 2, 2, 7, 7, 13, 14, 14,
3409 14, 14, 14, 14, 14, 14, 14, 6, 7, 6, 6, 6, 5, 4, 13, 13
3412 const VP40_AC_CAT3_CODES: [[u32; 32]; 16] = [
3414 0x0007, 0x000F, 0x00BB, 0x00BA, 0x05CF, 0x173A, 0x2E77, 0x0029,
3415 0x0172, 0x0007, 0x0006, 0x0009, 0x0008, 0x0001, 0x0005, 0x000D,
3416 0x001D, 0x001C, 0x00B8, 0x02E6, 0x2E76, 0x1739, 0x1738, 0x0002,
3417 0x0006, 0x0016, 0x0004, 0x0028, 0x0015, 0x000C, 0x0000, 0x002F
3419 0x000B, 0x0002, 0x0054, 0x002F, 0x02AC, 0x156B, 0x1568, 0x0016,
3420 0x0154, 0x0007, 0x0006, 0x0004, 0x0003, 0x0013, 0x0028, 0x002E,
3421 0x0157, 0x0155, 0x055B, 0x2AD3, 0x2AD2, 0x2AD5, 0x2AD4, 0x0003,
3422 0x0008, 0x0000, 0x000A, 0x0003, 0x0002, 0x002B, 0x0012, 0x0029
3424 0x000F, 0x0007, 0x0001, 0x0000, 0x01C4, 0x0703, 0x0E02, 0x0011,
3425 0x00E1, 0x0005, 0x0006, 0x0002, 0x0001, 0x0009, 0x0010, 0x00E3,
3426 0x01C5, 0x01C1, 0x0702, 0x1C07, 0x1C06, 0x0E01, 0x0E00, 0x0004,
3427 0x0007, 0x001D, 0x000D, 0x0001, 0x0005, 0x0006, 0x000C, 0x0039
3429 0x0001, 0x001C, 0x0011, 0x0013, 0x0042, 0x0207, 0x0815, 0x0075,
3430 0x0041, 0x0005, 0x0006, 0x0000, 0x001F, 0x003B, 0x0074, 0x0043,
3431 0x0080, 0x0206, 0x0814, 0x0817, 0x0816, 0x0409, 0x0408, 0x0003,
3432 0x0009, 0x001E, 0x0011, 0x0003, 0x0005, 0x0010, 0x0002, 0x0012
3434 0x0001, 0x001F, 0x0027, 0x0001, 0x004B, 0x0123, 0x0915, 0x0000,
3435 0x0049, 0x0005, 0x0006, 0x001D, 0x001C, 0x0013, 0x004A, 0x0090,
3436 0x0914, 0x0917, 0x0916, 0x0911, 0x0910, 0x0913, 0x0912, 0x0003,
3437 0x0005, 0x0001, 0x0012, 0x0008, 0x0008, 0x001E, 0x0026, 0x0001
3439 0x0003, 0x0001, 0x003F, 0x000B, 0x004E, 0x0132, 0x099A, 0x004F,
3440 0x0098, 0x0006, 0x0005, 0x001D, 0x001C, 0x007C, 0x0267, 0x1331,
3441 0x1330, 0x1333, 0x1332, 0x266D, 0x266C, 0x266F, 0x266E, 0x0001,
3442 0x0004, 0x001E, 0x0012, 0x000A, 0x0008, 0x0000, 0x007D, 0x004D
3444 0x0002, 0x0007, 0x0015, 0x0003, 0x0004, 0x00A7, 0x0536, 0x0028,
3445 0x029A, 0x0006, 0x0004, 0x001C, 0x0017, 0x00A4, 0x29BE, 0x537F,
3446 0x537E, 0x29B9, 0x29B8, 0x29BB, 0x29BA, 0x29BD, 0x29BC, 0x000F,
3447 0x0000, 0x0005, 0x0016, 0x001D, 0x0006, 0x0001, 0x00A5, 0x014C
3449 0x0004, 0x0007, 0x001A, 0x000C, 0x0006, 0x0029, 0x01BD, 0x1BE3,
3450 0x1BE0, 0x0000, 0x0007, 0x006E, 0x01BC, 0x37C3, 0x37C2, 0x37CD,
3451 0x37CC, 0x37CF, 0x37CE, 0x37C9, 0x37C8, 0x37CB, 0x37CA, 0x0015,
3452 0x01BF, 0x037D, 0x0036, 0x0002, 0x000B, 0x0028, 0x37C5, 0x37C4
3454 0x0001, 0x0009, 0x0003, 0x0002, 0x011F, 0x08E9, 0x08E8, 0x002D,
3455 0x0022, 0x0006, 0x0007, 0x0010, 0x0011, 0x0017, 0x002C, 0x0046,
3456 0x011E, 0x011C, 0x0477, 0x08EB, 0x08EA, 0x08ED, 0x08EC, 0x0003,
3457 0x000B, 0x0001, 0x0014, 0x000A, 0x0009, 0x0015, 0x0000, 0x0010
3459 0x0001, 0x001D, 0x0022, 0x0013, 0x011E, 0x08FC, 0x23F5, 0x0023,
3460 0x0022, 0x0005, 0x0006, 0x0010, 0x000B, 0x0010, 0x008E, 0x023E,
3461 0x08FF, 0x11FD, 0x23F4, 0x23F7, 0x23F6, 0x23F9, 0x23F8, 0x0003,
3462 0x0009, 0x0000, 0x001C, 0x000A, 0x000F, 0x0001, 0x0012, 0x0046
3464 0x0003, 0x001F, 0x003C, 0x003D, 0x0086, 0x0877, 0x10E8, 0x0041,
3465 0x0040, 0x0005, 0x0006, 0x0007, 0x0006, 0x0004, 0x010F, 0x021C,
3466 0x0875, 0x21D3, 0x21D2, 0x21D9, 0x21D8, 0x21DB, 0x21DA, 0x0002,
3467 0x0009, 0x0000, 0x0011, 0x0003, 0x000E, 0x0002, 0x0005, 0x0042
3469 0x0004, 0x0001, 0x003D, 0x0009, 0x00F3, 0x0793, 0x1E45, 0x0000,
3470 0x0002, 0x0005, 0x0006, 0x0008, 0x0001, 0x0003, 0x01E5, 0x0792,
3471 0x1E44, 0x1E47, 0x1E46, 0x1E41, 0x1E40, 0x1E43, 0x1E42, 0x0001,
3472 0x0006, 0x001F, 0x000F, 0x000E, 0x000E, 0x0005, 0x0078, 0x0001
3474 0x0004, 0x0005, 0x000E, 0x0017, 0x003E, 0x00F0, 0x0F1E, 0x007A,
3475 0x007F, 0x0006, 0x0007, 0x0005, 0x0004, 0x007B, 0x01E2, 0x1E3F,
3476 0x1E3E, 0x0F19, 0x0F18, 0x0F1B, 0x0F1A, 0x0F1D, 0x0F1C, 0x0000,
3477 0x0003, 0x0016, 0x0009, 0x0008, 0x000A, 0x0006, 0x007E, 0x0079
3479 0x0005, 0x000C, 0x001A, 0x0004, 0x001A, 0x00DE, 0x0DF4, 0x00DD,
3480 0x006D, 0x0000, 0x0007, 0x0025, 0x0024, 0x00DC, 0x0DF7, 0x1BEB,
3481 0x1BEA, 0x0DF1, 0x0DF0, 0x0DF3, 0x0DF2, 0x1BED, 0x1BEC, 0x0008,
3482 0x0013, 0x000C, 0x0037, 0x0036, 0x0005, 0x0007, 0x006C, 0x01BF
3484 0x0005, 0x000D, 0x001F, 0x000C, 0x003B, 0x0040, 0x041A, 0x0104,
3485 0x0107, 0x0001, 0x0000, 0x0024, 0x0021, 0x020B, 0x106E, 0x20DF,
3486 0x20DE, 0x1055, 0x1054, 0x1057, 0x1056, 0x106D, 0x106C, 0x0011,
3487 0x003A, 0x0025, 0x0038, 0x0039, 0x0013, 0x001E, 0x020C, 0x0414
3489 0x0000, 0x0007, 0x000D, 0x0005, 0x0009, 0x0022, 0x0CD1, 0x0CD0,
3490 0x0CD3, 0x0003, 0x0002, 0x008D, 0x00CC, 0x066B, 0x0CD2, 0x19B5,
3491 0x19B4, 0x19B7, 0x19B6, 0x19B1, 0x19B0, 0x19B3, 0x19B2, 0x0047,
3492 0x008C, 0x0337, 0x0067, 0x0018, 0x0010, 0x0032, 0x0CD5, 0x0CD4
3495 const VP40_AC_CAT3_BITS: [[u8; 32]; 16] = [
3497 4, 6, 8, 8, 11, 13, 14, 6, 9, 3, 3, 4, 4, 4, 5, 6,
3498 7, 7, 8, 10, 14, 13, 13, 3, 4, 5, 5, 6, 5, 6, 4, 6
3500 4, 5, 7, 7, 10, 13, 13, 6, 9, 3, 3, 4, 4, 5, 6, 7,
3501 9, 9, 11, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 6, 5, 6
3503 4, 5, 6, 6, 9, 11, 12, 6, 8, 3, 3, 4, 4, 5, 6, 8,
3504 9, 9, 11, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6
3506 3, 5, 6, 6, 8, 11, 13, 7, 8, 3, 3, 4, 5, 6, 7, 8,
3507 9, 11, 13, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6
3509 3, 5, 6, 5, 8, 10, 13, 6, 8, 3, 3, 5, 5, 6, 8, 9,
3510 13, 13, 13, 13, 13, 13, 13, 3, 4, 4, 5, 5, 4, 5, 6, 6
3512 3, 4, 6, 5, 7, 9, 12, 7, 8, 3, 3, 5, 5, 7, 10, 13,
3513 13, 13, 13, 14, 14, 14, 14, 3, 4, 5, 5, 5, 4, 4, 7, 7
3515 3, 4, 5, 4, 5, 8, 11, 6, 10, 3, 3, 5, 5, 8, 14, 15,
3516 15, 14, 14, 14, 14, 14, 14, 4, 4, 5, 5, 5, 4, 4, 8, 9
3518 3, 4, 5, 4, 4, 6, 9, 13, 13, 2, 3, 7, 9, 14, 14, 14,
3519 14, 14, 14, 14, 14, 14, 14, 5, 9, 10, 6, 3, 4, 6, 14, 14
3521 3, 5, 6, 6, 10, 13, 13, 7, 7, 3, 3, 5, 5, 6, 7, 8,
3522 10, 10, 12, 13, 13, 13, 13, 3, 4, 4, 5, 5, 4, 5, 5, 6
3524 3, 5, 6, 6, 9, 12, 14, 7, 7, 3, 3, 5, 5, 6, 8, 10,
3525 12, 13, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3527 3, 5, 6, 6, 8, 12, 13, 7, 7, 3, 3, 5, 5, 6, 9, 10,
3528 12, 14, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3530 3, 4, 6, 5, 8, 11, 13, 7, 7, 3, 3, 5, 5, 7, 9, 11,
3531 13, 13, 13, 13, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 7, 7
3533 3, 4, 5, 5, 7, 9, 13, 8, 8, 3, 3, 5, 5, 8, 10, 14,
3534 14, 13, 13, 13, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 8, 8
3536 3, 4, 5, 4, 6, 9, 13, 9, 8, 2, 3, 6, 6, 9, 13, 14,
3537 14, 13, 13, 13, 13, 14, 14, 4, 5, 5, 6, 6, 4, 4, 8, 10
3539 3, 4, 5, 4, 6, 7, 11, 9, 9, 2, 2, 6, 6, 10, 13, 14,
3540 14, 13, 13, 13, 13, 13, 13, 5, 6, 6, 6, 6, 5, 5, 10, 11
3542 2, 4, 5, 4, 5, 7, 13, 13, 13, 2, 2, 9, 9, 12, 13, 14,
3543 14, 14, 14, 14, 14, 14, 14, 8, 9, 11, 8, 6, 6, 7, 13, 13
3547 const VP40_QMAT: &[i16; 64] = &[
3548 16, 17, 18, 20, 22, 24, 26, 28,
3549 17, 18, 20, 22, 24, 26, 28, 32,
3550 18, 20, 22, 24, 26, 28, 32, 36,
3551 20, 22, 24, 26, 28, 32, 36, 40,
3552 22, 24, 26, 28, 32, 36, 40, 44,
3553 24, 26, 28, 32, 36, 40, 44, 48,
3554 26, 28, 32, 36, 40, 44, 48, 52,
3555 28, 32, 36, 40, 44, 48, 52, 56
3557 const VP40_DC_Y_SCALES: [i16; 64] = [
3558 180, 180, 180, 180, 180, 180, 175, 170,
3559 165, 160, 157, 155, 152, 150, 147, 145,
3560 142, 140, 137, 135, 132, 130, 127, 125,
3561 122, 120, 117, 115, 112, 110, 107, 105,
3562 102, 100, 97, 95, 92, 90, 87, 85,
3563 82, 80, 77, 75, 72, 70, 67, 65,
3564 62, 60, 57, 55, 52, 50, 47, 45,
3565 42, 40, 37, 35, 32, 30, 27, 25
3567 const VP40_DC_C_SCALES: [i16; 64] = [
3568 150, 150, 150, 150, 150, 150, 150, 150,
3569 150, 150, 150, 150, 150, 150, 147, 145,
3570 142, 140, 137, 135, 132, 130, 127, 125,
3571 122, 120, 117, 115, 112, 110, 107, 105,
3572 102, 100, 97, 95, 92, 90, 87, 85,
3573 82, 80, 77, 75, 72, 70, 67, 65,
3574 62, 60, 57, 55, 52, 50, 47, 45,
3575 42, 40, 37, 35, 32, 30, 27, 25
3577 const VP40_AC_SCALES: [i16; 64] = [
3578 500, 475, 450, 430, 410, 390, 370, 350,
3579 330, 315, 300, 285, 270, 260, 250, 240,
3580 230, 220, 210, 200, 190, 185, 180, 170,
3581 160, 150, 143, 135, 128, 120, 113, 106,
3582 100, 94, 90, 85, 80, 75, 70, 66,
3583 62, 57, 52, 49, 45, 41, 38, 35,
3584 33, 30, 27, 24, 22, 20, 18, 16,
3585 14, 12, 10, 9, 7, 6, 4, 1
3588 const VP40_MBPAT_CODES: [[u8; 14]; 2] = [
3589 [ 0b000, 0b1111, 0b1001, 0b010, 0b1101, 0b01110, 0b1011, 0b001, 0b01111, 0b1000, 0b0110, 0b1110, 0b1100, 0b1010 ],
3590 [ 0b0111, 0b1010, 0b1001, 0b1100, 0b1000, 0b01101, 0b000, 0b1110, 0b01100, 0b1101, 0b001, 0b1011, 0b1111, 0b010 ]
3592 const VP40_MBPAT_BITS: [[u8; 14]; 2] = [
3593 [ 3, 4, 4, 3, 4, 5, 4, 3, 5, 4, 4, 4, 4, 4 ],
3594 [ 4, 4, 4, 4, 4, 5, 3, 4, 5, 4, 3, 4, 4, 3 ]
3596 const VP40_BP_PREDICTOR: [u8; 15] = [ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1 ];
3597 const VP40_MV_X_CODES: [[u32; 63]; 7] = [
3599 0x06A, 0x11A, 0x18E, 0x237, 0x04A, 0x236, 0x07A, 0x0D6,
3600 0x07E, 0x1FD, 0x08C, 0x0D7, 0x087, 0x183, 0x03C, 0x061,
3601 0x047, 0x069, 0x040, 0x048, 0x049, 0x086, 0x013, 0x0D2,
3602 0x01C, 0x042, 0x025, 0x01B, 0x013, 0x005, 0x000, 0x007,
3603 0x005, 0x01B, 0x019, 0x019, 0x008, 0x045, 0x01D, 0x0C6,
3604 0x068, 0x090, 0x041, 0x04B, 0x031, 0x18F, 0x062, 0x03E,
3605 0x044, 0x068, 0x030, 0x182, 0x0C0, 0x1A7, 0x091, 0x092,
3606 0x07B, 0x0FF, 0x1A6, 0x1FC, 0x06A, 0x093, 0x06B
3608 0x039, 0x259, 0x01B, 0x1D1, 0x137, 0x1D0, 0x01A, 0x1B5,
3609 0x01D, 0x4BC, 0x06C, 0x038, 0x071, 0x02D, 0x07D, 0x075,
3610 0x019, 0x0E9, 0x037, 0x015, 0x01E, 0x0DB, 0x04C, 0x070,
3611 0x00D, 0x00C, 0x027, 0x004, 0x002, 0x000, 0x005, 0x007,
3612 0x006, 0x002, 0x008, 0x024, 0x00C, 0x03B, 0x01E, 0x09A,
3613 0x00E, 0x069, 0x04A, 0x12D, 0x035, 0x0F9, 0x018, 0x07F,
3614 0x00F, 0x0F8, 0x07E, 0x25F, 0x068, 0x02C, 0x014, 0x258,
3615 0x136, 0x4BD, 0x12E, 0x1B4, 0x017, 0x039, 0x01F
3617 0x029, 0x3CB, 0x1F5, 0x263, 0x1F4, 0x3DA, 0x050, 0x260,
3618 0x1EC, 0x3D3, 0x109, 0x3D2, 0x051, 0x792, 0x0F3, 0x09A,
3619 0x0F7, 0x132, 0x0C1, 0x1E8, 0x02A, 0x085, 0x061, 0x1F7,
3620 0x078, 0x0C7, 0x023, 0x07C, 0x012, 0x00B, 0x00E, 0x00D,
3621 0x000, 0x005, 0x003, 0x004, 0x019, 0x020, 0x03F, 0x043,
3622 0x062, 0x09F, 0x04E, 0x181, 0x02B, 0x137, 0x0F5, 0x089,
3623 0x0C6, 0x262, 0x088, 0x3C8, 0x1F6, 0x3CA, 0x09E, 0x261,
3624 0x136, 0x108, 0x133, 0x793, 0x180, 0x3DB, 0x045
3626 0x001, 0x1C7, 0x067, 0x0B5, 0x066, 0x139, 0x099, 0x0B4,
3627 0x0C3, 0x130, 0x000, 0x131, 0x09E, 0x0B7, 0x02C, 0x001,
3628 0x028, 0x138, 0x04B, 0x031, 0x060, 0x091, 0x003, 0x09D,
3629 0x017, 0x04D, 0x031, 0x070, 0x007, 0x03A, 0x007, 0x002,
3630 0x00B, 0x001, 0x00F, 0x008, 0x00D, 0x004, 0x00A, 0x00D,
3631 0x019, 0x002, 0x03B, 0x04A, 0x015, 0x0C2, 0x018, 0x032,
3632 0x072, 0x1C6, 0x029, 0x1C5, 0x049, 0x121, 0x01B, 0x030,
3633 0x01A, 0x1C4, 0x09F, 0x0B6, 0x019, 0x120, 0x073
3635 0x023, 0x1C8, 0x043, 0x110, 0x00C, 0x153, 0x022, 0x111,
3636 0x00F, 0x042, 0x023, 0x1C9, 0x02A, 0x01B, 0x073, 0x045,
3637 0x06E, 0x089, 0x06C, 0x01A, 0x06F, 0x0B6, 0x00B, 0x0E5,
3638 0x025, 0x020, 0x029, 0x04D, 0x002, 0x014, 0x01A, 0x017,
3639 0x01E, 0x027, 0x018, 0x028, 0x01F, 0x000, 0x006, 0x010,
3640 0x007, 0x00B, 0x003, 0x004, 0x01D, 0x02C, 0x019, 0x02B,
3641 0x009, 0x055, 0x038, 0x00E, 0x024, 0x0A8, 0x00A, 0x099,
3642 0x05A, 0x098, 0x06D, 0x152, 0x02B, 0x0B7, 0x001
3644 0x03D, 0x0B1, 0x0DD, 0x1F6, 0x0C5, 0x188, 0x037, 0x03F,
3645 0x01E, 0x189, 0x00F, 0x03E, 0x06A, 0x1F7, 0x061, 0x079,
3646 0x018, 0x0B0, 0x00E, 0x0B3, 0x00C, 0x0DF, 0x006, 0x0DC,
3647 0x019, 0x0DE, 0x027, 0x00E, 0x01A, 0x063, 0x00F, 0x00E,
3648 0x014, 0x07C, 0x036, 0x06B, 0x03F, 0x060, 0x008, 0x074,
3649 0x009, 0x078, 0x012, 0x00D, 0x015, 0x02D, 0x002, 0x01C,
3650 0x005, 0x03B, 0x000, 0x034, 0x019, 0x026, 0x010, 0x075,
3651 0x002, 0x036, 0x023, 0x0B2, 0x022, 0x0FA, 0x017
3653 0x015, 0x0DD, 0x03E, 0x16E, 0x04C, 0x012, 0x05D, 0x0B6,
3654 0x06F, 0x1F1, 0x069, 0x1F0, 0x01D, 0x16F, 0x002, 0x06B,
3655 0x00C, 0x0DC, 0x068, 0x09B, 0x07D, 0x09A, 0x00D, 0x013,
3656 0x008, 0x0F9, 0x02C, 0x012, 0x033, 0x04F, 0x00D, 0x005,
3657 0x012, 0x03F, 0x032, 0x013, 0x03B, 0x005, 0x02F, 0x05A,
3658 0x03F, 0x01C, 0x03A, 0x008, 0x036, 0x05C, 0x010, 0x000,
3659 0x00C, 0x04E, 0x003, 0x06A, 0x00E, 0x003, 0x014, 0x01E,
3660 0x01C, 0x00F, 0x018, 0x023, 0x01E, 0x022, 0x002
3663 const VP40_MV_X_BITS: [[u8; 63]; 7] = [
3665 7, 9, 9, 10, 8, 10, 8, 9, 8, 10, 8, 9, 8, 9, 7, 7,
3666 7, 8, 7, 8, 7, 8, 6, 8, 6, 7, 6, 6, 5, 4, 2, 3,
3667 3, 5, 5, 6, 5, 7, 6, 8, 7, 8, 7, 8, 7, 9, 7, 7,
3668 7, 8, 7, 9, 8, 9, 8, 9, 8, 9, 9, 10, 8, 9, 7
3670 7, 10, 8, 10, 9, 10, 8, 10, 8, 11, 8, 9, 8, 9, 8, 8,
3671 7, 9, 7, 8, 7, 9, 7, 8, 6, 7, 6, 6, 4, 4, 3, 3,
3672 3, 3, 4, 6, 5, 7, 6, 8, 6, 8, 7, 9, 7, 9, 7, 8,
3673 7, 9, 8, 10, 8, 9, 8, 10, 9, 11, 9, 10, 8, 9, 7
3675 7, 10, 9, 10, 9, 10, 8, 10, 9, 10, 9, 10, 8, 11, 8, 8,
3676 8, 9, 8, 9, 7, 8, 7, 9, 7, 8, 6, 7, 5, 5, 4, 4,
3677 2, 3, 3, 4, 5, 6, 6, 7, 7, 8, 7, 9, 7, 9, 8, 8,
3678 8, 10, 8, 10, 9, 10, 8, 10, 9, 9, 9, 11, 9, 10, 7
3680 6, 9, 8, 9, 8, 9, 8, 9, 8, 9, 7, 9, 8, 9, 7, 7,
3681 7, 9, 7, 8, 7, 8, 6, 8, 6, 7, 6, 7, 5, 6, 4, 4,
3682 4, 4, 4, 4, 4, 4, 4, 5, 5, 6, 6, 7, 6, 8, 6, 7,
3683 7, 9, 7, 9, 7, 9, 7, 8, 7, 9, 8, 9, 7, 9, 7
3685 6, 9, 8, 9, 7, 9, 7, 9, 7, 8, 7, 9, 7, 8, 7, 7,
3686 7, 8, 7, 8, 7, 8, 6, 8, 6, 7, 6, 7, 5, 6, 5, 5,
3687 5, 6, 5, 6, 5, 5, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6,
3688 5, 7, 6, 7, 6, 8, 6, 8, 7, 8, 7, 9, 7, 8, 5
3690 6, 8, 8, 9, 8, 9, 7, 8, 7, 9, 7, 8, 7, 9, 7, 7,
3691 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 7, 6, 7, 5, 5,
3692 5, 7, 6, 7, 6, 7, 5, 7, 5, 7, 5, 6, 5, 6, 4, 5,
3693 4, 6, 4, 6, 5, 6, 5, 7, 5, 7, 6, 8, 6, 8, 5
3695 5, 8, 7, 9, 7, 8, 7, 8, 7, 9, 7, 9, 7, 9, 6, 7,
3696 6, 8, 7, 8, 7, 8, 6, 8, 6, 8, 6, 7, 6, 7, 5, 5,
3697 5, 7, 6, 7, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 5, 5,
3698 5, 7, 5, 7, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 3
3701 const VP40_MV_Y_CODES: [[u32; 63]; 7] = [
3703 0x052, 0x14C, 0x1FA, 0x124, 0x082, 0x29E, 0x08E, 0x24B,
3704 0x09C, 0x3F7, 0x086, 0x114, 0x083, 0x3A5, 0x0FA, 0x04F,
3705 0x0FB, 0x13B, 0x0FC, 0x172, 0x044, 0x173, 0x051, 0x087,
3706 0x05F, 0x0BA, 0x026, 0x05E, 0x016, 0x015, 0x006, 0x001,
3707 0x000, 0x01C, 0x01E, 0x075, 0x03B, 0x0FF, 0x025, 0x0BB,
3708 0x07C, 0x08B, 0x048, 0x171, 0x042, 0x14E, 0x046, 0x0FE,
3709 0x040, 0x13A, 0x093, 0x115, 0x08F, 0x3F6, 0x170, 0x29F,
3710 0x1D1, 0x24A, 0x1D3, 0x3A4, 0x1D0, 0x14D, 0x050
3712 0x0DE, 0x223, 0x136, 0x7C5, 0x12F, 0x4A1, 0x3D7, 0x7AC,
3713 0x133, 0x7C4, 0x1B8, 0x222, 0x096, 0x251, 0x095, 0x1F0,
3714 0x0DA, 0x110, 0x09A, 0x360, 0x0DD, 0x12E, 0x048, 0x092,
3715 0x078, 0x098, 0x027, 0x045, 0x01A, 0x010, 0x005, 0x000,
3716 0x001, 0x00E, 0x00C, 0x023, 0x03F, 0x0F4, 0x07D, 0x089,
3717 0x07B, 0x1BE, 0x0F9, 0x3E3, 0x0F3, 0x127, 0x0DB, 0x1EA,
3718 0x0D9, 0x6E7, 0x1BF, 0x4A0, 0x1B1, 0x6E6, 0x137, 0x7AD,
3719 0x126, 0x6C2, 0x132, 0x6C3, 0x129, 0x372, 0x0F2
3721 0x016, 0x09C, 0x13C, 0x09E, 0x12B, 0x0BA, 0x181, 0x317,
3722 0x084, 0x04E, 0x026, 0x316, 0x180, 0x05C, 0x0C1, 0x02F,
3723 0x010, 0x045, 0x012, 0x189, 0x024, 0x13D, 0x066, 0x023,
3724 0x067, 0x0C6, 0x024, 0x04B, 0x011, 0x032, 0x00D, 0x000,
3725 0x007, 0x005, 0x003, 0x003, 0x005, 0x020, 0x008, 0x025,
3726 0x026, 0x04F, 0x061, 0x02B, 0x04E, 0x18A, 0x043, 0x09F,
3727 0x014, 0x254, 0x094, 0x310, 0x085, 0x311, 0x02A, 0x0BB,
3728 0x18F, 0x255, 0x09D, 0x09F, 0x18E, 0x044, 0x026
3730 0x061, 0x12A, 0x00D, 0x3BD, 0x089, 0x109, 0x18E, 0x210,
3731 0x1D3, 0x211, 0x088, 0x019, 0x085, 0x018, 0x0E8, 0x0CE,
3732 0x040, 0x119, 0x045, 0x1D2, 0x04B, 0x1DD, 0x062, 0x094,
3733 0x075, 0x00C, 0x027, 0x00D, 0x002, 0x026, 0x006, 0x01E,
3734 0x00D, 0x01F, 0x001, 0x00A, 0x002, 0x007, 0x00B, 0x000,
3735 0x01C, 0x076, 0x032, 0x007, 0x024, 0x0C0, 0x007, 0x041,
3736 0x002, 0x18F, 0x047, 0x1DC, 0x043, 0x12B, 0x0CF, 0x118,
3737 0x0C6, 0x3BC, 0x08D, 0x3BF, 0x0C1, 0x3BE, 0x066
3739 0x007, 0x14D, 0x0A0, 0x09E, 0x0CF, 0x39C, 0x0A1, 0x39D,
3740 0x0AB, 0x1C5, 0x026, 0x14C, 0x025, 0x19C, 0x03F, 0x0E1,
3741 0x066, 0x1CF, 0x03E, 0x1C4, 0x072, 0x04E, 0x006, 0x0AA,
3742 0x01C, 0x0E6, 0x032, 0x051, 0x03B, 0x005, 0x01F, 0x018,
3743 0x002, 0x03A, 0x000, 0x036, 0x005, 0x008, 0x008, 0x016,
3744 0x009, 0x00D, 0x003, 0x02F, 0x01E, 0x02E, 0x01A, 0x02B,
3745 0x00C, 0x024, 0x01E, 0x0E0, 0x004, 0x0A7, 0x054, 0x1C7,
3746 0x052, 0x19D, 0x03A, 0x09F, 0x03B, 0x1C6, 0x037
3748 0x02A, 0x039, 0x025, 0x115, 0x024, 0x1FA, 0x02F, 0x114,
3749 0x075, 0x038, 0x0FC, 0x036, 0x01E, 0x1FB, 0x07F, 0x068,
3750 0x016, 0x037, 0x01F, 0x05C, 0x013, 0x08B, 0x001, 0x0FB,
3751 0x021, 0x044, 0x02B, 0x06B, 0x03B, 0x00C, 0x01C, 0x019,
3752 0x001, 0x020, 0x016, 0x07C, 0x00C, 0x074, 0x00A, 0x01C,
3753 0x012, 0x069, 0x00F, 0x06A, 0x014, 0x011, 0x01E, 0x017,
3754 0x002, 0x031, 0x01B, 0x030, 0x00D, 0x000, 0x001, 0x01D,
3755 0x023, 0x01A, 0x01D, 0x05D, 0x010, 0x0FA, 0x013
3757 0x012, 0x026, 0x041, 0x022, 0x01A, 0x0A9, 0x04C, 0x1B2,
3758 0x05C, 0x0A8, 0x058, 0x1B3, 0x040, 0x079, 0x00C, 0x055,
3759 0x01F, 0x0D8, 0x076, 0x023, 0x05F, 0x078, 0x00B, 0x01B,
3760 0x02D, 0x010, 0x037, 0x06D, 0x032, 0x00A, 0x01A, 0x01E,
3761 0x01F, 0x02B, 0x00D, 0x077, 0x031, 0x05D, 0x038, 0x027,
3762 0x00C, 0x0E9, 0x033, 0x05E, 0x030, 0x04D, 0x00A, 0x021,
3763 0x007, 0x03D, 0x039, 0x0E8, 0x00B, 0x059, 0x014, 0x027,
3764 0x011, 0x075, 0x00E, 0x009, 0x008, 0x012, 0x000
3767 const VP40_MV_Y_BITS: [[u8; 63]; 7] = [
3769 7, 9, 9, 9, 8, 10, 8, 10, 8, 10, 8, 9, 8, 10, 8, 7,
3770 8, 9, 8, 9, 7, 9, 7, 8, 7, 8, 6, 7, 5, 5, 3, 2,
3771 2, 5, 5, 7, 6, 8, 6, 8, 7, 8, 7, 9, 7, 9, 7, 8,
3772 7, 9, 8, 9, 8, 10, 9, 10, 9, 10, 9, 10, 9, 9, 7
3774 8, 10, 9, 11, 9, 11, 10, 11, 9, 11, 9, 10, 8, 10, 8, 9,
3775 8, 9, 8, 10, 8, 9, 7, 8, 7, 8, 6, 7, 5, 5, 3, 2,
3776 2, 4, 4, 6, 6, 8, 7, 8, 7, 9, 8, 10, 8, 9, 8, 9,
3777 8, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 10, 8
3779 7, 9, 9, 10, 9, 10, 9, 10, 8, 9, 8, 10, 9, 9, 8, 8,
3780 7, 9, 7, 9, 7, 9, 7, 8, 7, 8, 6, 7, 5, 6, 4, 3,
3781 3, 3, 3, 4, 4, 6, 5, 7, 6, 8, 7, 8, 7, 9, 7, 8,
3782 7, 10, 8, 10, 8, 10, 8, 10, 9, 10, 9, 10, 9, 9, 7
3784 7, 9, 8, 10, 8, 9, 9, 10, 9, 10, 8, 9, 8, 9, 8, 8,
3785 7, 9, 7, 9, 7, 9, 7, 8, 7, 7, 6, 7, 5, 6, 4, 5,
3786 4, 5, 3, 4, 3, 4, 4, 5, 5, 7, 6, 7, 6, 8, 6, 7,
3787 6, 9, 7, 9, 7, 9, 8, 9, 8, 10, 8, 10, 8, 10, 7
3789 6, 9, 8, 9, 8, 10, 8, 10, 8, 9, 7, 9, 7, 9, 7, 8,
3790 7, 9, 7, 9, 7, 8, 6, 8, 6, 8, 6, 7, 6, 6, 5, 5,
3791 4, 6, 4, 6, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6,
3792 5, 7, 6, 8, 6, 8, 7, 9, 7, 9, 7, 9, 7, 9, 6
3794 6, 8, 7, 9, 7, 9, 7, 9, 7, 8, 8, 8, 7, 9, 7, 7,
3795 6, 8, 7, 8, 6, 8, 6, 8, 6, 7, 6, 7, 6, 6, 5, 5,
3796 4, 6, 5, 7, 5, 7, 5, 6, 5, 7, 5, 7, 5, 6, 5, 5,
3797 4, 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 8, 6, 8, 5
3799 5, 7, 7, 8, 7, 8, 7, 9, 7, 8, 7, 9, 7, 8, 6, 7,
3800 6, 8, 7, 8, 7, 8, 6, 7, 6, 7, 6, 7, 6, 6, 5, 5,
3801 5, 6, 5, 7, 6, 7, 6, 7, 5, 8, 6, 7, 6, 7, 5, 6,
3802 5, 7, 6, 8, 5, 7, 5, 6, 5, 7, 5, 6, 5, 6, 3
3806 const VP40_LOOP_STRENGTH: [i16; 64] = [
3807 30, 25, 20, 20, 15, 15, 14, 14,
3808 13, 13, 12, 12, 11, 11, 10, 10,
3809 9, 9, 8, 8, 7, 7, 7, 7,
3810 6, 6, 6, 6, 5, 5, 5, 5,
3811 4, 4, 4, 4, 3, 3, 3, 3,
3812 2, 2, 2, 2, 2, 2, 2, 2,
3813 2, 2, 2, 2, 2, 2, 2, 2,
3814 1, 1, 1, 1, 1, 1, 1, 1
3816 const VP40_MV_LUT_INDEX: [usize; 32] = [
3817 0, 1, 2, 2, 3, 3, 3, 3,
3818 4, 4, 4, 4, 4, 4, 4, 4,
3819 5, 5, 5, 5, 5, 5, 5, 5,
3820 6, 6, 6, 6, 6, 6, 6, 6