2014-04-29 08:14:42 +00:00
|
|
|
#ifndef STRATEGIES_PICTURE_H_
|
|
|
|
#define STRATEGIES_PICTURE_H_
|
|
|
|
/*****************************************************************************
|
|
|
|
* This file is part of Kvazaar HEVC encoder.
|
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Copyright (C) 2013-2015 Tampere University of Technology and others (see
|
2014-04-29 08:14:42 +00:00
|
|
|
* COPYING file).
|
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Kvazaar is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License, or (at your
|
|
|
|
* option) any later version.
|
2014-04-29 08:14:42 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* 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.
|
2014-04-29 08:14:42 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-29 08:14:42 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-12-17 11:42:57 +00:00
|
|
|
/**
|
|
|
|
* \ingroup Optimization
|
|
|
|
* \file
|
|
|
|
* Interface for distortion metric functions.
|
|
|
|
*/
|
|
|
|
|
2016-03-30 09:41:37 +00:00
|
|
|
#include "global.h" // IWYU pragma: keep
|
2019-09-02 14:09:07 +00:00
|
|
|
#include "inter.h"
|
2016-04-01 14:14:23 +00:00
|
|
|
#include "kvazaar.h"
|
2018-04-18 12:25:44 +00:00
|
|
|
#include "encoderstate.h"
|
2019-01-21 15:20:51 +00:00
|
|
|
#include "strategies/optimized_sad_func_ptr_t.h"
|
2016-01-22 13:07:49 +00:00
|
|
|
|
2014-04-29 08:14:42 +00:00
|
|
|
|
2015-11-13 12:41:53 +00:00
|
|
|
typedef kvz_pixel (*pred_buffer)[32 * 32];
|
2014-06-16 09:13:41 +00:00
|
|
|
|
2015-11-23 12:20:44 +00:00
|
|
|
// Function macro for defining hadamard calculating functions
|
|
|
|
// for fixed size blocks. They calculate hadamard for integer
|
|
|
|
// multiples of 8x8 with the 8x8 hadamard function.
|
|
|
|
#define SATD_NxN(suffix, n) \
|
|
|
|
/* Declare the function in advance, hopefully reducing the probability that the
|
|
|
|
* macro expands to something unexpected and silently breaks things. */ \
|
|
|
|
static cost_pixel_nxn_func satd_ ## n ## x ## n ## _ ## suffix;\
|
|
|
|
static unsigned satd_ ## n ## x ## n ## _ ## suffix ( \
|
|
|
|
const kvz_pixel * const block1, \
|
|
|
|
const kvz_pixel * const block2) \
|
|
|
|
{ \
|
|
|
|
unsigned sum = 0; \
|
|
|
|
for (unsigned y = 0; y < (n); y += 8) { \
|
|
|
|
unsigned row = y * (n); \
|
|
|
|
for (unsigned x = 0; x < (n); x += 8) { \
|
|
|
|
sum += satd_8x8_subblock_ ## suffix(&block1[row + x], (n), &block2[row + x], (n)); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return sum >> (KVZ_BIT_DEPTH - 8); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-08 10:21:22 +00:00
|
|
|
// Function macro for defining hadamard calculating functions for dynamic size
|
|
|
|
// blocks. They calculate hadamard for integer multiples of 8x8 with the 8x8
|
|
|
|
// hadamard function.
|
|
|
|
#define SATD_ANY_SIZE(suffix) \
|
2015-12-08 10:43:10 +00:00
|
|
|
static cost_pixel_any_size_func satd_any_size_ ## suffix; \
|
2015-12-08 10:21:22 +00:00
|
|
|
static unsigned satd_any_size_ ## suffix ( \
|
|
|
|
int width, int height, \
|
|
|
|
const kvz_pixel *block1, int stride1, \
|
|
|
|
const kvz_pixel *block2, int stride2) \
|
|
|
|
{ \
|
|
|
|
unsigned sum = 0; \
|
2016-06-15 03:18:32 +00:00
|
|
|
if (width % 8 != 0) { \
|
|
|
|
/* Process the first column using 4x4 blocks. */ \
|
|
|
|
for (int y = 0; y < height; y += 4) { \
|
|
|
|
sum += kvz_satd_4x4_subblock_ ## suffix(&block1[y * stride1], stride1, \
|
|
|
|
&block2[y * stride2], stride2); \
|
|
|
|
} \
|
|
|
|
block1 += 4; \
|
|
|
|
block2 += 4; \
|
|
|
|
width -= 4; \
|
|
|
|
} \
|
|
|
|
if (height % 8 != 0) { \
|
|
|
|
/* Process the first row using 4x4 blocks. */ \
|
|
|
|
for (int x = 0; x < width; x += 4) { \
|
|
|
|
sum += kvz_satd_4x4_subblock_ ## suffix(&block1[x], stride1, \
|
|
|
|
&block2[x], stride2); \
|
|
|
|
} \
|
|
|
|
block1 += 4 * stride1; \
|
|
|
|
block2 += 4 * stride2; \
|
|
|
|
height -= 4; \
|
|
|
|
} \
|
|
|
|
/* The rest can now be processed with 8x8 blocks. */ \
|
2015-12-08 10:21:22 +00:00
|
|
|
for (int y = 0; y < height; y += 8) { \
|
|
|
|
const kvz_pixel *row1 = &block1[y * stride1]; \
|
|
|
|
const kvz_pixel *row2 = &block2[y * stride2]; \
|
|
|
|
for (int x = 0; x < width; x += 8) { \
|
2016-06-15 03:18:32 +00:00
|
|
|
sum += satd_8x8_subblock_ ## suffix(&row1[x], stride1, \
|
|
|
|
&row2[x], stride2); \
|
2015-12-08 10:21:22 +00:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return sum >> (KVZ_BIT_DEPTH - 8); \
|
|
|
|
}
|
|
|
|
|
2015-06-30 08:43:48 +00:00
|
|
|
typedef unsigned(reg_sad_func)(const kvz_pixel *const data1, const kvz_pixel *const data2,
|
2014-06-16 09:13:41 +00:00
|
|
|
const int width, const int height,
|
|
|
|
const unsigned stride1, const unsigned stride2);
|
2015-06-30 08:43:48 +00:00
|
|
|
typedef unsigned (cost_pixel_nxn_func)(const kvz_pixel *block1, const kvz_pixel *block2);
|
2015-12-08 10:43:10 +00:00
|
|
|
typedef unsigned (cost_pixel_any_size_func)(
|
|
|
|
int width, int height,
|
|
|
|
const kvz_pixel *block1, int stride1,
|
|
|
|
const kvz_pixel *block2, int stride2
|
|
|
|
);
|
2015-11-13 12:41:53 +00:00
|
|
|
typedef void (cost_pixel_nxn_multi_func)(const pred_buffer preds, const kvz_pixel *orig, unsigned num_modes, unsigned *costs_out);
|
2018-11-04 19:04:17 +00:00
|
|
|
typedef void (cost_pixel_any_size_multi_func)(int width, int height, const kvz_pixel **preds, const int stride, const kvz_pixel *orig, const int orig_stride, unsigned num_modes, unsigned *costs_out, int8_t *valid);
|
2014-06-16 09:13:41 +00:00
|
|
|
|
2016-10-20 12:37:15 +00:00
|
|
|
typedef unsigned (pixels_calc_ssd_func)(const kvz_pixel *const ref, const kvz_pixel *const rec, const int ref_stride, const int rec_stride, const int width);
|
2019-01-18 15:32:52 +00:00
|
|
|
typedef optimized_sad_func_ptr_t (get_optimized_sad_func)(int32_t);
|
2019-01-22 13:57:16 +00:00
|
|
|
typedef uint32_t (ver_sad_func)(const kvz_pixel *pic_data, const kvz_pixel *ref_data,
|
|
|
|
int32_t block_width, int32_t block_height,
|
|
|
|
uint32_t pic_stride);
|
2019-01-22 19:27:21 +00:00
|
|
|
typedef uint32_t (hor_sad_func)(const kvz_pixel *pic_data, const kvz_pixel *ref_data,
|
|
|
|
int32_t width, int32_t height, uint32_t pic_stride,
|
|
|
|
uint32_t ref_stride, uint32_t left, uint32_t right);
|
2018-04-18 12:25:44 +00:00
|
|
|
|
|
|
|
typedef void (inter_recon_bipred_func)(const int hi_prec_luma_rec0,
|
2020-01-27 11:11:31 +00:00
|
|
|
const int hi_prec_luma_rec1,
|
|
|
|
const int hi_prec_chroma_rec0,
|
|
|
|
const int hi_prec_chroma_rec1,
|
|
|
|
int height,
|
|
|
|
int width,
|
|
|
|
int ypos,
|
|
|
|
int xpos,
|
|
|
|
const hi_prec_buf_t*high_precision_rec0,
|
|
|
|
const hi_prec_buf_t*high_precision_rec1,
|
|
|
|
lcu_t* lcu,
|
|
|
|
kvz_pixel temp_lcu_y[LCU_WIDTH*LCU_WIDTH],
|
|
|
|
kvz_pixel temp_lcu_u[LCU_WIDTH_C*LCU_WIDTH_C],
|
|
|
|
kvz_pixel temp_lcu_v[LCU_WIDTH_C*LCU_WIDTH_C],
|
2019-09-02 14:09:07 +00:00
|
|
|
bool predict_luma,
|
2020-01-27 11:11:31 +00:00
|
|
|
bool predict_chroma);
|
2018-04-18 12:25:44 +00:00
|
|
|
|
2020-02-24 17:37:36 +00:00
|
|
|
typedef double (pixel_var_func)(const kvz_pixel *buf, const uint32_t len);
|
|
|
|
|
2014-06-16 09:13:41 +00:00
|
|
|
// Declare function pointers.
|
2015-08-26 08:50:27 +00:00
|
|
|
extern reg_sad_func * kvz_reg_sad;
|
2014-06-16 09:13:41 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
extern cost_pixel_nxn_func * kvz_sad_4x4;
|
|
|
|
extern cost_pixel_nxn_func * kvz_sad_8x8;
|
|
|
|
extern cost_pixel_nxn_func * kvz_sad_16x16;
|
|
|
|
extern cost_pixel_nxn_func * kvz_sad_32x32;
|
|
|
|
extern cost_pixel_nxn_func * kvz_sad_64x64;
|
2014-06-16 09:13:41 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
extern cost_pixel_nxn_func * kvz_satd_4x4;
|
|
|
|
extern cost_pixel_nxn_func * kvz_satd_8x8;
|
|
|
|
extern cost_pixel_nxn_func * kvz_satd_16x16;
|
|
|
|
extern cost_pixel_nxn_func * kvz_satd_32x32;
|
|
|
|
extern cost_pixel_nxn_func * kvz_satd_64x64;
|
2015-12-08 10:43:10 +00:00
|
|
|
extern cost_pixel_any_size_func *kvz_satd_any_size;
|
2014-06-13 07:20:02 +00:00
|
|
|
|
2015-11-13 12:41:53 +00:00
|
|
|
extern cost_pixel_nxn_multi_func * kvz_sad_4x4_dual;
|
|
|
|
extern cost_pixel_nxn_multi_func * kvz_sad_8x8_dual;
|
|
|
|
extern cost_pixel_nxn_multi_func * kvz_sad_16x16_dual;
|
|
|
|
extern cost_pixel_nxn_multi_func * kvz_sad_32x32_dual;
|
|
|
|
extern cost_pixel_nxn_multi_func * kvz_sad_64x64_dual;
|
|
|
|
|
|
|
|
extern cost_pixel_nxn_multi_func * kvz_satd_4x4_dual;
|
|
|
|
extern cost_pixel_nxn_multi_func * kvz_satd_8x8_dual;
|
|
|
|
extern cost_pixel_nxn_multi_func * kvz_satd_16x16_dual;
|
|
|
|
extern cost_pixel_nxn_multi_func * kvz_satd_32x32_dual;
|
|
|
|
extern cost_pixel_nxn_multi_func * kvz_satd_64x64_dual;
|
|
|
|
|
2016-06-27 14:06:32 +00:00
|
|
|
extern cost_pixel_any_size_multi_func *kvz_satd_any_size_quad;
|
2014-06-13 07:20:02 +00:00
|
|
|
|
2016-10-20 12:37:15 +00:00
|
|
|
extern pixels_calc_ssd_func *kvz_pixels_calc_ssd;
|
|
|
|
|
2018-08-28 12:31:10 +00:00
|
|
|
extern inter_recon_bipred_func * kvz_inter_recon_bipred_blend;
|
2018-04-18 12:25:44 +00:00
|
|
|
|
2019-01-18 15:32:52 +00:00
|
|
|
extern get_optimized_sad_func *kvz_get_optimized_sad;
|
2019-01-22 13:57:16 +00:00
|
|
|
extern ver_sad_func *kvz_ver_sad;
|
2019-01-22 19:27:21 +00:00
|
|
|
extern hor_sad_func *kvz_hor_sad;
|
2019-01-18 15:32:52 +00:00
|
|
|
|
2020-02-24 17:37:36 +00:00
|
|
|
extern pixel_var_func *kvz_pixel_var;
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
int kvz_strategy_register_picture(void* opaque, uint8_t bitdepth);
|
|
|
|
cost_pixel_nxn_func * kvz_pixels_get_satd_func(unsigned n);
|
|
|
|
cost_pixel_nxn_func * kvz_pixels_get_sad_func(unsigned n);
|
2015-11-13 12:41:53 +00:00
|
|
|
cost_pixel_nxn_multi_func * kvz_pixels_get_satd_dual_func(unsigned n);
|
|
|
|
cost_pixel_nxn_multi_func * kvz_pixels_get_sad_dual_func(unsigned n);
|
2014-06-16 09:13:41 +00:00
|
|
|
|
|
|
|
#define STRATEGIES_PICTURE_EXPORTS \
|
2015-08-26 08:50:27 +00:00
|
|
|
{"reg_sad", (void**) &kvz_reg_sad}, \
|
|
|
|
{"sad_4x4", (void**) &kvz_sad_4x4}, \
|
|
|
|
{"sad_8x8", (void**) &kvz_sad_8x8}, \
|
|
|
|
{"sad_16x16", (void**) &kvz_sad_16x16}, \
|
|
|
|
{"sad_32x32", (void**) &kvz_sad_32x32}, \
|
|
|
|
{"sad_64x64", (void**) &kvz_sad_64x64}, \
|
|
|
|
{"satd_4x4", (void**) &kvz_satd_4x4}, \
|
|
|
|
{"satd_8x8", (void**) &kvz_satd_8x8}, \
|
|
|
|
{"satd_16x16", (void**) &kvz_satd_16x16}, \
|
|
|
|
{"satd_32x32", (void**) &kvz_satd_32x32}, \
|
|
|
|
{"satd_64x64", (void**) &kvz_satd_64x64}, \
|
2015-12-08 10:21:22 +00:00
|
|
|
{"satd_any_size", (void**) &kvz_satd_any_size}, \
|
2015-11-13 12:41:53 +00:00
|
|
|
{"sad_4x4_dual", (void**) &kvz_sad_4x4_dual}, \
|
|
|
|
{"sad_8x8_dual", (void**) &kvz_sad_8x8_dual}, \
|
|
|
|
{"sad_16x16_dual", (void**) &kvz_sad_16x16_dual}, \
|
|
|
|
{"sad_32x32_dual", (void**) &kvz_sad_32x32_dual}, \
|
|
|
|
{"sad_64x64_dual", (void**) &kvz_sad_64x64_dual}, \
|
|
|
|
{"satd_4x4_dual", (void**) &kvz_satd_4x4_dual}, \
|
|
|
|
{"satd_8x8_dual", (void**) &kvz_satd_8x8_dual}, \
|
|
|
|
{"satd_16x16_dual", (void**) &kvz_satd_16x16_dual}, \
|
|
|
|
{"satd_32x32_dual", (void**) &kvz_satd_32x32_dual}, \
|
|
|
|
{"satd_64x64_dual", (void**) &kvz_satd_64x64_dual}, \
|
2016-06-27 14:06:32 +00:00
|
|
|
{"satd_any_size_quad", (void**) &kvz_satd_any_size_quad}, \
|
2016-10-20 12:37:15 +00:00
|
|
|
{"pixels_calc_ssd", (void**) &kvz_pixels_calc_ssd}, \
|
2018-08-28 12:31:10 +00:00
|
|
|
{"inter_recon_bipred", (void**) &kvz_inter_recon_bipred_blend}, \
|
2019-01-18 15:32:52 +00:00
|
|
|
{"get_optimized_sad", (void**) &kvz_get_optimized_sad}, \
|
2019-01-22 13:57:16 +00:00
|
|
|
{"ver_sad", (void**) &kvz_ver_sad}, \
|
2019-01-22 19:27:21 +00:00
|
|
|
{"hor_sad", (void**) &kvz_hor_sad}, \
|
2020-02-24 17:37:36 +00:00
|
|
|
{"pixel_var", (void**) &kvz_pixel_var}, \
|
2014-06-13 07:20:02 +00:00
|
|
|
|
2014-04-29 08:14:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif //STRATEGIES_PICTURE_H_
|