2015-02-23 11:18:48 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* This file is part of Kvazaar HEVC encoder.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 Tampere University of Technology and others (see
|
|
|
|
* COPYING file).
|
|
|
|
*
|
|
|
|
* Kvazaar is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 2.1 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Kvazaar is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
#include "greatest/greatest.h"
|
2013-10-09 12:31:27 +00:00
|
|
|
|
2014-07-28 12:49:51 +00:00
|
|
|
#include "test_strategies.h"
|
|
|
|
|
2014-06-12 12:04:48 +00:00
|
|
|
#include "src/image.h"
|
2013-10-09 12:31:27 +00:00
|
|
|
|
2014-06-16 14:05:29 +00:00
|
|
|
#include <string.h>
|
2014-06-13 07:34:08 +00:00
|
|
|
|
|
|
|
|
2013-10-09 12:31:27 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// EXTERNAL FUNCTIONS
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// DEFINES
|
2014-06-16 13:07:11 +00:00
|
|
|
#define TEST_SAD(X, Y) image_calc_sad(g_pic, g_ref, 0, 0, (X), (Y), 8, 8, -1)
|
2013-10-09 12:31:27 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GLOBALS
|
|
|
|
const uint8_t ref_data[64] = {
|
|
|
|
1,2,2,2,2,2,2,3,
|
|
|
|
4,5,5,5,5,5,5,6,
|
|
|
|
4,5,5,5,5,5,5,6,
|
|
|
|
4,5,5,5,5,5,5,6,
|
|
|
|
4,5,5,5,5,5,5,6,
|
|
|
|
4,5,5,5,5,5,5,6,
|
|
|
|
4,5,5,5,5,5,5,6,
|
|
|
|
7,8,8,8,8,8,8,9
|
|
|
|
};
|
|
|
|
|
|
|
|
const uint8_t pic_data[64] = {
|
|
|
|
1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1
|
|
|
|
};
|
|
|
|
|
2015-03-04 11:55:06 +00:00
|
|
|
image_t *g_pic = 0;
|
|
|
|
image_t *g_ref = 0;
|
2013-10-09 12:31:27 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// SETUP, TEARDOWN AND HELPER FUNCTIONS
|
2014-06-13 07:34:08 +00:00
|
|
|
static void setup_tests()
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-06-12 12:04:48 +00:00
|
|
|
g_pic = image_alloc(8, 8, 1);
|
|
|
|
for (int i = 0; i < 64; ++i) {
|
|
|
|
g_pic->y[i] = pic_data[i] + 48;
|
2013-10-10 16:09:44 +00:00
|
|
|
}
|
2013-10-09 12:31:27 +00:00
|
|
|
|
2014-06-12 12:04:48 +00:00
|
|
|
g_ref = image_alloc(8, 8, 0);
|
|
|
|
for (int i = 0; i < 64; ++i) {
|
|
|
|
g_ref->y[i] = ref_data[i] + 48;
|
2013-10-10 16:09:44 +00:00
|
|
|
}
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
static void tear_down_tests()
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-06-12 12:04:48 +00:00
|
|
|
image_free(g_pic);
|
|
|
|
image_free(g_ref);
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
|
2013-10-09 12:31:27 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2013-10-11 11:08:56 +00:00
|
|
|
// OVERLAPPING BOUNDARY TESTS
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_topleft(void)
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-10 12:16:14 +00:00
|
|
|
1*(4*4) + (2+4)*(4*4) + 5*(4*4) - 64,
|
|
|
|
TEST_SAD(-3, -3));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_top(void)
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-10 12:16:14 +00:00
|
|
|
(1+3)*4 + 2*(6*4) + (4+6)*4 + 5*(6*4) - 64,
|
|
|
|
TEST_SAD(0, -3));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_topright(void)
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-10 12:16:14 +00:00
|
|
|
3*(4*4) + (2+6)*(4*4) + 5*(4*4) - 64,
|
|
|
|
TEST_SAD(3, -3));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_left(void)
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-10 12:16:14 +00:00
|
|
|
(1+7)*4 + 4*(6*4) + (2+8)*4 + 5*(6*4) - 64,
|
|
|
|
TEST_SAD(-3, 0));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_no_offset(void)
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-10 12:16:14 +00:00
|
|
|
(1+3+7+9) + (2+4+6+8)*6 + 5*(6*6) - 64,
|
2013-10-09 12:31:27 +00:00
|
|
|
TEST_SAD(0, 0));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_right(void)
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-10 12:16:14 +00:00
|
|
|
(3+9)*4 + 6*(4*6) + (2+8)*4 + 5*(6*4) - 64,
|
|
|
|
TEST_SAD(3, 0));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_bottomleft(void)
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-10 12:16:14 +00:00
|
|
|
7*(4*4) + (4+8)*(4*4) + 5*(4*4) - 64,
|
|
|
|
TEST_SAD(-3, 3));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_bottom(void)
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-10 12:16:14 +00:00
|
|
|
(7+9)*4 + 8*(6*4) + (4+6)*4 + 5*(6*4) - 64,
|
|
|
|
TEST_SAD(0, 3));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_bottomright(void)
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-10 12:16:14 +00:00
|
|
|
9*(4*4) + (6+8)*(4*4) + 5*(4*4) - 64,
|
2013-10-11 09:38:14 +00:00
|
|
|
TEST_SAD(3, 3));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 11:08:56 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OUT OF FRAME TESTS
|
|
|
|
|
2014-02-07 11:06:17 +00:00
|
|
|
#define DIST 10
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_topleft_out(void)
|
2013-10-11 11:08:56 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-11 11:08:56 +00:00
|
|
|
1*(8*8) - 64,
|
2014-02-07 11:06:17 +00:00
|
|
|
TEST_SAD(-DIST, -DIST));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-11 11:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_top_out(void)
|
2013-10-11 11:08:56 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-11 11:08:56 +00:00
|
|
|
(1+3)*8 + 2*(6*8) - 64,
|
2014-02-07 11:06:17 +00:00
|
|
|
TEST_SAD(0, -DIST));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-11 11:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_topright_out(void)
|
2013-10-11 11:08:56 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-11 11:08:56 +00:00
|
|
|
3*(8*8) - 64,
|
2014-02-07 11:06:17 +00:00
|
|
|
TEST_SAD(DIST, -DIST));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-11 11:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_left_out(void)
|
2013-10-11 11:08:56 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-11 11:08:56 +00:00
|
|
|
(1+7)*8 + 4*(6*8) - 64,
|
2014-02-07 11:06:17 +00:00
|
|
|
TEST_SAD(-DIST, 0));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-11 11:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_right_out(void)
|
2013-10-11 11:08:56 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-11 11:08:56 +00:00
|
|
|
(3+9)*8 + 6*(6*8) - 64,
|
2014-02-07 11:06:17 +00:00
|
|
|
TEST_SAD(DIST, 0));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-11 11:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_bottomleft_out(void)
|
2013-10-11 11:08:56 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-11 11:08:56 +00:00
|
|
|
7*(8*8) - 64,
|
2014-02-07 11:06:17 +00:00
|
|
|
TEST_SAD(-DIST, DIST));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-11 11:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_bottom_out(void)
|
2013-10-11 11:08:56 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-11 11:08:56 +00:00
|
|
|
(7+9)*8 + 8*(6*8) - 64,
|
2014-02-07 11:06:17 +00:00
|
|
|
TEST_SAD(0, DIST));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-11 11:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 12:35:37 +00:00
|
|
|
TEST test_bottomright_out(void)
|
2013-10-11 11:08:56 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
ASSERT_EQ(
|
2013-10-11 11:08:56 +00:00
|
|
|
9*(8*8) - 64,
|
2014-02-07 11:06:17 +00:00
|
|
|
TEST_SAD(DIST, DIST));
|
2014-01-31 12:35:37 +00:00
|
|
|
PASS();
|
2013-10-11 11:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 12:04:48 +00:00
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
struct sad_test_env_t {
|
2015-03-04 11:55:06 +00:00
|
|
|
image_t *g_pic;
|
|
|
|
image_t *g_ref;
|
2014-06-13 07:34:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-10-09 12:31:27 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// TEST FIXTURES
|
2014-01-31 12:35:37 +00:00
|
|
|
SUITE(sad_tests)
|
2013-10-09 12:31:27 +00:00
|
|
|
{
|
2014-01-31 12:35:37 +00:00
|
|
|
//SET_SETUP(sad_setup);
|
|
|
|
//SET_TEARDOWN(sad_teardown);
|
2013-10-11 11:08:56 +00:00
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
setup_tests();
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < strategies.count; ++i) {
|
2014-06-16 14:05:29 +00:00
|
|
|
if (strcmp(strategies.strategies[i].type, "reg_sad") != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
// Change the global reg_sad function pointer.
|
|
|
|
reg_sad = strategies.strategies[i].fptr;
|
2013-10-09 12:31:27 +00:00
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
// Tests for movement vectors that overlap frame.
|
|
|
|
RUN_TEST(test_topleft);
|
|
|
|
RUN_TEST(test_top);
|
|
|
|
RUN_TEST(test_topright);
|
2013-10-09 12:31:27 +00:00
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
RUN_TEST(test_left);
|
|
|
|
RUN_TEST(test_no_offset);
|
|
|
|
RUN_TEST(test_right);
|
2013-10-09 12:31:27 +00:00
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
RUN_TEST(test_bottomleft);
|
|
|
|
RUN_TEST(test_bottom);
|
|
|
|
RUN_TEST(test_bottomright);
|
2013-10-11 11:08:56 +00:00
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
// Tests for movement vectors that are outside the frame.
|
|
|
|
RUN_TEST(test_topleft_out);
|
|
|
|
RUN_TEST(test_top_out);
|
|
|
|
RUN_TEST(test_topright_out);
|
2013-10-11 11:08:56 +00:00
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
RUN_TEST(test_left_out);
|
|
|
|
RUN_TEST(test_right_out);
|
2013-10-11 11:08:56 +00:00
|
|
|
|
2014-06-13 07:34:08 +00:00
|
|
|
RUN_TEST(test_bottomleft_out);
|
|
|
|
RUN_TEST(test_bottom_out);
|
|
|
|
RUN_TEST(test_bottomright_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
tear_down_tests();
|
2013-10-09 12:31:27 +00:00
|
|
|
}
|