11b362b15af34006e6a11974088a46d42b903418eJohann/* 21b362b15af34006e6a11974088a46d42b903418eJohann * Copyright (c) 2012 The WebM project authors. All Rights Reserved. 31b362b15af34006e6a11974088a46d42b903418eJohann * 41b362b15af34006e6a11974088a46d42b903418eJohann * Use of this source code is governed by a BSD-style license 51b362b15af34006e6a11974088a46d42b903418eJohann * that can be found in the LICENSE file in the root of the source 61b362b15af34006e6a11974088a46d42b903418eJohann * tree. An additional intellectual property rights grant can be found 71b362b15af34006e6a11974088a46d42b903418eJohann * in the file PATENTS. All contributing project authors may 81b362b15af34006e6a11974088a46d42b903418eJohann * be found in the AUTHORS file in the root of the source tree. 91b362b15af34006e6a11974088a46d42b903418eJohann */ 10ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "test/clear_system_state.h" 11ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "test/register_state_check.h" 121b362b15af34006e6a11974088a46d42b903418eJohann#include "third_party/googletest/src/include/gtest/gtest.h" 133df0563f1b24dac6c0bd122fc922a48211269061hkuang#include "./vpx_config.h" 143df0563f1b24dac6c0bd122fc922a48211269061hkuang#include "./vp8_rtcd.h" 151b362b15af34006e6a11974088a46d42b903418eJohann#include "vpx/vpx_integer.h" 161b362b15af34006e6a11974088a46d42b903418eJohann#include "vpx_mem/vpx_mem.h" 171b362b15af34006e6a11974088a46d42b903418eJohann 181b362b15af34006e6a11974088a46d42b903418eJohanntypedef void (*post_proc_func_t)(unsigned char *src_ptr, 191b362b15af34006e6a11974088a46d42b903418eJohann unsigned char *dst_ptr, 201b362b15af34006e6a11974088a46d42b903418eJohann int src_pixels_per_line, 211b362b15af34006e6a11974088a46d42b903418eJohann int dst_pixels_per_line, 221b362b15af34006e6a11974088a46d42b903418eJohann int cols, 231b362b15af34006e6a11974088a46d42b903418eJohann unsigned char *flimit, 241b362b15af34006e6a11974088a46d42b903418eJohann int size); 251b362b15af34006e6a11974088a46d42b903418eJohann 261b362b15af34006e6a11974088a46d42b903418eJohannnamespace { 271b362b15af34006e6a11974088a46d42b903418eJohann 286ac915abcdb404a00d927fe6308a47fcf09d9519hkuangclass VP8PostProcessingFilterTest 29ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang : public ::testing::TestWithParam<post_proc_func_t> { 30ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang public: 31ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang virtual void TearDown() { 32ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang libvpx_test::ClearSystemState(); 33ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } 34ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang}; 351b362b15af34006e6a11974088a46d42b903418eJohann 361b362b15af34006e6a11974088a46d42b903418eJohann// Test routine for the VP8 post-processing function 371b362b15af34006e6a11974088a46d42b903418eJohann// vp8_post_proc_down_and_across_mb_row_c. 381b362b15af34006e6a11974088a46d42b903418eJohann 396ac915abcdb404a00d927fe6308a47fcf09d9519hkuangTEST_P(VP8PostProcessingFilterTest, FilterOutputCheck) { 401b362b15af34006e6a11974088a46d42b903418eJohann // Size of the underlying data block that will be filtered. 411b362b15af34006e6a11974088a46d42b903418eJohann const int block_width = 16; 421b362b15af34006e6a11974088a46d42b903418eJohann const int block_height = 16; 431b362b15af34006e6a11974088a46d42b903418eJohann 441b362b15af34006e6a11974088a46d42b903418eJohann // 5-tap filter needs 2 padding rows above and below the block in the input. 451b362b15af34006e6a11974088a46d42b903418eJohann const int input_width = block_width; 461b362b15af34006e6a11974088a46d42b903418eJohann const int input_height = block_height + 4; 471b362b15af34006e6a11974088a46d42b903418eJohann const int input_stride = input_width; 481b362b15af34006e6a11974088a46d42b903418eJohann const int input_size = input_width * input_height; 491b362b15af34006e6a11974088a46d42b903418eJohann 501b362b15af34006e6a11974088a46d42b903418eJohann // Filter extends output block by 8 samples at left and right edges. 511b362b15af34006e6a11974088a46d42b903418eJohann const int output_width = block_width + 16; 521b362b15af34006e6a11974088a46d42b903418eJohann const int output_height = block_height; 531b362b15af34006e6a11974088a46d42b903418eJohann const int output_stride = output_width; 541b362b15af34006e6a11974088a46d42b903418eJohann const int output_size = output_width * output_height; 551b362b15af34006e6a11974088a46d42b903418eJohann 561b362b15af34006e6a11974088a46d42b903418eJohann uint8_t *const src_image = 571b362b15af34006e6a11974088a46d42b903418eJohann reinterpret_cast<uint8_t*>(vpx_calloc(input_size, 1)); 581b362b15af34006e6a11974088a46d42b903418eJohann uint8_t *const dst_image = 591b362b15af34006e6a11974088a46d42b903418eJohann reinterpret_cast<uint8_t*>(vpx_calloc(output_size, 1)); 601b362b15af34006e6a11974088a46d42b903418eJohann 611b362b15af34006e6a11974088a46d42b903418eJohann // Pointers to top-left pixel of block in the input and output images. 621b362b15af34006e6a11974088a46d42b903418eJohann uint8_t *const src_image_ptr = src_image + (input_stride << 1); 631b362b15af34006e6a11974088a46d42b903418eJohann uint8_t *const dst_image_ptr = dst_image + 8; 643df0563f1b24dac6c0bd122fc922a48211269061hkuang uint8_t *const flimits = 653df0563f1b24dac6c0bd122fc922a48211269061hkuang reinterpret_cast<uint8_t *>(vpx_memalign(16, block_width)); 661b362b15af34006e6a11974088a46d42b903418eJohann (void)vpx_memset(flimits, 255, block_width); 671b362b15af34006e6a11974088a46d42b903418eJohann 681b362b15af34006e6a11974088a46d42b903418eJohann // Initialize pixels in the input: 691b362b15af34006e6a11974088a46d42b903418eJohann // block pixels to value 1, 701b362b15af34006e6a11974088a46d42b903418eJohann // border pixels to value 10. 711b362b15af34006e6a11974088a46d42b903418eJohann (void)vpx_memset(src_image, 10, input_size); 721b362b15af34006e6a11974088a46d42b903418eJohann uint8_t *pixel_ptr = src_image_ptr; 731b362b15af34006e6a11974088a46d42b903418eJohann for (int i = 0; i < block_height; ++i) { 741b362b15af34006e6a11974088a46d42b903418eJohann for (int j = 0; j < block_width; ++j) { 751b362b15af34006e6a11974088a46d42b903418eJohann pixel_ptr[j] = 1; 761b362b15af34006e6a11974088a46d42b903418eJohann } 771b362b15af34006e6a11974088a46d42b903418eJohann pixel_ptr += input_stride; 781b362b15af34006e6a11974088a46d42b903418eJohann } 791b362b15af34006e6a11974088a46d42b903418eJohann 801b362b15af34006e6a11974088a46d42b903418eJohann // Initialize pixels in the output to 99. 811b362b15af34006e6a11974088a46d42b903418eJohann (void)vpx_memset(dst_image, 99, output_size); 821b362b15af34006e6a11974088a46d42b903418eJohann 83ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang REGISTER_STATE_CHECK(GetParam()(src_image_ptr, dst_image_ptr, input_stride, 84ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang output_stride, block_width, flimits, 16)); 851b362b15af34006e6a11974088a46d42b903418eJohann 861b362b15af34006e6a11974088a46d42b903418eJohann static const uint8_t expected_data[block_height] = { 871b362b15af34006e6a11974088a46d42b903418eJohann 4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4 881b362b15af34006e6a11974088a46d42b903418eJohann }; 891b362b15af34006e6a11974088a46d42b903418eJohann 901b362b15af34006e6a11974088a46d42b903418eJohann pixel_ptr = dst_image_ptr; 911b362b15af34006e6a11974088a46d42b903418eJohann for (int i = 0; i < block_height; ++i) { 921b362b15af34006e6a11974088a46d42b903418eJohann for (int j = 0; j < block_width; ++j) { 931b362b15af34006e6a11974088a46d42b903418eJohann EXPECT_EQ(expected_data[i], pixel_ptr[j]) 946ac915abcdb404a00d927fe6308a47fcf09d9519hkuang << "VP8PostProcessingFilterTest failed with invalid filter output"; 951b362b15af34006e6a11974088a46d42b903418eJohann } 961b362b15af34006e6a11974088a46d42b903418eJohann pixel_ptr += output_stride; 971b362b15af34006e6a11974088a46d42b903418eJohann } 981b362b15af34006e6a11974088a46d42b903418eJohann 991b362b15af34006e6a11974088a46d42b903418eJohann vpx_free(src_image); 1001b362b15af34006e6a11974088a46d42b903418eJohann vpx_free(dst_image); 1011b362b15af34006e6a11974088a46d42b903418eJohann vpx_free(flimits); 1021b362b15af34006e6a11974088a46d42b903418eJohann}; 1031b362b15af34006e6a11974088a46d42b903418eJohann 1046ac915abcdb404a00d927fe6308a47fcf09d9519hkuangINSTANTIATE_TEST_CASE_P(C, VP8PostProcessingFilterTest, 1051b362b15af34006e6a11974088a46d42b903418eJohann ::testing::Values(vp8_post_proc_down_and_across_mb_row_c)); 1061b362b15af34006e6a11974088a46d42b903418eJohann 1071b362b15af34006e6a11974088a46d42b903418eJohann#if HAVE_SSE2 1086ac915abcdb404a00d927fe6308a47fcf09d9519hkuangINSTANTIATE_TEST_CASE_P(SSE2, VP8PostProcessingFilterTest, 1091b362b15af34006e6a11974088a46d42b903418eJohann ::testing::Values(vp8_post_proc_down_and_across_mb_row_sse2)); 1101b362b15af34006e6a11974088a46d42b903418eJohann#endif 1111b362b15af34006e6a11974088a46d42b903418eJohann 1121b362b15af34006e6a11974088a46d42b903418eJohann} // namespace 113