forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBea3c0dfTahinli3 months ago1465 commits

superres-pin-harness.c144 lines, 7.1 KiBHistoryRawDownload
1#include <stdio.h>
2#include <stdint.h>
3#include <string.h>
4
5#define RS_SUBPEL_BITS 6
6#define RS_SCALE_SUBPEL_BITS 14
7#define RS_SCALE_SUBPEL_MASK ((1 << RS_SCALE_SUBPEL_BITS) - 1)
8#define RS_SCALE_EXTRA_BITS (RS_SCALE_SUBPEL_BITS - RS_SUBPEL_BITS)
9#define RS_SCALE_EXTRA_OFF (1 << (RS_SCALE_EXTRA_BITS - 1))
10#define UPSCALE_NORMATIVE_TAPS 8
11
12extern const int16_t av1_resize_filter_normative[1 << RS_SUBPEL_BITS][UPSCALE_NORMATIVE_TAPS];
13extern int32_t av1_get_upscale_convolve_step(int in_length, int out_length);
14extern void av1_convolve_horiz_rs_c(const uint8_t *src, int src_stride,
15 uint8_t *dst, int dst_stride, int w,
16 int h, const int16_t *x_filters,
17 int x0_qn, int x_step_qn);
18
19// verbatim copy of resize.c's static get_upscale_convolve_x0 -- the one
20// formula in the pipeline this harness does not exercise via a real
21// exported symbol; everything else (the coefficient table + the
22// convolution/rounding kernel, the actual bug risk) runs real compiled
23// libaom code.
24static int32_t get_upscale_convolve_x0(int in_length, int out_length,
25 int32_t x_step_qn) {
26 const int err = out_length * x_step_qn - (in_length << RS_SCALE_SUBPEL_BITS);
27 const int32_t x0 =
28 (-((out_length - in_length) << (RS_SCALE_SUBPEL_BITS - 1)) +
29 out_length / 2) /
30 out_length +
31 RS_SCALE_EXTRA_OFF - err / 2;
32 return (int32_t)((uint32_t)x0 & RS_SCALE_SUBPEL_MASK);
33}
34
35static void run_case_margin(const char *label, int in_len, int out_len,
36 const uint8_t *input, const uint8_t *margin,
37 int margin_len) {
38 uint8_t padded[512];
39 const int pad = 32;
40 uint8_t *row = padded + pad;
41 memset(padded, input[0], pad);
42 memcpy(row, input, in_len);
43 memcpy(row + in_len, margin, margin_len);
44 memset(row + in_len + margin_len, margin[margin_len - 1], pad);
45
46 int32_t x_step_qn = av1_get_upscale_convolve_step(in_len, out_len);
47 int32_t x0_qn = get_upscale_convolve_x0(in_len, out_len, x_step_qn);
48 printf("%s: x_step_qn=%d x0_qn=%d\n", label, x_step_qn, x0_qn);
49 uint8_t out[256];
50 av1_convolve_horiz_rs_c(row - 1, 0, out, 0, out_len, 1,
51 &av1_resize_filter_normative[0][0], x0_qn,
52 x_step_qn);
53 printf("%s out:", label);
54 for (int i = 0; i < out_len; i++) printf(" %d", out[i]);
55 printf("\n");
56}
57
58// Runs one row through the real compiled libaom convolver, edge-replicated
59// padding on both sides (the single-tile case, matching this decoder's
60// `superres::upscale_row`). `right_pad_col` lets the caller feed a
61// right-edge pad value that differs from `input[in_len-1]`, to test
62// r3's charter question (does the padding value change the output at
63// all near the right edge, i.e. does the failing case even depend on
64// what's beyond column `in_len-1`).
65static void run_case(const char *label, int in_len, int out_len,
66 const uint8_t *input, int right_pad_val) {
67 uint8_t padded[512];
68 const int pad = 32;
69 uint8_t *row = padded + pad;
70 memset(padded, input[0], pad);
71 memcpy(row, input, in_len);
72 memset(row + in_len, right_pad_val, pad);
73
74 int32_t x_step_qn = av1_get_upscale_convolve_step(in_len, out_len);
75 int32_t x0_qn = get_upscale_convolve_x0(in_len, out_len, x_step_qn);
76 printf("%s: in_len=%d out_len=%d x_step_qn=%d x0_qn=%d right_pad=%d\n",
77 label, in_len, out_len, x_step_qn, x0_qn, right_pad_val);
78
79 uint8_t out[256];
80 av1_convolve_horiz_rs_c(row - 1, 0, out, 0, out_len, 1,
81 &av1_resize_filter_normative[0][0], x0_qn,
82 x_step_qn);
83 printf("%s out:", label);
84 for (int i = 0; i < out_len; i++) printf(" %d", out[i]);
85 printf("\n");
86}
87
88int main(void) {
89 uint8_t input8[8] = { 10, 20, 30, 40, 50, 60, 70, 80 };
90 run_case("in8->out12", 8, 12, input8, input8[7]);
91 run_case("in8->out16", 8, 16, input8, input8[7]);
92
93 // r3: the exact failing ratio (43 -> 64), row 6 of the real aomenc
94 // superres key-frame gate fixture (`EC_SUPERRES_DEBUG=1` dump of the
95 // input row this decoder feeds `upscale_row`, matched against the
96 // `DIFF frame=0 row=6 col=62 got=140 want=141` mismatch). Run once
97 // with the replicate-from-column-42 padding this decoder uses, and
98 // once with a right pad value that visibly differs, to settle whether
99 // the failing columns even read past the real input at all.
100 uint8_t row6[43] = { 102, 102, 103, 103, 104, 105, 106, 107, 108, 109,
101 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
102 120, 121, 122, 123, 125, 126, 127, 127, 128, 129,
103 130, 130, 131, 131, 133, 134, 136, 137, 138, 139,
104 140, 140, 141 };
105 run_case("row6-replicate", 43, 64, row6, row6[42]);
106 run_case("row6-farpad", 43, 64, row6, 255);
107
108 // r3 decisive check: `CROPDBG` dumped the pre-crop reconstructed row at
109 // the real (mi-aligned) width 48 -- columns 43..47 are genuine decoded
110 // pixels (140,140,140,140,140), NOT a replicate of column 42 (141, this
111 // decoder's current padding value). Feed the real trailing pixels
112 // instead of a flat replicate and see if the failing columns change.
113 uint8_t row6_real48[48] = { 102, 102, 103, 103, 104, 105, 106, 107, 108, 109,
114 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
115 120, 121, 122, 123, 125, 126, 127, 127, 128, 129,
116 130, 130, 131, 131, 133, 134, 136, 137, 138, 139,
117 140, 140, 141, 140, 140, 140, 140, 140 };
118 run_case("row6-realpad48", 48, 64, row6_real48, row6_real48[47]);
119 // Same real trailing pixels but in_len still 43 (matches frame_width),
120 // right_pad taken from the first real trailing pixel (140) rather than
121 // the frame-edge pixel (141) -- the actual libaom border-extend source.
122 run_case("row6-realedgeval", 43, 64, row6, 140);
123
124 // r3 round 2: frame 2's rows 17/18 still mismatched by 1 at col 62 with
125 // the flat-margin fix landed. Their real margin is NOT flat (a gradient
126 // slope continues past the frame edge), so this checks the fix's
127 // n-real-pixels-then-replicate strategy against the true 5-pixel margin.
128 uint8_t row17[43] = { 109, 109, 109, 110, 111, 112, 112, 113, 114, 115,
129 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
130 126, 127, 128, 129, 130, 131, 131, 132, 133, 134,
131 135, 136, 137, 139, 139, 140, 140, 141, 142, 142,
132 143, 144, 145 };
133 uint8_t margin17[5] = { 146, 146, 147, 147, 147 };
134 run_case_margin("row17-margin", 43, 64, row17, margin17, 5);
135
136 uint8_t row18[43] = { 109, 110, 110, 110, 111, 112, 113, 114, 115, 116,
137 117, 118, 119, 120, 121, 122, 122, 123, 124, 125,
138 126, 127, 128, 129, 130, 131, 132, 133, 133, 134,
139 134, 136, 138, 140, 139, 140, 140, 141, 142, 142,
140 143, 144, 145 };
141 uint8_t margin18[5] = { 146, 147, 147, 148, 148 };
142 run_case_margin("row18-margin", 43, 64, row18, margin18, 5);
143 return 0;
144}