shithub: dav1d

Download patch

ref: acfa495a20f2d436683c4ced629469e32875cb03
parent: 2df2aab9a70eb3f8e0605c875102084397c92fc0
author: David Michael Barr <b@rr-dav.id.au>
date: Tue Oct 16 16:14:05 EDT 2018

checkasm: Add unit tests for chroma-from-luma

--- a/tests/checkasm/ipred.c
+++ b/tests/checkasm/ipred.c
@@ -46,6 +46,13 @@
     [FILTER_PRED]   = "filter"
 };
 
+static const char *const cfl_pred_mode_names[DC_128_PRED + 1] = {
+    [DC_PRED]       = "cfl",
+    [DC_128_PRED]   = "cfl_128",
+    [TOP_DC_PRED]   = "cfl_top",
+    [LEFT_DC_PRED]  = "cfl_left",
+};
+
 static const uint8_t z_angles[27] = {
      3,  6,  9,
     14, 17, 20, 23, 26, 29, 32,
@@ -93,9 +100,52 @@
     report("intra_pred");
 }
 
+static void check_cfl_pred(Dav1dIntraPredDSPContext *const c) {
+    ALIGN_STK_32(pixel, c_dst, 32 * 32,);
+    ALIGN_STK_32(pixel, a_dst, 32 * 32,);
+    ALIGN_STK_32(int16_t, ac, 32 * 32,);
+    ALIGN_STK_32(pixel, topleft_buf, 257,);
+    pixel *const topleft = topleft_buf + 128;
+
+    declare_func(void, pixel *dst, ptrdiff_t stride, const pixel *topleft,
+                 int width, int height, const int16_t *ac, int alpha);
+
+    for (int mode = 0; mode <= DC_128_PRED; mode += 1 + 2 * !mode)
+        for (int w = 4; w <= 32; w <<= 1)
+            if (check_func(c->cfl_pred[mode], "cfl_pred_%s_w%d_%dbpc",
+                cfl_pred_mode_names[mode], w, BITDEPTH))
+            {
+                for (int h = imax(w / 4, 4); h <= imin(w * 4, 32); h <<= 1)
+                {
+                    const ptrdiff_t stride = w * sizeof(pixel);
+
+                    int alpha = ((rand() & 15) + 1) * (1 - (rand() & 2));
+
+                    for (int i = -h * 2; i <= w * 2; i++)
+                        topleft[i] = rand() & ((1 << BITDEPTH) - 1);
+
+                    int luma_avg = w * h >> 1;
+                    for (int i = 0; i < w * h; i++)
+                        luma_avg += ac[i] = rand() & ((1 << BITDEPTH) - 1) << 3;
+                    luma_avg /= w * h;
+                    for (int i = 0; i < w * h; i++)
+                        ac[i] -= luma_avg;
+
+                    call_ref(c_dst, stride, topleft, w, h, ac, alpha);
+                    call_new(a_dst, stride, topleft, w, h, ac, alpha);
+                    if (memcmp(c_dst, a_dst, w * h * sizeof(*c_dst)))
+                        fail();
+
+                    bench_new(a_dst, stride, topleft, w, h, ac, alpha);
+                }
+            }
+    report("cfl_pred");
+}
+
 void bitfn(checkasm_check_ipred)(void) {
     Dav1dIntraPredDSPContext c;
     bitfn(dav1d_intra_pred_dsp_init)(&c);
 
     check_intra_pred(&c);
+    check_cfl_pred(&c);
 }