Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 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 | */ |
James Zern | 5b75674 | 2013-06-17 22:58:40 -0700 | [diff] [blame] | 10 | #include "test/clear_system_state.h" |
James Zern | eebb648 | 2012-11-27 13:08:05 -0800 | [diff] [blame] | 11 | #include "test/register_state_check.h" |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 12 | #include "third_party/googletest/src/include/gtest/gtest.h" |
Yaowu Xu | afffa3d | 2013-09-05 08:45:56 -0700 | [diff] [blame] | 13 | #include "./vpx_config.h" |
| 14 | #include "./vp8_rtcd.h" |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 15 | #include "vpx/vpx_integer.h" |
| 16 | #include "vpx_mem/vpx_mem.h" |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 17 | |
James Zern | 25d74e6 | 2014-07-16 18:58:53 -0700 | [diff] [blame] | 18 | typedef void (*PostProcFunc)(unsigned char *src_ptr, |
| 19 | unsigned char *dst_ptr, |
| 20 | int src_pixels_per_line, |
| 21 | int dst_pixels_per_line, |
| 22 | int cols, |
| 23 | unsigned char *flimit, |
| 24 | int size); |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 25 | |
| 26 | namespace { |
| 27 | |
James Zern | 5221e91 | 2014-03-22 14:13:14 -0700 | [diff] [blame] | 28 | class VP8PostProcessingFilterTest |
James Zern | 25d74e6 | 2014-07-16 18:58:53 -0700 | [diff] [blame] | 29 | : public ::testing::TestWithParam<PostProcFunc> { |
James Zern | 5b75674 | 2013-06-17 22:58:40 -0700 | [diff] [blame] | 30 | public: |
| 31 | virtual void TearDown() { |
| 32 | libvpx_test::ClearSystemState(); |
| 33 | } |
| 34 | }; |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 35 | |
| 36 | // Test routine for the VP8 post-processing function |
Yunqing Wang | 4c53bac | 2012-09-28 10:13:07 -0700 | [diff] [blame] | 37 | // vp8_post_proc_down_and_across_mb_row_c. |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 38 | |
James Zern | 5221e91 | 2014-03-22 14:13:14 -0700 | [diff] [blame] | 39 | TEST_P(VP8PostProcessingFilterTest, FilterOutputCheck) { |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 40 | // Size of the underlying data block that will be filtered. |
| 41 | const int block_width = 16; |
| 42 | const int block_height = 16; |
| 43 | |
| 44 | // 5-tap filter needs 2 padding rows above and below the block in the input. |
| 45 | const int input_width = block_width; |
| 46 | const int input_height = block_height + 4; |
| 47 | const int input_stride = input_width; |
| 48 | const int input_size = input_width * input_height; |
| 49 | |
| 50 | // Filter extends output block by 8 samples at left and right edges. |
| 51 | const int output_width = block_width + 16; |
| 52 | const int output_height = block_height; |
| 53 | const int output_stride = output_width; |
| 54 | const int output_size = output_width * output_height; |
| 55 | |
| 56 | uint8_t *const src_image = |
| 57 | reinterpret_cast<uint8_t*>(vpx_calloc(input_size, 1)); |
| 58 | uint8_t *const dst_image = |
| 59 | reinterpret_cast<uint8_t*>(vpx_calloc(output_size, 1)); |
| 60 | |
| 61 | // Pointers to top-left pixel of block in the input and output images. |
| 62 | uint8_t *const src_image_ptr = src_image + (input_stride << 1); |
| 63 | uint8_t *const dst_image_ptr = dst_image + 8; |
Yaowu Xu | afffa3d | 2013-09-05 08:45:56 -0700 | [diff] [blame] | 64 | uint8_t *const flimits = |
| 65 | reinterpret_cast<uint8_t *>(vpx_memalign(16, block_width)); |
James Zern | f58011a | 2015-04-23 20:47:40 -0700 | [diff] [blame] | 66 | (void)memset(flimits, 255, block_width); |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 67 | |
| 68 | // Initialize pixels in the input: |
| 69 | // block pixels to value 1, |
| 70 | // border pixels to value 10. |
James Zern | f58011a | 2015-04-23 20:47:40 -0700 | [diff] [blame] | 71 | (void)memset(src_image, 10, input_size); |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 72 | uint8_t *pixel_ptr = src_image_ptr; |
| 73 | for (int i = 0; i < block_height; ++i) { |
| 74 | for (int j = 0; j < block_width; ++j) { |
| 75 | pixel_ptr[j] = 1; |
| 76 | } |
| 77 | pixel_ptr += input_stride; |
| 78 | } |
| 79 | |
| 80 | // Initialize pixels in the output to 99. |
James Zern | f58011a | 2015-04-23 20:47:40 -0700 | [diff] [blame] | 81 | (void)memset(dst_image, 99, output_size); |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 82 | |
James Zern | 29e1b1a | 2014-07-09 21:02:02 -0700 | [diff] [blame] | 83 | ASM_REGISTER_STATE_CHECK( |
| 84 | GetParam()(src_image_ptr, dst_image_ptr, input_stride, |
| 85 | output_stride, block_width, flimits, 16)); |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 86 | |
| 87 | static const uint8_t expected_data[block_height] = { |
Yunqing Wang | 4c53bac | 2012-09-28 10:13:07 -0700 | [diff] [blame] | 88 | 4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4 |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Yunqing Wang | 4c53bac | 2012-09-28 10:13:07 -0700 | [diff] [blame] | 91 | pixel_ptr = dst_image_ptr; |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 92 | for (int i = 0; i < block_height; ++i) { |
| 93 | for (int j = 0; j < block_width; ++j) { |
| 94 | EXPECT_EQ(expected_data[i], pixel_ptr[j]) |
James Zern | 5221e91 | 2014-03-22 14:13:14 -0700 | [diff] [blame] | 95 | << "VP8PostProcessingFilterTest failed with invalid filter output"; |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 96 | } |
| 97 | pixel_ptr += output_stride; |
| 98 | } |
| 99 | |
| 100 | vpx_free(src_image); |
| 101 | vpx_free(dst_image); |
Yunqing Wang | 4c53bac | 2012-09-28 10:13:07 -0700 | [diff] [blame] | 102 | vpx_free(flimits); |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
James Zern | 5221e91 | 2014-03-22 14:13:14 -0700 | [diff] [blame] | 105 | INSTANTIATE_TEST_CASE_P(C, VP8PostProcessingFilterTest, |
Yunqing Wang | 4c53bac | 2012-09-28 10:13:07 -0700 | [diff] [blame] | 106 | ::testing::Values(vp8_post_proc_down_and_across_mb_row_c)); |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 107 | |
| 108 | #if HAVE_SSE2 |
James Zern | 5221e91 | 2014-03-22 14:13:14 -0700 | [diff] [blame] | 109 | INSTANTIATE_TEST_CASE_P(SSE2, VP8PostProcessingFilterTest, |
Yunqing Wang | 4c53bac | 2012-09-28 10:13:07 -0700 | [diff] [blame] | 110 | ::testing::Values(vp8_post_proc_down_and_across_mb_row_sse2)); |
Adrian Grange | c7acd6d | 2012-06-19 12:03:36 -0700 | [diff] [blame] | 111 | #endif |
| 112 | |
| 113 | } // namespace |