forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

tests.rs106 lines, 3.9 KiBHistoryRawDownload
1use super::*;
2
3/// The level-0 luma 4x4 corner, read off the C file by eye as well as by
4/// the extractor: a table that shifted a chunk boundary moves this.
5#[test]
6fn table_anchor_level0_luma_4x4() {
7 let m = iwt_matrix(0, false, 4, 4).unwrap();
8 assert_eq!(
9 m.data,
10 &[32, 43, 73, 97, 43, 67, 94, 110, 73, 94, 137, 150, 97, 110, 150, 200]
11 );
12 assert_eq!(m.stride, 4);
13}
14
15/// Chroma matrices are DIFFERENT data at the same level, not a re-read
16/// of the luma ones (`iwt_matrix_ref[q][c >= 1]`).
17#[test]
18fn chroma_matrix_at_the_same_level_differs_from_luma() {
19 let luma = iwt_matrix(0, false, 4, 4).unwrap();
20 let chroma = iwt_matrix(0, true, 4, 4).unwrap();
21 assert_eq!(
22 chroma.data,
23 &[35, 46, 57, 66, 46, 60, 69, 71, 57, 69, 90, 90, 66, 71, 90, 109]
24 );
25 assert_ne!(luma.data, chroma.data);
26}
27
28/// Every level selects a matrix below 15 and nothing does at 15 (the
29/// flat sentinel libaom stores as NULL), for every stored shape and
30/// both plane kinds; the shape lengths follow the walk.
31#[test]
32fn level_and_shape_selection_matches_the_walk() {
33 const SHAPES: [(usize, usize, usize); 14] = [
34 (4, 4, 16),
35 (8, 8, 64),
36 (16, 16, 256),
37 (32, 32, 1024),
38 (4, 8, 32),
39 (8, 4, 32),
40 (8, 16, 128),
41 (16, 8, 128),
42 (16, 32, 512),
43 (32, 16, 512),
44 (4, 16, 64),
45 (16, 4, 64),
46 (8, 32, 256),
47 (32, 8, 256),
48 ];
49 for level in 0..NUM_QM_LEVELS {
50 for chroma in [false, true] {
51 for &(w, h, len) in SHAPES.iter() {
52 let m = iwt_matrix(level, chroma, w, h);
53 if level >= NUM_QM_LEVELS - 1 {
54 assert!(m.is_none());
55 } else {
56 let m = m.unwrap();
57 assert_eq!(m.data.len(), len, "{level} {chroma} {w}x{h}");
58 // the stride is the column stride of libaom's
59 // column-major position space: the active HEIGHT.
60 assert_eq!(m.stride, h);
61 }
62 }
63 }
64 }
65}
66
67/// The 64-axis clamps (`av1_get_adjusted_tx_size`): 64x64/64x32/32x64
68/// read the 32x32 matrix, 64x16 the 32x16 one, 16x64 the 16x32 one --
69/// the same slice as their adjusted shapes.
70#[test]
71fn clamped_64_shapes_reuse_their_adjusted_matrix() {
72 let sq = iwt_matrix(3, false, 32, 32).unwrap();
73 for &(w, h) in [(64usize, 64usize), (64, 32), (32, 64)].iter() {
74 let m = iwt_matrix(3, false, w, h).unwrap();
75 assert_eq!(m.data.as_ptr(), sq.data.as_ptr(), "{w}x{h}");
76 assert_eq!(m.stride, 32);
77 }
78 let r3216 = iwt_matrix(3, true, 32, 16).unwrap();
79 let m = iwt_matrix(3, true, 64, 16).unwrap();
80 assert_eq!(m.data.as_ptr(), r3216.data.as_ptr());
81 assert_eq!(m.stride, 16);
82 let r1632 = iwt_matrix(3, true, 16, 32).unwrap();
83 let m = iwt_matrix(3, true, 16, 64).unwrap();
84 assert_eq!(m.data.as_ptr(), r1632.data.as_ptr());
85 assert_eq!(m.stride, 32);
86}
87
88/// `dqv_at` is libaom's `get_dqv` verbatim: an entry of 32 (`1 <<
89/// AOM_QM_BITS`) is the identity, rounding is half-up into the shift,
90/// and a position on a later ROW of a true-w raster re-strides onto the
91/// matrix stride.
92#[test]
93fn dqv_scales_and_rounds_like_get_dqv() {
94 let m = iwt_matrix(0, false, 8, 8).unwrap();
95 // DC: entry 32 is the exact identity.
96 assert_eq!(dqv_at(&m, 0, 8, 100), 100);
97 // pos 1 = cell (0,1) = column-major index 1*8+0 = 8, entry 32
98 // (row-major would read data[1] = 32 too at this corner -- the
99 // shapes coincide at the top-left corner): exact.
100 assert_eq!(dqv_at(&m, 1, 8, 100), 100);
101 // pos 8 = cell (1,0) = column-major index 0*8+1 = 1, entry 32:
102 // (32 * 10 + 16) >> 5 = 10. Row-major indexing would have read
103 // data[8] = 32 as well here -- but at pos 1 they differ (32 vs 35),
104 // which is how the oracle exposed the transposition.
105 assert_eq!(dqv_at(&m, 8, 8, 10), ((32 * 10) + 16) >> 5);
106}