]> git.nihav.org Git - nihav.git/blob - nihav-duck/src/codecs/vp3.rs
remove trailing whitespaces
[nihav.git] / nihav-duck / src / codecs / vp3.rs
1 use std::mem;
2 use std::ptr;
3 use nihav_core::codecs::*;
4 use nihav_codec_support::codecs::{MV, ZERO_MV, ZIGZAG};
5 use nihav_codec_support::codecs::blockdsp::*;
6 use nihav_core::io::bitreader::*;
7 use nihav_core::io::codebook::*;
8 use nihav_core::io::intcode::*;
9 use super::vpcommon::*;
10
11 #[derive(Clone,Copy,Debug,PartialEq)]
12 enum SBState {
13 Coded,
14 Partial,
15 Uncoded,
16 }
17
18 fn map_idx(idx: usize) -> u8 {
19 idx as u8
20 }
21
22 struct 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
29 fn map_mbt(idx: usize) -> VPMBType {
30 VP30_MBTYPE_SYMS[idx]
31 }
32
33 impl 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
63 struct 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
71 impl 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
150 struct VP40AuxCodes {
151 mv_x_cb: [Codebook<i8>; 7],
152 mv_y_cb: [Codebook<i8>; 7],
153 mbpat_cb: [Codebook<u8>; 2],
154 }
155
156 fn map_mv(idx: usize) -> i8 {
157 (idx as i8) - 31
158 }
159
160 impl 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)]
187 enum Codes {
188 None,
189 VP30(VP30Codes),
190 VP31(VP31Codes),
191 }
192
193 #[derive(Clone)]
194 struct Block {
195 btype: VPMBType,
196 coeffs: [i16; 64],
197 has_ac: bool,
198 idx: usize,
199 mv: MV,
200 coded: bool,
201 }
202
203 impl 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
216 type ReadRunFunc = fn (&mut BitReader) -> DecoderResult<usize>;
217
218 const VP31_LONG_RUN_BASE: [usize; 7] = [ 1, 2, 4, 6, 10, 18, 34 ];
219 const VP31_LONG_RUN_BITS: [u8; 7] = [ 0, 1, 1, 2, 3, 4, 12 ];
220 fn 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
226 const VP31_SHORT_RUN_BASE: [usize; 6] = [ 1, 3, 5, 7, 11, 15 ];
227 const VP31_SHORT_RUN_BITS: [u8; 6] = [ 1, 1, 1, 2, 2, 4 ];
228 fn 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
233 fn 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
246 struct BitRunDecoder {
247 value: bool,
248 run: usize,
249 read_run: ReadRunFunc,
250 }
251
252 impl 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
267 const VP30_NE0_BITS: [u8; 5] = [ 2, 2, 3, 4, 8 ];
268 const VP30_NE0_BASE: [usize; 5] = [ 1, 5, 9, 17, 33 ];
269 fn 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 }
273 fn 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 }
283 fn 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 */
299 const 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 ];
305 fn 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
324 struct 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
361 fn 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
377 fn 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
383 fn 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
418 fn 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
424 fn 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
433 fn 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
439 fn 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
446 fn 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
454 fn 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
562 macro_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
571 fn 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
576 fn 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
581 fn 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
590 impl 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
1818 impl 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
1884 impl 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
1890 pub fn get_decoder_vp3() -> Box<dyn NADecoder + Send> {
1891 Box::new(VP34Decoder::new(3))
1892 }
1893
1894 pub fn get_decoder_vp4() -> Box<dyn NADecoder + Send> {
1895 Box::new(VP34Decoder::new(4))
1896 }
1897
1898 #[cfg(test)]
1899 mod 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 test_decoding("avi", "vp3", "assets/Duck/vp30-logo.avi", Some(23), &dmx_reg, &dec_reg,
1914 ExpectedTestResult::MD5([0x51aba7df, 0x6e42534d, 0xef6c5b13, 0x26c38d1f]));
1915 }
1916
1917 #[test]
1918 fn test_vp31() {
1919 let mut dmx_reg = RegisteredDemuxers::new();
1920 generic_register_all_demuxers(&mut dmx_reg);
1921 let mut dec_reg = RegisteredDecoders::new();
1922 duck_register_all_decoders(&mut dec_reg);
1923
1924 // let file = "assets/Duck/vp31.avi";
1925 // let file = "assets/Duck/vp31_crash.avi";
1926 // let file = "assets/Duck/01-vp31-0500.avi";
1927 // test_file_decoding("avi", file, Some(3), true, false, None/*Some("vp31")*/, &dmx_reg, &dec_reg);
1928 //panic!("end");
1929 test_decoding("avi", "vp3", "assets/Duck/01-vp31-0500.avi", Some(16), &dmx_reg, &dec_reg,
1930 ExpectedTestResult::MD5([0x65112f7e, 0x2914f29b, 0x2908ed2f, 0xce5fc8c5]));
1931 }
1932
1933 #[test]
1934 fn test_vp4() {
1935 let mut dmx_reg = RegisteredDemuxers::new();
1936 generic_register_all_demuxers(&mut dmx_reg);
1937 let mut dec_reg = RegisteredDecoders::new();
1938 duck_register_all_decoders(&mut dec_reg);
1939
1940 test_decoding("avi", "vp3", "assets/Duck/ot171_vp40.avi", Some(86), &dmx_reg, &dec_reg,
1941 ExpectedTestResult::MD5([0xd41d8cd9, 0x8f00b204, 0xe9800998, 0xecf8427e]));
1942 }
1943 }
1944
1945 const HILBERT_ORDER: [[usize; 2]; 16] = [
1946 [ 0, 0 ], [ 1, 0 ], [ 1, 1 ], [ 0, 1 ],
1947 [ 0, 2 ], [ 0, 3 ], [ 1, 3 ], [ 1, 2 ],
1948 [ 2, 2 ], [ 2, 3 ], [ 3, 3 ], [ 3, 2 ],
1949 [ 3, 1 ], [ 2, 1 ], [ 2, 0 ], [ 3, 0 ]
1950 ];
1951
1952 const VP31_LOOP_STRENGTH: [i16; 64] = [
1953 30, 25, 20, 20, 15, 15, 14, 14,
1954 13, 13, 12, 12, 11, 11, 10, 10,
1955 9, 9, 8, 8, 7, 7, 7, 7,
1956 6, 6, 6, 6, 5, 5, 5, 5,
1957 4, 4, 4, 4, 3, 3, 3, 3,
1958 2, 2, 2, 2, 2, 2, 2, 2,
1959 0, 0, 0, 0, 0, 0, 0, 0,
1960 0, 0, 0, 0, 0, 0, 0, 0
1961 ];
1962
1963 const VP31_DEFAULT_MB_MODES: [VPMBType; 8] = [
1964 VPMBType::InterNoMV, VPMBType::Intra, VPMBType::InterMV, VPMBType::InterNearest,
1965 VPMBType::InterNear, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1966 ];
1967
1968 const VP31_MB_MODES: [[VPMBType; 8]; 6] = [
1969 [
1970 VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterMV, VPMBType::InterNoMV,
1971 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1972 ], [
1973 VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterNoMV, VPMBType::InterMV,
1974 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1975 ], [
1976 VPMBType::InterNearest, VPMBType::InterMV, VPMBType::InterNear, VPMBType::InterNoMV,
1977 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1978 ], [
1979 VPMBType::InterNearest, VPMBType::InterMV, VPMBType::InterNoMV, VPMBType::InterNear,
1980 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1981 ], [
1982 VPMBType::InterNoMV, VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterMV,
1983 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1984 ], [
1985 VPMBType::InterNoMV, VPMBType::GoldenNoMV, VPMBType::InterNearest, VPMBType::InterNear,
1986 VPMBType::InterMV, VPMBType::Intra, VPMBType::GoldenMV, VPMBType::InterFourMV
1987 ]
1988 ];
1989
1990 const VP3_LITERAL_BASE: [i16; 6] = [ 7, 9, 13, 21, 37, 69 ];
1991
1992 const VP31_AC_SCALES: [i16; 64] = [
1993 500, 450, 400, 370, 340, 310, 285, 265,
1994 245, 225, 210, 195, 185, 180, 170, 160,
1995 150, 145, 135, 130, 125, 115, 110, 107,
1996 100, 96, 93, 89, 85, 82, 75, 74,
1997 70, 68, 64, 60, 57, 56, 52, 50,
1998 49, 45, 44, 43, 40, 38, 37, 35,
1999 33, 32, 30, 29, 28, 25, 24, 22,
2000 21, 19, 18, 17, 15, 13, 12, 10
2001 ];
2002
2003 const VP31_DC_SCALES: [i16; 64] = [
2004 220, 200, 190, 180, 170, 170, 160, 160,
2005 150, 150, 140, 140, 130, 130, 120, 120,
2006 110, 110, 100, 100, 90, 90, 90, 80,
2007 80, 80, 70, 70, 70, 60, 60, 60,
2008 60, 50, 50, 50, 50, 40, 40, 40,
2009 40, 40, 30, 30, 30, 30, 30, 30,
2010 30, 20, 20, 20, 20, 20, 20, 20,
2011 20, 10, 10, 10, 10, 10, 10, 10
2012 ];
2013
2014 const VP3_QMAT_Y: &[i16; 64] = &[
2015 16, 11, 10, 16, 24, 40, 51, 61,
2016 12, 12, 14, 19, 26, 58, 60, 55,
2017 14, 13, 16, 24, 40, 57, 69, 56,
2018 14, 17, 22, 29, 51, 87, 80, 62,
2019 18, 22, 37, 58, 68, 109, 103, 77,
2020 24, 35, 55, 64, 81, 104, 113, 92,
2021 49, 64, 78, 87, 103, 121, 120, 101,
2022 72, 92, 95, 98, 112, 100, 103, 99
2023 ];
2024
2025 const VP3_QMAT_C: &[i16; 64] = &[
2026 17, 18, 24, 47, 99, 99, 99, 99,
2027 18, 21, 26, 66, 99, 99, 99, 99,
2028 24, 26, 56, 99, 99, 99, 99, 99,
2029 47, 66, 99, 99, 99, 99, 99, 99,
2030 99, 99, 99, 99, 99, 99, 99, 99,
2031 99, 99, 99, 99, 99, 99, 99, 99,
2032 99, 99, 99, 99, 99, 99, 99, 99,
2033 99, 99, 99, 99, 99, 99, 99, 99
2034 ];
2035
2036 const VP3_QMAT_INTER: &[i16; 64] = &[
2037 16, 16, 16, 20, 24, 28, 32, 40,
2038 16, 16, 20, 24, 28, 32, 40, 48,
2039 16, 20, 24, 28, 32, 40, 48, 64,
2040 20, 24, 28, 32, 40, 48, 64, 64,
2041 24, 28, 32, 40, 48, 64, 64, 64,
2042 28, 32, 40, 48, 64, 64, 64, 96,
2043 32, 40, 48, 64, 64, 64, 96, 128,
2044 40, 48, 64, 64, 64, 96, 128, 128
2045 ];
2046
2047 const VP31_DC_CODES: [[u16; 32]; 16] = [
2048 [
2049 0x002D, 0x0026, 0x0166, 0x004E, 0x02CE, 0x059E, 0x027D, 0x0008,
2050 0x04F9, 0x000F, 0x000E, 0x001B, 0x0006, 0x0008, 0x0005, 0x001A,
2051 0x0015, 0x0007, 0x000C, 0x0001, 0x0000, 0x0009, 0x0017, 0x0029,
2052 0x0028, 0x00B2, 0x04F8, 0x059F, 0x009E, 0x013F, 0x0012, 0x0058,
2053 ], [
2054 0x0010, 0x0047, 0x01FF, 0x008C, 0x03FC, 0x046A, 0x0469, 0x0022,
2055 0x11A1, 0x000E, 0x000D, 0x0004, 0x0005, 0x0009, 0x0006, 0x001E,
2056 0x0016, 0x0007, 0x000C, 0x0001, 0x0000, 0x000A, 0x0017, 0x007D,
2057 0x007E, 0x011B, 0x08D1, 0x03FD, 0x046B, 0x11A0, 0x007C, 0x00FE,
2058 ], [
2059 0x0016, 0x0020, 0x0086, 0x0087, 0x0367, 0x06CC, 0x06CB, 0x006E,
2060 0x366D, 0x000F, 0x000E, 0x0004, 0x0005, 0x000A, 0x0006, 0x001A,
2061 0x0011, 0x0007, 0x000C, 0x0001, 0x0000, 0x0009, 0x0017, 0x006F,
2062 0x006D, 0x0364, 0x0D9A, 0x06CA, 0x1B37, 0x366C, 0x0042, 0x00D8,
2063 ], [
2064 0x0000, 0x002D, 0x00F7, 0x0058, 0x0167, 0x02CB, 0x02CA, 0x000E,
2065 0x1661, 0x0003, 0x0002, 0x0008, 0x0009, 0x000D, 0x0002, 0x001F,
2066 0x0017, 0x0001, 0x000C, 0x000E, 0x000A, 0x0006, 0x0078, 0x000F,
2067 0x007A, 0x0164, 0x0599, 0x02CD, 0x0B31, 0x1660, 0x0079, 0x00F6,
2068 ], [
2069 0x0003, 0x003C, 0x000F, 0x007A, 0x001D, 0x0020, 0x0072, 0x0006,
2070 0x0399, 0x0004, 0x0005, 0x0005, 0x0006, 0x000E, 0x0004, 0x0000,
2071 0x0019, 0x0002, 0x000D, 0x0007, 0x001F, 0x0030, 0x0011, 0x0031,
2072 0x0005, 0x0021, 0x00E7, 0x0038, 0x01CD, 0x0398, 0x007B, 0x0009,
2073 ], [
2074 0x0009, 0x0002, 0x0074, 0x0007, 0x00EC, 0x00D1, 0x01A6, 0x0006,
2075 0x0D21, 0x0005, 0x0006, 0x0008, 0x0007, 0x000F, 0x0004, 0x0000,
2076 0x001C, 0x0002, 0x0005, 0x0003, 0x000C, 0x0035, 0x01A7, 0x001B,
2077 0x0077, 0x01A5, 0x0349, 0x00D0, 0x0691, 0x0D20, 0x0075, 0x00ED,
2078 ], [
2079 0x000A, 0x000C, 0x0012, 0x001B, 0x00B7, 0x016C, 0x0099, 0x005A,
2080 0x16D8, 0x0007, 0x0006, 0x0009, 0x0008, 0x0000, 0x0005, 0x0017,
2081 0x000E, 0x0002, 0x0003, 0x000F, 0x001A, 0x004D, 0x2DB3, 0x002C,
2082 0x0011, 0x02DA, 0x05B7, 0x0098, 0x0B6D, 0x2DB2, 0x0010, 0x0027,
2083 ], [
2084 0x000D, 0x000F, 0x001D, 0x0008, 0x0051, 0x0056, 0x00AF, 0x002A,
2085 0x148A, 0x0007, 0x0000, 0x0008, 0x0009, 0x000C, 0x0006, 0x0017,
2086 0x000B, 0x0016, 0x0015, 0x0009, 0x0050, 0x00AE, 0x2917, 0x001C,
2087 0x0014, 0x0290, 0x0523, 0x0149, 0x0A44, 0x2916, 0x0053, 0x00A5,
2088 ], [
2089 0x0001, 0x001D, 0x00F5, 0x00F4, 0x024D, 0x0499, 0x0498, 0x0001,
2090 0x0021, 0x0006, 0x0005, 0x0006, 0x0005, 0x0002, 0x0007, 0x0025,
2091 0x007B, 0x001C, 0x0020, 0x000D, 0x0048, 0x0092, 0x0127, 0x000E,
2092 0x0004, 0x0011, 0x000C, 0x003C, 0x000F, 0x0000, 0x001F, 0x0013,
2093 ], [
2094 0x0005, 0x003C, 0x0040, 0x000D, 0x0031, 0x0061, 0x0060, 0x0002,
2095 0x00F5, 0x0006, 0x0005, 0x0007, 0x0006, 0x0002, 0x0009, 0x0025,
2096 0x0007, 0x0021, 0x0024, 0x0010, 0x0041, 0x00F4, 0x0019, 0x000E,
2097 0x0003, 0x0011, 0x0011, 0x003F, 0x003E, 0x007B, 0x0000, 0x0013,
2098 ], [
2099 0x000A, 0x0007, 0x0001, 0x0009, 0x0131, 0x0261, 0x0260, 0x0015,
2100 0x0001, 0x0007, 0x0006, 0x0008, 0x0007, 0x0006, 0x0012, 0x002F,
2101 0x0014, 0x0027, 0x002D, 0x0016, 0x004D, 0x0099, 0x0000, 0x0004,
2102 0x0001, 0x0005, 0x0017, 0x002E, 0x002C, 0x0008, 0x0006, 0x0001,
2103 ], [
2104 0x0000, 0x000E, 0x0017, 0x002A, 0x0010, 0x00F9, 0x00F8, 0x001E,
2105 0x003F, 0x0007, 0x0006, 0x0009, 0x0008, 0x0006, 0x000F, 0x0005,
2106 0x0016, 0x0029, 0x002B, 0x0015, 0x0050, 0x0011, 0x007D, 0x0004,
2107 0x0017, 0x0006, 0x0014, 0x002C, 0x002D, 0x000E, 0x0009, 0x0051,
2108 ], [
2109 0x0002, 0x0018, 0x002F, 0x000D, 0x0053, 0x0295, 0x0294, 0x00A4,
2110 0x007C, 0x0000, 0x0007, 0x0009, 0x0008, 0x001B, 0x000C, 0x0028,
2111 0x006A, 0x001E, 0x001D, 0x0069, 0x00D7, 0x007D, 0x014B, 0x0019,
2112 0x0016, 0x002E, 0x001C, 0x002B, 0x002A, 0x0068, 0x003F, 0x00D6,
2113 ], [
2114 0x0002, 0x001B, 0x000C, 0x0018, 0x0029, 0x007F, 0x02F0, 0x0198,
2115 0x0179, 0x0000, 0x0007, 0x0009, 0x0008, 0x001A, 0x000D, 0x002A,
2116 0x0064, 0x001E, 0x0067, 0x005F, 0x00CD, 0x007E, 0x02F1, 0x0016,
2117 0x000E, 0x002E, 0x0065, 0x002B, 0x0028, 0x003E, 0x00BD, 0x0199,
2118 ], [
2119 0x0002, 0x0007, 0x0016, 0x0006, 0x0036, 0x005C, 0x015D, 0x015C,
2120 0x02BF, 0x0000, 0x0007, 0x0009, 0x0008, 0x0018, 0x0034, 0x002A,
2121 0x005E, 0x006A, 0x0064, 0x005D, 0x00CB, 0x00AD, 0x02BE, 0x0014,
2122 0x0033, 0x006E, 0x005F, 0x006F, 0x006B, 0x00CA, 0x00AC, 0x015E,
2123 ], [
2124 0x000F, 0x001D, 0x0018, 0x000B, 0x0019, 0x0029, 0x00D6, 0x0551,
2125 0x0AA1, 0x0001, 0x0000, 0x0009, 0x0008, 0x001B, 0x0038, 0x0028,
2126 0x0057, 0x006A, 0x0068, 0x0056, 0x00E5, 0x0155, 0x0AA0, 0x0073,
2127 0x0069, 0x00D7, 0x00AB, 0x00E4, 0x00A9, 0x0151, 0x0150, 0x02A9,
2128 ]
2129 ];
2130
2131 const VP31_DC_BITS: [[u8; 32]; 16] = [
2132 [
2133 6, 7, 9, 8, 10, 11, 11, 5, 12, 4, 4, 5, 4, 4, 4, 5,
2134 5, 4, 4, 3, 3, 4, 5, 6, 6, 8, 12, 11, 9, 10, 6, 7,
2135 ], [
2136 5, 7, 9, 8, 10, 11, 11, 6, 13, 4, 4, 4, 4, 4, 4, 5,
2137 5, 4, 4, 3, 3, 4, 5, 7, 7, 9, 12, 10, 11, 13, 7, 8,
2138 ], [
2139 5, 6, 8, 8, 10, 11, 11, 7, 14, 4, 4, 4, 4, 4, 4, 5,
2140 5, 4, 4, 3, 3, 4, 5, 7, 7, 10, 12, 11, 13, 14, 7, 8,
2141 ], [
2142 4, 6, 8, 7, 9, 10, 10, 6, 13, 3, 3, 4, 4, 4, 4, 5,
2143 5, 4, 4, 4, 4, 5, 7, 6, 7, 9, 11, 10, 12, 13, 7, 8,
2144 ], [
2145 4, 6, 7, 7, 8, 9, 10, 6, 13, 3, 3, 4, 4, 4, 4, 4,
2146 5, 4, 4, 4, 5, 6, 8, 6, 6, 9, 11, 9, 12, 13, 7, 7,
2147 ], [
2148 4, 5, 7, 6, 8, 9, 10, 6, 13, 3, 3, 4, 4, 4, 4, 4,
2149 5, 4, 4, 4, 5, 7, 10, 6, 7, 10, 11, 9, 12, 13, 7, 8,
2150 ], [
2151 4, 5, 6, 6, 8, 9, 9, 7, 13, 3, 3, 4, 4, 3, 4, 5,
2152 5, 4, 4, 5, 6, 8, 14, 6, 6, 10, 11, 9, 12, 14, 6, 7,
2153 ], [
2154 4, 5, 6, 5, 7, 8, 9, 7, 13, 3, 2, 4, 4, 4, 4, 5,
2155 5, 5, 5, 5, 7, 9, 14, 6, 6, 10, 11, 9, 12, 14, 7, 8,
2156 ], [
2157 4, 6, 8, 8, 10, 11, 11, 5, 6, 3, 3, 4, 4, 4, 5, 6,
2158 7, 6, 6, 6, 7, 8, 9, 4, 4, 5, 6, 6, 5, 5, 5, 5,
2159 ], [
2160 4, 6, 7, 7, 9, 10, 10, 5, 8, 3, 3, 4, 4, 4, 5, 6,
2161 6, 6, 6, 6, 7, 8, 8, 4, 4, 5, 6, 6, 6, 7, 4, 5,
2162 ], [
2163 4, 5, 6, 6, 9, 10, 10, 6, 7, 3, 3, 4, 4, 4, 5, 6,
2164 6, 6, 6, 6, 7, 8, 7, 4, 4, 5, 6, 6, 6, 6, 5, 5,
2165 ], [
2166 3, 5, 6, 6, 7, 10, 10, 7, 8, 3, 3, 4, 4, 4, 5, 5,
2167 6, 6, 6, 6, 7, 7, 9, 4, 5, 5, 6, 6, 6, 6, 6, 7,
2168 ], [
2169 3, 5, 6, 5, 7, 10, 10, 8, 8, 2, 3, 4, 4, 5, 5, 6,
2170 7, 6, 6, 7, 8, 8, 9, 5, 5, 6, 6, 6, 6, 7, 7, 8,
2171 ], [
2172 3, 5, 5, 5, 6, 8, 10, 9, 9, 2, 3, 4, 4, 5, 5, 6,
2173 7, 6, 7, 7, 8, 8, 10, 5, 5, 6, 7, 6, 6, 7, 8, 9,
2174 ], [
2175 3, 4, 5, 4, 6, 7, 9, 9, 10, 2, 3, 4, 4, 5, 6, 6,
2176 7, 7, 7, 7, 8, 8, 10, 5, 6, 7, 7, 7, 7, 8, 8, 9,
2177 ], [
2178 4, 5, 5, 4, 5, 6, 8, 11, 12, 2, 2, 4, 4, 5, 6, 6,
2179 7, 7, 7, 7, 8, 9, 12, 7, 7, 8, 8, 8, 8, 9, 9, 10,
2180 ]
2181 ];
2182
2183 const VP31_AC_CAT0_CODES: [[u16; 32]; 16] = [
2184 [
2185 0x0008, 0x0025, 0x017A, 0x02F7, 0x0BDB, 0x17B4, 0x2F6B, 0x001D,
2186 0x2F6A, 0x0008, 0x0007, 0x0001, 0x0002, 0x000A, 0x0006, 0x0000,
2187 0x001C, 0x0009, 0x000D, 0x000F, 0x000C, 0x0003, 0x000A, 0x0016,
2188 0x0013, 0x005D, 0x0024, 0x00BC, 0x005C, 0x05EC, 0x000B, 0x005F,
2189 ], [
2190 0x000F, 0x0010, 0x004B, 0x00C6, 0x031D, 0x0C71, 0x0C70, 0x0001,
2191 0x0C73, 0x0008, 0x0009, 0x0002, 0x0003, 0x000B, 0x0006, 0x0000,
2192 0x001C, 0x0005, 0x000D, 0x000F, 0x000A, 0x0019, 0x0013, 0x001D,
2193 0x0030, 0x0062, 0x0024, 0x004A, 0x018F, 0x0C72, 0x000E, 0x0011,
2194 ], [
2195 0x001B, 0x0003, 0x008D, 0x0040, 0x0239, 0x0471, 0x08E0, 0x0003,
2196 0x11C3, 0x000A, 0x0009, 0x0004, 0x0005, 0x000E, 0x0007, 0x0001,
2197 0x001E, 0x0006, 0x000C, 0x000B, 0x0002, 0x0000, 0x0041, 0x001F,
2198 0x0022, 0x0002, 0x008F, 0x008C, 0x011D, 0x11C2, 0x001A, 0x0021,
2199 ], [
2200 0x001F, 0x0003, 0x0003, 0x0043, 0x000B, 0x0015, 0x0051, 0x0003,
2201 0x0050, 0x000D, 0x000C, 0x0004, 0x0006, 0x000E, 0x000A, 0x0001,
2202 0x001E, 0x0005, 0x0009, 0x0007, 0x0011, 0x0002, 0x0004, 0x0002,
2203 0x002D, 0x0020, 0x0042, 0x0001, 0x0000, 0x0029, 0x0017, 0x002C,
2204 ], [
2205 0x0003, 0x001F, 0x003A, 0x005D, 0x0173, 0x02E4, 0x172D, 0x0004,
2206 0x172C, 0x000F, 0x000E, 0x0009, 0x0008, 0x000C, 0x000A, 0x0001,
2207 0x0016, 0x0002, 0x0005, 0x001A, 0x002F, 0x0038, 0x05CA, 0x0006,
2208 0x0037, 0x001E, 0x003B, 0x0039, 0x00B8, 0x0B97, 0x0000, 0x0036,
2209 ], [
2210 0x0006, 0x0037, 0x005D, 0x000C, 0x00B9, 0x02E3, 0x05C4, 0x0004,
2211 0x1715, 0x0000, 0x000F, 0x0008, 0x0007, 0x000C, 0x0009, 0x001D,
2212 0x0016, 0x001C, 0x001A, 0x000B, 0x005E, 0x0170, 0x1714, 0x000A,
2213 0x000A, 0x0036, 0x005F, 0x001B, 0x001A, 0x0B8B, 0x0002, 0x0007,
2214 ], [
2215 0x000C, 0x000B, 0x0079, 0x0022, 0x00F0, 0x0119, 0x0230, 0x001D,
2216 0x08C4, 0x0001, 0x0000, 0x000A, 0x0009, 0x000B, 0x0007, 0x001C,
2217 0x003D, 0x000D, 0x0008, 0x0015, 0x008D, 0x118B, 0x118A, 0x000D,
2218 0x0010, 0x0009, 0x0014, 0x0047, 0x00F1, 0x0463, 0x001F, 0x000C,
2219 ], [
2220 0x0000, 0x001A, 0x0033, 0x000C, 0x0046, 0x01E3, 0x03C5, 0x0017,
2221 0x1E21, 0x0002, 0x0001, 0x0009, 0x000A, 0x0007, 0x001B, 0x003D,
2222 0x001B, 0x0022, 0x0079, 0x00F0, 0x1E20, 0x1E23, 0x1E22, 0x000E,
2223 0x0016, 0x0018, 0x0032, 0x001A, 0x0047, 0x0789, 0x001F, 0x0010,
2224 ], [
2225 0x001D, 0x0061, 0x004E, 0x009E, 0x027C, 0x09F5, 0x09F4, 0x0003,
2226 0x0060, 0x0000, 0x000F, 0x000B, 0x000A, 0x0009, 0x0005, 0x000D,
2227 0x0031, 0x0008, 0x0038, 0x0012, 0x0026, 0x013F, 0x04FB, 0x000D,
2228 0x0002, 0x000C, 0x0039, 0x001C, 0x000F, 0x001D, 0x0008, 0x0019,
2229 ], [
2230 0x0007, 0x0019, 0x00AB, 0x00AA, 0x0119, 0x0461, 0x0460, 0x001B,
2231 0x0047, 0x0001, 0x0000, 0x000C, 0x000B, 0x0009, 0x0005, 0x000D,
2232 0x0035, 0x003D, 0x003C, 0x0018, 0x0022, 0x008D, 0x0231, 0x000E,
2233 0x001F, 0x0009, 0x002B, 0x0010, 0x0034, 0x0054, 0x0008, 0x0014,
2234 ], [
2235 0x000C, 0x0005, 0x0008, 0x005B, 0x004D, 0x0131, 0x0261, 0x001A,
2236 0x0012, 0x0000, 0x000F, 0x000A, 0x0009, 0x0006, 0x001B, 0x0006,
2237 0x001C, 0x002C, 0x0015, 0x005A, 0x0027, 0x0099, 0x0260, 0x000E,
2238 0x0004, 0x000F, 0x0007, 0x001D, 0x000B, 0x0014, 0x0008, 0x0017,
2239 ], [
2240 0x000F, 0x0013, 0x0075, 0x0024, 0x0095, 0x0251, 0x04A0, 0x0010,
2241 0x00C8, 0x0002, 0x0001, 0x0001, 0x0000, 0x001A, 0x0011, 0x002C,
2242 0x0065, 0x0074, 0x004B, 0x00C9, 0x0129, 0x0943, 0x0942, 0x0003,
2243 0x000A, 0x001C, 0x0018, 0x0033, 0x0017, 0x002D, 0x001B, 0x003B,
2244 ], [
2245 0x0003, 0x001A, 0x002D, 0x0038, 0x0028, 0x0395, 0x0E51, 0x0037,
2246 0x00E4, 0x0001, 0x0000, 0x001F, 0x001E, 0x0017, 0x003A, 0x0073,
2247 0x002A, 0x002B, 0x0029, 0x01CB, 0x0729, 0x1CA1, 0x1CA0, 0x0004,
2248 0x000A, 0x0004, 0x0018, 0x0036, 0x000B, 0x002C, 0x0019, 0x003B,
2249 ], [
2250 0x0004, 0x0004, 0x003F, 0x0017, 0x0075, 0x01F5, 0x07D1, 0x0017,
2251 0x01F6, 0x0001, 0x0000, 0x001B, 0x001A, 0x000A, 0x0032, 0x0074,
2252 0x00F8, 0x00F9, 0x01F7, 0x03E9, 0x0FA0, 0x1F43, 0x1F42, 0x0003,
2253 0x000A, 0x001E, 0x001C, 0x003B, 0x0018, 0x0016, 0x0016, 0x0033,
2254 ], [
2255 0x0004, 0x0007, 0x0018, 0x001E, 0x0036, 0x0031, 0x0177, 0x0077,
2256 0x0176, 0x0001, 0x0000, 0x001A, 0x0019, 0x003A, 0x0019, 0x005C,
2257 0x00BA, 0x0061, 0x00C1, 0x0180, 0x0302, 0x0607, 0x0606, 0x0002,
2258 0x000A, 0x001F, 0x001C, 0x0037, 0x0016, 0x0076, 0x000D, 0x002F,
2259 ], [
2260 0x0000, 0x000A, 0x001A, 0x000C, 0x001D, 0x0039, 0x0078, 0x005E,
2261 0x0393, 0x0002, 0x0001, 0x0016, 0x000F, 0x002E, 0x005F, 0x0073,
2262 0x00E5, 0x01C8, 0x0E4A, 0x1C97, 0x1C96, 0x0E49, 0x0E48, 0x0004,
2263 0x0006, 0x001F, 0x001B, 0x001D, 0x0038, 0x0038, 0x003D, 0x0079,
2264 ]
2265 ];
2266
2267 const VP31_AC_CAT0_BITS: [[u8; 32]; 16] = [
2268 [
2269 5, 7, 9, 10, 12, 13, 14, 5, 14, 4, 4, 4, 4, 4, 4, 4,
2270 5, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 8, 7, 11, 5, 7,
2271 ], [
2272 5, 6, 8, 8, 10, 12, 12, 4, 12, 4, 4, 4, 4, 4, 4, 4,
2273 5, 4, 4, 4, 4, 5, 6, 5, 6, 7, 7, 8, 9, 12, 5, 6,
2274 ], [
2275 5, 6, 8, 7, 10, 11, 12, 4, 13, 4, 4, 4, 4, 4, 4, 4,
2276 5, 4, 4, 4, 4, 5, 7, 5, 6, 6, 8, 8, 9, 13, 5, 6,
2277 ], [
2278 5, 6, 7, 7, 9, 10, 12, 4, 12, 4, 4, 4, 4, 4, 4, 4,
2279 5, 4, 4, 4, 5, 6, 8, 4, 6, 6, 7, 7, 7, 11, 5, 6,
2280 ], [
2281 4, 6, 7, 7, 9, 10, 13, 4, 13, 4, 4, 4, 4, 4, 4, 4,
2282 5, 4, 4, 5, 6, 7, 11, 4, 6, 6, 7, 7, 8, 12, 4, 6,
2283 ], [
2284 4, 6, 7, 6, 8, 10, 11, 4, 13, 3, 4, 4, 4, 4, 4, 5,
2285 5, 5, 5, 5, 7, 9, 13, 4, 5, 6, 7, 7, 7, 12, 4, 5,
2286 ], [
2287 4, 5, 7, 6, 8, 9, 10, 5, 12, 3, 3, 4, 4, 4, 4, 5,
2288 6, 5, 5, 6, 8, 13, 13, 4, 5, 5, 6, 7, 8, 11, 5, 5,
2289 ], [
2290 3, 5, 6, 5, 7, 9, 10, 5, 13, 3, 3, 4, 4, 4, 5, 6,
2291 6, 6, 7, 8, 13, 13, 13, 4, 5, 5, 6, 6, 7, 11, 5, 5,
2292 ], [
2293 5, 7, 8, 9, 11, 13, 13, 4, 7, 3, 4, 4, 4, 4, 4, 5,
2294 6, 5, 6, 6, 7, 10, 12, 4, 4, 5, 6, 6, 5, 6, 4, 5,
2295 ], [
2296 4, 6, 8, 8, 10, 12, 12, 5, 8, 3, 3, 4, 4, 4, 4, 5,
2297 6, 6, 6, 6, 7, 9, 11, 4, 5, 5, 6, 6, 6, 7, 4, 5,
2298 ], [
2299 4, 5, 6, 7, 9, 11, 12, 5, 7, 3, 4, 4, 4, 4, 5, 5,
2300 6, 6, 6, 7, 8, 10, 12, 4, 4, 5, 5, 6, 5, 6, 4, 5,
2301 ], [
2302 4, 5, 7, 6, 8, 10, 11, 5, 8, 3, 3, 4, 4, 5, 5, 6,
2303 7, 7, 7, 8, 9, 12, 12, 3, 4, 5, 5, 6, 5, 6, 5, 6,
2304 ], [
2305 3, 5, 6, 6, 7, 10, 12, 6, 8, 3, 3, 5, 5, 5, 6, 7,
2306 7, 7, 7, 9, 11, 13, 13, 3, 4, 4, 5, 6, 5, 6, 5, 6,
2307 ], [
2308 3, 4, 6, 5, 7, 9, 11, 6, 9, 3, 3, 5, 5, 5, 6, 7,
2309 8, 8, 9, 10, 12, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6,
2310 ], [
2311 3, 4, 5, 5, 6, 7, 9, 7, 9, 3, 3, 5, 5, 6, 6, 7,
2312 8, 8, 9, 10, 11, 12, 12, 3, 4, 5, 5, 6, 5, 7, 5, 6,
2313 ], [
2314 3, 4, 5, 4, 5, 6, 7, 7, 11, 3, 3, 5, 5, 6, 7, 8,
2315 9, 10, 13, 14, 14, 13, 13, 3, 4, 5, 5, 6, 6, 7, 6, 7,
2316 ]
2317 ];
2318
2319 const VP31_AC_CAT1_CODES: [[u16; 32]; 16] = [
2320 [
2321 0x000B, 0x002B, 0x0054, 0x01B7, 0x06D9, 0x0DB1, 0x0DB0, 0x0002,
2322 0x00AB, 0x0009, 0x000A, 0x0007, 0x0008, 0x000F, 0x000C, 0x0003,
2323 0x001D, 0x0004, 0x000B, 0x0006, 0x001A, 0x0003, 0x00AA, 0x0001,
2324 0x0000, 0x0014, 0x006C, 0x00DA, 0x0002, 0x036D, 0x001C, 0x0037,
2325 ], [
2326 0x001D, 0x0004, 0x00B6, 0x006A, 0x05B9, 0x16E1, 0x16E0, 0x0007,
2327 0x016F, 0x000C, 0x000D, 0x0009, 0x0008, 0x000F, 0x000A, 0x0003,
2328 0x0017, 0x0002, 0x0004, 0x001C, 0x002C, 0x006B, 0x0B71, 0x0005,
2329 0x0003, 0x001B, 0x005A, 0x0034, 0x0005, 0x02DD, 0x0000, 0x000C,
2330 ], [
2331 0x0003, 0x007F, 0x00A1, 0x00A0, 0x020C, 0x0834, 0x106B, 0x0007,
2332 0x0082, 0x000E, 0x000D, 0x000B, 0x000C, 0x0000, 0x0009, 0x0002,
2333 0x0011, 0x001E, 0x0015, 0x003E, 0x0040, 0x041B, 0x106A, 0x0006,
2334 0x000A, 0x0029, 0x007E, 0x0051, 0x0021, 0x0107, 0x0004, 0x000B,
2335 ], [
2336 0x0007, 0x001B, 0x00F6, 0x00E9, 0x03A1, 0x0740, 0x0E82, 0x001F,
2337 0x01EF, 0x0001, 0x0002, 0x000B, 0x000C, 0x000D, 0x0008, 0x001C,
2338 0x0003, 0x0012, 0x0002, 0x0075, 0x01D1, 0x1D07, 0x1D06, 0x000A,
2339 0x0013, 0x003B, 0x001A, 0x007A, 0x003C, 0x01EE, 0x0000, 0x000C,
2340 ], [
2341 0x000D, 0x003D, 0x0042, 0x0037, 0x00D9, 0x0362, 0x06C6, 0x001F,
2342 0x0086, 0x0001, 0x0002, 0x000C, 0x000B, 0x000A, 0x0001, 0x000F,
2343 0x0025, 0x003C, 0x001A, 0x0087, 0x01B0, 0x0D8F, 0x0D8E, 0x000E,
2344 0x0013, 0x000C, 0x0024, 0x0020, 0x0011, 0x006D, 0x0000, 0x000E,
2345 ], [
2346 0x0000, 0x0012, 0x0076, 0x0077, 0x014D, 0x0533, 0x14C9, 0x0013,
2347 0x00A5, 0x0002, 0x0003, 0x000B, 0x000C, 0x0008, 0x001A, 0x002B,
2348 0x0075, 0x0074, 0x00A7, 0x0298, 0x14C8, 0x14CB, 0x14CA, 0x000F,
2349 0x001C, 0x0007, 0x002A, 0x0028, 0x001B, 0x00A4, 0x0002, 0x0006,
2350 ], [
2351 0x0002, 0x001A, 0x002B, 0x003A, 0x00ED, 0x0283, 0x0A0A, 0x0004,
2352 0x00A1, 0x0004, 0x0003, 0x000B, 0x000C, 0x001F, 0x0006, 0x0077,
2353 0x00A3, 0x00A2, 0x0140, 0x1417, 0x1416, 0x0A09, 0x0A08, 0x0000,
2354 0x001E, 0x0007, 0x002A, 0x0029, 0x001C, 0x00EC, 0x001B, 0x0005,
2355 ], [
2356 0x0002, 0x0002, 0x0018, 0x001D, 0x0035, 0x00E4, 0x01CF, 0x001D,
2357 0x0072, 0x0004, 0x0005, 0x0006, 0x0007, 0x0006, 0x0073, 0x0038,
2358 0x01CE, 0x039B, 0x0398, 0x0733, 0x0732, 0x0735, 0x0734, 0x0000,
2359 0x001F, 0x001B, 0x0034, 0x000F, 0x001E, 0x00E5, 0x0019, 0x0038,
2360 ], [
2361 0x0016, 0x0050, 0x0172, 0x02E7, 0x1732, 0x2E67, 0x2E66, 0x0006,
2362 0x0051, 0x0001, 0x0000, 0x000D, 0x000C, 0x0009, 0x001C, 0x0009,
2363 0x001C, 0x001D, 0x005D, 0x00B8, 0x05CD, 0x1731, 0x1730, 0x000F,
2364 0x0005, 0x000F, 0x0008, 0x0029, 0x001D, 0x002F, 0x0008, 0x0015,
2365 ], [
2366 0x0009, 0x0021, 0x0040, 0x00AD, 0x02B0, 0x1589, 0x1588, 0x001C,
2367 0x005F, 0x0000, 0x000F, 0x000D, 0x000C, 0x0006, 0x0011, 0x002A,
2368 0x0057, 0x005E, 0x0041, 0x0159, 0x0563, 0x158B, 0x158A, 0x0001,
2369 0x0005, 0x0014, 0x003B, 0x002E, 0x0004, 0x003A, 0x0007, 0x0016,
2370 ], [
2371 0x000E, 0x0007, 0x0046, 0x0045, 0x0064, 0x032A, 0x0657, 0x0018,
2372 0x000D, 0x0000, 0x000F, 0x000A, 0x000B, 0x001A, 0x0036, 0x0047,
2373 0x0044, 0x0018, 0x0033, 0x00CB, 0x0656, 0x0329, 0x0328, 0x0002,
2374 0x0006, 0x0019, 0x000E, 0x0037, 0x0009, 0x000F, 0x0002, 0x0010,
2375 ], [
2376 0x0003, 0x0018, 0x0023, 0x0077, 0x0194, 0x1956, 0x32AF, 0x003A,
2377 0x0076, 0x0002, 0x0001, 0x001F, 0x001E, 0x0014, 0x0022, 0x0064,
2378 0x0197, 0x0196, 0x032B, 0x0654, 0x32AE, 0x1955, 0x1954, 0x0000,
2379 0x0009, 0x001C, 0x0015, 0x0010, 0x000D, 0x0017, 0x0016, 0x0033,
2380 ], [
2381 0x0005, 0x0006, 0x003E, 0x0010, 0x0048, 0x093F, 0x24FA, 0x0032,
2382 0x0067, 0x0002, 0x0001, 0x001B, 0x001E, 0x0034, 0x0066, 0x0092,
2383 0x0126, 0x024E, 0x049E, 0x49F7, 0x49F6, 0x24F9, 0x24F8, 0x0000,
2384 0x0007, 0x0018, 0x0011, 0x003F, 0x000E, 0x0013, 0x0035, 0x0025,
2385 ], [
2386 0x0005, 0x0008, 0x0012, 0x001C, 0x001C, 0x00EA, 0x1D75, 0x001E,
2387 0x0066, 0x0001, 0x0002, 0x001B, 0x001A, 0x001F, 0x003B, 0x0074,
2388 0x01D6, 0x03AF, 0x1D74, 0x1D77, 0x1D76, 0x0EB9, 0x0EB8, 0x000F,
2389 0x0006, 0x0013, 0x003B, 0x003A, 0x0000, 0x0018, 0x0032, 0x0067,
2390 ], [
2391 0x0004, 0x000A, 0x001B, 0x000C, 0x000D, 0x00E6, 0x0684, 0x0072,
2392 0x00E7, 0x0002, 0x0001, 0x0017, 0x0016, 0x0018, 0x00D1, 0x01A0,
2393 0x0686, 0x0D0F, 0x0D0A, 0x1A17, 0x1A16, 0x1A1D, 0x1A1C, 0x000F,
2394 0x001D, 0x000E, 0x0035, 0x0038, 0x0000, 0x000F, 0x0019, 0x0069,
2395 ], [
2396 0x0003, 0x000C, 0x001B, 0x0000, 0x0003, 0x002E, 0x0051, 0x00BC,
2397 0x0053, 0x0004, 0x0002, 0x0016, 0x0015, 0x0015, 0x0050, 0x00A4,
2398 0x0294, 0x052B, 0x052A, 0x052D, 0x052C, 0x052F, 0x052E, 0x000E,
2399 0x001A, 0x0004, 0x0028, 0x0029, 0x000F, 0x000B, 0x005F, 0x00BD,
2400 ]
2401 ];
2402
2403 const VP31_AC_CAT1_BITS: [[u8; 32]; 16] = [
2404 [
2405 5, 7, 8, 9, 11, 12, 12, 4, 9, 4, 4, 4, 4, 4, 4, 4,
2406 5, 4, 4, 4, 5, 6, 9, 4, 5, 6, 7, 8, 6, 10, 5, 6,
2407 ], [
2408 5, 6, 8, 8, 11, 13, 13, 4, 9, 4, 4, 4, 4, 4, 4, 4,
2409 5, 4, 4, 5, 6, 8, 12, 4, 5, 6, 7, 7, 6, 10, 4, 5,
2410 ], [
2411 4, 7, 8, 8, 10, 12, 13, 4, 8, 4, 4, 4, 4, 3, 4, 4,
2412 5, 5, 5, 6, 7, 11, 13, 4, 5, 6, 7, 7, 6, 9, 4, 5,
2413 ], [
2414 4, 6, 8, 8, 10, 11, 12, 5, 9, 3, 3, 4, 4, 4, 4, 5,
2415 5, 5, 5, 7, 9, 13, 13, 4, 5, 6, 6, 7, 6, 9, 4, 5,
2416 ], [
2417 4, 6, 7, 7, 9, 11, 12, 5, 8, 3, 3, 4, 4, 4, 4, 5,
2418 6, 6, 6, 8, 10, 13, 13, 4, 5, 5, 6, 6, 5, 8, 4, 5,
2419 ], [
2420 3, 5, 7, 7, 9, 11, 13, 5, 8, 3, 3, 4, 4, 4, 5, 6,
2421 7, 7, 8, 10, 13, 13, 13, 4, 5, 5, 6, 6, 5, 8, 4, 5,
2422 ], [
2423 3, 5, 6, 6, 8, 10, 12, 5, 8, 3, 3, 4, 4, 5, 5, 7,
2424 8, 8, 9, 13, 13, 12, 12, 3, 5, 5, 6, 6, 5, 8, 5, 5,
2425 ], [
2426 3, 4, 5, 5, 6, 8, 11, 7, 9, 3, 3, 4, 4, 5, 7, 8,
2427 11, 12, 12, 13, 13, 13, 13, 3, 5, 5, 6, 6, 5, 8, 5, 6,
2428 ], [
2429 5, 7, 9, 10, 13, 14, 14, 4, 7, 3, 3, 4, 4, 4, 5, 5,
2430 6, 6, 7, 8, 11, 13, 13, 4, 4, 5, 5, 6, 5, 6, 4, 5,
2431 ], [
2432 4, 6, 7, 8, 10, 13, 13, 5, 7, 3, 4, 4, 4, 4, 5, 6,
2433 7, 7, 7, 9, 11, 13, 13, 3, 4, 5, 6, 6, 4, 6, 4, 5,
2434 ], [
2435 4, 5, 7, 7, 9, 12, 13, 5, 6, 3, 4, 4, 4, 5, 6, 7,
2436 7, 7, 8, 10, 13, 12, 12, 3, 4, 5, 5, 6, 4, 5, 4, 5,
2437 ], [
2438 3, 5, 6, 7, 9, 13, 14, 6, 7, 3, 3, 5, 5, 5, 6, 7,
2439 9, 9, 10, 11, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6,
2440 ], [
2441 3, 4, 6, 5, 7, 12, 14, 6, 7, 3, 3, 5, 5, 6, 7, 8,
2442 9, 10, 11, 15, 15, 14, 14, 3, 4, 5, 5, 6, 4, 5, 6, 6,
2443 ], [
2444 3, 4, 5, 5, 6, 9, 14, 6, 7, 3, 3, 5, 5, 6, 7, 8,
2445 10, 11, 14, 14, 14, 13, 13, 4, 4, 5, 6, 6, 3, 5, 6, 7,
2446 ], [
2447 3, 4, 5, 4, 5, 8, 11, 7, 8, 3, 3, 5, 5, 6, 8, 9,
2448 11, 12, 12, 13, 13, 13, 13, 4, 5, 5, 6, 6, 3, 5, 6, 7,
2449 ], [
2450 3, 4, 5, 3, 4, 6, 9, 8, 9, 3, 3, 5, 5, 7, 9, 10,
2451 12, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 6, 7, 8,
2452 ]
2453 ];
2454
2455 const VP31_AC_CAT2_CODES: [[u16; 32]; 16] = [
2456 [
2457 0x0003, 0x0009, 0x00D0, 0x01A3, 0x0344, 0x0D14, 0x1A2B, 0x0004,
2458 0x0015, 0x0000, 0x000F, 0x000B, 0x000C, 0x000E, 0x0009, 0x001B,
2459 0x000A, 0x0014, 0x000D, 0x002A, 0x0014, 0x068B, 0x1A2A, 0x0008,
2460 0x000B, 0x002B, 0x000B, 0x0069, 0x0035, 0x0008, 0x0007, 0x000C,
2461 ], [
2462 0x000A, 0x003C, 0x0032, 0x0030, 0x00C5, 0x0621, 0x0620, 0x001F,
2463 0x0033, 0x0001, 0x0000, 0x000E, 0x000D, 0x000C, 0x0004, 0x000D,
2464 0x0026, 0x0027, 0x0014, 0x0063, 0x0189, 0x0623, 0x0622, 0x000B,
2465 0x0012, 0x003D, 0x0022, 0x0015, 0x000B, 0x0023, 0x0007, 0x0010,
2466 ], [
2467 0x000F, 0x000C, 0x0043, 0x0010, 0x0044, 0x0114, 0x0455, 0x0018,
2468 0x0023, 0x0001, 0x0000, 0x000E, 0x000D, 0x0009, 0x0019, 0x0009,
2469 0x0017, 0x0016, 0x0042, 0x008B, 0x0454, 0x0457, 0x0456, 0x000B,
2470 0x0015, 0x000A, 0x0029, 0x0020, 0x000D, 0x0028, 0x0007, 0x0011,
2471 ], [
2472 0x0001, 0x001A, 0x0029, 0x002A, 0x00A0, 0x0285, 0x1425, 0x0002,
2473 0x0000, 0x0002, 0x0003, 0x000C, 0x000B, 0x0008, 0x0012, 0x0001,
2474 0x0051, 0x0001, 0x0143, 0x0508, 0x1424, 0x1427, 0x1426, 0x000F,
2475 0x001C, 0x0003, 0x0037, 0x002B, 0x0013, 0x0036, 0x001D, 0x0001,
2476 ], [
2477 0x0004, 0x001F, 0x003D, 0x0006, 0x0016, 0x0053, 0x014A, 0x0034,
2478 0x002A, 0x0002, 0x0003, 0x000B, 0x000C, 0x001C, 0x0037, 0x0017,
2479 0x002B, 0x0028, 0x00A4, 0x052D, 0x052C, 0x052F, 0x052E, 0x0000,
2480 0x001D, 0x0007, 0x0004, 0x0035, 0x0014, 0x0036, 0x0015, 0x003C,
2481 ], [
2482 0x0004, 0x000A, 0x0007, 0x001D, 0x0009, 0x01F3, 0x07C7, 0x0008,
2483 0x01F0, 0x0003, 0x0002, 0x000D, 0x000C, 0x0017, 0x007D, 0x01F2,
2484 0x07C6, 0x07C5, 0x1F12, 0x3E27, 0x3E26, 0x1F11, 0x1F10, 0x0000,
2485 0x001E, 0x0006, 0x0039, 0x0038, 0x003F, 0x002C, 0x0005, 0x002D,
2486 ], [
2487 0x0002, 0x0007, 0x0018, 0x0003, 0x0005, 0x0035, 0x004F, 0x0012,
2488 0x04E5, 0x0005, 0x0004, 0x000D, 0x000E, 0x0033, 0x0026, 0x009D,
2489 0x04E4, 0x04E7, 0x04E6, 0x04E1, 0x04E0, 0x04E3, 0x04E2, 0x0000,
2490 0x001F, 0x000C, 0x003D, 0x003C, 0x0032, 0x0034, 0x001B, 0x0008,
2491 ], [
2492 0x0000, 0x0004, 0x001C, 0x000F, 0x0002, 0x0007, 0x0075, 0x00E8,
2493 0x1D2A, 0x0005, 0x0004, 0x000D, 0x000C, 0x0077, 0x0E96, 0x3A57,
2494 0x3A56, 0x3A5D, 0x3A5C, 0x3A5F, 0x3A5E, 0x1D29, 0x1D28, 0x0003,
2495 0x0006, 0x000A, 0x002C, 0x0017, 0x0076, 0x01D3, 0x03A4, 0x002D,
2496 ], [
2497 0x000A, 0x0024, 0x00BF, 0x0085, 0x0211, 0x0842, 0x1087, 0x0018,
2498 0x0020, 0x0001, 0x0002, 0x000E, 0x000D, 0x0007, 0x0013, 0x0025,
2499 0x005E, 0x0043, 0x00BE, 0x0109, 0x1086, 0x0841, 0x0840, 0x000F,
2500 0x0001, 0x0011, 0x0000, 0x002E, 0x0019, 0x0001, 0x0006, 0x0016,
2501 ], [
2502 0x0002, 0x000F, 0x006F, 0x0061, 0x0374, 0x1BA8, 0x3753, 0x0012,
2503 0x0036, 0x0000, 0x0001, 0x000A, 0x000B, 0x001A, 0x0031, 0x0060,
2504 0x00DC, 0x01BB, 0x06EB, 0x1BAB, 0x3752, 0x3755, 0x3754, 0x000E,
2505 0x0006, 0x0013, 0x000E, 0x003E, 0x0008, 0x001E, 0x0019, 0x003F,
2506 ], [
2507 0x0003, 0x001C, 0x0025, 0x0024, 0x01DA, 0x1DBD, 0x3B7C, 0x003C,
2508 0x003D, 0x0000, 0x0001, 0x000B, 0x000A, 0x000B, 0x0077, 0x00EC,
2509 0x03B6, 0x076E, 0x1DBF, 0x76FB, 0x76FA, 0x3B79, 0x3B78, 0x000D,
2510 0x001F, 0x0013, 0x000A, 0x0008, 0x000C, 0x0008, 0x0009, 0x003A,
2511 ], [
2512 0x0005, 0x0003, 0x0004, 0x0010, 0x008F, 0x0475, 0x11D1, 0x0079,
2513 0x0027, 0x0002, 0x0003, 0x0001, 0x0000, 0x0026, 0x0046, 0x011C,
2514 0x0477, 0x08ED, 0x11D0, 0x11D3, 0x11D2, 0x11D9, 0x11D8, 0x000D,
2515 0x001F, 0x0012, 0x0005, 0x003D, 0x000C, 0x000E, 0x0022, 0x0078,
2516 ], [
2517 0x0005, 0x000C, 0x001B, 0x0000, 0x0006, 0x03E2, 0x3E3D, 0x000F,
2518 0x0034, 0x0003, 0x0002, 0x001E, 0x001D, 0x007D, 0x01F0, 0x07C6,
2519 0x3E3C, 0x3E3F, 0x3E3E, 0x3E39, 0x3E38, 0x3E3B, 0x3E3A, 0x0008,
2520 0x001C, 0x0002, 0x003F, 0x0035, 0x0009, 0x0001, 0x000E, 0x00F9,
2521 ], [
2522 0x0004, 0x000B, 0x0001, 0x000A, 0x001E, 0x00E0, 0x0E1E, 0x0071,
2523 0x0039, 0x0007, 0x0006, 0x000D, 0x000C, 0x0020, 0x01C2, 0x1C3F,
2524 0x1C3E, 0x0E19, 0x0E18, 0x0E1B, 0x0E1A, 0x0E1D, 0x0E1C, 0x0000,
2525 0x0009, 0x001D, 0x001F, 0x0011, 0x0005, 0x0001, 0x0043, 0x0042,
2526 ], [
2527 0x0004, 0x000D, 0x0007, 0x0002, 0x0014, 0x016C, 0x16D1, 0x02DF,
2528 0x016E, 0x0000, 0x0007, 0x002C, 0x002B, 0x02DE, 0x16D0, 0x16D3,
2529 0x16D2, 0x2DB5, 0x2DB4, 0x2DB7, 0x2DB6, 0x16D9, 0x16D8, 0x000C,
2530 0x002A, 0x005A, 0x001B, 0x001A, 0x0017, 0x000C, 0x05B7, 0x05B5,
2531 ], [
2532 0x0002, 0x000F, 0x001C, 0x000C, 0x003B, 0x01AC, 0x1AD8, 0x35B3,
2533 0x35B2, 0x0001, 0x0000, 0x0069, 0x0068, 0x35BD, 0x35BC, 0x35BF,
2534 0x35BE, 0x35B9, 0x35B8, 0x35BB, 0x35BA, 0x35B5, 0x35B4, 0x01A9,
2535 0x01A8, 0x035A, 0x00D7, 0x00D5, 0x003A, 0x001B, 0x35B7, 0x35B6,
2536 ]
2537 ];
2538
2539 const VP31_AC_CAT2_BITS: [[u8; 32]; 16] = [
2540 [
2541 4, 6, 8, 9, 10, 12, 13, 4, 7, 3, 4, 4, 4, 4, 4, 5,
2542 5, 5, 5, 6, 7, 11, 13, 4, 5, 6, 6, 7, 6, 6, 4, 5,
2543 ], [
2544 4, 6, 7, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 4, 4, 5,
2545 6, 6, 6, 8, 10, 12, 12, 4, 5, 6, 6, 6, 5, 6, 4, 5,
2546 ], [
2547 4, 5, 7, 6, 8, 10, 12, 5, 7, 3, 3, 4, 4, 4, 5, 5,
2548 6, 6, 7, 9, 12, 12, 12, 4, 5, 5, 6, 6, 5, 6, 4, 5,
2549 ], [
2550 3, 5, 6, 6, 8, 10, 13, 5, 7, 3, 3, 4, 4, 4, 5, 6,
2551 7, 7, 9, 11, 13, 13, 13, 4, 5, 5, 6, 6, 5, 6, 5, 5,
2552 ], [
2553 3, 5, 6, 5, 7, 9, 11, 6, 8, 3, 3, 4, 4, 5, 6, 7,
2554 8, 8, 10, 13, 13, 13, 13, 3, 5, 5, 5, 6, 5, 6, 5, 6,
2555 ], [
2556 3, 4, 5, 5, 6, 9, 11, 6, 9, 3, 3, 4, 4, 5, 7, 9,
2557 11, 11, 13, 14, 14, 13, 13, 3, 5, 5, 6, 6, 6, 6, 5, 6,
2558 ], [
2559 3, 4, 5, 4, 5, 7, 9, 7, 13, 3, 3, 4, 4, 6, 8, 10,
2560 13, 13, 13, 13, 13, 13, 13, 3, 5, 5, 6, 6, 6, 7, 6, 6,
2561 ], [
2562 3, 4, 5, 4, 4, 5, 7, 8, 13, 3, 3, 4, 4, 7, 12, 14,
2563 14, 14, 14, 14, 14, 13, 13, 3, 5, 5, 7, 6, 7, 9, 10, 7,
2564 ], [
2565 4, 6, 8, 8, 10, 12, 13, 5, 6, 3, 3, 4, 4, 4, 5, 6,
2566 7, 7, 8, 9, 13, 12, 12, 4, 4, 5, 5, 6, 5, 5, 4, 5,
2567 ], [
2568 3, 5, 7, 7, 10, 13, 14, 5, 6, 3, 3, 4, 4, 5, 6, 7,
2569 8, 9, 11, 13, 14, 14, 14, 4, 4, 5, 5, 6, 4, 5, 5, 6,
2570 ], [
2571 3, 5, 6, 6, 9, 13, 14, 6, 6, 3, 3, 4, 4, 5, 7, 8,
2572 10, 11, 13, 15, 15, 14, 14, 4, 5, 5, 5, 5, 4, 4, 5, 6,
2573 ], [
2574 3, 4, 5, 5, 8, 11, 13, 7, 6, 3, 3, 4, 4, 6, 7, 9,
2575 11, 12, 13, 13, 13, 13, 13, 4, 5, 5, 5, 6, 4, 4, 6, 7,
2576 ], [
2577 3, 4, 5, 4, 6, 10, 14, 7, 6, 3, 3, 5, 5, 7, 9, 11,
2578 14, 14, 14, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 3, 7, 8,
2579 ], [
2580 3, 4, 4, 4, 6, 9, 13, 8, 7, 3, 3, 5, 5, 7, 10, 14,
2581 14, 13, 13, 13, 13, 13, 13, 4, 5, 6, 6, 6, 4, 3, 8, 8,
2582 ], [
2583 3, 4, 4, 3, 5, 9, 13, 10, 9, 2, 3, 6, 6, 10, 13, 13,
2584 13, 14, 14, 14, 14, 13, 13, 5, 6, 7, 6, 6, 5, 4, 11, 11,
2585 ], [
2586 2, 4, 5, 4, 6, 9, 13, 14, 14, 2, 2, 7, 7, 14, 14, 14,
2587 14, 14, 14, 14, 14, 14, 14, 9, 9, 10, 8, 8, 6, 5, 14, 14,
2588 ]
2589 ];
2590
2591 const VP31_AC_CAT3_CODES: [[u16; 32]; 16] = [
2592 [
2593 0x0000, 0x0010, 0x0072, 0x0071, 0x0154, 0x0AAB, 0x0AA8, 0x0014,
2594 0x0070, 0x0002, 0x0003, 0x000C, 0x000B, 0x0003, 0x0011, 0x0073,
2595 0x0054, 0x00AB, 0x02AB, 0x1553, 0x1552, 0x1555, 0x1554, 0x000D,
2596 0x001E, 0x0012, 0x003E, 0x002B, 0x0002, 0x003F, 0x001D, 0x0013,
2597 ], [
2598 0x0003, 0x001F, 0x0029, 0x003D, 0x000C, 0x0069, 0x0345, 0x0002,
2599 0x0028, 0x0002, 0x0001, 0x000E, 0x000C, 0x0015, 0x0007, 0x001B,
2600 0x006B, 0x006A, 0x0344, 0x0347, 0x0346, 0x01A1, 0x01A0, 0x000B,
2601 0x001A, 0x0012, 0x0000, 0x003C, 0x0008, 0x001B, 0x0013, 0x0001,
2602 ], [
2603 0x0004, 0x0004, 0x003F, 0x0014, 0x0056, 0x015C, 0x15D5, 0x003C,
2604 0x002A, 0x0000, 0x0001, 0x000E, 0x000D, 0x000C, 0x00AF, 0x02BB,
2605 0x15D4, 0x15D7, 0x15D6, 0x15D1, 0x15D0, 0x15D3, 0x15D2, 0x000B,
2606 0x0019, 0x000D, 0x003E, 0x0031, 0x0007, 0x0005, 0x003D, 0x0030,
2607 ], [
2608 0x0005, 0x0008, 0x001A, 0x0000, 0x0036, 0x0011, 0x0106, 0x000A,
2609 0x006E, 0x0002, 0x0003, 0x0003, 0x0002, 0x006F, 0x0021, 0x020F,
2610 0x020E, 0x0101, 0x0100, 0x0103, 0x0102, 0x0105, 0x0104, 0x000C,
2611 0x001E, 0x0003, 0x003E, 0x003F, 0x0009, 0x000E, 0x000B, 0x0009,
2612 ], [
2613 0x0002, 0x000E, 0x001E, 0x000C, 0x001F, 0x006E, 0x00AD, 0x00AF,
2614 0x0014, 0x0004, 0x0003, 0x001A, 0x0017, 0x002A, 0x0576, 0x0AEF,
2615 0x0AEE, 0x0571, 0x0570, 0x0573, 0x0572, 0x0575, 0x0574, 0x0003,
2616 0x0016, 0x0004, 0x0036, 0x000B, 0x000A, 0x0000, 0x006F, 0x00AC,
2617 ], [
2618 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
2619 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
2620 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
2621 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
2622 ], [
2623 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
2624 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
2625 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
2626 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
2627 ], [
2628 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
2629 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
2630 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
2631 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
2632 ], [
2633 0x0003, 0x0011, 0x0020, 0x0074, 0x010D, 0x0863, 0x0860, 0x000A,
2634 0x0075, 0x0001, 0x0000, 0x000B, 0x000A, 0x0018, 0x0038, 0x0042,
2635 0x010F, 0x010E, 0x0219, 0x10C3, 0x10C2, 0x10C5, 0x10C4, 0x000F,
2636 0x0004, 0x0019, 0x000B, 0x0039, 0x0009, 0x001B, 0x001A, 0x003B,
2637 ], [
2638 0x0005, 0x0001, 0x003E, 0x0001, 0x00E2, 0x1C6F, 0x38D9, 0x0039,
2639 0x001F, 0x0002, 0x0001, 0x0009, 0x0008, 0x0000, 0x0070, 0x01C7,
2640 0x038C, 0x071A, 0x38D8, 0x38DB, 0x38DA, 0x38DD, 0x38DC, 0x000D,
2641 0x001D, 0x000E, 0x003F, 0x003C, 0x000C, 0x0006, 0x003D, 0x001E,
2642 ], [
2643 0x0006, 0x000B, 0x0011, 0x001E, 0x0074, 0x03AA, 0x1D5C, 0x0001,
2644 0x0021, 0x0001, 0x0002, 0x0007, 0x0006, 0x003E, 0x00EB, 0x01D4,
2645 0x0EAF, 0x3ABB, 0x3ABA, 0x1D59, 0x1D58, 0x1D5B, 0x1D5A, 0x000A,
2646 0x001C, 0x0001, 0x003F, 0x003B, 0x0001, 0x0009, 0x0020, 0x0000,
2647 ], [
2648 0x0004, 0x000A, 0x0017, 0x0004, 0x0016, 0x016A, 0x16B1, 0x0017,
2649 0x005B, 0x0006, 0x0007, 0x0001, 0x0000, 0x000A, 0x02D7, 0x0B5A,
2650 0x16B0, 0x16B3, 0x16B2, 0x2D6D, 0x2D6C, 0x2D6F, 0x2D6E, 0x0006,
2651 0x000A, 0x0004, 0x002C, 0x0017, 0x0003, 0x0007, 0x0016, 0x00B4,
2652 ], [
2653 0x0005, 0x000D, 0x0005, 0x0009, 0x0033, 0x0193, 0x192C, 0x0061,
2654 0x0031, 0x0000, 0x0007, 0x0010, 0x0011, 0x00C8, 0x192F, 0x325B,
2655 0x325A, 0x1929, 0x1928, 0x192B, 0x192A, 0x325D, 0x325C, 0x0018,
2656 0x001A, 0x001B, 0x0065, 0x0019, 0x0004, 0x0007, 0x0060, 0x0324,
2657 ], [
2658 0x0006, 0x0000, 0x0002, 0x000F, 0x0039, 0x01D9, 0x1D82, 0x0761,
2659 0x03BE, 0x0001, 0x0002, 0x000F, 0x000E, 0x0762, 0x3B07, 0x3B06,
2660 0x3B1D, 0x3B1C, 0x3B1F, 0x3B1E, 0x3B19, 0x3B18, 0x3B1B, 0x0038,
2661 0x01DE, 0x00ED, 0x03BF, 0x00EE, 0x003A, 0x0006, 0x0EC0, 0x3B1A,
2662 ], [
2663 0x0000, 0x0002, 0x000F, 0x0006, 0x001C, 0x01D0, 0x0E8C, 0x1D1B,
2664 0x1D1A, 0x0003, 0x0002, 0x00EA, 0x00E9, 0x0E89, 0x0E88, 0x0E8B,
2665 0x0E8A, 0x1D65, 0x1D64, 0x1D67, 0x1D66, 0x1D61, 0x1D60, 0x03AD,
2666 0x1D63, 0x1D62, 0x1D1D, 0x1D1C, 0x003B, 0x01D7, 0x1D1F, 0x1D1E,
2667 ], [
2668 0x0002, 0x000F, 0x001C, 0x000C, 0x003B, 0x01AC, 0x1AD8, 0x35B3,
2669 0x35B2, 0x0001, 0x0000, 0x0069, 0x0068, 0x35BD, 0x35BC, 0x35BF,
2670 0x35BE, 0x35B9, 0x35B8, 0x35BB, 0x35BA, 0x35B5, 0x35B4, 0x01A9,
2671 0x01A8, 0x035A, 0x00D7, 0x00D5, 0x003A, 0x001B, 0x35B7, 0x35B6,
2672 ]
2673 ];
2674
2675 const VP31_AC_CAT3_BITS: [[u8; 32]; 16] = [
2676 [
2677 3, 5, 7, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 4, 5, 7,
2678 7, 8, 10, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 6, 5, 5,
2679 ], [
2680 3, 5, 6, 6, 7, 10, 13, 5, 6, 3, 3, 4, 4, 5, 6, 8,
2681 10, 10, 13, 13, 13, 12, 12, 4, 5, 5, 5, 6, 4, 5, 5, 5,
2682 ], [
2683 3, 4, 6, 5, 7, 9, 13, 6, 6, 3, 3, 4, 4, 5, 8, 10,
2684 13, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 4, 6, 6,
2685 ], [
2686 3, 4, 5, 4, 6, 8, 12, 7, 7, 3, 3, 4, 4, 7, 9, 13,
2687 13, 12, 12, 12, 12, 12, 12, 4, 5, 5, 6, 6, 4, 4, 7, 7,
2688 ], [
2689 3, 4, 5, 4, 5, 7, 10, 10, 7, 3, 3, 5, 5, 8, 13, 14,
2690 14, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 3, 7, 10,
2691 ], [
2692 3, 4, 3, 3, 4, 6, 11, 13, 8, 3, 3, 6, 6, 13, 13, 13,
2693 13, 13, 13, 13, 14, 14, 14, 3, 6, 8, 9, 8, 6, 5, 12, 14,
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, 5, 6, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 5, 6, 7,
2702 9, 9, 10, 13, 13, 13, 13, 4, 4, 5, 5, 6, 4, 5, 5, 6,
2703 ], [
2704 3, 4, 6, 5, 8, 13, 14, 6, 6, 3, 3, 4, 4, 5, 7, 9,
2705 10, 11, 14, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 4, 6, 6,
2706 ], [
2707 3, 4, 5, 5, 7, 10, 13, 6, 6, 3, 3, 4, 4, 6, 8, 9,
2708 12, 14, 14, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 4, 6, 6,
2709 ], [
2710 3, 4, 5, 4, 6, 9, 13, 7, 7, 3, 3, 4, 4, 6, 10, 12,
2711 13, 13, 13, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 4, 7, 8,
2712 ], [
2713 3, 4, 4, 4, 6, 9, 13, 8, 7, 2, 3, 5, 5, 8, 13, 14,
2714 14, 13, 13, 13, 13, 14, 14, 5, 6, 6, 7, 6, 4, 4, 8, 10,
2715 ], [
2716 3, 3, 4, 4, 6, 9, 13, 11, 10, 2, 2, 6, 6, 11, 14, 14,
2717 14, 14, 14, 14, 14, 14, 14, 6, 9, 8, 10, 8, 6, 5, 12, 14,
2718 ], [
2719 2, 3, 5, 4, 6, 10, 13, 14, 14, 2, 2, 9, 9, 13, 13, 13,
2720 13, 14, 14, 14, 14, 14, 14, 11, 14, 14, 14, 14, 7, 10, 14, 14,
2721 ], [
2722 2, 4, 5, 4, 6, 9, 13, 14, 14, 2, 2, 7, 7, 14, 14, 14,
2723 14, 14, 14, 14, 14, 14, 14, 9, 9, 10, 8, 8, 6, 5, 14, 14,
2724 ]
2725 ];
2726
2727 const VP31_DC_WEIGHTS: [[i16; 5]; 16] = [
2728 [ 0, 0, 0, 0, 0 ],
2729 [ 1, 0, 0, 0, 1 ],
2730 [ 0, 1, 0, 0, 1 ],
2731 [ 1, 0, 0, 0, 1 ],
2732
2733 [ 0, 0, 1, 0, 1 ],
2734 [ 1, 0, 1, 0, 2 ],
2735 [ 0, 0, 1, 0, 1 ],
2736 [ 29, -26, 29, 0, 32 ],
2737
2738 [ 0, 0, 0, 1, 1 ],
2739 [ 75, 0, 0, 53, 128 ],
2740 [ 0, 1, 0, 1, 2 ],
2741 [ 75, 0, 0, 53, 128 ],
2742
2743 [ 0, 0, 1, 0, 1 ],
2744 [ 75, 0, 0, 53, 128 ],
2745 [ 0, 3, 10, 3, 16 ],
2746 [ 29, -26, 29, 0, 32 ],
2747 ];
2748
2749 const VP30_DC_SCALES: [i16; 64] = [
2750 24, 20, 20, 20, 20, 20, 20, 20,
2751 19, 19, 19, 19, 18, 18, 18, 18,
2752 17, 17, 17, 17, 16, 16, 15, 15,
2753 14, 14, 13, 13, 12, 12, 11, 11,
2754 10, 10, 9, 9, 8, 8, 7, 7,
2755 6, 6, 6, 6, 5, 5, 5, 5,
2756 4, 4, 4, 4, 3, 3, 3, 3,
2757 2, 2, 2, 2, 1, 1, 1, 1
2758 ];
2759
2760 const VP30_AC_SCALES: [i16; 64] = [
2761 3000, 2500, 2000, 1500, 1200, 1000, 900, 800,
2762 750, 700, 650, 630, 600, 550, 500, 450,
2763 410, 380, 350, 320, 290, 260, 240, 220,
2764 200, 180, 165, 150, 140, 130, 120, 115,
2765 110, 100, 95, 90, 85, 80, 75, 70,
2766 67, 65, 63, 61, 57, 55, 53, 50,
2767 49, 46, 44, 42, 39, 36, 33, 30,
2768 27, 24, 21, 19, 17, 15, 12, 10
2769 ];
2770
2771 const VP30_DC_CODES: [[u16; 32]; 5] = [
2772 [
2773 0x0005, 0x002D, 0x0004, 0x0009, 0x0088, 0x0225, 0x0224, 0x0005,
2774 0x0011, 0x0007, 0x0006, 0x0009, 0x000A, 0x0007, 0x0017, 0x000C,
2775 0x002C, 0x0005, 0x0008, 0x0003, 0x0012, 0x0010, 0x0113, 0x0003,
2776 0x0010, 0x0000, 0x0013, 0x001A, 0x0023, 0x0045, 0x0001, 0x001B
2777 ], [
2778 0x000B, 0x0012, 0x0029, 0x0010, 0x000D, 0x00A2, 0x0020, 0x0009,
2779 0x0050, 0x0007, 0x0006, 0x0006, 0x0005, 0x0002, 0x0008, 0x0027,
2780 0x0005, 0x0022, 0x0023, 0x0057, 0x00A3, 0x0011, 0x0021, 0x0007,
2781 0x0000, 0x0009, 0x002A, 0x0003, 0x0007, 0x0026, 0x000C, 0x0056
2782 ], [
2783 0x000D, 0x0018, 0x0009, 0x0017, 0x0033, 0x0056, 0x00F7, 0x00F1,
2784 0x007A, 0x0000, 0x0007, 0x0009, 0x0008, 0x0005, 0x000D, 0x002D,
2785 0x0010, 0x001D, 0x001C, 0x0057, 0x00CB, 0x00F6, 0x00F0, 0x0014,
2786 0x000C, 0x002C, 0x0011, 0x001F, 0x002A, 0x0064, 0x00CA, 0x0079
2787 ], [
2788 0x000F, 0x001A, 0x0013, 0x001B, 0x003B, 0x0072, 0x01D3, 0x0707,
2789 0x0E0D, 0x0001, 0x0000, 0x000C, 0x000B, 0x0008, 0x0012, 0x002A,
2790 0x0073, 0x0028, 0x0075, 0x0056, 0x0052, 0x01C0, 0x0E0C, 0x0071,
2791 0x0057, 0x00E1, 0x00A6, 0x00E8, 0x00A7, 0x03A5, 0x03A4, 0x0382
2792 ], [
2793 0x000F, 0x001B, 0x0014, 0x001D, 0x0010, 0x0073, 0x00E2, 0x023C,
2794 0x11C9, 0x0001, 0x0000, 0x000C, 0x000B, 0x0009, 0x0015, 0x0035,
2795 0x0072, 0x0034, 0x0022, 0x0070, 0x0046, 0x011D, 0x11C8, 0x01C7,
2796 0x01C6, 0x0238, 0x047E, 0x023E, 0x0473, 0x08E5, 0x023D, 0x047F
2797 ]
2798 ];
2799 const VP30_DC_BITS: [[u8; 32]; 5] = [
2800 [
2801 4, 6, 6, 6, 8, 10, 10, 6, 7, 3, 3, 4, 4, 4, 5, 5,
2802 6, 5, 5, 5, 6, 7, 9, 4, 5, 5, 6, 6, 6, 7, 5, 6
2803 ], [
2804 4, 5, 6, 5, 6, 8, 9, 7, 7, 3, 3, 4, 4, 4, 5, 6,
2805 6, 6, 6, 7, 8, 8, 9, 4, 4, 5, 6, 5, 5, 6, 6, 7
2806 ], [
2807 4, 5, 5, 5, 6, 7, 9, 9, 8, 2, 3, 4, 4, 4, 5, 6,
2808 6, 6, 6, 7, 8, 9, 9, 5, 5, 6, 6, 6, 6, 7, 8, 8
2809 ], [
2810 4, 5, 5, 5, 6, 7, 9, 11, 12, 2, 2, 4, 4, 4, 5, 6,
2811 7, 6, 7, 7, 7, 9, 12, 7, 7, 8, 8, 8, 8, 10, 10, 10
2812 ], [
2813 4, 5, 5, 5, 5, 7, 8, 10, 13, 2, 2, 4, 4, 4, 5, 6,
2814 7, 6, 6, 7, 7, 9, 13, 9, 9, 10, 11, 10, 11, 12, 10, 11
2815 ]
2816 ];
2817 const VP30_AC_INTRA_CODES: [[u16; 32]; 5] = [
2818 [
2819 0x0008, 0x0033, 0x0008, 0x004B, 0x0089, 0x0221, 0x0220, 0x001F,
2820 0x0045, 0x0000, 0x000E, 0x000B, 0x000A, 0x000D, 0x0006, 0x001E,
2821 0x000A, 0x0018, 0x0013, 0x0005, 0x0009, 0x0046, 0x0111, 0x0007,
2822 0x000B, 0x0032, 0x0010, 0x004A, 0x0024, 0x0047, 0x0003, 0x0009
2823 ], [
2824 0x000E, 0x000E, 0x007B, 0x001E, 0x007E, 0x03EF, 0x07DD, 0x0018,
2825 0x00FA, 0x0002, 0x0000, 0x000A, 0x0008, 0x000B, 0x0003, 0x0012,
2826 0x0033, 0x000C, 0x003C, 0x001A, 0x007F, 0x01F6, 0x07DC, 0x000D,
2827 0x0013, 0x0004, 0x001B, 0x007A, 0x0032, 0x007C, 0x001F, 0x0005
2828 ], [
2829 0x0000, 0x0018, 0x0034, 0x000C, 0x006A, 0x01F9, 0x07EA, 0x0016,
2830 0x0FD7, 0x0002, 0x0001, 0x000A, 0x0009, 0x0007, 0x001B, 0x003E,
2831 0x0020, 0x0021, 0x006B, 0x01FB, 0x03F4, 0x1FAD, 0x1FAC, 0x000E,
2832 0x0019, 0x0011, 0x002F, 0x007F, 0x002E, 0x01F8, 0x001E, 0x000D
2833 ], [
2834 0x000E, 0x0016, 0x002E, 0x0003, 0x006E, 0x008B, 0x0113, 0x0018,
2835 0x0221, 0x0001, 0x0002, 0x000A, 0x0009, 0x0007, 0x001A, 0x0002,
2836 0x001B, 0x0023, 0x006F, 0x008A, 0x0111, 0x0441, 0x0440, 0x000F,
2837 0x0019, 0x0010, 0x0036, 0x001A, 0x002F, 0x0112, 0x0000, 0x000C
2838 ], [
2839 0x000E, 0x000F, 0x001B, 0x0033, 0x005A, 0x00B6, 0x0008, 0x001A,
2840 0x004D, 0x0001, 0x0002, 0x000A, 0x0009, 0x0008, 0x001B, 0x0003,
2841 0x002C, 0x002E, 0x0005, 0x00B7, 0x0027, 0x0099, 0x0098, 0x000F,
2842 0x0018, 0x000E, 0x002F, 0x001A, 0x0032, 0x0012, 0x0000, 0x000C
2843 ]
2844 ];
2845 const VP30_AC_INTRA_BITS: [[u8; 32]; 5] = [
2846 [
2847 4, 6, 6, 7, 9, 11, 11, 5, 8, 3, 4, 4, 4, 4, 4, 5,
2848 5, 5, 5, 5, 6, 8, 10, 4, 5, 6, 6, 7, 6, 8, 4, 5
2849 ], [
2850 4, 5, 7, 6, 8, 11, 12, 5, 9, 3, 3, 4, 4, 4, 4, 5,
2851 6, 5, 6, 6, 8, 10, 12, 4, 5, 5, 6, 7, 6, 8, 5, 5
2852 ], [
2853 3, 5, 6, 5, 7, 9, 11, 5, 12, 3, 3, 4, 4, 4, 5, 6,
2854 6, 6, 7, 9, 10, 13, 13, 4, 5, 5, 6, 7, 6, 9, 5, 5
2855 ], [
2856 4, 5, 6, 5, 7, 8, 9, 5, 10, 3, 3, 4, 4, 4, 5, 5,
2857 6, 6, 7, 8, 9, 11, 11, 4, 5, 5, 6, 6, 6, 9, 4, 5
2858 ], [
2859 4, 5, 6, 6, 7, 8, 7, 5, 10, 3, 3, 4, 4, 4, 5, 5,
2860 6, 6, 6, 8, 9, 11, 11, 4, 5, 5, 6, 6, 6, 8, 4, 5
2861 ]
2862 ];
2863 const VP30_AC_INTER_CODES: [[u16; 32]; 5] = [
2864 [
2865 0x000D, 0x0038, 0x0061, 0x0060, 0x0393, 0x1C95, 0x1C94, 0x0014,
2866 0x0073, 0x0001, 0x0000, 0x000B, 0x0009, 0x001D, 0x000E, 0x0022,
2867 0x0046, 0x0047, 0x00E5, 0x01C8, 0x0724, 0x1C97, 0x1C96, 0x000F,
2868 0x0006, 0x0019, 0x000F, 0x0031, 0x0004, 0x0010, 0x0005, 0x0015
2869 ], [
2870 0x0004, 0x001B, 0x0030, 0x0034, 0x00D5, 0x06B3, 0x3595, 0x0031,
2871 0x001A, 0x0002, 0x0001, 0x001F, 0x001E, 0x000C, 0x001B, 0x00D7,
2872 0x00D4, 0x01AD, 0x0358, 0x0D64, 0x3594, 0x3597, 0x3596, 0x0000,
2873 0x000A, 0x001D, 0x0017, 0x0039, 0x0007, 0x0019, 0x0016, 0x0038
2874 ], [
2875 0x0005, 0x0009, 0x001A, 0x001E, 0x001F, 0x00E2, 0x038E, 0x0070,
2876 0x003B, 0x0001, 0x0000, 0x0019, 0x0018, 0x001E, 0x003A, 0x01C6,
2877 0x071E, 0x0E3E, 0x1C7E, 0x71FD, 0x71FC, 0x71FF, 0x71FE, 0x0002,
2878 0x0008, 0x001D, 0x001B, 0x0039, 0x001F, 0x000D, 0x000C, 0x001C
2879 ], [
2880 0x0003, 0x000B, 0x001C, 0x000D, 0x0004, 0x000A, 0x0076, 0x00E8,
2881 0x01DC, 0x0001, 0x0000, 0x0033, 0x0032, 0x00E9, 0x03BB, 0x0774,
2882 0x1DD5, 0x3BAD, 0x3BAC, 0x3BAF, 0x3BAE, 0x3BA9, 0x3BA8, 0x0004,
2883 0x000A, 0x001F, 0x001E, 0x0030, 0x000B, 0x0075, 0x0031, 0x00EF
2884 ], [
2885 0x0009, 0x001E, 0x000F, 0x000E, 0x000C, 0x0008, 0x0001, 0x00E3,
2886 0x00E2, 0x0002, 0x0000, 0x003A, 0x0039, 0x0070, 0x01DC, 0x0776,
2887 0x0775, 0x0EEF, 0x0EE8, 0x1DD3, 0x1DD2, 0x1DDD, 0x1DDC, 0x0005,
2888 0x001F, 0x001B, 0x0006, 0x006A, 0x0034, 0x0076, 0x006B, 0x00EF
2889 ]
2890 ];
2891 const VP30_AC_INTER_BITS: [[u8; 32]; 5] = [
2892 [
2893 4, 6, 7, 7, 10, 13, 13, 5, 7, 3, 3, 4, 4, 5, 5, 6,
2894 7, 7, 8, 9, 11, 13, 13, 4, 4, 5, 5, 6, 4, 5, 4, 5
2895 ], [
2896 3, 5, 6, 6, 8, 11, 14, 6, 6, 3, 3, 5, 5, 5, 6, 8,
2897 8, 9, 10, 12, 14, 14, 14, 3, 4, 5, 5, 6, 4, 5, 5, 6
2898 ], [
2899 3, 4, 5, 5, 6, 8, 10, 7, 7, 3, 3, 5, 5, 6, 7, 9,
2900 11, 12, 13, 15, 15, 15, 15, 3, 4, 5, 5, 6, 5, 5, 5, 6
2901 ], [
2902 3, 4, 5, 4, 4, 5, 7, 8, 9, 3, 3, 6, 6, 8, 10, 11,
2903 13, 14, 14, 14, 14, 14, 14, 3, 4, 5, 5, 6, 5, 7, 6, 8
2904 ], [
2905 4, 5, 5, 4, 4, 4, 3, 9, 9, 3, 3, 7, 7, 8, 10, 12,
2906 12, 13, 13, 14, 14, 14, 14, 3, 5, 5, 4, 7, 6, 8, 7, 9
2907 ]
2908 ];
2909 const VP30_MBTYPE_CODES: [u8; 7] = [ 0x00, 0x08, 0x0A, 0x03, 0x0B, 0x13, 0x12 ];
2910 const VP30_MBTYPE_BITS: [u8; 7] = [ 1, 4, 4, 2, 4, 5, 5 ];
2911 const VP30_MBTYPE_SYMS: [VPMBType; 7] = [
2912 VPMBType::InterNoMV, VPMBType::Intra, VPMBType::InterMV, VPMBType::InterNearest,
2913 VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
2914 ];
2915
2916 const VP40_DC_CODES: [[u32; 32]; 16] = [
2917 [
2918 0x000C, 0x0070, 0x01CA, 0x01CB, 0x0391, 0x1C9B, 0x3935, 0x0071,
2919 0x3934, 0x000B, 0x000F, 0x0019, 0x0002, 0x0009, 0x0003, 0x001D,
2920 0x0018, 0x0007, 0x000D, 0x0002, 0x0000, 0x000A, 0x0008, 0x001A,
2921 0x0073, 0x006F, 0x0E4C, 0x0727, 0x0392, 0x0390, 0x0036, 0x006E
2922 ], [
2923 0x0011, 0x007A, 0x0083, 0x0040, 0x0105, 0x0413, 0x0410, 0x007B,
2924 0x0822, 0x000E, 0x0002, 0x0002, 0x0006, 0x000A, 0x0007, 0x001F,
2925 0x0017, 0x0009, 0x000D, 0x0000, 0x000C, 0x0003, 0x003C, 0x002C,
2926 0x0021, 0x0169, 0x0412, 0x02D0, 0x02D1, 0x0823, 0x005B, 0x00B5
2927 ], [
2928 0x0017, 0x0010, 0x00B6, 0x0022, 0x016A, 0x02D0, 0x0B48, 0x0077,
2929 0x1692, 0x0000, 0x0003, 0x0003, 0x0009, 0x000C, 0x0005, 0x0002,
2930 0x001C, 0x0008, 0x000D, 0x000F, 0x000A, 0x0009, 0x0023, 0x003A,
2931 0x002C, 0x016B, 0x05A5, 0x02D3, 0x02D1, 0x1693, 0x0076, 0x00B7
2932 ], [
2933 0x001E, 0x0013, 0x00FB, 0x007C, 0x0046, 0x07D6, 0x0FA9, 0x0012,
2934 0x1F50, 0x0001, 0x0004, 0x0005, 0x000A, 0x000E, 0x0007, 0x0000,
2935 0x0017, 0x0006, 0x000D, 0x000C, 0x0001, 0x002C, 0x008F, 0x003F,
2936 0x002D, 0x01F4, 0x07D5, 0x008E, 0x07D7, 0x1F51, 0x0010, 0x0022
2937 ], [
2938 0x0001, 0x002B, 0x0012, 0x0055, 0x0027, 0x03B0, 0x0762, 0x0077,
2939 0x0261, 0x0002, 0x0006, 0x0007, 0x000B, 0x000F, 0x0008, 0x0000,
2940 0x001C, 0x0003, 0x0009, 0x0006, 0x0014, 0x0054, 0x0131, 0x0005,
2941 0x003A, 0x01D9, 0x0099, 0x004D, 0x0763, 0x0260, 0x0008, 0x00ED
2942 ], [
2943 0x0004, 0x0033, 0x0060, 0x0065, 0x00C2, 0x030D, 0x0619, 0x0064,
2944 0x1862, 0x0004, 0x0007, 0x000A, 0x000B, 0x000D, 0x0006, 0x0000,
2945 0x000F, 0x0003, 0x0005, 0x0002, 0x0002, 0x0077, 0x0C30, 0x0003,
2946 0x0031, 0x0187, 0x01D9, 0x00ED, 0x01D8, 0x1863, 0x001C, 0x003A
2947 ], [
2948 0x0008, 0x000A, 0x006A, 0x0016, 0x001E, 0x034E, 0x069F, 0x0068,
2949 0x0D28, 0x0005, 0x0007, 0x0007, 0x000C, 0x0000, 0x0006, 0x001B,
2950 0x0012, 0x0002, 0x0004, 0x0013, 0x000E, 0x034B, 0x1A53, 0x0006,
2951 0x0017, 0x01A6, 0x069E, 0x01A4, 0x0695, 0x1A52, 0x006B, 0x001F
2952 ], [
2953 0x000E, 0x000F, 0x0017, 0x0025, 0x009F, 0x0138, 0x024B, 0x0093,
2954 0x092A, 0x0005, 0x0000, 0x0008, 0x000D, 0x000F, 0x0006, 0x0004,
2955 0x000E, 0x0019, 0x0018, 0x000A, 0x009E, 0x0494, 0x1256, 0x0026,
2956 0x0016, 0x0124, 0x04E5, 0x0273, 0x04E4, 0x1257, 0x0048, 0x009D
2957 ], [
2958 0x0004, 0x002C, 0x0050, 0x001E, 0x0071, 0x00E1, 0x00E0, 0x001D,
2959 0x0006, 0x0007, 0x0006, 0x0007, 0x0005, 0x0006, 0x0015, 0x0000,
2960 0x0029, 0x0002, 0x0006, 0x0001, 0x0023, 0x001F, 0x0039, 0x0009,
2961 0x0002, 0x0010, 0x0007, 0x002D, 0x002F, 0x002E, 0x0022, 0x0051
2962 ], [
2963 0x0008, 0x002F, 0x0051, 0x0050, 0x02ED, 0x05D9, 0x05D8, 0x00BA,
2964 0x005C, 0x0007, 0x0006, 0x0009, 0x0006, 0x0007, 0x0016, 0x0005,
2965 0x002B, 0x0006, 0x000A, 0x0001, 0x000F, 0x001D, 0x0177, 0x0004,
2966 0x0001, 0x0004, 0x0001, 0x002A, 0x000B, 0x0029, 0x0000, 0x001C
2967 ], [
2968 0x000A, 0x003C, 0x0074, 0x004E, 0x026D, 0x04D9, 0x04D8, 0x009A,
2969 0x004C, 0x0000, 0x0006, 0x0008, 0x0007, 0x0006, 0x0016, 0x0008,
2970 0x002E, 0x000A, 0x000B, 0x003D, 0x0024, 0x00EB, 0x0137, 0x001F,
2971 0x001C, 0x003B, 0x0012, 0x0025, 0x002F, 0x0013, 0x004F, 0x00EA
2972 ], [
2973 0x000A, 0x000A, 0x0003, 0x0016, 0x0009, 0x0021, 0x0020, 0x00B3,
2974 0x0058, 0x0007, 0x0006, 0x0007, 0x0006, 0x0004, 0x0013, 0x0002,
2975 0x0025, 0x0000, 0x0003, 0x002D, 0x005D, 0x00B2, 0x0011, 0x0008,
2976 0x0002, 0x0006, 0x0017, 0x002F, 0x0007, 0x0024, 0x005C, 0x0005
2977 ], [
2978 0x000B, 0x0013, 0x001F, 0x0031, 0x0021, 0x0295, 0x0528, 0x00A4,
2979 0x003C, 0x0000, 0x0007, 0x0006, 0x0005, 0x001B, 0x0012, 0x0032,
2980 0x001D, 0x002B, 0x0030, 0x001C, 0x003D, 0x014B, 0x0529, 0x0008,
2981 0x001A, 0x0033, 0x0011, 0x002A, 0x0009, 0x0028, 0x0053, 0x0020
2982 ], [
2983 0x000E, 0x0015, 0x0029, 0x003F, 0x004D, 0x02F1, 0x05E0, 0x0092,
2984 0x0048, 0x0000, 0x0006, 0x0006, 0x0005, 0x0004, 0x000F, 0x002E,
2985 0x001D, 0x0028, 0x0027, 0x005F, 0x00BD, 0x0179, 0x05E1, 0x0008,
2986 0x001E, 0x002D, 0x001C, 0x002C, 0x003E, 0x0025, 0x004C, 0x0093
2987 ], [
2988 0x000C, 0x0017, 0x0035, 0x0013, 0x0021, 0x00AD, 0x06F1, 0x01BD,
2989 0x00D9, 0x0000, 0x0007, 0x0007, 0x0006, 0x0004, 0x0011, 0x002A,
2990 0x006E, 0x0025, 0x0024, 0x0057, 0x00D8, 0x0379, 0x06F0, 0x0005,
2991 0x0016, 0x0029, 0x006D, 0x0028, 0x0034, 0x0020, 0x00DF, 0x00AC
2992 ], [
2993 0x0000, 0x001A, 0x0006, 0x0019, 0x0030, 0x005A, 0x018A, 0x02DD,
2994 0x018B, 0x0001, 0x0007, 0x000A, 0x0009, 0x0002, 0x0010, 0x002E,
2995 0x006E, 0x002C, 0x000E, 0x005E, 0x00C4, 0x05B9, 0x05B8, 0x0011,
2996 0x0036, 0x005F, 0x001E, 0x0063, 0x006F, 0x001F, 0x00B6, 0x016F
2997 ]
2998 ];
2999 const VP40_DC_BITS: [[u8; 32]; 16] = [
3000 [
3001 5, 7, 9, 9, 10, 13, 14, 7, 14, 4, 4, 5, 4, 4, 4, 5,
3002 5, 4, 4, 3, 3, 4, 4, 6, 7, 8, 12, 11, 10, 10, 7, 8
3003 ], [
3004 5, 7, 8, 7, 9, 11, 11, 7, 12, 4, 3, 4, 4, 4, 4, 5,
3005 5, 4, 4, 3, 4, 4, 6, 6, 6, 9, 11, 10, 10, 12, 7, 8
3006 ], [
3007 5, 6, 8, 7, 9, 10, 12, 7, 13, 3, 3, 4, 4, 4, 4, 4,
3008 5, 4, 4, 4, 4, 5, 7, 6, 6, 9, 11, 10, 10, 13, 7, 8
3009 ], [
3010 5, 6, 8, 7, 8, 11, 12, 6, 13, 3, 3, 4, 4, 4, 4, 4,
3011 5, 4, 4, 4, 4, 6, 9, 6, 6, 9, 11, 9, 11, 13, 6, 7
3012 ], [
3013 4, 6, 7, 7, 8, 10, 11, 7, 12, 3, 3, 4, 4, 4, 4, 4,
3014 5, 4, 4, 4, 5, 7, 11, 5, 6, 9, 10, 9, 11, 12, 6, 8
3015 ], [
3016 4, 6, 7, 7, 8, 10, 11, 7, 13, 3, 3, 4, 4, 4, 4, 4,
3017 5, 4, 4, 4, 5, 8, 12, 5, 6, 9, 10, 9, 10, 13, 6, 7
3018 ], [
3019 4, 5, 7, 6, 7, 10, 11, 7, 12, 3, 3, 4, 4, 3, 4, 5,
3020 5, 4, 4, 5, 6, 10, 13, 5, 6, 9, 11, 9, 11, 13, 7, 7
3021 ], [
3022 4, 5, 6, 6, 8, 9, 10, 8, 12, 3, 2, 4, 4, 4, 4, 4,
3023 5, 5, 5, 5, 8, 11, 13, 6, 6, 9, 11, 10, 11, 13, 7, 8
3024 ], [
3025 4, 6, 7, 7, 9, 10, 10, 7, 6, 3, 3, 4, 4, 4, 5, 5,
3026 6, 5, 5, 5, 6, 7, 8, 4, 4, 5, 6, 6, 6, 6, 6, 7
3027 ], [
3028 4, 6, 7, 7, 10, 11, 11, 8, 7, 3, 3, 4, 4, 4, 5, 5,
3029 6, 5, 5, 5, 6, 7, 9, 4, 4, 5, 6, 6, 5, 6, 6, 7
3030 ], [
3031 4, 6, 7, 7, 10, 11, 11, 8, 7, 2, 3, 4, 4, 4, 5, 5,
3032 6, 5, 5, 6, 6, 8, 9, 5, 5, 6, 6, 6, 6, 6, 7, 8
3033 ], [
3034 4, 5, 6, 6, 8, 10, 10, 8, 7, 3, 3, 4, 4, 4, 5, 5,
3035 6, 5, 5, 6, 7, 8, 9, 4, 4, 5, 6, 6, 5, 6, 7, 7
3036 ], [
3037 4, 5, 6, 6, 7, 10, 11, 8, 7, 2, 3, 4, 4, 5, 5, 6,
3038 6, 6, 6, 6, 7, 9, 11, 4, 5, 6, 6, 6, 5, 6, 7, 7
3039 ], [
3040 4, 5, 6, 6, 7, 10, 11, 8, 7, 2, 3, 4, 4, 4, 5, 6,
3041 6, 6, 6, 7, 8, 9, 11, 4, 5, 6, 6, 6, 6, 6, 7, 8
3042 ], [
3043 4, 5, 6, 5, 6, 8, 11, 9, 8, 2, 3, 4, 4, 4, 5, 6,
3044 7, 6, 6, 7, 8, 10, 11, 4, 5, 6, 7, 6, 6, 6, 8, 8
3045 ], [
3046 3, 5, 5, 5, 6, 7, 9, 10, 9, 2, 3, 4, 4, 4, 5, 6,
3047 7, 6, 6, 7, 8, 11, 11, 5, 6, 7, 7, 7, 7, 7, 8, 9
3048 ]
3049 ];
3050 const VP40_AC_CAT0_CODES: [[u32; 32]; 16] = [
3051 [
3052 0x0006, 0x001E, 0x01CC, 0x01CE, 0x0734, 0x1CD5, 0x1CD4, 0x0018,
3053 0x0E6B, 0x0000, 0x000F, 0x0006, 0x0007, 0x000D, 0x0008, 0x0002,
3054 0x0019, 0x0005, 0x000B, 0x000A, 0x001D, 0x0027, 0x01CF, 0x0004,
3055 0x0038, 0x000E, 0x004C, 0x001F, 0x004D, 0x039B, 0x0012, 0x0072
3056 ], [
3057 0x0009, 0x004B, 0x0090, 0x0091, 0x0745, 0x1D11, 0x1D10, 0x0019,
3058 0x0E89, 0x0000, 0x000F, 0x0008, 0x0007, 0x000D, 0x000B, 0x0002,
3059 0x001C, 0x0003, 0x000A, 0x0005, 0x0018, 0x0010, 0x01D0, 0x0006,
3060 0x003B, 0x0011, 0x004A, 0x0049, 0x00E9, 0x03A3, 0x0013, 0x0075
3061 ], [
3062 0x0019, 0x0074, 0x001D, 0x00EA, 0x0073, 0x01CA, 0x0396, 0x001C,
3063 0x00E4, 0x0002, 0x0001, 0x0007, 0x0008, 0x000D, 0x0009, 0x001F,
3064 0x0018, 0x0000, 0x0006, 0x001E, 0x003B, 0x00EB, 0x0397, 0x000A,
3065 0x0002, 0x002C, 0x005B, 0x005A, 0x000F, 0x0038, 0x0017, 0x0006
3066 ], [
3067 0x001E, 0x006F, 0x00AE, 0x00AF, 0x0187, 0x061B, 0x0C35, 0x001A,
3068 0x030C, 0x0002, 0x0001, 0x0007, 0x0008, 0x000E, 0x0009, 0x001F,
3069 0x0014, 0x0000, 0x0001, 0x0019, 0x002A, 0x0060, 0x0C34, 0x000B,
3070 0x000D, 0x0036, 0x006E, 0x0056, 0x0031, 0x00C2, 0x0018, 0x0019
3071 ], [
3072 0x0001, 0x002C, 0x0005, 0x0015, 0x0008, 0x0097, 0x012D, 0x0017,
3073 0x004A, 0x0003, 0x0002, 0x0009, 0x000A, 0x000E, 0x0008, 0x001F,
3074 0x0007, 0x001E, 0x001B, 0x0004, 0x005A, 0x0024, 0x012C, 0x000C,
3075 0x0006, 0x0000, 0x0003, 0x005B, 0x0014, 0x0013, 0x001A, 0x000B
3076 ], [
3077 0x0004, 0x0000, 0x0017, 0x0063, 0x018B, 0x0310, 0x0C44, 0x0019,
3078 0x0623, 0x0004, 0x0003, 0x000A, 0x000B, 0x000D, 0x0003, 0x001C,
3079 0x0003, 0x000A, 0x0004, 0x0003, 0x018A, 0x188B, 0x188A, 0x000F,
3080 0x000B, 0x0002, 0x000A, 0x0002, 0x0016, 0x0189, 0x001D, 0x0030
3081 ], [
3082 0x000D, 0x0003, 0x0077, 0x000D, 0x0082, 0x020D, 0x0830, 0x0019,
3083 0x0419, 0x0003, 0x0002, 0x000A, 0x0009, 0x000B, 0x0002, 0x0011,
3084 0x0039, 0x0002, 0x0021, 0x0040, 0x1063, 0x20C5, 0x20C4, 0x000F,
3085 0x0018, 0x0007, 0x0038, 0x000C, 0x0076, 0x0107, 0x0000, 0x003A
3086 ], [
3087 0x000F, 0x001C, 0x0036, 0x0008, 0x0061, 0x0091, 0x0243, 0x0009,
3088 0x0120, 0x0005, 0x0003, 0x0008, 0x0005, 0x0001, 0x0013, 0x0031,
3089 0x0076, 0x0060, 0x0093, 0x0909, 0x0908, 0x090B, 0x090A, 0x0001,
3090 0x001A, 0x0019, 0x003A, 0x0025, 0x0077, 0x0092, 0x0000, 0x0037
3091 ], [
3092 0x001F, 0x0079, 0x00F1, 0x00F0, 0x011B, 0x0469, 0x0468, 0x003B,
3093 0x0022, 0x0005, 0x0004, 0x0007, 0x0005, 0x0006, 0x001C, 0x0001,
3094 0x0035, 0x003D, 0x003A, 0x0010, 0x0047, 0x008C, 0x0235, 0x0001,
3095 0x0001, 0x0019, 0x0000, 0x0030, 0x0009, 0x0031, 0x001B, 0x0034
3096 ], [
3097 0x0003, 0x001B, 0x00F3, 0x00FD, 0x03C9, 0x0F20, 0x1E42, 0x003D,
3098 0x00FC, 0x0006, 0x0004, 0x0002, 0x0000, 0x0001, 0x0017, 0x003E,
3099 0x001A, 0x0039, 0x002B, 0x0078, 0x01E5, 0x0791, 0x1E43, 0x0002,
3100 0x0007, 0x001D, 0x000C, 0x0038, 0x0014, 0x007F, 0x0016, 0x002A
3101 ], [
3102 0x0007, 0x0039, 0x0051, 0x0078, 0x03CB, 0x0F29, 0x1E51, 0x003D,
3103 0x00F3, 0x0006, 0x0004, 0x0002, 0x0000, 0x0001, 0x0017, 0x003E,
3104 0x007F, 0x002B, 0x007E, 0x0050, 0x01E4, 0x0795, 0x1E50, 0x0002,
3105 0x0006, 0x001D, 0x0006, 0x0038, 0x0007, 0x0029, 0x0016, 0x002A
3106 ], [
3107 0x0008, 0x003B, 0x001D, 0x0072, 0x01CC, 0x0734, 0x1CD5, 0x003A,
3108 0x001C, 0x0006, 0x0005, 0x0002, 0x0001, 0x0000, 0x0012, 0x003E,
3109 0x007F, 0x001E, 0x007E, 0x00E7, 0x039B, 0x0E6B, 0x1CD4, 0x0002,
3110 0x0006, 0x001E, 0x000E, 0x0038, 0x0006, 0x000F, 0x0013, 0x001F
3111 ], [
3112 0x000D, 0x003F, 0x0073, 0x000C, 0x00E4, 0x072B, 0x0E54, 0x003A,
3113 0x001A, 0x0005, 0x0004, 0x0002, 0x0001, 0x0000, 0x0007, 0x0038,
3114 0x0076, 0x0077, 0x001B, 0x01CB, 0x0394, 0x1CAB, 0x1CAA, 0x0002,
3115 0x0006, 0x001E, 0x000E, 0x003E, 0x0019, 0x001F, 0x0018, 0x001E
3116 ], [
3117 0x000E, 0x0007, 0x000C, 0x001C, 0x00BD, 0x02F3, 0x0BC9, 0x001F,
3118 0x00BF, 0x0006, 0x0004, 0x0002, 0x0001, 0x001E, 0x0001, 0x000D,
3119 0x003A, 0x003B, 0x00BE, 0x0178, 0x05E5, 0x1791, 0x1790, 0x0002,
3120 0x0006, 0x001F, 0x0016, 0x0000, 0x0015, 0x002E, 0x0014, 0x001E
3121 ], [
3122 0x0000, 0x001B, 0x0031, 0x003A, 0x0060, 0x006F, 0x01B9, 0x000E,
3123 0x001A, 0x0005, 0x0003, 0x0002, 0x001F, 0x001A, 0x0039, 0x000C,
3124 0x00C3, 0x00C2, 0x0036, 0x00DD, 0x0370, 0x06E3, 0x06E2, 0x0002,
3125 0x0008, 0x001E, 0x0019, 0x003B, 0x0012, 0x000F, 0x0013, 0x0038
3126 ], [
3127 0x0002, 0x0000, 0x0003, 0x001C, 0x0032, 0x001C, 0x0199, 0x0004,
3128 0x00CD, 0x0004, 0x0003, 0x001B, 0x001A, 0x003D, 0x0067, 0x003B,
3129 0x0198, 0x0075, 0x00E9, 0x03A1, 0x03A0, 0x03A3, 0x03A2, 0x0005,
3130 0x0002, 0x001F, 0x001D, 0x003C, 0x0018, 0x000F, 0x0006, 0x0005
3131 ]
3132 ];
3133 const VP40_AC_CAT0_BITS: [[u8; 32]; 16] = [
3134 [
3135 5, 7, 9, 9, 11, 13, 13, 5, 12, 3, 4, 4, 4, 4, 4, 4,
3136 5, 4, 4, 4, 5, 6, 9, 4, 6, 6, 7, 7, 7, 10, 5, 7
3137 ], [
3138 5, 7, 8, 8, 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, 8, 10, 5, 7
3140 ], [
3141 5, 7, 8, 8, 10, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3142 5, 4, 4, 5, 6, 8, 13, 4, 5, 6, 7, 7, 7, 9, 5, 6
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 4, 6, 7, 7, 8, 12, 13, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3148 5, 5, 5, 5, 7, 10, 13, 4, 5, 5, 6, 7, 7, 9, 5, 6
3149 ], [
3150 4, 5, 7, 7, 9, 10, 12, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3151 5, 5, 5, 6, 9, 13, 13, 4, 5, 5, 6, 6, 7, 9, 5, 6
3152 ], [
3153 4, 5, 7, 6, 8, 10, 12, 5, 11, 3, 3, 4, 4, 4, 4, 5,
3154 6, 5, 6, 7, 13, 14, 14, 4, 5, 5, 6, 6, 7, 9, 4, 6
3155 ], [
3156 4, 5, 6, 5, 7, 8, 10, 5, 9, 3, 3, 4, 4, 4, 5, 6,
3157 7, 7, 8, 12, 12, 12, 12, 3, 5, 5, 6, 6, 7, 8, 4, 6
3158 ], [
3159 5, 7, 8, 8, 10, 12, 12, 6, 7, 3, 3, 4, 4, 4, 5, 5,
3160 6, 6, 6, 6, 8, 9, 11, 3, 4, 5, 5, 6, 5, 6, 5, 6
3161 ], [
3162 4, 6, 8, 8, 10, 12, 13, 6, 8, 3, 3, 4, 4, 4, 5, 6,
3163 6, 6, 6, 7, 9, 11, 13, 3, 4, 5, 5, 6, 5, 7, 5, 6
3164 ], [
3165 4, 6, 7, 7, 10, 12, 13, 6, 8, 3, 3, 4, 4, 4, 5, 6,
3166 7, 6, 7, 7, 9, 11, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3167 ], [
3168 4, 6, 7, 7, 9, 11, 13, 6, 7, 3, 3, 4, 4, 4, 5, 6,
3169 7, 6, 7, 8, 10, 12, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3170 ], [
3171 4, 6, 7, 6, 8, 11, 12, 6, 7, 3, 3, 4, 4, 4, 5, 6,
3172 7, 7, 7, 9, 10, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3173 ], [
3174 4, 5, 6, 6, 8, 10, 12, 6, 8, 3, 3, 4, 4, 5, 5, 6,
3175 7, 7, 8, 9, 11, 13, 13, 3, 4, 5, 5, 5, 5, 6, 5, 6
3176 ], [
3177 3, 5, 6, 6, 7, 9, 11, 6, 7, 3, 3, 4, 5, 5, 6, 6,
3178 8, 8, 8, 10, 12, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6
3179 ], [
3180 3, 4, 5, 5, 6, 7, 9, 6, 8, 3, 3, 5, 5, 6, 7, 8,
3181 9, 9, 10, 12, 12, 12, 12, 3, 4, 5, 5, 6, 5, 6, 5, 6
3182 ]
3183 ];
3184 const VP40_AC_CAT1_CODES: [[u32; 32]; 16] = [
3185 [
3186 0x0004, 0x00F5, 0x0182, 0x060F, 0x1839, 0x1838, 0x183B, 0x0013,
3187 0x00C0, 0x0003, 0x0002, 0x000B, 0x000A, 0x000E, 0x0008, 0x0001,
3188 0x0012, 0x001F, 0x0000, 0x0006, 0x007B, 0x0306, 0x183A, 0x000D,
3189 0x0007, 0x0031, 0x000A, 0x0061, 0x003C, 0x00F4, 0x0019, 0x000B
3190 ], [
3191 0x000A, 0x001A, 0x01D8, 0x03B3, 0x0ECA, 0x1D96, 0x3B2F, 0x0014,
3192 0x0036, 0x0004, 0x0003, 0x000C, 0x000B, 0x0000, 0x0004, 0x001C,
3193 0x0005, 0x0015, 0x0007, 0x0017, 0x0037, 0x0764, 0x3B2E, 0x000F,
3194 0x001A, 0x003A, 0x000C, 0x0077, 0x0004, 0x00ED, 0x001B, 0x0016
3195 ], [
3196 0x001A, 0x002D, 0x0058, 0x01F4, 0x07D4, 0x1F55, 0x1F54, 0x0014,
3197 0x0059, 0x0004, 0x0003, 0x000B, 0x000C, 0x000E, 0x0004, 0x0015,
3198 0x0005, 0x0007, 0x0004, 0x007C, 0x03EB, 0x1F57, 0x1F56, 0x0000,
3199 0x001B, 0x003F, 0x000D, 0x000C, 0x000A, 0x00FB, 0x001E, 0x0017
3200 ], [
3201 0x0000, 0x0075, 0x004A, 0x0097, 0x025B, 0x0969, 0x0968, 0x000B,
3202 0x00E8, 0x0005, 0x0004, 0x0007, 0x000C, 0x000D, 0x0001, 0x000A,
3203 0x0039, 0x003B, 0x0018, 0x00E9, 0x012C, 0x096B, 0x096A, 0x0001,
3204 0x001F, 0x0008, 0x0019, 0x0013, 0x000D, 0x0024, 0x001E, 0x0038
3205 ], [
3206 0x0004, 0x0014, 0x006E, 0x0057, 0x0159, 0x0562, 0x0AC7, 0x000B,
3207 0x006F, 0x0006, 0x0005, 0x0008, 0x0009, 0x0007, 0x001E, 0x0002,
3208 0x0007, 0x0006, 0x002A, 0x00AD, 0x0AC6, 0x0561, 0x0560, 0x0001,
3209 0x001F, 0x000C, 0x0039, 0x001A, 0x0000, 0x0036, 0x001D, 0x0038
3210 ], [
3211 0x0007, 0x001B, 0x000E, 0x000D, 0x03E1, 0x1F06, 0x3E0F, 0x0002,
3212 0x00F9, 0x0005, 0x0006, 0x0008, 0x0009, 0x0004, 0x000C, 0x001A,
3213 0x000F, 0x000C, 0x01F1, 0x07C0, 0x3E0E, 0x1F05, 0x1F04, 0x0001,
3214 0x0000, 0x001C, 0x003F, 0x003D, 0x0005, 0x007D, 0x001D, 0x003C
3215 ], [
3216 0x000F, 0x000A, 0x0071, 0x0006, 0x01C2, 0x0702, 0x1C0E, 0x0002,
3217 0x000E, 0x0005, 0x0004, 0x0006, 0x0007, 0x001D, 0x0017, 0x000F,
3218 0x01C3, 0x01C1, 0x0380, 0x381F, 0x381E, 0x1C0D, 0x1C0C, 0x0001,
3219 0x0004, 0x0018, 0x0001, 0x0000, 0x000D, 0x0016, 0x0019, 0x0039
3220 ], [
3221 0x0002, 0x001E, 0x003B, 0x000D, 0x0061, 0x01FA, 0x1FB5, 0x0031,
3222 0x00FC, 0x0004, 0x0005, 0x0001, 0x0007, 0x003A, 0x0060, 0x03F7,
3223 0x07EC, 0x1FB7, 0x3F6C, 0x7EDB, 0x7EDA, 0x3F69, 0x3F68, 0x0001,
3224 0x0000, 0x0019, 0x003E, 0x0039, 0x000D, 0x0038, 0x000C, 0x007F
3225 ], [
3226 0x001E, 0x0070, 0x0127, 0x0126, 0x0492, 0x124D, 0x124C, 0x0001,
3227 0x007F, 0x0006, 0x0005, 0x0005, 0x0004, 0x0001, 0x0007, 0x0025,
3228 0x0071, 0x007E, 0x0048, 0x0125, 0x0248, 0x124F, 0x124E, 0x0003,
3229 0x0008, 0x001D, 0x0006, 0x003E, 0x0002, 0x0000, 0x0013, 0x0039
3230 ], [
3231 0x0001, 0x0001, 0x00E7, 0x0091, 0x0240, 0x120D, 0x120C, 0x003C,
3232 0x0000, 0x0006, 0x0005, 0x0005, 0x0004, 0x001F, 0x0004, 0x0025,
3233 0x0072, 0x0049, 0x00E6, 0x0121, 0x0482, 0x120F, 0x120E, 0x0003,
3234 0x0008, 0x001D, 0x0005, 0x003D, 0x0003, 0x0001, 0x0013, 0x0038
3235 ], [
3236 0x0004, 0x000F, 0x00F4, 0x005B, 0x02D3, 0x0B4A, 0x1697, 0x003C,
3237 0x000E, 0x0006, 0x0005, 0x0002, 0x0001, 0x001D, 0x0000, 0x007B,
3238 0x002C, 0x00F5, 0x00B5, 0x0168, 0x1696, 0x0B49, 0x0B48, 0x0003,
3239 0x0009, 0x001F, 0x000A, 0x0001, 0x0008, 0x0006, 0x001C, 0x0017
3240 ], [
3241 0x0008, 0x0039, 0x001A, 0x0003, 0x00DB, 0x06D6, 0x0DAF, 0x003C,
3242 0x000C, 0x0006, 0x0005, 0x0002, 0x0001, 0x001D, 0x003D, 0x0000,
3243 0x0002, 0x0037, 0x006C, 0x01B4, 0x0DAE, 0x06D5, 0x06D4, 0x0002,
3244 0x0007, 0x001F, 0x0007, 0x0001, 0x0009, 0x000D, 0x000C, 0x0038
3245 ], [
3246 0x000F, 0x0004, 0x002F, 0x002E, 0x0054, 0x0555, 0x0554, 0x0016,
3247 0x000E, 0x0006, 0x0005, 0x0001, 0x0000, 0x0009, 0x000B, 0x0014,
3248 0x0057, 0x0056, 0x00AB, 0x0557, 0x0556, 0x02A9, 0x02A8, 0x0003,
3249 0x0008, 0x0013, 0x000A, 0x0008, 0x000E, 0x0012, 0x0006, 0x000F
3250 ], [
3251 0x0001, 0x000E, 0x0006, 0x0004, 0x00DA, 0x0DBE, 0x1B7E, 0x0007,
3252 0x001A, 0x0005, 0x0004, 0x001C, 0x001B, 0x003A, 0x0037, 0x006C,
3253 0x01B6, 0x036E, 0x0DBD, 0x36FF, 0x36FE, 0x1B79, 0x1B78, 0x0002,
3254 0x000C, 0x0000, 0x000F, 0x000C, 0x000F, 0x001A, 0x003B, 0x0005
3255 ], [
3256 0x0005, 0x001E, 0x003A, 0x003E, 0x00FC, 0x0FD7, 0x3F55, 0x0077,
3257 0x0030, 0x0003, 0x0004, 0x001A, 0x0019, 0x007F, 0x01FB, 0x03F4,
3258 0x0FD6, 0x1FA9, 0x3F54, 0x3F57, 0x3F56, 0x3F51, 0x3F50, 0x0001,
3259 0x0004, 0x001C, 0x000B, 0x000A, 0x0000, 0x001B, 0x0031, 0x0076
3260 ], [
3261 0x0005, 0x000C, 0x001B, 0x0008, 0x0038, 0x0015, 0x00A3, 0x00E6,
3262 0x0004, 0x0001, 0x0002, 0x0012, 0x0003, 0x000B, 0x0029, 0x00A0,
3263 0x0142, 0x0287, 0x0286, 0x0289, 0x0288, 0x028B, 0x028A, 0x000F,
3264 0x001D, 0x0013, 0x0001, 0x0000, 0x0003, 0x001A, 0x0072, 0x00E7
3265 ]
3266 ];
3267 const VP40_AC_CAT1_BITS: [[u8; 32]; 16] = [
3268 [
3269 5, 8, 9, 11, 13, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 4,
3270 5, 5, 4, 5, 7, 10, 13, 4, 5, 6, 6, 7, 6, 8, 5, 6
3271 ], [
3272 5, 7, 9, 10, 12, 13, 14, 5, 8, 3, 3, 4, 4, 3, 4, 5,
3273 5, 5, 5, 6, 8, 11, 14, 4, 5, 6, 6, 7, 5, 8, 5, 6
3274 ], [
3275 5, 7, 8, 9, 11, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 5,
3276 5, 5, 5, 7, 10, 13, 13, 3, 5, 6, 6, 6, 5, 8, 5, 6
3277 ], [
3278 4, 7, 8, 9, 11, 13, 13, 5, 8, 3, 3, 4, 4, 4, 4, 5,
3279 6, 6, 6, 8, 10, 13, 13, 3, 5, 5, 6, 6, 5, 7, 5, 6
3280 ], [
3281 4, 6, 8, 8, 10, 12, 13, 5, 8, 3, 3, 4, 4, 4, 5, 5,
3282 6, 6, 7, 9, 13, 12, 12, 3, 5, 5, 6, 6, 4, 7, 5, 6
3283 ], [
3284 4, 6, 7, 7, 10, 13, 14, 5, 8, 3, 3, 4, 4, 4, 5, 6,
3285 7, 7, 9, 11, 14, 13, 13, 3, 4, 5, 6, 6, 4, 7, 5, 6
3286 ], [
3287 4, 5, 7, 6, 9, 11, 13, 5, 7, 3, 3, 4, 4, 5, 6, 7,
3288 9, 9, 10, 14, 14, 13, 13, 3, 4, 5, 5, 5, 4, 6, 5, 6
3289 ], [
3290 3, 5, 6, 5, 7, 9, 13, 6, 8, 3, 3, 4, 4, 6, 7, 10,
3291 11, 13, 14, 15, 15, 14, 14, 3, 4, 5, 6, 6, 4, 6, 5, 7
3292 ], [
3293 5, 7, 9, 9, 11, 13, 13, 5, 7, 3, 3, 4, 4, 4, 5, 6,
3294 7, 7, 7, 9, 10, 13, 13, 3, 4, 5, 5, 6, 4, 5, 5, 6
3295 ], [
3296 4, 6, 8, 8, 10, 13, 13, 6, 6, 3, 3, 4, 4, 5, 5, 6,
3297 7, 7, 8, 9, 11, 13, 13, 3, 4, 5, 5, 6, 4, 5, 5, 6
3298 ], [
3299 4, 6, 8, 8, 11, 13, 14, 6, 6, 3, 3, 4, 4, 5, 5, 7,
3300 7, 8, 9, 10, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6
3301 ], [
3302 4, 6, 7, 7, 10, 13, 14, 6, 6, 3, 3, 4, 4, 5, 6, 6,
3303 7, 8, 9, 11, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6
3304 ], [
3305 4, 5, 7, 7, 9, 13, 13, 6, 6, 3, 3, 4, 4, 5, 6, 7,
3306 9, 9, 10, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6
3307 ], [
3308 3, 5, 6, 6, 9, 13, 14, 6, 6, 3, 3, 5, 5, 6, 7, 8,
3309 10, 11, 13, 15, 15, 14, 14, 3, 4, 4, 5, 5, 4, 5, 6, 6
3310 ], [
3311 3, 5, 6, 6, 8, 12, 14, 7, 6, 3, 3, 5, 5, 7, 9, 10,
3312 12, 13, 14, 14, 14, 14, 14, 3, 4, 5, 5, 5, 3, 5, 6, 7
3313 ], [
3314 3, 4, 5, 4, 6, 8, 11, 8, 6, 3, 3, 5, 5, 7, 9, 11,
3315 12, 13, 13, 13, 13, 13, 13, 4, 5, 5, 5, 5, 3, 5, 7, 8
3316 ]
3317 ];
3318 const VP40_AC_CAT2_CODES: [[u32; 32]; 16] = [
3319 [
3320 0x0009, 0x0015, 0x0028, 0x0052, 0x029A, 0x0537, 0x0536, 0x000A,
3321 0x0054, 0x0004, 0x0003, 0x000C, 0x000B, 0x000D, 0x0003, 0x0014,
3322 0x003A, 0x0004, 0x0038, 0x0055, 0x00A7, 0x0299, 0x0298, 0x0000,
3323 0x001E, 0x0008, 0x002B, 0x000B, 0x000B, 0x003B, 0x001F, 0x0039
3324 ], [
3325 0x001D, 0x002F, 0x0002, 0x0007, 0x0019, 0x0035, 0x0034, 0x0009,
3326 0x002E, 0x0006, 0x0005, 0x0009, 0x0008, 0x0007, 0x001F, 0x0008,
3327 0x0018, 0x0019, 0x0001, 0x0000, 0x0018, 0x0037, 0x0036, 0x0001,
3328 0x0001, 0x000A, 0x0039, 0x0016, 0x000D, 0x0001, 0x001E, 0x0038
3329 ], [
3330 0x0001, 0x0071, 0x00E0, 0x01C3, 0x0708, 0x1C26, 0x384F, 0x0001,
3331 0x0031, 0x0006, 0x0005, 0x0009, 0x0008, 0x0005, 0x000F, 0x0039,
3332 0x0077, 0x0076, 0x0030, 0x0385, 0x384E, 0x1C25, 0x1C24, 0x0001,
3333 0x0004, 0x000D, 0x0000, 0x0019, 0x001F, 0x000E, 0x001E, 0x003A
3334 ], [
3335 0x0006, 0x000C, 0x00D6, 0x007B, 0x01E8, 0x07A4, 0x0F4B, 0x0036,
3336 0x006A, 0x0007, 0x0005, 0x0008, 0x0009, 0x0001, 0x0007, 0x000D,
3337 0x003C, 0x00D7, 0x00F5, 0x07A7, 0x0F4A, 0x0F4D, 0x0F4C, 0x0002,
3338 0x0002, 0x000E, 0x0037, 0x0034, 0x0000, 0x0019, 0x0018, 0x001F
3339 ], [
3340 0x000A, 0x0027, 0x00BF, 0x00BE, 0x0224, 0x225D, 0x225C, 0x0026,
3341 0x005E, 0x0007, 0x0006, 0x0006, 0x0007, 0x0016, 0x002E, 0x0045,
3342 0x0088, 0x0113, 0x044A, 0x225F, 0x225E, 0x112D, 0x112C, 0x0002,
3343 0x0002, 0x0012, 0x0003, 0x0002, 0x0003, 0x0000, 0x0010, 0x0023
3344 ], [
3345 0x000F, 0x0006, 0x0075, 0x0074, 0x000A, 0x00BF, 0x00B9, 0x0022,
3346 0x0003, 0x0005, 0x0006, 0x0001, 0x0002, 0x0007, 0x0000, 0x0004,
3347 0x0016, 0x005E, 0x00B8, 0x00BB, 0x00BA, 0x017D, 0x017C, 0x0002,
3348 0x0006, 0x001C, 0x0010, 0x003B, 0x0009, 0x0007, 0x0001, 0x0023
3349 ], [
3350 0x0001, 0x001C, 0x0036, 0x003B, 0x00EA, 0x075B, 0x1D65, 0x0019,
3351 0x0074, 0x0004, 0x0005, 0x0000, 0x0001, 0x0037, 0x01D7, 0x075A,
3352 0x1D64, 0x1D67, 0x1D66, 0x1D61, 0x1D60, 0x1D63, 0x1D62, 0x0002,
3353 0x001F, 0x001A, 0x000D, 0x003D, 0x000C, 0x0007, 0x003C, 0x0018
3354 ], [
3355 0x0002, 0x0001, 0x0014, 0x0000, 0x002F, 0x00BB, 0x02E4, 0x007D,
3356 0x00BA, 0x0003, 0x0004, 0x0016, 0x001A, 0x00B8, 0x172E, 0x2E5F,
3357 0x2E5E, 0x1729, 0x1728, 0x172B, 0x172A, 0x172D, 0x172C, 0x0001,
3358 0x001E, 0x0015, 0x001B, 0x003F, 0x000C, 0x000E, 0x007C, 0x0173
3359 ], [
3360 0x0003, 0x007B, 0x0058, 0x01EA, 0x1EB1, 0x1EB0, 0x1EB3, 0x0013,
3361 0x0012, 0x0005, 0x0006, 0x0002, 0x0001, 0x0013, 0x003C, 0x002D,
3362 0x00F4, 0x0059, 0x03D7, 0x0F5B, 0x1EB2, 0x1EB5, 0x1EB4, 0x0003,
3363 0x000E, 0x001F, 0x0012, 0x0008, 0x0008, 0x0000, 0x000A, 0x0017
3364 ], [
3365 0x0008, 0x003C, 0x00F5, 0x00F4, 0x1EF7, 0x3DE9, 0x3DE8, 0x001C,
3366 0x000D, 0x0005, 0x0006, 0x0001, 0x0000, 0x0007, 0x000C, 0x00F6,
3367 0x01EE, 0x03DF, 0x07BC, 0x3DEB, 0x3DEA, 0x3DED, 0x3DEC, 0x0002,
3368 0x0009, 0x001F, 0x000F, 0x0005, 0x000E, 0x0006, 0x0004, 0x001D
3369 ], [
3370 0x0009, 0x0039, 0x0019, 0x0018, 0x0706, 0x383D, 0x383C, 0x000D,
3371 0x000F, 0x0005, 0x0006, 0x0000, 0x001D, 0x0003, 0x0071, 0x00E1,
3372 0x01C0, 0x0382, 0x1C1D, 0x383F, 0x383E, 0x3839, 0x3838, 0x0002,
3373 0x0008, 0x0002, 0x000D, 0x000C, 0x000F, 0x0007, 0x0002, 0x000E
3374 ], [
3375 0x0000, 0x0006, 0x0035, 0x0034, 0x0777, 0x1DD4, 0x3BAB, 0x000E,
3376 0x000F, 0x0005, 0x0004, 0x001C, 0x0019, 0x003A, 0x00EF, 0x01DC,
3377 0x0776, 0x0774, 0x3BAA, 0x3BAD, 0x3BAC, 0x3BAF, 0x3BAE, 0x0002,
3378 0x0007, 0x0002, 0x0018, 0x000C, 0x000F, 0x000D, 0x001B, 0x0076
3379 ], [
3380 0x0002, 0x0011, 0x0006, 0x004F, 0x0130, 0x1319, 0x1318, 0x004E,
3381 0x0007, 0x0006, 0x0005, 0x0010, 0x000D, 0x0005, 0x0099, 0x0262,
3382 0x098E, 0x131B, 0x131A, 0x263D, 0x263C, 0x263F, 0x263E, 0x0001,
3383 0x0007, 0x0000, 0x0012, 0x000C, 0x000E, 0x000F, 0x0004, 0x004D
3384 ], [
3385 0x0003, 0x0000, 0x0002, 0x0037, 0x01B7, 0x0DB5, 0x36DD, 0x006C,
3386 0x0016, 0x0005, 0x0004, 0x0003, 0x000A, 0x002E, 0x036C, 0x0DB4,
3387 0x36DC, 0x36DF, 0x36DE, 0x36D9, 0x36D8, 0x36DB, 0x36DA, 0x000E,
3388 0x0004, 0x001A, 0x0019, 0x0018, 0x000F, 0x0001, 0x002F, 0x00DA
3389 ], [
3390 0x0006, 0x0006, 0x000F, 0x0000, 0x0075, 0x03B8, 0x1DCA, 0x0074,
3391 0x0076, 0x0004, 0x0005, 0x0003, 0x0002, 0x01DE, 0x0EE6, 0x3B97,
3392 0x3B96, 0x3B9D, 0x3B9C, 0x3B9F, 0x3B9E, 0x1DC9, 0x1DC8, 0x0005,
3393 0x001C, 0x0009, 0x000E, 0x0008, 0x000F, 0x0001, 0x01DF, 0x01DD
3394 ], [
3395 0x0004, 0x000B, 0x001D, 0x000C, 0x0014, 0x00E0, 0x3875, 0x0386,
3396 0x01C2, 0x0000, 0x0001, 0x0071, 0x0072, 0x1C3F, 0x3874, 0x3877,
3397 0x3876, 0x3871, 0x3870, 0x3873, 0x3872, 0x3879, 0x3878, 0x003C,
3398 0x0073, 0x002A, 0x003D, 0x002B, 0x001F, 0x000D, 0x1C3E, 0x1C3D
3399 ]
3400 ];
3401 const VP40_AC_CAT2_BITS: [[u8; 32]; 16] = [
3402 [
3403 5, 7, 8, 9, 12, 13, 13, 5, 7, 3, 3, 4, 4, 4, 4, 5,
3404 6, 5, 6, 7, 10, 12, 12, 3, 5, 5, 6, 6, 5, 6, 5, 6
3405 ], [
3406 5, 7, 8, 9, 11, 12, 12, 5, 7, 3, 3, 4, 4, 4, 5, 5,
3407 6, 6, 6, 7, 11, 12, 12, 3, 4, 5, 6, 6, 5, 5, 5, 6
3408 ], [
3409 4, 7, 8, 9, 11, 13, 14, 5, 7, 3, 3, 4, 4, 4, 5, 6,
3410 7, 7, 7, 10, 14, 13, 13, 3, 4, 5, 5, 6, 5, 5, 5, 6
3411 ], [
3412 4, 6, 8, 8, 10, 12, 13, 6, 7, 3, 3, 4, 4, 4, 5, 6,
3413 7, 8, 9, 12, 13, 13, 13, 3, 4, 5, 6, 6, 4, 5, 5, 6
3414 ], [
3415 4, 6, 8, 8, 10, 14, 14, 6, 7, 3, 3, 4, 4, 5, 6, 7,
3416 8, 9, 11, 14, 14, 13, 13, 3, 4, 5, 5, 5, 4, 4, 5, 6
3417 ], [
3418 4, 5, 7, 7, 9, 13, 13, 6, 7, 3, 3, 4, 4, 5, 6, 8,
3419 10, 12, 13, 13, 13, 14, 14, 3, 4, 5, 5, 6, 4, 4, 5, 6
3420 ], [
3421 3, 5, 6, 6, 8, 11, 13, 6, 7, 3, 3, 4, 4, 6, 9, 11,
3422 13, 13, 13, 13, 13, 13, 13, 3, 5, 5, 5, 6, 4, 4, 6, 6
3423 ], [
3424 3, 4, 5, 4, 6, 8, 10, 7, 8, 3, 3, 5, 5, 8, 13, 14,
3425 14, 13, 13, 13, 13, 13, 13, 3, 5, 5, 5, 6, 4, 4, 7, 9
3426 ], [
3427 4, 7, 8, 9, 13, 13, 13, 6, 6, 3, 3, 4, 4, 5, 6, 7,
3428 8, 8, 10, 12, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 5, 6
3429 ], [
3430 4, 6, 8, 8, 13, 14, 14, 6, 6, 3, 3, 4, 4, 5, 6, 8,
3431 9, 10, 11, 14, 14, 14, 14, 3, 4, 5, 5, 5, 4, 4, 5, 6
3432 ], [
3433 4, 6, 7, 7, 11, 14, 14, 6, 6, 3, 3, 4, 5, 5, 7, 8,
3434 9, 10, 13, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 5, 6
3435 ], [
3436 3, 5, 7, 7, 11, 13, 14, 6, 6, 3, 3, 5, 5, 6, 8, 9,
3437 11, 11, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3438 ], [
3439 3, 5, 6, 7, 9, 13, 13, 7, 6, 3, 3, 5, 5, 6, 8, 10,
3440 12, 13, 13, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3441 ], [
3442 3, 4, 5, 6, 9, 12, 14, 7, 6, 3, 3, 5, 5, 7, 10, 12,
3443 14, 14, 14, 14, 14, 14, 14, 4, 4, 5, 5, 5, 4, 3, 7, 8
3444 ], [
3445 3, 4, 5, 4, 7, 10, 13, 7, 7, 3, 3, 5, 5, 9, 12, 14,
3446 14, 14, 14, 14, 14, 13, 13, 4, 5, 5, 5, 5, 4, 3, 9, 9
3447 ], [
3448 3, 4, 5, 4, 5, 8, 14, 10, 9, 2, 2, 7, 7, 13, 14, 14,
3449 14, 14, 14, 14, 14, 14, 14, 6, 7, 6, 6, 6, 5, 4, 13, 13
3450 ]
3451 ];
3452 const VP40_AC_CAT3_CODES: [[u32; 32]; 16] = [
3453 [
3454 0x0007, 0x000F, 0x00BB, 0x00BA, 0x05CF, 0x173A, 0x2E77, 0x0029,
3455 0x0172, 0x0007, 0x0006, 0x0009, 0x0008, 0x0001, 0x0005, 0x000D,
3456 0x001D, 0x001C, 0x00B8, 0x02E6, 0x2E76, 0x1739, 0x1738, 0x0002,
3457 0x0006, 0x0016, 0x0004, 0x0028, 0x0015, 0x000C, 0x0000, 0x002F
3458 ], [
3459 0x000B, 0x0002, 0x0054, 0x002F, 0x02AC, 0x156B, 0x1568, 0x0016,
3460 0x0154, 0x0007, 0x0006, 0x0004, 0x0003, 0x0013, 0x0028, 0x002E,
3461 0x0157, 0x0155, 0x055B, 0x2AD3, 0x2AD2, 0x2AD5, 0x2AD4, 0x0003,
3462 0x0008, 0x0000, 0x000A, 0x0003, 0x0002, 0x002B, 0x0012, 0x0029
3463 ], [
3464 0x000F, 0x0007, 0x0001, 0x0000, 0x01C4, 0x0703, 0x0E02, 0x0011,
3465 0x00E1, 0x0005, 0x0006, 0x0002, 0x0001, 0x0009, 0x0010, 0x00E3,
3466 0x01C5, 0x01C1, 0x0702, 0x1C07, 0x1C06, 0x0E01, 0x0E00, 0x0004,
3467 0x0007, 0x001D, 0x000D, 0x0001, 0x0005, 0x0006, 0x000C, 0x0039
3468 ], [
3469 0x0001, 0x001C, 0x0011, 0x0013, 0x0042, 0x0207, 0x0815, 0x0075,
3470 0x0041, 0x0005, 0x0006, 0x0000, 0x001F, 0x003B, 0x0074, 0x0043,
3471 0x0080, 0x0206, 0x0814, 0x0817, 0x0816, 0x0409, 0x0408, 0x0003,
3472 0x0009, 0x001E, 0x0011, 0x0003, 0x0005, 0x0010, 0x0002, 0x0012
3473 ], [
3474 0x0001, 0x001F, 0x0027, 0x0001, 0x004B, 0x0123, 0x0915, 0x0000,
3475 0x0049, 0x0005, 0x0006, 0x001D, 0x001C, 0x0013, 0x004A, 0x0090,
3476 0x0914, 0x0917, 0x0916, 0x0911, 0x0910, 0x0913, 0x0912, 0x0003,
3477 0x0005, 0x0001, 0x0012, 0x0008, 0x0008, 0x001E, 0x0026, 0x0001
3478 ], [
3479 0x0003, 0x0001, 0x003F, 0x000B, 0x004E, 0x0132, 0x099A, 0x004F,
3480 0x0098, 0x0006, 0x0005, 0x001D, 0x001C, 0x007C, 0x0267, 0x1331,
3481 0x1330, 0x1333, 0x1332, 0x266D, 0x266C, 0x266F, 0x266E, 0x0001,
3482 0x0004, 0x001E, 0x0012, 0x000A, 0x0008, 0x0000, 0x007D, 0x004D
3483 ], [
3484 0x0002, 0x0007, 0x0015, 0x0003, 0x0004, 0x00A7, 0x0536, 0x0028,
3485 0x029A, 0x0006, 0x0004, 0x001C, 0x0017, 0x00A4, 0x29BE, 0x537F,
3486 0x537E, 0x29B9, 0x29B8, 0x29BB, 0x29BA, 0x29BD, 0x29BC, 0x000F,
3487 0x0000, 0x0005, 0x0016, 0x001D, 0x0006, 0x0001, 0x00A5, 0x014C
3488 ], [
3489 0x0004, 0x0007, 0x001A, 0x000C, 0x0006, 0x0029, 0x01BD, 0x1BE3,
3490 0x1BE0, 0x0000, 0x0007, 0x006E, 0x01BC, 0x37C3, 0x37C2, 0x37CD,
3491 0x37CC, 0x37CF, 0x37CE, 0x37C9, 0x37C8, 0x37CB, 0x37CA, 0x0015,
3492 0x01BF, 0x037D, 0x0036, 0x0002, 0x000B, 0x0028, 0x37C5, 0x37C4
3493 ], [
3494 0x0001, 0x0009, 0x0003, 0x0002, 0x011F, 0x08E9, 0x08E8, 0x002D,
3495 0x0022, 0x0006, 0x0007, 0x0010, 0x0011, 0x0017, 0x002C, 0x0046,
3496 0x011E, 0x011C, 0x0477, 0x08EB, 0x08EA, 0x08ED, 0x08EC, 0x0003,
3497 0x000B, 0x0001, 0x0014, 0x000A, 0x0009, 0x0015, 0x0000, 0x0010
3498 ], [
3499 0x0001, 0x001D, 0x0022, 0x0013, 0x011E, 0x08FC, 0x23F5, 0x0023,
3500 0x0022, 0x0005, 0x0006, 0x0010, 0x000B, 0x0010, 0x008E, 0x023E,
3501 0x08FF, 0x11FD, 0x23F4, 0x23F7, 0x23F6, 0x23F9, 0x23F8, 0x0003,
3502 0x0009, 0x0000, 0x001C, 0x000A, 0x000F, 0x0001, 0x0012, 0x0046
3503 ], [
3504 0x0003, 0x001F, 0x003C, 0x003D, 0x0086, 0x0877, 0x10E8, 0x0041,
3505 0x0040, 0x0005, 0x0006, 0x0007, 0x0006, 0x0004, 0x010F, 0x021C,
3506 0x0875, 0x21D3, 0x21D2, 0x21D9, 0x21D8, 0x21DB, 0x21DA, 0x0002,
3507 0x0009, 0x0000, 0x0011, 0x0003, 0x000E, 0x0002, 0x0005, 0x0042
3508 ], [
3509 0x0004, 0x0001, 0x003D, 0x0009, 0x00F3, 0x0793, 0x1E45, 0x0000,
3510 0x0002, 0x0005, 0x0006, 0x0008, 0x0001, 0x0003, 0x01E5, 0x0792,
3511 0x1E44, 0x1E47, 0x1E46, 0x1E41, 0x1E40, 0x1E43, 0x1E42, 0x0001,
3512 0x0006, 0x001F, 0x000F, 0x000E, 0x000E, 0x0005, 0x0078, 0x0001
3513 ], [
3514 0x0004, 0x0005, 0x000E, 0x0017, 0x003E, 0x00F0, 0x0F1E, 0x007A,
3515 0x007F, 0x0006, 0x0007, 0x0005, 0x0004, 0x007B, 0x01E2, 0x1E3F,
3516 0x1E3E, 0x0F19, 0x0F18, 0x0F1B, 0x0F1A, 0x0F1D, 0x0F1C, 0x0000,
3517 0x0003, 0x0016, 0x0009, 0x0008, 0x000A, 0x0006, 0x007E, 0x0079
3518 ], [
3519 0x0005, 0x000C, 0x001A, 0x0004, 0x001A, 0x00DE, 0x0DF4, 0x00DD,
3520 0x006D, 0x0000, 0x0007, 0x0025, 0x0024, 0x00DC, 0x0DF7, 0x1BEB,
3521 0x1BEA, 0x0DF1, 0x0DF0, 0x0DF3, 0x0DF2, 0x1BED, 0x1BEC, 0x0008,
3522 0x0013, 0x000C, 0x0037, 0x0036, 0x0005, 0x0007, 0x006C, 0x01BF
3523 ], [
3524 0x0005, 0x000D, 0x001F, 0x000C, 0x003B, 0x0040, 0x041A, 0x0104,
3525 0x0107, 0x0001, 0x0000, 0x0024, 0x0021, 0x020B, 0x106E, 0x20DF,
3526 0x20DE, 0x1055, 0x1054, 0x1057, 0x1056, 0x106D, 0x106C, 0x0011,
3527 0x003A, 0x0025, 0x0038, 0x0039, 0x0013, 0x001E, 0x020C, 0x0414
3528 ], [
3529 0x0000, 0x0007, 0x000D, 0x0005, 0x0009, 0x0022, 0x0CD1, 0x0CD0,
3530 0x0CD3, 0x0003, 0x0002, 0x008D, 0x00CC, 0x066B, 0x0CD2, 0x19B5,
3531 0x19B4, 0x19B7, 0x19B6, 0x19B1, 0x19B0, 0x19B3, 0x19B2, 0x0047,
3532 0x008C, 0x0337, 0x0067, 0x0018, 0x0010, 0x0032, 0x0CD5, 0x0CD4
3533 ]
3534 ];
3535 const VP40_AC_CAT3_BITS: [[u8; 32]; 16] = [
3536 [
3537 4, 6, 8, 8, 11, 13, 14, 6, 9, 3, 3, 4, 4, 4, 5, 6,
3538 7, 7, 8, 10, 14, 13, 13, 3, 4, 5, 5, 6, 5, 6, 4, 6
3539 ], [
3540 4, 5, 7, 7, 10, 13, 13, 6, 9, 3, 3, 4, 4, 5, 6, 7,
3541 9, 9, 11, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 6, 5, 6
3542 ], [
3543 4, 5, 6, 6, 9, 11, 12, 6, 8, 3, 3, 4, 4, 5, 6, 8,
3544 9, 9, 11, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6
3545 ], [
3546 3, 5, 6, 6, 8, 11, 13, 7, 8, 3, 3, 4, 5, 6, 7, 8,
3547 9, 11, 13, 13, 13, 12, 12, 3, 4, 5, 5, 5, 4, 5, 5, 6
3548 ], [
3549 3, 5, 6, 5, 8, 10, 13, 6, 8, 3, 3, 5, 5, 6, 8, 9,
3550 13, 13, 13, 13, 13, 13, 13, 3, 4, 4, 5, 5, 4, 5, 6, 6
3551 ], [
3552 3, 4, 6, 5, 7, 9, 12, 7, 8, 3, 3, 5, 5, 7, 10, 13,
3553 13, 13, 13, 14, 14, 14, 14, 3, 4, 5, 5, 5, 4, 4, 7, 7
3554 ], [
3555 3, 4, 5, 4, 5, 8, 11, 6, 10, 3, 3, 5, 5, 8, 14, 15,
3556 15, 14, 14, 14, 14, 14, 14, 4, 4, 5, 5, 5, 4, 4, 8, 9
3557 ], [
3558 3, 4, 5, 4, 4, 6, 9, 13, 13, 2, 3, 7, 9, 14, 14, 14,
3559 14, 14, 14, 14, 14, 14, 14, 5, 9, 10, 6, 3, 4, 6, 14, 14
3560 ], [
3561 3, 5, 6, 6, 10, 13, 13, 7, 7, 3, 3, 5, 5, 6, 7, 8,
3562 10, 10, 12, 13, 13, 13, 13, 3, 4, 4, 5, 5, 4, 5, 5, 6
3563 ], [
3564 3, 5, 6, 6, 9, 12, 14, 7, 7, 3, 3, 5, 5, 6, 8, 10,
3565 12, 13, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3566 ], [
3567 3, 5, 6, 6, 8, 12, 13, 7, 7, 3, 3, 5, 5, 6, 9, 10,
3568 12, 14, 14, 14, 14, 14, 14, 3, 4, 4, 5, 5, 4, 4, 6, 7
3569 ], [
3570 3, 4, 6, 5, 8, 11, 13, 7, 7, 3, 3, 5, 5, 7, 9, 11,
3571 13, 13, 13, 13, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 7, 7
3572 ], [
3573 3, 4, 5, 5, 7, 9, 13, 8, 8, 3, 3, 5, 5, 8, 10, 14,
3574 14, 13, 13, 13, 13, 13, 13, 3, 4, 5, 5, 5, 4, 4, 8, 8
3575 ], [
3576 3, 4, 5, 4, 6, 9, 13, 9, 8, 2, 3, 6, 6, 9, 13, 14,
3577 14, 13, 13, 13, 13, 14, 14, 4, 5, 5, 6, 6, 4, 4, 8, 10
3578 ], [
3579 3, 4, 5, 4, 6, 7, 11, 9, 9, 2, 2, 6, 6, 10, 13, 14,
3580 14, 13, 13, 13, 13, 13, 13, 5, 6, 6, 6, 6, 5, 5, 10, 11
3581 ], [
3582 2, 4, 5, 4, 5, 7, 13, 13, 13, 2, 2, 9, 9, 12, 13, 14,
3583 14, 14, 14, 14, 14, 14, 14, 8, 9, 11, 8, 6, 6, 7, 13, 13
3584 ]
3585 ];
3586
3587 const VP40_QMAT: &[i16; 64] = &[
3588 16, 17, 18, 20, 22, 24, 26, 28,
3589 17, 18, 20, 22, 24, 26, 28, 32,
3590 18, 20, 22, 24, 26, 28, 32, 36,
3591 20, 22, 24, 26, 28, 32, 36, 40,
3592 22, 24, 26, 28, 32, 36, 40, 44,
3593 24, 26, 28, 32, 36, 40, 44, 48,
3594 26, 28, 32, 36, 40, 44, 48, 52,
3595 28, 32, 36, 40, 44, 48, 52, 56
3596 ];
3597 const VP40_DC_Y_SCALES: [i16; 64] = [
3598 180, 180, 180, 180, 180, 180, 175, 170,
3599 165, 160, 157, 155, 152, 150, 147, 145,
3600 142, 140, 137, 135, 132, 130, 127, 125,
3601 122, 120, 117, 115, 112, 110, 107, 105,
3602 102, 100, 97, 95, 92, 90, 87, 85,
3603 82, 80, 77, 75, 72, 70, 67, 65,
3604 62, 60, 57, 55, 52, 50, 47, 45,
3605 42, 40, 37, 35, 32, 30, 27, 25
3606 ];
3607 const VP40_DC_C_SCALES: [i16; 64] = [
3608 150, 150, 150, 150, 150, 150, 150, 150,
3609 150, 150, 150, 150, 150, 150, 147, 145,
3610 142, 140, 137, 135, 132, 130, 127, 125,
3611 122, 120, 117, 115, 112, 110, 107, 105,
3612 102, 100, 97, 95, 92, 90, 87, 85,
3613 82, 80, 77, 75, 72, 70, 67, 65,
3614 62, 60, 57, 55, 52, 50, 47, 45,
3615 42, 40, 37, 35, 32, 30, 27, 25
3616 ];
3617 const VP40_AC_SCALES: [i16; 64] = [
3618 500, 475, 450, 430, 410, 390, 370, 350,
3619 330, 315, 300, 285, 270, 260, 250, 240,
3620 230, 220, 210, 200, 190, 185, 180, 170,
3621 160, 150, 143, 135, 128, 120, 113, 106,
3622 100, 94, 90, 85, 80, 75, 70, 66,
3623 62, 57, 52, 49, 45, 41, 38, 35,
3624 33, 30, 27, 24, 22, 20, 18, 16,
3625 14, 12, 10, 9, 7, 6, 4, 1
3626 ];
3627
3628 const VP40_MBPAT_CODES: [[u8; 14]; 2] = [
3629 [ 0b000, 0b1111, 0b1001, 0b010, 0b1101, 0b01110, 0b1011, 0b001, 0b01111, 0b1000, 0b0110, 0b1110, 0b1100, 0b1010 ],
3630 [ 0b0111, 0b1010, 0b1001, 0b1100, 0b1000, 0b01101, 0b000, 0b1110, 0b01100, 0b1101, 0b001, 0b1011, 0b1111, 0b010 ]
3631 ];
3632 const VP40_MBPAT_BITS: [[u8; 14]; 2] = [
3633 [ 3, 4, 4, 3, 4, 5, 4, 3, 5, 4, 4, 4, 4, 4 ],
3634 [ 4, 4, 4, 4, 4, 5, 3, 4, 5, 4, 3, 4, 4, 3 ]
3635 ];
3636 const VP40_BP_PREDICTOR: [u8; 15] = [ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1 ];
3637 const VP40_MV_X_CODES: [[u32; 63]; 7] = [
3638 [
3639 0x06A, 0x11A, 0x18E, 0x237, 0x04A, 0x236, 0x07A, 0x0D6,
3640 0x07E, 0x1FD, 0x08C, 0x0D7, 0x087, 0x183, 0x03C, 0x061,
3641 0x047, 0x069, 0x040, 0x048, 0x049, 0x086, 0x013, 0x0D2,
3642 0x01C, 0x042, 0x025, 0x01B, 0x013, 0x005, 0x000, 0x007,
3643 0x005, 0x01B, 0x019, 0x019, 0x008, 0x045, 0x01D, 0x0C6,
3644 0x068, 0x090, 0x041, 0x04B, 0x031, 0x18F, 0x062, 0x03E,
3645 0x044, 0x068, 0x030, 0x182, 0x0C0, 0x1A7, 0x091, 0x092,
3646 0x07B, 0x0FF, 0x1A6, 0x1FC, 0x06A, 0x093, 0x06B
3647 ], [
3648 0x039, 0x259, 0x01B, 0x1D1, 0x137, 0x1D0, 0x01A, 0x1B5,
3649 0x01D, 0x4BC, 0x06C, 0x038, 0x071, 0x02D, 0x07D, 0x075,
3650 0x019, 0x0E9, 0x037, 0x015, 0x01E, 0x0DB, 0x04C, 0x070,
3651 0x00D, 0x00C, 0x027, 0x004, 0x002, 0x000, 0x005, 0x007,
3652 0x006, 0x002, 0x008, 0x024, 0x00C, 0x03B, 0x01E, 0x09A,
3653 0x00E, 0x069, 0x04A, 0x12D, 0x035, 0x0F9, 0x018, 0x07F,
3654 0x00F, 0x0F8, 0x07E, 0x25F, 0x068, 0x02C, 0x014, 0x258,
3655 0x136, 0x4BD, 0x12E, 0x1B4, 0x017, 0x039, 0x01F
3656 ], [
3657 0x029, 0x3CB, 0x1F5, 0x263, 0x1F4, 0x3DA, 0x050, 0x260,
3658 0x1EC, 0x3D3, 0x109, 0x3D2, 0x051, 0x792, 0x0F3, 0x09A,
3659 0x0F7, 0x132, 0x0C1, 0x1E8, 0x02A, 0x085, 0x061, 0x1F7,
3660 0x078, 0x0C7, 0x023, 0x07C, 0x012, 0x00B, 0x00E, 0x00D,
3661 0x000, 0x005, 0x003, 0x004, 0x019, 0x020, 0x03F, 0x043,
3662 0x062, 0x09F, 0x04E, 0x181, 0x02B, 0x137, 0x0F5, 0x089,
3663 0x0C6, 0x262, 0x088, 0x3C8, 0x1F6, 0x3CA, 0x09E, 0x261,
3664 0x136, 0x108, 0x133, 0x793, 0x180, 0x3DB, 0x045
3665 ], [
3666 0x001, 0x1C7, 0x067, 0x0B5, 0x066, 0x139, 0x099, 0x0B4,
3667 0x0C3, 0x130, 0x000, 0x131, 0x09E, 0x0B7, 0x02C, 0x001,
3668 0x028, 0x138, 0x04B, 0x031, 0x060, 0x091, 0x003, 0x09D,
3669 0x017, 0x04D, 0x031, 0x070, 0x007, 0x03A, 0x007, 0x002,
3670 0x00B, 0x001, 0x00F, 0x008, 0x00D, 0x004, 0x00A, 0x00D,
3671 0x019, 0x002, 0x03B, 0x04A, 0x015, 0x0C2, 0x018, 0x032,
3672 0x072, 0x1C6, 0x029, 0x1C5, 0x049, 0x121, 0x01B, 0x030,
3673 0x01A, 0x1C4, 0x09F, 0x0B6, 0x019, 0x120, 0x073
3674 ], [
3675 0x023, 0x1C8, 0x043, 0x110, 0x00C, 0x153, 0x022, 0x111,
3676 0x00F, 0x042, 0x023, 0x1C9, 0x02A, 0x01B, 0x073, 0x045,
3677 0x06E, 0x089, 0x06C, 0x01A, 0x06F, 0x0B6, 0x00B, 0x0E5,
3678 0x025, 0x020, 0x029, 0x04D, 0x002, 0x014, 0x01A, 0x017,
3679 0x01E, 0x027, 0x018, 0x028, 0x01F, 0x000, 0x006, 0x010,
3680 0x007, 0x00B, 0x003, 0x004, 0x01D, 0x02C, 0x019, 0x02B,
3681 0x009, 0x055, 0x038, 0x00E, 0x024, 0x0A8, 0x00A, 0x099,
3682 0x05A, 0x098, 0x06D, 0x152, 0x02B, 0x0B7, 0x001
3683 ], [
3684 0x03D, 0x0B1, 0x0DD, 0x1F6, 0x0C5, 0x188, 0x037, 0x03F,
3685 0x01E, 0x189, 0x00F, 0x03E, 0x06A, 0x1F7, 0x061, 0x079,
3686 0x018, 0x0B0, 0x00E, 0x0B3, 0x00C, 0x0DF, 0x006, 0x0DC,
3687 0x019, 0x0DE, 0x027, 0x00E, 0x01A, 0x063, 0x00F, 0x00E,
3688 0x014, 0x07C, 0x036, 0x06B, 0x03F, 0x060, 0x008, 0x074,
3689 0x009, 0x078, 0x012, 0x00D, 0x015, 0x02D, 0x002, 0x01C,
3690 0x005, 0x03B, 0x000, 0x034, 0x019, 0x026, 0x010, 0x075,
3691 0x002, 0x036, 0x023, 0x0B2, 0x022, 0x0FA, 0x017
3692 ], [
3693 0x015, 0x0DD, 0x03E, 0x16E, 0x04C, 0x012, 0x05D, 0x0B6,
3694 0x06F, 0x1F1, 0x069, 0x1F0, 0x01D, 0x16F, 0x002, 0x06B,
3695 0x00C, 0x0DC, 0x068, 0x09B, 0x07D, 0x09A, 0x00D, 0x013,
3696 0x008, 0x0F9, 0x02C, 0x012, 0x033, 0x04F, 0x00D, 0x005,
3697 0x012, 0x03F, 0x032, 0x013, 0x03B, 0x005, 0x02F, 0x05A,
3698 0x03F, 0x01C, 0x03A, 0x008, 0x036, 0x05C, 0x010, 0x000,
3699 0x00C, 0x04E, 0x003, 0x06A, 0x00E, 0x003, 0x014, 0x01E,
3700 0x01C, 0x00F, 0x018, 0x023, 0x01E, 0x022, 0x002
3701 ]
3702 ];
3703 const VP40_MV_X_BITS: [[u8; 63]; 7] = [
3704 [
3705 7, 9, 9, 10, 8, 10, 8, 9, 8, 10, 8, 9, 8, 9, 7, 7,
3706 7, 8, 7, 8, 7, 8, 6, 8, 6, 7, 6, 6, 5, 4, 2, 3,
3707 3, 5, 5, 6, 5, 7, 6, 8, 7, 8, 7, 8, 7, 9, 7, 7,
3708 7, 8, 7, 9, 8, 9, 8, 9, 8, 9, 9, 10, 8, 9, 7
3709 ], [
3710 7, 10, 8, 10, 9, 10, 8, 10, 8, 11, 8, 9, 8, 9, 8, 8,
3711 7, 9, 7, 8, 7, 9, 7, 8, 6, 7, 6, 6, 4, 4, 3, 3,
3712 3, 3, 4, 6, 5, 7, 6, 8, 6, 8, 7, 9, 7, 9, 7, 8,
3713 7, 9, 8, 10, 8, 9, 8, 10, 9, 11, 9, 10, 8, 9, 7
3714 ], [
3715 7, 10, 9, 10, 9, 10, 8, 10, 9, 10, 9, 10, 8, 11, 8, 8,
3716 8, 9, 8, 9, 7, 8, 7, 9, 7, 8, 6, 7, 5, 5, 4, 4,
3717 2, 3, 3, 4, 5, 6, 6, 7, 7, 8, 7, 9, 7, 9, 8, 8,
3718 8, 10, 8, 10, 9, 10, 8, 10, 9, 9, 9, 11, 9, 10, 7
3719 ], [
3720 6, 9, 8, 9, 8, 9, 8, 9, 8, 9, 7, 9, 8, 9, 7, 7,
3721 7, 9, 7, 8, 7, 8, 6, 8, 6, 7, 6, 7, 5, 6, 4, 4,
3722 4, 4, 4, 4, 4, 4, 4, 5, 5, 6, 6, 7, 6, 8, 6, 7,
3723 7, 9, 7, 9, 7, 9, 7, 8, 7, 9, 8, 9, 7, 9, 7
3724 ], [
3725 6, 9, 8, 9, 7, 9, 7, 9, 7, 8, 7, 9, 7, 8, 7, 7,
3726 7, 8, 7, 8, 7, 8, 6, 8, 6, 7, 6, 7, 5, 6, 5, 5,
3727 5, 6, 5, 6, 5, 5, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6,
3728 5, 7, 6, 7, 6, 8, 6, 8, 7, 8, 7, 9, 7, 8, 5
3729 ], [
3730 6, 8, 8, 9, 8, 9, 7, 8, 7, 9, 7, 8, 7, 9, 7, 7,
3731 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 7, 6, 7, 5, 5,
3732 5, 7, 6, 7, 6, 7, 5, 7, 5, 7, 5, 6, 5, 6, 4, 5,
3733 4, 6, 4, 6, 5, 6, 5, 7, 5, 7, 6, 8, 6, 8, 5
3734 ], [
3735 5, 8, 7, 9, 7, 8, 7, 8, 7, 9, 7, 9, 7, 9, 6, 7,
3736 6, 8, 7, 8, 7, 8, 6, 8, 6, 8, 6, 7, 6, 7, 5, 5,
3737 5, 7, 6, 7, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 5, 5,
3738 5, 7, 5, 7, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 3
3739 ]
3740 ];
3741 const VP40_MV_Y_CODES: [[u32; 63]; 7] = [
3742 [
3743 0x052, 0x14C, 0x1FA, 0x124, 0x082, 0x29E, 0x08E, 0x24B,
3744 0x09C, 0x3F7, 0x086, 0x114, 0x083, 0x3A5, 0x0FA, 0x04F,
3745 0x0FB, 0x13B, 0x0FC, 0x172, 0x044, 0x173, 0x051, 0x087,
3746 0x05F, 0x0BA, 0x026, 0x05E, 0x016, 0x015, 0x006, 0x001,
3747 0x000, 0x01C, 0x01E, 0x075, 0x03B, 0x0FF, 0x025, 0x0BB,
3748 0x07C, 0x08B, 0x048, 0x171, 0x042, 0x14E, 0x046, 0x0FE,
3749 0x040, 0x13A, 0x093, 0x115, 0x08F, 0x3F6, 0x170, 0x29F,
3750 0x1D1, 0x24A, 0x1D3, 0x3A4, 0x1D0, 0x14D, 0x050
3751 ], [
3752 0x0DE, 0x223, 0x136, 0x7C5, 0x12F, 0x4A1, 0x3D7, 0x7AC,
3753 0x133, 0x7C4, 0x1B8, 0x222, 0x096, 0x251, 0x095, 0x1F0,
3754 0x0DA, 0x110, 0x09A, 0x360, 0x0DD, 0x12E, 0x048, 0x092,
3755 0x078, 0x098, 0x027, 0x045, 0x01A, 0x010, 0x005, 0x000,
3756 0x001, 0x00E, 0x00C, 0x023, 0x03F, 0x0F4, 0x07D, 0x089,
3757 0x07B, 0x1BE, 0x0F9, 0x3E3, 0x0F3, 0x127, 0x0DB, 0x1EA,
3758 0x0D9, 0x6E7, 0x1BF, 0x4A0, 0x1B1, 0x6E6, 0x137, 0x7AD,
3759 0x126, 0x6C2, 0x132, 0x6C3, 0x129, 0x372, 0x0F2
3760 ], [
3761 0x016, 0x09C, 0x13C, 0x09E, 0x12B, 0x0BA, 0x181, 0x317,
3762 0x084, 0x04E, 0x026, 0x316, 0x180, 0x05C, 0x0C1, 0x02F,
3763 0x010, 0x045, 0x012, 0x189, 0x024, 0x13D, 0x066, 0x023,
3764 0x067, 0x0C6, 0x024, 0x04B, 0x011, 0x032, 0x00D, 0x000,
3765 0x007, 0x005, 0x003, 0x003, 0x005, 0x020, 0x008, 0x025,
3766 0x026, 0x04F, 0x061, 0x02B, 0x04E, 0x18A, 0x043, 0x09F,
3767 0x014, 0x254, 0x094, 0x310, 0x085, 0x311, 0x02A, 0x0BB,
3768 0x18F, 0x255, 0x09D, 0x09F, 0x18E, 0x044, 0x026
3769 ], [
3770 0x061, 0x12A, 0x00D, 0x3BD, 0x089, 0x109, 0x18E, 0x210,
3771 0x1D3, 0x211, 0x088, 0x019, 0x085, 0x018, 0x0E8, 0x0CE,
3772 0x040, 0x119, 0x045, 0x1D2, 0x04B, 0x1DD, 0x062, 0x094,
3773 0x075, 0x00C, 0x027, 0x00D, 0x002, 0x026, 0x006, 0x01E,
3774 0x00D, 0x01F, 0x001, 0x00A, 0x002, 0x007, 0x00B, 0x000,
3775 0x01C, 0x076, 0x032, 0x007, 0x024, 0x0C0, 0x007, 0x041,
3776 0x002, 0x18F, 0x047, 0x1DC, 0x043, 0x12B, 0x0CF, 0x118,
3777 0x0C6, 0x3BC, 0x08D, 0x3BF, 0x0C1, 0x3BE, 0x066
3778 ], [
3779 0x007, 0x14D, 0x0A0, 0x09E, 0x0CF, 0x39C, 0x0A1, 0x39D,
3780 0x0AB, 0x1C5, 0x026, 0x14C, 0x025, 0x19C, 0x03F, 0x0E1,
3781 0x066, 0x1CF, 0x03E, 0x1C4, 0x072, 0x04E, 0x006, 0x0AA,
3782 0x01C, 0x0E6, 0x032, 0x051, 0x03B, 0x005, 0x01F, 0x018,
3783 0x002, 0x03A, 0x000, 0x036, 0x005, 0x008, 0x008, 0x016,
3784 0x009, 0x00D, 0x003, 0x02F, 0x01E, 0x02E, 0x01A, 0x02B,
3785 0x00C, 0x024, 0x01E, 0x0E0, 0x004, 0x0A7, 0x054, 0x1C7,
3786 0x052, 0x19D, 0x03A, 0x09F, 0x03B, 0x1C6, 0x037
3787 ], [
3788 0x02A, 0x039, 0x025, 0x115, 0x024, 0x1FA, 0x02F, 0x114,
3789 0x075, 0x038, 0x0FC, 0x036, 0x01E, 0x1FB, 0x07F, 0x068,
3790 0x016, 0x037, 0x01F, 0x05C, 0x013, 0x08B, 0x001, 0x0FB,
3791 0x021, 0x044, 0x02B, 0x06B, 0x03B, 0x00C, 0x01C, 0x019,
3792 0x001, 0x020, 0x016, 0x07C, 0x00C, 0x074, 0x00A, 0x01C,
3793 0x012, 0x069, 0x00F, 0x06A, 0x014, 0x011, 0x01E, 0x017,
3794 0x002, 0x031, 0x01B, 0x030, 0x00D, 0x000, 0x001, 0x01D,
3795 0x023, 0x01A, 0x01D, 0x05D, 0x010, 0x0FA, 0x013
3796 ], [
3797 0x012, 0x026, 0x041, 0x022, 0x01A, 0x0A9, 0x04C, 0x1B2,
3798 0x05C, 0x0A8, 0x058, 0x1B3, 0x040, 0x079, 0x00C, 0x055,
3799 0x01F, 0x0D8, 0x076, 0x023, 0x05F, 0x078, 0x00B, 0x01B,
3800 0x02D, 0x010, 0x037, 0x06D, 0x032, 0x00A, 0x01A, 0x01E,
3801 0x01F, 0x02B, 0x00D, 0x077, 0x031, 0x05D, 0x038, 0x027,
3802 0x00C, 0x0E9, 0x033, 0x05E, 0x030, 0x04D, 0x00A, 0x021,
3803 0x007, 0x03D, 0x039, 0x0E8, 0x00B, 0x059, 0x014, 0x027,
3804 0x011, 0x075, 0x00E, 0x009, 0x008, 0x012, 0x000
3805 ]
3806 ];
3807 const VP40_MV_Y_BITS: [[u8; 63]; 7] = [
3808 [
3809 7, 9, 9, 9, 8, 10, 8, 10, 8, 10, 8, 9, 8, 10, 8, 7,
3810 8, 9, 8, 9, 7, 9, 7, 8, 7, 8, 6, 7, 5, 5, 3, 2,
3811 2, 5, 5, 7, 6, 8, 6, 8, 7, 8, 7, 9, 7, 9, 7, 8,
3812 7, 9, 8, 9, 8, 10, 9, 10, 9, 10, 9, 10, 9, 9, 7
3813 ], [
3814 8, 10, 9, 11, 9, 11, 10, 11, 9, 11, 9, 10, 8, 10, 8, 9,
3815 8, 9, 8, 10, 8, 9, 7, 8, 7, 8, 6, 7, 5, 5, 3, 2,
3816 2, 4, 4, 6, 6, 8, 7, 8, 7, 9, 8, 10, 8, 9, 8, 9,
3817 8, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 10, 8
3818 ], [
3819 7, 9, 9, 10, 9, 10, 9, 10, 8, 9, 8, 10, 9, 9, 8, 8,
3820 7, 9, 7, 9, 7, 9, 7, 8, 7, 8, 6, 7, 5, 6, 4, 3,
3821 3, 3, 3, 4, 4, 6, 5, 7, 6, 8, 7, 8, 7, 9, 7, 8,
3822 7, 10, 8, 10, 8, 10, 8, 10, 9, 10, 9, 10, 9, 9, 7
3823 ], [
3824 7, 9, 8, 10, 8, 9, 9, 10, 9, 10, 8, 9, 8, 9, 8, 8,
3825 7, 9, 7, 9, 7, 9, 7, 8, 7, 7, 6, 7, 5, 6, 4, 5,
3826 4, 5, 3, 4, 3, 4, 4, 5, 5, 7, 6, 7, 6, 8, 6, 7,
3827 6, 9, 7, 9, 7, 9, 8, 9, 8, 10, 8, 10, 8, 10, 7
3828 ], [
3829 6, 9, 8, 9, 8, 10, 8, 10, 8, 9, 7, 9, 7, 9, 7, 8,
3830 7, 9, 7, 9, 7, 8, 6, 8, 6, 8, 6, 7, 6, 6, 5, 5,
3831 4, 6, 4, 6, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6,
3832 5, 7, 6, 8, 6, 8, 7, 9, 7, 9, 7, 9, 7, 9, 6
3833 ], [
3834 6, 8, 7, 9, 7, 9, 7, 9, 7, 8, 8, 8, 7, 9, 7, 7,
3835 6, 8, 7, 8, 6, 8, 6, 8, 6, 7, 6, 7, 6, 6, 5, 5,
3836 4, 6, 5, 7, 5, 7, 5, 6, 5, 7, 5, 7, 5, 6, 5, 5,
3837 4, 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 8, 6, 8, 5
3838 ], [
3839 5, 7, 7, 8, 7, 8, 7, 9, 7, 8, 7, 9, 7, 8, 6, 7,
3840 6, 8, 7, 8, 7, 8, 6, 7, 6, 7, 6, 7, 6, 6, 5, 5,
3841 5, 6, 5, 7, 6, 7, 6, 7, 5, 8, 6, 7, 6, 7, 5, 6,
3842 5, 7, 6, 8, 5, 7, 5, 6, 5, 7, 5, 6, 5, 6, 3
3843 ]
3844 ];
3845
3846 const VP40_LOOP_STRENGTH: [i16; 64] = [
3847 30, 25, 20, 20, 15, 15, 14, 14,
3848 13, 13, 12, 12, 11, 11, 10, 10,
3849 9, 9, 8, 8, 7, 7, 7, 7,
3850 6, 6, 6, 6, 5, 5, 5, 5,
3851 4, 4, 4, 4, 3, 3, 3, 3,
3852 2, 2, 2, 2, 2, 2, 2, 2,
3853 2, 2, 2, 2, 2, 2, 2, 2,
3854 1, 1, 1, 1, 1, 1, 1, 1
3855 ];
3856 const VP40_MV_LUT_INDEX: [usize; 32] = [
3857 0, 1, 2, 2, 3, 3, 3, 3,
3858 4, 4, 4, 4, 4, 4, 4, 4,
3859 5, 5, 5, 5, 5, 5, 5, 5,
3860 6, 6, 6, 6, 6, 6, 6, 6
3861 ];