]> git.nihav.org Git - nihav.git/blame - nihav-duck/src/codecs/vp3.rs
vp3: rename in preparation for VP30 decoding
[nihav.git] / nihav-duck / src / codecs / vp3.rs
CommitLineData
5b24175d
KS
1use std::mem;
2use std::ptr;
3use nihav_core::codecs::*;
4use nihav_core::codecs::blockdsp::*;
5use nihav_core::io::bitreader::*;
6use nihav_core::io::codebook::*;
7use nihav_core::io::intcode::*;
8use super::vpcommon::*;
9
10#[derive(Clone,Copy,Debug,PartialEq)]
11enum SBState {
12 Coded,
13 Partial,
14 Uncoded,
15}
16
6543b6f8
KS
17fn map_idx(idx: usize) -> u8 {
18 idx as u8
19}
20
21struct VP31Codes {
5b24175d
KS
22 dc_cb: [Codebook<u8>; 16],
23 ac0_cb: [Codebook<u8>; 16],
24 ac1_cb: [Codebook<u8>; 16],
25 ac2_cb: [Codebook<u8>; 16],
26 ac3_cb: [Codebook<u8>; 16],
27}
28
6543b6f8 29impl VP31Codes {
5b24175d
KS
30 fn new() -> Self {
31 let mut dc_cb: [Codebook<u8>; 16];
32 let mut ac0_cb: [Codebook<u8>; 16];
33 let mut ac1_cb: [Codebook<u8>; 16];
34 let mut ac2_cb: [Codebook<u8>; 16];
35 let mut ac3_cb: [Codebook<u8>; 16];
36 unsafe {
37 dc_cb = mem::uninitialized();
38 ac0_cb = mem::uninitialized();
39 ac1_cb = mem::uninitialized();
40 ac2_cb = mem::uninitialized();
41 ac3_cb = mem::uninitialized();
42 for i in 0..16 {
6543b6f8 43 let mut cr = TableCodebookDescReader::new(&VP31_DC_CODES[i], &VP31_DC_BITS[i], map_idx);
5b24175d
KS
44 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
45 ptr::write(&mut dc_cb[i], cb);
46
6543b6f8 47 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT0_CODES[i], &VP31_AC_CAT0_BITS[i], map_idx);
5b24175d
KS
48 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
49 ptr::write(&mut ac0_cb[i], cb);
6543b6f8 50 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT1_CODES[i], &VP31_AC_CAT1_BITS[i], map_idx);
5b24175d
KS
51 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
52 ptr::write(&mut ac1_cb[i], cb);
6543b6f8 53 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT2_CODES[i], &VP31_AC_CAT2_BITS[i], map_idx);
5b24175d
KS
54 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
55 ptr::write(&mut ac2_cb[i], cb);
6543b6f8 56 let mut cr = TableCodebookDescReader::new(&VP31_AC_CAT3_CODES[i], &VP31_AC_CAT3_BITS[i], map_idx);
5b24175d
KS
57 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
58 ptr::write(&mut ac3_cb[i], cb);
59 }
60 }
61 Self { dc_cb, ac0_cb, ac1_cb, ac2_cb, ac3_cb }
62 }
63}
64
65#[derive(Clone)]
66struct Block {
67 btype: VPMBType,
68 coeffs: [i16; 64],
69 has_ac: bool,
70 idx: usize,
71 mv: MV,
72 coded: bool,
73}
74
75impl Block {
76 fn new() -> Self {
77 Self {
78 btype: VPMBType::Intra,
79 coeffs: [0; 64],
80 has_ac: false,
81 idx: 0,
82 mv: ZERO_MV,
83 coded: false,
84 }
85 }
86}
87
88type ReadRunFunc = fn (&mut BitReader) -> DecoderResult<usize>;
89
6543b6f8
KS
90const VP31_LONG_RUN_BASE: [usize; 7] = [ 1, 2, 4, 6, 10, 18, 34 ];
91const VP31_LONG_RUN_BITS: [u8; 7] = [ 0, 1, 1, 2, 3, 4, 12 ];
5b24175d
KS
92fn read_long_run(br: &mut BitReader) -> DecoderResult<usize> {
93 let pfx = br.read_code(UintCodeType::LimitedUnary(6, 0))? as usize;
94 if pfx == 0 { return Ok(1); }
6543b6f8 95 Ok(VP31_LONG_RUN_BASE[pfx] + (br.read(VP31_LONG_RUN_BITS[pfx])? as usize))
5b24175d
KS
96}
97
6543b6f8
KS
98const VP31_SHORT_RUN_BASE: [usize; 6] = [ 1, 3, 5, 7, 11, 15 ];
99const VP31_SHORT_RUN_BITS: [u8; 6] = [ 1, 1, 1, 2, 2, 4 ];
5b24175d
KS
100fn read_short_run(br: &mut BitReader) -> DecoderResult<usize> {
101 let pfx = br.read_code(UintCodeType::LimitedUnary(5, 0))? as usize;
6543b6f8 102 Ok(VP31_SHORT_RUN_BASE[pfx] + (br.read(VP31_SHORT_RUN_BITS[pfx])? as usize))
5b24175d
KS
103}
104
105struct BitRunDecoder {
106 value: bool,
107 run: usize,
108 read_run: ReadRunFunc,
109}
110
111impl BitRunDecoder {
112 fn new(br: &mut BitReader, read_run: ReadRunFunc) -> DecoderResult<Self> {
113 let value = !br.read_bool()?; // it will be flipped before run decoding
114 Ok(Self { value, run: 0, read_run })
115 }
116 fn get_val(&mut self, br: &mut BitReader) -> DecoderResult<bool> {
117 if self.run == 0 {
118 self.value = !self.value;
119 self.run = (self.read_run)(br)?;
120 }
121 self.run -= 1;
122 Ok(self.value)
123 }
124}
125
126struct VP34Decoder {
127 info: NACodecInfoRef,
128 width: usize,
129 height: usize,
130 mb_w: usize,
131 mb_h: usize,
132 version: u8,
133 is_intra: bool,
134 quant: usize,
135 shuf: VPShuffler,
6543b6f8 136 codes: VP31Codes,
5b24175d
KS
137 loop_str: i16,
138
139 blocks: Vec<Block>,
140 y_blocks: usize,
141 y_sbs: usize,
142 qmat_y: [i16; 64],
143 qmat_c: [i16; 64],
144 qmat_inter: [i16; 64],
145
146 eob_run: usize,
147 last_dc: [i16; 3],
148
149 blk_addr: Vec<usize>,
150 sb_info: Vec<SBState>,
151 sb_blocks: Vec<u8>,
152}
153
154fn read_mv_comp_packed(br: &mut BitReader) -> DecoderResult<i16> {
155 let code = br.read(3)?;
156 match code {
157 0 => Ok(0),
158 1 => Ok(1),
159 2 => Ok(-1),
160 3 => if br.read_bool()? { Ok(-2) } else { Ok(2) },
161 4 => if br.read_bool()? { Ok(-3) } else { Ok(3) },
162 5 => {
163 let val = (br.read(2)? as i16) + 4;
164 if br.read_bool()? {
165 Ok(-val)
166 } else {
167 Ok(val)
168 }
169 },
170 6 => {
171 let val = (br.read(3)? as i16) + 8;
172 if br.read_bool()? {
173 Ok(-val)
174 } else {
175 Ok(val)
176 }
177 },
178 _ => {
179 let val = (br.read(4)? as i16) + 16;
180 if br.read_bool()? {
181 Ok(-val)
182 } else {
183 Ok(val)
184 }
185 },
186 }
187}
188
189fn read_mv_packed(br: &mut BitReader) -> DecoderResult<MV> {
190 let x = read_mv_comp_packed(br)?;
191 let y = read_mv_comp_packed(br)?;
192 Ok(MV{ x, y })
193}
194
195fn read_mv_comp_raw(br: &mut BitReader) -> DecoderResult<i16> {
196 let val = br.read(5)? as i16;
197 if br.read_bool()? {
198 Ok(-val)
199 } else {
200 Ok(val)
201 }
202}
203
204fn read_mv_raw(br: &mut BitReader) -> DecoderResult<MV> {
205 let x = read_mv_comp_raw(br)?;
206 let y = read_mv_comp_raw(br)?;
207 Ok(MV{ x, y })
208}
209
210fn rescale_qmat(dst_qmat: &mut [i16; 64], base_qmat: &[i16; 64], dc_quant: i16, ac_quant: i16) {
211 for (dst, src) in dst_qmat.iter_mut().zip(base_qmat.iter()) {
212 *dst = (src.wrapping_mul(ac_quant) / 100).max(2) << 2;
213 }
214 dst_qmat[0] = (base_qmat[0] * dc_quant / 100).max(4) << 2;
215}
216
6543b6f8
KS
217fn expand_token(blk: &mut Block, br: &mut BitReader, eob_run: &mut usize, coef_no: usize, token: u8) -> DecoderResult<()> {
218 match token {
219 // EOBs
220 0 | 1 | 2 => { *eob_run = (token as usize) + 1; },
221 3 | 4 | 5 => {
222 let bits = token - 1;
223 *eob_run = (br.read(bits)? as usize) + (1 << bits);
224 },
225 6 => { *eob_run = br.read(12)? as usize; },
226 // zero runs
227 7 | 8 => {
228 let bits = if token == 7 { 3 } else { 6 };
229 let run = (br.read(bits)? as usize) + 1;
230 blk.idx += run;
231 validate!(blk.idx <= 64);
232 },
233 // single coefficients
234 9 | 10 | 11 | 12 => {
235 let val = (i16::from(token) - 7) >> 1;
236 if (token & 1) == 1 {
237 blk.coeffs[ZIGZAG[blk.idx]] = val;
238 } else {
239 blk.coeffs[ZIGZAG[blk.idx]] = -val;
240 }
241 blk.idx += 1;
242 },
243 13 | 14 | 15 | 16 => {
244 let val = i16::from(token) - 10;
245 if !br.read_bool()? {
246 blk.coeffs[ZIGZAG[blk.idx]] = val;
247 } else {
248 blk.coeffs[ZIGZAG[blk.idx]] = -val;
249 }
250 blk.idx += 1;
251 },
252 17 | 18 | 19 | 20 | 21 | 22 => {
253 let add_bits = if token == 22 { 9 } else { token - 16 };
254 let sign = br.read_bool()?;
255 let val = (br.read(add_bits)? as i16) + VP3_LITERAL_BASE[(token - 17) as usize];
256 if !sign {
257 blk.coeffs[ZIGZAG[blk.idx]] = val;
258 } else {
259 blk.coeffs[ZIGZAG[blk.idx]] = -val;
260 }
261 blk.idx += 1;
262 }
263 // zero run plus coefficient
264 23 | 24 | 25 | 26 | 27 => {
265 blk.idx += (token - 22) as usize;
266 validate!(blk.idx < 64);
267 if !br.read_bool()? {
268 blk.coeffs[ZIGZAG[blk.idx]] = 1;
269 } else {
270 blk.coeffs[ZIGZAG[blk.idx]] = -1;
271 }
272 blk.idx += 1;
273 },
274 28 | 29 => {
275 let run_bits = token - 26;
276 if token == 28 {
277 blk.idx += 6;
278 } else {
279 blk.idx += 10;
280 }
281 let sign = br.read_bool()?;
282 blk.idx += br.read(run_bits)? as usize;
283 validate!(blk.idx < 64);
284 if !sign {
285 blk.coeffs[ZIGZAG[blk.idx]] = 1;
286 } else {
287 blk.coeffs[ZIGZAG[blk.idx]] = -1;
288 }
289 blk.idx += 1;
290 },
291 30 => {
292 blk.idx += 1;
293 validate!(blk.idx < 64);
294 let sign = br.read_bool()?;
295 let val = (br.read(1)? as i16) + 2;
296 if !sign {
297 blk.coeffs[ZIGZAG[blk.idx]] = val;
298 } else {
299 blk.coeffs[ZIGZAG[blk.idx]] = -val;
300 }
301 blk.idx += 1;
302 },
303 _ => {
304 let sign = br.read_bool()?;
305 let val = (br.read(1)? as i16) + 2;
306 blk.idx += (br.read(1)? as usize) + 2;
307 validate!(blk.idx < 64);
308 if !sign {
309 blk.coeffs[ZIGZAG[blk.idx]] = val;
310 } else {
311 blk.coeffs[ZIGZAG[blk.idx]] = -val;
312 }
313 blk.idx += 1;
314 },
315 };
316 if *eob_run > 0 {
317 blk.idx = 64;
318 *eob_run -= 1;
319 } else if coef_no > 0 {
320 blk.has_ac = true;
321 }
322 Ok(())
323}
5b24175d
KS
324macro_rules! fill_dc_pred {
325 ($self: expr, $ref_id: expr, $pred: expr, $pp: expr, $bit: expr, $idx: expr) => {
326 if $self.blocks[$idx].coded && $self.blocks[$idx].btype.get_ref_id() == $ref_id {
327 $pred[$bit] = $self.blocks[$idx].coeffs[0] as i32;
328 $pp |= 1 << $bit;
329 }
330 };
331}
332
333fn vp3_interp00(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize)
334{
335 let mut didx = 0;
336 let mut sidx = 0;
337 for _ in 0..bh {
338 for x in 0..bw { dst[didx + x] = src[sidx + x]; }
339 didx += dstride;
340 sidx += sstride;
341 }
342}
343
344fn vp3_interp01(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize)
345{
346 let mut didx = 0;
347 let mut sidx = 0;
348 for _ in 0..bh {
349 for x in 0..bw { dst[didx + x] = (((src[sidx + x] as u16) + (src[sidx + x + 1] as u16)) >> 1) as u8; }
350 didx += dstride;
351 sidx += sstride;
352 }
353}
354
355fn vp3_interp10(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize)
356{
357 let mut didx = 0;
358 let mut sidx = 0;
359 for _ in 0..bh {
360 for x in 0..bw { dst[didx + x] = (((src[sidx + x] as u16) + (src[sidx + x + sstride] as u16)) >> 1) as u8; }
361 didx += dstride;
362 sidx += sstride;
363 }
364}
365
366fn vp3_interp11(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize)
367{
368 let mut didx = 0;
369 let mut sidx = 0;
370 for _ in 0..bh {
371 for x in 0..bw {
372 dst[didx + x] = (((src[sidx + x] as u16) +
373 (src[sidx + x + 1] as u16) +
374 (src[sidx + x + sstride] as u16) +
375 (src[sidx + x + sstride + 1] as u16)) >> 2) as u8;
376 }
377 didx += dstride;
378 sidx += sstride;
379 }
380}
381
6543b6f8 382fn vp31_loop_filter(data: &mut [u8], mut off: usize, step: usize, stride: usize, loop_str: i16) {
5b24175d
KS
383 for _ in 0..8 {
384 let a = data[off - step * 2] as i16;
385 let b = data[off - step] as i16;
386 let c = data[off] as i16;
387 let d = data[off + step] as i16;
388 let mut diff = ((a - d) + 3 * (c - b) + 4) >> 3;
389 if diff.abs() >= 2 * loop_str {
390 diff = 0;
391 } else if diff.abs() >= loop_str {
392 if diff < 0 {
393 diff = -diff - 2 * loop_str;
394 } else {
395 diff = -diff + 2 * loop_str;
396 }
397 }
398 if diff != 0 {
399 data[off - step] = (b + diff).max(0).min(255) as u8;
400 data[off] = (c - diff).max(0).min(255) as u8;
401 }
402
403 off += stride;
404 }
405}
406
6543b6f8 407fn vp31_loop_filter_v(frm: &mut NASimpleVideoFrame<u8>, x: usize, y: usize, plane: usize, loop_str: i16) {
5b24175d 408 let off = frm.offset[plane] + x + y * frm.stride[plane];
6543b6f8 409 vp31_loop_filter(frm.data, off, 1, frm.stride[plane], loop_str);
5b24175d
KS
410}
411
6543b6f8 412fn vp31_loop_filter_h(frm: &mut NASimpleVideoFrame<u8>, x: usize, y: usize, plane: usize, loop_str: i16) {
5b24175d 413 let off = frm.offset[plane] + x + y * frm.stride[plane];
6543b6f8 414 vp31_loop_filter(frm.data, off, frm.stride[plane], 1, loop_str);
5b24175d
KS
415}
416
417pub const VP3_INTERP_FUNCS: &[blockdsp::BlkInterpFunc] = &[ vp3_interp00, vp3_interp01, vp3_interp10, vp3_interp11 ];
418
419impl VP34Decoder {
420 fn new(version: u8) -> Self {
421 Self {
422 info: NACodecInfoRef::default(),
423 width: 0,
424 height: 0,
425 mb_w: 0,
426 mb_h: 0,
427 version,
428 is_intra: true,
429 quant: 0,
430 shuf: VPShuffler::new(),
6543b6f8 431 codes: VP31Codes::new(),
5b24175d
KS
432 loop_str: 0,
433
434 blocks: Vec::new(),
435 y_blocks: 0,
436 y_sbs: 0,
437
438 qmat_y: [0; 64],
439 qmat_c: [0; 64],
440 qmat_inter: [0; 64],
441
442 eob_run: 0,
443 last_dc: [0; 3],
444
445 blk_addr: Vec::new(),
446 sb_info: Vec::new(),
447 sb_blocks: Vec::new(),
448 }
449 }
450 fn parse_header(&mut self, br: &mut BitReader) -> DecoderResult<()> {
451 self.is_intra = !br.read_bool()?;
452 br.skip(1)?;
453 self.quant = br.read(6)? as usize;
6543b6f8 454 self.loop_str = VP31_LOOP_STRENGTH[self.quant];
5b24175d
KS
455println!("quant = {}", self.quant);
456 if self.is_intra {
457 if br.peek(8) != 0 {
458 unimplemented!();
459 }
460 let version = br.read(13)?;
461println!("intra, ver {} (self {})", version, self.version);
462 validate!((self.version == 3 && version == 1) || (self.version == 4 && version == 3));
463 let coding_type = br.read(1)?;
464 validate!(coding_type == 0);
465 br.skip(2)?;
466 }
467 Ok(())
468 }
6543b6f8 469 fn vp31_unpack_sb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
5b24175d
KS
470 let mut has_uncoded = false;
471 let mut has_partial = false;
472 {
473 let mut brun = BitRunDecoder::new(br, read_long_run)?;
474 for sb in self.sb_info.iter_mut() {
475 if brun.get_val(br)? {
476 *sb = SBState::Partial;
477 has_partial = true;
478 } else {
479 *sb = SBState::Uncoded;
480 has_uncoded = true;
481 }
482 }
483 }
484 if has_uncoded {
485 let mut brun = BitRunDecoder::new(br, read_long_run)?;
486 let mut cur_blk = 0;
487 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()) {
488 let nblks = *nblk as usize;
489 if *sb != SBState::Partial && brun.get_val(br)? {
490 *sb = SBState::Coded;
491 for _ in 0..nblks {
492 let blk_idx = self.blk_addr[cur_blk] >> 2;
493 self.blocks[blk_idx].coded = true;
494 cur_blk += 1;
495 }
496 } else {
497 for _ in 0..nblks {
498 let blk_idx = self.blk_addr[cur_blk] >> 2;
499 self.blocks[blk_idx].coded = false;
500 cur_blk += 1;
501 }
502 }
503 }
504 }
505 if has_partial {
506 let mut brun = BitRunDecoder::new(br, read_short_run)?;
507 let mut cur_blk = 0;
508 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()) {
509 let nblks = *nblk as usize;
510 if *sb == SBState::Partial {
511 for _ in 0..nblks {
512 let blk_idx = self.blk_addr[cur_blk] >> 2;
513 self.blocks[blk_idx].coded = brun.get_val(br)?;
514 cur_blk += 1;
515 }
516 } else {
517 cur_blk += nblks;
518 }
519 }
520 }
521 Ok(())
522 }
6543b6f8 523 fn vp31_unpack_mb_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
5b24175d
KS
524 let mut modes = [VPMBType::InterNoMV; 8];
525 let alphabet = br.read(3)? as usize;
526 let raw_modes = alphabet >= 7;
527 if alphabet == 0 {
6543b6f8 528 for mode in VP31_DEFAULT_MB_MODES.iter() {
5b24175d
KS
529 modes[br.read(3)? as usize] = *mode;
530 }
531 } else if alphabet < 7 {
6543b6f8 532 modes.copy_from_slice(&VP31_MB_MODES[alphabet - 1]);
5b24175d
KS
533 }
534
535 let mut cur_blk = 0;
536 for (sb, nblk) in self.sb_info.iter_mut().zip(self.sb_blocks.iter()).take(self.y_sbs) {
537 let nblks = *nblk as usize;
538 if *sb == SBState::Uncoded {
539 for _ in 0..nblks {
540 self.blocks[self.blk_addr[cur_blk] >> 2].btype = VPMBType::InterNoMV;
541 cur_blk += 1;
542 }
543 } else {
544 for _ in 0..nblks/4 {
545 let mut coded = *sb == SBState::Coded;
546 if !coded {
547 for blk in 0..4 {
548 if self.blocks[self.blk_addr[cur_blk + blk] >> 2].coded {
549 coded = true;
550 break;
551 }
552 }
553 }
554 let mode = if !coded {
555 VPMBType::InterNoMV
556 } else if !raw_modes {
557 let code = br.read_code(UintCodeType::LimitedUnary(7, 0))?;
558 modes[code as usize]
559 } else {
6543b6f8 560 VP31_DEFAULT_MB_MODES[br.read(3)? as usize]
5b24175d
KS
561 };
562 for _ in 0..4 {
563 self.blocks[self.blk_addr[cur_blk] >> 2].btype = mode;
564 cur_blk += 1;
565 }
566 }
567 }
568 }
569 // replicate types for chroma
570 let mut off_y = 0;
571 let mut off_u = self.y_blocks;
572 let mut off_v = off_u + self.mb_w * self.mb_h;
573 for _blk_y in 0..self.mb_h {
574 for blk_x in 0..self.mb_w {
575 let btype = self.blocks[off_y + blk_x * 2].btype;
576 self.blocks[off_u + blk_x].btype = btype;
577 self.blocks[off_v + blk_x].btype = btype;
578 }
579 off_y += self.mb_w * 2 * 2;
580 off_u += self.mb_w;
581 off_v += self.mb_w;
582 }
583 Ok(())
584 }
6543b6f8 585 fn vp31_unpack_mv_info(&mut self, br: &mut BitReader) -> DecoderResult<()> {
5b24175d
KS
586 let mut last_mv = ZERO_MV;
587 let mut last2_mv = ZERO_MV;
588 let read_mv = if br.read_bool()? { read_mv_raw } else { read_mv_packed };
589
590 let mut cur_blk = 0;
591 for _ in 0..self.y_blocks/4 {
592 if self.blocks[self.blk_addr[cur_blk] >> 2].btype == VPMBType::InterFourMV {
593 for _ in 0..4 {
594 let blk = &mut self.blocks[self.blk_addr[cur_blk] >> 2];
595 if blk.coded {
596 blk.mv = (read_mv)(br)?;
597 last2_mv = last_mv;
598 last_mv = blk.mv;
599 }
600 cur_blk += 1;
601 }
602 } else {
603 let cur_mv;
604 match self.blocks[self.blk_addr[cur_blk] >> 2].btype {
605 VPMBType::Intra | VPMBType::InterNoMV | VPMBType::GoldenNoMV => {
606 cur_mv = ZERO_MV;
607 },
608 VPMBType::InterMV => {
609 cur_mv = (read_mv)(br)?;
610 last2_mv = last_mv;
611 last_mv = cur_mv;
612 },
613 VPMBType::InterNearest => {
614 cur_mv = last_mv;
615 },
616 VPMBType::InterNear => {
617 cur_mv = last2_mv;
618 std::mem::swap(&mut last_mv, &mut last2_mv);
619 },
620 _ => { // GoldenMV
621 cur_mv = (read_mv)(br)?;
622 },
623 };
624 for _ in 0..4 {
625 self.blocks[self.blk_addr[cur_blk] >> 2].mv = cur_mv;
626 cur_blk += 1;
627 }
628 }
629 }
630 Ok(())
631 }
6543b6f8 632 fn vp31_unpack_coeffs(&mut self, br: &mut BitReader, coef_no: usize, table_y: usize, table_c: usize) -> DecoderResult<()> {
5b24175d
KS
633 let cbs = if coef_no == 0 {
634 [&self.codes.dc_cb[table_y], &self.codes.dc_cb[table_c]]
635 } else if coef_no < 6 {
636 [&self.codes.ac0_cb[table_y], &self.codes.ac0_cb[table_c]]
637 } else if coef_no < 15 {
638 [&self.codes.ac1_cb[table_y], &self.codes.ac1_cb[table_c]]
639 } else if coef_no < 28 {
640 [&self.codes.ac2_cb[table_y], &self.codes.ac2_cb[table_c]]
641 } else {
642 [&self.codes.ac3_cb[table_y], &self.codes.ac3_cb[table_c]]
643 };
644 for blkaddr in self.blk_addr.iter() {
645 let blk: &mut Block = &mut self.blocks[blkaddr >> 2];
646 if !blk.coded || blk.idx != coef_no { continue; }
647 if self.eob_run > 0 {
648 blk.idx = 64;
649 self.eob_run -= 1;
650 continue;
651 }
652 let cb = if (blkaddr & 3) == 0 { cbs[0] } else { cbs[1] };
653 let token = br.read_cb(cb)?;
6543b6f8 654 expand_token(blk, br, &mut self.eob_run, coef_no, token)?;
5b24175d
KS
655 }
656 Ok(())
657 }
6543b6f8 658 fn decode_vp31(&mut self, br: &mut BitReader, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<()> {
5b24175d
KS
659 for blk in self.blocks.iter_mut() {
660 blk.coeffs = [0; 64];
661 blk.idx = 0;
662 blk.coded = false;
663 blk.has_ac = false;
664 }
665 if self.is_intra {
666 for sb in self.sb_info.iter_mut() { *sb = SBState::Coded; }
667 for blk in self.blocks.iter_mut() {
668 blk.btype = VPMBType::Intra;
669 blk.coded = true;
670 }
671 } else {
672 if self.shuf.get_last().is_none() || self.shuf.get_golden().is_none() {
673 return Err(DecoderError::MissingReference);
674 }
6543b6f8
KS
675 self.vp31_unpack_sb_info(br)?;
676 self.vp31_unpack_mb_info(br)?;
677 self.vp31_unpack_mv_info(br)?;
5b24175d 678 }
6543b6f8
KS
679 let dc_quant = VP31_DC_SCALES[self.quant];
680 let ac_quant = VP31_AC_SCALES[self.quant];
5b24175d
KS
681 rescale_qmat(&mut self.qmat_y, VP3_QMAT_Y, dc_quant, ac_quant);
682 rescale_qmat(&mut self.qmat_c, VP3_QMAT_C, dc_quant, ac_quant);
683 rescale_qmat(&mut self.qmat_inter, VP3_QMAT_INTER, dc_quant, ac_quant);
684
685 self.eob_run = 0;
686 let dc_table_y = br.read(4)? as usize;
687 let dc_table_c = br.read(4)? as usize;
6543b6f8 688 self.vp31_unpack_coeffs(br, 0, dc_table_y, dc_table_c)?;
5b24175d
KS
689 self.restore_dcs();
690
691 let ac_table_y = br.read(4)? as usize;
692 let ac_table_c = br.read(4)? as usize;
693 for coef_no in 1..64 {
6543b6f8 694 self.vp31_unpack_coeffs(br, coef_no, ac_table_y, ac_table_c)?;
5b24175d
KS
695 }
696
697 if self.is_intra {
698 self.output_blocks_intra(frm);
699 } else {
700 self.output_blocks_inter(frm);
701 }
702 if self.loop_str > 0 {
6543b6f8 703 self.vp31_loop_filter(frm);
5b24175d
KS
704 }
705
706 Ok(())
707 }
708 fn decode_vp4(&mut self) -> DecoderResult<()> {
709unimplemented!();
710 }
711 fn predict_dc(&self, bx: usize, by: usize, bw: usize, blk_idx: usize) -> i16 {
712 let mut preds = [0i32; 4];
713 let mut pp: usize = 0;
714 let ref_id = self.blocks[blk_idx].btype.get_ref_id();
715 let is_right = bx == bw - 1;
716 if bx > 0 {
717 fill_dc_pred!(self, ref_id, preds, pp, 0, blk_idx - 1);
718 if by > 0 {
719 fill_dc_pred!(self, ref_id, preds, pp, 1, blk_idx - 1 - bw);
720 }
721 }
722 if by > 0 {
723 fill_dc_pred!(self, ref_id, preds, pp, 2, blk_idx - bw);
724 if !is_right {
725 fill_dc_pred!(self, ref_id, preds, pp, 3, blk_idx + 1 - bw);
726 }
727 }
728 if pp == 0 { return self.last_dc[ref_id as usize]; }
729 let mut pred = 0i32;
730 for i in 0..4 {
731 if (pp & (1 << i)) != 0 {
6543b6f8 732 pred += (preds[i] as i32) * (VP31_DC_WEIGHTS[pp][i] as i32);
5b24175d
KS
733 }
734 }
6543b6f8 735 pred /= VP31_DC_WEIGHTS[pp][4] as i32;
5b24175d
KS
736 if (pp & 7) == 7 {
737 if (pred - preds[2]).abs() > 128 { return preds[2] as i16; }
738 if (pred - preds[0]).abs() > 128 { return preds[0] as i16; }
739 if (pred - preds[1]).abs() > 128 { return preds[1] as i16; }
740 }
741 pred as i16
742 }
743 fn restore_dcs(&mut self) {
744 let blk_stride = self.mb_w * 2;
745 let mut blk_idx = 0;
746 self.last_dc = [0; 3];
747 for by in 0..self.mb_h*2 {
748 for bx in 0..self.mb_w*2 {
749 if !self.blocks[blk_idx + bx].coded { continue; }
750 let dc = self.predict_dc(bx, by, self.mb_w*2, blk_idx + bx);
751 self.blocks[blk_idx + bx].coeffs[0] += dc;
752 self.last_dc[self.blocks[blk_idx + bx].btype.get_ref_id() as usize] = self.blocks[blk_idx + bx].coeffs[0];
753 }
754 blk_idx += blk_stride;
755 }
756 let blk_stride = self.mb_w;
757 for _plane in 1..3 {
758 self.last_dc = [0; 3];
759 for by in 0..self.mb_h {
760 for bx in 0..self.mb_w {
761 if !self.blocks[blk_idx + bx].coded { continue; }
762 let dc = self.predict_dc(bx, by, self.mb_w, blk_idx + bx);
763 self.blocks[blk_idx + bx].coeffs[0] += dc;
764 self.last_dc[self.blocks[blk_idx + bx].btype.get_ref_id() as usize] = self.blocks[blk_idx + bx].coeffs[0];
765 }
766 blk_idx += blk_stride;
767 }
768 }
769 }
770 fn output_blocks_intra(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
771 let mut biter = self.blocks.iter_mut();
772 for by in 0..self.mb_h*2 {
773 for bx in 0..self.mb_w*2 {
774 let mut blk = biter.next().unwrap();
775 let qmat = if blk.btype == VPMBType::Intra { &self.qmat_y } else { &self.qmat_inter };
776 blk.coeffs[0] *= qmat[0];
777 if blk.has_ac {
778 unquant(&mut blk.coeffs, qmat);
779 vp_put_block(&mut blk.coeffs, bx, by, 0, frm);
780 } else {
781 vp_put_block_dc(&mut blk.coeffs, bx, by, 0, frm);
782 }
783 }
784 }
785 for plane in 1..3 {
786 for by in 0..self.mb_h {
787 for bx in 0..self.mb_w {
788 let mut blk = biter.next().unwrap();
789 let qmat = if blk.btype == VPMBType::Intra { &self.qmat_c } else { &self.qmat_inter };
790 blk.coeffs[0] *= qmat[0];
791 if blk.has_ac {
792 unquant(&mut blk.coeffs, qmat);
793 vp_put_block(&mut blk.coeffs, bx, by, plane, frm);
794 } else {
795 vp_put_block_dc(&mut blk.coeffs, bx, by, plane, frm);
796 }
797 }
798 }
799 }
800 }
801 fn output_blocks_inter(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
802 let mut blk_idx = 0;
803 let bstride = self.mb_w * 2;
804 for by in (0..self.mb_h*2).step_by(2) {
805 for bx in (0..self.mb_w*2).step_by(2) {
806 if self.blocks[blk_idx + bx].btype != VPMBType::InterFourMV {
807 continue;
808 }
809 let mv_a = self.blocks[blk_idx + bx].mv;
810 let mv_b = self.blocks[blk_idx + bx + 1].mv;
811 let mv_c = self.blocks[blk_idx + bx + bstride].mv;
812 let mv_d = self.blocks[blk_idx + bx + 1 + bstride].mv;
813 let mut mv_sum = mv_a + mv_b + mv_c + mv_d;
814 mv_sum.x = (mv_sum.x + 2) >> 2;
815 mv_sum.y = (mv_sum.y + 2) >> 2;
816
817 let src = self.shuf.get_last().unwrap();
818 let mode = ((mv_a.x & 1) + (mv_a.y & 1) * 2) as usize;
819 copy_block(frm, src.clone(), 0, bx * 8, by * 8, mv_a.x >> 1, mv_a.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
820 let mode = ((mv_b.x & 1) + (mv_b.y & 1) * 2) as usize;
821 copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8, mv_b.x >> 1, mv_b.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
822 let mode = ((mv_c.x & 1) + (mv_c.y & 1) * 2) as usize;
823 copy_block(frm, src.clone(), 0, bx * 8, by * 8 + 8, mv_c.x >> 1, mv_c.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
824 let mode = ((mv_d.x & 1) + (mv_d.y & 1) * 2) as usize;
825 copy_block(frm, src.clone(), 0, bx * 8 + 8, by * 8 + 8, mv_d.x >> 1, mv_d.y >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
826
827 let mx = (mv_sum.x >> 1) | (mv_sum.x & 1);
828 let my = (mv_sum.y >> 1) | (mv_sum.y & 1);
829 let mode = ((mx & 1) + (my & 1) * 2) as usize;
830 copy_block(frm, src.clone(), 1, bx * 4, by * 4, mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
831 copy_block(frm, src.clone(), 2, bx * 4, by * 4, mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
832 }
833 blk_idx += bstride;
834 }
835
836 let mut biter = self.blocks.iter_mut();
837 for by in 0..self.mb_h*2 {
838 for bx in 0..self.mb_w*2 {
839 let mut blk = biter.next().unwrap();
840 // do MC for whole macroblock
841 if !blk.btype.is_intra() && (((bx | by) & 1) == 0) && (blk.btype != VPMBType::InterFourMV) {
842 let src = if blk.btype.get_ref_id() == 1 {
843 self.shuf.get_last().unwrap()
844 } else {
845 self.shuf.get_golden().unwrap()
846 };
847 let mode = ((blk.mv.x & 1) + (blk.mv.y & 1) * 2) as usize;
848 copy_block(frm, src.clone(), 0, bx * 8, by * 8, blk.mv.x >> 1, blk.mv.y >> 1, 16, 16, 0, 1, mode, VP3_INTERP_FUNCS);
849 let mx = (blk.mv.x >> 1) | (blk.mv.x & 1);
850 let my = (blk.mv.y >> 1) | (blk.mv.y & 1);
851 let mode = ((mx & 1) + (my & 1) * 2) as usize;
852 copy_block(frm, src.clone(), 1, bx * 4, by * 4, mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
853 copy_block(frm, src.clone(), 2, bx * 4, by * 4, mx >> 1, my >> 1, 8, 8, 0, 1, mode, VP3_INTERP_FUNCS);
854 }
855 let qmat = if blk.btype.is_intra() { &self.qmat_y } else { &self.qmat_inter };
856 blk.coeffs[0] *= qmat[0];
857 if blk.has_ac {
858 unquant(&mut blk.coeffs, qmat);
859 }
860 if blk.btype.is_intra() {
861 if !blk.coded {
862 copy_block(frm, self.shuf.get_last().unwrap(), 0, bx * 8, by * 8, 0, 0, 8, 8, 0, 1, 0, VP3_INTERP_FUNCS);
863 } else if blk.has_ac {
864 vp_put_block(&mut blk.coeffs, bx, by, 0, frm);
865 } else {
866 vp_put_block_dc(&mut blk.coeffs, bx, by, 0, frm);
867 }
868 } else if blk.coded {
869 if blk.has_ac {
870 vp_add_block(&mut blk.coeffs, bx, by, 0, frm);
871 } else {
872 vp_add_block_dc(&mut blk.coeffs, bx, by, 0, frm);
873 }
874 }
875 }
876 }
877 for plane in 1..3 {
878 for by in 0..self.mb_h {
879 for bx in 0..self.mb_w {
880 let mut blk = biter.next().unwrap();
881 let qmat = if blk.btype.is_intra() { &self.qmat_c } else { &self.qmat_inter };
882 blk.coeffs[0] *= qmat[0];
883 if blk.has_ac {
884 unquant(&mut blk.coeffs, qmat);
885 }
886 if blk.btype.is_intra() {
887 if !blk.coded {
888 copy_block(frm, self.shuf.get_last().unwrap(), plane, bx * 8, by * 8, 0, 0, 8, 8, 0, 1, 0, VP3_INTERP_FUNCS);
889 } else if blk.has_ac {
890 vp_put_block(&mut blk.coeffs, bx, by, plane, frm);
891 } else {
892 vp_put_block_dc(&mut blk.coeffs, bx, by, plane, frm);
893 }
894 } else if blk.coded {
895 if blk.has_ac {
896 vp_add_block(&mut blk.coeffs, bx, by, plane, frm);
897 } else {
898 vp_add_block_dc(&mut blk.coeffs, bx, by, plane, frm);
899 }
900 }
901 }
902 }
903 }
904 }
6543b6f8 905 fn vp31_loop_filter(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
5b24175d
KS
906 let mut blk_idx = 0;
907 let blk_w = self.mb_w * 2;
908 for by in 0..self.mb_h*2 {
909 for bx in 0..blk_w {
910 let blk = &self.blocks[blk_idx + bx];
911 if (bx > 0) && blk.coded {
6543b6f8 912 vp31_loop_filter_v(frm, bx * 8, by * 8, 0, self.loop_str);
5b24175d
KS
913 }
914 if (by > 0) && blk.coded {
6543b6f8 915 vp31_loop_filter_h(frm, bx * 8, by * 8, 0, self.loop_str);
5b24175d
KS
916 }
917 if (bx < blk_w - 1) && !self.blocks[blk_idx + bx + 1].coded {
6543b6f8 918 vp31_loop_filter_v(frm, bx * 8 + 8, by * 8, 0, self.loop_str);
5b24175d
KS
919 }
920 if (by < self.mb_h * 2 - 1) && !self.blocks[blk_idx + bx + blk_w].coded {
6543b6f8 921 vp31_loop_filter_h(frm, bx * 8, by * 8 + 8, 0, self.loop_str);
5b24175d
KS
922 }
923 }
924 blk_idx += blk_w;
925 }
926/* for plane in 1..3 {
927 for by in 0..self.mb_h {
928 for bx in 0..self.mb_w {
929 }
930 }
931 }*/
932 }
933 fn generate_block_addr(&mut self) {
934 let sb_w_y = (self.width + 31) >> 5;
935 let sb_h_y = (self.height + 31) >> 5;
936 let sb_w_c = ((self.width >> 1) + 31) >> 5;
937 let sb_h_c = ((self.height >> 1) + 31) >> 5;
938 self.y_sbs = sb_w_y * sb_h_y;
939 let tot_sb = sb_w_y * sb_h_y + 2 * sb_w_c * sb_h_c;
940 let bw = self.width >> 3;
941 let bh = self.height >> 3;
942 let tot_blk = bw * bh * 3 / 2;
943 self.sb_info.resize(tot_sb, SBState::Uncoded);
944 self.sb_blocks = Vec::with_capacity(tot_sb);
945 self.blk_addr = Vec::with_capacity(tot_blk);
946 self.y_blocks = bw * bh;
947 let mut base_idx = 0;
948 for plane in 0..3 {
949 let w = if plane > 0 { self.width >> 1 } else { self.width };
950 let h = if plane > 0 { self.height >> 1 } else { self.height };
951 let sb_w = (w + 31) >> 5;
952 let sb_h = (h + 31) >> 5;
953 let blk_w = w >> 3;
954 let blk_h = h >> 3;
955 for y in 0..sb_h {
956 for x in 0..sb_w {
957 let mut nblocks = 0;
958 for blk_no in 0..16 {
959 let bx = x * 4 + HILBERT_ORDER[blk_no][0];
960 let by = y * 4 + HILBERT_ORDER[blk_no][1];
961 if (bx >= blk_w) || (by >= blk_h) { continue; }
962 let idx = base_idx + bx + by * blk_w;
963 self.blk_addr.push(idx * 4 + plane);
964 nblocks += 1;
965 }
966 self.sb_blocks.push(nblocks);
967 }
968 }
969 base_idx += blk_w * blk_h;
970 }
971 self.blocks.resize(tot_blk, Block::new());
972 }
973}
974
975impl NADecoder for VP34Decoder {
976 fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
977 if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
978 let fmt = YUV420_FORMAT;
979 self.width = vinfo.get_width();
980 self.height = vinfo.get_height();
981 validate!(((self.width | self.height) & 15) == 0);
982 self.mb_w = self.width >> 4;
983 self.mb_h = self.height >> 4;
984 let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), true, fmt));
985 self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
986 supp.pool_u8.set_dec_bufs(3);
987 supp.pool_u8.prealloc_video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt), 4)?;
988
989 if self.version == 3 {
990 self.generate_block_addr();
991 }
992 Ok(())
993 } else {
994 Err(DecoderError::InvalidData)
995 }
996 }
997 fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
998 let src = pkt.get_buffer();
999 validate!(src.len() > 0);
1000 let mut br = BitReader::new(&src, src.len(), BitReaderMode::BE);
1001
1002 self.parse_header(&mut br)?;
1003 if self.is_intra {
1004 self.shuf.clear();
1005 }
1006
1007 let ret = supp.pool_u8.get_free();
1008 if ret.is_none() {
1009 return Err(DecoderError::AllocError);
1010 }
1011 let mut buf = ret.unwrap();
1012 let mut dframe = NASimpleVideoFrame::from_video_buf(&mut buf).unwrap();
1013 if self.version == 3 {
6543b6f8 1014 self.decode_vp31(&mut br, &mut dframe)?;
5b24175d
KS
1015 } else {
1016 self.decode_vp4()?;
1017 }
1018
1019 if self.is_intra {
1020 self.shuf.add_golden_frame(buf.clone());
1021 }
1022 self.shuf.add_frame(buf.clone());
1023
1024 let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), NABufferType::Video(buf));
1025 frm.set_keyframe(self.is_intra);
1026 frm.set_frame_type(if self.is_intra { FrameType::I } else { FrameType::P });
1027 Ok(frm.into_ref())
1028 }
1029}
1030
1031pub fn get_decoder_vp3() -> Box<NADecoder> {
1032 Box::new(VP34Decoder::new(3))
1033}
1034
1035/*pub fn get_decoder_vp4() -> Box<NADecoder> {
1036 Box::new(VP34Decoder::new(4))
1037}*/
1038
1039#[cfg(test)]
1040mod test {
1041 use nihav_core::codecs::RegisteredDecoders;
1042 use nihav_core::demuxers::RegisteredDemuxers;
1043 use nihav_core::test::dec_video::*;
1044 use crate::codecs::duck_register_all_codecs;
1045 use nihav_commonfmt::demuxers::generic_register_all_demuxers;
1046
1047 #[test]
1048 fn test_vp3() {
1049 let mut dmx_reg = RegisteredDemuxers::new();
1050 generic_register_all_demuxers(&mut dmx_reg);
1051 let mut dec_reg = RegisteredDecoders::new();
1052 duck_register_all_codecs(&mut dec_reg);
1053
1054// let file = "assets/Duck/vp30-logo.avi";
1055 let file = "assets/Duck/vp31.avi";
1056// let file = "assets/Duck/vp31_crash.avi";
1057// let file = "assets/Duck/01-vp31-0500.avi";
1058 test_file_decoding("avi", file, Some(3), true, false, Some("vp3"), &dmx_reg, &dec_reg);
1059//panic!("end");
1060 }
1061
1062 #[test]
1063 fn test_vp4() {
1064 let mut dmx_reg = RegisteredDemuxers::new();
1065 generic_register_all_demuxers(&mut dmx_reg);
1066 let mut dec_reg = RegisteredDecoders::new();
1067 duck_register_all_codecs(&mut dec_reg);
1068
1069 let file = "assets/Duck/ot171_vp40.avi";
1070 test_file_decoding("avi", file, Some(16), true, false, Some("vp4"), &dmx_reg, &dec_reg);
1071 }
1072}
1073
1074const HILBERT_ORDER: [[usize; 2]; 16] = [
1075 [ 0, 0 ], [ 1, 0 ], [ 1, 1 ], [ 0, 1 ],
1076 [ 0, 2 ], [ 0, 3 ], [ 1, 3 ], [ 1, 2 ],
1077 [ 2, 2 ], [ 2, 3 ], [ 3, 3 ], [ 3, 2 ],
1078 [ 3, 1 ], [ 2, 1 ], [ 2, 0 ], [ 3, 0 ]
1079];
1080
6543b6f8 1081const VP31_LOOP_STRENGTH: [i16; 64] = [
5b24175d
KS
1082 30, 25, 20, 20, 15, 15, 14, 14,
1083 13, 13, 12, 12, 11, 11, 10, 10,
1084 9, 9, 8, 8, 7, 7, 7, 7,
1085 6, 6, 6, 6, 5, 5, 5, 5,
1086 4, 4, 4, 4, 3, 3, 3, 3,
1087 2, 2, 2, 2, 2, 2, 2, 2,
1088 0, 0, 0, 0, 0, 0, 0, 0,
1089 0, 0, 0, 0, 0, 0, 0, 0
1090];
1091
6543b6f8 1092const VP31_DEFAULT_MB_MODES: [VPMBType; 8] = [
5b24175d
KS
1093 VPMBType::InterNoMV, VPMBType::Intra, VPMBType::InterMV, VPMBType::InterNearest,
1094 VPMBType::InterNear, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1095];
1096
6543b6f8 1097const VP31_MB_MODES: [[VPMBType; 8]; 6] = [
5b24175d
KS
1098 [
1099 VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterMV, VPMBType::InterNoMV,
1100 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1101 ], [
1102 VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterNoMV, VPMBType::InterMV,
1103 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1104 ], [
1105 VPMBType::InterNearest, VPMBType::InterMV, VPMBType::InterNear, VPMBType::InterNoMV,
1106 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1107 ], [
1108 VPMBType::InterNearest, VPMBType::InterMV, VPMBType::InterNoMV, VPMBType::InterNear,
1109 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1110 ], [
1111 VPMBType::InterNoMV, VPMBType::InterNearest, VPMBType::InterNear, VPMBType::InterMV,
1112 VPMBType::Intra, VPMBType::GoldenNoMV, VPMBType::GoldenMV, VPMBType::InterFourMV
1113 ], [
1114 VPMBType::InterNoMV, VPMBType::GoldenNoMV, VPMBType::InterNearest, VPMBType::InterNear,
1115 VPMBType::InterMV, VPMBType::Intra, VPMBType::GoldenMV, VPMBType::InterFourMV
1116 ]
1117];
1118
1119const VP3_LITERAL_BASE: [i16; 6] = [ 7, 9, 13, 21, 37, 69 ];
1120
6543b6f8 1121const VP31_AC_SCALES: [i16; 64] = [
5b24175d
KS
1122 500, 450, 400, 370, 340, 310, 285, 265,
1123 245, 225, 210, 195, 185, 180, 170, 160,
1124 150, 145, 135, 130, 125, 115, 110, 107,
1125 100, 96, 93, 89, 85, 82, 75, 74,
1126 70, 68, 64, 60, 57, 56, 52, 50,
1127 49, 45, 44, 43, 40, 38, 37, 35,
1128 33, 32, 30, 29, 28, 25, 24, 22,
1129 21, 19, 18, 17, 15, 13, 12, 10
1130];
1131
6543b6f8 1132const VP31_DC_SCALES: [i16; 64] = [
5b24175d
KS
1133 220, 200, 190, 180, 170, 170, 160, 160,
1134 150, 150, 140, 140, 130, 130, 120, 120,
1135 110, 110, 100, 100, 90, 90, 90, 80,
1136 80, 80, 70, 70, 70, 60, 60, 60,
1137 60, 50, 50, 50, 50, 40, 40, 40,
1138 40, 40, 30, 30, 30, 30, 30, 30,
1139 30, 20, 20, 20, 20, 20, 20, 20,
1140 20, 10, 10, 10, 10, 10, 10, 10
1141];
1142
1143const VP3_QMAT_Y: &[i16; 64] = &[
1144 16, 11, 10, 16, 24, 40, 51, 61,
1145 12, 12, 14, 19, 26, 58, 60, 55,
1146 14, 13, 16, 24, 40, 57, 69, 56,
1147 14, 17, 22, 29, 51, 87, 80, 62,
1148 18, 22, 37, 58, 68, 109, 103, 77,
1149 24, 35, 55, 64, 81, 104, 113, 92,
1150 49, 64, 78, 87, 103, 121, 120, 101,
1151 72, 92, 95, 98, 112, 100, 103, 99
1152];
1153
1154const VP3_QMAT_C: &[i16; 64] = &[
1155 17, 18, 24, 47, 99, 99, 99, 99,
1156 18, 21, 26, 66, 99, 99, 99, 99,
1157 24, 26, 56, 99, 99, 99, 99, 99,
1158 47, 66, 99, 99, 99, 99, 99, 99,
1159 99, 99, 99, 99, 99, 99, 99, 99,
1160 99, 99, 99, 99, 99, 99, 99, 99,
1161 99, 99, 99, 99, 99, 99, 99, 99,
1162 99, 99, 99, 99, 99, 99, 99, 99
1163];
1164
1165const VP3_QMAT_INTER: &[i16; 64] = &[
1166 16, 16, 16, 20, 24, 28, 32, 40,
1167 16, 16, 20, 24, 28, 32, 40, 48,
1168 16, 20, 24, 28, 32, 40, 48, 64,
1169 20, 24, 28, 32, 40, 48, 64, 64,
1170 24, 28, 32, 40, 48, 64, 64, 64,
1171 28, 32, 40, 48, 64, 64, 64, 96,
1172 32, 40, 48, 64, 64, 64, 96, 128,
1173 40, 48, 64, 64, 64, 96, 128, 128
1174];
1175
1176const ZIGZAG: [usize; 64] = [
1177 0, 1, 8, 16, 9, 2, 3, 10,
1178 17, 24, 32, 25, 18, 11, 4, 5,
1179 12, 19, 26, 33, 40, 48, 41, 34,
1180 27, 20, 13, 6, 7, 14, 21, 28,
1181 35, 42, 49, 56, 57, 50, 43, 36,
1182 29, 22, 15, 23, 30, 37, 44, 51,
1183 58, 59, 52, 45, 38, 31, 39, 46,
1184 53, 60, 61, 54, 47, 55, 62, 63
1185];
1186
6543b6f8 1187const VP31_DC_CODES: [[u16; 32]; 16] = [
5b24175d
KS
1188 [
1189 0x002D, 0x0026, 0x0166, 0x004E, 0x02CE, 0x059E, 0x027D, 0x0008,
1190 0x04F9, 0x000F, 0x000E, 0x001B, 0x0006, 0x0008, 0x0005, 0x001A,
1191 0x0015, 0x0007, 0x000C, 0x0001, 0x0000, 0x0009, 0x0017, 0x0029,
1192 0x0028, 0x00B2, 0x04F8, 0x059F, 0x009E, 0x013F, 0x0012, 0x0058,
1193 ], [
1194 0x0010, 0x0047, 0x01FF, 0x008C, 0x03FC, 0x046A, 0x0469, 0x0022,
1195 0x11A1, 0x000E, 0x000D, 0x0004, 0x0005, 0x0009, 0x0006, 0x001E,
1196 0x0016, 0x0007, 0x000C, 0x0001, 0x0000, 0x000A, 0x0017, 0x007D,
1197 0x007E, 0x011B, 0x08D1, 0x03FD, 0x046B, 0x11A0, 0x007C, 0x00FE,
1198 ], [
1199 0x0016, 0x0020, 0x0086, 0x0087, 0x0367, 0x06CC, 0x06CB, 0x006E,
1200 0x366D, 0x000F, 0x000E, 0x0004, 0x0005, 0x000A, 0x0006, 0x001A,
1201 0x0011, 0x0007, 0x000C, 0x0001, 0x0000, 0x0009, 0x0017, 0x006F,
1202 0x006D, 0x0364, 0x0D9A, 0x06CA, 0x1B37, 0x366C, 0x0042, 0x00D8,
1203 ], [
1204 0x0000, 0x002D, 0x00F7, 0x0058, 0x0167, 0x02CB, 0x02CA, 0x000E,
1205 0x1661, 0x0003, 0x0002, 0x0008, 0x0009, 0x000D, 0x0002, 0x001F,
1206 0x0017, 0x0001, 0x000C, 0x000E, 0x000A, 0x0006, 0x0078, 0x000F,
1207 0x007A, 0x0164, 0x0599, 0x02CD, 0x0B31, 0x1660, 0x0079, 0x00F6,
1208 ], [
1209 0x0003, 0x003C, 0x000F, 0x007A, 0x001D, 0x0020, 0x0072, 0x0006,
1210 0x0399, 0x0004, 0x0005, 0x0005, 0x0006, 0x000E, 0x0004, 0x0000,
1211 0x0019, 0x0002, 0x000D, 0x0007, 0x001F, 0x0030, 0x0011, 0x0031,
1212 0x0005, 0x0021, 0x00E7, 0x0038, 0x01CD, 0x0398, 0x007B, 0x0009,
1213 ], [
1214 0x0009, 0x0002, 0x0074, 0x0007, 0x00EC, 0x00D1, 0x01A6, 0x0006,
1215 0x0D21, 0x0005, 0x0006, 0x0008, 0x0007, 0x000F, 0x0004, 0x0000,
1216 0x001C, 0x0002, 0x0005, 0x0003, 0x000C, 0x0035, 0x01A7, 0x001B,
1217 0x0077, 0x01A5, 0x0349, 0x00D0, 0x0691, 0x0D20, 0x0075, 0x00ED,
1218 ], [
1219 0x000A, 0x000C, 0x0012, 0x001B, 0x00B7, 0x016C, 0x0099, 0x005A,
1220 0x16D8, 0x0007, 0x0006, 0x0009, 0x0008, 0x0000, 0x0005, 0x0017,
1221 0x000E, 0x0002, 0x0003, 0x000F, 0x001A, 0x004D, 0x2DB3, 0x002C,
1222 0x0011, 0x02DA, 0x05B7, 0x0098, 0x0B6D, 0x2DB2, 0x0010, 0x0027,
1223 ], [
1224 0x000D, 0x000F, 0x001D, 0x0008, 0x0051, 0x0056, 0x00AF, 0x002A,
1225 0x148A, 0x0007, 0x0000, 0x0008, 0x0009, 0x000C, 0x0006, 0x0017,
1226 0x000B, 0x0016, 0x0015, 0x0009, 0x0050, 0x00AE, 0x2917, 0x001C,
1227 0x0014, 0x0290, 0x0523, 0x0149, 0x0A44, 0x2916, 0x0053, 0x00A5,
1228 ], [
1229 0x0001, 0x001D, 0x00F5, 0x00F4, 0x024D, 0x0499, 0x0498, 0x0001,
1230 0x0021, 0x0006, 0x0005, 0x0006, 0x0005, 0x0002, 0x0007, 0x0025,
1231 0x007B, 0x001C, 0x0020, 0x000D, 0x0048, 0x0092, 0x0127, 0x000E,
1232 0x0004, 0x0011, 0x000C, 0x003C, 0x000F, 0x0000, 0x001F, 0x0013,
1233 ], [
1234 0x0005, 0x003C, 0x0040, 0x000D, 0x0031, 0x0061, 0x0060, 0x0002,
1235 0x00F5, 0x0006, 0x0005, 0x0007, 0x0006, 0x0002, 0x0009, 0x0025,
1236 0x0007, 0x0021, 0x0024, 0x0010, 0x0041, 0x00F4, 0x0019, 0x000E,
1237 0x0003, 0x0011, 0x0011, 0x003F, 0x003E, 0x007B, 0x0000, 0x0013,
1238 ], [
1239 0x000A, 0x0007, 0x0001, 0x0009, 0x0131, 0x0261, 0x0260, 0x0015,
1240 0x0001, 0x0007, 0x0006, 0x0008, 0x0007, 0x0006, 0x0012, 0x002F,
1241 0x0014, 0x0027, 0x002D, 0x0016, 0x004D, 0x0099, 0x0000, 0x0004,
1242 0x0001, 0x0005, 0x0017, 0x002E, 0x002C, 0x0008, 0x0006, 0x0001,
1243 ], [
1244 0x0000, 0x000E, 0x0017, 0x002A, 0x0010, 0x00F9, 0x00F8, 0x001E,
1245 0x003F, 0x0007, 0x0006, 0x0009, 0x0008, 0x0006, 0x000F, 0x0005,
1246 0x0016, 0x0029, 0x002B, 0x0015, 0x0050, 0x0011, 0x007D, 0x0004,
1247 0x0017, 0x0006, 0x0014, 0x002C, 0x002D, 0x000E, 0x0009, 0x0051,
1248 ], [
1249 0x0002, 0x0018, 0x002F, 0x000D, 0x0053, 0x0295, 0x0294, 0x00A4,
1250 0x007C, 0x0000, 0x0007, 0x0009, 0x0008, 0x001B, 0x000C, 0x0028,
1251 0x006A, 0x001E, 0x001D, 0x0069, 0x00D7, 0x007D, 0x014B, 0x0019,
1252 0x0016, 0x002E, 0x001C, 0x002B, 0x002A, 0x0068, 0x003F, 0x00D6,
1253 ], [
1254 0x0002, 0x001B, 0x000C, 0x0018, 0x0029, 0x007F, 0x02F0, 0x0198,
1255 0x0179, 0x0000, 0x0007, 0x0009, 0x0008, 0x001A, 0x000D, 0x002A,
1256 0x0064, 0x001E, 0x0067, 0x005F, 0x00CD, 0x007E, 0x02F1, 0x0016,
1257 0x000E, 0x002E, 0x0065, 0x002B, 0x0028, 0x003E, 0x00BD, 0x0199,
1258 ], [
1259 0x0002, 0x0007, 0x0016, 0x0006, 0x0036, 0x005C, 0x015D, 0x015C,
1260 0x02BF, 0x0000, 0x0007, 0x0009, 0x0008, 0x0018, 0x0034, 0x002A,
1261 0x005E, 0x006A, 0x0064, 0x005D, 0x00CB, 0x00AD, 0x02BE, 0x0014,
1262 0x0033, 0x006E, 0x005F, 0x006F, 0x006B, 0x00CA, 0x00AC, 0x015E,
1263 ], [
1264 0x000F, 0x001D, 0x0018, 0x000B, 0x0019, 0x0029, 0x00D6, 0x0551,
1265 0x0AA1, 0x0001, 0x0000, 0x0009, 0x0008, 0x001B, 0x0038, 0x0028,
1266 0x0057, 0x006A, 0x0068, 0x0056, 0x00E5, 0x0155, 0x0AA0, 0x0073,
1267 0x0069, 0x00D7, 0x00AB, 0x00E4, 0x00A9, 0x0151, 0x0150, 0x02A9,
1268 ]
1269];
1270
6543b6f8 1271const VP31_DC_BITS: [[u8; 32]; 16] = [
5b24175d
KS
1272 [
1273 6, 7, 9, 8, 10, 11, 11, 5, 12, 4, 4, 5, 4, 4, 4, 5,
1274 5, 4, 4, 3, 3, 4, 5, 6, 6, 8, 12, 11, 9, 10, 6, 7,
1275 ], [
1276 5, 7, 9, 8, 10, 11, 11, 6, 13, 4, 4, 4, 4, 4, 4, 5,
1277 5, 4, 4, 3, 3, 4, 5, 7, 7, 9, 12, 10, 11, 13, 7, 8,
1278 ], [
1279 5, 6, 8, 8, 10, 11, 11, 7, 14, 4, 4, 4, 4, 4, 4, 5,
1280 5, 4, 4, 3, 3, 4, 5, 7, 7, 10, 12, 11, 13, 14, 7, 8,
1281 ], [
1282 4, 6, 8, 7, 9, 10, 10, 6, 13, 3, 3, 4, 4, 4, 4, 5,
1283 5, 4, 4, 4, 4, 5, 7, 6, 7, 9, 11, 10, 12, 13, 7, 8,
1284 ], [
1285 4, 6, 7, 7, 8, 9, 10, 6, 13, 3, 3, 4, 4, 4, 4, 4,
1286 5, 4, 4, 4, 5, 6, 8, 6, 6, 9, 11, 9, 12, 13, 7, 7,
1287 ], [
1288 4, 5, 7, 6, 8, 9, 10, 6, 13, 3, 3, 4, 4, 4, 4, 4,
1289 5, 4, 4, 4, 5, 7, 10, 6, 7, 10, 11, 9, 12, 13, 7, 8,
1290 ], [
1291 4, 5, 6, 6, 8, 9, 9, 7, 13, 3, 3, 4, 4, 3, 4, 5,
1292 5, 4, 4, 5, 6, 8, 14, 6, 6, 10, 11, 9, 12, 14, 6, 7,
1293 ], [
1294 4, 5, 6, 5, 7, 8, 9, 7, 13, 3, 2, 4, 4, 4, 4, 5,
1295 5, 5, 5, 5, 7, 9, 14, 6, 6, 10, 11, 9, 12, 14, 7, 8,
1296 ], [
1297 4, 6, 8, 8, 10, 11, 11, 5, 6, 3, 3, 4, 4, 4, 5, 6,
1298 7, 6, 6, 6, 7, 8, 9, 4, 4, 5, 6, 6, 5, 5, 5, 5,
1299 ], [
1300 4, 6, 7, 7, 9, 10, 10, 5, 8, 3, 3, 4, 4, 4, 5, 6,
1301 6, 6, 6, 6, 7, 8, 8, 4, 4, 5, 6, 6, 6, 7, 4, 5,
1302 ], [
1303 4, 5, 6, 6, 9, 10, 10, 6, 7, 3, 3, 4, 4, 4, 5, 6,
1304 6, 6, 6, 6, 7, 8, 7, 4, 4, 5, 6, 6, 6, 6, 5, 5,
1305 ], [
1306 3, 5, 6, 6, 7, 10, 10, 7, 8, 3, 3, 4, 4, 4, 5, 5,
1307 6, 6, 6, 6, 7, 7, 9, 4, 5, 5, 6, 6, 6, 6, 6, 7,
1308 ], [
1309 3, 5, 6, 5, 7, 10, 10, 8, 8, 2, 3, 4, 4, 5, 5, 6,
1310 7, 6, 6, 7, 8, 8, 9, 5, 5, 6, 6, 6, 6, 7, 7, 8,
1311 ], [
1312 3, 5, 5, 5, 6, 8, 10, 9, 9, 2, 3, 4, 4, 5, 5, 6,
1313 7, 6, 7, 7, 8, 8, 10, 5, 5, 6, 7, 6, 6, 7, 8, 9,
1314 ], [
1315 3, 4, 5, 4, 6, 7, 9, 9, 10, 2, 3, 4, 4, 5, 6, 6,
1316 7, 7, 7, 7, 8, 8, 10, 5, 6, 7, 7, 7, 7, 8, 8, 9,
1317 ], [
1318 4, 5, 5, 4, 5, 6, 8, 11, 12, 2, 2, 4, 4, 5, 6, 6,
1319 7, 7, 7, 7, 8, 9, 12, 7, 7, 8, 8, 8, 8, 9, 9, 10,
1320 ]
1321];
1322
6543b6f8 1323const VP31_AC_CAT0_CODES: [[u16; 32]; 16] = [
5b24175d
KS
1324 [
1325 0x0008, 0x0025, 0x017A, 0x02F7, 0x0BDB, 0x17B4, 0x2F6B, 0x001D,
1326 0x2F6A, 0x0008, 0x0007, 0x0001, 0x0002, 0x000A, 0x0006, 0x0000,
1327 0x001C, 0x0009, 0x000D, 0x000F, 0x000C, 0x0003, 0x000A, 0x0016,
1328 0x0013, 0x005D, 0x0024, 0x00BC, 0x005C, 0x05EC, 0x000B, 0x005F,
1329 ], [
1330 0x000F, 0x0010, 0x004B, 0x00C6, 0x031D, 0x0C71, 0x0C70, 0x0001,
1331 0x0C73, 0x0008, 0x0009, 0x0002, 0x0003, 0x000B, 0x0006, 0x0000,
1332 0x001C, 0x0005, 0x000D, 0x000F, 0x000A, 0x0019, 0x0013, 0x001D,
1333 0x0030, 0x0062, 0x0024, 0x004A, 0x018F, 0x0C72, 0x000E, 0x0011,
1334 ], [
1335 0x001B, 0x0003, 0x008D, 0x0040, 0x0239, 0x0471, 0x08E0, 0x0003,
1336 0x11C3, 0x000A, 0x0009, 0x0004, 0x0005, 0x000E, 0x0007, 0x0001,
1337 0x001E, 0x0006, 0x000C, 0x000B, 0x0002, 0x0000, 0x0041, 0x001F,
1338 0x0022, 0x0002, 0x008F, 0x008C, 0x011D, 0x11C2, 0x001A, 0x0021,
1339 ], [
1340 0x001F, 0x0003, 0x0003, 0x0043, 0x000B, 0x0015, 0x0051, 0x0003,
1341 0x0050, 0x000D, 0x000C, 0x0004, 0x0006, 0x000E, 0x000A, 0x0001,
1342 0x001E, 0x0005, 0x0009, 0x0007, 0x0011, 0x0002, 0x0004, 0x0002,
1343 0x002D, 0x0020, 0x0042, 0x0001, 0x0000, 0x0029, 0x0017, 0x002C,
1344 ], [
1345 0x0003, 0x001F, 0x003A, 0x005D, 0x0173, 0x02E4, 0x172D, 0x0004,
1346 0x172C, 0x000F, 0x000E, 0x0009, 0x0008, 0x000C, 0x000A, 0x0001,
1347 0x0016, 0x0002, 0x0005, 0x001A, 0x002F, 0x0038, 0x05CA, 0x0006,
1348 0x0037, 0x001E, 0x003B, 0x0039, 0x00B8, 0x0B97, 0x0000, 0x0036,
1349 ], [
1350 0x0006, 0x0037, 0x005D, 0x000C, 0x00B9, 0x02E3, 0x05C4, 0x0004,
1351 0x1715, 0x0000, 0x000F, 0x0008, 0x0007, 0x000C, 0x0009, 0x001D,
1352 0x0016, 0x001C, 0x001A, 0x000B, 0x005E, 0x0170, 0x1714, 0x000A,
1353 0x000A, 0x0036, 0x005F, 0x001B, 0x001A, 0x0B8B, 0x0002, 0x0007,
1354 ], [
1355 0x000C, 0x000B, 0x0079, 0x0022, 0x00F0, 0x0119, 0x0230, 0x001D,
1356 0x08C4, 0x0001, 0x0000, 0x000A, 0x0009, 0x000B, 0x0007, 0x001C,
1357 0x003D, 0x000D, 0x0008, 0x0015, 0x008D, 0x118B, 0x118A, 0x000D,
1358 0x0010, 0x0009, 0x0014, 0x0047, 0x00F1, 0x0463, 0x001F, 0x000C,
1359 ], [
1360 0x0000, 0x001A, 0x0033, 0x000C, 0x0046, 0x01E3, 0x03C5, 0x0017,
1361 0x1E21, 0x0002, 0x0001, 0x0009, 0x000A, 0x0007, 0x001B, 0x003D,
1362 0x001B, 0x0022, 0x0079, 0x00F0, 0x1E20, 0x1E23, 0x1E22, 0x000E,
1363 0x0016, 0x0018, 0x0032, 0x001A, 0x0047, 0x0789, 0x001F, 0x0010,
1364 ], [
1365 0x001D, 0x0061, 0x004E, 0x009E, 0x027C, 0x09F5, 0x09F4, 0x0003,
1366 0x0060, 0x0000, 0x000F, 0x000B, 0x000A, 0x0009, 0x0005, 0x000D,
1367 0x0031, 0x0008, 0x0038, 0x0012, 0x0026, 0x013F, 0x04FB, 0x000D,
1368 0x0002, 0x000C, 0x0039, 0x001C, 0x000F, 0x001D, 0x0008, 0x0019,
1369 ], [
1370 0x0007, 0x0019, 0x00AB, 0x00AA, 0x0119, 0x0461, 0x0460, 0x001B,
1371 0x0047, 0x0001, 0x0000, 0x000C, 0x000B, 0x0009, 0x0005, 0x000D,
1372 0x0035, 0x003D, 0x003C, 0x0018, 0x0022, 0x008D, 0x0231, 0x000E,
1373 0x001F, 0x0009, 0x002B, 0x0010, 0x0034, 0x0054, 0x0008, 0x0014,
1374 ], [
1375 0x000C, 0x0005, 0x0008, 0x005B, 0x004D, 0x0131, 0x0261, 0x001A,
1376 0x0012, 0x0000, 0x000F, 0x000A, 0x0009, 0x0006, 0x001B, 0x0006,
1377 0x001C, 0x002C, 0x0015, 0x005A, 0x0027, 0x0099, 0x0260, 0x000E,
1378 0x0004, 0x000F, 0x0007, 0x001D, 0x000B, 0x0014, 0x0008, 0x0017,
1379 ], [
1380 0x000F, 0x0013, 0x0075, 0x0024, 0x0095, 0x0251, 0x04A0, 0x0010,
1381 0x00C8, 0x0002, 0x0001, 0x0001, 0x0000, 0x001A, 0x0011, 0x002C,
1382 0x0065, 0x0074, 0x004B, 0x00C9, 0x0129, 0x0943, 0x0942, 0x0003,
1383 0x000A, 0x001C, 0x0018, 0x0033, 0x0017, 0x002D, 0x001B, 0x003B,
1384 ], [
1385 0x0003, 0x001A, 0x002D, 0x0038, 0x0028, 0x0395, 0x0E51, 0x0037,
1386 0x00E4, 0x0001, 0x0000, 0x001F, 0x001E, 0x0017, 0x003A, 0x0073,
1387 0x002A, 0x002B, 0x0029, 0x01CB, 0x0729, 0x1CA1, 0x1CA0, 0x0004,
1388 0x000A, 0x0004, 0x0018, 0x0036, 0x000B, 0x002C, 0x0019, 0x003B,
1389 ], [
1390 0x0004, 0x0004, 0x003F, 0x0017, 0x0075, 0x01F5, 0x07D1, 0x0017,
1391 0x01F6, 0x0001, 0x0000, 0x001B, 0x001A, 0x000A, 0x0032, 0x0074,
1392 0x00F8, 0x00F9, 0x01F7, 0x03E9, 0x0FA0, 0x1F43, 0x1F42, 0x0003,
1393 0x000A, 0x001E, 0x001C, 0x003B, 0x0018, 0x0016, 0x0016, 0x0033,
1394 ], [
1395 0x0004, 0x0007, 0x0018, 0x001E, 0x0036, 0x0031, 0x0177, 0x0077,
1396 0x0176, 0x0001, 0x0000, 0x001A, 0x0019, 0x003A, 0x0019, 0x005C,
1397 0x00BA, 0x0061, 0x00C1, 0x0180, 0x0302, 0x0607, 0x0606, 0x0002,
1398 0x000A, 0x001F, 0x001C, 0x0037, 0x0016, 0x0076, 0x000D, 0x002F,
1399 ], [
1400 0x0000, 0x000A, 0x001A, 0x000C, 0x001D, 0x0039, 0x0078, 0x005E,
1401 0x0393, 0x0002, 0x0001, 0x0016, 0x000F, 0x002E, 0x005F, 0x0073,
1402 0x00E5, 0x01C8, 0x0E4A, 0x1C97, 0x1C96, 0x0E49, 0x0E48, 0x0004,
1403 0x0006, 0x001F, 0x001B, 0x001D, 0x0038, 0x0038, 0x003D, 0x0079,
1404 ]
1405];
1406
6543b6f8 1407const VP31_AC_CAT0_BITS: [[u8; 32]; 16] = [
5b24175d
KS
1408 [
1409 5, 7, 9, 10, 12, 13, 14, 5, 14, 4, 4, 4, 4, 4, 4, 4,
1410 5, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 8, 7, 11, 5, 7,
1411 ], [
1412 5, 6, 8, 8, 10, 12, 12, 4, 12, 4, 4, 4, 4, 4, 4, 4,
1413 5, 4, 4, 4, 4, 5, 6, 5, 6, 7, 7, 8, 9, 12, 5, 6,
1414 ], [
1415 5, 6, 8, 7, 10, 11, 12, 4, 13, 4, 4, 4, 4, 4, 4, 4,
1416 5, 4, 4, 4, 4, 5, 7, 5, 6, 6, 8, 8, 9, 13, 5, 6,
1417 ], [
1418 5, 6, 7, 7, 9, 10, 12, 4, 12, 4, 4, 4, 4, 4, 4, 4,
1419 5, 4, 4, 4, 5, 6, 8, 4, 6, 6, 7, 7, 7, 11, 5, 6,
1420 ], [
1421 4, 6, 7, 7, 9, 10, 13, 4, 13, 4, 4, 4, 4, 4, 4, 4,
1422 5, 4, 4, 5, 6, 7, 11, 4, 6, 6, 7, 7, 8, 12, 4, 6,
1423 ], [
1424 4, 6, 7, 6, 8, 10, 11, 4, 13, 3, 4, 4, 4, 4, 4, 5,
1425 5, 5, 5, 5, 7, 9, 13, 4, 5, 6, 7, 7, 7, 12, 4, 5,
1426 ], [
1427 4, 5, 7, 6, 8, 9, 10, 5, 12, 3, 3, 4, 4, 4, 4, 5,
1428 6, 5, 5, 6, 8, 13, 13, 4, 5, 5, 6, 7, 8, 11, 5, 5,
1429 ], [
1430 3, 5, 6, 5, 7, 9, 10, 5, 13, 3, 3, 4, 4, 4, 5, 6,
1431 6, 6, 7, 8, 13, 13, 13, 4, 5, 5, 6, 6, 7, 11, 5, 5,
1432 ], [
1433 5, 7, 8, 9, 11, 13, 13, 4, 7, 3, 4, 4, 4, 4, 4, 5,
1434 6, 5, 6, 6, 7, 10, 12, 4, 4, 5, 6, 6, 5, 6, 4, 5,
1435 ], [
1436 4, 6, 8, 8, 10, 12, 12, 5, 8, 3, 3, 4, 4, 4, 4, 5,
1437 6, 6, 6, 6, 7, 9, 11, 4, 5, 5, 6, 6, 6, 7, 4, 5,
1438 ], [
1439 4, 5, 6, 7, 9, 11, 12, 5, 7, 3, 4, 4, 4, 4, 5, 5,
1440 6, 6, 6, 7, 8, 10, 12, 4, 4, 5, 5, 6, 5, 6, 4, 5,
1441 ], [
1442 4, 5, 7, 6, 8, 10, 11, 5, 8, 3, 3, 4, 4, 5, 5, 6,
1443 7, 7, 7, 8, 9, 12, 12, 3, 4, 5, 5, 6, 5, 6, 5, 6,
1444 ], [
1445 3, 5, 6, 6, 7, 10, 12, 6, 8, 3, 3, 5, 5, 5, 6, 7,
1446 7, 7, 7, 9, 11, 13, 13, 3, 4, 4, 5, 6, 5, 6, 5, 6,
1447 ], [
1448 3, 4, 6, 5, 7, 9, 11, 6, 9, 3, 3, 5, 5, 5, 6, 7,
1449 8, 8, 9, 10, 12, 13, 13, 3, 4, 5, 5, 6, 5, 6, 5, 6,
1450 ], [
1451 3, 4, 5, 5, 6, 7, 9, 7, 9, 3, 3, 5, 5, 6, 6, 7,
1452 8, 8, 9, 10, 11, 12, 12, 3, 4, 5, 5, 6, 5, 7, 5, 6,
1453 ], [
1454 3, 4, 5, 4, 5, 6, 7, 7, 11, 3, 3, 5, 5, 6, 7, 8,
1455 9, 10, 13, 14, 14, 13, 13, 3, 4, 5, 5, 6, 6, 7, 6, 7,
1456 ]
1457];
1458
6543b6f8 1459const VP31_AC_CAT1_CODES: [[u16; 32]; 16] = [
5b24175d
KS
1460 [
1461 0x000B, 0x002B, 0x0054, 0x01B7, 0x06D9, 0x0DB1, 0x0DB0, 0x0002,
1462 0x00AB, 0x0009, 0x000A, 0x0007, 0x0008, 0x000F, 0x000C, 0x0003,
1463 0x001D, 0x0004, 0x000B, 0x0006, 0x001A, 0x0003, 0x00AA, 0x0001,
1464 0x0000, 0x0014, 0x006C, 0x00DA, 0x0002, 0x036D, 0x001C, 0x0037,
1465 ], [
1466 0x001D, 0x0004, 0x00B6, 0x006A, 0x05B9, 0x16E1, 0x16E0, 0x0007,
1467 0x016F, 0x000C, 0x000D, 0x0009, 0x0008, 0x000F, 0x000A, 0x0003,
1468 0x0017, 0x0002, 0x0004, 0x001C, 0x002C, 0x006B, 0x0B71, 0x0005,
1469 0x0003, 0x001B, 0x005A, 0x0034, 0x0005, 0x02DD, 0x0000, 0x000C,
1470 ], [
1471 0x0003, 0x007F, 0x00A1, 0x00A0, 0x020C, 0x0834, 0x106B, 0x0007,
1472 0x0082, 0x000E, 0x000D, 0x000B, 0x000C, 0x0000, 0x0009, 0x0002,
1473 0x0011, 0x001E, 0x0015, 0x003E, 0x0040, 0x041B, 0x106A, 0x0006,
1474 0x000A, 0x0029, 0x007E, 0x0051, 0x0021, 0x0107, 0x0004, 0x000B,
1475 ], [
1476 0x0007, 0x001B, 0x00F6, 0x00E9, 0x03A1, 0x0740, 0x0E82, 0x001F,
1477 0x01EF, 0x0001, 0x0002, 0x000B, 0x000C, 0x000D, 0x0008, 0x001C,
1478 0x0003, 0x0012, 0x0002, 0x0075, 0x01D1, 0x1D07, 0x1D06, 0x000A,
1479 0x0013, 0x003B, 0x001A, 0x007A, 0x003C, 0x01EE, 0x0000, 0x000C,
1480 ], [
1481 0x000D, 0x003D, 0x0042, 0x0037, 0x00D9, 0x0362, 0x06C6, 0x001F,
1482 0x0086, 0x0001, 0x0002, 0x000C, 0x000B, 0x000A, 0x0001, 0x000F,
1483 0x0025, 0x003C, 0x001A, 0x0087, 0x01B0, 0x0D8F, 0x0D8E, 0x000E,
1484 0x0013, 0x000C, 0x0024, 0x0020, 0x0011, 0x006D, 0x0000, 0x000E,
1485 ], [
1486 0x0000, 0x0012, 0x0076, 0x0077, 0x014D, 0x0533, 0x14C9, 0x0013,
1487 0x00A5, 0x0002, 0x0003, 0x000B, 0x000C, 0x0008, 0x001A, 0x002B,
1488 0x0075, 0x0074, 0x00A7, 0x0298, 0x14C8, 0x14CB, 0x14CA, 0x000F,
1489 0x001C, 0x0007, 0x002A, 0x0028, 0x001B, 0x00A4, 0x0002, 0x0006,
1490 ], [
1491 0x0002, 0x001A, 0x002B, 0x003A, 0x00ED, 0x0283, 0x0A0A, 0x0004,
1492 0x00A1, 0x0004, 0x0003, 0x000B, 0x000C, 0x001F, 0x0006, 0x0077,
1493 0x00A3, 0x00A2, 0x0140, 0x1417, 0x1416, 0x0A09, 0x0A08, 0x0000,
1494 0x001E, 0x0007, 0x002A, 0x0029, 0x001C, 0x00EC, 0x001B, 0x0005,
1495 ], [
1496 0x0002, 0x0002, 0x0018, 0x001D, 0x0035, 0x00E4, 0x01CF, 0x001D,
1497 0x0072, 0x0004, 0x0005, 0x0006, 0x0007, 0x0006, 0x0073, 0x0038,
1498 0x01CE, 0x039B, 0x0398, 0x0733, 0x0732, 0x0735, 0x0734, 0x0000,
1499 0x001F, 0x001B, 0x0034, 0x000F, 0x001E, 0x00E5, 0x0019, 0x0038,
1500 ], [
1501 0x0016, 0x0050, 0x0172, 0x02E7, 0x1732, 0x2E67, 0x2E66, 0x0006,
1502 0x0051, 0x0001, 0x0000, 0x000D, 0x000C, 0x0009, 0x001C, 0x0009,
1503 0x001C, 0x001D, 0x005D, 0x00B8, 0x05CD, 0x1731, 0x1730, 0x000F,
1504 0x0005, 0x000F, 0x0008, 0x0029, 0x001D, 0x002F, 0x0008, 0x0015,
1505 ], [
1506 0x0009, 0x0021, 0x0040, 0x00AD, 0x02B0, 0x1589, 0x1588, 0x001C,
1507 0x005F, 0x0000, 0x000F, 0x000D, 0x000C, 0x0006, 0x0011, 0x002A,
1508 0x0057, 0x005E, 0x0041, 0x0159, 0x0563, 0x158B, 0x158A, 0x0001,
1509 0x0005, 0x0014, 0x003B, 0x002E, 0x0004, 0x003A, 0x0007, 0x0016,
1510 ], [
1511 0x000E, 0x0007, 0x0046, 0x0045, 0x0064, 0x032A, 0x0657, 0x0018,
1512 0x000D, 0x0000, 0x000F, 0x000A, 0x000B, 0x001A, 0x0036, 0x0047,
1513 0x0044, 0x0018, 0x0033, 0x00CB, 0x0656, 0x0329, 0x0328, 0x0002,
1514 0x0006, 0x0019, 0x000E, 0x0037, 0x0009, 0x000F, 0x0002, 0x0010,
1515 ], [
1516 0x0003, 0x0018, 0x0023, 0x0077, 0x0194, 0x1956, 0x32AF, 0x003A,
1517 0x0076, 0x0002, 0x0001, 0x001F, 0x001E, 0x0014, 0x0022, 0x0064,
1518 0x0197, 0x0196, 0x032B, 0x0654, 0x32AE, 0x1955, 0x1954, 0x0000,
1519 0x0009, 0x001C, 0x0015, 0x0010, 0x000D, 0x0017, 0x0016, 0x0033,
1520 ], [
1521 0x0005, 0x0006, 0x003E, 0x0010, 0x0048, 0x093F, 0x24FA, 0x0032,
1522 0x0067, 0x0002, 0x0001, 0x001B, 0x001E, 0x0034, 0x0066, 0x0092,
1523 0x0126, 0x024E, 0x049E, 0x49F7, 0x49F6, 0x24F9, 0x24F8, 0x0000,
1524 0x0007, 0x0018, 0x0011, 0x003F, 0x000E, 0x0013, 0x0035, 0x0025,
1525 ], [
1526 0x0005, 0x0008, 0x0012, 0x001C, 0x001C, 0x00EA, 0x1D75, 0x001E,
1527 0x0066, 0x0001, 0x0002, 0x001B, 0x001A, 0x001F, 0x003B, 0x0074,
1528 0x01D6, 0x03AF, 0x1D74, 0x1D77, 0x1D76, 0x0EB9, 0x0EB8, 0x000F,
1529 0x0006, 0x0013, 0x003B, 0x003A, 0x0000, 0x0018, 0x0032, 0x0067,
1530 ], [
1531 0x0004, 0x000A, 0x001B, 0x000C, 0x000D, 0x00E6, 0x0684, 0x0072,
1532 0x00E7, 0x0002, 0x0001, 0x0017, 0x0016, 0x0018, 0x00D1, 0x01A0,
1533 0x0686, 0x0D0F, 0x0D0A, 0x1A17, 0x1A16, 0x1A1D, 0x1A1C, 0x000F,
1534 0x001D, 0x000E, 0x0035, 0x0038, 0x0000, 0x000F, 0x0019, 0x0069,
1535 ], [
1536 0x0003, 0x000C, 0x001B, 0x0000, 0x0003, 0x002E, 0x0051, 0x00BC,
1537 0x0053, 0x0004, 0x0002, 0x0016, 0x0015, 0x0015, 0x0050, 0x00A4,
1538 0x0294, 0x052B, 0x052A, 0x052D, 0x052C, 0x052F, 0x052E, 0x000E,
1539 0x001A, 0x0004, 0x0028, 0x0029, 0x000F, 0x000B, 0x005F, 0x00BD,
1540 ]
1541];
1542
6543b6f8 1543const VP31_AC_CAT1_BITS: [[u8; 32]; 16] = [
5b24175d
KS
1544 [
1545 5, 7, 8, 9, 11, 12, 12, 4, 9, 4, 4, 4, 4, 4, 4, 4,
1546 5, 4, 4, 4, 5, 6, 9, 4, 5, 6, 7, 8, 6, 10, 5, 6,
1547 ], [
1548 5, 6, 8, 8, 11, 13, 13, 4, 9, 4, 4, 4, 4, 4, 4, 4,
1549 5, 4, 4, 5, 6, 8, 12, 4, 5, 6, 7, 7, 6, 10, 4, 5,
1550 ], [
1551 4, 7, 8, 8, 10, 12, 13, 4, 8, 4, 4, 4, 4, 3, 4, 4,
1552 5, 5, 5, 6, 7, 11, 13, 4, 5, 6, 7, 7, 6, 9, 4, 5,
1553 ], [
1554 4, 6, 8, 8, 10, 11, 12, 5, 9, 3, 3, 4, 4, 4, 4, 5,
1555 5, 5, 5, 7, 9, 13, 13, 4, 5, 6, 6, 7, 6, 9, 4, 5,
1556 ], [
1557 4, 6, 7, 7, 9, 11, 12, 5, 8, 3, 3, 4, 4, 4, 4, 5,
1558 6, 6, 6, 8, 10, 13, 13, 4, 5, 5, 6, 6, 5, 8, 4, 5,
1559 ], [
1560 3, 5, 7, 7, 9, 11, 13, 5, 8, 3, 3, 4, 4, 4, 5, 6,
1561 7, 7, 8, 10, 13, 13, 13, 4, 5, 5, 6, 6, 5, 8, 4, 5,
1562 ], [
1563 3, 5, 6, 6, 8, 10, 12, 5, 8, 3, 3, 4, 4, 5, 5, 7,
1564 8, 8, 9, 13, 13, 12, 12, 3, 5, 5, 6, 6, 5, 8, 5, 5,
1565 ], [
1566 3, 4, 5, 5, 6, 8, 11, 7, 9, 3, 3, 4, 4, 5, 7, 8,
1567 11, 12, 12, 13, 13, 13, 13, 3, 5, 5, 6, 6, 5, 8, 5, 6,
1568 ], [
1569 5, 7, 9, 10, 13, 14, 14, 4, 7, 3, 3, 4, 4, 4, 5, 5,
1570 6, 6, 7, 8, 11, 13, 13, 4, 4, 5, 5, 6, 5, 6, 4, 5,
1571 ], [
1572 4, 6, 7, 8, 10, 13, 13, 5, 7, 3, 4, 4, 4, 4, 5, 6,
1573 7, 7, 7, 9, 11, 13, 13, 3, 4, 5, 6, 6, 4, 6, 4, 5,
1574 ], [
1575 4, 5, 7, 7, 9, 12, 13, 5, 6, 3, 4, 4, 4, 5, 6, 7,
1576 7, 7, 8, 10, 13, 12, 12, 3, 4, 5, 5, 6, 4, 5, 4, 5,
1577 ], [
1578 3, 5, 6, 7, 9, 13, 14, 6, 7, 3, 3, 5, 5, 5, 6, 7,
1579 9, 9, 10, 11, 14, 13, 13, 3, 4, 5, 5, 5, 4, 5, 5, 6,
1580 ], [
1581 3, 4, 6, 5, 7, 12, 14, 6, 7, 3, 3, 5, 5, 6, 7, 8,
1582 9, 10, 11, 15, 15, 14, 14, 3, 4, 5, 5, 6, 4, 5, 6, 6,
1583 ], [
1584 3, 4, 5, 5, 6, 9, 14, 6, 7, 3, 3, 5, 5, 6, 7, 8,
1585 10, 11, 14, 14, 14, 13, 13, 4, 4, 5, 6, 6, 3, 5, 6, 7,
1586 ], [
1587 3, 4, 5, 4, 5, 8, 11, 7, 8, 3, 3, 5, 5, 6, 8, 9,
1588 11, 12, 12, 13, 13, 13, 13, 4, 5, 5, 6, 6, 3, 5, 6, 7,
1589 ], [
1590 3, 4, 5, 3, 4, 6, 9, 8, 9, 3, 3, 5, 5, 7, 9, 10,
1591 12, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 6, 7, 8,
1592 ]
1593];
1594
6543b6f8 1595const VP31_AC_CAT2_CODES: [[u16; 32]; 16] = [
5b24175d
KS
1596 [
1597 0x0003, 0x0009, 0x00D0, 0x01A3, 0x0344, 0x0D14, 0x1A2B, 0x0004,
1598 0x0015, 0x0000, 0x000F, 0x000B, 0x000C, 0x000E, 0x0009, 0x001B,
1599 0x000A, 0x0014, 0x000D, 0x002A, 0x0014, 0x068B, 0x1A2A, 0x0008,
1600 0x000B, 0x002B, 0x000B, 0x0069, 0x0035, 0x0008, 0x0007, 0x000C,
1601 ], [
1602 0x000A, 0x003C, 0x0032, 0x0030, 0x00C5, 0x0621, 0x0620, 0x001F,
1603 0x0033, 0x0001, 0x0000, 0x000E, 0x000D, 0x000C, 0x0004, 0x000D,
1604 0x0026, 0x0027, 0x0014, 0x0063, 0x0189, 0x0623, 0x0622, 0x000B,
1605 0x0012, 0x003D, 0x0022, 0x0015, 0x000B, 0x0023, 0x0007, 0x0010,
1606 ], [
1607 0x000F, 0x000C, 0x0043, 0x0010, 0x0044, 0x0114, 0x0455, 0x0018,
1608 0x0023, 0x0001, 0x0000, 0x000E, 0x000D, 0x0009, 0x0019, 0x0009,
1609 0x0017, 0x0016, 0x0042, 0x008B, 0x0454, 0x0457, 0x0456, 0x000B,
1610 0x0015, 0x000A, 0x0029, 0x0020, 0x000D, 0x0028, 0x0007, 0x0011,
1611 ], [
1612 0x0001, 0x001A, 0x0029, 0x002A, 0x00A0, 0x0285, 0x1425, 0x0002,
1613 0x0000, 0x0002, 0x0003, 0x000C, 0x000B, 0x0008, 0x0012, 0x0001,
1614 0x0051, 0x0001, 0x0143, 0x0508, 0x1424, 0x1427, 0x1426, 0x000F,
1615 0x001C, 0x0003, 0x0037, 0x002B, 0x0013, 0x0036, 0x001D, 0x0001,
1616 ], [
1617 0x0004, 0x001F, 0x003D, 0x0006, 0x0016, 0x0053, 0x014A, 0x0034,
1618 0x002A, 0x0002, 0x0003, 0x000B, 0x000C, 0x001C, 0x0037, 0x0017,
1619 0x002B, 0x0028, 0x00A4, 0x052D, 0x052C, 0x052F, 0x052E, 0x0000,
1620 0x001D, 0x0007, 0x0004, 0x0035, 0x0014, 0x0036, 0x0015, 0x003C,
1621 ], [
1622 0x0004, 0x000A, 0x0007, 0x001D, 0x0009, 0x01F3, 0x07C7, 0x0008,
1623 0x01F0, 0x0003, 0x0002, 0x000D, 0x000C, 0x0017, 0x007D, 0x01F2,
1624 0x07C6, 0x07C5, 0x1F12, 0x3E27, 0x3E26, 0x1F11, 0x1F10, 0x0000,
1625 0x001E, 0x0006, 0x0039, 0x0038, 0x003F, 0x002C, 0x0005, 0x002D,
1626 ], [
1627 0x0002, 0x0007, 0x0018, 0x0003, 0x0005, 0x0035, 0x004F, 0x0012,
1628 0x04E5, 0x0005, 0x0004, 0x000D, 0x000E, 0x0033, 0x0026, 0x009D,
1629 0x04E4, 0x04E7, 0x04E6, 0x04E1, 0x04E0, 0x04E3, 0x04E2, 0x0000,
1630 0x001F, 0x000C, 0x003D, 0x003C, 0x0032, 0x0034, 0x001B, 0x0008,
1631 ], [
1632 0x0000, 0x0004, 0x001C, 0x000F, 0x0002, 0x0007, 0x0075, 0x00E8,
1633 0x1D2A, 0x0005, 0x0004, 0x000D, 0x000C, 0x0077, 0x0E96, 0x3A57,
1634 0x3A56, 0x3A5D, 0x3A5C, 0x3A5F, 0x3A5E, 0x1D29, 0x1D28, 0x0003,
1635 0x0006, 0x000A, 0x002C, 0x0017, 0x0076, 0x01D3, 0x03A4, 0x002D,
1636 ], [
1637 0x000A, 0x0024, 0x00BF, 0x0085, 0x0211, 0x0842, 0x1087, 0x0018,
1638 0x0020, 0x0001, 0x0002, 0x000E, 0x000D, 0x0007, 0x0013, 0x0025,
1639 0x005E, 0x0043, 0x00BE, 0x0109, 0x1086, 0x0841, 0x0840, 0x000F,
1640 0x0001, 0x0011, 0x0000, 0x002E, 0x0019, 0x0001, 0x0006, 0x0016,
1641 ], [
1642 0x0002, 0x000F, 0x006F, 0x0061, 0x0374, 0x1BA8, 0x3753, 0x0012,
1643 0x0036, 0x0000, 0x0001, 0x000A, 0x000B, 0x001A, 0x0031, 0x0060,
1644 0x00DC, 0x01BB, 0x06EB, 0x1BAB, 0x3752, 0x3755, 0x3754, 0x000E,
1645 0x0006, 0x0013, 0x000E, 0x003E, 0x0008, 0x001E, 0x0019, 0x003F,
1646 ], [
1647 0x0003, 0x001C, 0x0025, 0x0024, 0x01DA, 0x1DBD, 0x3B7C, 0x003C,
1648 0x003D, 0x0000, 0x0001, 0x000B, 0x000A, 0x000B, 0x0077, 0x00EC,
1649 0x03B6, 0x076E, 0x1DBF, 0x76FB, 0x76FA, 0x3B79, 0x3B78, 0x000D,
1650 0x001F, 0x0013, 0x000A, 0x0008, 0x000C, 0x0008, 0x0009, 0x003A,
1651 ], [
1652 0x0005, 0x0003, 0x0004, 0x0010, 0x008F, 0x0475, 0x11D1, 0x0079,
1653 0x0027, 0x0002, 0x0003, 0x0001, 0x0000, 0x0026, 0x0046, 0x011C,
1654 0x0477, 0x08ED, 0x11D0, 0x11D3, 0x11D2, 0x11D9, 0x11D8, 0x000D,
1655 0x001F, 0x0012, 0x0005, 0x003D, 0x000C, 0x000E, 0x0022, 0x0078,
1656 ], [
1657 0x0005, 0x000C, 0x001B, 0x0000, 0x0006, 0x03E2, 0x3E3D, 0x000F,
1658 0x0034, 0x0003, 0x0002, 0x001E, 0x001D, 0x007D, 0x01F0, 0x07C6,
1659 0x3E3C, 0x3E3F, 0x3E3E, 0x3E39, 0x3E38, 0x3E3B, 0x3E3A, 0x0008,
1660 0x001C, 0x0002, 0x003F, 0x0035, 0x0009, 0x0001, 0x000E, 0x00F9,
1661 ], [
1662 0x0004, 0x000B, 0x0001, 0x000A, 0x001E, 0x00E0, 0x0E1E, 0x0071,
1663 0x0039, 0x0007, 0x0006, 0x000D, 0x000C, 0x0020, 0x01C2, 0x1C3F,
1664 0x1C3E, 0x0E19, 0x0E18, 0x0E1B, 0x0E1A, 0x0E1D, 0x0E1C, 0x0000,
1665 0x0009, 0x001D, 0x001F, 0x0011, 0x0005, 0x0001, 0x0043, 0x0042,
1666 ], [
1667 0x0004, 0x000D, 0x0007, 0x0002, 0x0014, 0x016C, 0x16D1, 0x02DF,
1668 0x016E, 0x0000, 0x0007, 0x002C, 0x002B, 0x02DE, 0x16D0, 0x16D3,
1669 0x16D2, 0x2DB5, 0x2DB4, 0x2DB7, 0x2DB6, 0x16D9, 0x16D8, 0x000C,
1670 0x002A, 0x005A, 0x001B, 0x001A, 0x0017, 0x000C, 0x05B7, 0x05B5,
1671 ], [
1672 0x0002, 0x000F, 0x001C, 0x000C, 0x003B, 0x01AC, 0x1AD8, 0x35B3,
1673 0x35B2, 0x0001, 0x0000, 0x0069, 0x0068, 0x35BD, 0x35BC, 0x35BF,
1674 0x35BE, 0x35B9, 0x35B8, 0x35BB, 0x35BA, 0x35B5, 0x35B4, 0x01A9,
1675 0x01A8, 0x035A, 0x00D7, 0x00D5, 0x003A, 0x001B, 0x35B7, 0x35B6,
1676 ]
1677];
1678
6543b6f8 1679const VP31_AC_CAT2_BITS: [[u8; 32]; 16] = [
5b24175d
KS
1680 [
1681 4, 6, 8, 9, 10, 12, 13, 4, 7, 3, 4, 4, 4, 4, 4, 5,
1682 5, 5, 5, 6, 7, 11, 13, 4, 5, 6, 6, 7, 6, 6, 4, 5,
1683 ], [
1684 4, 6, 7, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 4, 4, 5,
1685 6, 6, 6, 8, 10, 12, 12, 4, 5, 6, 6, 6, 5, 6, 4, 5,
1686 ], [
1687 4, 5, 7, 6, 8, 10, 12, 5, 7, 3, 3, 4, 4, 4, 5, 5,
1688 6, 6, 7, 9, 12, 12, 12, 4, 5, 5, 6, 6, 5, 6, 4, 5,
1689 ], [
1690 3, 5, 6, 6, 8, 10, 13, 5, 7, 3, 3, 4, 4, 4, 5, 6,
1691 7, 7, 9, 11, 13, 13, 13, 4, 5, 5, 6, 6, 5, 6, 5, 5,
1692 ], [
1693 3, 5, 6, 5, 7, 9, 11, 6, 8, 3, 3, 4, 4, 5, 6, 7,
1694 8, 8, 10, 13, 13, 13, 13, 3, 5, 5, 5, 6, 5, 6, 5, 6,
1695 ], [
1696 3, 4, 5, 5, 6, 9, 11, 6, 9, 3, 3, 4, 4, 5, 7, 9,
1697 11, 11, 13, 14, 14, 13, 13, 3, 5, 5, 6, 6, 6, 6, 5, 6,
1698 ], [
1699 3, 4, 5, 4, 5, 7, 9, 7, 13, 3, 3, 4, 4, 6, 8, 10,
1700 13, 13, 13, 13, 13, 13, 13, 3, 5, 5, 6, 6, 6, 7, 6, 6,
1701 ], [
1702 3, 4, 5, 4, 4, 5, 7, 8, 13, 3, 3, 4, 4, 7, 12, 14,
1703 14, 14, 14, 14, 14, 13, 13, 3, 5, 5, 7, 6, 7, 9, 10, 7,
1704 ], [
1705 4, 6, 8, 8, 10, 12, 13, 5, 6, 3, 3, 4, 4, 4, 5, 6,
1706 7, 7, 8, 9, 13, 12, 12, 4, 4, 5, 5, 6, 5, 5, 4, 5,
1707 ], [
1708 3, 5, 7, 7, 10, 13, 14, 5, 6, 3, 3, 4, 4, 5, 6, 7,
1709 8, 9, 11, 13, 14, 14, 14, 4, 4, 5, 5, 6, 4, 5, 5, 6,
1710 ], [
1711 3, 5, 6, 6, 9, 13, 14, 6, 6, 3, 3, 4, 4, 5, 7, 8,
1712 10, 11, 13, 15, 15, 14, 14, 4, 5, 5, 5, 5, 4, 4, 5, 6,
1713 ], [
1714 3, 4, 5, 5, 8, 11, 13, 7, 6, 3, 3, 4, 4, 6, 7, 9,
1715 11, 12, 13, 13, 13, 13, 13, 4, 5, 5, 5, 6, 4, 4, 6, 7,
1716 ], [
1717 3, 4, 5, 4, 6, 10, 14, 7, 6, 3, 3, 5, 5, 7, 9, 11,
1718 14, 14, 14, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 3, 7, 8,
1719 ], [
1720 3, 4, 4, 4, 6, 9, 13, 8, 7, 3, 3, 5, 5, 7, 10, 14,
1721 14, 13, 13, 13, 13, 13, 13, 4, 5, 6, 6, 6, 4, 3, 8, 8,
1722 ], [
1723 3, 4, 4, 3, 5, 9, 13, 10, 9, 2, 3, 6, 6, 10, 13, 13,
1724 13, 14, 14, 14, 14, 13, 13, 5, 6, 7, 6, 6, 5, 4, 11, 11,
1725 ], [
1726 2, 4, 5, 4, 6, 9, 13, 14, 14, 2, 2, 7, 7, 14, 14, 14,
1727 14, 14, 14, 14, 14, 14, 14, 9, 9, 10, 8, 8, 6, 5, 14, 14,
1728 ]
1729];
1730
6543b6f8 1731const VP31_AC_CAT3_CODES: [[u16; 32]; 16] = [
5b24175d
KS
1732 [
1733 0x0000, 0x0010, 0x0072, 0x0071, 0x0154, 0x0AAB, 0x0AA8, 0x0014,
1734 0x0070, 0x0002, 0x0003, 0x000C, 0x000B, 0x0003, 0x0011, 0x0073,
1735 0x0054, 0x00AB, 0x02AB, 0x1553, 0x1552, 0x1555, 0x1554, 0x000D,
1736 0x001E, 0x0012, 0x003E, 0x002B, 0x0002, 0x003F, 0x001D, 0x0013,
1737 ], [
1738 0x0003, 0x001F, 0x0029, 0x003D, 0x000C, 0x0069, 0x0345, 0x0002,
1739 0x0028, 0x0002, 0x0001, 0x000E, 0x000C, 0x0015, 0x0007, 0x001B,
1740 0x006B, 0x006A, 0x0344, 0x0347, 0x0346, 0x01A1, 0x01A0, 0x000B,
1741 0x001A, 0x0012, 0x0000, 0x003C, 0x0008, 0x001B, 0x0013, 0x0001,
1742 ], [
1743 0x0004, 0x0004, 0x003F, 0x0014, 0x0056, 0x015C, 0x15D5, 0x003C,
1744 0x002A, 0x0000, 0x0001, 0x000E, 0x000D, 0x000C, 0x00AF, 0x02BB,
1745 0x15D4, 0x15D7, 0x15D6, 0x15D1, 0x15D0, 0x15D3, 0x15D2, 0x000B,
1746 0x0019, 0x000D, 0x003E, 0x0031, 0x0007, 0x0005, 0x003D, 0x0030,
1747 ], [
1748 0x0005, 0x0008, 0x001A, 0x0000, 0x0036, 0x0011, 0x0106, 0x000A,
1749 0x006E, 0x0002, 0x0003, 0x0003, 0x0002, 0x006F, 0x0021, 0x020F,
1750 0x020E, 0x0101, 0x0100, 0x0103, 0x0102, 0x0105, 0x0104, 0x000C,
1751 0x001E, 0x0003, 0x003E, 0x003F, 0x0009, 0x000E, 0x000B, 0x0009,
1752 ], [
1753 0x0002, 0x000E, 0x001E, 0x000C, 0x001F, 0x006E, 0x00AD, 0x00AF,
1754 0x0014, 0x0004, 0x0003, 0x001A, 0x0017, 0x002A, 0x0576, 0x0AEF,
1755 0x0AEE, 0x0571, 0x0570, 0x0573, 0x0572, 0x0575, 0x0574, 0x0003,
1756 0x0016, 0x0004, 0x0036, 0x000B, 0x000A, 0x0000, 0x006F, 0x00AC,
1757 ], [
1758 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
1759 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
1760 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
1761 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
1762 ], [
1763 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
1764 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
1765 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
1766 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
1767 ], [
1768 0x0004, 0x0005, 0x0003, 0x0001, 0x0004, 0x002F, 0x0526, 0x1495,
1769 0x00A6, 0x0007, 0x0006, 0x002D, 0x002C, 0x1494, 0x1497, 0x1496,
1770 0x1491, 0x1490, 0x1493, 0x1492, 0x293D, 0x293C, 0x293F, 0x0000,
1771 0x0028, 0x00A5, 0x0148, 0x00A7, 0x002E, 0x0015, 0x0A4E, 0x293E,
1772 ], [
1773 0x0003, 0x0011, 0x0020, 0x0074, 0x010D, 0x0863, 0x0860, 0x000A,
1774 0x0075, 0x0001, 0x0000, 0x000B, 0x000A, 0x0018, 0x0038, 0x0042,
1775 0x010F, 0x010E, 0x0219, 0x10C3, 0x10C2, 0x10C5, 0x10C4, 0x000F,
1776 0x0004, 0x0019, 0x000B, 0x0039, 0x0009, 0x001B, 0x001A, 0x003B,
1777 ], [
1778 0x0005, 0x0001, 0x003E, 0x0001, 0x00E2, 0x1C6F, 0x38D9, 0x0039,
1779 0x001F, 0x0002, 0x0001, 0x0009, 0x0008, 0x0000, 0x0070, 0x01C7,
1780 0x038C, 0x071A, 0x38D8, 0x38DB, 0x38DA, 0x38DD, 0x38DC, 0x000D,
1781 0x001D, 0x000E, 0x003F, 0x003C, 0x000C, 0x0006, 0x003D, 0x001E,
1782 ], [
1783 0x0006, 0x000B, 0x0011, 0x001E, 0x0074, 0x03AA, 0x1D5C, 0x0001,
1784 0x0021, 0x0001, 0x0002, 0x0007, 0x0006, 0x003E, 0x00EB, 0x01D4,
1785 0x0EAF, 0x3ABB, 0x3ABA, 0x1D59, 0x1D58, 0x1D5B, 0x1D5A, 0x000A,
1786 0x001C, 0x0001, 0x003F, 0x003B, 0x0001, 0x0009, 0x0020, 0x0000,
1787 ], [
1788 0x0004, 0x000A, 0x0017, 0x0004, 0x0016, 0x016A, 0x16B1, 0x0017,
1789 0x005B, 0x0006, 0x0007, 0x0001, 0x0000, 0x000A, 0x02D7, 0x0B5A,
1790 0x16B0, 0x16B3, 0x16B2, 0x2D6D, 0x2D6C, 0x2D6F, 0x2D6E, 0x0006,
1791 0x000A, 0x0004, 0x002C, 0x0017, 0x0003, 0x0007, 0x0016, 0x00B4,
1792 ], [
1793 0x0005, 0x000D, 0x0005, 0x0009, 0x0033, 0x0193, 0x192C, 0x0061,
1794 0x0031, 0x0000, 0x0007, 0x0010, 0x0011, 0x00C8, 0x192F, 0x325B,
1795 0x325A, 0x1929, 0x1928, 0x192B, 0x192A, 0x325D, 0x325C, 0x0018,
1796 0x001A, 0x001B, 0x0065, 0x0019, 0x0004, 0x0007, 0x0060, 0x0324,
1797 ], [
1798 0x0006, 0x0000, 0x0002, 0x000F, 0x0039, 0x01D9, 0x1D82, 0x0761,
1799 0x03BE, 0x0001, 0x0002, 0x000F, 0x000E, 0x0762, 0x3B07, 0x3B06,
1800 0x3B1D, 0x3B1C, 0x3B1F, 0x3B1E, 0x3B19, 0x3B18, 0x3B1B, 0x0038,
1801 0x01DE, 0x00ED, 0x03BF, 0x00EE, 0x003A, 0x0006, 0x0EC0, 0x3B1A,
1802 ], [
1803 0x0000, 0x0002, 0x000F, 0x0006, 0x001C, 0x01D0, 0x0E8C, 0x1D1B,
1804 0x1D1A, 0x0003, 0x0002, 0x00EA, 0x00E9, 0x0E89, 0x0E88, 0x0E8B,
1805 0x0E8A, 0x1D65, 0x1D64, 0x1D67, 0x1D66, 0x1D61, 0x1D60, 0x03AD,
1806 0x1D63, 0x1D62, 0x1D1D, 0x1D1C, 0x003B, 0x01D7, 0x1D1F, 0x1D1E,
1807 ], [
1808 0x0002, 0x000F, 0x001C, 0x000C, 0x003B, 0x01AC, 0x1AD8, 0x35B3,
1809 0x35B2, 0x0001, 0x0000, 0x0069, 0x0068, 0x35BD, 0x35BC, 0x35BF,
1810 0x35BE, 0x35B9, 0x35B8, 0x35BB, 0x35BA, 0x35B5, 0x35B4, 0x01A9,
1811 0x01A8, 0x035A, 0x00D7, 0x00D5, 0x003A, 0x001B, 0x35B7, 0x35B6,
1812 ]
1813];
1814
6543b6f8 1815const VP31_AC_CAT3_BITS: [[u8; 32]; 16] = [
5b24175d
KS
1816 [
1817 3, 5, 7, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 4, 5, 7,
1818 7, 8, 10, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 6, 5, 5,
1819 ], [
1820 3, 5, 6, 6, 7, 10, 13, 5, 6, 3, 3, 4, 4, 5, 6, 8,
1821 10, 10, 13, 13, 13, 12, 12, 4, 5, 5, 5, 6, 4, 5, 5, 5,
1822 ], [
1823 3, 4, 6, 5, 7, 9, 13, 6, 6, 3, 3, 4, 4, 5, 8, 10,
1824 13, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 4, 6, 6,
1825 ], [
1826 3, 4, 5, 4, 6, 8, 12, 7, 7, 3, 3, 4, 4, 7, 9, 13,
1827 13, 12, 12, 12, 12, 12, 12, 4, 5, 5, 6, 6, 4, 4, 7, 7,
1828 ], [
1829 3, 4, 5, 4, 5, 7, 10, 10, 7, 3, 3, 5, 5, 8, 13, 14,
1830 14, 13, 13, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 3, 7, 10,
1831 ], [
1832 3, 4, 3, 3, 4, 6, 11, 13, 8, 3, 3, 6, 6, 13, 13, 13,
1833 13, 13, 13, 13, 14, 14, 14, 3, 6, 8, 9, 8, 6, 5, 12, 14,
1834 ], [
1835 3, 4, 3, 3, 4, 6, 11, 13, 8, 3, 3, 6, 6, 13, 13, 13,
1836 13, 13, 13, 13, 14, 14, 14, 3, 6, 8, 9, 8, 6, 5, 12, 14,
1837 ], [
1838 3, 4, 3, 3, 4, 6, 11, 13, 8, 3, 3, 6, 6, 13, 13, 13,
1839 13, 13, 13, 13, 14, 14, 14, 3, 6, 8, 9, 8, 6, 5, 12, 14,
1840 ], [
1841 3, 5, 6, 7, 9, 12, 12, 5, 7, 3, 3, 4, 4, 5, 6, 7,
1842 9, 9, 10, 13, 13, 13, 13, 4, 4, 5, 5, 6, 4, 5, 5, 6,
1843 ], [
1844 3, 4, 6, 5, 8, 13, 14, 6, 6, 3, 3, 4, 4, 5, 7, 9,
1845 10, 11, 14, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 4, 6, 6,
1846 ], [
1847 3, 4, 5, 5, 7, 10, 13, 6, 6, 3, 3, 4, 4, 6, 8, 9,
1848 12, 14, 14, 13, 13, 13, 13, 4, 5, 5, 6, 6, 4, 4, 6, 6,
1849 ], [
1850 3, 4, 5, 4, 6, 9, 13, 7, 7, 3, 3, 4, 4, 6, 10, 12,
1851 13, 13, 13, 14, 14, 14, 14, 4, 5, 5, 6, 6, 4, 4, 7, 8,
1852 ], [
1853 3, 4, 4, 4, 6, 9, 13, 8, 7, 2, 3, 5, 5, 8, 13, 14,
1854 14, 13, 13, 13, 13, 14, 14, 5, 6, 6, 7, 6, 4, 4, 8, 10,
1855 ], [
1856 3, 3, 4, 4, 6, 9, 13, 11, 10, 2, 2, 6, 6, 11, 14, 14,
1857 14, 14, 14, 14, 14, 14, 14, 6, 9, 8, 10, 8, 6, 5, 12, 14,
1858 ], [
1859 2, 3, 5, 4, 6, 10, 13, 14, 14, 2, 2, 9, 9, 13, 13, 13,
1860 13, 14, 14, 14, 14, 14, 14, 11, 14, 14, 14, 14, 7, 10, 14, 14,
1861 ], [
1862 2, 4, 5, 4, 6, 9, 13, 14, 14, 2, 2, 7, 7, 14, 14, 14,
1863 14, 14, 14, 14, 14, 14, 14, 9, 9, 10, 8, 8, 6, 5, 14, 14,
1864 ]
1865];
1866
6543b6f8 1867const VP31_DC_WEIGHTS: [[i16; 5]; 16] = [
5b24175d
KS
1868 [ 0, 0, 0, 0, 0 ],
1869 [ 1, 0, 0, 0, 1 ],
1870 [ 0, 1, 0, 0, 1 ],
1871 [ 1, 0, 0, 0, 1 ],
1872
1873 [ 0, 0, 1, 0, 1 ],
1874 [ 1, 0, 1, 0, 2 ],
1875 [ 0, 0, 1, 0, 1 ],
1876 [ 29, -26, 29, 0, 32 ],
1877
1878 [ 0, 0, 0, 1, 1 ],
1879 [ 75, 0, 0, 53, 128 ],
1880 [ 0, 1, 0, 1, 2 ],
1881 [ 75, 0, 0, 53, 128 ],
1882
1883 [ 0, 0, 1, 0, 1 ],
1884 [ 75, 0, 0, 53, 128 ],
1885 [ 0, 3, 10, 3, 16 ],
1886 [ 29, -26, 29, 0, 32 ],
1887];