forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

tests.rs122 lines, 4.2 KiBHistoryRawDownload
1use super::*;
2
3/// Every row of a CDF table is non-decreasing and ends with the
4/// alphabet's total (`32768`) followed by the adaptation counter (`0`),
5/// which is the shape [`crate::msac`] expects to read.
6fn assert_row_shape(row: &[u16]) {
7 assert_eq!(row[row.len() - 2], 32768, "row does not total 32768");
8 assert_eq!(row[row.len() - 1], 0, "row's adaptation counter is not 0");
9 for w in row[..row.len() - 1].windows(2) {
10 assert!(w[0] <= w[1], "row is not non-decreasing: {row:?}");
11 }
12}
13
14/// Every `eob_pt` table libaom keeps as `[q][plane][2]` has its class-1
15/// (`tx_class != TX_CLASS_2D`) row here, and it is the *other* row.
16///
17/// libaom only ever trained the class-1 row where a 1D tx type can occur:
18/// `av1_get_ext_tx_set_type` returns `DCT_IDTX`/`DCTONLY` once
19/// `tx_size_sqr_up >= TX_32X32`, so the 512- and 1024-point rows are the
20/// untouched uniform initialiser. Pinned so a future table edit cannot
21/// quietly narrow the domain back to 2D-only (lane-eobc1 r1; values
22/// diffed against `token_cdfs.h` by `scripts/extract-eob-class1.py`).
23#[test]
24fn eob_pt_class1_rows_cover_every_size() {
25 fn uniform(row: &[u16]) -> bool {
26 let n = row.len() - 1;
27 row[..n].iter().enumerate().all(|(i, &v)| {
28 let n = n as u32;
29 v == (((i as u32 + 1) * 32768 + n / 2) / n) as u16
30 })
31 }
32 let trained: [(&[u16], &[u16]); 8] = [
33 (&EOB_PT_16_LUMA, &EOB_PT_16_LUMA_CLASS1),
34 (&EOB_PT_16_CHROMA, &EOB_PT_16_CHROMA_CLASS1),
35 (&EOB_PT_64_LUMA, &EOB_PT_64_LUMA_CLASS1),
36 (&EOB_PT_64_CHROMA, &EOB_PT_64_CHROMA_CLASS1),
37 (&EOB_PT_128_CHROMA, &EOB_PT_128_CHROMA_CLASS1),
38 (&EOB_PT_256_LUMA, &EOB_PT_256_LUMA_CLASS1),
39 (&EOB_PT_256_CHROMA, &EOB_PT_256_CHROMA_CLASS1),
40 (&EOB_PT_512_LUMA, &EOB_PT_512_LUMA_CLASS1),
41 ];
42 for (two_d, class1) in trained {
43 assert_row_shape(class1);
44 assert_eq!(two_d.len(), class1.len());
45 }
46 for (two_d, class1) in &trained[..7] {
47 assert_ne!(two_d, class1, "class-1 row is a copy of the 2D row");
48 assert!(!uniform(class1), "class-1 row was never trained");
49 }
50 for row in [
51 &EOB_PT_512_LUMA_CLASS1[..],
52 &EOB_PT_512_CHROMA_CLASS1[..],
53 &EOB_PT_1024_LUMA_CLASS1[..],
54 &EOB_PT_1024_CHROMA_CLASS1[..],
55 ] {
56 assert_row_shape(row);
57 assert!(uniform(row), "libaom trained a 32-point class-1 row");
58 }
59}
60
61#[test]
62fn inter_frame_tables_are_well_formed_cdfs() {
63 for row in INTRA_INTER {
64 assert_row_shape(&row);
65 }
66 for ctx in SINGLE_REF {
67 for row in ctx {
68 assert_row_shape(&row);
69 }
70 }
71 for row in Y_MODE {
72 assert_row_shape(&row);
73 }
74 for row in NEW_MV {
75 assert_row_shape(&row);
76 }
77 for row in ZERO_MV {
78 assert_row_shape(&row);
79 }
80 for row in REF_MV {
81 assert_row_shape(&row);
82 }
83 for row in DRL_MODE {
84 assert_row_shape(&row);
85 }
86 assert_row_shape(&MV_JOINT);
87 assert_row_shape(&MV_CLASS);
88 assert_row_shape(&MV_CLASS0_BIT);
89 for row in MV_CLASS0_FR {
90 assert_row_shape(&row);
91 }
92 assert_row_shape(&MV_CLASS0_HP);
93 for row in MV_BIT {
94 assert_row_shape(&row);
95 }
96 assert_row_shape(&MV_FR);
97 assert_row_shape(&MV_HP);
98 assert_row_shape(&MV_SIGN);
99}
100
101/// Each table's row length matches the spec's symbol count for that
102/// syntax element: two entries (total, counter) plus one fewer than the
103/// alphabet.
104#[test]
105fn inter_frame_tables_have_the_spec_alphabet_size() {
106 assert_eq!(INTRA_INTER[0].len(), 2 + 1); // binary
107 assert_eq!(SINGLE_REF[0][0].len(), 2 + 1); // binary
108 assert_eq!(Y_MODE[0].len(), 2 + 13 - 1); // 13 luma intra modes
109 assert_eq!(NEW_MV[0].len(), 2 + 1);
110 assert_eq!(ZERO_MV[0].len(), 2 + 1);
111 assert_eq!(REF_MV[0].len(), 2 + 1);
112 assert_eq!(DRL_MODE[0].len(), 2 + 1);
113 assert_eq!(MV_JOINT.len(), 2 + 3); // MV_JOINTS = 4
114 assert_eq!(MV_CLASS.len(), 2 + 10); // MV_CLASSES = 11
115 assert_eq!(MV_CLASS0_BIT.len(), 2 + 1);
116 assert_eq!(MV_CLASS0_FR[0].len(), 2 + 3); // 4-way fraction
117 assert_eq!(MV_CLASS0_HP.len(), 2 + 1);
118 assert_eq!(MV_BIT[0].len(), 2 + 1);
119 assert_eq!(MV_FR.len(), 2 + 3);
120 assert_eq!(MV_HP.len(), 2 + 1);
121 assert_eq!(MV_SIGN.len(), 2 + 1);
122}