av1_convolve_2d_test_util.cc 19 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 24

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

namespace libaom_test {

namespace AV1Convolve2D {

::testing::internal::ParamGenerator<Convolve2DParam> BuildParams(
25
    convolve_2d_func filter, int has_subx, int has_suby, int is_compound) {
David Barker's avatar
David Barker committed
26
  const Convolve2DParam params[] = {
27 28 29 30 31
    make_tuple(4, 4, filter, has_subx, has_suby, is_compound),
    make_tuple(8, 8, filter, has_subx, has_suby, is_compound),
    make_tuple(64, 64, filter, has_subx, has_suby, is_compound),
    make_tuple(4, 16, filter, has_subx, has_suby, is_compound),
    make_tuple(32, 8, filter, has_subx, has_suby, is_compound),
David Barker's avatar
David Barker committed
32 33 34 35 36 37 38 39 40 41 42 43 44
  };
  return ::testing::ValuesIn(params);
}

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;
45 46 47 48
  const int has_subx = GET_PARAM(3);
  const int has_suby = GET_PARAM(4);
  const int is_compound = GET_PARAM(5);
  (void)is_compound;
David Barker's avatar
David Barker committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

  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);
66
      const int do_average = rnd_.Rand8() & 1;
David Barker's avatar
David Barker committed
67
      ConvolveParams conv_params1 =
68
          get_conv_params_no_round(0, do_average, 0, output, MAX_SB_SIZE, 1);
David Barker's avatar
David Barker committed
69
      ConvolveParams conv_params2 =
70
          get_conv_params_no_round(0, do_average, 0, output2, MAX_SB_SIZE, 1);
David Barker's avatar
David Barker committed
71

72 73 74 75
      const int subx_range = has_subx ? 16 : 1;
      const int suby_range = has_suby ? 16 : 1;
      for (subx = 0; subx < subx_range; ++subx)
        for (suby = 0; suby < suby_range; ++suby) {
76 77 78 79 80 81
          // 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
82 83 84 85
          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);
86 87 88 89 90 91
            av1_convolve_2d_c(input + offset_r * w + offset_c, w, NULL, 0,
                              out_w, out_h, &filter_params_x, &filter_params_y,
                              subx, suby, &conv_params1);
            test_impl(input + offset_r * w + offset_c, w, NULL, 0, out_w, out_h,
                      &filter_params_x, &filter_params_y, subx, suby,
                      &conv_params2);
David Barker's avatar
David Barker committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

            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;
}
109 110

#if CONFIG_JNT_COMP
111 112 113 114 115 116 117 118
AV1JntConvolve2DTest::~AV1JntConvolve2DTest() {}
void AV1JntConvolve2DTest::SetUp() {
  rnd_.Reset(ACMRandom::DeterministicSeed());
}

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

void AV1JntConvolve2DTest::RunCheckOutput(convolve_2d_func test_impl) {
119 120 121
  const int w = 128, h = 128;
  const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
  int i, j, k, l, m;
122 123 124 125
  const int has_subx = GET_PARAM(3);
  const int has_suby = GET_PARAM(4);
  const int is_compound = GET_PARAM(5);
  (void)is_compound;
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144

  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 =
145
          get_conv_params_no_round(0, do_average, 0, output, MAX_SB_SIZE, 1);
146
      ConvolveParams conv_params2 =
147
          get_conv_params_no_round(0, do_average, 0, output2, MAX_SB_SIZE, 1);
148

149
      // Test special case where jnt_comp_avg is not used
Cheng Chen's avatar
Cheng Chen committed
150 151
      conv_params1.use_jnt_comp_avg = 0;
      conv_params2.use_jnt_comp_avg = 0;
152

153 154 155 156
      const int subx_range = has_subx ? 16 : 1;
      const int suby_range = has_suby ? 16 : 1;
      for (subx = 0; subx < subx_range; ++subx)
        for (suby = 0; suby < suby_range; ++suby) {
157 158 159 160 161 162 163 164 165 166
          // 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);
167 168
            av1_jnt_convolve_2d_c(input + offset_r * w + offset_c, w, NULL, 0,
                                  out_w, out_h, &filter_params_x,
169
                                  &filter_params_y, subx, suby, &conv_params1);
170 171 172
            test_impl(input + offset_r * w + offset_c, w, NULL, 0, out_w, out_h,
                      &filter_params_x, &filter_params_y, subx, suby,
                      &conv_params2);
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188

            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
189 190
          conv_params1.use_jnt_comp_avg = 1;
          conv_params2.use_jnt_comp_avg = 1;
191 192 193 194 195
          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];

196 197
          for (subx = 0; subx < subx_range; ++subx)
            for (suby = 0; suby < suby_range; ++suby) {
198 199 200 201 202 203 204 205 206 207
              // 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);
208
                av1_jnt_convolve_2d_c(input + offset_r * w + offset_c, w, NULL,
209 210 211 212 213 214
                                      0, out_w, out_h, &filter_params_x,
                                      &filter_params_y, subx, suby,
                                      &conv_params1);
                test_impl(input + offset_r * w + offset_c, w, NULL, 0, out_w,
                          out_h, &filter_params_x, &filter_params_y, subx, suby,
                          &conv_params2);
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235

                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
236 237 238 239 240 241 242 243
}  // namespace AV1Convolve2D

#if CONFIG_HIGHBITDEPTH
namespace AV1HighbdConvolve2D {

::testing::internal::ParamGenerator<HighbdConvolve2DParam> BuildParams(
    highbd_convolve_2d_func filter) {
  const HighbdConvolve2DParam params[] = {
244 245 246 247 248 249 250 251
    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
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
  };
  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);
267
  const int bd = GET_PARAM(2);
David Barker's avatar
David Barker committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
  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 =
287
          get_conv_params_no_round(0, 0, 0, output, MAX_SB_SIZE, 1);
David Barker's avatar
David Barker committed
288
      ConvolveParams conv_params2 =
289
          get_conv_params_no_round(0, 0, 0, output2, MAX_SB_SIZE, 1);
David Barker's avatar
David Barker committed
290 291 292

      for (subx = 0; subx < 16; ++subx)
        for (suby = 0; suby < 16; ++suby) {
293 294 295 296 297 298
          // 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
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
          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;
}
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
#if CONFIG_JNT_COMP
AV1HighbdJntConvolve2DTest::~AV1HighbdJntConvolve2DTest() {}
void AV1HighbdJntConvolve2DTest::SetUp() {
  rnd_.Reset(ACMRandom::DeterministicSeed());
}

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

void AV1HighbdJntConvolve2DTest::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);
  const int bd = GET_PARAM(2);
  int i, j, k, l, m;

  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 =
Cheng Chen's avatar
Fix bug  
Cheng Chen committed
359
          get_conv_params_no_round(0, 0, 0, output, MAX_SB_SIZE, 1);
360
      ConvolveParams conv_params2 =
Cheng Chen's avatar
Fix bug  
Cheng Chen committed
361
          get_conv_params_no_round(0, 0, 0, output2, MAX_SB_SIZE, 1);
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447

      // Test special case where jnt_comp_avg is not used
      conv_params1.use_jnt_comp_avg = 0;
      conv_params2.use_jnt_comp_avg = 0;

      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);
            av1_highbd_jnt_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
                    << ")";
              }
          }
        }

      // Test different combination of fwd and bck offset weights
      for (l = 0; l < 2; ++l) {
        for (m = 0; m < 4; ++m) {
          conv_params1.use_jnt_comp_avg = 1;
          conv_params2.use_jnt_comp_avg = 1;
          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);
                av1_highbd_jnt_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])
                        << "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
448 449 450
}  // namespace AV1HighbdConvolve2D
#endif  // CONFIG_HIGHBITDEPTH
}  // namespace libaom_test