TUT HEVC Encoder
Loading...
Searching...
No Matches
sao_shared_generics.h
Go to the documentation of this file.
1/*****************************************************************************
2 * This file is part of Kvazaar HEVC encoder.
3 *
4 * Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice, this
14 * list of conditions and the following disclaimer in the documentation and/or
15 * other materials provided with the distribution.
16 *
17 * * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 ****************************************************************************/
32
33#ifndef SAO_BAND_DDISTORTION_H_
34#define SAO_BAND_DDISTORTION_H_
35
36// #include "encoder.h"
37#include "encoderstate.h"
38#include "kvazaar.h"
39#include "sao.h"
40
41// Mapping of edge_idx values to eo-classes.
43{
44 // Mapping relationships between a, b and c to eo_idx.
45 static const int sao_eo_idx_to_eo_category[] = { 1, 2, 0, 3, 4 };
46
47 int eo_idx = 2 + SIGN3((int)c - (int)a) + SIGN3((int)c - (int)b);
48
50}
51
52static int sao_edge_ddistortion_generic(const encoder_control_t* const encoder,
53 const kvz_pixel *orig_data,
54 const kvz_pixel *rec_data,
57 int32_t eo_class,
58 const int32_t offsets[NUM_SAO_EDGE_CATEGORIES])
59{
60 int y, x;
61 int32_t sum = 0;
62 vector2d_t a_ofs = g_sao_edge_offsets[eo_class][0];
63 vector2d_t b_ofs = g_sao_edge_offsets[eo_class][1];
64
65 const int bit_offset = encoder->bitdepth != 8 ? 1 << (encoder->bitdepth - 9) : 0;
66
67 for (y = 1; y < block_height - 1; y++) {
68 for (x = 1; x < block_width - 1; x++) {
69 uint32_t c_pos = y * block_width + x;
70 uint32_t a_pos = (y + a_ofs.y) * block_width + x + a_ofs.x;
71 uint32_t b_pos = (y + b_ofs.y) * block_width + x + b_ofs.x;
72
77
79 int32_t offset = offsets[eo_cat];
80
81 if (offset != 0) {
82 int32_t diff = (orig - c + bit_offset) >> (encoder->bitdepth - 8);
85
86 sum += curr;
87 }
88 }
89 }
90 return sum;
91}
92
93static int sao_band_ddistortion_generic(const encoder_state_t * const state,
94 const kvz_pixel *orig_data,
95 const kvz_pixel *rec_data,
96 int block_width,
97 int block_height,
98 int band_pos,
99 const int sao_bands[4])
100{
101 int y, x;
102 int shift = state->encoder_control->bitdepth-5;
103 int sum = 0;
104 for (y = 0; y < block_height; ++y) {
105 for (x = 0; x < block_width; ++x) {
106 const int32_t curr_pos = y * block_width + x;
107
110
111 int32_t band = (rec >> shift) - band_pos;
112 int32_t offset = 0;
113 if (band >= 0 && band <= 3) {
115 }
116 // Offset is applied to reconstruction, so it is subtracted from diff.
117
118 int32_t diff = orig - rec;
120
121 int32_t dmask = (offset == 0) ? -1 : 0;
122 diff &= ~dmask;
123 delta &= ~dmask;
124
125 sum += delta * delta - diff * diff;
126 }
127 }
128
129 return sum;
130}
131
132#endif
Top level of the encoder implementation.
#define MAX_TILES_PER_DIM
Definition global.h:232
#define SIGN3(x)
Definition global.h:216
This file defines the public API of Kvazaar when used as a library.
uint8_t kvz_pixel
Definition kvazaar.h:95
Sample Adaptive Offset filter.
static const vector2d_t g_sao_edge_offsets[SAO_NUM_EO][2]
Definition sao.h:71
@ NUM_SAO_EDGE_CATEGORIES
Definition sao.h:52
static int sao_band_ddistortion_generic(const encoder_state_t *const state, const kvz_pixel *orig_data, const kvz_pixel *rec_data, int block_width, int block_height, int band_pos, const int sao_bands[4])
Definition sao_shared_generics.h:93
static int sao_calc_eo_cat(kvz_pixel a, kvz_pixel b, kvz_pixel c)
Definition sao_shared_generics.h:42
static int sao_edge_ddistortion_generic(const encoder_control_t *const encoder, const kvz_pixel *orig_data, const kvz_pixel *rec_data, int32_t block_width, int32_t block_height, int32_t eo_class, const int32_t offsets[NUM_SAO_EDGE_CATEGORIES])
Definition sao_shared_generics.h:52
Definition encoder.h:51
int8_t bitdepth
Definition encoder.h:84
Definition encoderstate.h:274
const encoder_control_t * encoder_control
Definition encoderstate.h:275
Definition cu.h:121