2015-02-23 11:18:48 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* This file is part of Kvazaar HEVC encoder.
|
|
|
|
*
|
2021-10-07 08:32:59 +00:00
|
|
|
* Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
* other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
2015-02-23 11:18:48 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-16 15:01:55 +00:00
|
|
|
#include "greatest/greatest.h"
|
|
|
|
|
2014-07-28 12:49:51 +00:00
|
|
|
#include "test_strategies.h"
|
|
|
|
|
2014-06-16 15:01:55 +00:00
|
|
|
#include "src/image.h"
|
|
|
|
#include "src/strategyselector.h"
|
|
|
|
|
2014-07-28 09:29:33 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2014-06-16 15:01:55 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// MACROS
|
2014-07-28 09:29:33 +00:00
|
|
|
#define NUM_TESTS 2
|
2014-06-16 15:01:55 +00:00
|
|
|
#define LCU_MAX_LOG_W 6
|
|
|
|
#define LCU_MIN_LOG_W 2
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GLOBALS
|
2015-07-01 06:52:39 +00:00
|
|
|
static kvz_pixel * bufs[NUM_TESTS][7][2];
|
2014-06-16 15:01:55 +00:00
|
|
|
|
|
|
|
static struct {
|
|
|
|
int log_width; // for selecting dim from bufs
|
|
|
|
cost_pixel_nxn_func * tested_func;
|
|
|
|
} test_env;
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// SETUP, TEARDOWN AND HELPER FUNCTIONS
|
2015-06-30 08:43:48 +00:00
|
|
|
static void init_gradient(int x_px, int y_px, int width, int slope, kvz_pixel *buf)
|
2014-07-28 09:29:33 +00:00
|
|
|
{
|
|
|
|
for (int y = 0; y < width; ++y) {
|
|
|
|
for (int x = 0; x < width; ++x) {
|
|
|
|
int diff_x = x_px - x;
|
|
|
|
int diff_y = y_px - y;
|
|
|
|
int val = sqrt(diff_x * diff_x + diff_y * diff_y) + 0.5 + slope;
|
|
|
|
buf[y * width + x] = CLIP(0, 255, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-16 15:01:55 +00:00
|
|
|
static void setup_tests()
|
|
|
|
{
|
|
|
|
for (int test = 0; test < NUM_TESTS; ++test) {
|
|
|
|
for (int w = LCU_MIN_LOG_W; w <= LCU_MAX_LOG_W; ++w) {
|
|
|
|
bufs[test][w][0] = 0;
|
|
|
|
bufs[test][w][1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
bufs[test][w][0] = malloc(size * sizeof(kvz_pixel) + SIMD_ALIGNMENT);
|
2014-07-14 13:08:19 +00:00
|
|
|
bufs[test][w][0] = ALIGNED_POINTER(bufs[test][w][0], SIMD_ALIGNMENT);
|
|
|
|
|
2015-06-30 08:43:48 +00:00
|
|
|
bufs[test][w][1] = malloc(size * sizeof(kvz_pixel) + SIMD_ALIGNMENT);
|
2014-07-14 13:08:19 +00:00
|
|
|
bufs[test][w][1] = ALIGNED_POINTER(bufs[test][w][1], SIMD_ALIGNMENT);
|
2014-06-16 15:01:55 +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(bufs[test][w][0], 0, size);
|
|
|
|
FILL_ARRAY(bufs[test][w][1], 255, size);
|
2014-06-16 15:01:55 +00:00
|
|
|
}
|
2014-07-28 09:29:33 +00:00
|
|
|
|
|
|
|
test = 1;
|
|
|
|
for (int w = LCU_MIN_LOG_W; w <= LCU_MAX_LOG_W; ++w) {
|
|
|
|
unsigned width = 1 << w;
|
|
|
|
unsigned size = 1 << (w * 2);
|
|
|
|
init_gradient(3, 1, width, 1, bufs[test][w][0]);
|
|
|
|
//init_gradient(width / 2, 0, width, 1, bufs[test][w][1]);
|
2015-02-13 09:56:55 +00:00
|
|
|
FILL_ARRAY(bufs[test][w][1], 128, size);
|
2014-07-28 09:29:33 +00:00
|
|
|
}
|
2014-06-16 15:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tear_down_tests()
|
|
|
|
{
|
|
|
|
for (int test = 0; test < NUM_TESTS; ++test) {
|
|
|
|
for (int log_width = 2; log_width <= 6; ++log_width) {
|
2014-07-14 13:08:19 +00:00
|
|
|
//free(bufs[test][log_width][0]);
|
|
|
|
//free(bufs[test][log_width][1]);
|
2014-06-16 15:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-30 08:43:48 +00:00
|
|
|
static unsigned test_calc_sad(const kvz_pixel * buf1, const kvz_pixel * buf2, int dim)
|
2014-06-16 15:01:55 +00:00
|
|
|
{
|
|
|
|
unsigned result = 0;
|
|
|
|
for (int i = 0; i < dim * dim; ++i) {
|
|
|
|
result += abs(buf1[i] - buf2[i]);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// TESTS
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the maximum SAD value for a given buffer size doesn't overflow.
|
|
|
|
*/
|
|
|
|
TEST test_black_and_white(void)
|
|
|
|
{
|
|
|
|
const int test = 0;
|
|
|
|
const int width = 1 << test_env.log_width;
|
|
|
|
|
2015-06-30 08:43:48 +00:00
|
|
|
kvz_pixel * buf1 = bufs[test][test_env.log_width][0];
|
|
|
|
kvz_pixel * buf2 = bufs[test][test_env.log_width][1];
|
2014-06-16 15:01:55 +00:00
|
|
|
|
|
|
|
unsigned result1 = test_env.tested_func(buf1, buf2);
|
|
|
|
unsigned result2 = test_env.tested_func(buf2, buf1);
|
|
|
|
|
|
|
|
// Order of parameters must not matter.
|
|
|
|
ASSERT_EQ(result1, result2);
|
|
|
|
|
|
|
|
// Result matches trivial implementation.
|
|
|
|
ASSERT_EQ(result1, 255 * width * width);
|
|
|
|
|
|
|
|
PASS();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-28 09:29:33 +00:00
|
|
|
/**
|
|
|
|
* Test that the maximum SAD value for a given buffer size doesn't overflow.
|
|
|
|
*/
|
|
|
|
TEST test_gradient(void)
|
|
|
|
{
|
|
|
|
const int test = 1;
|
|
|
|
const int width = 1 << test_env.log_width;
|
|
|
|
|
2015-06-30 08:43:48 +00:00
|
|
|
kvz_pixel * buf1 = bufs[test][test_env.log_width][0];
|
|
|
|
kvz_pixel * buf2 = bufs[test][test_env.log_width][1];
|
2014-07-28 09:29:33 +00:00
|
|
|
|
|
|
|
unsigned result = test_calc_sad(buf1, buf2, width);
|
|
|
|
unsigned result1 = test_env.tested_func(buf1, buf2);
|
|
|
|
unsigned result2 = test_env.tested_func(buf2, buf1);
|
|
|
|
|
|
|
|
// Order of parameters must not matter.
|
|
|
|
ASSERT_EQ(result1, result2);
|
|
|
|
|
|
|
|
// Result matches trivial implementation.
|
|
|
|
ASSERT_EQ(result1, result);
|
|
|
|
|
|
|
|
PASS();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-16 15:01:55 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// TEST FIXTURES
|
|
|
|
SUITE(intra_sad_tests)
|
|
|
|
{
|
|
|
|
//SET_SETUP(sad_setup);
|
|
|
|
//SET_TEARDOWN(sad_teardown);
|
|
|
|
|
|
|
|
setup_tests();
|
|
|
|
|
|
|
|
// Loop through all strategies picking out the intra sad ones and run
|
|
|
|
// selectec strategies though all tests.
|
2017-07-24 09:15:17 +00:00
|
|
|
for (volatile unsigned i = 0; i < strategies.count; ++i) {
|
2014-06-16 15:01:55 +00:00
|
|
|
const char * type = strategies.strategies[i].type;
|
|
|
|
|
2015-09-18 12:26:37 +00:00
|
|
|
if (strcmp(type, "sad_4x4") == 0) {
|
2014-06-16 15:01:55 +00:00
|
|
|
test_env.log_width = 2;
|
2015-09-18 12:26:37 +00:00
|
|
|
} else if (strcmp(type, "sad_8x8") == 0) {
|
2014-06-16 15:01:55 +00:00
|
|
|
test_env.log_width = 3;
|
2015-09-18 12:26:37 +00:00
|
|
|
} else if (strcmp(type, "sad_16x16") == 0) {
|
2014-06-16 15:01:55 +00:00
|
|
|
test_env.log_width = 4;
|
2015-09-18 12:26:37 +00:00
|
|
|
} else if (strcmp(type, "sad_32x32") == 0) {
|
2014-06-16 15:01:55 +00:00
|
|
|
test_env.log_width = 5;
|
2015-09-18 12:26:37 +00:00
|
|
|
} else if (strcmp(type, "sad_64x64") == 0) {
|
2014-06-16 15:01:55 +00:00
|
|
|
test_env.log_width = 6;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_env.tested_func = strategies.strategies[i].fptr;
|
|
|
|
|
|
|
|
// Tests
|
|
|
|
RUN_TEST(test_black_and_white);
|
2014-07-28 09:29:33 +00:00
|
|
|
RUN_TEST(test_gradient);
|
2014-06-16 15:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tear_down_tests();
|
|
|
|
}
|