]> granicus.if.org Git - libvpx/blob - test/pp_filter_test.cc
Merge "Support a constant quality mode in VP9"
[libvpx] / test / pp_filter_test.cc
1 /*
2  *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 #include "test/clear_system_state.h"
11 #include "test/register_state_check.h"
12 #include "third_party/googletest/src/include/gtest/gtest.h"
13 extern "C" {
14 #include "./vpx_config.h"
15 #include "./vp8_rtcd.h"
16 #include "vpx/vpx_integer.h"
17 #include "vpx_mem/vpx_mem.h"
18 }
19
20 typedef void (*post_proc_func_t)(unsigned char *src_ptr,
21                                  unsigned char *dst_ptr,
22                                  int src_pixels_per_line,
23                                  int dst_pixels_per_line,
24                                  int cols,
25                                  unsigned char *flimit,
26                                  int size);
27
28 namespace {
29
30 class Vp8PostProcessingFilterTest
31     : public ::testing::TestWithParam<post_proc_func_t> {
32  public:
33   virtual void TearDown() {
34     libvpx_test::ClearSystemState();
35   }
36 };
37
38 // Test routine for the VP8 post-processing function
39 // vp8_post_proc_down_and_across_mb_row_c.
40
41 TEST_P(Vp8PostProcessingFilterTest, FilterOutputCheck) {
42   // Size of the underlying data block that will be filtered.
43   const int block_width  = 16;
44   const int block_height = 16;
45
46   // 5-tap filter needs 2 padding rows above and below the block in the input.
47   const int input_width = block_width;
48   const int input_height = block_height + 4;
49   const int input_stride = input_width;
50   const int input_size = input_width * input_height;
51
52   // Filter extends output block by 8 samples at left and right edges.
53   const int output_width = block_width + 16;
54   const int output_height = block_height;
55   const int output_stride = output_width;
56   const int output_size = output_width * output_height;
57
58   uint8_t *const src_image =
59       reinterpret_cast<uint8_t*>(vpx_calloc(input_size, 1));
60   uint8_t *const dst_image =
61       reinterpret_cast<uint8_t*>(vpx_calloc(output_size, 1));
62
63   // Pointers to top-left pixel of block in the input and output images.
64   uint8_t *const src_image_ptr = src_image + (input_stride << 1);
65   uint8_t *const dst_image_ptr = dst_image + 8;
66   uint8_t *const flimits =
67       reinterpret_cast<uint8_t *>(vpx_memalign(16, block_width));
68   (void)vpx_memset(flimits, 255, block_width);
69
70   // Initialize pixels in the input:
71   //   block pixels to value 1,
72   //   border pixels to value 10.
73   (void)vpx_memset(src_image, 10, input_size);
74   uint8_t *pixel_ptr = src_image_ptr;
75   for (int i = 0; i < block_height; ++i) {
76     for (int j = 0; j < block_width; ++j) {
77       pixel_ptr[j] = 1;
78     }
79     pixel_ptr += input_stride;
80   }
81
82   // Initialize pixels in the output to 99.
83   (void)vpx_memset(dst_image, 99, output_size);
84
85   REGISTER_STATE_CHECK(GetParam()(src_image_ptr, dst_image_ptr, input_stride,
86                                   output_stride, block_width, flimits, 16));
87
88   static const uint8_t expected_data[block_height] = {
89     4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4
90   };
91
92   pixel_ptr = dst_image_ptr;
93   for (int i = 0; i < block_height; ++i) {
94     for (int j = 0; j < block_width; ++j) {
95       EXPECT_EQ(expected_data[i], pixel_ptr[j])
96           << "Vp8PostProcessingFilterTest failed with invalid filter output";
97     }
98     pixel_ptr += output_stride;
99   }
100
101   vpx_free(src_image);
102   vpx_free(dst_image);
103   vpx_free(flimits);
104 };
105
106 INSTANTIATE_TEST_CASE_P(C, Vp8PostProcessingFilterTest,
107     ::testing::Values(vp8_post_proc_down_and_across_mb_row_c));
108
109 #if HAVE_SSE2
110 INSTANTIATE_TEST_CASE_P(SSE2, Vp8PostProcessingFilterTest,
111     ::testing::Values(vp8_post_proc_down_and_across_mb_row_sse2));
112 #endif
113
114 }  // namespace