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-06-18 13:28:34 +00:00
|
|
|
#include "greatest/greatest.h"
|
|
|
|
|
2014-07-28 12:49:51 +00:00
|
|
|
#include "test_strategies.h"
|
|
|
|
|
2014-06-18 13:28:34 +00:00
|
|
|
#include "src/image.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// MACROS
|
|
|
|
#define NUM_TESTS 3
|
|
|
|
#define LCU_MAX_LOG_W 6
|
|
|
|
#define LCU_MIN_LOG_W 2
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GLOBALS
|
2015-07-01 06:52:39 +00:00
|
|
|
static kvz_pixel * satd_bufs[NUM_TESTS][7][2];
|
2014-06-18 13:28:34 +00:00
|
|
|
|
|
|
|
static struct {
|
|
|
|
int log_width; // for selecting dim from satd_bufs
|
|
|
|
cost_pixel_nxn_func * tested_func;
|
|
|
|
} satd_test_env;
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// SETUP, TEARDOWN AND HELPER FUNCTIONS
|
|
|
|
static void setup_tests()
|
|
|
|
{
|
|
|
|
for (int test = 0; test < NUM_TESTS; ++test) {
|
2014-09-25 14:28:59 +00:00
|
|
|
for (int w = 0; w <= LCU_MIN_LOG_W; ++w) {
|
|
|
|
satd_bufs[test][w][0] = NULL;
|
|
|
|
satd_bufs[test][w][1] = NULL;
|
2014-06-18 13:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int w = LCU_MIN_LOG_W; w <= LCU_MAX_LOG_W; ++w) {
|
|
|
|
unsigned size = 1 << (w * 2);
|
2015-06-30 08:43:48 +00:00
|
|
|
satd_bufs[test][w][0] = malloc(size * sizeof(kvz_pixel));
|
|
|
|
satd_bufs[test][w][1] = malloc(size * sizeof(kvz_pixel));
|
2014-06-18 13:28:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-14 09:57:18 +00:00
|
|
|
//Black and white buffers
|
2014-06-18 13:28:34 +00:00
|
|
|
int test = 0;
|
|
|
|
for (int w = LCU_MIN_LOG_W; w <= LCU_MAX_LOG_W; ++w) {
|
|
|
|
unsigned size = 1 << (w * 2);
|
2015-02-13 09:56:55 +00:00
|
|
|
FILL_ARRAY(satd_bufs[test][w][0], 0, size);
|
|
|
|
FILL_ARRAY(satd_bufs[test][w][1], 255, size);
|
2014-06-18 13:28:34 +00:00
|
|
|
}
|
|
|
|
|
2014-07-14 09:57:18 +00:00
|
|
|
//Checker patterns, buffer 1 is negative of buffer 2
|
2014-06-18 13:28:34 +00:00
|
|
|
test = 1;
|
|
|
|
for (int w = LCU_MIN_LOG_W; w <= LCU_MAX_LOG_W; ++w) {
|
|
|
|
unsigned size = 1 << (w * 2);
|
|
|
|
for (int i = 0; i < size; ++i){
|
2014-07-14 09:57:18 +00:00
|
|
|
satd_bufs[test][w][0][i] = 255 * ( ( ((i >> w)%2) + (i % 2) ) % 2);
|
|
|
|
satd_bufs[test][w][1][i] = (satd_bufs[test][w][0][i] + 1) % 2 ;
|
2014-06-18 13:28:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-14 09:57:18 +00:00
|
|
|
//Gradient test pattern
|
2014-06-18 13:28:34 +00:00
|
|
|
test = 2;
|
|
|
|
for (int w = LCU_MIN_LOG_W; w <= LCU_MAX_LOG_W; ++w) {
|
|
|
|
unsigned size = 1 << (w * 2);
|
|
|
|
for (int i = 0; i < size; ++i){
|
|
|
|
int column = (i % (1 << w) );
|
|
|
|
int row = (i / (1 << w) );
|
|
|
|
int r = sqrt(row * row + column * column);
|
|
|
|
satd_bufs[test][w][0][i] = 255 / (r + 1);
|
|
|
|
satd_bufs[test][w][1][i] = 255 - 255 / (r + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void satd_tear_down_tests()
|
|
|
|
{
|
|
|
|
for (int test = 0; test < NUM_TESTS; ++test) {
|
|
|
|
for (int log_width = 2; log_width <= 6; ++log_width) {
|
|
|
|
free(satd_bufs[test][log_width][0]);
|
|
|
|
free(satd_bufs[test][log_width][1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// TESTS
|
|
|
|
|
|
|
|
TEST satd_test_black_and_white(void)
|
|
|
|
{
|
2014-10-29 13:42:16 +00:00
|
|
|
const int satd_results[5] = {2040, 4080, 16320, 65280, 261120};
|
2014-06-18 13:28:34 +00:00
|
|
|
|
|
|
|
const int test = 0;
|
|
|
|
|
2015-06-30 08:43:48 +00:00
|
|
|
kvz_pixel * buf1 = satd_bufs[test][satd_test_env.log_width][0];
|
|
|
|
kvz_pixel * buf2 = satd_bufs[test][satd_test_env.log_width][1];
|
2014-06-18 13:28:34 +00:00
|
|
|
|
|
|
|
unsigned result1 = satd_test_env.tested_func(buf1, buf2);
|
|
|
|
unsigned result2 = satd_test_env.tested_func(buf2, buf1);
|
|
|
|
|
2014-10-29 13:02:35 +00:00
|
|
|
ASSERT_EQ(result1, result2);
|
2014-06-18 13:28:34 +00:00
|
|
|
ASSERT_EQ(result1, satd_results[satd_test_env.log_width - 2]);
|
|
|
|
|
|
|
|
PASS();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST satd_test_checkers(void)
|
|
|
|
{
|
2014-10-29 13:42:16 +00:00
|
|
|
const int satd_checkers_results[5] = { 2040, 4080, 16320, 65280, 261120 };
|
2014-06-18 13:28:34 +00:00
|
|
|
|
|
|
|
const int test = 1;
|
|
|
|
|
2015-06-30 08:43:48 +00:00
|
|
|
kvz_pixel * buf1 = satd_bufs[test][satd_test_env.log_width][0];
|
|
|
|
kvz_pixel * buf2 = satd_bufs[test][satd_test_env.log_width][1];
|
2014-06-18 13:28:34 +00:00
|
|
|
|
2014-07-14 09:57:18 +00:00
|
|
|
unsigned result1 = satd_test_env.tested_func(buf1, buf2);
|
|
|
|
unsigned result2 = satd_test_env.tested_func(buf2, buf1);
|
2014-06-18 13:28:34 +00:00
|
|
|
|
2014-10-29 13:02:35 +00:00
|
|
|
ASSERT_EQ(result1, result2);
|
2014-07-14 09:57:18 +00:00
|
|
|
ASSERT_EQ(result1, satd_checkers_results[satd_test_env.log_width - 2]);
|
2014-06-18 13:28:34 +00:00
|
|
|
|
|
|
|
PASS();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST satd_test_gradient(void)
|
|
|
|
{
|
2014-10-29 13:42:16 +00:00
|
|
|
const int satd_gradient_results[5] = {3140,9004,20481,67262,258672};
|
2014-06-18 13:28:34 +00:00
|
|
|
|
|
|
|
const int test = 2;
|
|
|
|
|
2015-06-30 08:43:48 +00:00
|
|
|
kvz_pixel * buf1 = satd_bufs[test][satd_test_env.log_width][0];
|
|
|
|
kvz_pixel * buf2 = satd_bufs[test][satd_test_env.log_width][1];
|
2014-06-18 13:28:34 +00:00
|
|
|
|
|
|
|
unsigned result1 = satd_test_env.tested_func(buf1, buf2);
|
|
|
|
unsigned result2 = satd_test_env.tested_func(buf2, buf1);
|
|
|
|
|
2014-10-29 13:02:35 +00:00
|
|
|
ASSERT_EQ(result1, result2);
|
2014-06-18 13:28:34 +00:00
|
|
|
ASSERT_EQ(result1, satd_gradient_results[satd_test_env.log_width - 2]);
|
|
|
|
|
|
|
|
PASS();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// TEST FIXTURES
|
|
|
|
SUITE(satd_tests)
|
|
|
|
{
|
|
|
|
setup_tests();
|
|
|
|
|
|
|
|
// Loop through all strategies picking out the intra sad ones and run
|
|
|
|
// selectec strategies though all tests.
|
|
|
|
for (unsigned i = 0; i < strategies.count; ++i) {
|
|
|
|
const char * type = strategies.strategies[i].type;
|
|
|
|
|
2015-09-18 12:26:37 +00:00
|
|
|
if (strcmp(type, "satd_4x4") == 0) {
|
2014-06-18 13:28:34 +00:00
|
|
|
satd_test_env.log_width = 2;
|
|
|
|
}
|
2015-09-18 12:26:37 +00:00
|
|
|
else if (strcmp(type, "satd_8x8") == 0) {
|
2014-06-18 13:28:34 +00:00
|
|
|
satd_test_env.log_width = 3;
|
|
|
|
}
|
2015-09-18 12:26:37 +00:00
|
|
|
else if (strcmp(type, "satd_16x16") == 0) {
|
2014-06-18 13:28:34 +00:00
|
|
|
satd_test_env.log_width = 4;
|
|
|
|
}
|
2015-09-18 12:26:37 +00:00
|
|
|
else if (strcmp(type, "satd_32x32") == 0) {
|
2014-06-18 13:28:34 +00:00
|
|
|
satd_test_env.log_width = 5;
|
|
|
|
}
|
2015-09-18 12:26:37 +00:00
|
|
|
else if (strcmp(type, "satd_64x64") == 0) {
|
2014-06-18 13:28:34 +00:00
|
|
|
satd_test_env.log_width = 6;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
satd_test_env.tested_func = strategies.strategies[i].fptr;
|
|
|
|
|
|
|
|
// Tests
|
2014-07-14 09:57:18 +00:00
|
|
|
RUN_TEST(satd_test_black_and_white);
|
|
|
|
RUN_TEST(satd_test_checkers);
|
2014-06-18 13:28:34 +00:00
|
|
|
RUN_TEST(satd_test_gradient);
|
|
|
|
}
|
|
|
|
|
|
|
|
satd_tear_down_tests();
|
|
|
|
}
|