FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h26x/h2656_sao_template.c
Date: 2024-12-12 01:08:13
Exec Total Coverage
Lines: 112 122 91.8%
Functions: 7 12 58.3%
Branches: 116 122 95.1%

Line Branch Exec Source
1 /*
2 * HEVC/VVC SAO template
3 *
4 * Copyright (C) 2024 Nuo Mi
5 * Copyright (C) 2012 - 2013 Guillaume Martres
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 9828 static void FUNC(sao_band_filter)(uint8_t *_dst, const uint8_t *_src,
25 ptrdiff_t stride_dst, ptrdiff_t stride_src,
26 const int16_t *sao_offset_val, int sao_left_class,
27 int width, int height)
28 {
29 9828 pixel *dst = (pixel *)_dst;
30 9828 const pixel *src = (const pixel *)_src;
31 9828 int offset_table[32] = { 0 };
32 int k, y, x;
33 9828 int shift = BIT_DEPTH - 5;
34
35 9828 stride_dst /= sizeof(pixel);
36 9828 stride_src /= sizeof(pixel);
37
38
2/2
✓ Branch 0 taken 19656 times.
✓ Branch 1 taken 4914 times.
49140 for (k = 0; k < 4; k++)
39 39312 offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
40
2/2
✓ Branch 0 taken 559600 times.
✓ Branch 1 taken 4914 times.
1129028 for (y = 0; y < height; y++) {
41
2/2
✓ Branch 0 taken 69676032 times.
✓ Branch 1 taken 559600 times.
140471264 for (x = 0; x < width; x++)
42 139352064 dst[x] = av_clip_pixel(src[x] + offset_table[(src[x] >> shift) & 31]);
43 1119200 dst += stride_dst;
44 1119200 src += stride_src;
45 }
46 9828 }
47
48 #define CMP(a, b) (((a) > (b)) - ((a) < (b)))
49
50 16588 static void FUNC(sao_edge_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t stride_dst, const int16_t *sao_offset_val,
51 int eo, int width, int height) {
52
53 static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
54 static const int8_t pos[4][2][2] = {
55 { { -1, 0 }, { 1, 0 } }, // horizontal
56 { { 0, -1 }, { 0, 1 } }, // vertical
57 { { -1, -1 }, { 1, 1 } }, // 45 degree
58 { { 1, -1 }, { -1, 1 } }, // 135 degree
59 };
60 16588 pixel *dst = (pixel *)_dst;
61 16588 const pixel *src = (const pixel *)_src;
62 int a_stride, b_stride;
63 int x, y;
64 16588 ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
65 16588 stride_dst /= sizeof(pixel);
66
67 16588 a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src;
68 16588 b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src;
69
2/2
✓ Branch 0 taken 823976 times.
✓ Branch 1 taken 8294 times.
1664540 for (y = 0; y < height; y++) {
70
2/2
✓ Branch 0 taken 91822464 times.
✓ Branch 1 taken 823976 times.
185292880 for (x = 0; x < width; x++) {
71 183644928 int diff0 = CMP(src[x], src[x + a_stride]);
72 183644928 int diff1 = CMP(src[x], src[x + b_stride]);
73 183644928 int offset_val = edge_idx[2 + diff0 + diff1];
74 183644928 dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
75 }
76 1647952 src += stride_src;
77 1647952 dst += stride_dst;
78 }
79 16588 }
80
81 338 static void FUNC(sao_edge_restore_0)(uint8_t *_dst, const uint8_t *_src,
82 ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao,
83 const int *borders, int _width, int _height,
84 int c_idx, const uint8_t *vert_edge,
85 const uint8_t *horiz_edge, const uint8_t *diag_edge)
86 {
87 int x, y;
88 338 pixel *dst = (pixel *)_dst;
89 338 const pixel *src = (const pixel *)_src;
90 338 const int16_t *sao_offset_val = sao->offset_val[c_idx];
91 338 int sao_eo_class = sao->eo_class[c_idx];
92 338 int init_x = 0, width = _width, height = _height;
93
94 338 stride_dst /= sizeof(pixel);
95 338 stride_src /= sizeof(pixel);
96
97
2/2
✓ Branch 0 taken 141 times.
✓ Branch 1 taken 28 times.
338 if (sao_eo_class != SAO_EO_VERT) {
98
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 141 times.
282 if (borders[0]) {
99 int offset_val = sao_offset_val[0];
100 for (y = 0; y < height; y++) {
101 dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
102 }
103 init_x = 1;
104 }
105
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 137 times.
282 if (borders[2]) {
106 8 int offset_val = sao_offset_val[0];
107 8 int offset = width - 1;
108
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 4 times.
1032 for (x = 0; x < height; x++) {
109 1024 dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
110 }
111 8 width--;
112 }
113 }
114
2/2
✓ Branch 0 taken 141 times.
✓ Branch 1 taken 28 times.
338 if (sao_eo_class != SAO_EO_HORIZ) {
115
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 115 times.
282 if (borders[1]) {
116 52 int offset_val = sao_offset_val[0];
117
2/2
✓ Branch 0 taken 3328 times.
✓ Branch 1 taken 26 times.
6708 for (x = init_x; x < width; x++)
118 6656 dst[x] = av_clip_pixel(src[x] + offset_val);
119 }
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 141 times.
282 if (borders[3]) {
121 int offset_val = sao_offset_val[0];
122 ptrdiff_t y_stride_dst = stride_dst * (height - 1);
123 ptrdiff_t y_stride_src = stride_src * (height - 1);
124 for (x = init_x; x < width; x++)
125 dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
126 height--;
127 }
128 }
129 338 }
130
131 16250 static void FUNC(sao_edge_restore_1)(uint8_t *_dst, const uint8_t *_src,
132 ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao,
133 const int *borders, int _width, int _height,
134 int c_idx, const uint8_t *vert_edge,
135 const uint8_t *horiz_edge, const uint8_t *diag_edge)
136 {
137 int x, y;
138 16250 pixel *dst = (pixel *)_dst;
139 16250 const pixel *src = (const pixel *)_src;
140 16250 const int16_t *sao_offset_val = sao->offset_val[c_idx];
141 16250 int sao_eo_class = sao->eo_class[c_idx];
142 16250 int init_x = 0, init_y = 0, width = _width, height = _height;
143
144 16250 stride_dst /= sizeof(pixel);
145 16250 stride_src /= sizeof(pixel);
146
147
2/2
✓ Branch 0 taken 5868 times.
✓ Branch 1 taken 2257 times.
16250 if (sao_eo_class != SAO_EO_VERT) {
148
2/2
✓ Branch 0 taken 568 times.
✓ Branch 1 taken 5300 times.
11736 if (borders[0]) {
149 1136 int offset_val = sao_offset_val[0];
150
2/2
✓ Branch 0 taken 57016 times.
✓ Branch 1 taken 568 times.
115168 for (y = 0; y < height; y++) {
151 114032 dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
152 }
153 1136 init_x = 1;
154 }
155
2/2
✓ Branch 0 taken 511 times.
✓ Branch 1 taken 5357 times.
11736 if (borders[2]) {
156 1022 int offset_val = sao_offset_val[0];
157 1022 int offset = width - 1;
158
2/2
✓ Branch 0 taken 49688 times.
✓ Branch 1 taken 511 times.
100398 for (x = 0; x < height; x++) {
159 99376 dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
160 }
161 1022 width--;
162 }
163 }
164
2/2
✓ Branch 0 taken 6702 times.
✓ Branch 1 taken 1423 times.
16250 if (sao_eo_class != SAO_EO_HORIZ) {
165
2/2
✓ Branch 0 taken 1183 times.
✓ Branch 1 taken 5519 times.
13404 if (borders[1]) {
166 2366 int offset_val = sao_offset_val[0];
167
2/2
✓ Branch 0 taken 111931 times.
✓ Branch 1 taken 1183 times.
226228 for (x = init_x; x < width; x++)
168 223862 dst[x] = av_clip_pixel(src[x] + offset_val);
169 2366 init_y = 1;
170 }
171
2/2
✓ Branch 0 taken 1258 times.
✓ Branch 1 taken 5444 times.
13404 if (borders[3]) {
172 2516 int offset_val = sao_offset_val[0];
173 2516 ptrdiff_t y_stride_dst = stride_dst * (height - 1);
174 2516 ptrdiff_t y_stride_src = stride_src * (height - 1);
175
2/2
✓ Branch 0 taken 121534 times.
✓ Branch 1 taken 1258 times.
245584 for (x = init_x; x < width; x++)
176 243068 dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
177 2516 height--;
178 }
179 }
180
181 {
182
8/8
✓ Branch 0 taken 7992 times.
✓ Branch 1 taken 133 times.
✓ Branch 2 taken 1596 times.
✓ Branch 3 taken 6396 times.
✓ Branch 4 taken 1448 times.
✓ Branch 5 taken 148 times.
✓ Branch 6 taken 1233 times.
✓ Branch 7 taken 215 times.
16250 int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
183
8/8
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 191 times.
✓ Branch 2 taken 2760 times.
✓ Branch 3 taken 5174 times.
✓ Branch 4 taken 2233 times.
✓ Branch 5 taken 527 times.
✓ Branch 6 taken 2066 times.
✓ Branch 7 taken 167 times.
16250 int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
184
8/8
✓ Branch 0 taken 7848 times.
✓ Branch 1 taken 277 times.
✓ Branch 2 taken 1576 times.
✓ Branch 3 taken 6272 times.
✓ Branch 4 taken 1431 times.
✓ Branch 5 taken 145 times.
✓ Branch 6 taken 1141 times.
✓ Branch 7 taken 290 times.
16250 int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
185
8/8
✓ Branch 0 taken 7881 times.
✓ Branch 1 taken 244 times.
✓ Branch 2 taken 2769 times.
✓ Branch 3 taken 5112 times.
✓ Branch 4 taken 2506 times.
✓ Branch 5 taken 263 times.
✓ Branch 6 taken 2068 times.
✓ Branch 7 taken 438 times.
16250 int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3];
186
187 // Restore pixels that can't be modified
188
4/4
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 8042 times.
✓ Branch 2 taken 59 times.
✓ Branch 3 taken 24 times.
16250 if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
189
2/2
✓ Branch 0 taken 7163 times.
✓ Branch 1 taken 59 times.
14444 for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
190 14326 dst[y*stride_dst] = src[y*stride_src];
191 }
192
4/4
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 7981 times.
✓ Branch 2 taken 108 times.
✓ Branch 3 taken 36 times.
16250 if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
193
2/2
✓ Branch 0 taken 11836 times.
✓ Branch 1 taken 108 times.
23888 for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
194 23672 dst[y*stride_dst+width-1] = src[y*stride_src+width-1];
195 }
196
197
4/4
✓ Branch 0 taken 107 times.
✓ Branch 1 taken 8018 times.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 52 times.
16250 if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
198
2/2
✓ Branch 0 taken 7026 times.
✓ Branch 1 taken 55 times.
14162 for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
199 14052 dst[x] = src[x];
200 }
201
4/4
✓ Branch 0 taken 223 times.
✓ Branch 1 taken 7902 times.
✓ Branch 2 taken 157 times.
✓ Branch 3 taken 66 times.
16250 if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
202
2/2
✓ Branch 0 taken 16765 times.
✓ Branch 1 taken 157 times.
33844 for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
203 33530 dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x];
204 }
205
4/4
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 7992 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 111 times.
16250 if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
206 44 dst[0] = src[0];
207
4/4
✓ Branch 0 taken 191 times.
✓ Branch 1 taken 7934 times.
✓ Branch 2 taken 67 times.
✓ Branch 3 taken 124 times.
16250 if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
208 134 dst[width-1] = src[width-1];
209
4/4
✓ Branch 0 taken 277 times.
✓ Branch 1 taken 7848 times.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 235 times.
16250 if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
210 84 dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1];
211
4/4
✓ Branch 0 taken 244 times.
✓ Branch 1 taken 7881 times.
✓ Branch 2 taken 58 times.
✓ Branch 3 taken 186 times.
16250 if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
212 116 dst[stride_dst*(height-1)] = src[stride_src*(height-1)];
213
214 }
215 16250 }
216
217 #undef CMP
218