forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

tx4x8_table_tests.rs89 lines, 3.2 KiBHistoryRawDownload
1use super::*;
2
3/// Asymmetric gate on the two new scan tables (class
4/// `reference-layout-not-spec`): a transposed pair of tables passes any
5/// "is a permutation" check, so this pins the pair AGAINST each other --
6/// `SCAN_8X4[k]` must be `SCAN_4X8[k]` reflected across the diagonal, and
7/// both must be bijections of `0..32` in our own row-major indexing.
8#[test]
9fn the_rect_4x8_scans_are_each_other_transposed() {
10 let mut seen_a = [false; 32];
11 let mut seen_b = [false; 32];
12 for k in 0..32usize {
13 let a = SCAN_4X8[k] as usize;
14 let b = SCAN_8X4[k] as usize;
15 assert!(!seen_a[a] && !seen_b[b], "scan position {k} repeats");
16 seen_a[a] = true;
17 seen_b[b] = true;
18 let (row, col) = (a / 4, a % 4);
19 assert_eq!(
20 b,
21 col * 8 + row,
22 "SCAN_8X4[{k}] is not SCAN_4X8[{k}] transposed"
23 );
24 }
25 assert!(seen_a.iter().all(|&s| s) && seen_b.iter().all(|&s| s));
26}
27
28/// `mrow_scan_4x8`/`mcol_scan_4x8`/`mrow_scan_8x4`/`mcol_scan_8x4`
29/// (libaom `scan.c`), converted out of their column-major encoding by
30/// `(p % h) * w + p / h` -- the head of each, pinned so the rect
31/// `V_DCT`/`H_DCT` walk cannot silently transpose.
32#[test]
33fn the_rect_class1_scans_match_libaom() {
34 assert_eq!(
35 class_scan_table_wh(4, 8, TxClass::Vert),
36 (0..32u16).collect::<Vec<_>>()
37 );
38 assert_eq!(
39 &class_scan_table_wh(4, 8, TxClass::Horiz)[..8],
40 &[0u16, 4, 8, 12, 16, 20, 24, 28]
41 );
42 assert_eq!(
43 class_scan_table_wh(8, 4, TxClass::Vert),
44 (0..32u16).collect::<Vec<_>>()
45 );
46 assert_eq!(
47 &class_scan_table_wh(8, 4, TxClass::Horiz)[..8],
48 &[0u16, 8, 16, 24, 1, 9, 17, 25]
49 );
50}
51
52/// The 32-position `eob_pt` alphabet: six symbols (one more than the
53/// 16-position table, one fewer than the 64-position one), strictly
54/// increasing, terminated at 32768 with the adaptation counter after it.
55#[test]
56fn the_32_position_eob_tables_are_well_formed() {
57 for table in [
58 &cdf::EOB_PT_32_LUMA_Q0,
59 &cdf::EOB_PT_32_LUMA_Q1,
60 &cdf::EOB_PT_32_LUMA,
61 &cdf::EOB_PT_32_LUMA_Q3,
62 &cdf::EOB_PT_32_LUMA_CLASS1_Q0,
63 &cdf::EOB_PT_32_LUMA_CLASS1_Q1,
64 &cdf::EOB_PT_32_LUMA_CLASS1,
65 &cdf::EOB_PT_32_LUMA_CLASS1_Q3,
66 ] {
67 assert_eq!(table.len(), 7);
68 assert_eq!(table[5], 32768);
69 assert_eq!(table[6], 0);
70 for w in table[..6].windows(2) {
71 assert!(w[0] < w[1], "{table:?} is not increasing");
72 }
73 }
74}
75
76/// `Reach::of_rect` must read libaom's own `has_tr_4x8`/`has_tr_8x4`
77/// rows, not the 32x16 pair the two existing rect strips use: the two
78/// shapes disagree at a position inside the superblock, which is what
79/// makes this an asymmetric check rather than a tautology.
80#[test]
81fn the_sub8_rect_reach_tables_are_shape_specific() {
82 let fctx = &crate::decode::FrameCtx::new();
83 let a = Reach::of_rect(4, 8, 4, 8, 64, 64, fctx);
84 let b = Reach::of_rect(8, 4, 8, 4, 64, 64, fctx);
85 assert!(
86 a.above_right != b.above_right || a.below_left != b.below_left,
87 "4x8 and 8x4 reach identically at mirrored positions -- one table is unused"
88 );
89}