]> granicus.if.org Git - libvpx/blob - test/pp_filter_test.cc
Merge "Removed unused dr from VP8D_COMP"
[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 "third_party/googletest/src/include/gtest/gtest.h"
11 extern "C" {
12 #include "vpx_config.h"
13 #include "vpx_rtcd.h"
14 #include "vpx/vpx_integer.h"
15 #include "vpx_mem/vpx_mem.h"
16 }
17
18 typedef void (*post_proc_func_t)(unsigned char *src_ptr,
19                                  unsigned char *dst_ptr,
20                                  int src_pixels_per_line,
21                                  int dst_pixels_per_line,
22                                  int rows,
23                                  int cols,
24                                  int flimit);
25
26 namespace {
27
28 class Vp8PostProcessingFilterTest
29     : public ::testing::TestWithParam<post_proc_func_t> {};
30
31 // Test routine for the VP8 post-processing function
32 // vp8_post_proc_down_and_across_c.
33
34 TEST_P(Vp8PostProcessingFilterTest, FilterOutputCheck) {
35   // Size of the underlying data block that will be filtered.
36   const int block_width  = 16;
37   const int block_height = 16;
38
39   // 5-tap filter needs 2 padding rows above and below the block in the input.
40   const int input_width = block_width;
41   const int input_height = block_height + 4;
42   const int input_stride = input_width;
43   const int input_size = input_width * input_height;
44
45   // Filter extends output block by 8 samples at left and right edges.
46   const int output_width = block_width + 16;
47   const int output_height = block_height;
48   const int output_stride = output_width;
49   const int output_size = output_width * output_height;
50
51   uint8_t *const src_image =
52       reinterpret_cast<uint8_t*>(vpx_calloc(input_size, 1));
53   uint8_t *const dst_image =
54       reinterpret_cast<uint8_t*>(vpx_calloc(output_size, 1));
55
56   // Pointers to top-left pixel of block in the input and output images.
57   uint8_t *const src_image_ptr = src_image + (input_stride << 1);
58   uint8_t *const dst_image_ptr = dst_image + 8;
59
60   // Initialize pixels in the input:
61   //   block pixels to value 1,
62   //   border pixels to value 10.
63   (void)vpx_memset(src_image, 10, input_size);
64   uint8_t *pixel_ptr = src_image_ptr;
65   for (int i = 0; i < block_height; ++i) {
66     for (int j = 0; j < block_width; ++j) {
67       pixel_ptr[j] = 1;
68     }
69     pixel_ptr += input_stride;
70   }
71
72   // Initialize pixels in the output to 99.
73   (void)vpx_memset(dst_image, 99, output_size);
74
75   GetParam()(src_image_ptr, dst_image_ptr, input_stride,
76              output_stride, block_height, block_width,
77              255);
78
79   static const uint8_t expected_data[block_height] = {
80     3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3
81   };
82
83   pixel_ptr = dst_image;
84   for (int i = 0; i < block_height; ++i) {
85     for (int j = 0; j < block_width; ++j) {
86       EXPECT_EQ(expected_data[i], pixel_ptr[j])
87           << "Vp8PostProcessingFilterTest failed with invalid filter output";
88     }
89     pixel_ptr += output_stride;
90   }
91
92   vpx_free(src_image);
93   vpx_free(dst_image);
94 };
95
96 INSTANTIATE_TEST_CASE_P(C, Vp8PostProcessingFilterTest,
97                         ::testing::Values(vp8_post_proc_down_and_across_c));
98
99 #if HAVE_MMX
100 INSTANTIATE_TEST_CASE_P(MMX, Vp8PostProcessingFilterTest,
101                         ::testing::Values(vp8_post_proc_down_and_across_mmx));
102 #endif
103
104 #if HAVE_SSE2
105 INSTANTIATE_TEST_CASE_P(SSE2, Vp8PostProcessingFilterTest,
106                         ::testing::Values(vp8_post_proc_down_and_across_xmm));
107 #endif
108
109 }  // namespace