pp_filter_test.cc 3.77 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 *  Copyright (c) 2012 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.
 */
10
#include "test/clear_system_state.h"
11
#include "test/register_state_check.h"
12
#include "third_party/googletest/src/include/gtest/gtest.h"
Yaowu Xu's avatar
Yaowu Xu committed
13 14
#include "./vpx_config.h"
#include "./vp8_rtcd.h"
15 16 17 18 19 20 21 22
#include "vpx/vpx_integer.h"
#include "vpx_mem/vpx_mem.h"

typedef void (*post_proc_func_t)(unsigned char *src_ptr,
                                 unsigned char *dst_ptr,
                                 int src_pixels_per_line,
                                 int dst_pixels_per_line,
                                 int cols,
23 24
                                 unsigned char *flimit,
                                 int size);
25 26 27

namespace {

28
class VP8PostProcessingFilterTest
29 30 31 32 33 34
    : public ::testing::TestWithParam<post_proc_func_t> {
 public:
  virtual void TearDown() {
    libvpx_test::ClearSystemState();
  }
};
35 36

// Test routine for the VP8 post-processing function
37
// vp8_post_proc_down_and_across_mb_row_c.
38

39
TEST_P(VP8PostProcessingFilterTest, FilterOutputCheck) {
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  // Size of the underlying data block that will be filtered.
  const int block_width  = 16;
  const int block_height = 16;

  // 5-tap filter needs 2 padding rows above and below the block in the input.
  const int input_width = block_width;
  const int input_height = block_height + 4;
  const int input_stride = input_width;
  const int input_size = input_width * input_height;

  // Filter extends output block by 8 samples at left and right edges.
  const int output_width = block_width + 16;
  const int output_height = block_height;
  const int output_stride = output_width;
  const int output_size = output_width * output_height;

  uint8_t *const src_image =
      reinterpret_cast<uint8_t*>(vpx_calloc(input_size, 1));
  uint8_t *const dst_image =
      reinterpret_cast<uint8_t*>(vpx_calloc(output_size, 1));

  // Pointers to top-left pixel of block in the input and output images.
  uint8_t *const src_image_ptr = src_image + (input_stride << 1);
  uint8_t *const dst_image_ptr = dst_image + 8;
Yaowu Xu's avatar
Yaowu Xu committed
64 65
  uint8_t *const flimits =
      reinterpret_cast<uint8_t *>(vpx_memalign(16, block_width));
66
  (void)vpx_memset(flimits, 255, block_width);
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

  // Initialize pixels in the input:
  //   block pixels to value 1,
  //   border pixels to value 10.
  (void)vpx_memset(src_image, 10, input_size);
  uint8_t *pixel_ptr = src_image_ptr;
  for (int i = 0; i < block_height; ++i) {
    for (int j = 0; j < block_width; ++j) {
      pixel_ptr[j] = 1;
    }
    pixel_ptr += input_stride;
  }

  // Initialize pixels in the output to 99.
  (void)vpx_memset(dst_image, 99, output_size);

83 84
  REGISTER_STATE_CHECK(GetParam()(src_image_ptr, dst_image_ptr, input_stride,
                                  output_stride, block_width, flimits, 16));
85 86

  static const uint8_t expected_data[block_height] = {
87
    4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4
88 89
  };

90
  pixel_ptr = dst_image_ptr;
91 92 93
  for (int i = 0; i < block_height; ++i) {
    for (int j = 0; j < block_width; ++j) {
      EXPECT_EQ(expected_data[i], pixel_ptr[j])
94
          << "VP8PostProcessingFilterTest failed with invalid filter output";
95 96 97 98 99 100
    }
    pixel_ptr += output_stride;
  }

  vpx_free(src_image);
  vpx_free(dst_image);
101
  vpx_free(flimits);
102 103
};

104
INSTANTIATE_TEST_CASE_P(C, VP8PostProcessingFilterTest,
105
    ::testing::Values(vp8_post_proc_down_and_across_mb_row_c));
106 107

#if HAVE_SSE2
108
INSTANTIATE_TEST_CASE_P(SSE2, VP8PostProcessingFilterTest,
109
    ::testing::Values(vp8_post_proc_down_and_across_mb_row_sse2));
110 111 112
#endif

}  // namespace