15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/*
2ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch *
4ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch *  Use of this source code is governed by a BSD-style license
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *  that can be found in the LICENSE file in the root of the source
6ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch *  tree. An additional intellectual property rights grant can be found
7ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch *  in the file PATENTS.  All contributing project authors may
8ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch *  be found in the AUTHORS file in the root of the source tree.
93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) */
10ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "test/clear_system_state.h"
11ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "test/register_state_check.h"
123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "third_party/googletest/src/include/gtest/gtest.h"
133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "./vpx_config.h"
14ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "./vp8_rtcd.h"
15ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "vpx/vpx_integer.h"
16ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "vpx_mem/vpx_mem.h"
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
18ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochtypedef void (*PostProcFunc)(unsigned char *src_ptr,
194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             unsigned char *dst_ptr,
20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                             int src_pixels_per_line,
21f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             int dst_pixels_per_line,
22ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                             int cols,
23ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                             unsigned char *flimit,
24ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                             int size);
2546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
26ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochnamespace {
27ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
28ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochclass VP8PostProcessingFilterTest
29ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    : public ::testing::TestWithParam<PostProcFunc> {
30ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch public:
31ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual void TearDown() {
32ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    libvpx_test::ClearSystemState();
333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)};
353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
36ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// Test routine for the VP8 post-processing function
37ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// vp8_post_proc_down_and_across_mb_row_c.
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_P(VP8PostProcessingFilterTest, FilterOutputCheck) {
4068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Size of the underlying data block that will be filtered.
4168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const int block_width  = 16;
4268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const int block_height = 16;
433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
44ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // 5-tap filter needs 2 padding rows above and below the block in the input.
4568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const int input_width = block_width;
4668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const int input_height = block_height + 4;
4768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const int input_stride = input_width;
48ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  const int input_size = input_width * input_height;
49ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Filter extends output block by 8 samples at left and right edges.
51ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  const int output_width = block_width + 16;
52ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  const int output_height = block_height;
53ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  const int output_stride = output_width;
54ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  const int output_size = output_width * output_height;
55ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
56ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  uint8_t *const src_image =
57c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      reinterpret_cast<uint8_t*>(vpx_calloc(input_size, 1));
58ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  uint8_t *const dst_image =
59ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      reinterpret_cast<uint8_t*>(vpx_calloc(output_size, 1));
60c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
61ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Pointers to top-left pixel of block in the input and output images.
62ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  uint8_t *const src_image_ptr = src_image + (input_stride << 1);
63ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  uint8_t *const dst_image_ptr = dst_image + 8;
64ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  uint8_t *const flimits =
65ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      reinterpret_cast<uint8_t *>(vpx_memalign(16, block_width));
66ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  (void)vpx_memset(flimits, 255, block_width);
67ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
68ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Initialize pixels in the input:
69ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  //   block pixels to value 1,
70ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  //   border pixels to value 10.
71ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  (void)vpx_memset(src_image, 10, input_size);
72ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  uint8_t *pixel_ptr = src_image_ptr;
73ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  for (int i = 0; i < block_height; ++i) {
74ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    for (int j = 0; j < block_width; ++j) {
75ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      pixel_ptr[j] = 1;
76ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    }
77ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    pixel_ptr += input_stride;
78ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
79ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
8046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Initialize pixels in the output to 99.
8146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  (void)vpx_memset(dst_image, 99, output_size);
8246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
83ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  ASM_REGISTER_STATE_CHECK(
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetParam()(src_image_ptr, dst_image_ptr, input_stride,
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 output_stride, block_width, flimits, 16));
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const uint8_t expected_data[block_height] = {
883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4
89ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  };
90ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  pixel_ptr = dst_image_ptr;
92116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  for (int i = 0; i < block_height; ++i) {
93116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    for (int j = 0; j < block_width; ++j) {
94116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      EXPECT_EQ(expected_data[i], pixel_ptr[j])
953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)          << "VP8PostProcessingFilterTest failed with invalid filter output";
96116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    }
97ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    pixel_ptr += output_stride;
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
100ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  vpx_free(src_image);
1013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  vpx_free(dst_image);
1023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  vpx_free(flimits);
1033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)};
1043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
105ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben MurdochINSTANTIATE_TEST_CASE_P(C, VP8PostProcessingFilterTest,
1063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    ::testing::Values(vp8_post_proc_down_and_across_mb_row_c));
107ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
108ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#if HAVE_SSE2
109ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben MurdochINSTANTIATE_TEST_CASE_P(SSE2, VP8PostProcessingFilterTest,
1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ::testing::Values(vp8_post_proc_down_and_across_mb_row_sse2));
1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace
11468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)