]> git.nihav.org Git - nihav.git/blame_incremental - codecs/vp3.rs
add MPEG-4 ASP decoder
[nihav.git] / codecs / vp3.rs
... / ...
CommitLineData
1use std::mem;
2use std::ptr;
3use nihav_core::codecs::*;
4use nihav_codec_support::codecs::{MV, ZERO_MV, ZIGZAG};
5use nihav_codec_support::codecs::blockdsp::*;
6use nihav_core::io::bitreader::*;
7use nihav_core::io::codebook::*;
8use nihav_core::io::intcode::*;
9use super::vpcommon::*;
10
11#[derive(Clone,Copy,Debug,PartialEq)]
12enum SBState {
13 Coded,
14 Partial,
15 Uncoded,
16}
17
18fn map_idx(idx: usize) -> u8 {
19 idx as u8
20}
21
22struct VP30Codes {
23 dc_cb: [Codebook<u8>; 5],
24 ac_i_cb: [Codebook<u8>; 5],
25 ac_p_cb: [Codebook<u8>; 5],
26 mbtype_cb: Codebook<VPMBType>,
27}
28
29fn map_mbt(idx: usize) -> VPMBType {
30 VP30_MBTYPE_SYMS[idx]
31}
32
33impl VP30Codes {
34 fn new() -> Self {
35 let dc_cb;
36 let ac_i_cb;
37 let ac_p_cb;
38 let mut cr = TableCodebookDescReader::new(&VP30_MBTYPE_CODES, &VP30_MBTYPE_BITS, map_mbt);
39 let mbtype_cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
40 unsafe {
41 let mut udc_cb: mem::MaybeUninit::<[Codebook<u8>; 5]> = mem::MaybeUninit::uninit();
42 let mut uac_i_cb: mem::MaybeUninit::<[Codebook<u8>; 5]> = mem::MaybeUninit::uninit();
43 let mut uac_p_cb: mem::MaybeUninit::<[Codebook<u8>; 5]> = mem::MaybeUninit::uninit();
44 for i in 0..5 {
45 let mut cr = TableCodebookDescReader::new(&VP30_DC_CODES[i], &VP30_DC_BITS[i], map_idx);
46 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
47 ptr::write(&mut (*udc_cb.as_mut_ptr())[i], cb);
48 let mut cr = TableCodebookDescReader::new(&VP30_AC_INTRA_CODES[i], &VP30_AC_INTRA_BITS[i], map_idx);
49 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
50 ptr::write(&mut (*uac_i_cb.as_mut_ptr())[i], cb);
51 let mut cr = TableCodebookDescReader::new(&VP30_AC_INTER_CODES[i], &VP30_AC_INTER_BITS[i], map_idx);
52 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
53 ptr::write(&mut (*uac_p_cb.as_mut_ptr())[i], cb);
54 }
55 dc_cb = udc_cb.assume_init();
56 ac_i_cb = uac_i_cb.assume_init();
57 ac_p_cb = uac_p_cb.assume_init();
58 }
59 Self { dc_cb, ac_i_cb, ac_p_cb, mbtype_cb }
60 }
61}
62
63struct VP31Codes {
64 dc_cb: [Codebook<u8>; 16],
65 ac0_cb: [Codebook<u8>; 16],
66 ac1_cb: [Codebook<u8>; 16],
67 ac2_cb: [Codebook<u8>; 16],
68 ac3_cb: [Codebook<u8>; 16],
69}
70
71impl VP31Codes {
72 fn new() -> Self {
73 let dc_cb;
74 let ac0_cb;
75 let ac1_cb;
76 let ac2_cb;
77 let ac3_cb;
78 unsafe {
79 let mut udc_cb: mem::MaybeUninit::<[Codebook<u8>; 16]> = mem::MaybeUninit::uninit();
80 let mut uac0_cb: mem::MaybeUninit::<[Codebook<u8>; 16]> = mem::MaybeUninit::uninit();
81 let mut uac1_cb: mem::MaybeUninit::<[Codebook<u8>; 16]> = mem::MaybeUninit::uninit();
82 let mut uac2_cb: mem::MaybeUninit::<[Codebook<u8>; 16]> = mem::MaybeUninit::uninit();
83 let mut uac3_cb: mem::MaybeUninit::<[Codebook<u8>; 16]> = mem::MaybeUninit::uninit();
84 for i in 0..16 {
85 let mut cr = TableCodebookDescReader::new(&VP31_DC_CODES[i], &VP31_DC_BITS[i], map_idx);
86 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
87 ptr::write(&mut (*udc_cb.as_mut_ptr())[i], cb);
88
89 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT0_CODES[i], &VP31_AC_CAT0_BITS[i], map_idx);
90 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
91 ptr::write(&mut (*uac0_cb.as_mut_ptr())[i], cb);
92 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT1_CODES[i], &VP31_AC_CAT1_BITS[i], map_idx);
93 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
94 ptr::write(&mut (*uac1_cb.as_mut_ptr())[i], cb);
95 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT2_CODES[i], &VP31_AC_CAT2_BITS[i], map_idx);
96 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
97 ptr::write(&mut (*uac2_cb.as_mut_ptr())[i], cb);
98 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT3_CODES[i], &VP31_AC_CAT3_BITS[i], map_idx);
99 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
100 ptr::write(&mut (*uac3_cb.as_mut_ptr())[i], cb);
101 }
102 dc_cb = udc_cb.assume_init();
103 ac0_cb = uac0_cb.assume_init();
104 ac1_cb = uac1_cb.assume_init();
105 ac2_cb = uac2_cb.assume_init();
106 ac3_cb = uac3_cb.assume_init();
107 }
108 Self { dc_cb, ac0_cb, ac1_cb, ac2_cb, ac3_cb }
109 }
110 fn new_vp4() -> VP31Codes {
111 let dc_cb;
112 let ac0_cb;
113 let ac1_cb;
114 let ac2_cb;
115 let ac3_cb;
116 unsafe {
117 let mut udc_cb: mem::MaybeUninit::<[Codebook<u8>; 16]> = mem::MaybeUninit::uninit();
118 let mut uac0_cb: mem::MaybeUninit::<[Codebook<u8>; 16]> = mem::MaybeUninit::uninit();
119 let mut uac1_cb: mem::MaybeUninit::<[Codebook<u8>; 16]> = mem::MaybeUninit::uninit();
120 let mut uac2_cb: mem::MaybeUninit::<[Codebook<u8>; 16]> = mem::MaybeUninit::uninit();
121 let mut uac3_cb: mem::MaybeUninit::<[Codebook<u8>; 16]> = mem::MaybeUninit::uninit();
122 for i in 0..16 {
123 let mut cr = TableCodebookDescReader::new(&VP40_DC_CODES[i], &VP40_DC_BITS[i], map_idx);
124 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
125 ptr::write(&mut (*udc_cb.as_mut_ptr())[i], cb);
126
127 let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT0_CODES[i], &VP40_AC_CAT0_BITS[i], map_idx);
128 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
129 ptr::write(&mut (*uac0_cb.as_mut_ptr())[i], cb);
130 let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT1_CODES[i], &VP40_AC_CAT1_BITS[i], map_idx);
131 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
132 ptr::write(&mut (*uac1_cb.as_mut_ptr())[i], cb);
133 let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT2_CODES[i], &VP40_AC_CAT2_BITS[i], map_idx);
134 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
135 ptr::write(&mut (*uac2_cb.as_mut_ptr())[i], cb);
136 let mut cr = TableCodebookDescReader::new(&VP40_AC_CAT3_CODES[i], &VP40_AC_CAT3_BITS[i], map_idx);
137 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
138 ptr::write(&mut (*uac3_cb.as_mut_ptr())[i], cb);
139 }
140 dc_cb = udc_cb.assume_init();
141 ac0_cb = uac0_cb.assume_init();
142 ac1_cb = uac1_cb.assume_init();
143 ac2_cb = uac2_cb.assume_init();
144 ac3_cb = uac3_cb.assume_init();
145 }
146 VP31Codes { dc_cb, ac0_cb, ac1_cb, ac2_cb, ac3_cb }
147 }
148}
149
150struct VP40AuxCodes {
151 mv_x_cb: [Codebook<i8>; 7],
152 mv_y_cb: [Codebook<i8>; 7],
153 mbpat_cb: [Codebook<u8>; 2],
154}
155
156fn map_mv(idx: usize) -> i8 {
157 (idx as i8) - 31
158}
159
160impl VP40AuxCodes {
161 fn new() -> Self {
162 let mv_x_cb;
163 let mv_y_cb;
164 unsafe {
165 let mut umv_x_cb: mem::MaybeUninit::<[Codebook<i8>; 7]> = mem::MaybeUninit::uninit();
166 let mut umv_y_cb: mem::MaybeUninit::<[Codebook<i8>; 7]> = mem::MaybeUninit::uninit();
167 for i in 0..7 {
168 let mut cr = TableCodebookDescReader::new(&VP40_MV_X_CODES[i], &VP40_MV_X_BITS[i], map_mv);
169 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
170 ptr::write(&mut (*umv_x_cb.as_mut_ptr())[i], cb);
171 let mut cr = TableCodebookDescReader::new(&VP40_MV_Y_CODES[i], &VP40_MV_Y_BITS[i], map_mv);
172 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
173 ptr::write(&mut (*umv_y_cb.as_mut_ptr())[i], cb);
174 }
175 mv_x_cb = umv_x_cb.assume_init();
176 mv_y_cb = umv_y_cb.assume_init();
177 }
178 let mut cr0 = TableCodebookDescReader::new(&VP40_MBPAT_CODES[0], &VP40_MBPAT_BITS[0], map_idx);
179 let mut cr1 = TableCodebookDescReader::new(&VP40_MBPAT_CODES[1], &VP40_MBPAT_BITS[1], map_idx);
180 let mbpat_cb = [Codebook::new(&mut cr0, CodebookMode::MSB).unwrap(),
181 Codebook::new(&mut cr1, CodebookMode::MSB).unwrap()];
182 Self { mv_x_cb, mv_y_cb, mbpat_cb }
183 }
184}
185
186#[allow(clippy::large_enum_variant)]
187enum Codes {
188 None,
189 VP30(VP30Codes),
190 VP31(VP31Codes),
191}
192
193#[derive(Clone)]
194struct Block {
195 btype: VPMBType,
196 coeffs: [i16; 64],
197 has_ac: bool,
198 idx: usize,
199 mv: MV,
200 coded: bool,
201}
202
203impl Block {
204 fn new() -> Self {
205 Self {
206 btype: VPMBType::Intra,
207 coeffs: [0; 64],
208 has_ac: false,
209 idx: 0,
210 mv: ZERO_MV,
211 coded: false,
212 }
213 }
214}
215
216type ReadRunFunc = fn (&mut BitReader) -> DecoderResult<usize>;
217
218const VP31_LONG_RUN_BASE: [usize; 7] = [ 1, 2, 4, 6, 10, 18, 34 ];
219const VP31_LONG_RUN_BITS: [u8; 7] = [ 0, 1, 1, 2, 3, 4, 12 ];
220fn read_long_run(br: &mut BitReader) -> DecoderResult<usize> {
221 let pfx = br.read_code(UintCodeType::LimitedUnary(6, 0))? as usize;
222 if pfx == 0 { return Ok(1); }
223 Ok(VP31_LONG_RUN_BASE[pfx] + (br.read(VP31_LONG_RUN_BITS[pfx])? as usize))
224}
225
226const VP31_SHORT_RUN_BASE: [usize; 6] = [ 1, 3, 5, 7, 11, 15 ];
227const VP31_SHORT_RUN_BITS: [u8; 6] = [ 1, 1, 1, 2, 2, 4 ];
228fn read_short_run(br: &mut BitReader) -> DecoderResult<usize> {
229 let pfx = br.read_code(UintCodeType::LimitedUnary(5, 0))? as usize;
230 Ok(VP31_SHORT_RUN_BASE[pfx] + (br.read(VP31_SHORT_RUN_BITS[pfx])? as usize))
231}
232
233fn read_mb_run(br: &mut BitReader) -> DecoderResult<usize> {
234 let pfx = br.read_code(UintCodeType::LimitedUnary(10, 0))? as usize;
235 if pfx == 10 { unimplemented!(); }
236 if pfx < 2 {
237 Ok(pfx + 1)
238 } else {
239 let base = (1 << (pfx - 1)) + 1;
240 let bits = (pfx - 1) as u8;
241 let add_bits = br.read(bits)? as usize;
242 Ok(base + add_bits)
243 }
244}
245
246struct BitRunDecoder {
247 value: bool,
248 run: usize,
249 read_run: ReadRunFunc,
250}
251
252impl BitRunDecoder {
253 fn new(br: &mut BitReader, read_run: ReadRunFunc) -> DecoderResult<Self> {
254 let value = !br.read_bool()?; // it will be flipped before run decoding
255 Ok(Self { value, run: 0, read_run })
256 }
257 fn get_val(&mut self, br: &mut BitReader) -> DecoderResult<bool> {
258 if self.run == 0 {
259 self.value = !self.value;
260 self.run = (self.read_run)(br)?;
261 }
262 self.run -= 1;
263 Ok(self.value)
264 }
265}
266
267const VP30_NE0_BITS: [u8; 5] = [ 2, 2, 3, 4, 8 ];
268const VP30_NE0_BASE: [usize; 5] = [ 1, 5, 9, 17, 33 ];
269fn vp30_read_ne_run0(br: &mut BitReader) -> DecoderResult<usize> {
270 let len = br.read_code(UintCodeType::LimitedUnary(4, 0))? as usize;
271 Ok(VP30_NE0_BASE[len] + (br.read(VP30_NE0_BITS[len])? as usize))
272}
273fn vp30_read_ne_run1(br: &mut BitReader) -> DecoderResult<usize> {
274 let len = br.read_code(UintCodeType::LimitedUnary(6, 0))? as usize;
275 if len == 0 {
276 Ok((br.read(1)? as usize) + 1)
277 } else if len < 6 {
278 Ok(len + 2)
279 } else {
280 Ok((br.read(8)? as usize) + 8)
281 }
282}
283fn vp30_read_coded_run0(br: &mut BitReader) -> DecoderResult<usize> {
284 let len = br.read_code(UintCodeType::LimitedUnary(5, 0))? as usize;
285 Ok(len + 1)
286}
287/*
288 0 - 1
289 11 - 2
290 1000 - 3
291 1010 - 4
292 10011 - 5
293 10111 - 6
294 10010 - 7 + get_bits(3)
295 101100 - 15 + get_bits(5)
296 1011010 - 47 + get_bits(8)
297 1011011 - 303 + get_bits(16)
298 */
299const VP30_CRUN1_LUT: [u8; 32] = [
300 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
301 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
302 0x34, 0x34, 0x75, 0x55, 0x44, 0x44, 0x85, 0x65,
303 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22
304];
305fn vp30_read_coded_run1(br: &mut BitReader) -> DecoderResult<usize> {
306 let idx = br.peek(5) as usize;
307 let sym = (VP30_CRUN1_LUT[idx] >> 4) as usize;
308 let bits = VP30_CRUN1_LUT[idx] & 0xF;
309 br.skip(u32::from(bits))?;
310 if sym < 7 {
311 Ok(sym)
312 } else if sym == 7 {
313 Ok(7 + (br.read(3)? as usize))
314 } else {
315 let len = br.read_code(UintCodeType::Unary012)?;
316 match len {
317 0 => Ok(15 + (br.read(5)? as usize)),
318 1 => Ok(47 + (br.read(8)? as usize)),
319 _ => Ok(303 + (br.read(16)? as usize)),
320 }
321 }
322}
323
324struct VP34Decoder {
325 info: NACodecInfoRef,
326 width: usize,
327 height: usize,
328 mb_w: usize,
329 mb_h: usize,
330 version: u8,
331 is_intra: bool,
332 update_gf: bool,
333 quant: usize,
334 shuf: VPShuffler,
335 codes: Codes,
336 aux_codes: Option<VP40AuxCodes>,
337 loop_str: i16,
338 mc_buf: NAVideoBufferRef<u8>,
339
340 blocks: Vec<Block>,
341 mb_coded: Vec<bool>,
342 mb_partial: Vec<bool>,
343 y_blocks: usize,
344 y_sbs: usize,
345 qmat_y: [i16; 64],
346 qmat_c: [i16; 64],
347 qmat_y_p: [i16; 64],
348 qmat_c_p: [i16; 64],
349
350 eob_run: usize,
351 last_dc: [i16; 3],
352
353 blk_addr: Vec<usize>,
354 blk_sub: Vec<u8>,
355 sb_info: Vec<SBState>,
356 sb_blocks: Vec<u8>,
357 sb_mbs: Vec<u8>,
358 mb_blocks: Vec<u8>,
359}
360
361fn vp30_read_mv_comp(br: &mut BitReader) -> DecoderResult<i16> {
362 let mode = br.read(2)?;
363 if mode == 0 { return Ok(0); }
364 let sign = br.read_bool()?;
365 let val = match mode - 1 {
366 0 => 1,
367 1 => 2 + (br.read(2)? as i16),
368 _ => br.read(5)? as i16,
369 };
370 if !sign {
371 Ok(val)
372 } else {
373 Ok(-val)
374 }
375}
376
377fn vp30_read_mv(br: &mut BitReader) -> DecoderResult<MV> {
378 let x = vp30_read_mv_comp(br)?;
379 let y = vp30_read_mv_comp(br)?;
380 Ok(MV{ x, y })
381}
382
383fn read_mv_comp_packed(br: &mut BitReader) -> DecoderResult<i16> {
384 let code = br.read(3)?;
385 match code {
386 0 => Ok(0),
387 1 => Ok(1),
388 2 => Ok(-1),
389 3 => if br.read_bool()? { Ok(-2) } else { Ok(2) },
390 4 => if br.read_bool()? { Ok(-3) } else { Ok(3) },
391 5 => {
392 let val = (br.read(2)? as i16) + 4;
393 if br.read_bool()? {
394 Ok(-val)
395 } else {
396 Ok(val)
397 }
398 },
399 6 => {
400 let val = (br.read(3)? as i16) + 8;
401 if br.read_bool()? {
402 Ok(-val)
403 } else {
404 Ok(val)
405 }
406 },
407 _ => {
408 let val = (br.read(4)? as i16) + 16;
409 if br.read_bool()? {
410 Ok(-val)
411 } else {
412 Ok(val)
413 }
414 },
415 }
416}
417
418fn read_mv_packed(br: &mut BitReader) -> DecoderResult<MV> {
419 let x = read_mv_comp_packed(br)?;
420 let y = read_mv_comp_packed(br)?;
421 Ok(MV{ x, y })
422}
423
424fn read_mv_comp_raw(br: &mut BitReader) -> DecoderResult<i16> {
425 let val = br.read(5)? as i16;
426 if br.read_bool()? {
427 Ok(-val)
428 } else {
429 Ok(val)
430 }
431}
432
433fn read_mv_raw(br: &mut BitReader) -> DecoderResult<MV> {
434 let x = read_mv_comp_raw(br)?;
435 let y = read_mv_comp_raw(br)?;
436 Ok(MV{ x, y })
437}
438
439fn rescale_qmat(dst_qmat: &mut [i16; 64], base_qmat: &[i16; 64], dc_quant: i16, ac_quant: i16, minval: i16) {
440 for (dst, src) in dst_qmat.iter_mut().zip(base_qmat.iter()) {
441 *dst = (src.wrapping_mul(ac_quant) / 100).max(minval) << 2;
442 }
443 dst_qmat[0] = (base_qmat[0] * dc_quant / 100).max(minval * 2) << 2;
444}
445
446fn rescale_qmat_vp4(dst_qmat: &mut [i16; 64], base_qmat: &[i16; 64], dc_quant: i16, ac_quant: i16, is_intra: bool) {
447 let (bias, minval) = if is_intra { (3, 4) } else { (6, 8) };
448 for (dst, src) in dst_qmat.iter_mut().zip(base_qmat.iter()) {
449 *dst = ((src - bias).wrapping_mul(ac_quant) / 100 + bias) << 2;
450 }
451 dst_qmat[0] = (base_qmat[0] * dc_quant / 100).max(minval) << 2;
452}
453
454fn expand_token(blk: &mut Block, br: &mut BitReader, eob_run: &mut usize, token: u8) -> DecoderResult<()> {
455 match token {
456 // EOBs
457 0 | 1 | 2 => { *eob_run = (token as usize) + 1; },
458 3 | 4 | 5 => {
459 let bits = token - 1;
460 *eob_run = (br.read(bits)? as usize) + (1 << bits);
461 },
462 6 => { *eob_run = br.read(12)? as usize; },
463 // zero runs
464 7 | 8 => {
465 let bits = if token == 7 { 3 } else { 6 };
466 let run = (br.read(bits)? as usize) + 1;
467 blk.idx += run;
468 validate!(blk.idx <= 64);
469 },
470 // single coefficients
471 9 | 10 | 11 | 12 => {
472 let val = (i16::from(token) - 7) >> 1;
473 if (token & 1) == 1 {
474 blk.coeffs[ZIGZAG[blk.idx]] = val;
475 } else {
476 blk.coeffs[ZIGZAG[blk.idx]] = -val;
477 }
478 blk.idx += 1;
479 },
480 13 | 14 | 15 | 16 => {
481 let val = i16::from(token) - 10;
482 if !br.read_bool()? {
483 blk.coeffs[ZIGZAG[blk.idx]] = val;
484 } else {
485 blk.coeffs[ZIGZAG[blk.idx]] = -val;
486 }
487 blk.idx += 1;
488 },
489 17 | 18 | 19 | 20 | 21 | 22 => {
490 let add_bits = if token == 22 { 9 } else { token - 16 };
491 let sign = br.read_bool()?;
492 let val = (br.read(add_bits)? as i16) + VP3_LITERAL_BASE[(token - 17) as usize];
493 if !sign {
494 blk.coeffs[ZIGZAG[blk.idx]] = val;
495 } else {
496 blk.coeffs[ZIGZAG[blk.idx]] = -val;
497 }
498 blk.idx += 1;
499 }
500 // zero run plus coefficient
501 23 | 24 | 25 | 26 | 27 => {
502 blk.idx += (token - 22) as usize;
503 validate!(blk.idx < 64);
504 if !br.read_bool()? {
505 blk.coeffs[ZIGZAG[blk.idx]] = 1;
506 } else {
507 blk.coeffs[ZIGZAG[blk.idx]] = -1;
508 }
509 blk.idx += 1;
510 },
511 28 | 29 => {
512 let run_bits = token - 26;
513 if token == 28 {
514 blk.idx += 6;
515 } else {
516 blk.idx += 10;
517 }
518 let sign = br.read_bool()?;
519 blk.idx += br.read(run_bits)? as usize;
520 validate!(blk.idx < 64);
521 if !sign {
522 blk.coeffs[ZIGZAG[blk.idx]] = 1;
523 } else {
524 blk.coeffs[ZIGZAG[blk.idx]] = -1;
525 }
526 blk.idx += 1;
527 },
528 30 => {
529 blk.idx += 1;
530 validate!(blk.idx < 64);
531 let sign = br.read_bool()?;
532 let val = (br.read(1)? as i16) + 2;
533 if !sign {
534 blk.coeffs[ZIGZAG[blk.idx]] = val;
535 } else {
536 blk.coeffs[ZIGZAG[blk.idx]] = -val;
537 }
538 blk.idx += 1;
539 },
540 _ => {
541 let sign = br.read_bool()?;
542 let val = (br.read(1)? as i16) + 2;
543 blk.idx += (br.read(1)? as usize) + 2;
544 validate!(blk.idx < 64);
545 if !sign {
546 blk.coeffs[ZIGZAG[blk.idx]] = val;
547 } else {
548 blk.coeffs[ZIGZAG[blk.idx]] = -val;
549 }
550 blk.idx += 1;
551 },
552 };
553 if *eob_run > 0 {
554 blk.idx = 64;
555 *eob_run -= 1;
556 } else if (token > 8) && (blk.idx > 1) {
557 blk.has_ac = true;
558 }
559 Ok(())
560}
561
562macro_rules! fill_dc_pred {
563 ($self: expr, $ref_id: expr, $pred: expr, $pp: expr, $bit: expr, $idx: expr) => {
564 if $self.blocks[$idx].coded && $self.blocks[$idx].btype.get_ref_id() == $ref_id {
565 $pred[$bit] = i32::from($self.blocks[$idx].coeffs[0]);
566 $pp |= 1 << $bit;
567 }
568 };
569}
570
571fn vp31_loop_filter_v(frm: &mut NASimpleVideoFrame<u8>, x: usize, y: usize, plane: usize, loop_str: i16) {
572 let off = frm.offset[plane] + x + y * frm.stride[plane];
573 vp31_loop_filter(frm.data, off, 1, frm.stride[plane], 8, loop_str);
574}
575
576fn vp31_loop_filter_h(frm: &mut NASimpleVideoFrame<u8>, x: usize, y: usize, plane: usize, loop_str: i16) {
577 let off = frm.offset[plane] + x + y * frm.stride[plane];
578 vp31_loop_filter(frm.data, off, frm.stride[plane], 1, 8, loop_str);
579}
580
581fn vp3_mv_mode(mvx: i16, mvy: i16) -> usize {
582 let mode = ((mvx & 1) + (mvy & 1) * 2) as usize;
583 if (mode == 3) && (mvx ^ mvy < 0) {
584 4
585 } else {
586 mode
587 }
588}
589
590impl VP34Decoder {
591 fn new(version: u8) -> Self {
592 let vt = alloc_video_buffer(NAVideoInfo::new(24, 24, false, YUV420_FORMAT), 4).unwrap();
593 let mc_buf = vt.get_vbuf().unwrap();
594 Self {
595 info: NACodecInfoRef::default(),
596 width: 0,
597 height: 0,
598 mb_w: 0,
599 mb_h: 0,
600 version,
601 is_intra: true,
602 update_gf: false,
603 quant: 0,
604 shuf: VPShuffler::new(),
605 codes: Codes::None,
606 aux_codes: None,
607 loop_str: 0,
608 mc_buf,
609
610 blocks: Vec::new(),
611 mb_coded: Vec::new(),
612 mb_partial: Vec::new(),
613 y_blocks: 0,
614 y_sbs: 0,
615
616 qmat_y: [0; 64],
617 qmat_c: [0; 64],
618 qmat_y_p: [0; 64],
619 qmat_c_p: [0; 64],
620
621 eob_run: 0,
622 last_dc: [0; 3],
623
624 blk_addr: Vec::new(),
625 blk_sub: Vec::new(),
626 sb_info: Vec::new(),
627 sb_blocks: Vec::new(),
628 sb_mbs: Vec::new(),
629 mb_blocks: Vec::new(),
630 }
631 }
632 fn parse_header(&mut self, br: &mut BitReader) -> DecoderResult<()> {
633 self.is_intra = !br.read_bool()?;
634 br.skip(1)?;
635 self.quant = br.read(6)? as usize;
636 if self.is_intra {
637 if br.peek(8) != 0 {
638 validate!(self.version == 3 || self.version == 30);
639 let mb_w = br.read(8)? as usize;
640 let mb_h = br.read(8)? as usize;
641 validate!(mb_w == self.mb_w && mb_h == self.mb_h);
642 if self.version == 3 {
643 self.version = 30;
644 self.codes = Codes::VP30(VP30Codes::new());
645 }
646 } else {
647 let version = br.read(13)?;
648 let coding_type = br.read(1)?;
649 validate!(coding_type == 0);
650 br.skip(2)?;
651 if version == 1 {
652 validate!(self.version == 3 || self.version == 31);
653 if self.version == 3 {
654 self.version = 31;
655 self.codes = Codes::VP31(VP31Codes::new());
656 }
657 } else if version == 3 {
658 validate!(self.version == 4);
659 let mb_h = br.read(8)? as usize;
660 let mb_w = br.read(8)? as usize;
661 validate!(mb_w == self.mb_w && mb_h == self.mb_h);
662 let fact1 = br.read(5)?;
663 let fact2 = br.read(3)?;
664 validate!(fact1 == 1 && fact2 == 1);
665 let fact1 = br.read(5)?;
666 let fact2 = br.read(3)?;
667 validate!(fact1 == 1 && fact2 == 1);
668 br.skip(2)?;
669 } else {
670 return Err(DecoderError::InvalidData);
671 }
672 }
673 }
674 self.loop_str = if self.version != 4 {
675 VP31_LOOP_STRENGTH[self.quant]
676 } else {
677 VP40_LOOP_STRENGTH[self.quant]
678 };
679 Ok(())
680 }
681 fn vp30_unpack_sb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
682 let mut has_nonempty = false;
683 {
684 let mut bit = !br.read_bool()?;
685 let mut run = 0;
686 for sb in self.sb_info.iter_mut() {
687 if run == 0 {
688 bit = !bit;
689 run = if bit { vp30_read_ne_run1(br)? } else { vp30_read_ne_run0(br)? };
690 }
691 *sb = if bit { has_nonempty = true; SBState::Partial } else { SBState::Uncoded };
692 run -= 1;
693 }
694 validate!(run == 0);
695 }
696 if has_nonempty {
697 for el in self.mb_coded.iter_mut() { *el = false; }
698 let mut bit = !br.read_bool()?;
699 let mut run = 0;
700 let mut mbiter = self.mb_coded.iter_mut();
701 for (sb, nmb) in self.sb_info.iter_mut().zip(self.sb_mbs.iter()) {
702 let nmbs = *nmb as usize;
703 if *sb == SBState::Partial {
704 for _ in 0..nmbs {
705 if run == 0 {
706 bit = !bit;
707 run = if bit { vp30_read_coded_run1(br)? } else { vp30_read_coded_run0(br)? };
708 }
709 run -= 1;
710 *mbiter.next().unwrap() = bit;
711 }
712 } else {
713 for _ in 0..nmbs {
714 mbiter.next().unwrap();
715 }
716 }
717 }
718 validate!(run == 0);
719 let mut bit = !br.read_bool()?;
720 let mut run = 0;
721 let mut cur_blk = 0;
722 for (coded, nblk) in self.mb_coded.iter().zip(self.mb_blocks.iter()) {
723 let nblks = *nblk as usize;
724 if *coded {
725 let mut cb = [false; 4];
726 for j in 0..nblks {
727 if run == 0 {
728 bit = !bit;
729 run = if bit { vp30_read_coded_run1(br)? } else { vp30_read_coded_run0(br)? };
730 }
731 run -= 1;
732 cb[j] = bit;
733 }
734 for j in 0..nblks {
735 let addr = self.blk_addr[cur_blk + j] >> 2;
736 self.blocks[addr].coded = cb[j];
737 }
738 }
739 cur_blk += nblks;
740 }
741 validate!(run == 0);
742 }
743 Ok(())
744 }
745 fn vp30_unpack_mb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
746 let mut cur_blk = 0;
747 if let Codes::VP30(ref codes) = self.codes {
748 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()).take(self.y_sbs) {
749 let nblks = *nblk as usize;
750 if *sb == SBState::Uncoded {
751 for _ in 0..nblks {
752 self.blocks[self.blk_addr[cur_blk] >> 2].btype = VPMBType::InterNoMV;
753 cur_blk += 1;
754 }
755 } else {
756 for _ in 0..nblks/4 {
757 let mut coded = *sb == SBState::Coded;
758 if !coded {
759 for blk in 0..4 {
760 if self.blocks[self.blk_addr[cur_blk + blk] >> 2].coded {
761 coded = true;
762 break;
763 }
764 }
765 }
766 let mode = if !coded {
767 VPMBType::InterNoMV
768 } else {
769 br.read_cb(&codes.mbtype_cb)?
770 };
771 for _ in 0..4 {
772 self.blocks[self.blk_addr[cur_blk] >> 2].btype = mode;
773 cur_blk += 1;
774 }
775 }
776 }
777 }
778 } else {
779 return Err(DecoderError::Bug);
780 }
781 // replicate types for chroma
782 let mut off_y = 0;
783 let mut off_u = self.y_blocks;
784 let mut off_v = off_u + self.mb_w * self.mb_h;
785 for _blk_y in 0..self.mb_h {
786 for blk_x in 0..self.mb_w {
787 let btype = self.blocks[off_y + blk_x * 2].btype;
788 self.blocks[off_u + blk_x].btype = btype;
789 self.blocks[off_v + blk_x].btype = btype;
790 }
791 off_y += self.mb_w * 2 * 2;
792 off_u += self.mb_w;
793 off_v += self.mb_w;
794 }
795 Ok(())
796 }
797 fn vp30_unpack_mv_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
798 let mut last_mv = ZERO_MV;
799
800 let mut cur_blk = 0;
801 for _ in 0..self.y_blocks/4 {
802 let baddr = self.blk_addr[cur_blk] >> 2;
803 if self.blocks[baddr].btype == VPMBType::InterFourMV {
804 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);
805 for i in 0..4 {
806 let blk = &mut self.blocks[saddr + (i & 1) + (i & 2) * self.mb_w];
807 if blk.coded {
808 blk.mv = vp30_read_mv(br)?;
809 }
810 cur_blk += 1;
811 }
812 } else {
813 let cur_mv;
814 match self.blocks[baddr].btype {
815 VPMBType::Intra | VPMBType::InterNoMV | VPMBType::GoldenNoMV => {
816 cur_mv = ZERO_MV;
817 },
818 VPMBType::InterMV => {
819 cur_mv = vp30_read_mv(br)?;
820 last_mv = cur_mv;
821 },
822 VPMBType::InterNearest => {
823 cur_mv = last_mv;
824 },
825 _ => { // GoldenMV
826 cur_mv = vp30_read_mv(br)?;
827 },
828 };
829 for _ in 0..4 {
830 self.blocks[self.blk_addr[cur_blk] >> 2].mv = cur_mv;
831 cur_blk += 1;
832 }
833 }
834 }
835 Ok(())
836 }
837 fn vp30_unpack_coeffs(&mut self, br: &mut BitReader, coef_no: usize, table: usize) -> DecoderResult<()> {
838 if let Codes::VP30(ref codes) = self.codes {
839 for blkaddr in self.blk_addr.iter() {
840 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
841 if !blk.coded || blk.idx != coef_no { continue; }
842 if self.eob_run > 0 {
843 blk.idx = 64;
844 self.eob_run -= 1;
845 continue;
846 }
847 let cb = if coef_no == 0 {
848 &codes.dc_cb[table]
849 } else if blk.btype.is_intra() {
850 &codes.ac_i_cb[table]
851 } else {
852 &codes.ac_p_cb[table]
853 };
854 let token = br.read_cb(cb)?;
855 expand_token(blk, br, &mut self.eob_run, token)?;
856 }
857 Ok(())
858 } else {
859 Err(DecoderError::Bug)
860 }
861 }
862 fn vp31_unpack_sb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
863 let mut has_uncoded = false;
864 let mut has_partial = false;
865 {
866 let mut brun = BitRunDecoder::new(br, read_long_run)?;
867 for sb in self.sb_info.iter_mut() {
868 if brun.get_val(br)? {
869 *sb = SBState::Partial;
870 has_partial = true;
871 } else {
872 *sb = SBState::Uncoded;
873 has_uncoded = true;
874 }
875 }
876 }
877 if has_uncoded {
878 let mut brun = BitRunDecoder::new(br, read_long_run)?;
879 let mut cur_blk = 0;
880 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()) {
881 let nblks = *nblk as usize;
882 if *sb != SBState::Partial && brun.get_val(br)? {
883 *sb = SBState::Coded;
884 for _ in 0..nblks {
885 let blk_idx = self.blk_addr[cur_blk] >> 2;
886 self.blocks[blk_idx].coded = true;
887 cur_blk += 1;
888 }
889 } else {
890 for _ in 0..nblks {
891 let blk_idx = self.blk_addr[cur_blk] >> 2;
892 self.blocks[blk_idx].coded = false;
893 cur_blk += 1;
894 }
895 }
896 }
897 }
898 if has_partial {
899 let mut brun = BitRunDecoder::new(br, read_short_run)?;
900 let mut cur_blk = 0;
901 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()) {
902 let nblks = *nblk as usize;
903 if *sb == SBState::Partial {
904 for _ in 0..nblks {
905 let blk_idx = self.blk_addr[cur_blk] >> 2;
906 self.blocks[blk_idx].coded = brun.get_val(br)?;
907 cur_blk += 1;
908 }
909 } else {
910 cur_blk += nblks;
911 }
912 }
913 }
914 Ok(())
915 }
916 fn vp31_unpack_mb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
917 let mut modes = [VPMBType::InterNoMV; 8];
918 let alphabet = br.read(3)? as usize;
919 let raw_modes = alphabet >= 7;
920 if alphabet == 0 {
921 for mode in VP31_DEFAULT_MB_MODES.iter() {
922 modes[br.read(3)? as usize] = *mode;
923 }
924 } else if alphabet < 7 {
925 modes.copy_from_slice(&VP31_MB_MODES[alphabet - 1]);
926 }
927
928 let mut cur_blk = 0;
929 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()).take(self.y_sbs) {
930 let nblks = *nblk as usize;
931 if *sb == SBState::Uncoded {
932 for _ in 0..nblks {
933 self.blocks[self.blk_addr[cur_blk] >> 2].btype = VPMBType::InterNoMV;
934 cur_blk += 1;
935 }
936 } else {
937 for _ in 0..nblks/4 {
938 let mut coded = *sb == SBState::Coded;
939 if !coded {
940 for blk in 0..4 {
941 if self.blocks[self.blk_addr[cur_blk + blk] >> 2].coded {
942 coded = true;
943 break;
944 }
945 }
946 }
947 let mode = if !coded {
948 VPMBType::InterNoMV
949 } else if !raw_modes {
950 let code = br.read_code(UintCodeType::LimitedUnary(7, 0))?;
951 modes[code as usize]
952 } else {
953 VP31_DEFAULT_MB_MODES[br.read(3)? as usize]
954 };
955 for _ in 0..4 {
956 self.blocks[self.blk_addr[cur_blk] >> 2].btype = mode;
957 cur_blk += 1;
958 }
959 }
960 }
961 }
962 // replicate types for chroma
963 let mut off_y = 0;
964 let mut off_u = self.y_blocks;
965 let mut off_v = off_u + self.mb_w * self.mb_h;
966 for _blk_y in 0..self.mb_h {
967 for blk_x in 0..self.mb_w {
968 let btype = self.blocks[off_y + blk_x * 2].btype;
969 self.blocks[off_u + blk_x].btype = btype;
970 self.blocks[off_v + blk_x].btype = btype;
971 }
972 off_y += self.mb_w * 2 * 2;
973 off_u += self.mb_w;
974 off_v += self.mb_w;
975 }
976 Ok(())
977 }
978 fn vp31_unpack_mv_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
979 let mut last_mv = ZERO_MV;
980 let mut last2_mv = ZERO_MV;
981 let read_mv = if br.read_bool()? { read_mv_raw } else { read_mv_packed };
982
983 let mut cur_blk = 0;
984 for _ in 0..self.y_blocks/4 {
985 if self.blocks[self.blk_addr[cur_blk] >> 2].btype == VPMBType::InterFourMV {
986 let a0 = self.blk_addr[cur_blk + 0] >> 2;
987 let a1 = self.blk_addr[cur_blk + 1] >> 2;
988 let a2 = self.blk_addr[cur_blk + 2] >> 2;
989 let a3 = self.blk_addr[cur_blk + 3] >> 2;
990 let first = a0.min(a1).min(a2).min(a3);
991 let last = a0.max(a1).max(a2).max(a3);
992 self.blocks[first + 0].mv = (read_mv)(br)?;
993 self.blocks[first + 1].mv = (read_mv)(br)?;
994 self.blocks[last - 1].mv = (read_mv)(br)?;
995 self.blocks[last + 0].mv = (read_mv)(br)?;
996 last2_mv = last_mv;
997 last_mv = self.blocks[last].mv;
998 cur_blk += 4;
999 } else {
1000 let cur_mv;
1001 match self.blocks[self.blk_addr[cur_blk] >> 2].btype {
1002 VPMBType::Intra | VPMBType::InterNoMV | VPMBType::GoldenNoMV => {
1003 cur_mv = ZERO_MV;
1004 },
1005 VPMBType::InterMV => {
1006 cur_mv = (read_mv)(br)?;
1007 last2_mv = last_mv;
1008 last_mv = cur_mv;
1009 },
1010 VPMBType::InterNearest => {
1011 cur_mv = last_mv;
1012 },
1013 VPMBType::InterNear => {
1014 cur_mv = last2_mv;
1015 std::mem::swap(&mut last_mv, &mut last2_mv);
1016 },
1017 _ => { // GoldenMV
1018 cur_mv = (read_mv)(br)?;
1019 },
1020 };
1021 for _ in 0..4 {
1022 self.blocks[self.blk_addr[cur_blk] >> 2].mv = cur_mv;
1023 cur_blk += 1;
1024 }
1025 }
1026 }
1027 Ok(())
1028 }
1029 fn vp31_unpack_coeffs(&mut self, br: &mut BitReader, coef_no: usize, table_y: usize, table_c: usize) -> DecoderResult<()> {
1030 if let Codes::VP31(ref codes) = self.codes {
1031 let cbs = if coef_no == 0 {
1032 [&codes.dc_cb[table_y], &codes.dc_cb[table_c]]
1033 } else if coef_no < 6 {
1034 [&codes.ac0_cb[table_y], &codes.ac0_cb[table_c]]
1035 } else if coef_no < 15 {
1036 [&codes.ac1_cb[table_y], &codes.ac1_cb[table_c]]
1037 } else if coef_no < 28 {
1038 [&codes.ac2_cb[table_y], &codes.ac2_cb[table_c]]
1039 } else {
1040 [&codes.ac3_cb[table_y], &codes.ac3_cb[table_c]]
1041 };
1042 for blkaddr in self.blk_addr.iter() {
1043 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
1044 if !blk.coded || blk.idx != coef_no { continue; }
1045 if self.eob_run > 0 {
1046 blk.idx = 64;
1047 self.eob_run -= 1;
1048 continue;
1049 }
1050 let cb = if (blkaddr & 3) == 0 { cbs[0] } else { cbs[1] };
1051 let token = br.read_cb(cb)?;
1052 expand_token(blk, br, &mut self.eob_run, token)?;
1053 }
1054 Ok(())
1055 } else {
1056 Err(DecoderError::Bug)
1057 }
1058 }
1059 fn vp40_unpack_sb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
1060 let mut has_uncoded = false;
1061
1062 if let Some(ref aux_codes) = self.aux_codes {
1063 for el in self.sb_info.iter_mut() {
1064 *el = SBState::Partial;
1065 }
1066 {
1067 let mut mbiter = self.mb_coded.iter_mut();
1068 let mut brun = BitRunDecoder::new(br, read_mb_run)?;
1069 for nmb in self.sb_mbs.iter() {
1070 let nmbs = *nmb as usize;
1071 for _ in 0..nmbs {
1072 let coded = brun.get_val(br)?;
1073 *mbiter.next().unwrap() = coded;
1074 has_uncoded |= !coded;
1075 }
1076 }
1077 }
1078 if has_uncoded {
1079 let mut mbiter = self.mb_coded.iter().zip(self.mb_partial.iter_mut());
1080 let mut brun = BitRunDecoder::new(br, read_mb_run)?;
1081 for nmb in self.sb_mbs.iter() {
1082 let nmbs = *nmb as usize;
1083 for _ in 0..nmbs {
1084 let (coded, partial) = mbiter.next().unwrap();
1085 if *coded {
1086 *partial = false;
1087 } else {
1088 *partial = brun.get_val(br)?;
1089 }
1090 }
1091 }
1092
1093 let mut bpmode = 0;
1094 let mut cur_blk = 0;
1095 for ((coded, partial), nblk) in self.mb_coded.iter().zip(self.mb_partial.iter()).zip(self.mb_blocks.iter()) {
1096 let nblks = *nblk as usize;
1097 if *coded {
1098 for _ in 0..nblks {
1099 let addr = self.blk_addr[cur_blk] >> 2;
1100 self.blocks[addr].coded = true;
1101 cur_blk += 1;
1102 }
1103 } else if !*partial {
1104 for _ in 0..nblks {
1105 let addr = self.blk_addr[cur_blk] >> 2;
1106 self.blocks[addr].coded = false;
1107 cur_blk += 1;
1108 }
1109 } else {
1110 let mut pat = br.read_cb(&aux_codes.mbpat_cb[bpmode])? + 1;
1111 bpmode = VP40_BP_PREDICTOR[pat as usize] as usize;
1112
1113 let mut addrs = [0; 4];
1114 for i in 0..nblks {
1115 addrs[i] = self.blk_addr[cur_blk + i] >> 2;
1116 for j in (0..i).rev() {
1117 if addrs[j] > addrs[j + 1] {
1118 addrs.swap(j, j + 1);
1119 }
1120 }
1121 }
1122 for i in 0..nblks {
1123 self.blocks[addrs[i]].coded = (pat & 8) != 0;
1124 pat <<= 1;
1125 cur_blk += 1;
1126 }
1127 }
1128 }
1129 }
1130 Ok(())
1131 } else {
1132 Err(DecoderError::Bug)
1133 }
1134 }
1135 fn vp40_unpack_mv_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
1136 let mut last_mv = ZERO_MV;
1137 let mut last2_mv = ZERO_MV;
1138 let mut last_mv_g = ZERO_MV;
1139
1140 let mut cur_blk = 0;
1141 if let Some(ref codes) = self.aux_codes {
1142 for _ in 0..self.y_blocks/4 {
1143 if self.blocks[self.blk_addr[cur_blk] >> 2].btype == VPMBType::InterFourMV {
1144 let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.abs() as usize]];
1145 let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.abs() as usize]];
1146 let x_sign = last_mv.x < 0;
1147 let y_sign = last_mv.y < 0;
1148 last2_mv = last_mv;
1149 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);
1150 for i in 0..4 {
1151 let blk = &mut self.blocks[saddr + (i & 1) + (i >> 1) * self.mb_w * 2];
1152 blk.mv.x = i16::from(br.read_cb(x_cb)?);
1153 if x_sign {
1154 blk.mv.x = -blk.mv.x;
1155 }
1156 blk.mv.y = i16::from(br.read_cb(y_cb)?);
1157 if y_sign {
1158 blk.mv.y = -blk.mv.y;
1159 }
1160 last_mv = blk.mv;
1161 cur_blk += 1;
1162 }
1163 } else {
1164 let cur_mv;
1165 match self.blocks[self.blk_addr[cur_blk] >> 2].btype {
1166 VPMBType::Intra | VPMBType::InterNoMV | VPMBType::GoldenNoMV => {
1167 cur_mv = ZERO_MV;
1168 },
1169 VPMBType::InterMV => {
1170 let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.abs() as usize]];
1171 let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.abs() as usize]];
1172 let x_sign = last_mv.x < 0;
1173 let y_sign = last_mv.y < 0;
1174 let x = i16::from(br.read_cb(x_cb)?);
1175 let y = i16::from(br.read_cb(y_cb)?);
1176 cur_mv = MV { x: if !x_sign { x } else { -x }, y: if !y_sign { y } else { -y } };
1177 last2_mv = last_mv;
1178 last_mv = cur_mv;
1179 },
1180 VPMBType::InterNearest => {
1181 cur_mv = last_mv;
1182 },
1183 VPMBType::InterNear => {
1184 cur_mv = last2_mv;
1185 std::mem::swap(&mut last_mv, &mut last2_mv);
1186 },
1187 _ => { // GoldenMV
1188 let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv_g.x.abs() as usize]];
1189 let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv_g.y.abs() as usize]];
1190 let x_sign = last_mv_g.x < 0;
1191 let y_sign = last_mv_g.y < 0;
1192 let x = i16::from(br.read_cb(x_cb)?);
1193 let y = i16::from(br.read_cb(y_cb)?);
1194 cur_mv = MV { x: if !x_sign { x } else { -x }, y: if !y_sign { y } else { -y } };
1195 last_mv_g = cur_mv;
1196 },
1197 };
1198 for _ in 0..4 {
1199 self.blocks[self.blk_addr[cur_blk] >> 2].mv = cur_mv;
1200 cur_blk += 1;
1201 }
1202 }
1203 }
1204 Ok(())
1205 } else {
1206 Err(DecoderError::Bug)
1207 }
1208 }
1209 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<()> {
1210 const VP40_PRED_MASKS: [usize; 16] = [ // top, bottom, left, right
1211 0b1010, 0b1010, 0b1000, 0b1011,
1212 0b1010, 0b1010, 0b0010, 0b1110,
1213 0b0010, 0b1010, 0b0010, 0b0110,
1214 0b0100, 0b0111, 0b1110, 0b1110
1215 ];
1216 self.last_dc = [0; 3];
1217 if let Codes::VP31(ref codes) = self.codes {
1218 let mut coef_eob: [usize; 64] = [0; 64];
1219 for (blkaddr, bsub) in self.blk_addr.iter().zip(self.blk_sub.iter()) {
1220 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
1221 if !blk.coded { continue; }
1222 let mut idx = blkaddr >> 2;
1223 let (bx, by) = if (blkaddr & 3) == 0 {
1224 (idx % (self.mb_w * 2), idx / (self.mb_w * 2))
1225 } else {
1226 idx -= self.mb_w * self.mb_h * 4;
1227 if idx >= self.mb_w * self.mb_h {
1228 idx -= self.mb_w * self.mb_h;
1229 }
1230 (idx % self.mb_w, idx / self.mb_w)
1231 };
1232 while blk.idx < 64 {
1233 if coef_eob[blk.idx] > 0 {
1234 coef_eob[blk.idx] -= 1;
1235 blk.idx = 64;
1236 continue;
1237 }
1238 let cbs = if blk.idx == 0 {
1239 [&codes.dc_cb[dc_table_y], &codes.dc_cb[dc_table_c]]
1240 } else if blk.idx < 6 {
1241 [&codes.ac0_cb[ac_table_y], &codes.ac0_cb[ac_table_c]]
1242 } else if blk.idx < 15 {
1243 [&codes.ac1_cb[ac_table_y], &codes.ac1_cb[ac_table_c]]
1244 } else if blk.idx < 28 {
1245 [&codes.ac2_cb[ac_table_y], &codes.ac2_cb[ac_table_c]]
1246 } else {
1247 [&codes.ac3_cb[ac_table_y], &codes.ac3_cb[ac_table_c]]
1248 };
1249 let cb = if (blkaddr & 3) == 0 { cbs[0] } else { cbs[1] };
1250 let token = br.read_cb(cb)?;
1251 expand_token(blk, br, &mut coef_eob[blk.idx], token)?;
1252 if blk.idx == 64 { break; }
1253 }
1254 let idx = blkaddr >> 2;
1255 let mask = VP40_PRED_MASKS[*bsub as usize];
1256 if (blkaddr & 3) == 0 {
1257 let pred_dc = self.vp40_predict_dc(bx, by, self.mb_w * 2, self.mb_h * 2, idx, mask, true);
1258 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
1259 blk.coeffs[0] += pred_dc;
1260 self.last_dc[blk.btype.get_ref_id() as usize] = blk.coeffs[0];
1261 } else {
1262 let pred_dc = self.vp40_predict_dc(bx, by, self.mb_w, self.mb_h, idx, mask, false);
1263 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
1264 blk.coeffs[0] += pred_dc;
1265 self.last_dc[blk.btype.get_ref_id() as usize] = blk.coeffs[0];
1266 }
1267 }
1268 Ok(())
1269 } else {
1270 Err(DecoderError::Bug)
1271 }
1272 }
1273 fn decode_vp30(&mut self, br: &mut BitReader, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<()> {
1274 for blk in self.blocks.iter_mut() {
1275 blk.coeffs = [0; 64];
1276 blk.idx = 0;
1277 blk.coded = false;
1278 blk.has_ac = false;
1279 }
1280 if self.is_intra {
1281 for sb in self.sb_info.iter_mut() { *sb = SBState::Coded; }
1282 for blk in self.blocks.iter_mut() {
1283 blk.btype = VPMBType::Intra;
1284 blk.coded = true;
1285 }
1286 } else {
1287 if self.shuf.get_last().is_none() || self.shuf.get_golden().is_none() {
1288 return Err(DecoderError::MissingReference);
1289 }
1290 self.vp30_unpack_sb_info(br)?;
1291 self.vp30_unpack_mb_info(br)?;
1292 self.vp30_unpack_mv_info(br)?;
1293 }
1294 let dc_quant = VP30_DC_SCALES[self.quant] * 10;
1295 let ac_quant = VP30_AC_SCALES[self.quant];
1296
1297 self.update_gf = ac_quant <= 50;
1298
1299 rescale_qmat(&mut self.qmat_y, VP3_QMAT_Y, dc_quant, ac_quant, 2);
1300 rescale_qmat(&mut self.qmat_c, VP3_QMAT_C, dc_quant, ac_quant, 2);
1301 rescale_qmat(&mut self.qmat_y_p, VP3_QMAT_INTER, dc_quant, ac_quant, 4);
1302 if self.quant == 10 {
1303 self.qmat_y[29] = 980;
1304 self.qmat_y[58] = 1636;
1305 self.qmat_y[59] = 1964;
1306 } else if self.quant == 31 {
1307 self.qmat_y[58] = 456;
1308 } else if self.quant == 44 {
1309 self.qmat_y[58] = 224;
1310 }
1311 self.qmat_c_p.copy_from_slice(&self.qmat_y_p);
1312
1313 let table = if ac_quant <= 50 {
1314 0
1315 } else if ac_quant <= 150 {
1316 1
1317 } else if ac_quant <= 300 {
1318 2
1319 } else if ac_quant <= 600 {
1320 3
1321 } else {
1322 4
1323 };
1324
1325 self.eob_run = 0;
1326 self.vp30_unpack_coeffs(br, 0, table)?;
1327 let mut last_dc_i = 0;
1328 let mut last_dc_p = 0;
1329 for blkaddr in self.blk_addr.iter() {
1330 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
1331 if !blk.coded { continue; }
1332 if blk.btype.is_intra() {
1333 blk.coeffs[0] += last_dc_i;
1334 last_dc_i = blk.coeffs[0];
1335 } else {
1336 blk.coeffs[0] += last_dc_p;
1337 last_dc_p = blk.coeffs[0];
1338 }
1339 }
1340
1341 for coef_no in 1..64 {
1342 self.vp30_unpack_coeffs(br, coef_no, table)?;
1343 }
1344
1345 if self.is_intra {
1346 self.output_blocks_intra(frm);
1347 } else {
1348 self.output_blocks_inter(frm);
1349 }
1350
1351 Ok(())
1352 }
1353 fn decode_vp31(&mut self, br: &mut BitReader, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<()> {
1354 for blk in self.blocks.iter_mut() {
1355 blk.coeffs = [0; 64];
1356 blk.idx = 0;
1357 blk.coded = false;
1358 blk.has_ac = false;
1359 }
1360 if self.is_intra {
1361 for sb in self.sb_info.iter_mut() { *sb = SBState::Coded; }
1362 for blk in self.blocks.iter_mut() {
1363 blk.btype = VPMBType::Intra;
1364 blk.coded = true;
1365 }
1366 } else {
1367 if self.shuf.get_last().is_none() || self.shuf.get_golden().is_none() {
1368 return Err(DecoderError::MissingReference);
1369 }
1370 self.vp31_unpack_sb_info(br)?;
1371 self.vp31_unpack_mb_info(br)?;
1372 self.vp31_unpack_mv_info(br)?;
1373 }
1374 let dc_quant = VP31_DC_SCALES[self.quant];
1375 let ac_quant = VP31_AC_SCALES[self.quant];
1376 rescale_qmat(&mut self.qmat_y, VP3_QMAT_Y, dc_quant, ac_quant, 2);
1377 rescale_qmat(&mut self.qmat_c, VP3_QMAT_C, dc_quant, ac_quant, 2);
1378 rescale_qmat(&mut self.qmat_y_p, VP3_QMAT_INTER, dc_quant, ac_quant, 4);
1379 rescale_qmat(&mut self.qmat_c_p, VP3_QMAT_INTER, dc_quant, ac_quant, 4);
1380
1381 self.eob_run = 0;
1382 let dc_table_y = br.read(4)? as usize;
1383 let dc_table_c = br.read(4)? as usize;
1384 self.vp31_unpack_coeffs(br, 0, dc_table_y, dc_table_c)?;
1385 self.restore_dcs();
1386
1387 let ac_table_y = br.read(4)? as usize;
1388 let ac_table_c = br.read(4)? as usize;
1389 for coef_no in 1..64 {
1390 self.vp31_unpack_coeffs(br, coef_no, ac_table_y, ac_table_c)?;
1391 }
1392
1393 if self.is_intra {
1394 self.output_blocks_intra(frm);
1395 } else {
1396 self.output_blocks_inter(frm);
1397 }
1398 if self.loop_str > 0 {
1399 self.vp31_loop_filter(frm);
1400 }
1401
1402 Ok(())
1403 }
1404 fn decode_vp4(&mut self, br: &mut BitReader, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<()> {
1405 for blk in self.blocks.iter_mut() {
1406 blk.coeffs = [0; 64];
1407 blk.idx = 0;
1408 blk.coded = false;
1409 blk.has_ac = false;
1410 }
1411 if self.is_intra {
1412 for sb in self.sb_info.iter_mut() { *sb = SBState::Coded; }
1413 for blk in self.blocks.iter_mut() {
1414 blk.btype = VPMBType::Intra;
1415 blk.coded = true;
1416 }
1417 } else {
1418 if self.shuf.get_last().is_none() || self.shuf.get_golden().is_none() {
1419 return Err(DecoderError::MissingReference);
1420 }
1421 self.vp40_unpack_sb_info(br)?;
1422 self.vp31_unpack_mb_info(br)?;
1423 self.vp40_unpack_mv_info(br)?;
1424 }
1425 let dc_y_quant = VP40_DC_Y_SCALES[self.quant];
1426 let dc_c_quant = VP40_DC_C_SCALES[self.quant];
1427 let ac_quant = VP40_AC_SCALES[self.quant];
1428 rescale_qmat_vp4(&mut self.qmat_y, VP40_QMAT, dc_y_quant, ac_quant, true);
1429 rescale_qmat_vp4(&mut self.qmat_y_p, VP40_QMAT, dc_c_quant, ac_quant, false);
1430 self.qmat_c.copy_from_slice(&self.qmat_y);
1431 self.qmat_c_p.copy_from_slice(&self.qmat_y_p);
1432
1433 self.eob_run = 0;
1434 let dc_table_y = br.read(4)? as usize;
1435 let dc_table_c = br.read(4)? as usize;
1436 let ac_table_y = br.read(4)? as usize;
1437 let ac_table_c = br.read(4)? as usize;
1438 self.vp40_unpack_coeffs(br, dc_table_y, dc_table_c, ac_table_y, ac_table_c)?;
1439
1440 if self.is_intra {
1441 self.output_blocks_intra(frm);
1442 } else {
1443 self.output_blocks_inter(frm);
1444 }
1445
1446 Ok(())
1447 }
1448 fn vp31_predict_dc(&self, bx: usize, by: usize, bw: usize, blk_idx: usize) -> i16 {
1449 let mut preds = [0i32; 4];
1450 let mut pp: usize = 0;
1451 let ref_id = self.blocks[blk_idx].btype.get_ref_id();
1452 let is_right = bx == bw - 1;
1453 if bx > 0 {
1454 fill_dc_pred!(self, ref_id, preds, pp, 0, blk_idx - 1);
1455 if by > 0 {
1456 fill_dc_pred!(self, ref_id, preds, pp, 1, blk_idx - 1 - bw);
1457 }
1458 }
1459 if by > 0 {
1460 fill_dc_pred!(self, ref_id, preds, pp, 2, blk_idx - bw);
1461 if !is_right {
1462 fill_dc_pred!(self, ref_id, preds, pp, 3, blk_idx + 1 - bw);
1463 }
1464 }
1465 if pp == 0 { return self.last_dc[ref_id as usize]; }
1466 let mut pred = 0i32;
1467 for i in 0..4 {
1468 if (pp & (1 << i)) != 0 {
1469 pred += (preds[i] as i32) * i32::from(VP31_DC_WEIGHTS[pp][i]);
1470 }
1471 }
1472 pred /= i32::from(VP31_DC_WEIGHTS[pp][4]);
1473 if (pp & 7) == 7 {
1474 if (pred - preds[2]).abs() > 128 { return preds[2] as i16; }
1475 if (pred - preds[0]).abs() > 128 { return preds[0] as i16; }
1476 if (pred - preds[1]).abs() > 128 { return preds[1] as i16; }
1477 }
1478 pred as i16
1479 }
1480 fn vp40_predict_dc(&self, bx: usize, by: usize, bw: usize, bh: usize, blk_idx: usize, mask: usize, is_luma: bool) -> i16 {
1481 let mut preds = [0i32; 4];
1482 let mut pp: usize = 0;
1483 let ref_id = self.blocks[blk_idx].btype.get_ref_id();
1484 if (by > 0) && (((mask >> 3) & 1) == 1) { //top
1485 fill_dc_pred!(self, ref_id, preds, pp, 0, blk_idx - bw);
1486 }
1487 if (by < bh - 1) && (((mask >> 2) & 1) == 1) { //bottom
1488 fill_dc_pred!(self, ref_id, preds, pp, 1, blk_idx + bw);
1489 }
1490 if (bx > 0) && (((mask >> 1) & 1) == 1) { //left
1491 fill_dc_pred!(self, ref_id, preds, pp, 2, blk_idx - 1);
1492 }
1493 if (is_luma && bx == 0 && (by >= 4)) && (((mask >> 1) & 1) == 1) { //left wrap
1494 fill_dc_pred!(self, ref_id, preds, pp, 2, blk_idx - 1 - 3 * bw);
1495 }
1496 if (bx < bw - 1) && (((mask >> 0) & 1) == 1) { //right
1497 fill_dc_pred!(self, ref_id, preds, pp, 3, blk_idx + 1);
1498 }
1499 if pp == 0 { return self.last_dc[ref_id as usize]; }
1500 let mut pred = 0i32;
1501 let mut npred = 0;
1502 for i in 0..4 {
1503 if (pp & (1 << i)) != 0 {
1504 pred += preds[i] as i32;
1505 npred += 1;
1506 if npred == 2 {
1507 return (pred / 2) as i16;
1508 }
1509 }
1510 }
1511 self.last_dc[ref_id as usize]
1512 }
1513 fn restore_dcs(&mut self) {
1514 let blk_stride = self.mb_w * 2;
1515 let mut blk_idx = 0;
1516 self.last_dc = [0; 3];
1517 for by in 0..self.mb_h*2 {
1518 for bx in 0..self.mb_w*2 {
1519 if !self.blocks[blk_idx + bx].coded { continue; }
1520 let dc = self.vp31_predict_dc(bx, by, self.mb_w*2, blk_idx + bx);
1521 self.blocks[blk_idx + bx].coeffs[0] += dc;
1522 self.last_dc[self.blocks[blk_idx + bx].btype.get_ref_id() as usize] = self.blocks[blk_idx + bx].coeffs[0];
1523 }
1524 blk_idx += blk_stride;
1525 }
1526 let blk_stride = self.mb_w;
1527 for _plane in 1..3 {
1528 self.last_dc = [0; 3];
1529 for by in 0..self.mb_h {
1530 for bx in 0..self.mb_w {
1531 if !self.blocks[blk_idx + bx].coded { continue; }
1532 let dc = self.vp31_predict_dc(bx, by, self.mb_w, blk_idx + bx);
1533 self.blocks[blk_idx + bx].coeffs[0] += dc;
1534 self.last_dc[self.blocks[blk_idx + bx].btype.get_ref_id() as usize] = self.blocks[blk_idx + bx].coeffs[0];
1535 }
1536 blk_idx += blk_stride;
1537 }
1538 }
1539 }
1540 fn output_blocks_intra(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
1541 let mut biter = self.blocks.iter_mut();
1542 for by in 0..self.mb_h*2 {
1543 for bx in 0..self.mb_w*2 {
1544 let mut blk = biter.next().unwrap();
1545 let qmat = &self.qmat_y;
1546 blk.coeffs[0] *= qmat[0];
1547 if blk.has_ac {
1548 unquant(&mut blk.coeffs, qmat);
1549 vp_put_block(&mut blk.coeffs, bx, by, 0, frm);
1550 } else {
1551 vp_put_block_dc(&mut blk.coeffs, bx, by, 0, frm);
1552 }
1553 }
1554 }
1555 for plane in 1..3 {
1556 for by in 0..self.mb_h {
1557 for bx in 0..self.mb_w {
1558 let mut blk = biter.next().unwrap();
1559 let qmat = &self.qmat_c;
1560 blk.coeffs[0] *= qmat[0];
1561 if blk.has_ac {
1562 unquant(&mut blk.coeffs, qmat);
1563 vp_put_block(&mut blk.coeffs, bx, by, plane, frm);
1564 } else {
1565 vp_put_block_dc(&mut blk.coeffs, bx, by, plane, frm);
1566 }
1567 }
1568 }
1569 }
1570 }
1571 #[allow(clippy::cognitive_complexity)]
1572 fn output_blocks_inter(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
1573 let mut blk_idx = 0;
1574 let bstride = self.mb_w * 2;
1575 for by in (0..self.mb_h*2).step_by(2) {
1576 for bx in (0..self.mb_w*2).step_by(2) {
1577 if self.blocks[blk_idx + bx].btype != VPMBType::InterFourMV {
1578 continue;
1579 }
1580 let mvs = [ self.blocks[blk_idx + bx].mv,
1581 self.blocks[blk_idx + bx + 1].mv,
1582 self.blocks[blk_idx + bx + bstride].mv,
1583 self.blocks[blk_idx + bx + 1 + bstride].mv ];
1584 let mut mv_sum = mvs[0] + mvs[1] + mvs[2] + mvs[3];
1585 mv_sum.x = (mv_sum.x + 2) >> 2;
1586 mv_sum.y = (mv_sum.y + 2) >> 2;
1587
1588 let src = self.shuf.get_last().unwrap();
1589 for i in 0..4 {
1590 let xoff = (i & 1) * 8;
1591 let yoff = (i >> 1) * 8;
1592
1593 let mode = vp3_mv_mode(mvs[i].x, mvs[i].y);
1594 if self.version != 4 {
1595 copy_block(frm, src.clone(), 0, bx * 8 + xoff, by * 8 + yoff,
1596 mvs[i].x >> 1, mvs[i].y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1597 } else {
1598 vp_copy_block(frm, src.clone(), 0, bx * 8 + xoff, by * 8 + yoff,
1599 mvs[i].x >> 1, mvs[i].y >> 1, 0, 1, self.loop_str,
1600 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1601 }
1602 }
1603
1604 let mx = (mv_sum.x >> 1) | (mv_sum.x & 1);
1605 let my = (mv_sum.y >> 1) | (mv_sum.y & 1);
1606 let mode = vp3_mv_mode(mx, my);
1607 copy_block(frm, src.clone(), 1, bx * 4, by * 4, mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1608 copy_block(frm, src.clone(), 2, bx * 4, by * 4, mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1609 }
1610 blk_idx += bstride * 2;
1611 }
1612
1613 let mut biter = self.blocks.iter_mut();
1614 for by in 0..self.mb_h*2 {
1615 for bx in 0..self.mb_w*2 {
1616 let mut blk = biter.next().unwrap();
1617 // do MC for whole macroblock
1618 if !blk.btype.is_intra() && (((bx | by) & 1) == 0) && (blk.btype != VPMBType::InterFourMV) {
1619 let src = if blk.btype.get_ref_id() == 1 {
1620 self.shuf.get_last().unwrap()
1621 } else {
1622 self.shuf.get_golden().unwrap()
1623 };
1624 let mode = vp3_mv_mode(blk.mv.x, blk.mv.y);
1625 if self.version != 4 {
1626 copy_block(frm, src.clone(), 0, bx * 8, by * 8,
1627 blk.mv.x >> 1, blk.mv.y >> 1, 16, 16, 0, 1, mode, VP3_INTERP_FUNCS);
1628 } else {
1629 vp_copy_block(frm, src.clone(), 0, bx * 8, by * 8,
1630 blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str,
1631 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1632 vp_copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8,
1633 blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str,
1634 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1635 vp_copy_block(frm, src.clone(), 0, bx * 8, by * 8 + 8,
1636 blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str,
1637 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1638 vp_copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8 + 8,
1639 blk.mv.x >> 1, blk.mv.y >> 1, 0, 1, self.loop_str,
1640 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1641 }
1642 let mx = (blk.mv.x >> 1) | (blk.mv.x & 1);
1643 let my = (blk.mv.y >> 1) | (blk.mv.y & 1);
1644 let mode = vp3_mv_mode(mx, my);
1645 if self.version != 4 {
1646 copy_block(frm, src.clone(), 1, bx * 4, by * 4,
1647 mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1648 copy_block(frm, src.clone(), 2, bx * 4, by * 4,
1649 mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
1650 } else {
1651 vp_copy_block(frm, src.clone(), 1, bx * 4, by * 4,
1652 mx >> 1, my >> 1, 0, 1, self.loop_str,
1653 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1654 vp_copy_block(frm, src.clone(), 2, bx * 4, by * 4,
1655 mx >> 1, my >> 1, 0, 1, self.loop_str,
1656 mode, VP3_INTERP_FUNCS, self.mc_buf.clone());
1657 }
1658 }
1659 let qmat = if blk.btype.is_intra() { &self.qmat_y } else { &self.qmat_y_p };
1660 blk.coeffs[0] *= qmat[0];
1661 if blk.has_ac {
1662 unquant(&mut blk.coeffs, qmat);
1663 }
1664 if !blk.coded {
1665 copy_block(frm, self.shuf.get_last().unwrap(), 0, bx * 8, by * 8, 0, 0, 8, 8, 0, 1, 0, VP3_INTERP_FUNCS);
1666 } else if blk.btype.is_intra() {
1667 if blk.has_ac {
1668 vp_put_block(&mut blk.coeffs, bx, by, 0, frm);
1669 } else {
1670 vp_put_block_dc(&mut blk.coeffs, bx, by, 0, frm);
1671 }
1672 } else {
1673 if blk.has_ac {
1674 vp_add_block(&mut blk.coeffs, bx, by, 0, frm);
1675 } else {
1676 vp_add_block_dc(&mut blk.coeffs, bx, by, 0, frm);
1677 }
1678 }
1679 }
1680 }
1681 for plane in 1..3 {
1682 for by in 0..self.mb_h {
1683 for bx in 0..self.mb_w {
1684 let mut blk = biter.next().unwrap();
1685 let qmat = if blk.btype.is_intra() { &self.qmat_c } else { &self.qmat_c_p };
1686 blk.coeffs[0] *= qmat[0];
1687 if blk.has_ac {
1688 unquant(&mut blk.coeffs, qmat);
1689 }
1690 if !blk.coded {
1691 copy_block(frm, self.shuf.get_last().unwrap(), plane, bx * 8, by * 8, 0, 0, 8, 8, 0, 1, 0, VP3_INTERP_FUNCS);
1692 } else if blk.btype.is_intra() {
1693 if blk.has_ac {
1694 vp_put_block(&mut blk.coeffs, bx, by, plane, frm);
1695 } else {
1696 vp_put_block_dc(&mut blk.coeffs, bx, by, plane, frm);
1697 }
1698 } else {
1699 if blk.has_ac {
1700 vp_add_block(&mut blk.coeffs, bx, by, plane, frm);
1701 } else {
1702 vp_add_block_dc(&mut blk.coeffs, bx, by, plane, frm);
1703 }
1704 }
1705 }
1706 }
1707 }
1708 }
1709 fn vp31_loop_filter(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
1710 let mut blk_idx = 0;
1711 let blk_w = self.mb_w * 2;
1712 for by in 0..self.mb_h*2 {
1713 for bx in 0..blk_w {
1714 let blk = &self.blocks[blk_idx + bx];
1715 if (bx > 0) && blk.coded {
1716 vp31_loop_filter_v(frm, bx * 8, by * 8, 0, self.loop_str);
1717 }
1718 if (by > 0) && blk.coded {
1719 vp31_loop_filter_h(frm, bx * 8, by * 8, 0, self.loop_str);
1720 }
1721 if (bx < blk_w - 1) && !self.blocks[blk_idx + bx + 1].coded {
1722 vp31_loop_filter_v(frm, bx * 8 + 8, by * 8, 0, self.loop_str);
1723 }
1724 if (by < self.mb_h * 2 - 1) && !self.blocks[blk_idx + bx + blk_w].coded {
1725 vp31_loop_filter_h(frm, bx * 8, by * 8 + 8, 0, self.loop_str);
1726 }
1727 }
1728 blk_idx += blk_w;
1729 }
1730 let blk_w = self.mb_w;
1731 for plane in 1..3 {
1732 for by in 0..self.mb_h {
1733 for bx in 0..self.mb_w {
1734 let blk = &self.blocks[blk_idx + bx];
1735 if (bx > 0) && blk.coded {
1736 vp31_loop_filter_v(frm, bx * 8, by * 8, plane, self.loop_str);
1737 }
1738 if (by > 0) && blk.coded {
1739 vp31_loop_filter_h(frm, bx * 8, by * 8, plane, self.loop_str);
1740 }
1741 if (bx < blk_w - 1) && !self.blocks[blk_idx + bx + 1].coded {
1742 vp31_loop_filter_v(frm, bx * 8 + 8, by * 8, plane, self.loop_str);
1743 }
1744 if (by < self.mb_h - 1) && !self.blocks[blk_idx + bx + blk_w].coded {
1745 vp31_loop_filter_h(frm, bx * 8, by * 8 + 8, plane, self.loop_str);
1746 }
1747 }
1748 blk_idx += blk_w;
1749 }
1750 }
1751 }
1752 fn generate_block_addr(&mut self) {
1753 let sb_w_y = (self.width + 31) >> 5;
1754 let sb_h_y = (self.height + 31) >> 5;
1755 let sb_w_c = ((self.width >> 1) + 31) >> 5;
1756 let sb_h_c = ((self.height >> 1) + 31) >> 5;
1757 self.y_sbs = sb_w_y * sb_h_y;
1758 let tot_sb = sb_w_y * sb_h_y + 2 * sb_w_c * sb_h_c;
1759 let tot_mb = self.mb_w * self.mb_h * 2 + ((self.mb_w + 1) & !1) * ((self.mb_h + 1) & !1) * 2;
1760 let bw = self.width >> 3;
1761 let bh = self.height >> 3;
1762 let tot_blk = bw * bh * 3 / 2;
1763 self.sb_info.resize(tot_sb, SBState::Uncoded);
1764 self.sb_blocks = Vec::with_capacity(tot_sb);
1765 self.mb_blocks = Vec::with_capacity(tot_mb);
1766 self.sb_mbs = Vec::with_capacity(tot_sb);
1767 self.blk_addr = Vec::with_capacity(tot_blk);
1768 self.blk_sub = Vec::with_capacity(tot_blk);
1769 self.y_blocks = bw * bh;
1770 let mut base_idx = 0;
1771 for plane in 0..3 {
1772 let w = if plane > 0 { self.width >> 1 } else { self.width };
1773 let h = if plane > 0 { self.height >> 1 } else { self.height };
1774 let sb_w = (w + 31) >> 5;
1775 let sb_h = (h + 31) >> 5;
1776 let blk_w = w >> 3;
1777 let blk_h = h >> 3;
1778 for y in 0..sb_h {
1779 for x in 0..sb_w {
1780 let mut nmbs = 0;
1781 for mb_no in 0..4 {
1782 let bx = x * 4 + HILBERT_ORDER[mb_no * 4][0];
1783 let by = y * 4 + HILBERT_ORDER[mb_no * 4][1];
1784 if (bx >= blk_w) || (by >= blk_h) { continue; }
1785 let mut nblocks = 0;
1786 for blk_no in 0..4 {
1787 let bx = x * 4 + HILBERT_ORDER[mb_no * 4 + blk_no][0];
1788 let by = y * 4 + HILBERT_ORDER[mb_no * 4 + blk_no][1];
1789 if (bx >= blk_w) || (by >= blk_h) { continue; }
1790 nblocks += 1;
1791 }
1792 self.mb_blocks.push(nblocks);
1793 nmbs += 1;
1794 }
1795 self.sb_mbs.push(nmbs);
1796
1797 let mut nblocks = 0;
1798 for blk_no in 0..16 {
1799 let bx = x * 4 + HILBERT_ORDER[blk_no][0];
1800 let by = y * 4 + HILBERT_ORDER[blk_no][1];
1801 if (bx >= blk_w) || (by >= blk_h) { continue; }
1802 let idx = base_idx + bx + by * blk_w;
1803 self.blk_addr.push(idx * 4 + plane);
1804 self.blk_sub.push(blk_no as u8);
1805 nblocks += 1;
1806 }
1807 self.sb_blocks.push(nblocks);
1808 }
1809 }
1810 base_idx += blk_w * blk_h;
1811 }
1812 self.blocks.resize(tot_blk, Block::new());
1813 self.mb_coded.resize(tot_mb, false);
1814 self.mb_partial.resize(tot_mb, false);
1815 }
1816}
1817
1818impl NADecoder for VP34Decoder {
1819 fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
1820 if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
1821 let fmt = YUV420_FORMAT;
1822 self.width = vinfo.get_width();
1823 self.height = vinfo.get_height();
1824 validate!(((self.width | self.height) & 15) == 0);
1825 self.mb_w = self.width >> 4;
1826 self.mb_h = self.height >> 4;
1827 let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), true, fmt));
1828 self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
1829 supp.pool_u8.set_dec_bufs(3);
1830 supp.pool_u8.prealloc_video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), true, fmt), 4)?;
1831
1832 self.generate_block_addr();
1833 if self.version == 4 {
1834 self.codes = Codes::VP31(VP31Codes::new_vp4());
1835 self.aux_codes = Some(VP40AuxCodes::new());
1836 }
1837 Ok(())
1838 } else {
1839 Err(DecoderError::InvalidData)
1840 }
1841 }
1842 fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
1843 let src = pkt.get_buffer();
1844 validate!(src.len() > 0);
1845 let mut br = BitReader::new(&src, BitReaderMode::BE);
1846
1847 self.parse_header(&mut br)?;
1848 if self.is_intra {
1849 self.shuf.clear();
1850 } else {
1851 if !self.shuf.has_refs() {
1852 return Err(DecoderError::MissingReference);
1853 }
1854 }
1855
1856 let ret = supp.pool_u8.get_free();
1857 if ret.is_none() {
1858 return Err(DecoderError::AllocError);
1859 }
1860 let mut buf = ret.unwrap();
1861 let mut dframe = NASimpleVideoFrame::from_video_buf(&mut buf).unwrap();
1862 match self.version {
1863 30 => self.decode_vp30(&mut br, &mut dframe)?,
1864 31 => self.decode_vp31(&mut br, &mut dframe)?,
1865 4 => self.decode_vp4(&mut br, &mut dframe)?,
1866 _ => return Err(DecoderError::Bug),
1867 }
1868
1869 if self.is_intra || self.update_gf {
1870 self.shuf.add_golden_frame(buf.clone());
1871 }
1872 self.shuf.add_frame(buf.clone());
1873
1874 let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), NABufferType::Video(buf));
1875 frm.set_keyframe(self.is_intra);
1876 frm.set_frame_type(if self.is_intra { FrameType::I } else { FrameType::P });
1877 Ok(frm.into_ref())
1878 }
1879 fn flush(&mut self) {
1880 self.shuf.clear();
1881 }
1882}
1883
1884impl NAOptionHandler for VP34Decoder {
1885 fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
1886 fn set_options(&mut self, _options: &[NAOption]) { }
1887 fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
1888}
1889
1890pub fn get_decoder_vp3() -> Box<dyn NADecoder + Send> {
1891 Box::new(VP34Decoder::new(3))
1892}
1893
1894pub fn get_decoder_vp4() -> Box<dyn NADecoder + Send> {
1895 Box::new(VP34Decoder::new(4))
1896}
1897
1898#[cfg(test)]
1899mod test {
1900 use nihav_core::codecs::RegisteredDecoders;
1901 use nihav_core::demuxers::RegisteredDemuxers;
1902 use nihav_codec_support::test::dec_video::*;
1903 use crate::duck_register_all_decoders;
1904 use nihav_commonfmt::generic_register_all_demuxers;
1905
1906 #[test]
1907 fn test_vp30() {
1908 let mut dmx_reg = RegisteredDemuxers::new();
1909 generic_register_all_demuxers(&mut dmx_reg);
1910 let mut dec_reg = RegisteredDecoders::new();
1911 duck_register_all_decoders(&mut dec_reg);
1912
1913 // sample: https://samples.mplayerhq.hu/V-codecs/VP3/vp30-logo.avi
1914 test_decoding("avi", "vp3", "assets/Duck/vp30-logo.avi", Some(23), &dmx_reg, &dec_reg,
1915 ExpectedTestResult::MD5([0x51aba7df, 0x6e42534d, 0xef6c5b13, 0x26c38d1f]));
1916 }
1917
1918 #[test]
1919 fn test_vp31() {
1920 let mut dmx_reg = RegisteredDemuxers::new();
1921 generic_register_all_demuxers(&mut dmx_reg);
1922 let mut dec_reg = RegisteredDecoders::new();
1923 duck_register_all_decoders(&mut dec_reg);
1924
1925// let file = "assets/Duck/vp31.avi";
1926// let file = "assets/Duck/vp31_crash.avi";
1927// let file = "assets/Duck/01-vp31-0500.avi";
1928// test_file_decoding("avi", file, Some(3), true, false, None/*Some("vp31")*/, &dmx_reg, &dec_reg);
1929//panic!("end");
1930 // sample: https://samples.mplayerhq.hu/V-codecs/VP3/01-vp31-0500.avi
1931 test_decoding("avi", "vp3", "assets/Duck/01-vp31-0500.avi", Some(16), &dmx_reg, &dec_reg,
1932 ExpectedTestResult::MD5([0x65112f7e, 0x2914f29b, 0x2908ed2f, 0xce5fc8c5]));
1933 }
1934
1935 #[test]
1936 fn test_vp4() {
1937 let mut dmx_reg = RegisteredDemuxers::new();
1938 generic_register_all_demuxers(&mut dmx_reg);
1939 let mut dec_reg = RegisteredDecoders::new();
1940 duck_register_all_decoders(&mut dec_reg);
1941
1942 // sample: https://samples.mplayerhq.hu/V-codecs/VP4/ot171_vp40.avi
1943 test_decoding("avi", "vp3", "assets/Duck/ot171_vp40.avi", Some(86), &dmx_reg, &dec_reg,
1944 ExpectedTestResult::MD5([0xd41d8cd9, 0x8f00b204, 0xe9800998, 0xecf8427e]));
1945 }
1946}
1947
1948const HILBERT_ORDER: [[usize; 2]; 16] = [
1949 [ 0, 0 ], [ 1, 0 ], [ 1, 1 ], [ 0, 1 ],
1950 [ 0, 2 ], [ 0, 3 ], [ 1, 3 ], [ 1, 2 ],
1951 [ 2, 2 ], [ 2, 3 ], [ 3, 3 ], [ 3, 2 ],
1952 [ 3, 1 ], [ 2, 1 ], [ 2, 0 ], [ 3, 0 ]
1953];
1954
1955const VP31_LOOP_STRENGTH: [i16; 64] = [
1956 30, 25, 20, 20, 15, 15, 14, 14,
1957 13, 13, 12, 12, 11, 11, 10, 10,
1958 9, 9, 8, 8, 7, 7, 7, 7,
1959 6, 6, 6, 6, 5, 5, 5, 5,
1960 4, 4, 4, 4, 3, 3, 3, 3,
1961 2, 2, 2, 2, 2, 2, 2, 2,
1962 0, 0, 0, 0, 0, 0, 0, 0,
1963 0, 0, 0, 0, 0, 0, 0, 0
1964];
1965
1966const VP31_DEFAULT_MB_MODES: [VPMBType; 8] = [
1967 VPMBType::InterNoMV, VPMBType::Intra, VPMBType::InterMV, VPMBType::InterNearest,
1968 VPMBType::InterNear, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1969];
1970
1971const VP31_MB_MODES: [[VPMBType; 8]; 6] = [
1972 [
1973 VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterMV, VPMBType::InterNoMV,
1974 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1975 ], [
1976 VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterNoMV, VPMBType::InterMV,
1977 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1978 ], [
1979 VPMBType::InterNearest, VPMBType::InterMV, VPMBType::InterNear, VPMBType::InterNoMV,
1980 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1981 ], [
1982 VPMBType::InterNearest, VPMBType::InterMV, VPMBType::InterNoMV, VPMBType::InterNear,
1983 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1984 ], [
1985 VPMBType::InterNoMV, VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterMV,
1986 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1987 ], [
1988 VPMBType::InterNoMV, VPMBType::GoldenNoMV, VPMBType::InterNearest, VPMBType::InterNear,
1989 VPMBType::InterMV, VPMBType::Intra, VPMBType::GoldenMV, VPMBType::InterFourMV
1990 ]
1991];
1992
1993const VP3_LITERAL_BASE: [i16; 6] = [ 7, 9, 13, 21, 37, 69 ];
1994
1995const VP31_AC_SCALES: [i16; 64] = [
1996 500, 450, 400, 370, 340, 310, 285, 265,
1997 245, 225, 210, 195, 185, 180, 170, 160,
1998 150, 145, 135, 130, 125, 115, 110, 107,
1999 100, 96, 93, 89, 85, 82, 75, 74,
2000 70, 68, 64, 60, 57, 56, 52, 50,
2001 49, 45, 44, 43, 40, 38, 37, 35,
2002 33, 32, 30, 29, 28, 25, 24, 22,
2003 21, 19, 18, 17, 15, 13, 12, 10
2004];
2005
2006const VP31_DC_SCALES: [i16; 64] = [
2007 220, 200, 190, 180, 170, 170, 160, 160,
2008 150, 150, 140, 140, 130, 130, 120, 120,
2009 110, 110, 100, 100, 90, 90, 90, 80,
2010 80, 80, 70, 70, 70, 60, 60, 60,
2011 60, 50, 50, 50, 50, 40, 40, 40,
2012 40, 40, 30, 30, 30, 30, 30, 30,
2013 30, 20, 20, 20, 20, 20, 20, 20,
2014 20, 10, 10, 10, 10, 10, 10, 10
2015];
2016
2017const VP3_QMAT_Y: &[i16; 64] = &[
2018 16, 11, 10, 16, 24, 40, 51, 61,
2019 12, 12, 14, 19, 26, 58, 60, 55,
2020 14, 13, 16, 24, 40, 57, 69, 56,
2021 14, 17, 22, 29, 51, 87, 80, 62,
2022 18, 22, 37, 58, 68, 109, 103, 77,
2023 24, 35, 55, 64, 81, 104, 113, 92,
2024 49, 64, 78, 87, 103, 121, 120, 101,
2025 72, 92, 95, 98, 112, 100, 103, 99
2026];
2027
2028const VP3_QMAT_C: &[i16; 64] = &[
2029 17, 18, 24, 47, 99, 99, 99, 99,
2030 18, 21, 26, 66, 99, 99, 99, 99,
2031 24, 26, 56, 99, 99, 99, 99, 99,
2032 47, 66, 99, 99, 99, 99, 99, 99,
2033 99, 99, 99, 99, 99, 99, 99, 99,
2034 99, 99, 99, 99, 99, 99, 99, 99,
2035 99, 99, 99, 99, 99, 99, 99, 99,
2036 99, 99, 99, 99, 99, 99, 99, 99
2037];
2038
2039const VP3_QMAT_INTER: &[i16; 64] = &[
2040 16, 16, 16, 20, 24, 28, 32, 40,
2041 16, 16, 20, 24, 28, 32, 40, 48,
2042 16, 20, 24, 28, 32, 40, 48, 64,
2043 20, 24, 28, 32, 40, 48, 64, 64,
2044 24, 28, 32, 40, 48, 64, 64, 64,
2045 28, 32, 40, 48, 64, 64, 64, 96,
2046 32, 40, 48, 64, 64, 64, 96, 128,
2047 40, 48, 64, 64, 64, 96, 128, 128
2048];
2049
2050const VP31_DC_CODES: [[u16; 32]; 16] = [
2051 [
2052 0x002D, 0x0026, 0x0166, 0x004E, 0x02CE, 0x059E, 0x027D, 0x0008,
2053 0x04F9, 0x000F, 0x000E, 0x001B, 0x0006, 0x0008, 0x0005, 0x001A,
2054 0x0015, 0x0007, 0x000C, 0x0001, 0x0000, 0x0009, 0x0017, 0x0029,
2055 0x0028, 0x00B2, 0x04F8, 0x059F, 0x009E, 0x013F, 0x0012, 0x0058,
2056 ], [
2057 0x0010, 0x0047, 0x01FF, 0x008C, 0x03FC, 0x046A, 0x0469, 0x0022,
2058 0x11A1, 0x000E, 0x000D, 0x0004, 0x0005, 0x0009, 0x0006, 0x001E,
2059 0x0016, 0x0007, 0x000C, 0x0001, 0x0000, 0x000A, 0x0017, 0x007D,
2060 0x007E, 0x011B, 0x08D1, 0x03FD, 0x046B, 0x11A0, 0x007C, 0x00FE,
2061 ], [
2062 0x0016, 0x0020, 0x0086, 0x0087, 0x0367, 0x06CC, 0x06CB, 0x006E,
2063 0x366D, 0x000F, 0x000E, 0x0004, 0x0005, 0x000A, 0x0006, 0x001A,
2064 0x0011, 0x0007, 0x000C, 0x0001, 0x0000, 0x0009, 0x0017, 0x006F,
2065 0x006D, 0x0364, 0x0D9A, 0x06CA, 0x1B37, 0x366C, 0x0042, 0x00D8,
2066 ], [
2067 0x0000, 0x002D, 0x00F7, 0x0058, 0x0167, 0x02CB, 0x02CA, 0x000E,
2068 0x1661, 0x0003, 0x0002, 0x0008, 0x0009, 0x000D, 0x0002, 0x001F,
2069 0x0017, 0x0001, 0x000C, 0x000E, 0x000A, 0x0006, 0x0078, 0x000F,
2070 0x007A, 0x0164, 0x0599, 0x02CD, 0x0B31, 0x1660, 0x0079, 0x00F6,
2071 ], [
2072 0x0003, 0x003C, 0x000F, 0x007A, 0x001D, 0x0020, 0x0072, 0x0006,
2073 0x0399, 0x0004, 0x0005, 0x0005, 0x0006, 0x000E, 0x0004, 0x0000,
2074 0x0019, 0x0002, 0x000D, 0x0007, 0x001F, 0x0030, 0x0011, 0x0031,
2075 0x0005, 0x0021, 0x00E7, 0x0038, 0x01CD, 0x0398, 0x007B, 0x0009,
2076 ], [
2077 0x0009, 0x0002, 0x0074, 0x0007, 0x00EC, 0x00D1, 0x01A6, 0x0006,
2078 0x0D21, 0x0005, 0x0006, 0x0008, 0x0007, 0x000F, 0x0004, 0x0000,
2079 0x001C, 0x0002, 0x0005, 0x0003, 0x000C, 0x0035, 0x01A7, 0x001B,
2080 0x0077, 0x01A5, 0x0349, 0x00D0, 0x0691, 0x0D20, 0x0075, 0x00ED,
2081 ], [
2082 0x000A, 0x000C, 0x0012, 0x001B, 0x00B7, 0x016C, 0x0099, 0x005A,
2083 0x16D8, 0x0007, 0x0006, 0x0009, 0x0008, 0x0000, 0x0005, 0x0017,
2084 0x000E, 0x0002, 0x0003, 0x000F, 0x001A, 0x004D, 0x2DB3, 0x002C,
2085 0x0011, 0x02DA, 0x05B7, 0x0098, 0x0B6D, 0x2DB2, 0x0010, 0x0027,
2086 ], [
2087 0x000D, 0x000F, 0x001D, 0x0008, 0x0051, 0x0056, 0x00AF, 0x002A,
2088 0x148A, 0x0007, 0x0000, 0x0008, 0x0009, 0x000C, 0x0006, 0x0017,
2089 0x000B, 0x0016, 0x0015, 0x0009, 0x0050, 0x00AE, 0x2917, 0x001C,
2090 0x0014, 0x0290, 0x0523, 0x0149, 0x0A44, 0x2916, 0x0053, 0x00A5,
2091 ], [
2092 0x0001, 0x001D, 0x00F5, 0x00F4, 0x024D, 0x0499, 0x0498, 0x0001,
2093 0x0021, 0x0006, 0x0005, 0x0006, 0x0005, 0x0002, 0x0007, 0x0025,
2094 0x007B, 0x001C, 0x0020, 0x000D, 0x0048, 0x0092, 0x0127, 0x000E,
2095 0x0004, 0x0011, 0x000C, 0x003C, 0x000F, 0x0000, 0x001F, 0x0013,
2096 ], [
2097 0x0005, 0x003C, 0x0040, 0x000D, 0x0031, 0x0061, 0x0060, 0x0002,
2098 0x00F5, 0x0006, 0x0005, 0x0007, 0x0006, 0x0002, 0x0009, 0x0025,
2099 0x0007, 0x0021, 0x0024, 0x0010, 0x0041, 0x00F4, 0x0019, 0x000E,
2100 0x0003, 0x0011, 0x0011, 0x003F, 0x003E, 0x007B, 0x0000, 0x0013,
2101 ], [
2102 0x000A, 0x0007, 0x0001, 0x0009, 0x0131, 0x0261, 0x0260, 0x0015,
2103 0x0001, 0x0007, 0x0006, 0x0008, 0x0007, 0x0006, 0x0012, 0x002F,
2104 0x0014, 0x0027, 0x002D, 0x0016, 0x004D, 0x0099, 0x0000, 0x0004,
2105 0x0001, 0x0005, 0x0017, 0x002E, 0x002C, 0x0008, 0x0006, 0x0001,
2106 ], [
2107 0x0000, 0x000E, 0x0017, 0x002A, 0x0010, 0x00F9, 0x00F8, 0x001E,
2108 0x003F, 0x0007, 0x0006, 0x0009, 0x0008, 0x0006, 0x000F, 0x0005,
2109 0x0016, 0x0029, 0x002B, 0x0015, 0x0050, 0x0011, 0x007D, 0x0004,
2110 0x0017, 0x0006, 0x0014, 0x002C, 0x002D, 0x000E, 0x0009, 0x0051,
2111 ], [
2112 0x0002, 0x0018, 0x002F, 0x000D, 0x0053, 0x0295, 0x0294, 0x00A4,
2113 0x007C, 0x0000, 0x0007, 0x0009, 0x0008, 0x001B, 0x000C, 0x0028,
2114 0x006A, 0x001E, 0x001D, 0x0069, 0x00D7, 0x007D, 0x014B, 0x0019,
2115 0x0016, 0x002E, 0x001C, 0x002B, 0x002A, 0x0068, 0x003F, 0x00D6,
2116 ], [
2117 0x0002, 0x001B, 0x000C, 0x0018, 0x0029, 0x007F, 0x02F0, 0x0198,
2118 0x0179, 0x0000, 0x0007, 0x0009, 0x0008, 0x001A, 0x000D, 0x002A,
2119 0x0064, 0x001E, 0x0067, 0x005F, 0x00CD, 0x007E, 0x02F1, 0x0016,
2120 0x000E, 0x002E, 0x0065, 0x002B, 0x0028, 0x003E, 0x00BD, 0x0199,
2121 ], [
2122 0x0002, 0x0007, 0x0016, 0x0006, 0x0036, 0x005C, 0x015D, 0x015C,
2123 0x02BF, 0x0000, 0x0007, 0x0009, 0x0008, 0x0018, 0x0034, 0x002A,
2124 0x005E, 0x006A, 0x0064, 0x005D, 0x00CB, 0x00AD, 0x02BE, 0x0014,
2125 0x0033, 0x006E, 0x005F, 0x006F, 0x006B, 0x00CA, 0x00AC, 0x015E,
2126 ], [
2127 0x000F, 0x001D, 0x0018, 0x000B, 0x0019, 0x0029, 0x00D6, 0x0551,
2128 0x0AA1, 0x0001, 0x0000, 0x0009, 0x0008, 0x001B, 0x0038, 0x0028,
2129 0x0057, 0x006A, 0x0068, 0x0056, 0x00E5, 0x0155, 0x0AA0, 0x0073,
2130 0x0069, 0x00D7, 0x00AB, 0x00E4, 0x00A9, 0x0151, 0x0150, 0x02A9,
2131 ]
2132];
2133
2134const VP31_DC_BITS: [[u8; 32]; 16] = [
2135 [
2136 6, 7, 9, 8, 10, 11, 11, 5, 12, 4, 4, 5, 4, 4, 4, 5,
2137 5, 4, 4, 3, 3, 4, 5, 6, 6, 8, 12, 11, 9, 10, 6, 7,
2138 ], [
2139 5, 7, 9, 8, 10, 11, 11, 6, 13, 4, 4, 4, 4, 4, 4, 5,
2140 5, 4, 4, 3, 3, 4, 5, 7, 7, 9, 12, 10, 11, 13, 7, 8,
2141 ], [
2142 5, 6, 8, 8, 10, 11, 11, 7, 14, 4, 4, 4, 4, 4, 4, 5,
2143 5, 4, 4, 3, 3, 4, 5, 7, 7, 10, 12, 11, 13, 14, 7, 8,
2144 ], [
2145 4, 6, 8, 7, 9, 10, 10, 6, 13, 3, 3, 4, 4, 4, 4, 5,
2146 5, 4, 4, 4, 4, 5, 7, 6, 7, 9, 11, 10, 12, 13, 7, 8,
2147 ], [
2148 4, 6, 7, 7, 8, 9, 10, 6, 13, 3, 3, 4, 4, 4, 4, 4,
2149 5, 4, 4, 4, 5, 6, 8, 6, 6, 9, 11, 9, 12, 13, 7, 7,
2150 ], [
2151 4, 5, 7, 6, 8, 9, 10, 6, 13, 3, 3, 4, 4, 4, 4, 4,
2152 5, 4, 4, 4, 5, 7, 10, 6, 7, 10, 11, 9, 12, 13, 7, 8,
2153 ], [
2154 4, 5, 6, 6, 8, 9, 9, 7, 13, 3, 3, 4, 4, 3, 4, 5,
2155 5, 4, 4, 5, 6, 8, 14, 6, 6, 10, 11, 9, 12, 14, 6, 7,
2156 ], [
2157 4, 5, 6, 5, 7, 8, 9, 7, 13, 3, 2, 4, 4, 4, 4, 5,
2158 5, 5, 5, 5, 7, 9, 14, 6, 6, 10, 11, 9, 12, 14, 7, 8,
2159 ], [
2160 4, 6, 8, 8, 10, 11, 11, 5, 6, 3, 3, 4, 4, 4, 5, 6,
2161 7, 6, 6, 6, 7, 8, 9, 4, 4, 5, 6, 6, 5, 5, 5, 5,
2162 ], [
2163 4, 6, 7, 7, 9, 10, 10, 5, 8, 3, 3, 4, 4, 4, 5, 6,
2164 6, 6, 6, 6, 7, 8, 8, 4, 4, 5, 6, 6, 6, 7, 4, 5,
2165 ], [
2166 4, 5, 6, 6, 9, 10, 10, 6, 7, 3, 3, 4, 4, 4, 5, 6,
2167 6, 6, 6, 6, 7, 8, 7, 4, 4, 5, 6, 6, 6, 6, 5, 5,
2168 ], [
2169 3, 5, 6, 6, 7, 10, 10, 7, 8, 3, 3, 4, 4, 4, 5, 5,
2170 6, 6, 6, 6, 7, 7, 9, 4, 5, 5, 6, 6, 6, 6, 6, 7,
2171 ], [
2172 3, 5, 6, 5, 7, 10, 10, 8, 8, 2, 3, 4, 4, 5, 5, 6,
2173 7, 6, 6, 7, 8, 8, 9, 5, 5, 6, 6, 6, 6, 7, 7, 8,
2174 ], [
2175 3, 5, 5, 5, 6, 8, 10, 9, 9, 2, 3, 4, 4, 5, 5, 6,
2176 7, 6, 7, 7, 8, 8, 10, 5, 5, 6, 7, 6, 6, 7, 8, 9,
2177 ], [
2178 3, 4, 5, 4, 6, 7, 9, 9, 10, 2, 3, 4, 4, 5, 6, 6,
2179 7, 7, 7, 7, 8, 8, 10, 5, 6, 7, 7, 7, 7, 8, 8, 9,
2180 ], [
2181 4, 5, 5, 4, 5, 6, 8, 11, 12, 2, 2, 4, 4, 5, 6, 6,
2182 7, 7, 7, 7, 8, 9, 12, 7, 7, 8, 8, 8, 8, 9, 9, 10,
2183 ]
2184];
2185
2186const VP31_AC_CAT0_CODES: [[u16; 32]; 16] = [
2187 [
2188 0x0008, 0x0025, 0x017A, 0x02F7, 0x0BDB, 0x17B4, 0x2F6B, 0x001D,
2189 0x2F6A, 0x0008, 0x0007, 0x0001, 0x0002, 0x000A, 0x0006, 0x0000,
2190 0x001C, 0x0009, 0x000D, 0x000F, 0x000C, 0x0003, 0x000A, 0x0016,
2191 0x0013, 0x005D, 0x0024, 0x00BC, 0x005C, 0x05EC, 0x000B, 0x005F,
2192 ], [
2193 0x000F, 0x0010, 0x004B, 0x00C6, 0x031D, 0x0C71, 0x0C70, 0x0001,
2194 0x0C73, 0x0008, 0x0009, 0x0002, 0x0003, 0x000B, 0x0006, 0x0000,
2195 0x001C, 0x0005, 0x000D, 0x000F, 0x000A, 0x0019, 0x0013, 0x001D,
2196 0x0030, 0x0062, 0x0024, 0x004A, 0x018F, 0x0C72, 0x000E, 0x0011,
2197 ], [
2198 0x001B, 0x0003, 0x008D, 0x0040, 0x0239, 0x0471, 0x08E0, 0x0003,
2199 0x11C3, 0x000A, 0x0009, 0x0004, 0x0005, 0x000E, 0x0007, 0x0001,
2200 0x001E, 0x0006, 0x000C, 0x000B, 0x0002, 0x0000, 0x0041, 0x001F,
2201 0x0022, 0x0002, 0x008F, 0x008C, 0x011D, 0x11C2, 0x001A, 0x0021,
2202 ], [
2203 0x001F, 0x0003, 0x0003, 0x0043, 0x000B, 0x0015, 0x0051, 0x0003,
2204 0x0050, 0x000D, 0x000C, 0x0004, 0x0006, 0x000E, 0x000A, 0x0001,
2205 0x001E, 0x0005, 0x0009, 0x0007, 0x0011, 0x0002, 0x0004, 0x0002,
2206 0x002D, 0x0020, 0x0042, 0x0001, 0x0000, 0x0029, 0x0017, 0x002C,
2207 ], [
2208 0x0003, 0x001F, 0x003A, 0x005D, 0x0173, 0x02E4, 0x172D, 0x0004,
2209 0x172C, 0x000F, 0x000E, 0x0009, 0x0008, 0x000C, 0x000A, 0x0001,
2210 0x0016, 0x0002, 0x0005, 0x001A, 0x002F, 0x0038, 0x05CA, 0x0006,
2211 0x0037, 0x001E, 0x003B, 0x0039, 0x00B8, 0x0B97, 0x0000, 0x0036,
2212 ], [
2213 0x0006, 0x0037, 0x005D, 0x000C, 0x00B9, 0x02E3, 0x05C4, 0x0004,
2214 0x1715, 0x0000, 0x000F, 0x0008, 0x0007, 0x000C, 0x0009, 0x001D,
2215 0x0016, 0x001C, 0x001A, 0x000B, 0x005E, 0x0170, 0x1714, 0x000A,
2216 0x000A, 0x0036, 0x005F, 0x001B, 0x001A, 0x0B8B, 0x0002, 0x0007,
2217 ], [
2218 0x000C, 0x000B, 0x0079, 0x0022, 0x00F0, 0x0119, 0x0230, 0x001D,
2219 0x08C4, 0x0001, 0x0000, 0x000A, 0x0009, 0x000B, 0x0007, 0x001C,
2220 0x003D, 0x000D, 0x0008, 0x0015, 0x008D, 0x118B, 0x118A, 0x000D,
2221 0x0010, 0x0009, 0x0014, 0x0047, 0x00F1, 0x0463, 0x001F, 0x000C,
2222 ], [
2223 0x0000, 0x001A, 0x0033, 0x000C, 0x0046, 0x01E3, 0x03C5, 0x0017,
2224 0x1E21, 0x0002, 0x0001, 0x0009, 0x000A, 0x0007, 0x001B, 0x003D,
2225 0x001B, 0x0022, 0x0079, 0x00F0, 0x1E20, 0x1E23, 0x1E22, 0x000E,
2226 0x0016, 0x0018, 0x0032, 0x001A, 0x0047, 0x0789, 0x001F, 0x0010,
2227 ], [
2228 0x001D, 0x0061, 0x004E, 0x009E, 0x027C, 0x09F5, 0x09F4, 0x0003,
2229 0x0060, 0x0000, 0x000F, 0x000B, 0x000A, 0x0009, 0x0005, 0x000D,
2230 0x0031, 0x0008, 0x0038, 0x0012, 0x0026, 0x013F, 0x04FB, 0x000D,
2231 0x0002, 0x000C, 0x0039, 0x001C, 0x000F, 0x001D, 0x0008, 0x0019,
2232 ], [
2233 0x0007, 0x0019, 0x00AB, 0x00AA, 0x0119, 0x0461, 0x0460, 0x001B,
2234 0x0047, 0x0001, 0x0000, 0x000C, 0x000B, 0x0009, 0x0005, 0x000D,
2235 0x0035, 0x003D, 0x003C, 0x0018, 0x0022, 0x008D, 0x0231, 0x000E,
2236 0x001F, 0x0009, 0x002B, 0x0010, 0x0034, 0x0054, 0x0008, 0x0014,
2237 ], [
2238 0x000C, 0x0005, 0x0008, 0x005B, 0x004D, 0x0131, 0x0261, 0x001A,
2239 0x0012, 0x0000, 0x000F, 0x000A, 0x0009, 0x0006, 0x001B, 0x0006,
2240 0x001C, 0x002C, 0x0015, 0x005A, 0x0027, 0x0099, 0x0260, 0x000E,
2241 0x0004, 0x000F, 0x0007, 0x001D, 0x000B, 0x0014, 0x0008, 0x0017,
2242 ], [
2243 0x000F, 0x0013, 0x0075, 0x0024, 0x0095, 0x0251, 0x04A0, 0x0010,
2244 0x00C8, 0x0002, 0x0001, 0x0001, 0x0000, 0x001A, 0x0011, 0x002C,
2245 0x0065, 0x0074, 0x004B, 0x00C9, 0x0129, 0x0943, 0x0942, 0x0003,
2246 0x000A, 0x001C, 0x0018, 0x0033, 0x0017, 0x002D, 0x001B, 0x003B,
2247 ], [
2248 0x0003, 0x001A, 0x002D, 0x0038, 0x0028, 0x0395, 0x0E51, 0x0037,
2249 0x00E4, 0x0001, 0x0000, 0x001F, 0x001E, 0x0017, 0x003A, 0x0073,
2250 0x002A, 0x002B, 0x0029, 0x01CB, 0x0729, 0x1CA1, 0x1CA0, 0x0004,
2251 0x000A, 0x0004, 0x0018, 0x0036, 0x000B, 0x002C, 0x0019, 0x003B,
2252 ], [
2253 0x0004, 0x0004, 0x003F, 0x0017, 0x0075, 0x01F5, 0x07D1, 0x0017,
2254 0x01F6, 0x0001, 0x0000, 0x001B, 0x001A, 0x000A, 0x0032, 0x0074,
2255 0x00F8, 0x00F9, 0x01F7, 0x03E9, 0x0FA0, 0x1F43, 0x1F42, 0x0003,
2256 0x000A, 0x001E, 0x001C, 0x003B, 0x0018, 0x0016, 0x0016, 0x0033,
2257 ], [
2258 0x0004, 0x0007, 0x0018, 0x001E, 0x0036, 0x0031, 0x0177, 0x0077,
2259 0x0176, 0x0001, 0x0000, 0x001A, 0x0019, 0x003A, 0x0019, 0x005C,
2260 0x00BA, 0x0061, 0x00C1, 0x0180, 0x0302, 0x0607, 0x0606, 0x0002,
2261 0x000A, 0x001F, 0x001C, 0x0037, 0x0016, 0x0076, 0x000D, 0x002F,
2262 ], [
2263 0x0000, 0x000A, 0x001A, 0x000C, 0x001D, 0x0039, 0x0078, 0x005E,
2264 0x0393, 0x0002, 0x0001, 0x0016, 0x000F, 0x002E, 0x005F, 0x0073,
2265 0x00E5, 0x01C8, 0x0E4A, 0x1C97, 0x1C96, 0x0E49, 0x0E48, 0x0004,
2266 0x0006, 0x001F, 0x001B, 0x001D, 0x0038, 0x0038, 0x003D, 0x0079,
2267 ]
2268];
2269
2270const VP31_AC_CAT0_BITS: [[u8; 32]; 16] = [
2271 [
2272 5, 7, 9, 10, 12, 13, 14, 5, 14, 4, 4, 4, 4, 4, 4, 4,
2273 5, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 8, 7, 11, 5, 7,
2274 ], [
2275 5, 6, 8, 8, 10, 12, 12, 4, 12, 4, 4, 4, 4, 4, 4, 4,
2276 5, 4, 4, 4, 4, 5, 6, 5, 6, 7, 7, 8, 9, 12, 5, 6,
2277 ], [
2278 5, 6, 8, 7, 10, 11, 12, 4, 13, 4, 4, 4, 4, 4, 4, 4,
2279 5, 4, 4, 4, 4, 5, 7, 5, 6, 6, 8, 8, 9, 13, 5, 6,
2280 ], [
2281 5, 6, 7, 7, 9, 10, 12, 4, 12, 4, 4, 4, 4, 4, 4, 4,
2282 5, 4, 4, 4, 5, 6, 8, 4, 6, 6, 7, 7, 7, 11, 5, 6,
2283 ], [
2284 4, 6, 7, 7, 9, 10, 13, 4, 13, 4, 4, 4, 4, 4, 4, 4,
2285 5, 4, 4, 5, 6, 7, 11, 4, 6, 6, 7, 7, 8, 12, 4, 6,
2286 ], [
2287 4, 6, 7, 6, 8, 10, 11, 4, 13, 3, 4, 4, 4, 4, 4, 5,
2288 5, 5, 5, 5, 7, 9, 13, 4, 5, 6, 7, 7, 7, 12, 4, 5,
2289 ], [
2290 4, 5, 7, 6, 8, 9, 10, 5, 12, 3, 3, 4, 4, 4, 4, 5,
2291 6, 5, 5, 6, 8, 13, 13, 4, 5, 5, 6, 7, 8, 11, 5, 5,
2292 ], [
2293 3, 5, 6, 5, 7, 9, 10, 5, 13, 3, 3, 4, 4, 4, 5, 6,
2294 6, 6, 7, 8, 13, 13, 13, 4, 5, 5, 6, 6, 7, 11, 5, 5,
2295 ], [
2296 5, 7, 8, 9, 11, 13, 13, 4, 7, 3, 4, 4, 4, 4, 4, 5,
2297 6, 5, 6, 6, 7, 10, 12, 4, 4, 5, 6, 6, 5, 6, 4, 5,
2298 ], [
2299 4, 6, 8, 8, 10, 12, 12, 5, 8, 3, 3, 4, 4, 4, 4, 5,
2300 6, 6, 6, 6, 7, 9, 11, 4, 5, 5, 6, 6, 6, 7, 4, 5,
2301 ], [
2302 4, 5, 6, 7, 9, 11, 12, 5, 7, 3, 4, 4, 4, 4, 5, 5,
2303 6, 6, 6, 7, 8, 10, 12, 4, 4, 5, 5, 6, 5, 6, 4, 5,
2304 ], [
2305 4, 5, 7, 6, 8, 10, 11, 5, 8, 3, 3, 4, 4, 5, 5, 6,
2306 7, 7, 7, 8, 9, 12, 12, 3, 4, 5, 5, 6, 5, 6, 5, 6,
2307 ], [
2308 3, 5, 6, 6, 7, 10, 12, 6, 8, 3, 3, 5, 5, 5, 6, 7,
2309 7, 7, 7, 9, 11, 13, 13, 3, 4, 4, 5, 6, 5, 6, 5, 6,
2310 ], [
2311 3, 4, 6, 5, 7, 9, 11, 6, 9, 3, 3, 5, 5, 5, 6, 7,
2312 8, 8, 9, 10, 12, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6,
2313 ], [
2314 3, 4, 5, 5, 6, 7, 9, 7, 9, 3, 3, 5, 5, 6, 6, 7,
2315 8, 8, 9, 10, 11, 12, 12, 3, 4, 5, 5, 6, 5, 7, 5, 6,
2316 ], [
2317 3, 4, 5, 4, 5, 6, 7, 7, 11, 3, 3, 5, 5, 6, 7, 8,
2318 9, 10, 13, 14, 14, 13, 13, 3, 4, 5, 5, 6, 6, 7, 6, 7,
2319 ]
2320];
2321
2322const VP31_AC_CAT1_CODES: [[u16; 32]; 16] = [
2323 [
2324 0x000B, 0x002B, 0x0054, 0x01B7, 0x06D9, 0x0DB1, 0x0DB0, 0x0002,
2325 0x00AB, 0x0009, 0x000A, 0x0007, 0x0008, 0x000F, 0x000C, 0x0003,
2326 0x001D, 0x0004, 0x000B, 0x0006, 0x001A, 0x0003, 0x00AA, 0x0001,
2327 0x0000, 0x0014, 0x006C, 0x00DA, 0x0002, 0x036D, 0x001C, 0x0037,
2328 ], [
2329 0x001D, 0x0004, 0x00B6, 0x006A, 0x05B9, 0x16E1, 0x16E0, 0x0007,
2330 0x016F, 0x000C, 0x000D, 0x0009, 0x0008, 0x000F, 0x000A, 0x0003,
2331 0x0017, 0x0002, 0x0004, 0x001C, 0x002C, 0x006B, 0x0B71, 0x0005,
2332 0x0003, 0x001B, 0x005A, 0x0034, 0x0005, 0x02DD, 0x0000, 0x000C,
2333 ], [
2334 0x0003, 0x007F, 0x00A1, 0x00A0, 0x020C, 0x0834, 0x106B, 0x0007,
2335 0x0082, 0x000E, 0x000D, 0x000B, 0x000C, 0x0000, 0x0009, 0x0002,
2336 0x0011, 0x001E, 0x0015, 0x003E, 0x0040, 0x041B, 0x106A, 0x0006,
2337 0x000A, 0x0029, 0x007E, 0x0051, 0x0021, 0x0107, 0x0004, 0x000B,
2338 ], [
2339 0x0007, 0x001B, 0x00F6, 0x00E9, 0x03A1, 0x0740, 0x0E82, 0x001F,
2340 0x01EF, 0x0001, 0x0002, 0x000B, 0x000C, 0x000D, 0x0008, 0x001C,
2341 0x0003, 0x0012, 0x0002, 0x0075, 0x01D1, 0x1D07, 0x1D06, 0x000A,
2342 0x0013, 0x003B, 0x001A, 0x007A, 0x003C, 0x01EE, 0x0000, 0x000C,
2343 ], [
2344 0x000D, 0x003D, 0x0042, 0x0037, 0x00D9, 0x0362, 0x06C6, 0x001F,
2345 0x0086, 0x0001, 0x0002, 0x000C, 0x000B, 0x000A, 0x0001, 0x000F,
2346 0x0025, 0x003C, 0x001A, 0x0087, 0x01B0, 0x0D8F, 0x0D8E, 0x000E,
2347 0x0013, 0x000C, 0x0024, 0x0020, 0x0011, 0x006D, 0x0000, 0x000E,
2348 ], [
2349 0x0000, 0x0012, 0x0076, 0x0077, 0x014D, 0x0533, 0x14C9, 0x0013,
2350 0x00A5, 0x0002, 0x0003, 0x000B, 0x000C, 0x0008, 0x001A, 0x002B,
2351 0x0075, 0x0074, 0x00A7, 0x0298, 0x14C8, 0x14CB, 0x14CA, 0x000F,
2352 0x001C, 0x0007, 0x002A, 0x0028, 0x001B, 0x00A4, 0x0002, 0x0006,
2353 ], [
2354 0x0002, 0x001A, 0x002B, 0x003A, 0x00ED, 0x0283, 0x0A0A, 0x0004,
2355 0x00A1, 0x0004, 0x0003, 0x000B, 0x000C, 0x001F, 0x0006, 0x0077,
2356 0x00A3, 0x00A2, 0x0140, 0x1417, 0x1416, 0x0A09, 0x0A08, 0x0000,
2357 0x001E, 0x0007, 0x002A, 0x0029, 0x001C, 0x00EC, 0x001B, 0x0005,
2358 ], [
2359 0x0002, 0x0002, 0x0018, 0x001D, 0x0035, 0x00E4, 0x01CF, 0x001D,
2360 0x0072, 0x0004, 0x0005, 0x0006, 0x0007, 0x0006, 0x0073, 0x0038,
2361 0x01CE, 0x039B, 0x0398, 0x0733, 0x0732, 0x0735, 0x0734, 0x0000,
2362 0x001F, 0x001B, 0x0034, 0x000F, 0x001E, 0x00E5, 0x0019, 0x0038,
2363 ], [
2364 0x0016, 0x0050, 0x0172, 0x02E7, 0x1732, 0x2E67, 0x2E66, 0x0006,
2365 0x0051, 0x0001, 0x0000, 0x000D, 0x000C, 0x0009, 0x001C, 0x0009,
2366 0x001C, 0x001D, 0x005D, 0x00B8, 0x05CD, 0x1731, 0x1730, 0x000F,
2367 0x0005, 0x000F, 0x0008, 0x0029, 0x001D, 0x002F, 0x0008, 0x0015,
2368 ], [
2369 0x0009, 0x0021, 0x0040, 0x00AD, 0x02B0, 0x1589, 0x1588, 0x001C,
2370 0x005F, 0x0000, 0x000F, 0x000D, 0x000C, 0x0006, 0x0011, 0x002A,
2371 0x0057, 0x005E, 0x0041, 0x0159, 0x0563, 0x158B, 0x158A, 0x0001,
2372 0x0005, 0x0014, 0x003B, 0x002E, 0x0004, 0x003A, 0x0007, 0x0016,
2373 ], [
2374 0x000E, 0x0007, 0x0046, 0x0045, 0x0064, 0x032A, 0x0657, 0x0018,
2375 0x000D, 0x0000, 0x000F, 0x000A, 0x000B, 0x001A, 0x0036, 0x0047,
2376 0x0044, 0x0018, 0x0033, 0x00CB, 0x0656, 0x0329, 0x0328, 0x0002,
2377 0x0006, 0x0019, 0x000E, 0x0037, 0x0009, 0x000F, 0x0002, 0x0010,
2378 ], [
2379 0x0003, 0x0018, 0x0023, 0x0077, 0x0194, 0x1956, 0x32AF, 0x003A,
2380 0x0076, 0x0002, 0x0001, 0x001F, 0x001E, 0x0014, 0x0022, 0x0064,
2381 0x0197, 0x0196, 0x032B, 0x0654, 0x32AE, 0x1955, 0x1954, 0x0000,
2382 0x0009, 0x001C, 0x0015, 0x0010, 0x000D, 0x0017, 0x0016, 0x0033,
2383 ], [
2384 0x0005, 0x0006, 0x003E, 0x0010, 0x0048, 0x093F, 0x24FA, 0x0032,
2385 0x0067, 0x0002, 0x0001, 0x001B, 0x001E, 0x0034, 0x0066, 0x0092,
2386 0x0126, 0x024E, 0x049E, 0x49F7, 0x49F6, 0x24F9, 0x24F8, 0x0000,
2387 0x0007, 0x0018, 0x0011, 0x003F, 0x000E, 0x0013, 0x0035, 0x0025,
2388 ], [
2389 0x0005, 0x0008, 0x0012, 0x001C, 0x001C, 0x00EA, 0x1D75, 0x001E,
2390 0x0066, 0x0001, 0x0002, 0x001B, 0x001A, 0x001F, 0x003B, 0x0074,
2391 0x01D6, 0x03AF, 0x1D74, 0x1D77, 0x1D76, 0x0EB9, 0x0EB8, 0x000F,
2392 0x0006, 0x0013, 0x003B, 0x003A, 0x0000, 0x0018, 0x0032, 0x0067,
2393 ], [
2394 0x0004, 0x000A, 0x001B, 0x000C, 0x000D, 0x00E6, 0x0684, 0x0072,
2395 0x00E7, 0x0002, 0x0001, 0x0017, 0x0016, 0x0018, 0x00D1, 0x01A0,
2396 0x0686, 0x0D0F, 0x0D0A, 0x1A17, 0x1A16, 0x1A1D, 0x1A1C, 0x000F,
2397 0x001D, 0x000E, 0x0035, 0x0038, 0x0000, 0x000F, 0x0019, 0x0069,
2398 ], [
2399 0x0003, 0x000C, 0x001B, 0x0000, 0x0003, 0x002E, 0x0051, 0x00BC,
2400 0x0053, 0x0004, 0x0002, 0x0016, 0x0015, 0x0015, 0x0050, 0x00A4,
2401 0x0294, 0x052B, 0x052A, 0x052D, 0x052C, 0x052F, 0x052E, 0x000E,
2402 0x001A, 0x0004, 0x0028, 0x0029, 0x000F, 0x000B, 0x005F, 0x00BD,
2403 ]
2404];
2405
2406const VP31_AC_CAT1_BITS: [[u8; 32]; 16] = [
2407 [
2408 5, 7, 8, 9, 11, 12, 12, 4, 9, 4, 4, 4, 4, 4, 4, 4,
2409 5, 4, 4, 4, 5, 6, 9, 4, 5, 6, 7, 8, 6, 10, 5, 6,
2410 ], [
2411 5, 6, 8, 8, 11, 13, 13, 4, 9, 4, 4, 4, 4, 4, 4, 4,
2412 5, 4, 4, 5, 6, 8, 12, 4, 5, 6, 7, 7, 6, 10, 4, 5,
2413 ], [
2414 4, 7, 8, 8, 10, 12, 13, 4, 8, 4, 4, 4, 4, 3, 4, 4,
2415 5, 5, 5, 6, 7, 11, 13, 4, 5, 6, 7, 7, 6, 9, 4, 5,
2416 ], [
2417 4, 6, 8, 8, 10, 11, 12, 5, 9, 3, 3, 4, 4, 4, 4, 5,
2418 5, 5, 5, 7, 9, 13, 13, 4, 5, 6, 6, 7, 6, 9, 4, 5,
2419 ], [
2420 4, 6, 7, 7, 9, 11, 12, 5, 8, 3, 3, 4, 4, 4, 4, 5,
2421 6, 6, 6, 8, 10, 13, 13, 4, 5, 5, 6, 6, 5, 8, 4, 5,
2422 ], [
2423 3, 5, 7, 7, 9, 11, 13, 5, 8, 3, 3, 4, 4, 4, 5, 6,
2424 7, 7, 8, 10, 13, 13, 13, 4, 5, 5, 6, 6, 5, 8, 4, 5,
2425 ], [
2426 3, 5, 6, 6, 8, 10, 12, 5, 8, 3, 3, 4, 4, 5, 5, 7,
2427 8, 8, 9, 13, 13, 12, 12, 3, 5, 5, 6, 6, 5, 8, 5, 5,
2428 ], [
2429 3, 4, 5, 5, 6, 8, 11, 7, 9, 3, 3, 4, 4, 5, 7, 8,
2430 11, 12, 12, 13, 13, 13, 13, 3, 5, 5, 6, 6, 5, 8, 5, 6,
2431 ], [
2432 5, 7, 9, 10, 13, 14, 14, 4, 7, 3, 3, 4, 4, 4, 5, 5,
2433 6, 6, 7, 8, 11, 13, 13, 4, 4, 5, 5, 6, 5, 6, 4, 5,
2434 ], [
2435 4, 6, 7, 8, 10, 13, 13, 5, 7, 3, 4, 4, 4, 4, 5, 6,
2436 7, 7, 7, 9, 11, 13, 13, 3, 4, 5, 6, 6, 4, 6, 4, 5,
2437 ], [
2438 4, 5, 7, 7, 9, 12, 13, 5, 6, 3, 4, 4, 4, 5, 6, 7,
2439 7, 7, 8, 10, 13, 12, 12, 3, 4, 5, 5, 6, 4, 5, 4, 5,
2440 ], [
2441 3, 5, 6, 7, 9, 13, 14, 6, 7, 3, 3, 5, 5, 5, 6, 7,
2442 9, 9, 10, 11, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6,
2443 ], [
2444 3, 4, 6, 5, 7, 12, 14, 6, 7, 3, 3, 5, 5, 6, 7, 8,
2445 9, 10, 11, 15, 15, 14, 14, 3, 4, 5, 5, 6, 4, 5, 6, 6,
2446 ], [
2447 3, 4, 5, 5, 6, 9, 14, 6, 7, 3, 3, 5, 5, 6, 7, 8,
2448 10, 11, 14, 14, 14, 13, 13, 4, 4, 5, 6, 6, 3, 5, 6, 7,
2449 ], [
2450 3, 4, 5, 4, 5, 8, 11, 7, 8, 3, 3, 5, 5, 6, 8, 9,
2451 11, 12, 12, 13, 13, 13, 13, 4, 5, 5, 6, 6, 3, 5, 6, 7,
2452 ], [
2453 3, 4, 5, 3, 4, 6, 9, 8, 9, 3, 3, 5, 5, 7, 9, 10,
2454 12, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 6, 7, 8,
2455 ]
2456];
2457
2458const VP31_AC_CAT2_CODES: [[u16; 32]; 16] = [
2459 [
2460 0x0003, 0x0009, 0x00D0, 0x01A3, 0x0344, 0x0D14, 0x1A2B, 0x0004,
2461 0x0015, 0x0000, 0x000F, 0x000B, 0x000C, 0x000E, 0x0009, 0x001B,
2462 0x000A, 0x0014, 0x000D, 0x002A, 0x0014, 0x068B, 0x1A2A, 0x0008,
2463 0x000B, 0x002B, 0x000B, 0x0069, 0x0035, 0x0008, 0x0007, 0x000C,
2464 ], [
2465 0x000A, 0x003C, 0x0032, 0x0030, 0x00C5, 0x0621, 0x0620, 0x001F,
2466 0x0033, 0x0001, 0x0000, 0x000E, 0x000D, 0x000C, 0x0004, 0x000D,
2467 0x0026, 0x0027, 0x0014, 0x0063, 0x0189, 0x0623, 0x0622, 0x000B,
2468 0x0012, 0x003D, 0x0022, 0x0015, 0x000B, 0x0023, 0x0007, 0x0010,
2469 ], [
2470 0x000F, 0x000C, 0x0043, 0x0010, 0x0044, 0x0114, 0x0455, 0x0018,
2471 0x0023, 0x0001, 0x0000, 0x000E, 0x000D, 0x0009, 0x0019, 0x0009,
2472 0x0017, 0x0016, 0x0042, 0x008B, 0x0454, 0x0457, 0x0456, 0x000B,
2473 0x0015, 0x000A, 0x0029, 0x0020, 0x000D, 0x0028, 0x0007, 0x0011,
2474 ], [
2475 0x0001, 0x001A, 0x0029, 0x002A, 0x00A0, 0x0285, 0x1425, 0x0002,
2476 0x0000, 0x0002, 0x0003, 0x000C, 0x000B, 0x0008, 0x0012, 0x0001,
2477 0x0051, 0x0001, 0x0143, 0x0508, 0x1424, 0x1427, 0x1426, 0x000F,
2478 0x001C, 0x0003, 0x0037, 0x002B, 0x0013, 0x0036, 0x001D, 0x0001,
2479 ], [
2480 0x0004, 0x001F, 0x003D, 0x0006, 0x0016, 0x0053, 0x014A, 0x0034,
2481 0x002A, 0x0002, 0x0003, 0x000B, 0x000C, 0x001C, 0x0037, 0x0017,
2482 0x002B, 0x0028, 0x00A4, 0x052D, 0x052C, 0x052F, 0x052E, 0x0000,
2483 0x001D, 0x0007, 0x0004, 0x0035, 0x0014, 0x0036, 0x0015, 0x003C,
2484 ], [
2485 0x0004, 0x000A, 0x0007, 0x001D, 0x0009, 0x01F3, 0x07C7, 0x0008,
2486 0x01F0, 0x0003, 0x0002, 0x000D, 0x000C, 0x0017, 0x007D, 0x01F2,
2487 0x07C6, 0x07C5, 0x1F12, 0x3E27, 0x3E26, 0x1F11, 0x1F10, 0x0000,
2488 0x001E, 0x0006, 0x0039, 0x0038, 0x003F, 0x002C, 0x0005, 0x002D,
2489 ], [
2490 0x0002, 0x0007, 0x0018, 0x0003, 0x0005, 0x0035, 0x004F, 0x0012,
2491 0x04E5, 0x0005, 0x0004, 0x000D, 0x000E, 0x0033, 0x0026, 0x009D,
2492 0x04E4, 0x04E7, 0x04E6, 0x04E1, 0x04E0, 0x04E3, 0x04E2, 0x0000,
2493 0x001F, 0x000C, 0x003D, 0x003C, 0x0032, 0x0034, 0x001B, 0x0008,
2494 ], [
2495 0x0000, 0x0004, 0x001C, 0x000F, 0x0002, 0x0007, 0x0075, 0x00E8,
2496 0x1D2A, 0x0005, 0x0004, 0x000D, 0x000C, 0x0077, 0x0E96, 0x3A57,
2497 0x3A56, 0x3A5D, 0x3A5C, 0x3A5F, 0x3A5E, 0x1D29, 0x1D28, 0x0003,
2498 0x0006, 0x000A, 0x002C, 0x0017, 0x0076, 0x01D3, 0x03A4, 0x002D,
2499 ], [
2500 0x000A, 0x0024, 0x00BF, 0x0085, 0x0211, 0x0842, 0x1087, 0x0018,
2501 0x0020, 0x0001, 0x0002, 0x000E, 0x000D, 0x0007, 0x0013, 0x0025,
2502 0x005E, 0x0043, 0x00BE, 0x0109, 0x1086, 0x0841, 0x0840, 0x000F,
2503 0x0001, 0x0011, 0x0000, 0x002E, 0x0019, 0x0001, 0x0006, 0x0016,
2504 ], [
2505 0x0002, 0x000F, 0x006F, 0x0061, 0x0374, 0x1BA8, 0x3753, 0x0012,
2506 0x0036, 0x0000, 0x0001, 0x000A, 0x000B, 0x001A, 0x0031, 0x0060,
2507 0x00DC, 0x01BB, 0x06EB, 0x1BAB, 0x3752, 0x3755, 0x3754, 0x000E,
2508 0x0006, 0x0013, 0x000E, 0x003E, 0x0008, 0x001E, 0x0019, 0x003F,
2509 ], [
2510 0x0003, 0x001C, 0x0025, 0x0024, 0x01DA, 0x1DBD, 0x3B7C, 0x003C,
2511 0x003D, 0x0000, 0x0001, 0x000B, 0x000A, 0x000B, 0x0077, 0x00EC,
2512 0x03B6, 0x076E, 0x1DBF, 0x76FB, 0x76FA, 0x3B79, 0x3B78, 0x000D,
2513 0x001F, 0x0013, 0x000A, 0x0008, 0x000C, 0x0008, 0x0009, 0x003A,
2514 ], [
2515 0x0005, 0x0003, 0x0004, 0x0010, 0x008F, 0x0475, 0x11D1, 0x0079,
2516 0x0027, 0x0002, 0x0003, 0x0001, 0x0000, 0x0026, 0x0046, 0x011C,
2517 0x0477, 0x08ED, 0x11D0, 0x11D3, 0x11D2, 0x11D9, 0x11D8, 0x000D,
2518 0x001F, 0x0012, 0x0005, 0x003D, 0x000C, 0x000E, 0x0022, 0x0078,
2519 ], [
2520 0x0005, 0x000C, 0x001B, 0x0000, 0x0006, 0x03E2, 0x3E3D, 0x000F,
2521 0x0034, 0x0003, 0x0002, 0x001E, 0x001D, 0x007D, 0x01F0, 0x07C6,
2522 0x3E3C, 0x3E3F, 0x3E3E, 0x3E39, 0x3E38, 0x3E3B, 0x3E3A, 0x0008,
2523 0x001C, 0x0002, 0x003F, 0x0035, 0x0009, 0x0001, 0x000E, 0x00F9,
2524 ], [
2525 0x0004, 0x000B, 0x0001, 0x000A, 0x001E, 0x00E0, 0x0E1E, 0x0071,
2526 0x0039, 0x0007, 0x0006, 0x000D, 0x000C, 0x0020, 0x01C2, 0x1C3F,
2527 0x1C3E, 0x0E19, 0x0E18, 0x0E1B, 0x0E1A, 0x0E1D, 0x0E1C, 0x0000,
2528 0x0009, 0x001D, 0x001F, 0x0011, 0x0005, 0x0001, 0x0043, 0x0042,
2529 ], [
2530 0x0004, 0x000D, 0x0007, 0x0002, 0x0014, 0x016C, 0x16D1, 0x02DF,
2531 0x016E, 0x0000, 0x0007, 0x002C, 0x002B, 0x02DE, 0x16D0, 0x16D3,
2532 0x16D2, 0x2DB5, 0x2DB4, 0x2DB7, 0x2DB6, 0x16D9, 0x16D8, 0x000C,
2533 0x002A, 0x005A, 0x001B, 0x001A, 0x0017, 0x000C, 0x05B7, 0x05B5,
2534 ], [
2535 0x0002, 0x000F, 0x001C, 0x000C, 0x003B, 0x01AC, 0x1AD8, 0x35B3,
2536 0x35B2, 0x0001, 0x0000, 0x0069, 0x0068, 0x35BD, 0x35BC, 0x35BF,
2537 0x35BE, 0x35B9, 0x35B8, 0x35BB, 0x35BA, 0x35B5, 0x35B4, 0x01A9,
2538 0x01A8, 0x035A, 0x00D7, 0x00D5, 0x003A, 0x001B, 0x35B7, 0x35B6,
2539 ]
2540];
2541
2542const VP31_AC_CAT2_BITS: [[u8; 32]; 16] = [
2543 [
2544 4, 6, 8, 9, 10, 12, 13, 4, 7, 3, 4, 4, 4, 4, 4, 5,
2545 5, 5, 5, 6, 7, 11, 13, 4, 5, 6, 6, 7, 6, 6, 4, 5,
2546 ], [
2547 4, 6, 7, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 4, 4, 5,
2548 6, 6, 6, 8, 10, 12, 12, 4, 5, 6, 6, 6, 5, 6, 4, 5,
2549 ], [
2550 4, 5, 7, 6, 8, 10, 12, 5, 7, 3, 3, 4, 4, 4, 5, 5,
2551 6, 6, 7, 9, 12, 12, 12, 4, 5, 5, 6, 6, 5, 6, 4, 5,
2552 ], [
2553 3, 5, 6, 6, 8, 10, 13, 5, 7, 3, 3, 4, 4, 4, 5, 6,
2554 7, 7, 9, 11, 13, 13, 13, 4, 5, 5, 6, 6, 5, 6, 5, 5,
2555 ], [
2556 3, 5, 6, 5, 7, 9, 11, 6, 8, 3, 3, 4, 4, 5, 6, 7,
2557 8, 8, 10, 13, 13, 13, 13, 3, 5, 5, 5, 6, 5, 6, 5, 6,
2558 ], [
2559 3, 4, 5, 5, 6, 9, 11, 6, 9, 3, 3, 4, 4, 5, 7, 9,
2560 11, 11, 13, 14, 14, 13, 13, 3, 5, 5, 6, 6, 6, 6, 5, 6,
2561 ], [
2562 3, 4, 5, 4, 5, 7, 9, 7, 13, 3, 3, 4, 4, 6, 8, 10,
2563 13, 13, 13, 13, 13, 13, 13, 3, 5, 5, 6, 6, 6, 7, 6, 6,
2564 ], [
2565 3, 4, 5, 4, 4, 5, 7, 8, 13, 3, 3, 4, 4, 7, 12, 14,
2566 14, 14, 14, 14, 14, 13, 13, 3, 5, 5, 7, 6, 7, 9, 10, 7,
2567 ], [
2568 4, 6, 8, 8, 10, 12, 13, 5, 6, 3, 3, 4, 4, 4, 5, 6,
2569 7, 7, 8, 9, 13, 12, 12, 4, 4, 5, 5, 6, 5, 5, 4, 5,
2570 ], [
2571 3, 5, 7, 7, 10, 13, 14, 5, 6, 3, 3, 4, 4, 5, 6, 7,
2572 8, 9, 11, 13, 14, 14, 14, 4, 4, 5, 5, 6, 4, 5, 5, 6,
2573 ], [
2574 3, 5, 6, 6, 9, 13, 14, 6, 6, 3, 3, 4, 4, 5, 7, 8,
2575 10, 11, 13, 15, 15, 14, 14, 4, 5, 5, 5, 5, 4, 4, 5, 6,
2576 ], [
2577 3, 4, 5, 5, 8, 11, 13, 7, 6, 3, 3, 4, 4, 6, 7, 9,
2578 11, 12, 13, 13, 13, 13, 13, 4, 5, 5, 5, 6, 4, 4, 6, 7,
2579 ], [
2580 3, 4, 5, 4, 6, 10, 14, 7, 6, 3, 3, 5, 5, 7, 9, 11,
2581 14, 14, 14, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 3, 7, 8,
2582 ], [
2583 3, 4, 4, 4, 6, 9, 13, 8, 7, 3, 3, 5, 5, 7, 10, 14,
2584 14, 13, 13, 13, 13, 13, 13, 4, 5, 6, 6, 6, 4, 3, 8, 8,
2585 ], [
2586 3, 4, 4, 3, 5, 9, 13, 10, 9, 2, 3, 6, 6, 10, 13, 13,
2587 13, 14, 14, 14, 14, 13, 13, 5, 6, 7, 6, 6, 5, 4, 11, 11,
2588 ], [
2589 2, 4, 5, 4, 6, 9, 13, 14, 14, 2, 2, 7, 7, 14, 14, 14,
2590 14, 14, 14, 14, 14, 14, 14, 9, 9, 10, 8, 8, 6, 5, 14, 14,
2591 ]
2592];
2593
2594const VP31_AC_CAT3_CODES: [[u16; 32]; 16] = [
2595 [
2596 0x0000, 0x0010, 0x0072, 0x0071, 0x0154, 0x0AAB, 0x0AA8, 0x0014,
2597 0x0070, 0x0002, 0x0003, 0x000C, 0x000B, 0x0003, 0x0011, 0x0073,
2598 0x0054, 0x00AB, 0x02AB, 0x1553, 0x1552, 0x1555, 0x1554, 0x000D,
2599 0x001E, 0x0012, 0x003E, 0x002B, 0x0002, 0x003F, 0x001D, 0x0013,
2600 ], [
2601 0x0003, 0x001F, 0x0029, 0x003D, 0x000C, 0x0069, 0x0345, 0x0002,
2602 0x0028, 0x0002, 0x0001, 0x000E, 0x000C, 0x0015, 0x0007, 0x001B,
2603 0x006B, 0x006A, 0x0344, 0x0347, 0x0346, 0x01A1, 0x01A0, 0x000B,
2604 0x001A, 0x0012, 0x0000, 0x003C, 0x0008, 0x001B, 0x0013, 0x0001,
2605 ], [
2606 0x0004, 0x0004, 0x003F, 0x0014, 0x0056, 0x015C, 0x15D5, 0x003C,
2607 0x002A, 0x0000, 0x0001, 0x000E, 0x000D, 0x000C, 0x00AF, 0x02BB,
2608 0x15D4, 0x15D7, 0x15D6, 0x15D1, 0x15D0, 0x15D3, 0x15D2, 0x000B,
2609 0x0019, 0x000D, 0x003E, 0x0031, 0x0007, 0x0005, 0x003D, 0x0030,
2610 ], [
2611 0x0005, 0x0008, 0x001A, 0x0000, 0x0036, 0x0011, 0x0106, 0x000A,
2612 0x006E, 0x0002, 0x0003, 0x0003, 0x0002, 0x006F, 0x0021, 0x020F,
2613 0x020E, 0x0101, 0x0100, 0x0103, 0x0102, 0x0105, 0x0104, 0x000C,
2614 0x001E, 0x0003, 0x003E, 0x003F, 0x0009, 0x000E, 0x000B, 0x0009,
2615 ], [
2616 0x0002, 0x000E, 0x001E, 0x000C, 0x001F, 0x006E, 0x00AD, 0x00AF,
2617 0x0014, 0x0004, 0x0003, 0x001A, 0x0017, 0x002A, 0x0576, 0x0AEF,
2618 0x0AEE, 0x0571, 0x0570, 0x0573, 0x0572, 0x0575, 0x0574, 0x0003,
2619 0x0016, 0x0004, 0x0036, 0x000B, 0x000A, 0x0000, 0x006F, 0x00AC,
2620 ], [
2621 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
2622 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
2623 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
2624 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
2625 ], [
2626 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
2627 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
2628 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
2629 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
2630 ], [
2631 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
2632 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
2633 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
2634 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
2635 ], [
2636 0x0003, 0x0011, 0x0020, 0x0074, 0x010D, 0x0863, 0x0860, 0x000A,
2637 0x0075, 0x0001, 0x0000, 0x000B, 0x000A, 0x0018, 0x0038, 0x0042,
2638 0x010F, 0x010E, 0x0219, 0x10C3, 0x10C2, 0x10C5, 0x10C4, 0x000F,
2639 0x0004, 0x0019, 0x000B, 0x0039, 0x0009, 0x001B, 0x001A, 0x003B,
2640 ], [
2641 0x0005, 0x0001, 0x003E, 0x0001, 0x00E2, 0x1C6F, 0x38D9, 0x0039,
2642 0x001F, 0x0002, 0x0001, 0x0009, 0x0008, 0x0000, 0x0070, 0x01C7,
2643 0x038C, 0x071A, 0x38D8, 0x38DB, 0x38DA, 0x38DD, 0x38DC, 0x000D,
2644 0x001D, 0x000E, 0x003F, 0x003C, 0x000C, 0x0006, 0x003D, 0x001E,
2645 ], [
2646 0x0006, 0x000B, 0x0011, 0x001E, 0x0074, 0x03AA, 0x1D5C, 0x0001,
2647 0x0021, 0x0001, 0x0002, 0x0007, 0x0006, 0x003E, 0x00EB, 0x01D4,
2648 0x0EAF, 0x3ABB, 0x3ABA, 0x1D59, 0x1D58, 0x1D5B, 0x1D5A, 0x000A,
2649 0x001C, 0x0001, 0x003F, 0x003B, 0x0001, 0x0009, 0x0020, 0x0000,
2650 ], [
2651 0x0004, 0x000A, 0x0017, 0x0004, 0x0016, 0x016A, 0x16B1, 0x0017,
2652 0x005B, 0x0006, 0x0007, 0x0001, 0x0000, 0x000A, 0x02D7, 0x0B5A,
2653 0x16B0, 0x16B3, 0x16B2, 0x2D6D, 0x2D6C, 0x2D6F, 0x2D6E, 0x0006,
2654 0x000A, 0x0004, 0x002C, 0x0017, 0x0003, 0x0007, 0x0016, 0x00B4,
2655 ], [
2656 0x0005, 0x000D, 0x0005, 0x0009, 0x0033, 0x0193, 0x192C, 0x0061,
2657 0x0031, 0x0000, 0x0007, 0x0010, 0x0011, 0x00C8, 0x192F, 0x325B,
2658 0x325A, 0x1929, 0x1928, 0x192B, 0x192A, 0x325D, 0x325C, 0x0018,
2659 0x001A, 0x001B, 0x0065, 0x0019, 0x0004, 0x0007, 0x0060, 0x0324,
2660 ], [
2661 0x0006, 0x0000, 0x0002, 0x000F, 0x0039, 0x01D9, 0x1D82, 0x0761,
2662 0x03BE, 0x0001, 0x0002, 0x000F, 0x000E, 0x0762, 0x3B07, 0x3B06,
2663 0x3B1D, 0x3B1C, 0x3B1F, 0x3B1E, 0x3B19, 0x3B18, 0x3B1B, 0x0038,
2664 0x01DE, 0x00ED, 0x03BF, 0x00EE, 0x003A, 0x0006, 0x0EC0, 0x3B1A,
2665 ], [
2666 0x0000, 0x0002, 0x000F, 0x0006, 0x001C, 0x01D0, 0x0E8C, 0x1D1B,
2667 0x1D1A, 0x0003, 0x0002, 0x00EA, 0x00E9, 0x0E89, 0x0E88, 0x0E8B,
2668 0x0E8A, 0x1D65, 0x1D64, 0x1D67, 0x1D66, 0x1D61, 0x1D60, 0x03AD,
2669 0x1D63, 0x1D62, 0x1D1D, 0x1D1C, 0x003B, 0x01D7, 0x1D1F, 0x1D1E,
2670 ], [
2671 0x0002, 0x000F, 0x001C, 0x000C, 0x003B, 0x01AC, 0x1AD8, 0x35B3,
2672 0x35B2, 0x0001, 0x0000, 0x0069, 0x0068, 0x35BD, 0x35BC, 0x35BF,
2673 0x35BE, 0x35B9, 0x35B8, 0x35BB, 0x35BA, 0x35B5, 0x35B4, 0x01A9,
2674 0x01A8, 0x035A, 0x00D7, 0x00D5, 0x003A, 0x001B, 0x35B7, 0x35B6,
2675 ]
2676];
2677
2678const VP31_AC_CAT3_BITS: [[u8; 32]; 16] = [
2679 [
2680 3, 5, 7, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 4, 5, 7,
2681 7, 8, 10, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 6, 5, 5,
2682 ], [
2683 3, 5, 6, 6, 7, 10, 13, 5, 6, 3, 3, 4, 4, 5, 6, 8,
2684 10, 10, 13, 13, 13, 12, 12, 4, 5, 5, 5, 6, 4, 5, 5, 5,
2685 ], [
2686 3, 4, 6, 5, 7, 9, 13, 6, 6, 3, 3, 4, 4, 5, 8, 10,
2687 13, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 4, 6, 6,
2688 ], [
2689 3, 4, 5, 4, 6, 8, 12, 7, 7, 3, 3, 4, 4, 7, 9, 13,
2690 13, 12, 12, 12, 12, 12, 12, 4, 5, 5, 6, 6, 4, 4, 7, 7,
2691 ], [
2692 3, 4, 5, 4, 5, 7, 10, 10, 7, 3, 3, 5, 5, 8, 13, 14,
2693 14, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 3, 7, 10,
2694 ], [
2695 3, 4, 3, 3, 4, 6, 11, 13, 8, 3, 3, 6, 6, 13, 13, 13,
2696 13, 13, 13, 13, 14, 14, 14, 3, 6, 8, 9, 8, 6, 5, 12, 14,
2697 ], [
2698 3, 4, 3, 3, 4, 6, 11, 13, 8, 3, 3, 6, 6, 13, 13, 13,
2699 13, 13, 13, 13, 14, 14, 14, 3, 6, 8, 9, 8, 6, 5, 12, 14,
2700 ], [
2701 3, 4, 3, 3, 4, 6, 11, 13, 8, 3, 3, 6, 6, 13, 13, 13,
2702 13, 13, 13, 13, 14, 14, 14, 3, 6, 8, 9, 8, 6, 5, 12, 14,
2703 ], [
2704 3, 5, 6, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 5, 6, 7,
2705 9, 9, 10, 13, 13, 13, 13, 4, 4, 5, 5, 6, 4, 5, 5, 6,
2706 ], [
2707 3, 4, 6, 5, 8, 13, 14, 6, 6, 3, 3, 4, 4, 5, 7, 9,
2708 10, 11, 14, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 4, 6, 6,
2709 ], [
2710 3, 4, 5, 5, 7, 10, 13, 6, 6, 3, 3, 4, 4, 6, 8, 9,
2711 12, 14, 14, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 4, 6, 6,
2712 ], [
2713 3, 4, 5, 4, 6, 9, 13, 7, 7, 3, 3, 4, 4, 6, 10, 12,
2714 13, 13, 13, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 4, 7, 8,
2715 ], [
2716 3, 4, 4, 4, 6, 9, 13, 8, 7, 2, 3, 5, 5, 8, 13, 14,
2717 14, 13, 13, 13, 13, 14, 14, 5, 6, 6, 7, 6, 4, 4, 8, 10,
2718 ], [
2719 3, 3, 4, 4, 6, 9, 13, 11, 10, 2, 2, 6, 6, 11, 14, 14,
2720 14, 14, 14, 14, 14, 14, 14, 6, 9, 8, 10, 8, 6, 5, 12, 14,
2721 ], [
2722 2, 3, 5, 4, 6, 10, 13, 14, 14, 2, 2, 9, 9, 13, 13, 13,
2723 13, 14, 14, 14, 14, 14, 14, 11, 14, 14, 14, 14, 7, 10, 14, 14,
2724 ], [
2725 2, 4, 5, 4, 6, 9, 13, 14, 14, 2, 2, 7, 7, 14, 14, 14,
2726 14, 14, 14, 14, 14, 14, 14, 9, 9, 10, 8, 8, 6, 5, 14, 14,
2727 ]
2728];
2729
2730const VP31_DC_WEIGHTS: [[i16; 5]; 16] = [
2731 [ 0, 0, 0, 0, 0 ],
2732 [ 1, 0, 0, 0, 1 ],
2733 [ 0, 1, 0, 0, 1 ],
2734 [ 1, 0, 0, 0, 1 ],
2735
2736 [ 0, 0, 1, 0, 1 ],
2737 [ 1, 0, 1, 0, 2 ],
2738 [ 0, 0, 1, 0, 1 ],
2739 [ 29, -26, 29, 0, 32 ],
2740
2741 [ 0, 0, 0, 1, 1 ],
2742 [ 75, 0, 0, 53, 128 ],
2743 [ 0, 1, 0, 1, 2 ],
2744 [ 75, 0, 0, 53, 128 ],
2745
2746 [ 0, 0, 1, 0, 1 ],
2747 [ 75, 0, 0, 53, 128 ],
2748 [ 0, 3, 10, 3, 16 ],
2749 [ 29, -26, 29, 0, 32 ],
2750];
2751
2752const VP30_DC_SCALES: [i16; 64] = [
2753 24, 20, 20, 20, 20, 20, 20, 20,
2754 19, 19, 19, 19, 18, 18, 18, 18,
2755 17, 17, 17, 17, 16, 16, 15, 15,
2756 14, 14, 13, 13, 12, 12, 11, 11,
2757 10, 10, 9, 9, 8, 8, 7, 7,
2758 6, 6, 6, 6, 5, 5, 5, 5,
2759 4, 4, 4, 4, 3, 3, 3, 3,
2760 2, 2, 2, 2, 1, 1, 1, 1
2761];
2762
2763const VP30_AC_SCALES: [i16; 64] = [
2764 3000, 2500, 2000, 1500, 1200, 1000, 900, 800,
2765 750, 700, 650, 630, 600, 550, 500, 450,
2766 410, 380, 350, 320, 290, 260, 240, 220,
2767 200, 180, 165, 150, 140, 130, 120, 115,
2768 110, 100, 95, 90, 85, 80, 75, 70,
2769 67, 65, 63, 61, 57, 55, 53, 50,
2770 49, 46, 44, 42, 39, 36, 33, 30,
2771 27, 24, 21, 19, 17, 15, 12, 10
2772];
2773
2774const VP30_DC_CODES: [[u16; 32]; 5] = [
2775 [
2776 0x0005, 0x002D, 0x0004, 0x0009, 0x0088, 0x0225, 0x0224, 0x0005,
2777 0x0011, 0x0007, 0x0006, 0x0009, 0x000A, 0x0007, 0x0017, 0x000C,
2778 0x002C, 0x0005, 0x0008, 0x0003, 0x0012, 0x0010, 0x0113, 0x0003,
2779 0x0010, 0x0000, 0x0013, 0x001A, 0x0023, 0x0045, 0x0001, 0x001B
2780 ], [
2781 0x000B, 0x0012, 0x0029, 0x0010, 0x000D, 0x00A2, 0x0020, 0x0009,
2782 0x0050, 0x0007, 0x0006, 0x0006, 0x0005, 0x0002, 0x0008, 0x0027,
2783 0x0005, 0x0022, 0x0023, 0x0057, 0x00A3, 0x0011, 0x0021, 0x0007,
2784 0x0000, 0x0009, 0x002A, 0x0003, 0x0007, 0x0026, 0x000C, 0x0056
2785 ], [
2786 0x000D, 0x0018, 0x0009, 0x0017, 0x0033, 0x0056, 0x00F7, 0x00F1,
2787 0x007A, 0x0000, 0x0007, 0x0009, 0x0008, 0x0005, 0x000D, 0x002D,
2788 0x0010, 0x001D, 0x001C, 0x0057, 0x00CB, 0x00F6, 0x00F0, 0x0014,
2789 0x000C, 0x002C, 0x0011, 0x001F, 0x002A, 0x0064, 0x00CA, 0x0079
2790 ], [
2791 0x000F, 0x001A, 0x0013, 0x001B, 0x003B, 0x0072, 0x01D3, 0x0707,
2792 0x0E0D, 0x0001, 0x0000, 0x000C, 0x000B, 0x0008, 0x0012, 0x002A,
2793 0x0073, 0x0028, 0x0075, 0x0056, 0x0052, 0x01C0, 0x0E0C, 0x0071,
2794 0x0057, 0x00E1, 0x00A6, 0x00E8, 0x00A7, 0x03A5, 0x03A4, 0x0382
2795 ], [
2796 0x000F, 0x001B, 0x0014, 0x001D, 0x0010, 0x0073, 0x00E2, 0x023C,
2797 0x11C9, 0x0001, 0x0000, 0x000C, 0x000B, 0x0009, 0x0015, 0x0035,
2798 0x0072, 0x0034, 0x0022, 0x0070, 0x0046, 0x011D, 0x11C8, 0x01C7,
2799 0x01C6, 0x0238, 0x047E, 0x023E, 0x0473, 0x08E5, 0x023D, 0x047F
2800 ]
2801];
2802const VP30_DC_BITS: [[u8; 32]; 5] = [
2803 [
2804 4, 6, 6, 6, 8, 10, 10, 6, 7, 3, 3, 4, 4, 4, 5, 5,
2805 6, 5, 5, 5, 6, 7, 9, 4, 5, 5, 6, 6, 6, 7, 5, 6
2806 ], [
2807 4, 5, 6, 5, 6, 8, 9, 7, 7, 3, 3, 4, 4, 4, 5, 6,
2808 6, 6, 6, 7, 8, 8, 9, 4, 4, 5, 6, 5, 5, 6, 6, 7
2809 ], [
2810 4, 5, 5, 5, 6, 7, 9, 9, 8, 2, 3, 4, 4, 4, 5, 6,
2811 6, 6, 6, 7, 8, 9, 9, 5, 5, 6, 6, 6, 6, 7, 8, 8
2812 ], [
2813 4, 5, 5, 5, 6, 7, 9, 11, 12, 2, 2, 4, 4, 4, 5, 6,
2814 7, 6, 7, 7, 7, 9, 12, 7, 7, 8, 8, 8, 8, 10, 10, 10
2815 ], [
2816 4, 5, 5, 5, 5, 7, 8, 10, 13, 2, 2, 4, 4, 4, 5, 6,
2817 7, 6, 6, 7, 7, 9, 13, 9, 9, 10, 11, 10, 11, 12, 10, 11
2818 ]
2819];
2820const VP30_AC_INTRA_CODES: [[u16; 32]; 5] = [
2821 [
2822 0x0008, 0x0033, 0x0008, 0x004B, 0x0089, 0x0221, 0x0220, 0x001F,
2823 0x0045, 0x0000, 0x000E, 0x000B, 0x000A, 0x000D, 0x0006, 0x001E,
2824 0x000A, 0x0018, 0x0013, 0x0005, 0x0009, 0x0046, 0x0111, 0x0007,
2825 0x000B, 0x0032, 0x0010, 0x004A, 0x0024, 0x0047, 0x0003, 0x0009
2826 ], [
2827 0x000E, 0x000E, 0x007B, 0x001E, 0x007E, 0x03EF, 0x07DD, 0x0018,
2828 0x00FA, 0x0002, 0x0000, 0x000A, 0x0008, 0x000B, 0x0003, 0x0012,
2829 0x0033, 0x000C, 0x003C, 0x001A, 0x007F, 0x01F6, 0x07DC, 0x000D,
2830 0x0013, 0x0004, 0x001B, 0x007A, 0x0032, 0x007C, 0x001F, 0x0005
2831 ], [
2832 0x0000, 0x0018, 0x0034, 0x000C, 0x006A, 0x01F9, 0x07EA, 0x0016,
2833 0x0FD7, 0x0002, 0x0001, 0x000A, 0x0009, 0x0007, 0x001B, 0x003E,
2834 0x0020, 0x0021, 0x006B, 0x01FB, 0x03F4, 0x1FAD, 0x1FAC, 0x000E,
2835 0x0019, 0x0011, 0x002F, 0x007F, 0x002E, 0x01F8, 0x001E, 0x000D
2836 ], [
2837 0x000E, 0x0016, 0x002E, 0x0003, 0x006E, 0x008B, 0x0113, 0x0018,
2838 0x0221, 0x0001, 0x0002, 0x000A, 0x0009, 0x0007, 0x001A, 0x0002,
2839 0x001B, 0x0023, 0x006F, 0x008A, 0x0111, 0x0441, 0x0440, 0x000F,
2840 0x0019, 0x0010, 0x0036, 0x001A, 0x002F, 0x0112, 0x0000, 0x000C
2841 ], [
2842 0x000E, 0x000F, 0x001B, 0x0033, 0x005A, 0x00B6, 0x0008, 0x001A,
2843 0x004D, 0x0001, 0x0002, 0x000A, 0x0009, 0x0008, 0x001B, 0x0003,
2844 0x002C, 0x002E, 0x0005, 0x00B7, 0x0027, 0x0099, 0x0098, 0x000F,
2845 0x0018, 0x000E, 0x002F, 0x001A, 0x0032, 0x0012, 0x0000, 0x000C
2846 ]
2847];
2848const VP30_AC_INTRA_BITS: [[u8; 32]; 5] = [
2849 [
2850 4, 6, 6, 7, 9, 11, 11, 5, 8, 3, 4, 4, 4, 4, 4, 5,
2851 5, 5, 5, 5, 6, 8, 10, 4, 5, 6, 6, 7, 6, 8, 4, 5
2852 ], [
2853 4, 5, 7, 6, 8, 11, 12, 5, 9, 3, 3, 4, 4, 4, 4, 5,
2854 6, 5, 6, 6, 8, 10, 12, 4, 5, 5, 6, 7, 6, 8, 5, 5
2855 ], [
2856 3, 5, 6, 5, 7, 9, 11, 5, 12, 3, 3, 4, 4, 4, 5, 6,
2857 6, 6, 7, 9, 10, 13, 13, 4, 5, 5, 6, 7, 6, 9, 5, 5
2858 ], [
2859 4, 5, 6, 5, 7, 8, 9, 5, 10, 3, 3, 4, 4, 4, 5, 5,
2860 6, 6, 7, 8, 9, 11, 11, 4, 5, 5, 6, 6, 6, 9, 4, 5
2861 ], [
2862 4, 5, 6, 6, 7, 8, 7, 5, 10, 3, 3, 4, 4, 4, 5, 5,
2863 6, 6, 6, 8, 9, 11, 11, 4, 5, 5, 6, 6, 6, 8, 4, 5
2864 ]
2865];
2866const VP30_AC_INTER_CODES: [[u16; 32]; 5] = [
2867 [
2868 0x000D, 0x0038, 0x0061, 0x0060, 0x0393, 0x1C95, 0x1C94, 0x0014,
2869 0x0073, 0x0001, 0x0000, 0x000B, 0x0009, 0x001D, 0x000E, 0x0022,
2870 0x0046, 0x0047, 0x00E5, 0x01C8, 0x0724, 0x1C97, 0x1C96, 0x000F,
2871 0x0006, 0x0019, 0x000F, 0x0031, 0x0004, 0x0010, 0x0005, 0x0015
2872 ], [
2873 0x0004, 0x001B, 0x0030, 0x0034, 0x00D5, 0x06B3, 0x3595, 0x0031,
2874 0x001A, 0x0002, 0x0001, 0x001F, 0x001E, 0x000C, 0x001B, 0x00D7,
2875 0x00D4, 0x01AD, 0x0358, 0x0D64, 0x3594, 0x3597, 0x3596, 0x0000,
2876 0x000A, 0x001D, 0x0017, 0x0039, 0x0007, 0x0019, 0x0016, 0x0038
2877 ], [
2878 0x0005, 0x0009, 0x001A, 0x001E, 0x001F, 0x00E2, 0x038E, 0x0070,
2879 0x003B, 0x0001, 0x0000, 0x0019, 0x0018, 0x001E, 0x003A, 0x01C6,
2880 0x071E, 0x0E3E, 0x1C7E, 0x71FD, 0x71FC, 0x71FF, 0x71FE, 0x0002,
2881 0x0008, 0x001D, 0x001B, 0x0039, 0x001F, 0x000D, 0x000C, 0x001C
2882 ], [
2883 0x0003, 0x000B, 0x001C, 0x000D, 0x0004, 0x000A, 0x0076, 0x00E8,
2884 0x01DC, 0x0001, 0x0000, 0x0033, 0x0032, 0x00E9, 0x03BB, 0x0774,
2885 0x1DD5, 0x3BAD, 0x3BAC, 0x3BAF, 0x3BAE, 0x3BA9, 0x3BA8, 0x0004,
2886 0x000A, 0x001F, 0x001E, 0x0030, 0x000B, 0x0075, 0x0031, 0x00EF
2887 ], [
2888 0x0009, 0x001E, 0x000F, 0x000E, 0x000C, 0x0008, 0x0001, 0x00E3,
2889 0x00E2, 0x0002, 0x0000, 0x003A, 0x0039, 0x0070, 0x01DC, 0x0776,
2890 0x0775, 0x0EEF, 0x0EE8, 0x1DD3, 0x1DD2, 0x1DDD, 0x1DDC, 0x0005,
2891 0x001F, 0x001B, 0x0006, 0x006A, 0x0034, 0x0076, 0x006B, 0x00EF
2892 ]
2893];
2894const VP30_AC_INTER_BITS: [[u8; 32]; 5] = [
2895 [
2896 4, 6, 7, 7, 10, 13, 13, 5, 7, 3, 3, 4, 4, 5, 5, 6,
2897 7, 7, 8, 9, 11, 13, 13, 4, 4, 5, 5, 6, 4, 5, 4, 5
2898 ], [
2899 3, 5, 6, 6, 8, 11, 14, 6, 6, 3, 3, 5, 5, 5, 6, 8,
2900 8, 9, 10, 12, 14, 14, 14, 3, 4, 5, 5, 6, 4, 5, 5, 6
2901 ], [
2902 3, 4, 5, 5, 6, 8, 10, 7, 7, 3, 3, 5, 5, 6, 7, 9,
2903 11, 12, 13, 15, 15, 15, 15, 3, 4, 5, 5, 6, 5, 5, 5, 6
2904 ], [
2905 3, 4, 5, 4, 4, 5, 7, 8, 9, 3, 3, 6, 6, 8, 10, 11,
2906 13, 14, 14, 14, 14, 14, 14, 3, 4, 5, 5, 6, 5, 7, 6, 8
2907 ], [
2908 4, 5, 5, 4, 4, 4, 3, 9, 9, 3, 3, 7, 7, 8, 10, 12,
2909 12, 13, 13, 14, 14, 14, 14, 3, 5, 5, 4, 7, 6, 8, 7, 9
2910 ]
2911];
2912const VP30_MBTYPE_CODES: [u8; 7] = [ 0x00, 0x08, 0x0A, 0x03, 0x0B, 0x13, 0x12 ];
2913const VP30_MBTYPE_BITS: [u8; 7] = [ 1, 4, 4, 2, 4, 5, 5 ];
2914const VP30_MBTYPE_SYMS: [VPMBType; 7] = [
2915 VPMBType::InterNoMV, VPMBType::Intra, VPMBType::InterMV, VPMBType::InterNearest,
2916 VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
2917];
2918
2919const VP40_DC_CODES: [[u32; 32]; 16] = [
2920 [
2921 0x000C, 0x0070, 0x01CA, 0x01CB, 0x0391, 0x1C9B, 0x3935, 0x0071,
2922 0x3934, 0x000B, 0x000F, 0x0019, 0x0002, 0x0009, 0x0003, 0x001D,
2923 0x0018, 0x0007, 0x000D, 0x0002, 0x0000, 0x000A, 0x0008, 0x001A,
2924 0x0073, 0x006F, 0x0E4C, 0x0727, 0x0392, 0x0390, 0x0036, 0x006E
2925 ], [
2926 0x0011, 0x007A, 0x0083, 0x0040, 0x0105, 0x0413, 0x0410, 0x007B,
2927 0x0822, 0x000E, 0x0002, 0x0002, 0x0006, 0x000A, 0x0007, 0x001F,
2928 0x0017, 0x0009, 0x000D, 0x0000, 0x000C, 0x0003, 0x003C, 0x002C,
2929 0x0021, 0x0169, 0x0412, 0x02D0, 0x02D1, 0x0823, 0x005B, 0x00B5
2930 ], [
2931 0x0017, 0x0010, 0x00B6, 0x0022, 0x016A, 0x02D0, 0x0B48, 0x0077,
2932 0x1692, 0x0000, 0x0003, 0x0003, 0x0009, 0x000C, 0x0005, 0x0002,
2933 0x001C, 0x0008, 0x000D, 0x000F, 0x000A, 0x0009, 0x0023, 0x003A,
2934 0x002C, 0x016B, 0x05A5, 0x02D3, 0x02D1, 0x1693, 0x0076, 0x00B7
2935 ], [
2936 0x001E, 0x0013, 0x00FB, 0x007C, 0x0046, 0x07D6, 0x0FA9, 0x0012,
2937 0x1F50, 0x0001, 0x0004, 0x0005, 0x000A, 0x000E, 0x0007, 0x0000,
2938 0x0017, 0x0006, 0x000D, 0x000C, 0x0001, 0x002C, 0x008F, 0x003F,
2939 0x002D, 0x01F4, 0x07D5, 0x008E, 0x07D7, 0x1F51, 0x0010, 0x0022
2940 ], [
2941 0x0001, 0x002B, 0x0012, 0x0055, 0x0027, 0x03B0, 0x0762, 0x0077,
2942 0x0261, 0x0002, 0x0006, 0x0007, 0x000B, 0x000F, 0x0008, 0x0000,
2943 0x001C, 0x0003, 0x0009, 0x0006, 0x0014, 0x0054, 0x0131, 0x0005,
2944 0x003A, 0x01D9, 0x0099, 0x004D, 0x0763, 0x0260, 0x0008, 0x00ED
2945 ], [
2946 0x0004, 0x0033, 0x0060, 0x0065, 0x00C2, 0x030D, 0x0619, 0x0064,
2947 0x1862, 0x0004, 0x0007, 0x000A, 0x000B, 0x000D, 0x0006, 0x0000,
2948 0x000F, 0x0003, 0x0005, 0x0002, 0x0002, 0x0077, 0x0C30, 0x0003,
2949 0x0031, 0x0187, 0x01D9, 0x00ED, 0x01D8, 0x1863, 0x001C, 0x003A
2950 ], [
2951 0x0008, 0x000A, 0x006A, 0x0016, 0x001E, 0x034E, 0x069F, 0x0068,
2952 0x0D28, 0x0005, 0x0007, 0x0007, 0x000C, 0x0000, 0x0006, 0x001B,
2953 0x0012, 0x0002, 0x0004, 0x0013, 0x000E, 0x034B, 0x1A53, 0x0006,
2954 0x0017, 0x01A6, 0x069E, 0x01A4, 0x0695, 0x1A52, 0x006B, 0x001F
2955 ], [
2956 0x000E, 0x000F, 0x0017, 0x0025, 0x009F, 0x0138, 0x024B, 0x0093,
2957 0x092A, 0x0005, 0x0000, 0x0008, 0x000D, 0x000F, 0x0006, 0x0004,
2958 0x000E, 0x0019, 0x0018, 0x000A, 0x009E, 0x0494, 0x1256, 0x0026,
2959 0x0016, 0x0124, 0x04E5, 0x0273, 0x04E4, 0x1257, 0x0048, 0x009D
2960 ], [
2961 0x0004, 0x002C, 0x0050, 0x001E, 0x0071, 0x00E1, 0x00E0, 0x001D,
2962 0x0006, 0x0007, 0x0006, 0x0007, 0x0005, 0x0006, 0x0015, 0x0000,
2963 0x0029, 0x0002, 0x0006, 0x0001, 0x0023, 0x001F, 0x0039, 0x0009,
2964 0x0002, 0x0010, 0x0007, 0x002D, 0x002F, 0x002E, 0x0022, 0x0051
2965 ], [
2966 0x0008, 0x002F, 0x0051, 0x0050, 0x02ED, 0x05D9, 0x05D8, 0x00BA,
2967 0x005C, 0x0007, 0x0006, 0x0009, 0x0006, 0x0007, 0x0016, 0x0005,
2968 0x002B, 0x0006, 0x000A, 0x0001, 0x000F, 0x001D, 0x0177, 0x0004,
2969 0x0001, 0x0004, 0x0001, 0x002A, 0x000B, 0x0029, 0x0000, 0x001C
2970 ], [
2971 0x000A, 0x003C, 0x0074, 0x004E, 0x026D, 0x04D9, 0x04D8, 0x009A,
2972 0x004C, 0x0000, 0x0006, 0x0008, 0x0007, 0x0006, 0x0016, 0x0008,
2973 0x002E, 0x000A, 0x000B, 0x003D, 0x0024, 0x00EB, 0x0137, 0x001F,
2974 0x001C, 0x003B, 0x0012, 0x0025, 0x002F, 0x0013, 0x004F, 0x00EA
2975 ], [
2976 0x000A, 0x000A, 0x0003, 0x0016, 0x0009, 0x0021, 0x0020, 0x00B3,
2977 0x0058, 0x0007, 0x0006, 0x0007, 0x0006, 0x0004, 0x0013, 0x0002,
2978 0x0025, 0x0000, 0x0003, 0x002D, 0x005D, 0x00B2, 0x0011, 0x0008,
2979 0x0002, 0x0006, 0x0017, 0x002F, 0x0007, 0x0024, 0x005C, 0x0005
2980 ], [
2981 0x000B, 0x0013, 0x001F, 0x0031, 0x0021, 0x0295, 0x0528, 0x00A4,
2982 0x003C, 0x0000, 0x0007, 0x0006, 0x0005, 0x001B, 0x0012, 0x0032,
2983 0x001D, 0x002B, 0x0030, 0x001C, 0x003D, 0x014B, 0x0529, 0x0008,
2984 0x001A, 0x0033, 0x0011, 0x002A, 0x0009, 0x0028, 0x0053, 0x0020
2985 ], [
2986 0x000E, 0x0015, 0x0029, 0x003F, 0x004D, 0x02F1, 0x05E0, 0x0092,
2987 0x0048, 0x0000, 0x0006, 0x0006, 0x0005, 0x0004, 0x000F, 0x002E,
2988 0x001D, 0x0028, 0x0027, 0x005F, 0x00BD, 0x0179, 0x05E1, 0x0008,
2989 0x001E, 0x002D, 0x001C, 0x002C, 0x003E, 0x0025, 0x004C, 0x0093
2990 ], [
2991 0x000C, 0x0017, 0x0035, 0x0013, 0x0021, 0x00AD, 0x06F1, 0x01BD,
2992 0x00D9, 0x0000, 0x0007, 0x0007, 0x0006, 0x0004, 0x0011, 0x002A,
2993 0x006E, 0x0025, 0x0024, 0x0057, 0x00D8, 0x0379, 0x06F0, 0x0005,
2994 0x0016, 0x0029, 0x006D, 0x0028, 0x0034, 0x0020, 0x00DF, 0x00AC
2995 ], [
2996 0x0000, 0x001A, 0x0006, 0x0019, 0x0030, 0x005A, 0x018A, 0x02DD,
2997 0x018B, 0x0001, 0x0007, 0x000A, 0x0009, 0x0002, 0x0010, 0x002E,
2998 0x006E, 0x002C, 0x000E, 0x005E, 0x00C4, 0x05B9, 0x05B8, 0x0011,
2999 0x0036, 0x005F, 0x001E, 0x0063, 0x006F, 0x001F, 0x00B6, 0x016F
3000 ]
3001];
3002const VP40_DC_BITS: [[u8; 32]; 16] = [
3003 [
3004 5, 7, 9, 9, 10, 13, 14, 7, 14, 4, 4, 5, 4, 4, 4, 5,
3005 5, 4, 4, 3, 3, 4, 4, 6, 7, 8, 12, 11, 10, 10, 7, 8
3006 ], [
3007 5, 7, 8, 7, 9, 11, 11, 7, 12, 4, 3, 4, 4, 4, 4, 5,
3008 5, 4, 4, 3, 4, 4, 6, 6, 6, 9, 11, 10, 10, 12, 7, 8
3009 ], [
3010 5, 6, 8, 7, 9, 10, 12, 7, 13, 3, 3, 4, 4, 4, 4, 4,
3011 5, 4, 4, 4, 4, 5, 7, 6, 6, 9, 11, 10, 10, 13, 7, 8
3012 ], [
3013 5, 6, 8, 7, 8, 11, 12, 6, 13, 3, 3, 4, 4, 4, 4, 4,
3014 5, 4, 4, 4, 4, 6, 9, 6, 6, 9, 11, 9, 11, 13, 6, 7
3015 ], [
3016 4, 6, 7, 7, 8, 10, 11, 7, 12, 3, 3, 4, 4, 4, 4, 4,
3017 5, 4, 4, 4, 5, 7, 11, 5, 6, 9, 10, 9, 11, 12, 6, 8
3018 ], [
3019 4, 6, 7, 7, 8, 10, 11, 7, 13, 3, 3, 4, 4, 4, 4, 4,
3020 5, 4, 4, 4, 5, 8, 12, 5, 6, 9, 10, 9, 10, 13, 6, 7
3021 ], [
3022 4, 5, 7, 6, 7, 10, 11, 7, 12, 3, 3, 4, 4, 3, 4, 5,
3023 5, 4, 4, 5, 6, 10, 13, 5, 6, 9, 11, 9, 11, 13, 7, 7
3024 ], [
3025 4, 5, 6, 6, 8, 9, 10, 8, 12, 3, 2, 4, 4, 4, 4, 4,
3026 5, 5, 5, 5, 8, 11, 13, 6, 6, 9, 11, 10, 11, 13, 7, 8
3027 ], [
3028 4, 6, 7, 7, 9, 10, 10, 7, 6, 3, 3, 4, 4, 4, 5, 5,
3029 6, 5, 5, 5, 6, 7, 8, 4, 4, 5, 6, 6, 6, 6, 6, 7
3030 ], [
3031 4, 6, 7, 7, 10, 11, 11, 8, 7, 3, 3, 4, 4, 4, 5, 5,
3032 6, 5, 5, 5, 6, 7, 9, 4, 4, 5, 6, 6, 5, 6, 6, 7
3033 ], [
3034 4, 6, 7, 7, 10, 11, 11, 8, 7, 2, 3, 4, 4, 4, 5, 5,
3035 6, 5, 5, 6, 6, 8, 9, 5, 5, 6, 6, 6, 6, 6, 7, 8
3036 ], [
3037 4, 5, 6, 6, 8, 10, 10, 8, 7, 3, 3, 4, 4, 4, 5, 5,
3038 6, 5, 5, 6, 7, 8, 9, 4, 4, 5, 6, 6, 5, 6, 7, 7
3039 ], [
3040 4, 5, 6, 6, 7, 10, 11, 8, 7, 2, 3, 4, 4, 5, 5, 6,
3041 6, 6, 6, 6, 7, 9, 11, 4, 5, 6, 6, 6, 5, 6, 7, 7
3042 ], [
3043 4, 5, 6, 6, 7, 10, 11, 8, 7, 2, 3, 4, 4, 4, 5, 6,
3044 6, 6, 6, 7, 8, 9, 11, 4, 5, 6, 6, 6, 6, 6, 7, 8
3045 ], [
3046 4, 5, 6, 5, 6, 8, 11, 9, 8, 2, 3, 4, 4, 4, 5, 6,
3047 7, 6, 6, 7, 8, 10, 11, 4, 5, 6, 7, 6, 6, 6, 8, 8
3048 ], [
3049 3, 5, 5, 5, 6, 7, 9, 10, 9, 2, 3, 4, 4, 4, 5, 6,
3050 7, 6, 6, 7, 8, 11, 11, 5, 6, 7, 7, 7, 7, 7, 8, 9
3051 ]
3052];
3053const VP40_AC_CAT0_CODES: [[u32; 32]; 16] = [
3054 [
3055 0x0006, 0x001E, 0x01CC, 0x01CE, 0x0734, 0x1CD5, 0x1CD4, 0x0018,
3056 0x0E6B, 0x0000, 0x000F, 0x0006, 0x0007, 0x000D, 0x0008, 0x0002,
3057 0x0019, 0x0005, 0x000B, 0x000A, 0x001D, 0x0027, 0x01CF, 0x0004,
3058 0x0038, 0x000E, 0x004C, 0x001F, 0x004D, 0x039B, 0x0012, 0x0072
3059 ], [
3060 0x0009, 0x004B, 0x0090, 0x0091, 0x0745, 0x1D11, 0x1D10, 0x0019,
3061 0x0E89, 0x0000, 0x000F, 0x0008, 0x0007, 0x000D, 0x000B, 0x0002,
3062 0x001C, 0x0003, 0x000A, 0x0005, 0x0018, 0x0010, 0x01D0, 0x0006,
3063 0x003B, 0x0011, 0x004A, 0x0049, 0x00E9, 0x03A3, 0x0013, 0x0075
3064 ], [
3065 0x0019, 0x0074, 0x001D, 0x00EA, 0x0073, 0x01CA, 0x0396, 0x001C,
3066 0x00E4, 0x0002, 0x0001, 0x0007, 0x0008, 0x000D, 0x0009, 0x001F,
3067 0x0018, 0x0000, 0x0006, 0x001E, 0x003B, 0x00EB, 0x0397, 0x000A,
3068 0x0002, 0x002C, 0x005B, 0x005A, 0x000F, 0x0038, 0x0017, 0x0006
3069 ], [
3070 0x001E, 0x006F, 0x00AE, 0x00AF, 0x0187, 0x061B, 0x0C35, 0x001A,
3071 0x030C, 0x0002, 0x0001, 0x0007, 0x0008, 0x000E, 0x0009, 0x001F,
3072 0x0014, 0x0000, 0x0001, 0x0019, 0x002A, 0x0060, 0x0C34, 0x000B,
3073 0x000D, 0x0036, 0x006E, 0x0056, 0x0031, 0x00C2, 0x0018, 0x0019
3074 ], [
3075 0x0001, 0x002C, 0x0005, 0x0015, 0x0008, 0x0097, 0x012D, 0x0017,
3076 0x004A, 0x0003, 0x0002, 0x0009, 0x000A, 0x000E, 0x0008, 0x001F,
3077 0x0007, 0x001E, 0x001B, 0x0004, 0x005A, 0x0024, 0x012C, 0x000C,
3078 0x0006, 0x0000, 0x0003, 0x005B, 0x0014, 0x0013, 0x001A, 0x000B
3079 ], [
3080 0x0004, 0x0000, 0x0017, 0x0063, 0x018B, 0x0310, 0x0C44, 0x0019,
3081 0x0623, 0x0004, 0x0003, 0x000A, 0x000B, 0x000D, 0x0003, 0x001C,
3082 0x0003, 0x000A, 0x0004, 0x0003, 0x018A, 0x188B, 0x188A, 0x000F,
3083 0x000B, 0x0002, 0x000A, 0x0002, 0x0016, 0x0189, 0x001D, 0x0030
3084 ], [
3085 0x000D, 0x0003, 0x0077, 0x000D, 0x0082, 0x020D, 0x0830, 0x0019,
3086 0x0419, 0x0003, 0x0002, 0x000A, 0x0009, 0x000B, 0x0002, 0x0011,
3087 0x0039, 0x0002, 0x0021, 0x0040, 0x1063, 0x20C5, 0x20C4, 0x000F,
3088 0x0018, 0x0007, 0x0038, 0x000C, 0x0076, 0x0107, 0x0000, 0x003A
3089 ], [
3090 0x000F, 0x001C, 0x0036, 0x0008, 0x0061, 0x0091, 0x0243, 0x0009,
3091 0x0120, 0x0005, 0x0003, 0x0008, 0x0005, 0x0001, 0x0013, 0x0031,
3092 0x0076, 0x0060, 0x0093, 0x0909, 0x0908, 0x090B, 0x090A, 0x0001,
3093 0x001A, 0x0019, 0x003A, 0x0025, 0x0077, 0x0092, 0x0000, 0x0037
3094 ], [
3095 0x001F, 0x0079, 0x00F1, 0x00F0, 0x011B, 0x0469, 0x0468, 0x003B,
3096 0x0022, 0x0005, 0x0004, 0x0007, 0x0005, 0x0006, 0x001C, 0x0001,
3097 0x0035, 0x003D, 0x003A, 0x0010, 0x0047, 0x008C, 0x0235, 0x0001,
3098 0x0001, 0x0019, 0x0000, 0x0030, 0x0009, 0x0031, 0x001B, 0x0034
3099 ], [
3100 0x0003, 0x001B, 0x00F3, 0x00FD, 0x03C9, 0x0F20, 0x1E42, 0x003D,
3101 0x00FC, 0x0006, 0x0004, 0x0002, 0x0000, 0x0001, 0x0017, 0x003E,
3102 0x001A, 0x0039, 0x002B, 0x0078, 0x01E5, 0x0791, 0x1E43, 0x0002,
3103 0x0007, 0x001D, 0x000C, 0x0038, 0x0014, 0x007F, 0x0016, 0x002A
3104 ], [
3105 0x0007, 0x0039, 0x0051, 0x0078, 0x03CB, 0x0F29, 0x1E51, 0x003D,
3106 0x00F3, 0x0006, 0x0004, 0x0002, 0x0000, 0x0001, 0x0017, 0x003E,
3107 0x007F, 0x002B, 0x007E, 0x0050, 0x01E4, 0x0795, 0x1E50, 0x0002,
3108 0x0006, 0x001D, 0x0006, 0x0038, 0x0007, 0x0029, 0x0016, 0x002A
3109 ], [
3110 0x0008, 0x003B, 0x001D, 0x0072, 0x01CC, 0x0734, 0x1CD5, 0x003A,
3111 0x001C, 0x0006, 0x0005, 0x0002, 0x0001, 0x0000, 0x0012, 0x003E,
3112 0x007F, 0x001E, 0x007E, 0x00E7, 0x039B, 0x0E6B, 0x1CD4, 0x0002,
3113 0x0006, 0x001E, 0x000E, 0x0038, 0x0006, 0x000F, 0x0013, 0x001F
3114 ], [
3115 0x000D, 0x003F, 0x0073, 0x000C, 0x00E4, 0x072B, 0x0E54, 0x003A,
3116 0x001A, 0x0005, 0x0004, 0x0002, 0x0001, 0x0000, 0x0007, 0x0038,
3117 0x0076, 0x0077, 0x001B, 0x01CB, 0x0394, 0x1CAB, 0x1CAA, 0x0002,
3118 0x0006, 0x001E, 0x000E, 0x003E, 0x0019, 0x001F, 0x0018, 0x001E
3119 ], [
3120 0x000E, 0x0007, 0x000C, 0x001C, 0x00BD, 0x02F3, 0x0BC9, 0x001F,
3121 0x00BF, 0x0006, 0x0004, 0x0002, 0x0001, 0x001E, 0x0001, 0x000D,
3122 0x003A, 0x003B, 0x00BE, 0x0178, 0x05E5, 0x1791, 0x1790, 0x0002,
3123 0x0006, 0x001F, 0x0016, 0x0000, 0x0015, 0x002E, 0x0014, 0x001E
3124 ], [
3125 0x0000, 0x001B, 0x0031, 0x003A, 0x0060, 0x006F, 0x01B9, 0x000E,
3126 0x001A, 0x0005, 0x0003, 0x0002, 0x001F, 0x001A, 0x0039, 0x000C,
3127 0x00C3, 0x00C2, 0x0036, 0x00DD, 0x0370, 0x06E3, 0x06E2, 0x0002,
3128 0x0008, 0x001E, 0x0019, 0x003B, 0x0012, 0x000F, 0x0013, 0x0038
3129 ], [
3130 0x0002, 0x0000, 0x0003, 0x001C, 0x0032, 0x001C, 0x0199, 0x0004,
3131 0x00CD, 0x0004, 0x0003, 0x001B, 0x001A, 0x003D, 0x0067, 0x003B,
3132 0x0198, 0x0075, 0x00E9, 0x03A1, 0x03A0, 0x03A3, 0x03A2, 0x0005,
3133 0x0002, 0x001F, 0x001D, 0x003C, 0x0018, 0x000F, 0x0006, 0x0005
3134 ]
3135];
3136const VP40_AC_CAT0_BITS: [[u8; 32]; 16] = [
3137 [
3138 5, 7, 9, 9, 11, 13, 13, 5, 12, 3, 4, 4, 4, 4, 4, 4,
3139 5, 4, 4, 4, 5, 6, 9, 4, 6, 6, 7, 7, 7, 10, 5, 7
3140 ], [
3141 5, 7, 8, 8, 11, 13, 13, 5, 12, 3, 4, 4, 4, 4, 4, 4,
3142 5, 4, 4, 4, 5, 6, 9, 4, 6, 6, 7, 7, 8, 10, 5, 7
3143 ], [
3144 5, 7, 8, 8, 10, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3145 5, 4, 4, 5, 6, 8, 13, 4, 5, 6, 7, 7, 7, 9, 5, 6
3146 ], [
3147 5, 7, 8, 8, 10, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3148 5, 4, 4, 5, 6, 8, 13, 4, 5, 6, 7, 7, 7, 9, 5, 6
3149 ], [
3150 4, 6, 7, 7, 8, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3151 5, 5, 5, 5, 7, 10, 13, 4, 5, 5, 6, 7, 7, 9, 5, 6
3152 ], [
3153 4, 5, 7, 7, 9, 10, 12, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3154 5, 5, 5, 6, 9, 13, 13, 4, 5, 5, 6, 6, 7, 9, 5, 6
3155 ], [
3156 4, 5, 7, 6, 8, 10, 12, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3157 6, 5, 6, 7, 13, 14, 14, 4, 5, 5, 6, 6, 7, 9, 4, 6
3158 ], [
3159 4, 5, 6, 5, 7, 8, 10, 5, 9, 3, 3, 4, 4, 4, 5, 6,
3160 7, 7, 8, 12, 12, 12, 12, 3, 5, 5, 6, 6, 7, 8, 4, 6
3161 ], [
3162 5, 7, 8, 8, 10, 12, 12, 6, 7, 3, 3, 4, 4, 4, 5, 5,
3163 6, 6, 6, 6, 8, 9, 11, 3, 4, 5, 5, 6, 5, 6, 5, 6
3164 ], [
3165 4, 6, 8, 8, 10, 12, 13, 6, 8, 3, 3, 4, 4, 4, 5, 6,
3166 6, 6, 6, 7, 9, 11, 13, 3, 4, 5, 5, 6, 5, 7, 5, 6
3167 ], [
3168 4, 6, 7, 7, 10, 12, 13, 6, 8, 3, 3, 4, 4, 4, 5, 6,
3169 7, 6, 7, 7, 9, 11, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3170 ], [
3171 4, 6, 7, 7, 9, 11, 13, 6, 7, 3, 3, 4, 4, 4, 5, 6,
3172 7, 6, 7, 8, 10, 12, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3173 ], [
3174 4, 6, 7, 6, 8, 11, 12, 6, 7, 3, 3, 4, 4, 4, 5, 6,
3175 7, 7, 7, 9, 10, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3176 ], [
3177 4, 5, 6, 6, 8, 10, 12, 6, 8, 3, 3, 4, 4, 5, 5, 6,
3178 7, 7, 8, 9, 11, 13, 13, 3, 4, 5, 5, 5, 5, 6, 5, 6
3179 ], [
3180 3, 5, 6, 6, 7, 9, 11, 6, 7, 3, 3, 4, 5, 5, 6, 6,
3181 8, 8, 8, 10, 12, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3182 ], [
3183 3, 4, 5, 5, 6, 7, 9, 6, 8, 3, 3, 5, 5, 6, 7, 8,
3184 9, 9, 10, 12, 12, 12, 12, 3, 4, 5, 5, 6, 5, 6, 5, 6
3185 ]
3186];
3187const VP40_AC_CAT1_CODES: [[u32; 32]; 16] = [
3188 [
3189 0x0004, 0x00F5, 0x0182, 0x060F, 0x1839, 0x1838, 0x183B, 0x0013,
3190 0x00C0, 0x0003, 0x0002, 0x000B, 0x000A, 0x000E, 0x0008, 0x0001,
3191 0x0012, 0x001F, 0x0000, 0x0006, 0x007B, 0x0306, 0x183A, 0x000D,
3192 0x0007, 0x0031, 0x000A, 0x0061, 0x003C, 0x00F4, 0x0019, 0x000B
3193 ], [
3194 0x000A, 0x001A, 0x01D8, 0x03B3, 0x0ECA, 0x1D96, 0x3B2F, 0x0014,
3195 0x0036, 0x0004, 0x0003, 0x000C, 0x000B, 0x0000, 0x0004, 0x001C,
3196 0x0005, 0x0015, 0x0007, 0x0017, 0x0037, 0x0764, 0x3B2E, 0x000F,
3197 0x001A, 0x003A, 0x000C, 0x0077, 0x0004, 0x00ED, 0x001B, 0x0016
3198 ], [
3199 0x001A, 0x002D, 0x0058, 0x01F4, 0x07D4, 0x1F55, 0x1F54, 0x0014,
3200 0x0059, 0x0004, 0x0003, 0x000B, 0x000C, 0x000E, 0x0004, 0x0015,
3201 0x0005, 0x0007, 0x0004, 0x007C, 0x03EB, 0x1F57, 0x1F56, 0x0000,
3202 0x001B, 0x003F, 0x000D, 0x000C, 0x000A, 0x00FB, 0x001E, 0x0017
3203 ], [
3204 0x0000, 0x0075, 0x004A, 0x0097, 0x025B, 0x0969, 0x0968, 0x000B,
3205 0x00E8, 0x0005, 0x0004, 0x0007, 0x000C, 0x000D, 0x0001, 0x000A,
3206 0x0039, 0x003B, 0x0018, 0x00E9, 0x012C, 0x096B, 0x096A, 0x0001,
3207 0x001F, 0x0008, 0x0019, 0x0013, 0x000D, 0x0024, 0x001E, 0x0038
3208 ], [
3209 0x0004, 0x0014, 0x006E, 0x0057, 0x0159, 0x0562, 0x0AC7, 0x000B,
3210 0x006F, 0x0006, 0x0005, 0x0008, 0x0009, 0x0007, 0x001E, 0x0002,
3211 0x0007, 0x0006, 0x002A, 0x00AD, 0x0AC6, 0x0561, 0x0560, 0x0001,
3212 0x001F, 0x000C, 0x0039, 0x001A, 0x0000, 0x0036, 0x001D, 0x0038
3213 ], [
3214 0x0007, 0x001B, 0x000E, 0x000D, 0x03E1, 0x1F06, 0x3E0F, 0x0002,
3215 0x00F9, 0x0005, 0x0006, 0x0008, 0x0009, 0x0004, 0x000C, 0x001A,
3216 0x000F, 0x000C, 0x01F1, 0x07C0, 0x3E0E, 0x1F05, 0x1F04, 0x0001,
3217 0x0000, 0x001C, 0x003F, 0x003D, 0x0005, 0x007D, 0x001D, 0x003C
3218 ], [
3219 0x000F, 0x000A, 0x0071, 0x0006, 0x01C2, 0x0702, 0x1C0E, 0x0002,
3220 0x000E, 0x0005, 0x0004, 0x0006, 0x0007, 0x001D, 0x0017, 0x000F,
3221 0x01C3, 0x01C1, 0x0380, 0x381F, 0x381E, 0x1C0D, 0x1C0C, 0x0001,
3222 0x0004, 0x0018, 0x0001, 0x0000, 0x000D, 0x0016, 0x0019, 0x0039
3223 ], [
3224 0x0002, 0x001E, 0x003B, 0x000D, 0x0061, 0x01FA, 0x1FB5, 0x0031,
3225 0x00FC, 0x0004, 0x0005, 0x0001, 0x0007, 0x003A, 0x0060, 0x03F7,
3226 0x07EC, 0x1FB7, 0x3F6C, 0x7EDB, 0x7EDA, 0x3F69, 0x3F68, 0x0001,
3227 0x0000, 0x0019, 0x003E, 0x0039, 0x000D, 0x0038, 0x000C, 0x007F
3228 ], [
3229 0x001E, 0x0070, 0x0127, 0x0126, 0x0492, 0x124D, 0x124C, 0x0001,
3230 0x007F, 0x0006, 0x0005, 0x0005, 0x0004, 0x0001, 0x0007, 0x0025,
3231 0x0071, 0x007E, 0x0048, 0x0125, 0x0248, 0x124F, 0x124E, 0x0003,
3232 0x0008, 0x001D, 0x0006, 0x003E, 0x0002, 0x0000, 0x0013, 0x0039
3233 ], [
3234 0x0001, 0x0001, 0x00E7, 0x0091, 0x0240, 0x120D, 0x120C, 0x003C,
3235 0x0000, 0x0006, 0x0005, 0x0005, 0x0004, 0x001F, 0x0004, 0x0025,
3236 0x0072, 0x0049, 0x00E6, 0x0121, 0x0482, 0x120F, 0x120E, 0x0003,
3237 0x0008, 0x001D, 0x0005, 0x003D, 0x0003, 0x0001, 0x0013, 0x0038
3238 ], [
3239 0x0004, 0x000F, 0x00F4, 0x005B, 0x02D3, 0x0B4A, 0x1697, 0x003C,
3240 0x000E, 0x0006, 0x0005, 0x0002, 0x0001, 0x001D, 0x0000, 0x007B,
3241 0x002C, 0x00F5, 0x00B5, 0x0168, 0x1696, 0x0B49, 0x0B48, 0x0003,
3242 0x0009, 0x001F, 0x000A, 0x0001, 0x0008, 0x0006, 0x001C, 0x0017
3243 ], [
3244 0x0008, 0x0039, 0x001A, 0x0003, 0x00DB, 0x06D6, 0x0DAF, 0x003C,
3245 0x000C, 0x0006, 0x0005, 0x0002, 0x0001, 0x001D, 0x003D, 0x0000,
3246 0x0002, 0x0037, 0x006C, 0x01B4, 0x0DAE, 0x06D5, 0x06D4, 0x0002,
3247 0x0007, 0x001F, 0x0007, 0x0001, 0x0009, 0x000D, 0x000C, 0x0038
3248 ], [
3249 0x000F, 0x0004, 0x002F, 0x002E, 0x0054, 0x0555, 0x0554, 0x0016,
3250 0x000E, 0x0006, 0x0005, 0x0001, 0x0000, 0x0009, 0x000B, 0x0014,
3251 0x0057, 0x0056, 0x00AB, 0x0557, 0x0556, 0x02A9, 0x02A8, 0x0003,
3252 0x0008, 0x0013, 0x000A, 0x0008, 0x000E, 0x0012, 0x0006, 0x000F
3253 ], [
3254 0x0001, 0x000E, 0x0006, 0x0004, 0x00DA, 0x0DBE, 0x1B7E, 0x0007,
3255 0x001A, 0x0005, 0x0004, 0x001C, 0x001B, 0x003A, 0x0037, 0x006C,
3256 0x01B6, 0x036E, 0x0DBD, 0x36FF, 0x36FE, 0x1B79, 0x1B78, 0x0002,
3257 0x000C, 0x0000, 0x000F, 0x000C, 0x000F, 0x001A, 0x003B, 0x0005
3258 ], [
3259 0x0005, 0x001E, 0x003A, 0x003E, 0x00FC, 0x0FD7, 0x3F55, 0x0077,
3260 0x0030, 0x0003, 0x0004, 0x001A, 0x0019, 0x007F, 0x01FB, 0x03F4,
3261 0x0FD6, 0x1FA9, 0x3F54, 0x3F57, 0x3F56, 0x3F51, 0x3F50, 0x0001,
3262 0x0004, 0x001C, 0x000B, 0x000A, 0x0000, 0x001B, 0x0031, 0x0076
3263 ], [
3264 0x0005, 0x000C, 0x001B, 0x0008, 0x0038, 0x0015, 0x00A3, 0x00E6,
3265 0x0004, 0x0001, 0x0002, 0x0012, 0x0003, 0x000B, 0x0029, 0x00A0,
3266 0x0142, 0x0287, 0x0286, 0x0289, 0x0288, 0x028B, 0x028A, 0x000F,
3267 0x001D, 0x0013, 0x0001, 0x0000, 0x0003, 0x001A, 0x0072, 0x00E7
3268 ]
3269];
3270const VP40_AC_CAT1_BITS: [[u8; 32]; 16] = [
3271 [
3272 5, 8, 9, 11, 13, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 4,
3273 5, 5, 4, 5, 7, 10, 13, 4, 5, 6, 6, 7, 6, 8, 5, 6
3274 ], [
3275 5, 7, 9, 10, 12, 13, 14, 5, 8, 3, 3, 4, 4, 3, 4, 5,
3276 5, 5, 5, 6, 8, 11, 14, 4, 5, 6, 6, 7, 5, 8, 5, 6
3277 ], [
3278 5, 7, 8, 9, 11, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 5,
3279 5, 5, 5, 7, 10, 13, 13, 3, 5, 6, 6, 6, 5, 8, 5, 6
3280 ], [
3281 4, 7, 8, 9, 11, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 5,
3282 6, 6, 6, 8, 10, 13, 13, 3, 5, 5, 6, 6, 5, 7, 5, 6
3283 ], [
3284 4, 6, 8, 8, 10, 12, 13, 5, 8, 3, 3, 4, 4, 4, 5, 5,
3285 6, 6, 7, 9, 13, 12, 12, 3, 5, 5, 6, 6, 4, 7, 5, 6
3286 ], [
3287 4, 6, 7, 7, 10, 13, 14, 5, 8, 3, 3, 4, 4, 4, 5, 6,
3288 7, 7, 9, 11, 14, 13, 13, 3, 4, 5, 6, 6, 4, 7, 5, 6
3289 ], [
3290 4, 5, 7, 6, 9, 11, 13, 5, 7, 3, 3, 4, 4, 5, 6, 7,
3291 9, 9, 10, 14, 14, 13, 13, 3, 4, 5, 5, 5, 4, 6, 5, 6
3292 ], [
3293 3, 5, 6, 5, 7, 9, 13, 6, 8, 3, 3, 4, 4, 6, 7, 10,
3294 11, 13, 14, 15, 15, 14, 14, 3, 4, 5, 6, 6, 4, 6, 5, 7
3295 ], [
3296 5, 7, 9, 9, 11, 13, 13, 5, 7, 3, 3, 4, 4, 4, 5, 6,
3297 7, 7, 7, 9, 10, 13, 13, 3, 4, 5, 5, 6, 4, 5, 5, 6
3298 ], [
3299 4, 6, 8, 8, 10, 13, 13, 6, 6, 3, 3, 4, 4, 5, 5, 6,
3300 7, 7, 8, 9, 11, 13, 13, 3, 4, 5, 5, 6, 4, 5, 5, 6
3301 ], [
3302 4, 6, 8, 8, 11, 13, 14, 6, 6, 3, 3, 4, 4, 5, 5, 7,
3303 7, 8, 9, 10, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6
3304 ], [
3305 4, 6, 7, 7, 10, 13, 14, 6, 6, 3, 3, 4, 4, 5, 6, 6,
3306 7, 8, 9, 11, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6
3307 ], [
3308 4, 5, 7, 7, 9, 13, 13, 6, 6, 3, 3, 4, 4, 5, 6, 7,
3309 9, 9, 10, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6
3310 ], [
3311 3, 5, 6, 6, 9, 13, 14, 6, 6, 3, 3, 5, 5, 6, 7, 8,
3312 10, 11, 13, 15, 15, 14, 14, 3, 4, 4, 5, 5, 4, 5, 6, 6
3313 ], [
3314 3, 5, 6, 6, 8, 12, 14, 7, 6, 3, 3, 5, 5, 7, 9, 10,
3315 12, 13, 14, 14, 14, 14, 14, 3, 4, 5, 5, 5, 3, 5, 6, 7
3316 ], [
3317 3, 4, 5, 4, 6, 8, 11, 8, 6, 3, 3, 5, 5, 7, 9, 11,
3318 12, 13, 13, 13, 13, 13, 13, 4, 5, 5, 5, 5, 3, 5, 7, 8
3319 ]
3320];
3321const VP40_AC_CAT2_CODES: [[u32; 32]; 16] = [
3322 [
3323 0x0009, 0x0015, 0x0028, 0x0052, 0x029A, 0x0537, 0x0536, 0x000A,
3324 0x0054, 0x0004, 0x0003, 0x000C, 0x000B, 0x000D, 0x0003, 0x0014,
3325 0x003A, 0x0004, 0x0038, 0x0055, 0x00A7, 0x0299, 0x0298, 0x0000,
3326 0x001E, 0x0008, 0x002B, 0x000B, 0x000B, 0x003B, 0x001F, 0x0039
3327 ], [
3328 0x001D, 0x002F, 0x0002, 0x0007, 0x0019, 0x0035, 0x0034, 0x0009,
3329 0x002E, 0x0006, 0x0005, 0x0009, 0x0008, 0x0007, 0x001F, 0x0008,
3330 0x0018, 0x0019, 0x0001, 0x0000, 0x0018, 0x0037, 0x0036, 0x0001,
3331 0x0001, 0x000A, 0x0039, 0x0016, 0x000D, 0x0001, 0x001E, 0x0038
3332 ], [
3333 0x0001, 0x0071, 0x00E0, 0x01C3, 0x0708, 0x1C26, 0x384F, 0x0001,
3334 0x0031, 0x0006, 0x0005, 0x0009, 0x0008, 0x0005, 0x000F, 0x0039,
3335 0x0077, 0x0076, 0x0030, 0x0385, 0x384E, 0x1C25, 0x1C24, 0x0001,
3336 0x0004, 0x000D, 0x0000, 0x0019, 0x001F, 0x000E, 0x001E, 0x003A
3337 ], [
3338 0x0006, 0x000C, 0x00D6, 0x007B, 0x01E8, 0x07A4, 0x0F4B, 0x0036,
3339 0x006A, 0x0007, 0x0005, 0x0008, 0x0009, 0x0001, 0x0007, 0x000D,
3340 0x003C, 0x00D7, 0x00F5, 0x07A7, 0x0F4A, 0x0F4D, 0x0F4C, 0x0002,
3341 0x0002, 0x000E, 0x0037, 0x0034, 0x0000, 0x0019, 0x0018, 0x001F
3342 ], [
3343 0x000A, 0x0027, 0x00BF, 0x00BE, 0x0224, 0x225D, 0x225C, 0x0026,
3344 0x005E, 0x0007, 0x0006, 0x0006, 0x0007, 0x0016, 0x002E, 0x0045,
3345 0x0088, 0x0113, 0x044A, 0x225F, 0x225E, 0x112D, 0x112C, 0x0002,
3346 0x0002, 0x0012, 0x0003, 0x0002, 0x0003, 0x0000, 0x0010, 0x0023
3347 ], [
3348 0x000F, 0x0006, 0x0075, 0x0074, 0x000A, 0x00BF, 0x00B9, 0x0022,
3349 0x0003, 0x0005, 0x0006, 0x0001, 0x0002, 0x0007, 0x0000, 0x0004,
3350 0x0016, 0x005E, 0x00B8, 0x00BB, 0x00BA, 0x017D, 0x017C, 0x0002,
3351 0x0006, 0x001C, 0x0010, 0x003B, 0x0009, 0x0007, 0x0001, 0x0023
3352 ], [
3353 0x0001, 0x001C, 0x0036, 0x003B, 0x00EA, 0x075B, 0x1D65, 0x0019,
3354 0x0074, 0x0004, 0x0005, 0x0000, 0x0001, 0x0037, 0x01D7, 0x075A,
3355 0x1D64, 0x1D67, 0x1D66, 0x1D61, 0x1D60, 0x1D63, 0x1D62, 0x0002,
3356 0x001F, 0x001A, 0x000D, 0x003D, 0x000C, 0x0007, 0x003C, 0x0018
3357 ], [
3358 0x0002, 0x0001, 0x0014, 0x0000, 0x002F, 0x00BB, 0x02E4, 0x007D,
3359 0x00BA, 0x0003, 0x0004, 0x0016, 0x001A, 0x00B8, 0x172E, 0x2E5F,
3360 0x2E5E, 0x1729, 0x1728, 0x172B, 0x172A, 0x172D, 0x172C, 0x0001,
3361 0x001E, 0x0015, 0x001B, 0x003F, 0x000C, 0x000E, 0x007C, 0x0173
3362 ], [
3363 0x0003, 0x007B, 0x0058, 0x01EA, 0x1EB1, 0x1EB0, 0x1EB3, 0x0013,
3364 0x0012, 0x0005, 0x0006, 0x0002, 0x0001, 0x0013, 0x003C, 0x002D,
3365 0x00F4, 0x0059, 0x03D7, 0x0F5B, 0x1EB2, 0x1EB5, 0x1EB4, 0x0003,
3366 0x000E, 0x001F, 0x0012, 0x0008, 0x0008, 0x0000, 0x000A, 0x0017
3367 ], [
3368 0x0008, 0x003C, 0x00F5, 0x00F4, 0x1EF7, 0x3DE9, 0x3DE8, 0x001C,
3369 0x000D, 0x0005, 0x0006, 0x0001, 0x0000, 0x0007, 0x000C, 0x00F6,
3370 0x01EE, 0x03DF, 0x07BC, 0x3DEB, 0x3DEA, 0x3DED, 0x3DEC, 0x0002,
3371 0x0009, 0x001F, 0x000F, 0x0005, 0x000E, 0x0006, 0x0004, 0x001D
3372 ], [
3373 0x0009, 0x0039, 0x0019, 0x0018, 0x0706, 0x383D, 0x383C, 0x000D,
3374 0x000F, 0x0005, 0x0006, 0x0000, 0x001D, 0x0003, 0x0071, 0x00E1,
3375 0x01C0, 0x0382, 0x1C1D, 0x383F, 0x383E, 0x3839, 0x3838, 0x0002,
3376 0x0008, 0x0002, 0x000D, 0x000C, 0x000F, 0x0007, 0x0002, 0x000E
3377 ], [
3378 0x0000, 0x0006, 0x0035, 0x0034, 0x0777, 0x1DD4, 0x3BAB, 0x000E,
3379 0x000F, 0x0005, 0x0004, 0x001C, 0x0019, 0x003A, 0x00EF, 0x01DC,
3380 0x0776, 0x0774, 0x3BAA, 0x3BAD, 0x3BAC, 0x3BAF, 0x3BAE, 0x0002,
3381 0x0007, 0x0002, 0x0018, 0x000C, 0x000F, 0x000D, 0x001B, 0x0076
3382 ], [
3383 0x0002, 0x0011, 0x0006, 0x004F, 0x0130, 0x1319, 0x1318, 0x004E,
3384 0x0007, 0x0006, 0x0005, 0x0010, 0x000D, 0x0005, 0x0099, 0x0262,
3385 0x098E, 0x131B, 0x131A, 0x263D, 0x263C, 0x263F, 0x263E, 0x0001,
3386 0x0007, 0x0000, 0x0012, 0x000C, 0x000E, 0x000F, 0x0004, 0x004D
3387 ], [
3388 0x0003, 0x0000, 0x0002, 0x0037, 0x01B7, 0x0DB5, 0x36DD, 0x006C,
3389 0x0016, 0x0005, 0x0004, 0x0003, 0x000A, 0x002E, 0x036C, 0x0DB4,
3390 0x36DC, 0x36DF, 0x36DE, 0x36D9, 0x36D8, 0x36DB, 0x36DA, 0x000E,
3391 0x0004, 0x001A, 0x0019, 0x0018, 0x000F, 0x0001, 0x002F, 0x00DA
3392 ], [
3393 0x0006, 0x0006, 0x000F, 0x0000, 0x0075, 0x03B8, 0x1DCA, 0x0074,
3394 0x0076, 0x0004, 0x0005, 0x0003, 0x0002, 0x01DE, 0x0EE6, 0x3B97,
3395 0x3B96, 0x3B9D, 0x3B9C, 0x3B9F, 0x3B9E, 0x1DC9, 0x1DC8, 0x0005,
3396 0x001C, 0x0009, 0x000E, 0x0008, 0x000F, 0x0001, 0x01DF, 0x01DD
3397 ], [
3398 0x0004, 0x000B, 0x001D, 0x000C, 0x0014, 0x00E0, 0x3875, 0x0386,
3399 0x01C2, 0x0000, 0x0001, 0x0071, 0x0072, 0x1C3F, 0x3874, 0x3877,
3400 0x3876, 0x3871, 0x3870, 0x3873, 0x3872, 0x3879, 0x3878, 0x003C,
3401 0x0073, 0x002A, 0x003D, 0x002B, 0x001F, 0x000D, 0x1C3E, 0x1C3D
3402 ]
3403];
3404const VP40_AC_CAT2_BITS: [[u8; 32]; 16] = [
3405 [
3406 5, 7, 8, 9, 12, 13, 13, 5, 7, 3, 3, 4, 4, 4, 4, 5,
3407 6, 5, 6, 7, 10, 12, 12, 3, 5, 5, 6, 6, 5, 6, 5, 6
3408 ], [
3409 5, 7, 8, 9, 11, 12, 12, 5, 7, 3, 3, 4, 4, 4, 5, 5,
3410 6, 6, 6, 7, 11, 12, 12, 3, 4, 5, 6, 6, 5, 5, 5, 6
3411 ], [
3412 4, 7, 8, 9, 11, 13, 14, 5, 7, 3, 3, 4, 4, 4, 5, 6,
3413 7, 7, 7, 10, 14, 13, 13, 3, 4, 5, 5, 6, 5, 5, 5, 6
3414 ], [
3415 4, 6, 8, 8, 10, 12, 13, 6, 7, 3, 3, 4, 4, 4, 5, 6,
3416 7, 8, 9, 12, 13, 13, 13, 3, 4, 5, 6, 6, 4, 5, 5, 6
3417 ], [
3418 4, 6, 8, 8, 10, 14, 14, 6, 7, 3, 3, 4, 4, 5, 6, 7,
3419 8, 9, 11, 14, 14, 13, 13, 3, 4, 5, 5, 5, 4, 4, 5, 6
3420 ], [
3421 4, 5, 7, 7, 9, 13, 13, 6, 7, 3, 3, 4, 4, 5, 6, 8,
3422 10, 12, 13, 13, 13, 14, 14, 3, 4, 5, 5, 6, 4, 4, 5, 6
3423 ], [
3424 3, 5, 6, 6, 8, 11, 13, 6, 7, 3, 3, 4, 4, 6, 9, 11,
3425 13, 13, 13, 13, 13, 13, 13, 3, 5, 5, 5, 6, 4, 4, 6, 6
3426 ], [
3427 3, 4, 5, 4, 6, 8, 10, 7, 8, 3, 3, 5, 5, 8, 13, 14,
3428 14, 13, 13, 13, 13, 13, 13, 3, 5, 5, 5, 6, 4, 4, 7, 9
3429 ], [
3430 4, 7, 8, 9, 13, 13, 13, 6, 6, 3, 3, 4, 4, 5, 6, 7,
3431 8, 8, 10, 12, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 5, 6
3432 ], [
3433 4, 6, 8, 8, 13, 14, 14, 6, 6, 3, 3, 4, 4, 5, 6, 8,
3434 9, 10, 11, 14, 14, 14, 14, 3, 4, 5, 5, 5, 4, 4, 5, 6
3435 ], [
3436 4, 6, 7, 7, 11, 14, 14, 6, 6, 3, 3, 4, 5, 5, 7, 8,
3437 9, 10, 13, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 5, 6
3438 ], [
3439 3, 5, 7, 7, 11, 13, 14, 6, 6, 3, 3, 5, 5, 6, 8, 9,
3440 11, 11, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3441 ], [
3442 3, 5, 6, 7, 9, 13, 13, 7, 6, 3, 3, 5, 5, 6, 8, 10,
3443 12, 13, 13, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3444 ], [
3445 3, 4, 5, 6, 9, 12, 14, 7, 6, 3, 3, 5, 5, 7, 10, 12,
3446 14, 14, 14, 14, 14, 14, 14, 4, 4, 5, 5, 5, 4, 3, 7, 8
3447 ], [
3448 3, 4, 5, 4, 7, 10, 13, 7, 7, 3, 3, 5, 5, 9, 12, 14,
3449 14, 14, 14, 14, 14, 13, 13, 4, 5, 5, 5, 5, 4, 3, 9, 9
3450 ], [
3451 3, 4, 5, 4, 5, 8, 14, 10, 9, 2, 2, 7, 7, 13, 14, 14,
3452 14, 14, 14, 14, 14, 14, 14, 6, 7, 6, 6, 6, 5, 4, 13, 13
3453 ]
3454];
3455const VP40_AC_CAT3_CODES: [[u32; 32]; 16] = [
3456 [
3457 0x0007, 0x000F, 0x00BB, 0x00BA, 0x05CF, 0x173A, 0x2E77, 0x0029,
3458 0x0172, 0x0007, 0x0006, 0x0009, 0x0008, 0x0001, 0x0005, 0x000D,
3459 0x001D, 0x001C, 0x00B8, 0x02E6, 0x2E76, 0x1739, 0x1738, 0x0002,
3460 0x0006, 0x0016, 0x0004, 0x0028, 0x0015, 0x000C, 0x0000, 0x002F
3461 ], [
3462 0x000B, 0x0002, 0x0054, 0x002F, 0x02AC, 0x156B, 0x1568, 0x0016,
3463 0x0154, 0x0007, 0x0006, 0x0004, 0x0003, 0x0013, 0x0028, 0x002E,
3464 0x0157, 0x0155, 0x055B, 0x2AD3, 0x2AD2, 0x2AD5, 0x2AD4, 0x0003,
3465 0x0008, 0x0000, 0x000A, 0x0003, 0x0002, 0x002B, 0x0012, 0x0029
3466 ], [
3467 0x000F, 0x0007, 0x0001, 0x0000, 0x01C4, 0x0703, 0x0E02, 0x0011,
3468 0x00E1, 0x0005, 0x0006, 0x0002, 0x0001, 0x0009, 0x0010, 0x00E3,
3469 0x01C5, 0x01C1, 0x0702, 0x1C07, 0x1C06, 0x0E01, 0x0E00, 0x0004,
3470 0x0007, 0x001D, 0x000D, 0x0001, 0x0005, 0x0006, 0x000C, 0x0039
3471 ], [
3472 0x0001, 0x001C, 0x0011, 0x0013, 0x0042, 0x0207, 0x0815, 0x0075,
3473 0x0041, 0x0005, 0x0006, 0x0000, 0x001F, 0x003B, 0x0074, 0x0043,
3474 0x0080, 0x0206, 0x0814, 0x0817, 0x0816, 0x0409, 0x0408, 0x0003,
3475 0x0009, 0x001E, 0x0011, 0x0003, 0x0005, 0x0010, 0x0002, 0x0012
3476 ], [
3477 0x0001, 0x001F, 0x0027, 0x0001, 0x004B, 0x0123, 0x0915, 0x0000,
3478 0x0049, 0x0005, 0x0006, 0x001D, 0x001C, 0x0013, 0x004A, 0x0090,
3479 0x0914, 0x0917, 0x0916, 0x0911, 0x0910, 0x0913, 0x0912, 0x0003,
3480 0x0005, 0x0001, 0x0012, 0x0008, 0x0008, 0x001E, 0x0026, 0x0001
3481 ], [
3482 0x0003, 0x0001, 0x003F, 0x000B, 0x004E, 0x0132, 0x099A, 0x004F,
3483 0x0098, 0x0006, 0x0005, 0x001D, 0x001C, 0x007C, 0x0267, 0x1331,
3484 0x1330, 0x1333, 0x1332, 0x266D, 0x266C, 0x266F, 0x266E, 0x0001,
3485 0x0004, 0x001E, 0x0012, 0x000A, 0x0008, 0x0000, 0x007D, 0x004D
3486 ], [
3487 0x0002, 0x0007, 0x0015, 0x0003, 0x0004, 0x00A7, 0x0536, 0x0028,
3488 0x029A, 0x0006, 0x0004, 0x001C, 0x0017, 0x00A4, 0x29BE, 0x537F,
3489 0x537E, 0x29B9, 0x29B8, 0x29BB, 0x29BA, 0x29BD, 0x29BC, 0x000F,
3490 0x0000, 0x0005, 0x0016, 0x001D, 0x0006, 0x0001, 0x00A5, 0x014C
3491 ], [
3492 0x0004, 0x0007, 0x001A, 0x000C, 0x0006, 0x0029, 0x01BD, 0x1BE3,
3493 0x1BE0, 0x0000, 0x0007, 0x006E, 0x01BC, 0x37C3, 0x37C2, 0x37CD,
3494 0x37CC, 0x37CF, 0x37CE, 0x37C9, 0x37C8, 0x37CB, 0x37CA, 0x0015,
3495 0x01BF, 0x037D, 0x0036, 0x0002, 0x000B, 0x0028, 0x37C5, 0x37C4
3496 ], [
3497 0x0001, 0x0009, 0x0003, 0x0002, 0x011F, 0x08E9, 0x08E8, 0x002D,
3498 0x0022, 0x0006, 0x0007, 0x0010, 0x0011, 0x0017, 0x002C, 0x0046,
3499 0x011E, 0x011C, 0x0477, 0x08EB, 0x08EA, 0x08ED, 0x08EC, 0x0003,
3500 0x000B, 0x0001, 0x0014, 0x000A, 0x0009, 0x0015, 0x0000, 0x0010
3501 ], [
3502 0x0001, 0x001D, 0x0022, 0x0013, 0x011E, 0x08FC, 0x23F5, 0x0023,
3503 0x0022, 0x0005, 0x0006, 0x0010, 0x000B, 0x0010, 0x008E, 0x023E,
3504 0x08FF, 0x11FD, 0x23F4, 0x23F7, 0x23F6, 0x23F9, 0x23F8, 0x0003,
3505 0x0009, 0x0000, 0x001C, 0x000A, 0x000F, 0x0001, 0x0012, 0x0046
3506 ], [
3507 0x0003, 0x001F, 0x003C, 0x003D, 0x0086, 0x0877, 0x10E8, 0x0041,
3508 0x0040, 0x0005, 0x0006, 0x0007, 0x0006, 0x0004, 0x010F, 0x021C,
3509 0x0875, 0x21D3, 0x21D2, 0x21D9, 0x21D8, 0x21DB, 0x21DA, 0x0002,
3510 0x0009, 0x0000, 0x0011, 0x0003, 0x000E, 0x0002, 0x0005, 0x0042
3511 ], [
3512 0x0004, 0x0001, 0x003D, 0x0009, 0x00F3, 0x0793, 0x1E45, 0x0000,
3513 0x0002, 0x0005, 0x0006, 0x0008, 0x0001, 0x0003, 0x01E5, 0x0792,
3514 0x1E44, 0x1E47, 0x1E46, 0x1E41, 0x1E40, 0x1E43, 0x1E42, 0x0001,
3515 0x0006, 0x001F, 0x000F, 0x000E, 0x000E, 0x0005, 0x0078, 0x0001
3516 ], [
3517 0x0004, 0x0005, 0x000E, 0x0017, 0x003E, 0x00F0, 0x0F1E, 0x007A,
3518 0x007F, 0x0006, 0x0007, 0x0005, 0x0004, 0x007B, 0x01E2, 0x1E3F,
3519 0x1E3E, 0x0F19, 0x0F18, 0x0F1B, 0x0F1A, 0x0F1D, 0x0F1C, 0x0000,
3520 0x0003, 0x0016, 0x0009, 0x0008, 0x000A, 0x0006, 0x007E, 0x0079
3521 ], [
3522 0x0005, 0x000C, 0x001A, 0x0004, 0x001A, 0x00DE, 0x0DF4, 0x00DD,
3523 0x006D, 0x0000, 0x0007, 0x0025, 0x0024, 0x00DC, 0x0DF7, 0x1BEB,
3524 0x1BEA, 0x0DF1, 0x0DF0, 0x0DF3, 0x0DF2, 0x1BED, 0x1BEC, 0x0008,
3525 0x0013, 0x000C, 0x0037, 0x0036, 0x0005, 0x0007, 0x006C, 0x01BF
3526 ], [
3527 0x0005, 0x000D, 0x001F, 0x000C, 0x003B, 0x0040, 0x041A, 0x0104,
3528 0x0107, 0x0001, 0x0000, 0x0024, 0x0021, 0x020B, 0x106E, 0x20DF,
3529 0x20DE, 0x1055, 0x1054, 0x1057, 0x1056, 0x106D, 0x106C, 0x0011,
3530 0x003A, 0x0025, 0x0038, 0x0039, 0x0013, 0x001E, 0x020C, 0x0414
3531 ], [
3532 0x0000, 0x0007, 0x000D, 0x0005, 0x0009, 0x0022, 0x0CD1, 0x0CD0,
3533 0x0CD3, 0x0003, 0x0002, 0x008D, 0x00CC, 0x066B, 0x0CD2, 0x19B5,
3534 0x19B4, 0x19B7, 0x19B6, 0x19B1, 0x19B0, 0x19B3, 0x19B2, 0x0047,
3535 0x008C, 0x0337, 0x0067, 0x0018, 0x0010, 0x0032, 0x0CD5, 0x0CD4
3536 ]
3537];
3538const VP40_AC_CAT3_BITS: [[u8; 32]; 16] = [
3539 [
3540 4, 6, 8, 8, 11, 13, 14, 6, 9, 3, 3, 4, 4, 4, 5, 6,
3541 7, 7, 8, 10, 14, 13, 13, 3, 4, 5, 5, 6, 5, 6, 4, 6
3542 ], [
3543 4, 5, 7, 7, 10, 13, 13, 6, 9, 3, 3, 4, 4, 5, 6, 7,
3544 9, 9, 11, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 6, 5, 6
3545 ], [
3546 4, 5, 6, 6, 9, 11, 12, 6, 8, 3, 3, 4, 4, 5, 6, 8,
3547 9, 9, 11, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6
3548 ], [
3549 3, 5, 6, 6, 8, 11, 13, 7, 8, 3, 3, 4, 5, 6, 7, 8,
3550 9, 11, 13, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6
3551 ], [
3552 3, 5, 6, 5, 8, 10, 13, 6, 8, 3, 3, 5, 5, 6, 8, 9,
3553 13, 13, 13, 13, 13, 13, 13, 3, 4, 4, 5, 5, 4, 5, 6, 6
3554 ], [
3555 3, 4, 6, 5, 7, 9, 12, 7, 8, 3, 3, 5, 5, 7, 10, 13,
3556 13, 13, 13, 14, 14, 14, 14, 3, 4, 5, 5, 5, 4, 4, 7, 7
3557 ], [
3558 3, 4, 5, 4, 5, 8, 11, 6, 10, 3, 3, 5, 5, 8, 14, 15,
3559 15, 14, 14, 14, 14, 14, 14, 4, 4, 5, 5, 5, 4, 4, 8, 9
3560 ], [
3561 3, 4, 5, 4, 4, 6, 9, 13, 13, 2, 3, 7, 9, 14, 14, 14,
3562 14, 14, 14, 14, 14, 14, 14, 5, 9, 10, 6, 3, 4, 6, 14, 14
3563 ], [
3564 3, 5, 6, 6, 10, 13, 13, 7, 7, 3, 3, 5, 5, 6, 7, 8,
3565 10, 10, 12, 13, 13, 13, 13, 3, 4, 4, 5, 5, 4, 5, 5, 6
3566 ], [
3567 3, 5, 6, 6, 9, 12, 14, 7, 7, 3, 3, 5, 5, 6, 8, 10,
3568 12, 13, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3569 ], [
3570 3, 5, 6, 6, 8, 12, 13, 7, 7, 3, 3, 5, 5, 6, 9, 10,
3571 12, 14, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3572 ], [
3573 3, 4, 6, 5, 8, 11, 13, 7, 7, 3, 3, 5, 5, 7, 9, 11,
3574 13, 13, 13, 13, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 7, 7
3575 ], [
3576 3, 4, 5, 5, 7, 9, 13, 8, 8, 3, 3, 5, 5, 8, 10, 14,
3577 14, 13, 13, 13, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 8, 8
3578 ], [
3579 3, 4, 5, 4, 6, 9, 13, 9, 8, 2, 3, 6, 6, 9, 13, 14,
3580 14, 13, 13, 13, 13, 14, 14, 4, 5, 5, 6, 6, 4, 4, 8, 10
3581 ], [
3582 3, 4, 5, 4, 6, 7, 11, 9, 9, 2, 2, 6, 6, 10, 13, 14,
3583 14, 13, 13, 13, 13, 13, 13, 5, 6, 6, 6, 6, 5, 5, 10, 11
3584 ], [
3585 2, 4, 5, 4, 5, 7, 13, 13, 13, 2, 2, 9, 9, 12, 13, 14,
3586 14, 14, 14, 14, 14, 14, 14, 8, 9, 11, 8, 6, 6, 7, 13, 13
3587 ]
3588];
3589
3590const VP40_QMAT: &[i16; 64] = &[
3591 16, 17, 18, 20, 22, 24, 26, 28,
3592 17, 18, 20, 22, 24, 26, 28, 32,
3593 18, 20, 22, 24, 26, 28, 32, 36,
3594 20, 22, 24, 26, 28, 32, 36, 40,
3595 22, 24, 26, 28, 32, 36, 40, 44,
3596 24, 26, 28, 32, 36, 40, 44, 48,
3597 26, 28, 32, 36, 40, 44, 48, 52,
3598 28, 32, 36, 40, 44, 48, 52, 56
3599];
3600const VP40_DC_Y_SCALES: [i16; 64] = [
3601 180, 180, 180, 180, 180, 180, 175, 170,
3602 165, 160, 157, 155, 152, 150, 147, 145,
3603 142, 140, 137, 135, 132, 130, 127, 125,
3604 122, 120, 117, 115, 112, 110, 107, 105,
3605 102, 100, 97, 95, 92, 90, 87, 85,
3606 82, 80, 77, 75, 72, 70, 67, 65,
3607 62, 60, 57, 55, 52, 50, 47, 45,
3608 42, 40, 37, 35, 32, 30, 27, 25
3609];
3610const VP40_DC_C_SCALES: [i16; 64] = [
3611 150, 150, 150, 150, 150, 150, 150, 150,
3612 150, 150, 150, 150, 150, 150, 147, 145,
3613 142, 140, 137, 135, 132, 130, 127, 125,
3614 122, 120, 117, 115, 112, 110, 107, 105,
3615 102, 100, 97, 95, 92, 90, 87, 85,
3616 82, 80, 77, 75, 72, 70, 67, 65,
3617 62, 60, 57, 55, 52, 50, 47, 45,
3618 42, 40, 37, 35, 32, 30, 27, 25
3619];
3620const VP40_AC_SCALES: [i16; 64] = [
3621 500, 475, 450, 430, 410, 390, 370, 350,
3622 330, 315, 300, 285, 270, 260, 250, 240,
3623 230, 220, 210, 200, 190, 185, 180, 170,
3624 160, 150, 143, 135, 128, 120, 113, 106,
3625 100, 94, 90, 85, 80, 75, 70, 66,
3626 62, 57, 52, 49, 45, 41, 38, 35,
3627 33, 30, 27, 24, 22, 20, 18, 16,
3628 14, 12, 10, 9, 7, 6, 4, 1
3629];
3630
3631const VP40_MBPAT_CODES: [[u8; 14]; 2] = [
3632 [ 0b000, 0b1111, 0b1001, 0b010, 0b1101, 0b01110, 0b1011, 0b001, 0b01111, 0b1000, 0b0110, 0b1110, 0b1100, 0b1010 ],
3633 [ 0b0111, 0b1010, 0b1001, 0b1100, 0b1000, 0b01101, 0b000, 0b1110, 0b01100, 0b1101, 0b001, 0b1011, 0b1111, 0b010 ]
3634];
3635const VP40_MBPAT_BITS: [[u8; 14]; 2] = [
3636 [ 3, 4, 4, 3, 4, 5, 4, 3, 5, 4, 4, 4, 4, 4 ],
3637 [ 4, 4, 4, 4, 4, 5, 3, 4, 5, 4, 3, 4, 4, 3 ]
3638];
3639const VP40_BP_PREDICTOR: [u8; 15] = [ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1 ];
3640const VP40_MV_X_CODES: [[u32; 63]; 7] = [
3641 [
3642 0x06A, 0x11A, 0x18E, 0x237, 0x04A, 0x236, 0x07A, 0x0D6,
3643 0x07E, 0x1FD, 0x08C, 0x0D7, 0x087, 0x183, 0x03C, 0x061,
3644 0x047, 0x069, 0x040, 0x048, 0x049, 0x086, 0x013, 0x0D2,
3645 0x01C, 0x042, 0x025, 0x01B, 0x013, 0x005, 0x000, 0x007,
3646 0x005, 0x01B, 0x019, 0x019, 0x008, 0x045, 0x01D, 0x0C6,
3647 0x068, 0x090, 0x041, 0x04B, 0x031, 0x18F, 0x062, 0x03E,
3648 0x044, 0x068, 0x030, 0x182, 0x0C0, 0x1A7, 0x091, 0x092,
3649 0x07B, 0x0FF, 0x1A6, 0x1FC, 0x06A, 0x093, 0x06B
3650 ], [
3651 0x039, 0x259, 0x01B, 0x1D1, 0x137, 0x1D0, 0x01A, 0x1B5,
3652 0x01D, 0x4BC, 0x06C, 0x038, 0x071, 0x02D, 0x07D, 0x075,
3653 0x019, 0x0E9, 0x037, 0x015, 0x01E, 0x0DB, 0x04C, 0x070,
3654 0x00D, 0x00C, 0x027, 0x004, 0x002, 0x000, 0x005, 0x007,
3655 0x006, 0x002, 0x008, 0x024, 0x00C, 0x03B, 0x01E, 0x09A,
3656 0x00E, 0x069, 0x04A, 0x12D, 0x035, 0x0F9, 0x018, 0x07F,
3657 0x00F, 0x0F8, 0x07E, 0x25F, 0x068, 0x02C, 0x014, 0x258,
3658 0x136, 0x4BD, 0x12E, 0x1B4, 0x017, 0x039, 0x01F
3659 ], [
3660 0x029, 0x3CB, 0x1F5, 0x263, 0x1F4, 0x3DA, 0x050, 0x260,
3661 0x1EC, 0x3D3, 0x109, 0x3D2, 0x051, 0x792, 0x0F3, 0x09A,
3662 0x0F7, 0x132, 0x0C1, 0x1E8, 0x02A, 0x085, 0x061, 0x1F7,
3663 0x078, 0x0C7, 0x023, 0x07C, 0x012, 0x00B, 0x00E, 0x00D,
3664 0x000, 0x005, 0x003, 0x004, 0x019, 0x020, 0x03F, 0x043,
3665 0x062, 0x09F, 0x04E, 0x181, 0x02B, 0x137, 0x0F5, 0x089,
3666 0x0C6, 0x262, 0x088, 0x3C8, 0x1F6, 0x3CA, 0x09E, 0x261,
3667 0x136, 0x108, 0x133, 0x793, 0x180, 0x3DB, 0x045
3668 ], [
3669 0x001, 0x1C7, 0x067, 0x0B5, 0x066, 0x139, 0x099, 0x0B4,
3670 0x0C3, 0x130, 0x000, 0x131, 0x09E, 0x0B7, 0x02C, 0x001,
3671 0x028, 0x138, 0x04B, 0x031, 0x060, 0x091, 0x003, 0x09D,
3672 0x017, 0x04D, 0x031, 0x070, 0x007, 0x03A, 0x007, 0x002,
3673 0x00B, 0x001, 0x00F, 0x008, 0x00D, 0x004, 0x00A, 0x00D,
3674 0x019, 0x002, 0x03B, 0x04A, 0x015, 0x0C2, 0x018, 0x032,
3675 0x072, 0x1C6, 0x029, 0x1C5, 0x049, 0x121, 0x01B, 0x030,
3676 0x01A, 0x1C4, 0x09F, 0x0B6, 0x019, 0x120, 0x073
3677 ], [
3678 0x023, 0x1C8, 0x043, 0x110, 0x00C, 0x153, 0x022, 0x111,
3679 0x00F, 0x042, 0x023, 0x1C9, 0x02A, 0x01B, 0x073, 0x045,
3680 0x06E, 0x089, 0x06C, 0x01A, 0x06F, 0x0B6, 0x00B, 0x0E5,
3681 0x025, 0x020, 0x029, 0x04D, 0x002, 0x014, 0x01A, 0x017,
3682 0x01E, 0x027, 0x018, 0x028, 0x01F, 0x000, 0x006, 0x010,
3683 0x007, 0x00B, 0x003, 0x004, 0x01D, 0x02C, 0x019, 0x02B,
3684 0x009, 0x055, 0x038, 0x00E, 0x024, 0x0A8, 0x00A, 0x099,
3685 0x05A, 0x098, 0x06D, 0x152, 0x02B, 0x0B7, 0x001
3686 ], [
3687 0x03D, 0x0B1, 0x0DD, 0x1F6, 0x0C5, 0x188, 0x037, 0x03F,
3688 0x01E, 0x189, 0x00F, 0x03E, 0x06A, 0x1F7, 0x061, 0x079,
3689 0x018, 0x0B0, 0x00E, 0x0B3, 0x00C, 0x0DF, 0x006, 0x0DC,
3690 0x019, 0x0DE, 0x027, 0x00E, 0x01A, 0x063, 0x00F, 0x00E,
3691 0x014, 0x07C, 0x036, 0x06B, 0x03F, 0x060, 0x008, 0x074,
3692 0x009, 0x078, 0x012, 0x00D, 0x015, 0x02D, 0x002, 0x01C,
3693 0x005, 0x03B, 0x000, 0x034, 0x019, 0x026, 0x010, 0x075,
3694 0x002, 0x036, 0x023, 0x0B2, 0x022, 0x0FA, 0x017
3695 ], [
3696 0x015, 0x0DD, 0x03E, 0x16E, 0x04C, 0x012, 0x05D, 0x0B6,
3697 0x06F, 0x1F1, 0x069, 0x1F0, 0x01D, 0x16F, 0x002, 0x06B,
3698 0x00C, 0x0DC, 0x068, 0x09B, 0x07D, 0x09A, 0x00D, 0x013,
3699 0x008, 0x0F9, 0x02C, 0x012, 0x033, 0x04F, 0x00D, 0x005,
3700 0x012, 0x03F, 0x032, 0x013, 0x03B, 0x005, 0x02F, 0x05A,
3701 0x03F, 0x01C, 0x03A, 0x008, 0x036, 0x05C, 0x010, 0x000,
3702 0x00C, 0x04E, 0x003, 0x06A, 0x00E, 0x003, 0x014, 0x01E,
3703 0x01C, 0x00F, 0x018, 0x023, 0x01E, 0x022, 0x002
3704 ]
3705];
3706const VP40_MV_X_BITS: [[u8; 63]; 7] = [
3707 [
3708 7, 9, 9, 10, 8, 10, 8, 9, 8, 10, 8, 9, 8, 9, 7, 7,
3709 7, 8, 7, 8, 7, 8, 6, 8, 6, 7, 6, 6, 5, 4, 2, 3,
3710 3, 5, 5, 6, 5, 7, 6, 8, 7, 8, 7, 8, 7, 9, 7, 7,
3711 7, 8, 7, 9, 8, 9, 8, 9, 8, 9, 9, 10, 8, 9, 7
3712 ], [
3713 7, 10, 8, 10, 9, 10, 8, 10, 8, 11, 8, 9, 8, 9, 8, 8,
3714 7, 9, 7, 8, 7, 9, 7, 8, 6, 7, 6, 6, 4, 4, 3, 3,
3715 3, 3, 4, 6, 5, 7, 6, 8, 6, 8, 7, 9, 7, 9, 7, 8,
3716 7, 9, 8, 10, 8, 9, 8, 10, 9, 11, 9, 10, 8, 9, 7
3717 ], [
3718 7, 10, 9, 10, 9, 10, 8, 10, 9, 10, 9, 10, 8, 11, 8, 8,
3719 8, 9, 8, 9, 7, 8, 7, 9, 7, 8, 6, 7, 5, 5, 4, 4,
3720 2, 3, 3, 4, 5, 6, 6, 7, 7, 8, 7, 9, 7, 9, 8, 8,
3721 8, 10, 8, 10, 9, 10, 8, 10, 9, 9, 9, 11, 9, 10, 7
3722 ], [
3723 6, 9, 8, 9, 8, 9, 8, 9, 8, 9, 7, 9, 8, 9, 7, 7,
3724 7, 9, 7, 8, 7, 8, 6, 8, 6, 7, 6, 7, 5, 6, 4, 4,
3725 4, 4, 4, 4, 4, 4, 4, 5, 5, 6, 6, 7, 6, 8, 6, 7,
3726 7, 9, 7, 9, 7, 9, 7, 8, 7, 9, 8, 9, 7, 9, 7
3727 ], [
3728 6, 9, 8, 9, 7, 9, 7, 9, 7, 8, 7, 9, 7, 8, 7, 7,
3729 7, 8, 7, 8, 7, 8, 6, 8, 6, 7, 6, 7, 5, 6, 5, 5,
3730 5, 6, 5, 6, 5, 5, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6,
3731 5, 7, 6, 7, 6, 8, 6, 8, 7, 8, 7, 9, 7, 8, 5
3732 ], [
3733 6, 8, 8, 9, 8, 9, 7, 8, 7, 9, 7, 8, 7, 9, 7, 7,
3734 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 7, 6, 7, 5, 5,
3735 5, 7, 6, 7, 6, 7, 5, 7, 5, 7, 5, 6, 5, 6, 4, 5,
3736 4, 6, 4, 6, 5, 6, 5, 7, 5, 7, 6, 8, 6, 8, 5
3737 ], [
3738 5, 8, 7, 9, 7, 8, 7, 8, 7, 9, 7, 9, 7, 9, 6, 7,
3739 6, 8, 7, 8, 7, 8, 6, 8, 6, 8, 6, 7, 6, 7, 5, 5,
3740 5, 7, 6, 7, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 5, 5,
3741 5, 7, 5, 7, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 3
3742 ]
3743];
3744const VP40_MV_Y_CODES: [[u32; 63]; 7] = [
3745 [
3746 0x052, 0x14C, 0x1FA, 0x124, 0x082, 0x29E, 0x08E, 0x24B,
3747 0x09C, 0x3F7, 0x086, 0x114, 0x083, 0x3A5, 0x0FA, 0x04F,
3748 0x0FB, 0x13B, 0x0FC, 0x172, 0x044, 0x173, 0x051, 0x087,
3749 0x05F, 0x0BA, 0x026, 0x05E, 0x016, 0x015, 0x006, 0x001,
3750 0x000, 0x01C, 0x01E, 0x075, 0x03B, 0x0FF, 0x025, 0x0BB,
3751 0x07C, 0x08B, 0x048, 0x171, 0x042, 0x14E, 0x046, 0x0FE,
3752 0x040, 0x13A, 0x093, 0x115, 0x08F, 0x3F6, 0x170, 0x29F,
3753 0x1D1, 0x24A, 0x1D3, 0x3A4, 0x1D0, 0x14D, 0x050
3754 ], [
3755 0x0DE, 0x223, 0x136, 0x7C5, 0x12F, 0x4A1, 0x3D7, 0x7AC,
3756 0x133, 0x7C4, 0x1B8, 0x222, 0x096, 0x251, 0x095, 0x1F0,
3757 0x0DA, 0x110, 0x09A, 0x360, 0x0DD, 0x12E, 0x048, 0x092,
3758 0x078, 0x098, 0x027, 0x045, 0x01A, 0x010, 0x005, 0x000,
3759 0x001, 0x00E, 0x00C, 0x023, 0x03F, 0x0F4, 0x07D, 0x089,
3760 0x07B, 0x1BE, 0x0F9, 0x3E3, 0x0F3, 0x127, 0x0DB, 0x1EA,
3761 0x0D9, 0x6E7, 0x1BF, 0x4A0, 0x1B1, 0x6E6, 0x137, 0x7AD,
3762 0x126, 0x6C2, 0x132, 0x6C3, 0x129, 0x372, 0x0F2
3763 ], [
3764 0x016, 0x09C, 0x13C, 0x09E, 0x12B, 0x0BA, 0x181, 0x317,
3765 0x084, 0x04E, 0x026, 0x316, 0x180, 0x05C, 0x0C1, 0x02F,
3766 0x010, 0x045, 0x012, 0x189, 0x024, 0x13D, 0x066, 0x023,
3767 0x067, 0x0C6, 0x024, 0x04B, 0x011, 0x032, 0x00D, 0x000,
3768 0x007, 0x005, 0x003, 0x003, 0x005, 0x020, 0x008, 0x025,
3769 0x026, 0x04F, 0x061, 0x02B, 0x04E, 0x18A, 0x043, 0x09F,
3770 0x014, 0x254, 0x094, 0x310, 0x085, 0x311, 0x02A, 0x0BB,
3771 0x18F, 0x255, 0x09D, 0x09F, 0x18E, 0x044, 0x026
3772 ], [
3773 0x061, 0x12A, 0x00D, 0x3BD, 0x089, 0x109, 0x18E, 0x210,
3774 0x1D3, 0x211, 0x088, 0x019, 0x085, 0x018, 0x0E8, 0x0CE,
3775 0x040, 0x119, 0x045, 0x1D2, 0x04B, 0x1DD, 0x062, 0x094,
3776 0x075, 0x00C, 0x027, 0x00D, 0x002, 0x026, 0x006, 0x01E,
3777 0x00D, 0x01F, 0x001, 0x00A, 0x002, 0x007, 0x00B, 0x000,
3778 0x01C, 0x076, 0x032, 0x007, 0x024, 0x0C0, 0x007, 0x041,
3779 0x002, 0x18F, 0x047, 0x1DC, 0x043, 0x12B, 0x0CF, 0x118,
3780 0x0C6, 0x3BC, 0x08D, 0x3BF, 0x0C1, 0x3BE, 0x066
3781 ], [
3782 0x007, 0x14D, 0x0A0, 0x09E, 0x0CF, 0x39C, 0x0A1, 0x39D,
3783 0x0AB, 0x1C5, 0x026, 0x14C, 0x025, 0x19C, 0x03F, 0x0E1,
3784 0x066, 0x1CF, 0x03E, 0x1C4, 0x072, 0x04E, 0x006, 0x0AA,
3785 0x01C, 0x0E6, 0x032, 0x051, 0x03B, 0x005, 0x01F, 0x018,
3786 0x002, 0x03A, 0x000, 0x036, 0x005, 0x008, 0x008, 0x016,
3787 0x009, 0x00D, 0x003, 0x02F, 0x01E, 0x02E, 0x01A, 0x02B,
3788 0x00C, 0x024, 0x01E, 0x0E0, 0x004, 0x0A7, 0x054, 0x1C7,
3789 0x052, 0x19D, 0x03A, 0x09F, 0x03B, 0x1C6, 0x037
3790 ], [
3791 0x02A, 0x039, 0x025, 0x115, 0x024, 0x1FA, 0x02F, 0x114,
3792 0x075, 0x038, 0x0FC, 0x036, 0x01E, 0x1FB, 0x07F, 0x068,
3793 0x016, 0x037, 0x01F, 0x05C, 0x013, 0x08B, 0x001, 0x0FB,
3794 0x021, 0x044, 0x02B, 0x06B, 0x03B, 0x00C, 0x01C, 0x019,
3795 0x001, 0x020, 0x016, 0x07C, 0x00C, 0x074, 0x00A, 0x01C,
3796 0x012, 0x069, 0x00F, 0x06A, 0x014, 0x011, 0x01E, 0x017,
3797 0x002, 0x031, 0x01B, 0x030, 0x00D, 0x000, 0x001, 0x01D,
3798 0x023, 0x01A, 0x01D, 0x05D, 0x010, 0x0FA, 0x013
3799 ], [
3800 0x012, 0x026, 0x041, 0x022, 0x01A, 0x0A9, 0x04C, 0x1B2,
3801 0x05C, 0x0A8, 0x058, 0x1B3, 0x040, 0x079, 0x00C, 0x055,
3802 0x01F, 0x0D8, 0x076, 0x023, 0x05F, 0x078, 0x00B, 0x01B,
3803 0x02D, 0x010, 0x037, 0x06D, 0x032, 0x00A, 0x01A, 0x01E,
3804 0x01F, 0x02B, 0x00D, 0x077, 0x031, 0x05D, 0x038, 0x027,
3805 0x00C, 0x0E9, 0x033, 0x05E, 0x030, 0x04D, 0x00A, 0x021,
3806 0x007, 0x03D, 0x039, 0x0E8, 0x00B, 0x059, 0x014, 0x027,
3807 0x011, 0x075, 0x00E, 0x009, 0x008, 0x012, 0x000
3808 ]
3809];
3810const VP40_MV_Y_BITS: [[u8; 63]; 7] = [
3811 [
3812 7, 9, 9, 9, 8, 10, 8, 10, 8, 10, 8, 9, 8, 10, 8, 7,
3813 8, 9, 8, 9, 7, 9, 7, 8, 7, 8, 6, 7, 5, 5, 3, 2,
3814 2, 5, 5, 7, 6, 8, 6, 8, 7, 8, 7, 9, 7, 9, 7, 8,
3815 7, 9, 8, 9, 8, 10, 9, 10, 9, 10, 9, 10, 9, 9, 7
3816 ], [
3817 8, 10, 9, 11, 9, 11, 10, 11, 9, 11, 9, 10, 8, 10, 8, 9,
3818 8, 9, 8, 10, 8, 9, 7, 8, 7, 8, 6, 7, 5, 5, 3, 2,
3819 2, 4, 4, 6, 6, 8, 7, 8, 7, 9, 8, 10, 8, 9, 8, 9,
3820 8, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 10, 8
3821 ], [
3822 7, 9, 9, 10, 9, 10, 9, 10, 8, 9, 8, 10, 9, 9, 8, 8,
3823 7, 9, 7, 9, 7, 9, 7, 8, 7, 8, 6, 7, 5, 6, 4, 3,
3824 3, 3, 3, 4, 4, 6, 5, 7, 6, 8, 7, 8, 7, 9, 7, 8,
3825 7, 10, 8, 10, 8, 10, 8, 10, 9, 10, 9, 10, 9, 9, 7
3826 ], [
3827 7, 9, 8, 10, 8, 9, 9, 10, 9, 10, 8, 9, 8, 9, 8, 8,
3828 7, 9, 7, 9, 7, 9, 7, 8, 7, 7, 6, 7, 5, 6, 4, 5,
3829 4, 5, 3, 4, 3, 4, 4, 5, 5, 7, 6, 7, 6, 8, 6, 7,
3830 6, 9, 7, 9, 7, 9, 8, 9, 8, 10, 8, 10, 8, 10, 7
3831 ], [
3832 6, 9, 8, 9, 8, 10, 8, 10, 8, 9, 7, 9, 7, 9, 7, 8,
3833 7, 9, 7, 9, 7, 8, 6, 8, 6, 8, 6, 7, 6, 6, 5, 5,
3834 4, 6, 4, 6, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6,
3835 5, 7, 6, 8, 6, 8, 7, 9, 7, 9, 7, 9, 7, 9, 6
3836 ], [
3837 6, 8, 7, 9, 7, 9, 7, 9, 7, 8, 8, 8, 7, 9, 7, 7,
3838 6, 8, 7, 8, 6, 8, 6, 8, 6, 7, 6, 7, 6, 6, 5, 5,
3839 4, 6, 5, 7, 5, 7, 5, 6, 5, 7, 5, 7, 5, 6, 5, 5,
3840 4, 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 8, 6, 8, 5
3841 ], [
3842 5, 7, 7, 8, 7, 8, 7, 9, 7, 8, 7, 9, 7, 8, 6, 7,
3843 6, 8, 7, 8, 7, 8, 6, 7, 6, 7, 6, 7, 6, 6, 5, 5,
3844 5, 6, 5, 7, 6, 7, 6, 7, 5, 8, 6, 7, 6, 7, 5, 6,
3845 5, 7, 6, 8, 5, 7, 5, 6, 5, 7, 5, 6, 5, 6, 3
3846 ]
3847];
3848
3849const VP40_LOOP_STRENGTH: [i16; 64] = [
3850 30, 25, 20, 20, 15, 15, 14, 14,
3851 13, 13, 12, 12, 11, 11, 10, 10,
3852 9, 9, 8, 8, 7, 7, 7, 7,
3853 6, 6, 6, 6, 5, 5, 5, 5,
3854 4, 4, 4, 4, 3, 3, 3, 3,
3855 2, 2, 2, 2, 2, 2, 2, 2,
3856 2, 2, 2, 2, 2, 2, 2, 2,
3857 1, 1, 1, 1, 1, 1, 1, 1
3858];
3859const VP40_MV_LUT_INDEX: [usize; 32] = [
3860 0, 1, 2, 2, 3, 3, 3, 3,
3861 4, 4, 4, 4, 4, 4, 4, 4,
3862 5, 5, 5, 5, 5, 5, 5, 5,
3863 6, 6, 6, 6, 6, 6, 6, 6
3864];