TUT HEVC Encoder
strategies-picture.h
Go to the documentation of this file.
1#ifndef STRATEGIES_PICTURE_H_
2#define STRATEGIES_PICTURE_H_
3/*****************************************************************************
4 * This file is part of Kvazaar HEVC encoder.
5 *
6 * Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
11 *
12 * * Redistributions of source code must retain the above copyright notice, this
13 * list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above copyright notice, this
16 * list of conditions and the following disclaimer in the documentation and/or
17 * other materials provided with the distribution.
18 *
19 * * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
30 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
33 ****************************************************************************/
34
41#include "global.h" // IWYU pragma: keep
42#include "inter.h"
43#include "kvazaar.h"
44#include "encoderstate.h"
46
47
48typedef kvz_pixel (*pred_buffer)[32 * 32];
49
50// Function macro for defining hadamard calculating functions
51// for fixed size blocks. They calculate hadamard for integer
52// multiples of 8x8 with the 8x8 hadamard function.
53#define SATD_NxN(suffix, n) \
54/* Declare the function in advance, hopefully reducing the probability that the
55 * macro expands to something unexpected and silently breaks things. */ \
56static cost_pixel_nxn_func satd_ ## n ## x ## n ## _ ## suffix;\
57static unsigned satd_ ## n ## x ## n ## _ ## suffix ( \
58 const kvz_pixel * const block1, \
59 const kvz_pixel * const block2) \
60{ \
61 unsigned sum = 0; \
62 for (unsigned y = 0; y < (n); y += 8) { \
63 unsigned row = y * (n); \
64 for (unsigned x = 0; x < (n); x += 8) { \
65 sum += satd_8x8_subblock_ ## suffix(&block1[row + x], (n), &block2[row + x], (n)); \
66 } \
67 } \
68 return sum >> (KVZ_BIT_DEPTH - 8); \
69}
70
71
72// Function macro for defining hadamard calculating functions for dynamic size
73// blocks. They calculate hadamard for integer multiples of 8x8 with the 8x8
74// hadamard function.
75#define SATD_ANY_SIZE(suffix) \
76 static cost_pixel_any_size_func satd_any_size_ ## suffix; \
77 static unsigned satd_any_size_ ## suffix ( \
78 int width, int height, \
79 const kvz_pixel *block1, int stride1, \
80 const kvz_pixel *block2, int stride2) \
81 { \
82 unsigned sum = 0; \
83 if (width % 8 != 0) { \
84 /* Process the first column using 4x4 blocks. */ \
85 for (int y = 0; y < height; y += 4) { \
86 sum += kvz_satd_4x4_subblock_ ## suffix(&block1[y * stride1], stride1, \
87 &block2[y * stride2], stride2); \
88 } \
89 block1 += 4; \
90 block2 += 4; \
91 width -= 4; \
92 } \
93 if (height % 8 != 0) { \
94 /* Process the first row using 4x4 blocks. */ \
95 for (int x = 0; x < width; x += 4) { \
96 sum += kvz_satd_4x4_subblock_ ## suffix(&block1[x], stride1, \
97 &block2[x], stride2); \
98 } \
99 block1 += 4 * stride1; \
100 block2 += 4 * stride2; \
101 height -= 4; \
102 } \
103 /* The rest can now be processed with 8x8 blocks. */ \
104 for (int y = 0; y < height; y += 8) { \
105 const kvz_pixel *row1 = &block1[y * stride1]; \
106 const kvz_pixel *row2 = &block2[y * stride2]; \
107 for (int x = 0; x < width; x += 8) { \
108 sum += satd_8x8_subblock_ ## suffix(&row1[x], stride1, \
109 &row2[x], stride2); \
110 } \
111 } \
112 return sum >> (KVZ_BIT_DEPTH - 8); \
113 }
115typedef unsigned(reg_sad_func)(const kvz_pixel *const data1, const kvz_pixel *const data2,
116 const int width, const int height,
117 const unsigned stride1, const unsigned stride2);
118typedef unsigned (cost_pixel_nxn_func)(const kvz_pixel *block1, const kvz_pixel *block2);
119typedef unsigned (cost_pixel_any_size_func)(
120 int width, int height,
121 const kvz_pixel *block1, int stride1,
122 const kvz_pixel *block2, int stride2
124typedef void (cost_pixel_nxn_multi_func)(const pred_buffer preds, const kvz_pixel *orig, unsigned num_modes, unsigned *costs_out);
125typedef 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);
127typedef 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);
129typedef uint32_t (ver_sad_func)(const kvz_pixel *pic_data, const kvz_pixel *ref_data,
130 int32_t block_width, int32_t block_height,
131 uint32_t pic_stride);
132typedef uint32_t (hor_sad_func)(const kvz_pixel *pic_data, const kvz_pixel *ref_data,
133 int32_t width, int32_t height, uint32_t pic_stride,
134 uint32_t ref_stride, uint32_t left, uint32_t right);
136typedef void (inter_recon_bipred_func)(lcu_t * const lcu,
137 const yuv_t *const px_L0,
138 const yuv_t *const px_L1,
139 const yuv_im_t *const im_L0,
140 const yuv_im_t *const im_L1,
141 const unsigned pu_x,
142 const unsigned pu_y,
143 const unsigned pu_w,
144 const unsigned pu_h,
145 const unsigned im_flags_L0,
146 const unsigned im_flags_L1,
147 const bool predict_luma,
148 const bool predict_chroma);
150typedef double (pixel_var_func)(const kvz_pixel *buf, const uint32_t len);
151
152// Declare function pointers.
154
160
167
173
179
181
183
185
189
191
192int kvz_strategy_register_picture(void* opaque, uint8_t bitdepth);
198#define STRATEGIES_PICTURE_EXPORTS \
199 {"reg_sad", (void**) &kvz_reg_sad}, \
200 {"sad_4x4", (void**) &kvz_sad_4x4}, \
201 {"sad_8x8", (void**) &kvz_sad_8x8}, \
202 {"sad_16x16", (void**) &kvz_sad_16x16}, \
203 {"sad_32x32", (void**) &kvz_sad_32x32}, \
204 {"sad_64x64", (void**) &kvz_sad_64x64}, \
205 {"satd_4x4", (void**) &kvz_satd_4x4}, \
206 {"satd_8x8", (void**) &kvz_satd_8x8}, \
207 {"satd_16x16", (void**) &kvz_satd_16x16}, \
208 {"satd_32x32", (void**) &kvz_satd_32x32}, \
209 {"satd_64x64", (void**) &kvz_satd_64x64}, \
210 {"satd_any_size", (void**) &kvz_satd_any_size}, \
211 {"sad_4x4_dual", (void**) &kvz_sad_4x4_dual}, \
212 {"sad_8x8_dual", (void**) &kvz_sad_8x8_dual}, \
213 {"sad_16x16_dual", (void**) &kvz_sad_16x16_dual}, \
214 {"sad_32x32_dual", (void**) &kvz_sad_32x32_dual}, \
215 {"sad_64x64_dual", (void**) &kvz_sad_64x64_dual}, \
216 {"satd_4x4_dual", (void**) &kvz_satd_4x4_dual}, \
217 {"satd_8x8_dual", (void**) &kvz_satd_8x8_dual}, \
218 {"satd_16x16_dual", (void**) &kvz_satd_16x16_dual}, \
219 {"satd_32x32_dual", (void**) &kvz_satd_32x32_dual}, \
220 {"satd_64x64_dual", (void**) &kvz_satd_64x64_dual}, \
221 {"satd_any_size_quad", (void**) &kvz_satd_any_size_quad}, \
222 {"pixels_calc_ssd", (void**) &kvz_pixels_calc_ssd}, \
223 {"bipred_average", (void**) &kvz_bipred_average}, \
224 {"get_optimized_sad", (void**) &kvz_get_optimized_sad}, \
225 {"ver_sad", (void**) &kvz_ver_sad}, \
226 {"hor_sad", (void**) &kvz_hor_sad}, \
227 {"pixel_var", (void**) &kvz_pixel_var}, \
228
229
230
231#endif //STRATEGIES_PICTURE_H_
Top level of the encoder implementation.
Header that is included in every other header.
Inter prediction.
This file defines the public API of Kvazaar when used as a library.
uint8_t kvz_pixel
Definition: kvazaar.h:95
uint32_t(* optimized_sad_func_ptr_t)(const kvz_pixel *const, const kvz_pixel *const, const int32_t, const uint32_t, const uint32_t)
Definition: optimized_sad_func_ptr_t.h:13
cost_pixel_nxn_func * kvz_pixels_get_sad_func(unsigned n)
Get a function that calculates SAD for NxN block.
Definition: strategies-picture.c:139
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)
Definition: strategies-picture.h:131
cost_pixel_nxn_multi_func * kvz_satd_32x32_dual
Definition: strategies-picture.c:67
kvz_pixel(* pred_buffer)[32 *32]
Definition: strategies-picture.h:48
pixels_calc_ssd_func * kvz_pixels_calc_ssd
Definition: strategies-picture.c:73
cost_pixel_nxn_func * kvz_satd_8x8
Definition: strategies-picture.c:53
void() cost_pixel_nxn_multi_func(const pred_buffer preds, const kvz_pixel *orig, unsigned num_modes, unsigned *costs_out)
Definition: strategies-picture.h:123
cost_pixel_nxn_func * kvz_sad_8x8
Definition: strategies-picture.c:47
void() inter_recon_bipred_func(lcu_t *const lcu, const yuv_t *const px_L0, const yuv_t *const px_L1, const yuv_im_t *const im_L0, const yuv_im_t *const im_L1, const unsigned pu_x, const unsigned pu_y, const unsigned pu_w, const unsigned pu_h, const unsigned im_flags_L0, const unsigned im_flags_L1, const bool predict_luma, const bool predict_chroma)
Definition: strategies-picture.h:135
cost_pixel_nxn_multi_func * kvz_sad_8x8_dual
Definition: strategies-picture.c:59
double() pixel_var_func(const kvz_pixel *buf, const uint32_t len)
Definition: strategies-picture.h:149
cost_pixel_nxn_multi_func * kvz_sad_32x32_dual
Definition: strategies-picture.c:61
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)
Definition: strategies-picture.h:124
reg_sad_func * kvz_reg_sad
Definition: strategies-picture.c:44
optimized_sad_func_ptr_t() get_optimized_sad_func(int32_t)
Definition: strategies-picture.h:127
get_optimized_sad_func * kvz_get_optimized_sad
Definition: strategies-picture.c:77
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)
Definition: strategies-picture.h:126
cost_pixel_any_size_multi_func * kvz_satd_any_size_quad
Definition: strategies-picture.c:71
cost_pixel_nxn_multi_func * kvz_sad_4x4_dual
Definition: strategies-picture.c:58
cost_pixel_nxn_func * kvz_satd_32x32
Definition: strategies-picture.c:55
cost_pixel_any_size_func * kvz_satd_any_size
Definition: strategies-picture.c:70
cost_pixel_nxn_func * kvz_sad_64x64
Definition: strategies-picture.c:50
cost_pixel_nxn_func * kvz_pixels_get_satd_func(unsigned n)
Get a function that calculates SATD for NxN block.
Definition: strategies-picture.c:113
cost_pixel_nxn_multi_func * kvz_satd_8x8_dual
Definition: strategies-picture.c:65
cost_pixel_nxn_multi_func * kvz_pixels_get_satd_dual_func(unsigned n)
Get a function that calculates SATDs for 2 NxN blocks.
Definition: strategies-picture.c:164
hor_sad_func * kvz_hor_sad
Definition: strategies-picture.c:79
unsigned() cost_pixel_any_size_func(int width, int height, const kvz_pixel *block1, int stride1, const kvz_pixel *block2, int stride2)
Definition: strategies-picture.h:118
cost_pixel_nxn_multi_func * kvz_satd_64x64_dual
Definition: strategies-picture.c:68
pixel_var_func * kvz_pixel_var
Definition: strategies-picture.c:81
int kvz_strategy_register_picture(void *opaque, uint8_t bitdepth)
Definition: strategies-picture.c:84
unsigned() cost_pixel_nxn_func(const kvz_pixel *block1, const kvz_pixel *block2)
Definition: strategies-picture.h:117
cost_pixel_nxn_multi_func * kvz_sad_64x64_dual
Definition: strategies-picture.c:62
cost_pixel_nxn_func * kvz_satd_64x64
Definition: strategies-picture.c:56
cost_pixel_nxn_func * kvz_satd_16x16
Definition: strategies-picture.c:54
cost_pixel_nxn_multi_func * kvz_sad_16x16_dual
Definition: strategies-picture.c:60
cost_pixel_nxn_multi_func * kvz_satd_16x16_dual
Definition: strategies-picture.c:66
ver_sad_func * kvz_ver_sad
Definition: strategies-picture.c:78
inter_recon_bipred_func * kvz_bipred_average
Definition: strategies-picture.c:75
unsigned() reg_sad_func(const kvz_pixel *const data1, const kvz_pixel *const data2, const int width, const int height, const unsigned stride1, const unsigned stride2)
Definition: strategies-picture.h:114
cost_pixel_nxn_func * kvz_sad_32x32
Definition: strategies-picture.c:49
cost_pixel_nxn_func * kvz_sad_16x16
Definition: strategies-picture.c:48
cost_pixel_nxn_multi_func * kvz_satd_4x4_dual
Definition: strategies-picture.c:64
cost_pixel_nxn_func * kvz_sad_4x4
Definition: strategies-picture.c:46
cost_pixel_nxn_func * kvz_satd_4x4
Definition: strategies-picture.c:52
cost_pixel_nxn_multi_func * kvz_pixels_get_sad_dual_func(unsigned n)
Get a function that calculates SADs for 2 NxN blocks.
Definition: strategies-picture.c:190
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)
Definition: strategies-picture.h:128
Definition: cu.h:299
Definition: image.h:61
Definition: image.h:54