av1_convolve_2d_test_util.cc 13.2 KB
Newer Older
David Barker's avatar
David Barker committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 */

#include "test/av1_convolve_2d_test_util.h"

#include "av1/common/convolve.h"
15
#include "av1/common/common_data.h"
David Barker's avatar
David Barker committed
16 17 18 19 20 21 22 23

using std::tr1::tuple;
using std::tr1::make_tuple;

namespace libaom_test {

namespace AV1Convolve2D {

24 25 26 27 28 29 30 31 32 33 34
#if CONFIG_JNT_COMP
::testing::internal::ParamGenerator<Convolve2DParam> BuildParams(
    convolve_2d_func filter, convolve_2d_func filter2) {
  const Convolve2DParam params[] = {
    make_tuple(4, 4, filter, filter2),   make_tuple(8, 8, filter, filter2),
    make_tuple(64, 64, filter, filter2), make_tuple(4, 16, filter, filter2),
    make_tuple(32, 8, filter, filter2),
  };
  return ::testing::ValuesIn(params);
}
#else
David Barker's avatar
David Barker committed
35 36 37
::testing::internal::ParamGenerator<Convolve2DParam> BuildParams(
    convolve_2d_func filter) {
  const Convolve2DParam params[] = {
38 39 40
    make_tuple(4, 4, filter),   make_tuple(8, 8, filter),
    make_tuple(64, 64, filter), make_tuple(4, 16, filter),
    make_tuple(32, 8, filter),
David Barker's avatar
David Barker committed
41 42 43
  };
  return ::testing::ValuesIn(params);
}
44
#endif  // CONFIG_JNT_COMP
David Barker's avatar
David Barker committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

AV1Convolve2DTest::~AV1Convolve2DTest() {}
void AV1Convolve2DTest::SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }

void AV1Convolve2DTest::TearDown() { libaom_test::ClearSystemState(); }

void AV1Convolve2DTest::RunCheckOutput(convolve_2d_func test_impl) {
  const int w = 128, h = 128;
  const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
  int i, j, k;

  uint8_t *input = new uint8_t[h * w];

  int output_n = out_h * MAX_SB_SIZE;
  CONV_BUF_TYPE *output = new CONV_BUF_TYPE[output_n];
  CONV_BUF_TYPE *output2 = new CONV_BUF_TYPE[output_n];

  for (i = 0; i < h; ++i)
    for (j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand8();

  int hfilter, vfilter, subx, suby;
  for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
    for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL; ++vfilter) {
      InterpFilterParams filter_params_x =
          av1_get_interp_filter_params((InterpFilter)hfilter);
      InterpFilterParams filter_params_y =
          av1_get_interp_filter_params((InterpFilter)vfilter);
72
      const int do_average = rnd_.Rand8() & 1;
David Barker's avatar
David Barker committed
73
      ConvolveParams conv_params1 =
74
          get_conv_params_no_round(0, do_average, 0, output, MAX_SB_SIZE);
David Barker's avatar
David Barker committed
75
      ConvolveParams conv_params2 =
76
          get_conv_params_no_round(0, do_average, 0, output2, MAX_SB_SIZE);
David Barker's avatar
David Barker committed
77 78 79

      for (subx = 0; subx < 16; ++subx)
        for (suby = 0; suby < 16; ++suby) {
80 81 82 83 84 85
          // av1_convolve_2d is designed for accumulate two predicted blocks for
          // compound mode, so we set num_iter to two here.
          // A larger number may introduce overflow
          const int num_iters = 2;
          memset(output, 0, output_n * sizeof(*output));
          memset(output2, 0, output_n * sizeof(*output2));
David Barker's avatar
David Barker committed
86 87 88 89
          for (i = 0; i < num_iters; ++i) {
            // Choose random locations within the source block
            int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
            int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
90
            av1_convolve_2d_c(input + offset_r * w + offset_c, w, NULL,
David Barker's avatar
David Barker committed
91 92
                              MAX_SB_SIZE, out_w, out_h, &filter_params_x,
                              &filter_params_y, subx, suby, &conv_params1);
93
            test_impl(input + offset_r * w + offset_c, w, NULL, MAX_SB_SIZE,
David Barker's avatar
David Barker committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
                      out_w, out_h, &filter_params_x, &filter_params_y, subx,
                      suby, &conv_params2);

            for (j = 0; j < out_h; ++j)
              for (k = 0; k < out_w; ++k) {
                int idx = j * MAX_SB_SIZE + k;
                ASSERT_EQ(output[idx], output2[idx])
                    << "Pixel mismatch at index " << idx << " = (" << j << ", "
                    << k << "), sub pixel offset = (" << suby << ", " << subx
                    << ")";
              }
          }
        }
    }
  }
  delete[] input;
  delete[] output;
  delete[] output2;
}
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

#if CONFIG_JNT_COMP
void AV1Convolve2DTest::RunCheckOutput2(convolve_2d_func test_impl) {
  const int w = 128, h = 128;
  const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
  int i, j, k, l, m;

  uint8_t *input = new uint8_t[h * w];

  int output_n = out_h * MAX_SB_SIZE;
  CONV_BUF_TYPE *output = new CONV_BUF_TYPE[output_n];
  CONV_BUF_TYPE *output2 = new CONV_BUF_TYPE[output_n];

  for (i = 0; i < h; ++i)
    for (j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand8();

  int hfilter, vfilter, subx, suby;
  for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
    for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL; ++vfilter) {
      InterpFilterParams filter_params_x =
          av1_get_interp_filter_params((InterpFilter)hfilter);
      InterpFilterParams filter_params_y =
          av1_get_interp_filter_params((InterpFilter)vfilter);
      const int do_average = rnd_.Rand8() & 1;
      ConvolveParams conv_params1 =
          get_conv_params_no_round(0, do_average, 0, output, MAX_SB_SIZE);
      ConvolveParams conv_params2 =
          get_conv_params_no_round(0, do_average, 0, output2, MAX_SB_SIZE);

      // Test special case where fwd and bck offsets are -1
Cheng Chen's avatar
Cheng Chen committed
143 144
      conv_params1.use_jnt_comp_avg = 0;
      conv_params2.use_jnt_comp_avg = 0;
145 146 147 148 149 150 151 152 153 154 155 156 157

      for (subx = 0; subx < 16; ++subx)
        for (suby = 0; suby < 16; ++suby) {
          // av1_convolve_2d is designed for accumulate two predicted blocks
          // for compound mode, so we set num_iter to two here.
          // A larger number may introduce overflow
          const int num_iters = 2;
          memset(output, 0, output_n * sizeof(*output));
          memset(output2, 0, output_n * sizeof(*output2));
          for (i = 0; i < num_iters; ++i) {
            // Choose random locations within the source block
            int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
            int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
158
            av1_jnt_convolve_2d_c(input + offset_r * w + offset_c, w, NULL,
159 160
                                  MAX_SB_SIZE, out_w, out_h, &filter_params_x,
                                  &filter_params_y, subx, suby, &conv_params1);
161
            test_impl(input + offset_r * w + offset_c, w, NULL, MAX_SB_SIZE,
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
                      out_w, out_h, &filter_params_x, &filter_params_y, subx,
                      suby, &conv_params2);

            for (j = 0; j < out_h; ++j)
              for (k = 0; k < out_w; ++k) {
                int idx = j * MAX_SB_SIZE + k;
                ASSERT_EQ(output[idx], output2[idx])
                    << "Mismatch at unit tests for av1_jnt_convolve_2d\n"
                    << "Pixel mismatch at index " << idx << " = (" << j << ", "
                    << k << "), sub pixel offset = (" << suby << ", " << subx
                    << ")";
              }
          }
        }

      // Test different combination of fwd and bck offset weights
      for (l = 0; l < 2; ++l) {
        for (m = 0; m < 4; ++m) {
Cheng Chen's avatar
Cheng Chen committed
180 181
          conv_params1.use_jnt_comp_avg = 1;
          conv_params2.use_jnt_comp_avg = 1;
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
          conv_params1.fwd_offset = quant_dist_lookup_table[l][m][0];
          conv_params1.bck_offset = quant_dist_lookup_table[l][m][1];
          conv_params2.fwd_offset = quant_dist_lookup_table[l][m][0];
          conv_params2.bck_offset = quant_dist_lookup_table[l][m][1];

          for (subx = 0; subx < 16; ++subx)
            for (suby = 0; suby < 16; ++suby) {
              // av1_convolve_2d is designed for accumulate two predicted blocks
              // for compound mode, so we set num_iter to two here.
              // A larger number may introduce overflow
              const int num_iters = 2;
              memset(output, 0, output_n * sizeof(*output));
              memset(output2, 0, output_n * sizeof(*output2));
              for (i = 0; i < num_iters; ++i) {
                // Choose random locations within the source block
                int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
                int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
199 200
                av1_jnt_convolve_2d_c(input + offset_r * w + offset_c, w, NULL,
                                      MAX_SB_SIZE, out_w, out_h,
201 202
                                      &filter_params_x, &filter_params_y, subx,
                                      suby, &conv_params1);
203 204 205
                test_impl(input + offset_r * w + offset_c, w, NULL, MAX_SB_SIZE,
                          out_w, out_h, &filter_params_x, &filter_params_y,
                          subx, suby, &conv_params2);
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226

                for (j = 0; j < out_h; ++j)
                  for (k = 0; k < out_w; ++k) {
                    int idx = j * MAX_SB_SIZE + k;
                    ASSERT_EQ(output[idx], output2[idx])
                        << "Mismatch at unit tests for av1_jnt_convolve_2d\n"
                        << "Pixel mismatch at index " << idx << " = (" << j
                        << ", " << k << "), sub pixel offset = (" << suby
                        << ", " << subx << ")";
                  }
              }
            }
        }
      }
    }
  }
  delete[] input;
  delete[] output;
  delete[] output2;
}
#endif  // CONFIG_JNT_COMP
David Barker's avatar
David Barker committed
227 228 229 230 231 232 233 234
}  // namespace AV1Convolve2D

#if CONFIG_HIGHBITDEPTH
namespace AV1HighbdConvolve2D {

::testing::internal::ParamGenerator<HighbdConvolve2DParam> BuildParams(
    highbd_convolve_2d_func filter) {
  const HighbdConvolve2DParam params[] = {
235 236 237 238 239 240 241 242
    make_tuple(4, 4, 8, filter),    make_tuple(8, 8, 8, filter),
    make_tuple(64, 64, 8, filter),  make_tuple(4, 16, 8, filter),
    make_tuple(32, 8, 8, filter),   make_tuple(4, 4, 10, filter),
    make_tuple(8, 8, 10, filter),   make_tuple(64, 64, 10, filter),
    make_tuple(4, 16, 10, filter),  make_tuple(32, 8, 10, filter),
    make_tuple(4, 4, 12, filter),   make_tuple(8, 8, 12, filter),
    make_tuple(64, 64, 12, filter), make_tuple(4, 16, 12, filter),
    make_tuple(32, 8, 12, filter),
David Barker's avatar
David Barker committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
  };
  return ::testing::ValuesIn(params);
}

AV1HighbdConvolve2DTest::~AV1HighbdConvolve2DTest() {}
void AV1HighbdConvolve2DTest::SetUp() {
  rnd_.Reset(ACMRandom::DeterministicSeed());
}

void AV1HighbdConvolve2DTest::TearDown() { libaom_test::ClearSystemState(); }

void AV1HighbdConvolve2DTest::RunCheckOutput(
    highbd_convolve_2d_func test_impl) {
  const int w = 128, h = 128;
  const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
258
  const int bd = GET_PARAM(2);
David Barker's avatar
David Barker committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
  int i, j, k;

  uint16_t *input = new uint16_t[h * w];

  int output_n = out_h * MAX_SB_SIZE;
  CONV_BUF_TYPE *output = new CONV_BUF_TYPE[output_n];
  CONV_BUF_TYPE *output2 = new CONV_BUF_TYPE[output_n];

  for (i = 0; i < h; ++i)
    for (j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);

  int hfilter, vfilter, subx, suby;
  for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
    for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL; ++vfilter) {
      InterpFilterParams filter_params_x =
          av1_get_interp_filter_params((InterpFilter)hfilter);
      InterpFilterParams filter_params_y =
          av1_get_interp_filter_params((InterpFilter)vfilter);
      ConvolveParams conv_params1 =
278
          get_conv_params_no_round(0, 0, 0, output, MAX_SB_SIZE);
David Barker's avatar
David Barker committed
279
      ConvolveParams conv_params2 =
280
          get_conv_params_no_round(0, 0, 0, output2, MAX_SB_SIZE);
David Barker's avatar
David Barker committed
281 282 283

      for (subx = 0; subx < 16; ++subx)
        for (suby = 0; suby < 16; ++suby) {
284 285 286 287 288 289
          // av1_convolve_2d is designed for accumulate two predicted blocks for
          // compound mode, so we set num_iter to two here.
          // A larger number may introduce overflow
          const int num_iters = 2;
          memset(output, 0, output_n * sizeof(*output));
          memset(output2, 0, output_n * sizeof(*output2));
David Barker's avatar
David Barker committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
          for (i = 0; i < num_iters; ++i) {
            // Choose random locations within the source block
            int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
            int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
            av1_highbd_convolve_2d_c(input + offset_r * w + offset_c, w, output,
                                     MAX_SB_SIZE, out_w, out_h,
                                     &filter_params_x, &filter_params_y, subx,
                                     suby, &conv_params1, bd);
            test_impl(input + offset_r * w + offset_c, w, output2, MAX_SB_SIZE,
                      out_w, out_h, &filter_params_x, &filter_params_y, subx,
                      suby, &conv_params2, bd);

            for (j = 0; j < out_h; ++j)
              for (k = 0; k < out_w; ++k) {
                int idx = j * MAX_SB_SIZE + k;
                ASSERT_EQ(output[idx], output2[idx])
                    << "Pixel mismatch at index " << idx << " = (" << j << ", "
                    << k << "), sub pixel offset = (" << suby << ", " << subx
                    << ")";
              }
          }
        }
    }
  }
  delete[] input;
  delete[] output;
  delete[] output2;
}
}  // namespace AV1HighbdConvolve2D
#endif  // CONFIG_HIGHBITDEPTH
}  // namespace libaom_test