forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB00c1b3fTahinli2 months ago1999 commits

lr-sgr-pin-harness.c89 lines, 4.3 KiBHistoryRawDownload
1#include <stdio.h>
2#include <stdint.h>
3#include <stdlib.h>
4
5extern int av1_apply_selfguided_restoration_c(
6 const uint8_t *dat8, int width, int height, int stride, int eps,
7 const int *xqd, uint8_t *dst8, int dst_stride, int32_t *tmpbuf,
8 int bit_depth, int highbd);
9extern int av1_selfguided_restoration_c(const uint8_t *dgd8, int width,
10 int height, int dgd_stride,
11 int32_t *flt0, int32_t *flt1,
12 int flt_stride, int sgr_params_idx,
13 int bit_depth, int highbd);
14// Exported by scripts/instrument-aom-oracle.sh's rung 6 (normally `static`
15// in restoration.c) so this harness can get real per-tap A[]/B[] instead of
16// only the combined flt0/flt1 -- the missing half of r6's 9-tap cross-check.
17extern void calculate_intermediate_result(int32_t *dgd, int width, int height,
18 int dgd_stride, int bit_depth,
19 int sgr_params_idx, int radius_idx,
20 int pass, int32_t *A, int32_t *B);
21
22#define SGRPROJ_BORDER_VERT 3
23#define SGRPROJ_BORDER_HORZ 3
24
25int main(void) {
26 const int bw = 102, bh = 10;
27 // real libaom splits stripe_width into RESTORATION_PROC_UNIT_SIZE=64
28 // chunks (sgrproj_filter_stripe's `for j += procunit_width` loop) --
29 // av1_apply_selfguided_restoration_c's internal fixed-size arrays are
30 // sized for that max, so replicate the chunking (target col=6 is in
31 // the first 64-wide chunk).
32 const int w = 64, h = 4;
33 uint8_t *buf = malloc(bw * bh);
34 FILE *f = fopen("/tmp/lr_full.bin", "rb");
35 if (!f) { perror("open"); return 1; }
36 if (fread(buf, 1, bw * bh, f) != (size_t)(bw * bh)) { fprintf(stderr, "short read\n"); return 1; }
37 fclose(f);
38
39 const uint8_t *dgd8 = buf + 3 * bw + 3; // logical (0,0)
40 int xqd[2] = { -16, -32 };
41 uint8_t dst[w * h];
42 // flt1 = tmpbuf + RESTORATION_UNITPELS_MAX (~152100); undersizing this
43 // segfaults inside av1_apply_selfguided_restoration_c.
44 static int32_t tmpbuf[2 * 400 * 400];
45
46 int ret = av1_apply_selfguided_restoration_c(dgd8, w, h, bw, /*eps=*/6, xqd,
47 dst, w, tmpbuf, 8, 0);
48 printf("ret=%d\n", ret);
49 // target pixel: row i=1, col j=6
50 printf("out[1][6] = %d\n", dst[1 * w + 6]);
51 printf("dgd[1][6] = %d\n", dgd8[1 * bw + 6]);
52
53 static int32_t flt0[400 * 400], flt1[400 * 400];
54 int r2 = av1_selfguided_restoration_c(dgd8, w, h, bw, flt0, flt1, w, 6, 8, 0);
55 printf("selfguided ret=%d flt0[1][6]=%d flt1[1][6]=%d\n", r2, flt0[1 * w + 6],
56 flt1[1 * w + 6]);
57
58 // --- rung 6: real per-tap A[]/B[] ground truth for the dense (r1) arm ---
59 // Replicate av1_selfguided_restoration_c's own uint8->int32 border-extend
60 // copy (that function's `dgd32` setup, restoration.c) so
61 // calculate_intermediate_result sees exactly the same input it would from
62 // the real call path above.
63 const int dgd32_stride = w + 2 * SGRPROJ_BORDER_HORZ;
64 static int32_t dgd32_buf[(64 + 6) * (4 + 6)];
65 int32_t *dgd32 = dgd32_buf + dgd32_stride * SGRPROJ_BORDER_VERT + SGRPROJ_BORDER_HORZ;
66 for (int i = -SGRPROJ_BORDER_VERT; i < h + SGRPROJ_BORDER_VERT; ++i)
67 for (int j = -SGRPROJ_BORDER_HORZ; j < w + SGRPROJ_BORDER_HORZ; ++j)
68 dgd32[i * dgd32_stride + j] = dgd8[i * bw + j];
69
70 const int width_ext = w + 2 * SGRPROJ_BORDER_HORZ;
71 const int buf_stride = ((width_ext + 3) & ~3) + 16;
72 static int32_t A_[2 * 400 * 400], B_[2 * 400 * 400];
73 // radius_idx=1 (dense/r1 arm), pass=0 (every row, matches
74 // selfguided_restoration_internal's own call).
75 calculate_intermediate_result(dgd32, w, h, dgd32_stride, /*bit_depth=*/8,
76 /*sgr_params_idx=*/6, /*radius_idx=*/1,
77 /*pass=*/0, A_, B_);
78 int32_t *A = A_ + SGRPROJ_BORDER_VERT * buf_stride + SGRPROJ_BORDER_HORZ;
79 int32_t *B = B_ + SGRPROJ_BORDER_VERT * buf_stride + SGRPROJ_BORDER_HORZ;
80 const int ti = 1, tj = 6;
81 const char *names[9] = { "c", "u", "d", "l", "r", "ul", "ur", "dl", "dr" };
82 const int di[9] = { 0, -1, 1, 0, 0, -1, -1, 1, 1 };
83 const int dj[9] = { 0, 0, 0, -1, 1, -1, 1, -1, 1 };
84 for (int t = 0; t < 9; ++t) {
85 int k = (ti + di[t]) * buf_stride + (tj + dj[t]);
86 printf("real_ab %s = (%d,%d)\n", names[t], A[k], B[k]);
87 }
88 return 0;
89}