1472 lines · 54.1 KB · C++
RawDownload
/* *  Copyright (c) 2010 The WebM project authors. All Rights Reserved. * *  Use of this source code is governed by a BSD-style license *  that can be found in the LICENSE file in the root of the source *  tree. An additional intellectual property rights grant can be found *  in the file PATENTS.  All contributing project authors may *  be found in the AUTHORS file in the root of the source tree. */ #include <string.h>#include <tuple> #include "third_party/googletest/src/include/gtest/gtest.h" #include "./vp9_rtcd.h"#include "./vpx_config.h"#include "./vpx_dsp_rtcd.h"#include "test/acm_random.h"#include "test/clear_system_state.h"#include "test/register_state_check.h"#include "test/util.h"#include "vp9/common/vp9_common.h"#include "vp9/common/vp9_filter.h"#include "vpx_dsp/vpx_dsp_common.h"#include "vpx_dsp/vpx_filter.h"#include "vpx_mem/vpx_mem.h"#include "vpx_ports/mem.h"#include "vpx_ports/vpx_timer.h" namespace { static const unsigned int kMaxDimension = 64; typedef void (*ConvolveFunc)(const uint8_t *src, ptrdiff_t src_stride,                             uint8_t *dst, ptrdiff_t dst_stride,                             const InterpKernel *filter, int x0_q4,                             int x_step_q4, int y0_q4, int y_step_q4, int w,                             int h); typedef void (*WrapperFilterBlock2d8Func)(    const uint8_t *src_ptr, const unsigned int src_stride,    const int16_t *hfilter, const int16_t *vfilter, uint8_t *dst_ptr,    unsigned int dst_stride, unsigned int output_width,    unsigned int output_height, int use_highbd); struct ConvolveFunctions {  ConvolveFunctions(ConvolveFunc copy, ConvolveFunc avg, ConvolveFunc h8,                    ConvolveFunc h8_avg, ConvolveFunc v8, ConvolveFunc v8_avg,                    ConvolveFunc hv8, ConvolveFunc hv8_avg, ConvolveFunc sh8,                    ConvolveFunc sh8_avg, ConvolveFunc sv8,                    ConvolveFunc sv8_avg, ConvolveFunc shv8,                    ConvolveFunc shv8_avg, int bd)      : use_highbd_(bd) {    copy_[0] = copy;    copy_[1] = avg;    h8_[0] = h8;    h8_[1] = h8_avg;    v8_[0] = v8;    v8_[1] = v8_avg;    hv8_[0] = hv8;    hv8_[1] = hv8_avg;    sh8_[0] = sh8;    sh8_[1] = sh8_avg;    sv8_[0] = sv8;    sv8_[1] = sv8_avg;    shv8_[0] = shv8;    shv8_[1] = shv8_avg;  }   ConvolveFunc copy_[2];  ConvolveFunc h8_[2];  ConvolveFunc v8_[2];  ConvolveFunc hv8_[2];  ConvolveFunc sh8_[2];   // scaled horiz  ConvolveFunc sv8_[2];   // scaled vert  ConvolveFunc shv8_[2];  // scaled horiz/vert  int use_highbd_;  // 0 if high bitdepth not used, else the actual bit depth.}; typedef std::tuple<int, int, const ConvolveFunctions *> ConvolveParam; #define ALL_SIZES(convolve_fn)                                            \  make_tuple(4, 4, &convolve_fn), make_tuple(8, 4, &convolve_fn),         \      make_tuple(4, 8, &convolve_fn), make_tuple(8, 8, &convolve_fn),     \      make_tuple(16, 8, &convolve_fn), make_tuple(8, 16, &convolve_fn),   \      make_tuple(16, 16, &convolve_fn), make_tuple(32, 16, &convolve_fn), \      make_tuple(16, 32, &convolve_fn), make_tuple(32, 32, &convolve_fn), \      make_tuple(64, 32, &convolve_fn), make_tuple(32, 64, &convolve_fn), \      make_tuple(64, 64, &convolve_fn) // Reference 8-tap subpixel filter, slightly modified to fit into this test.#define VP9_FILTER_WEIGHT 128#define VP9_FILTER_SHIFT 7uint8_t clip_pixel(int x) { return x < 0 ? 0 : x > 255 ? 255 : x; } void filter_block2d_8_c(const uint8_t *src_ptr, const unsigned int src_stride,                        const int16_t *hfilter, const int16_t *vfilter,                        uint8_t *dst_ptr, unsigned int dst_stride,                        unsigned int output_width, unsigned int output_height) {  // Between passes, we use an intermediate buffer whose height is extended to  // have enough horizontally filtered values as input for the vertical pass.  // This buffer is allocated to be big enough for the largest block type we  // support.  const int kInterp_Extend = 4;  const unsigned int intermediate_height =      (kInterp_Extend - 1) + output_height + kInterp_Extend;  unsigned int i, j;   // Size of intermediate_buffer is max_intermediate_height * filter_max_width,  // where max_intermediate_height = (kInterp_Extend - 1) + filter_max_height  //                                 + kInterp_Extend  //                               = 3 + 16 + 4  //                               = 23  // and filter_max_width          = 16  //  uint8_t intermediate_buffer[71 * kMaxDimension];  vp9_zero(intermediate_buffer);  const int intermediate_next_stride =      1 - static_cast<int>(intermediate_height * output_width);   // Horizontal pass (src -> transposed intermediate).  uint8_t *output_ptr = intermediate_buffer;  const int src_next_row_stride = src_stride - output_width;  src_ptr -= (kInterp_Extend - 1) * src_stride + (kInterp_Extend - 1);  for (i = 0; i < intermediate_height; ++i) {    for (j = 0; j < output_width; ++j) {      // Apply filter...      const int temp = (src_ptr[0] * hfilter[0]) + (src_ptr[1] * hfilter[1]) +                       (src_ptr[2] * hfilter[2]) + (src_ptr[3] * hfilter[3]) +                       (src_ptr[4] * hfilter[4]) + (src_ptr[5] * hfilter[5]) +                       (src_ptr[6] * hfilter[6]) + (src_ptr[7] * hfilter[7]) +                       (VP9_FILTER_WEIGHT >> 1);  // Rounding       // Normalize back to 0-255...      *output_ptr = clip_pixel(temp >> VP9_FILTER_SHIFT);      ++src_ptr;      output_ptr += intermediate_height;    }    src_ptr += src_next_row_stride;    output_ptr += intermediate_next_stride;  }   // Vertical pass (transposed intermediate -> dst).  src_ptr = intermediate_buffer;  const int dst_next_row_stride = dst_stride - output_width;  for (i = 0; i < output_height; ++i) {    for (j = 0; j < output_width; ++j) {      // Apply filter...      const int temp = (src_ptr[0] * vfilter[0]) + (src_ptr[1] * vfilter[1]) +                       (src_ptr[2] * vfilter[2]) + (src_ptr[3] * vfilter[3]) +                       (src_ptr[4] * vfilter[4]) + (src_ptr[5] * vfilter[5]) +                       (src_ptr[6] * vfilter[6]) + (src_ptr[7] * vfilter[7]) +                       (VP9_FILTER_WEIGHT >> 1);  // Rounding       // Normalize back to 0-255...      *dst_ptr++ = clip_pixel(temp >> VP9_FILTER_SHIFT);      src_ptr += intermediate_height;    }    src_ptr += intermediate_next_stride;    dst_ptr += dst_next_row_stride;  }} void block2d_average_c(uint8_t *src, unsigned int src_stride,                       uint8_t *output_ptr, unsigned int output_stride,                       unsigned int output_width, unsigned int output_height) {  unsigned int i, j;  for (i = 0; i < output_height; ++i) {    for (j = 0; j < output_width; ++j) {      output_ptr[j] = (output_ptr[j] + src[i * src_stride + j] + 1) >> 1;    }    output_ptr += output_stride;  }} void filter_average_block2d_8_c(const uint8_t *src_ptr,                                const unsigned int src_stride,                                const int16_t *hfilter, const int16_t *vfilter,                                uint8_t *dst_ptr, unsigned int dst_stride,                                unsigned int output_width,                                unsigned int output_height) {  uint8_t tmp[kMaxDimension * kMaxDimension];   assert(output_width <= kMaxDimension);  assert(output_height <= kMaxDimension);  filter_block2d_8_c(src_ptr, src_stride, hfilter, vfilter, tmp, 64,                     output_width, output_height);  block2d_average_c(tmp, 64, dst_ptr, dst_stride, output_width, output_height);} #if CONFIG_VP9_HIGHBITDEPTHvoid highbd_filter_block2d_8_c(const uint16_t *src_ptr,                               const unsigned int src_stride,                               const int16_t *hfilter, const int16_t *vfilter,                               uint16_t *dst_ptr, unsigned int dst_stride,                               unsigned int output_width,                               unsigned int output_height, int bd) {  // Between passes, we use an intermediate buffer whose height is extended to  // have enough horizontally filtered values as input for the vertical pass.  // This buffer is allocated to be big enough for the largest block type we  // support.  const int kInterp_Extend = 4;  const unsigned int intermediate_height =      (kInterp_Extend - 1) + output_height + kInterp_Extend;   /* Size of intermediate_buffer is max_intermediate_height * filter_max_width,   * where max_intermediate_height = (kInterp_Extend - 1) + filter_max_height   *                                 + kInterp_Extend   *                               = 3 + 16 + 4   *                               = 23   * and filter_max_width = 16   */  uint16_t intermediate_buffer[71 * kMaxDimension];  const int intermediate_next_stride =      1 - static_cast<int>(intermediate_height * output_width);   vp9_zero(intermediate_buffer);   // Horizontal pass (src -> transposed intermediate).  {    uint16_t *output_ptr = intermediate_buffer;    const int src_next_row_stride = src_stride - output_width;    unsigned int i, j;    src_ptr -= (kInterp_Extend - 1) * src_stride + (kInterp_Extend - 1);    for (i = 0; i < intermediate_height; ++i) {      for (j = 0; j < output_width; ++j) {        // Apply filter...        const int temp = (src_ptr[0] * hfilter[0]) + (src_ptr[1] * hfilter[1]) +                         (src_ptr[2] * hfilter[2]) + (src_ptr[3] * hfilter[3]) +                         (src_ptr[4] * hfilter[4]) + (src_ptr[5] * hfilter[5]) +                         (src_ptr[6] * hfilter[6]) + (src_ptr[7] * hfilter[7]) +                         (VP9_FILTER_WEIGHT >> 1);  // Rounding         // Normalize back to 0-255...        *output_ptr = clip_pixel_highbd(temp >> VP9_FILTER_SHIFT, bd);        ++src_ptr;        output_ptr += intermediate_height;      }      src_ptr += src_next_row_stride;      output_ptr += intermediate_next_stride;    }  }   // Vertical pass (transposed intermediate -> dst).  {    uint16_t *src_ptr = intermediate_buffer;    const int dst_next_row_stride = dst_stride - output_width;    unsigned int i, j;    for (i = 0; i < output_height; ++i) {      for (j = 0; j < output_width; ++j) {        // Apply filter...        const int temp = (src_ptr[0] * vfilter[0]) + (src_ptr[1] * vfilter[1]) +                         (src_ptr[2] * vfilter[2]) + (src_ptr[3] * vfilter[3]) +                         (src_ptr[4] * vfilter[4]) + (src_ptr[5] * vfilter[5]) +                         (src_ptr[6] * vfilter[6]) + (src_ptr[7] * vfilter[7]) +                         (VP9_FILTER_WEIGHT >> 1);  // Rounding         // Normalize back to 0-255...        *dst_ptr++ = clip_pixel_highbd(temp >> VP9_FILTER_SHIFT, bd);        src_ptr += intermediate_height;      }      src_ptr += intermediate_next_stride;      dst_ptr += dst_next_row_stride;    }  }} void highbd_block2d_average_c(uint16_t *src, unsigned int src_stride,                              uint16_t *output_ptr, unsigned int output_stride,                              unsigned int output_width,                              unsigned int output_height) {  unsigned int i, j;  for (i = 0; i < output_height; ++i) {    for (j = 0; j < output_width; ++j) {      output_ptr[j] = (output_ptr[j] + src[i * src_stride + j] + 1) >> 1;    }    output_ptr += output_stride;  }} void highbd_filter_average_block2d_8_c(    const uint16_t *src_ptr, const unsigned int src_stride,    const int16_t *hfilter, const int16_t *vfilter, uint16_t *dst_ptr,    unsigned int dst_stride, unsigned int output_width,    unsigned int output_height, int bd) {  uint16_t tmp[kMaxDimension * kMaxDimension];   assert(output_width <= kMaxDimension);  assert(output_height <= kMaxDimension);  highbd_filter_block2d_8_c(src_ptr, src_stride, hfilter, vfilter, tmp, 64,                            output_width, output_height, bd);  highbd_block2d_average_c(tmp, 64, dst_ptr, dst_stride, output_width,                           output_height);}#endif  // CONFIG_VP9_HIGHBITDEPTH void wrapper_filter_average_block2d_8_c(    const uint8_t *src_ptr, const unsigned int src_stride,    const int16_t *hfilter, const int16_t *vfilter, uint8_t *dst_ptr,    unsigned int dst_stride, unsigned int output_width,    unsigned int output_height, int use_highbd) {#if CONFIG_VP9_HIGHBITDEPTH  if (use_highbd == 0) {    filter_average_block2d_8_c(src_ptr, src_stride, hfilter, vfilter, dst_ptr,                               dst_stride, output_width, output_height);  } else {    highbd_filter_average_block2d_8_c(CAST_TO_SHORTPTR(src_ptr), src_stride,                                      hfilter, vfilter,                                      CAST_TO_SHORTPTR(dst_ptr), dst_stride,                                      output_width, output_height, use_highbd);  }#else  ASSERT_EQ(0, use_highbd);  filter_average_block2d_8_c(src_ptr, src_stride, hfilter, vfilter, dst_ptr,                             dst_stride, output_width, output_height);#endif} void wrapper_filter_block2d_8_c(const uint8_t *src_ptr,                                const unsigned int src_stride,                                const int16_t *hfilter, const int16_t *vfilter,                                uint8_t *dst_ptr, unsigned int dst_stride,                                unsigned int output_width,                                unsigned int output_height, int use_highbd) {#if CONFIG_VP9_HIGHBITDEPTH  if (use_highbd == 0) {    filter_block2d_8_c(src_ptr, src_stride, hfilter, vfilter, dst_ptr,                       dst_stride, output_width, output_height);  } else {    highbd_filter_block2d_8_c(CAST_TO_SHORTPTR(src_ptr), src_stride, hfilter,                              vfilter, CAST_TO_SHORTPTR(dst_ptr), dst_stride,                              output_width, output_height, use_highbd);  }#else  ASSERT_EQ(0, use_highbd);  filter_block2d_8_c(src_ptr, src_stride, hfilter, vfilter, dst_ptr, dst_stride,                     output_width, output_height);#endif} class ConvolveTest : public ::testing::TestWithParam<ConvolveParam> { public:  static void SetUpTestCase() {    // Force input_ to be unaligned, output to be 16 byte aligned.    input_ = reinterpret_cast<uint8_t *>(                 vpx_memalign(kDataAlignment, kInputBufferSize + 1)) +             1;    output_ = reinterpret_cast<uint8_t *>(        vpx_memalign(kDataAlignment, kOutputBufferSize));    output_ref_ = reinterpret_cast<uint8_t *>(        vpx_memalign(kDataAlignment, kOutputBufferSize));#if CONFIG_VP9_HIGHBITDEPTH    input16_ = reinterpret_cast<uint16_t *>(vpx_memalign(                   kDataAlignment, (kInputBufferSize + 1) * sizeof(uint16_t))) +               1;    output16_ = reinterpret_cast<uint16_t *>(        vpx_memalign(kDataAlignment, (kOutputBufferSize) * sizeof(uint16_t)));    output16_ref_ = reinterpret_cast<uint16_t *>(        vpx_memalign(kDataAlignment, (kOutputBufferSize) * sizeof(uint16_t)));#endif  }   virtual void TearDown() { libvpx_test::ClearSystemState(); }   static void TearDownTestCase() {    vpx_free(input_ - 1);    input_ = NULL;    vpx_free(output_);    output_ = NULL;    vpx_free(output_ref_);    output_ref_ = NULL;#if CONFIG_VP9_HIGHBITDEPTH    vpx_free(input16_ - 1);    input16_ = NULL;    vpx_free(output16_);    output16_ = NULL;    vpx_free(output16_ref_);    output16_ref_ = NULL;#endif  }  protected:  static const int kDataAlignment = 16;  static const int kOuterBlockSize = 256;  static const int kInputStride = kOuterBlockSize;  static const int kOutputStride = kOuterBlockSize;  static const int kInputBufferSize = kOuterBlockSize * kOuterBlockSize;  static const int kOutputBufferSize = kOuterBlockSize * kOuterBlockSize;   int Width() const { return GET_PARAM(0); }  int Height() const { return GET_PARAM(1); }  int BorderLeft() const {    const int center = (kOuterBlockSize - Width()) / 2;    return (center + (kDataAlignment - 1)) & ~(kDataAlignment - 1);  }  int BorderTop() const { return (kOuterBlockSize - Height()) / 2; }   bool IsIndexInBorder(int i) {    return (i < BorderTop() * kOuterBlockSize ||            i >= (BorderTop() + Height()) * kOuterBlockSize ||            i % kOuterBlockSize < BorderLeft() ||            i % kOuterBlockSize >= (BorderLeft() + Width()));  }   virtual void SetUp() {    UUT_ = GET_PARAM(2);#if CONFIG_VP9_HIGHBITDEPTH    if (UUT_->use_highbd_ != 0) {      mask_ = (1 << UUT_->use_highbd_) - 1;    } else {      mask_ = 255;    }#endif    /* Set up guard blocks for an inner block centered in the outer block */    for (int i = 0; i < kOutputBufferSize; ++i) {      if (IsIndexInBorder(i)) {        output_[i] = 255;#if CONFIG_VP9_HIGHBITDEPTH        output16_[i] = mask_;#endif      } else {        output_[i] = 0;#if CONFIG_VP9_HIGHBITDEPTH        output16_[i] = 0;#endif      }    }     ::libvpx_test::ACMRandom prng;    for (int i = 0; i < kInputBufferSize; ++i) {      if (i & 1) {        input_[i] = 255;#if CONFIG_VP9_HIGHBITDEPTH        input16_[i] = mask_;#endif      } else {        input_[i] = prng.Rand8Extremes();#if CONFIG_VP9_HIGHBITDEPTH        input16_[i] = prng.Rand16() & mask_;#endif      }    }  }   void SetConstantInput(int value) {    memset(input_, value, kInputBufferSize);#if CONFIG_VP9_HIGHBITDEPTH    vpx_memset16(input16_, value, kInputBufferSize);#endif  }   void CopyOutputToRef() {    memcpy(output_ref_, output_, kOutputBufferSize);#if CONFIG_VP9_HIGHBITDEPTH    memcpy(output16_ref_, output16_,           kOutputBufferSize * sizeof(output16_ref_[0]));#endif  }   void CheckGuardBlocks() {    for (int i = 0; i < kOutputBufferSize; ++i) {      if (IsIndexInBorder(i)) {        EXPECT_EQ(255, output_[i]);      }    }  }   uint8_t *input() const {    const int offset = BorderTop() * kOuterBlockSize + BorderLeft();#if CONFIG_VP9_HIGHBITDEPTH    if (UUT_->use_highbd_ == 0) {      return input_ + offset;    } else {      return CAST_TO_BYTEPTR(input16_ + offset);    }#else    return input_ + offset;#endif  }   uint8_t *output() const {    const int offset = BorderTop() * kOuterBlockSize + BorderLeft();#if CONFIG_VP9_HIGHBITDEPTH    if (UUT_->use_highbd_ == 0) {      return output_ + offset;    } else {      return CAST_TO_BYTEPTR(output16_ + offset);    }#else    return output_ + offset;#endif  }   uint8_t *output_ref() const {    const int offset = BorderTop() * kOuterBlockSize + BorderLeft();#if CONFIG_VP9_HIGHBITDEPTH    if (UUT_->use_highbd_ == 0) {      return output_ref_ + offset;    } else {

Lines 1–500 of 1472.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t