FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h26x/h2656_sao_template.c
Date: 2026-04-10 22:11:37
Exec Total Coverage
Lines: 116 122 95.1%
Functions: 9 12 75.0%
Branches: 119 122 97.5%

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 12880 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 12880 pixel *dst = (pixel *)_dst;
30 12880 const pixel *src = (const pixel *)_src;
31 12880 int offset_table[32] = { 0 };
32 int k, y, x;
33 12880 int shift = BIT_DEPTH - 5;
34
35 12880 stride_dst /= sizeof(pixel);
36 12880 stride_src /= sizeof(pixel);
37
38
2/2
✓ Branch 0 taken 25760 times.
✓ Branch 1 taken 6440 times.
64400 for (k = 0; k < 4; k++)
39 51520 offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
40
2/2
✓ Branch 0 taken 716616 times.
✓ Branch 1 taken 6440 times.
1446112 for (y = 0; y < height; y++) {
41
2/2
✓ Branch 0 taken 85053728 times.
✓ Branch 1 taken 716616 times.
171540688 for (x = 0; x < width; x++)
42 170107456 dst[x] = av_clip_pixel(src[x] + offset_table[(src[x] >> shift) & 31]);
43 1433232 dst += stride_dst;
44 1433232 src += stride_src;
45 }
46 12880 }
47
48 #define CMP(a, b) (((a) > (b)) - ((a) < (b)))
49
50 21316 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 21316 pixel *dst = (pixel *)_dst;
61 21316 const pixel *src = (const pixel *)_src;
62 int a_stride, b_stride;
63 int x, y;
64 21316 ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
65 21316 stride_dst /= sizeof(pixel);
66
67 21316 a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src;
68 21316 b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src;
69
2/2
✓ Branch 0 taken 1053136 times.
✓ Branch 1 taken 10658 times.
2127588 for (y = 0; y < height; y++) {
70
2/2
✓ Branch 0 taken 113842464 times.
✓ Branch 1 taken 1053136 times.
229791200 for (x = 0; x < width; x++) {
71 227684928 int diff0 = CMP(src[x], src[x + a_stride]);
72 227684928 int diff1 = CMP(src[x], src[x + b_stride]);
73 227684928 int offset_val = edge_idx[2 + diff0 + diff1];
74 227684928 dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
75 }
76 2106272 src += stride_src;
77 2106272 dst += stride_dst;
78 }
79 21316 }
80
81 350 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 350 pixel *dst = (pixel *)_dst;
89 350 const pixel *src = (const pixel *)_src;
90 350 const int16_t *sao_offset_val = sao->offset_val[c_idx];
91 350 int sao_eo_class = sao->eo_class[c_idx];
92 350 int init_x = 0, width = _width, height = _height;
93
94 350 stride_dst /= sizeof(pixel);
95 350 stride_src /= sizeof(pixel);
96
97
2/2
✓ Branch 0 taken 147 times.
✓ Branch 1 taken 28 times.
350 if (sao_eo_class != SAO_EO_VERT) {
98
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 143 times.
294 if (borders[0]) {
99 8 int offset_val = sao_offset_val[0];
100
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 4 times.
520 for (y = 0; y < height; y++) {
101 512 dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
102 }
103 8 init_x = 1;
104 }
105
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 141 times.
294 if (borders[2]) {
106 12 int offset_val = sao_offset_val[0];
107 12 int offset = width - 1;
108
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 6 times.
1548 for (x = 0; x < height; x++) {
109 1536 dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
110 }
111 12 width--;
112 }
113 }
114
2/2
✓ Branch 0 taken 145 times.
✓ Branch 1 taken 30 times.
350 if (sao_eo_class != SAO_EO_HORIZ) {
115
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 115 times.
290 if (borders[1]) {
116 60 int offset_val = sao_offset_val[0];
117
2/2
✓ Branch 0 taken 3580 times.
✓ Branch 1 taken 30 times.
7220 for (x = init_x; x < width; x++)
118 7160 dst[x] = av_clip_pixel(src[x] + offset_val);
119 }
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 145 times.
290 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 350 }
130
131 20390 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 20390 pixel *dst = (pixel *)_dst;
139 20390 const pixel *src = (const pixel *)_src;
140 20390 const int16_t *sao_offset_val = sao->offset_val[c_idx];
141 20390 int sao_eo_class = sao->eo_class[c_idx];
142 20390 int init_x = 0, init_y = 0, width = _width, height = _height;
143
144 20390 stride_dst /= sizeof(pixel);
145 20390 stride_src /= sizeof(pixel);
146
147
2/2
✓ Branch 0 taken 7175 times.
✓ Branch 1 taken 3020 times.
20390 if (sao_eo_class != SAO_EO_VERT) {
148
2/2
✓ Branch 0 taken 732 times.
✓ Branch 1 taken 6443 times.
14350 if (borders[0]) {
149 1464 int offset_val = sao_offset_val[0];
150
2/2
✓ Branch 0 taken 72392 times.
✓ Branch 1 taken 732 times.
146248 for (y = 0; y < height; y++) {
151 144784 dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
152 }
153 1464 init_x = 1;
154 }
155
2/2
✓ Branch 0 taken 659 times.
✓ Branch 1 taken 6516 times.
14350 if (borders[2]) {
156 1318 int offset_val = sao_offset_val[0];
157 1318 int offset = width - 1;
158
2/2
✓ Branch 0 taken 62976 times.
✓ Branch 1 taken 659 times.
127270 for (x = 0; x < height; x++) {
159 125952 dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
160 }
161 1318 width--;
162 }
163 }
164
2/2
✓ Branch 0 taken 8178 times.
✓ Branch 1 taken 2017 times.
20390 if (sao_eo_class != SAO_EO_HORIZ) {
165
2/2
✓ Branch 0 taken 1403 times.
✓ Branch 1 taken 6775 times.
16356 if (borders[1]) {
166 2806 int offset_val = sao_offset_val[0];
167
2/2
✓ Branch 0 taken 132728 times.
✓ Branch 1 taken 1403 times.
268262 for (x = init_x; x < width; x++)
168 265456 dst[x] = av_clip_pixel(src[x] + offset_val);
169 2806 init_y = 1;
170 }
171
2/2
✓ Branch 0 taken 1459 times.
✓ Branch 1 taken 6719 times.
16356 if (borders[3]) {
172 2918 int offset_val = sao_offset_val[0];
173 2918 ptrdiff_t y_stride_dst = stride_dst * (height - 1);
174 2918 ptrdiff_t y_stride_src = stride_src * (height - 1);
175
2/2
✓ Branch 0 taken 138010 times.
✓ Branch 1 taken 1459 times.
278938 for (x = init_x; x < width; x++)
176 276020 dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
177 2918 height--;
178 }
179 }
180
181 {
182
8/8
✓ Branch 0 taken 9662 times.
✓ Branch 1 taken 533 times.
✓ Branch 2 taken 1834 times.
✓ Branch 3 taken 7828 times.
✓ Branch 4 taken 1631 times.
✓ Branch 5 taken 203 times.
✓ Branch 6 taken 1372 times.
✓ Branch 7 taken 259 times.
20390 int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
183
8/8
✓ Branch 0 taken 9595 times.
✓ Branch 1 taken 600 times.
✓ Branch 2 taken 3034 times.
✓ Branch 3 taken 6561 times.
✓ Branch 4 taken 2449 times.
✓ Branch 5 taken 585 times.
✓ Branch 6 taken 2244 times.
✓ Branch 7 taken 205 times.
20390 int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
184
8/8
✓ Branch 0 taken 9502 times.
✓ Branch 1 taken 693 times.
✓ Branch 2 taken 1817 times.
✓ Branch 3 taken 7685 times.
✓ Branch 4 taken 1624 times.
✓ Branch 5 taken 193 times.
✓ Branch 6 taken 1294 times.
✓ Branch 7 taken 330 times.
20390 int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
185
8/8
✓ Branch 0 taken 9527 times.
✓ Branch 1 taken 668 times.
✓ Branch 2 taken 3038 times.
✓ Branch 3 taken 6489 times.
✓ Branch 4 taken 2725 times.
✓ Branch 5 taken 313 times.
✓ Branch 6 taken 2244 times.
✓ Branch 7 taken 481 times.
20390 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 388 times.
✓ Branch 1 taken 9807 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 106 times.
20390 if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
189
2/2
✓ Branch 0 taken 25267 times.
✓ Branch 1 taken 282 times.
51098 for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
190 50534 dst[y*stride_dst] = src[y*stride_src];
191 }
192
4/4
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 9745 times.
✓ Branch 2 taken 331 times.
✓ Branch 3 taken 119 times.
20390 if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
193
2/2
✓ Branch 0 taken 30054 times.
✓ Branch 1 taken 331 times.
60770 for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
194 60108 dst[y*stride_dst+width-1] = src[y*stride_src+width-1];
195 }
196
197
4/4
✓ Branch 0 taken 416 times.
✓ Branch 1 taken 9779 times.
✓ Branch 2 taken 283 times.
✓ Branch 3 taken 133 times.
20390 if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
198
2/2
✓ Branch 0 taken 23768 times.
✓ Branch 1 taken 283 times.
48102 for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
199 47536 dst[x] = src[x];
200 }
201
4/4
✓ Branch 0 taken 548 times.
✓ Branch 1 taken 9647 times.
✓ Branch 2 taken 399 times.
✓ Branch 3 taken 149 times.
20390 if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
202
2/2
✓ Branch 0 taken 34996 times.
✓ Branch 1 taken 399 times.
70790 for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
203 69992 dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x];
204 }
205
4/4
✓ Branch 0 taken 533 times.
✓ Branch 1 taken 9662 times.
✓ Branch 2 taken 115 times.
✓ Branch 3 taken 418 times.
20390 if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
206 230 dst[0] = src[0];
207
4/4
✓ Branch 0 taken 600 times.
✓ Branch 1 taken 9595 times.
✓ Branch 2 taken 175 times.
✓ Branch 3 taken 425 times.
20390 if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
208 350 dst[width-1] = src[width-1];
209
4/4
✓ Branch 0 taken 693 times.
✓ Branch 1 taken 9502 times.
✓ Branch 2 taken 132 times.
✓ Branch 3 taken 561 times.
20390 if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
210 264 dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1];
211
4/4
✓ Branch 0 taken 668 times.
✓ Branch 1 taken 9527 times.
✓ Branch 2 taken 171 times.
✓ Branch 3 taken 497 times.
20390 if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
212 342 dst[stride_dst*(height-1)] = src[stride_src*(height-1)];
213
214 }
215 20390 }
216
217 #undef CMP
218