tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

blend_a64_mask_1d_test.cc (11508B)


      1 /*
      2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
      3 *
      4 * This source code is subject to the terms of the BSD 2 Clause License and
      5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
      6 * was not distributed with this source code in the LICENSE file, you can
      7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
      8 * Media Patent License 1.0 was not distributed with this source code in the
      9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
     10 */
     11 
     12 #include <math.h>
     13 #include <stdlib.h>
     14 #include <string.h>
     15 
     16 #include "gtest/gtest.h"
     17 #include "test/register_state_check.h"
     18 #include "test/function_equivalence_test.h"
     19 
     20 #include "config/aom_config.h"
     21 #include "config/aom_dsp_rtcd.h"
     22 #include "config/av1_rtcd.h"
     23 
     24 #include "aom/aom_integer.h"
     25 
     26 #include "av1/common/enums.h"
     27 
     28 #include "aom_dsp/blend.h"
     29 
     30 using libaom_test::FunctionEquivalenceTest;
     31 
     32 namespace {
     33 
     34 template <typename F, typename T>
     35 class BlendA64Mask1DTest : public FunctionEquivalenceTest<F> {
     36 public:
     37  static const int kIterations = 10000;
     38  static const int kMaxWidth = MAX_SB_SIZE * 5;  // * 5 to cover longer strides
     39  static const int kMaxHeight = MAX_SB_SIZE;
     40  static const int kBufSize = kMaxWidth * kMaxHeight;
     41  static const int kMaxMaskWidth = 2 * MAX_SB_SIZE;
     42  static const int kMaxMaskSize = kMaxMaskWidth;
     43 
     44  ~BlendA64Mask1DTest() override = default;
     45 
     46  virtual void Execute(const T *p_src0, const T *p_src1) = 0;
     47 
     48  void Common(int block_size) {
     49    w_ = block_size_wide[block_size];
     50    h_ = block_size_high[block_size];
     51 
     52    dst_offset_ = this->rng_(33);
     53    dst_stride_ = this->rng_(kMaxWidth + 1 - w_) + w_;
     54 
     55    src0_offset_ = this->rng_(33);
     56    src0_stride_ = this->rng_(kMaxWidth + 1 - w_) + w_;
     57 
     58    src1_offset_ = this->rng_(33);
     59    src1_stride_ = this->rng_(kMaxWidth + 1 - w_) + w_;
     60 
     61    T *p_src0;
     62    T *p_src1;
     63 
     64    switch (this->rng_(3)) {
     65      case 0:  // Separate sources
     66        p_src0 = src0_;
     67        p_src1 = src1_;
     68        break;
     69      case 1:  // src0 == dst
     70        p_src0 = dst_tst_;
     71        src0_stride_ = dst_stride_;
     72        src0_offset_ = dst_offset_;
     73        p_src1 = src1_;
     74        break;
     75      case 2:  // src1 == dst
     76        p_src0 = src0_;
     77        p_src1 = dst_tst_;
     78        src1_stride_ = dst_stride_;
     79        src1_offset_ = dst_offset_;
     80        break;
     81      default: FAIL();
     82    }
     83 
     84    Execute(p_src0, p_src1);
     85 
     86    for (int r = 0; r < h_; ++r) {
     87      for (int c = 0; c < w_; ++c) {
     88        ASSERT_EQ(dst_ref_[dst_offset_ + r * dst_stride_ + c],
     89                  dst_tst_[dst_offset_ + r * dst_stride_ + c]);
     90      }
     91    }
     92  }
     93 
     94  T dst_ref_[kBufSize];
     95  T dst_tst_[kBufSize];
     96  uint32_t dst_stride_;
     97  uint32_t dst_offset_;
     98 
     99  T src0_[kBufSize];
    100  uint32_t src0_stride_;
    101  uint32_t src0_offset_;
    102 
    103  T src1_[kBufSize];
    104  uint32_t src1_stride_;
    105  uint32_t src1_offset_;
    106 
    107  uint8_t mask_[kMaxMaskSize];
    108 
    109  int w_;
    110  int h_;
    111 };
    112 
    113 //////////////////////////////////////////////////////////////////////////////
    114 // 8 bit version
    115 //////////////////////////////////////////////////////////////////////////////
    116 
    117 using F8B = void (*)(uint8_t *dst, uint32_t dst_stride, const uint8_t *src0,
    118                     uint32_t src0_stride, const uint8_t *src1,
    119                     uint32_t src1_stride, const uint8_t *mask, int w, int h);
    120 using TestFuncs = libaom_test::FuncParam<F8B>;
    121 
    122 class BlendA64Mask1DTest8B : public BlendA64Mask1DTest<F8B, uint8_t> {
    123 protected:
    124  void Execute(const uint8_t *p_src0, const uint8_t *p_src1) override {
    125    params_.ref_func(dst_ref_ + dst_offset_, dst_stride_, p_src0 + src0_offset_,
    126                     src0_stride_, p_src1 + src1_offset_, src1_stride_, mask_,
    127                     w_, h_);
    128    API_REGISTER_STATE_CHECK(params_.tst_func(
    129        dst_tst_ + dst_offset_, dst_stride_, p_src0 + src0_offset_,
    130        src0_stride_, p_src1 + src1_offset_, src1_stride_, mask_, w_, h_));
    131  }
    132 };
    133 
    134 TEST_P(BlendA64Mask1DTest8B, RandomValues) {
    135  for (int bsize = 0; bsize < BLOCK_SIZES_ALL; ++bsize) {
    136    for (int i = 0; i < kBufSize; ++i) {
    137      dst_ref_[i] = rng_.Rand8();
    138      dst_tst_[i] = rng_.Rand8();
    139 
    140      src0_[i] = rng_.Rand8();
    141      src1_[i] = rng_.Rand8();
    142    }
    143 
    144    for (int i = 0; i < kMaxMaskSize; ++i)
    145      mask_[i] = rng_(AOM_BLEND_A64_MAX_ALPHA + 1);
    146 
    147    Common(bsize);
    148  }
    149 }
    150 
    151 TEST_P(BlendA64Mask1DTest8B, ExtremeValues) {
    152  for (int i = 0; i < kBufSize; ++i) {
    153    dst_ref_[i] = rng_(2) + 254;
    154    dst_tst_[i] = rng_(2) + 254;
    155    src0_[i] = rng_(2) + 254;
    156    src1_[i] = rng_(2) + 254;
    157  }
    158 
    159  for (int i = 0; i < kMaxMaskSize; ++i)
    160    mask_[i] = rng_(2) + AOM_BLEND_A64_MAX_ALPHA - 1;
    161 
    162  for (int bsize = 0; bsize < BLOCK_SIZES_ALL; ++bsize) {
    163    Common(bsize);
    164  }
    165 }
    166 
    167 static void blend_a64_hmask_ref(uint8_t *dst, uint32_t dst_stride,
    168                                const uint8_t *src0, uint32_t src0_stride,
    169                                const uint8_t *src1, uint32_t src1_stride,
    170                                const uint8_t *mask, int w, int h) {
    171  uint8_t mask2d[BlendA64Mask1DTest8B::kMaxMaskSize]
    172                [BlendA64Mask1DTest8B::kMaxMaskSize];
    173 
    174  for (int row = 0; row < h; ++row)
    175    for (int col = 0; col < w; ++col) mask2d[row][col] = mask[col];
    176 
    177  aom_blend_a64_mask_c(dst, dst_stride, src0, src0_stride, src1, src1_stride,
    178                       &mask2d[0][0], BlendA64Mask1DTest8B::kMaxMaskSize, w, h,
    179                       0, 0);
    180 }
    181 
    182 static void blend_a64_vmask_ref(uint8_t *dst, uint32_t dst_stride,
    183                                const uint8_t *src0, uint32_t src0_stride,
    184                                const uint8_t *src1, uint32_t src1_stride,
    185                                const uint8_t *mask, int w, int h) {
    186  uint8_t mask2d[BlendA64Mask1DTest8B::kMaxMaskSize]
    187                [BlendA64Mask1DTest8B::kMaxMaskSize];
    188 
    189  for (int row = 0; row < h; ++row)
    190    for (int col = 0; col < w; ++col) mask2d[row][col] = mask[row];
    191 
    192  aom_blend_a64_mask_c(dst, dst_stride, src0, src0_stride, src1, src1_stride,
    193                       &mask2d[0][0], BlendA64Mask1DTest8B::kMaxMaskSize, w, h,
    194                       0, 0);
    195 }
    196 
    197 INSTANTIATE_TEST_SUITE_P(
    198    C, BlendA64Mask1DTest8B,
    199    ::testing::Values(TestFuncs(blend_a64_hmask_ref, aom_blend_a64_hmask_c),
    200                      TestFuncs(blend_a64_vmask_ref, aom_blend_a64_vmask_c)));
    201 
    202 #if HAVE_SSE4_1
    203 INSTANTIATE_TEST_SUITE_P(
    204    SSE4_1, BlendA64Mask1DTest8B,
    205    ::testing::Values(
    206        TestFuncs(blend_a64_hmask_ref, aom_blend_a64_hmask_sse4_1),
    207        TestFuncs(blend_a64_vmask_ref, aom_blend_a64_vmask_sse4_1)));
    208 #endif  // HAVE_SSE4_1
    209 
    210 #if HAVE_NEON
    211 INSTANTIATE_TEST_SUITE_P(
    212    NEON, BlendA64Mask1DTest8B,
    213    ::testing::Values(TestFuncs(blend_a64_hmask_ref, aom_blend_a64_hmask_neon),
    214                      TestFuncs(blend_a64_vmask_ref,
    215                                aom_blend_a64_vmask_neon)));
    216 #endif  // HAVE_NEON
    217 
    218 //////////////////////////////////////////////////////////////////////////////
    219 // High bit-depth version
    220 //////////////////////////////////////////////////////////////////////////////
    221 #if CONFIG_AV1_HIGHBITDEPTH
    222 using FHBD = void (*)(uint8_t *dst, uint32_t dst_stride, const uint8_t *src0,
    223                      uint32_t src0_stride, const uint8_t *src1,
    224                      uint32_t src1_stride, const uint8_t *mask, int w, int h,
    225                      int bd);
    226 using TestFuncsHBD = libaom_test::FuncParam<FHBD>;
    227 
    228 class BlendA64Mask1DTestHBD : public BlendA64Mask1DTest<FHBD, uint16_t> {
    229 protected:
    230  void Execute(const uint16_t *p_src0, const uint16_t *p_src1) override {
    231    params_.ref_func(CONVERT_TO_BYTEPTR(dst_ref_ + dst_offset_), dst_stride_,
    232                     CONVERT_TO_BYTEPTR(p_src0 + src0_offset_), src0_stride_,
    233                     CONVERT_TO_BYTEPTR(p_src1 + src1_offset_), src1_stride_,
    234                     mask_, w_, h_, bit_depth_);
    235    API_REGISTER_STATE_CHECK(params_.tst_func(
    236        CONVERT_TO_BYTEPTR(dst_tst_ + dst_offset_), dst_stride_,
    237        CONVERT_TO_BYTEPTR(p_src0 + src0_offset_), src0_stride_,
    238        CONVERT_TO_BYTEPTR(p_src1 + src1_offset_), src1_stride_, mask_, w_, h_,
    239        bit_depth_));
    240  }
    241 
    242  int bit_depth_;
    243 };
    244 
    245 TEST_P(BlendA64Mask1DTestHBD, RandomValues) {
    246  for (bit_depth_ = 8; bit_depth_ <= 12; bit_depth_ += 2) {
    247    for (int bsize = 0; bsize < BLOCK_SIZES_ALL; ++bsize) {
    248      const int hi = 1 << bit_depth_;
    249 
    250      for (int i = 0; i < kBufSize; ++i) {
    251        dst_ref_[i] = rng_(hi);
    252        dst_tst_[i] = rng_(hi);
    253        src0_[i] = rng_(hi);
    254        src1_[i] = rng_(hi);
    255      }
    256 
    257      for (int i = 0; i < kMaxMaskSize; ++i)
    258        mask_[i] = rng_(AOM_BLEND_A64_MAX_ALPHA + 1);
    259 
    260      Common(bsize);
    261    }
    262  }
    263 }
    264 
    265 TEST_P(BlendA64Mask1DTestHBD, ExtremeValues) {
    266  for (bit_depth_ = 8; bit_depth_ <= 12; bit_depth_ += 2) {
    267    const int hi = 1 << bit_depth_;
    268    const int lo = hi - 2;
    269 
    270    for (int i = 0; i < kBufSize; ++i) {
    271      dst_ref_[i] = rng_(hi - lo) + lo;
    272      dst_tst_[i] = rng_(hi - lo) + lo;
    273      src0_[i] = rng_(hi - lo) + lo;
    274      src1_[i] = rng_(hi - lo) + lo;
    275    }
    276 
    277    for (int i = 0; i < kMaxMaskSize; ++i)
    278      mask_[i] = rng_(2) + AOM_BLEND_A64_MAX_ALPHA - 1;
    279 
    280    for (int bsize = 0; bsize < BLOCK_SIZES_ALL; ++bsize) {
    281      Common(bsize);
    282    }
    283  }
    284 }
    285 
    286 static void highbd_blend_a64_hmask_ref(
    287    uint8_t *dst, uint32_t dst_stride, const uint8_t *src0,
    288    uint32_t src0_stride, const uint8_t *src1, uint32_t src1_stride,
    289    const uint8_t *mask, int w, int h, int bd) {
    290  uint8_t mask2d[BlendA64Mask1DTestHBD::kMaxMaskSize]
    291                [BlendA64Mask1DTestHBD::kMaxMaskSize];
    292 
    293  for (int row = 0; row < h; ++row)
    294    for (int col = 0; col < w; ++col) mask2d[row][col] = mask[col];
    295 
    296  aom_highbd_blend_a64_mask_c(
    297      dst, dst_stride, src0, src0_stride, src1, src1_stride, &mask2d[0][0],
    298      BlendA64Mask1DTestHBD::kMaxMaskSize, w, h, 0, 0, bd);
    299 }
    300 
    301 static void highbd_blend_a64_vmask_ref(
    302    uint8_t *dst, uint32_t dst_stride, const uint8_t *src0,
    303    uint32_t src0_stride, const uint8_t *src1, uint32_t src1_stride,
    304    const uint8_t *mask, int w, int h, int bd) {
    305  uint8_t mask2d[BlendA64Mask1DTestHBD::kMaxMaskSize]
    306                [BlendA64Mask1DTestHBD::kMaxMaskSize];
    307 
    308  for (int row = 0; row < h; ++row)
    309    for (int col = 0; col < w; ++col) mask2d[row][col] = mask[row];
    310 
    311  aom_highbd_blend_a64_mask_c(
    312      dst, dst_stride, src0, src0_stride, src1, src1_stride, &mask2d[0][0],
    313      BlendA64Mask1DTestHBD::kMaxMaskSize, w, h, 0, 0, bd);
    314 }
    315 
    316 INSTANTIATE_TEST_SUITE_P(
    317    C, BlendA64Mask1DTestHBD,
    318    ::testing::Values(TestFuncsHBD(highbd_blend_a64_hmask_ref,
    319                                   aom_highbd_blend_a64_hmask_c),
    320                      TestFuncsHBD(highbd_blend_a64_vmask_ref,
    321                                   aom_highbd_blend_a64_vmask_c)));
    322 
    323 #if HAVE_SSE4_1
    324 INSTANTIATE_TEST_SUITE_P(
    325    SSE4_1, BlendA64Mask1DTestHBD,
    326    ::testing::Values(TestFuncsHBD(highbd_blend_a64_hmask_ref,
    327                                   aom_highbd_blend_a64_hmask_sse4_1),
    328                      TestFuncsHBD(highbd_blend_a64_vmask_ref,
    329                                   aom_highbd_blend_a64_vmask_sse4_1)));
    330 #endif  // HAVE_SSE4_1
    331 
    332 #if HAVE_NEON
    333 INSTANTIATE_TEST_SUITE_P(
    334    NEON, BlendA64Mask1DTestHBD,
    335    ::testing::Values(TestFuncsHBD(highbd_blend_a64_hmask_ref,
    336                                   aom_highbd_blend_a64_hmask_neon),
    337                      TestFuncsHBD(highbd_blend_a64_vmask_ref,
    338                                   aom_highbd_blend_a64_vmask_neon)));
    339 #endif  // HAVE_NEON
    340 
    341 #endif  // CONFIG_AV1_HIGHBITDEPTH
    342 }  // namespace