FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h26x/h2656_sao_template.c
Date: 2024-02-29 09:57:37
Exec Total Coverage
Lines: 122 122 100.0%
Functions: 11 16 68.8%
Branches: 122 122 100.0%

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 232560 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 232560 pixel *dst = (pixel *)_dst;
30 232560 const pixel *src = (const pixel *)_src;
31 232560 int offset_table[32] = { 0 };
32 int k, y, x;
33 232560 int shift = BIT_DEPTH - 5;
34
35 232560 stride_dst /= sizeof(pixel);
36 232560 stride_src /= sizeof(pixel);
37
38
2/2
✓ Branch 0 taken 465120 times.
✓ Branch 1 taken 116280 times.
1162800 for (k = 0; k < 4; k++)
39 930240 offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
40
2/2
✓ Branch 0 taken 4745968 times.
✓ Branch 1 taken 116280 times.
9724496 for (y = 0; y < height; y++) {
41
2/2
✓ Branch 0 taken 274454176 times.
✓ Branch 1 taken 4745968 times.
558400288 for (x = 0; x < width; x++)
42 548908352 dst[x] = av_clip_pixel(src[x] + offset_table[(src[x] >> shift) & 31]);
43 9491936 dst += stride_dst;
44 9491936 src += stride_src;
45 }
46 232560 }
47
48 #define CMP(a, b) (((a) > (b)) - ((a) < (b)))
49
50 759880 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 759880 pixel *dst = (pixel *)_dst;
61 759880 const pixel *src = (const pixel *)_src;
62 int a_stride, b_stride;
63 int x, y;
64 759880 ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
65 759880 stride_dst /= sizeof(pixel);
66
67 759880 a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src;
68 759880 b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src;
69
2/2
✓ Branch 0 taken 19996704 times.
✓ Branch 1 taken 379940 times.
40753288 for (y = 0; y < height; y++) {
70
2/2
✓ Branch 0 taken 1148594720 times.
✓ Branch 1 taken 19996704 times.
2337182848 for (x = 0; x < width; x++) {
71 2297189440 int diff0 = CMP(src[x], src[x + a_stride]);
72 2297189440 int diff1 = CMP(src[x], src[x + b_stride]);
73 2297189440 int offset_val = edge_idx[2 + diff0 + diff1];
74 2297189440 dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
75 }
76 39993408 src += stride_src;
77 39993408 dst += stride_dst;
78 }
79 759880 }
80
81 721398 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 721398 pixel *dst = (pixel *)_dst;
89 721398 const pixel *src = (const pixel *)_src;
90 721398 const int16_t *sao_offset_val = sao->offset_val[c_idx];
91 721398 int sao_eo_class = sao->eo_class[c_idx];
92 721398 int init_x = 0, width = _width, height = _height;
93
94 721398 stride_dst /= sizeof(pixel);
95 721398 stride_src /= sizeof(pixel);
96
97
2/2
✓ Branch 0 taken 282809 times.
✓ Branch 1 taken 77890 times.
721398 if (sao_eo_class != SAO_EO_VERT) {
98
2/2
✓ Branch 0 taken 13321 times.
✓ Branch 1 taken 269488 times.
565618 if (borders[0]) {
99 26642 int offset_val = sao_offset_val[0];
100
2/2
✓ Branch 0 taken 657864 times.
✓ Branch 1 taken 13321 times.
1342370 for (y = 0; y < height; y++) {
101 1315728 dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
102 }
103 26642 init_x = 1;
104 }
105
2/2
✓ Branch 0 taken 13557 times.
✓ Branch 1 taken 269252 times.
565618 if (borders[2]) {
106 27114 int offset_val = sao_offset_val[0];
107 27114 int offset = width - 1;
108
2/2
✓ Branch 0 taken 659416 times.
✓ Branch 1 taken 13557 times.
1345946 for (x = 0; x < height; x++) {
109 1318832 dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
110 }
111 27114 width--;
112 }
113 }
114
2/2
✓ Branch 0 taken 297065 times.
✓ Branch 1 taken 63634 times.
721398 if (sao_eo_class != SAO_EO_HORIZ) {
115
2/2
✓ Branch 0 taken 18487 times.
✓ Branch 1 taken 278578 times.
594130 if (borders[1]) {
116 36974 int offset_val = sao_offset_val[0];
117
2/2
✓ Branch 0 taken 910551 times.
✓ Branch 1 taken 18487 times.
1858076 for (x = init_x; x < width; x++)
118 1821102 dst[x] = av_clip_pixel(src[x] + offset_val);
119 }
120
2/2
✓ Branch 0 taken 23393 times.
✓ Branch 1 taken 273672 times.
594130 if (borders[3]) {
121 46786 int offset_val = sao_offset_val[0];
122 46786 ptrdiff_t y_stride_dst = stride_dst * (height - 1);
123 46786 ptrdiff_t y_stride_src = stride_src * (height - 1);
124
2/2
✓ Branch 0 taken 1115478 times.
✓ Branch 1 taken 23393 times.
2277742 for (x = init_x; x < width; x++)
125 2230956 dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
126 46786 height--;
127 }
128 }
129 721398 }
130
131 54208 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 54208 pixel *dst = (pixel *)_dst;
139 54208 const pixel *src = (const pixel *)_src;
140 54208 const int16_t *sao_offset_val = sao->offset_val[c_idx];
141 54208 int sao_eo_class = sao->eo_class[c_idx];
142 54208 int init_x = 0, init_y = 0, width = _width, height = _height;
143
144 54208 stride_dst /= sizeof(pixel);
145 54208 stride_src /= sizeof(pixel);
146
147
2/2
✓ Branch 0 taken 19177 times.
✓ Branch 1 taken 7927 times.
54208 if (sao_eo_class != SAO_EO_VERT) {
148
2/2
✓ Branch 0 taken 1764 times.
✓ Branch 1 taken 17413 times.
38354 if (borders[0]) {
149 3528 int offset_val = sao_offset_val[0];
150
2/2
✓ Branch 0 taken 115280 times.
✓ Branch 1 taken 1764 times.
234088 for (y = 0; y < height; y++) {
151 230560 dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
152 }
153 3528 init_x = 1;
154 }
155
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 17893 times.
38354 if (borders[2]) {
156 2568 int offset_val = sao_offset_val[0];
157 2568 int offset = width - 1;
158
2/2
✓ Branch 0 taken 85960 times.
✓ Branch 1 taken 1284 times.
174488 for (x = 0; x < height; x++) {
159 171920 dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
160 }
161 2568 width--;
162 }
163 }
164
2/2
✓ Branch 0 taken 20307 times.
✓ Branch 1 taken 6797 times.
54208 if (sao_eo_class != SAO_EO_HORIZ) {
165
2/2
✓ Branch 0 taken 3035 times.
✓ Branch 1 taken 17272 times.
40614 if (borders[1]) {
166 6070 int offset_val = sao_offset_val[0];
167
2/2
✓ Branch 0 taken 200168 times.
✓ Branch 1 taken 3035 times.
406406 for (x = init_x; x < width; x++)
168 400336 dst[x] = av_clip_pixel(src[x] + offset_val);
169 6070 init_y = 1;
170 }
171
2/2
✓ Branch 0 taken 2742 times.
✓ Branch 1 taken 17565 times.
40614 if (borders[3]) {
172 5484 int offset_val = sao_offset_val[0];
173 5484 ptrdiff_t y_stride_dst = stride_dst * (height - 1);
174 5484 ptrdiff_t y_stride_src = stride_src * (height - 1);
175
2/2
✓ Branch 0 taken 190325 times.
✓ Branch 1 taken 2742 times.
386134 for (x = init_x; x < width; x++)
176 380650 dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
177 5484 height--;
178 }
179 }
180
181 {
182
8/8
✓ Branch 0 taken 26814 times.
✓ Branch 1 taken 290 times.
✓ Branch 2 taken 5199 times.
✓ Branch 3 taken 21615 times.
✓ Branch 4 taken 4772 times.
✓ Branch 5 taken 427 times.
✓ Branch 6 taken 4332 times.
✓ Branch 7 taken 440 times.
54208 int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
183
8/8
✓ Branch 0 taken 26712 times.
✓ Branch 1 taken 392 times.
✓ Branch 2 taken 6935 times.
✓ Branch 3 taken 19777 times.
✓ Branch 4 taken 5759 times.
✓ Branch 5 taken 1176 times.
✓ Branch 6 taken 5374 times.
✓ Branch 7 taken 385 times.
54208 int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
184
8/8
✓ Branch 0 taken 26526 times.
✓ Branch 1 taken 578 times.
✓ Branch 2 taken 5123 times.
✓ Branch 3 taken 21403 times.
✓ Branch 4 taken 4774 times.
✓ Branch 5 taken 349 times.
✓ Branch 6 taken 4053 times.
✓ Branch 7 taken 721 times.
54208 int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
185
8/8
✓ Branch 0 taken 26608 times.
✓ Branch 1 taken 496 times.
✓ Branch 2 taken 6975 times.
✓ Branch 3 taken 19633 times.
✓ Branch 4 taken 6173 times.
✓ Branch 5 taken 802 times.
✓ Branch 6 taken 5297 times.
✓ Branch 7 taken 876 times.
54208 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 112 times.
✓ Branch 1 taken 26992 times.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 32 times.
54208 if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
189
2/2
✓ Branch 0 taken 6586 times.
✓ Branch 1 taken 80 times.
13332 for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
190 13172 dst[y*stride_dst] = src[y*stride_src];
191 }
192
4/4
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 26892 times.
✓ Branch 2 taken 176 times.
✓ Branch 3 taken 36 times.
54208 if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
193
2/2
✓ Branch 0 taken 12028 times.
✓ Branch 1 taken 176 times.
24408 for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
194 24056 dst[y*stride_dst+width-1] = src[y*stride_src+width-1];
195 }
196
197
4/4
✓ Branch 0 taken 226 times.
✓ Branch 1 taken 26878 times.
✓ Branch 2 taken 164 times.
✓ Branch 3 taken 62 times.
54208 if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
198
2/2
✓ Branch 0 taken 9832 times.
✓ Branch 1 taken 164 times.
19992 for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
199 19664 dst[x] = src[x];
200 }
201
4/4
✓ Branch 0 taken 444 times.
✓ Branch 1 taken 26660 times.
✓ Branch 2 taken 324 times.
✓ Branch 3 taken 120 times.
54208 if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
202
2/2
✓ Branch 0 taken 21102 times.
✓ Branch 1 taken 324 times.
42852 for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
203 42204 dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x];
204 }
205
4/4
✓ Branch 0 taken 290 times.
✓ Branch 1 taken 26814 times.
✓ Branch 2 taken 74 times.
✓ Branch 3 taken 216 times.
54208 if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
206 148 dst[0] = src[0];
207
4/4
✓ Branch 0 taken 392 times.
✓ Branch 1 taken 26712 times.
✓ Branch 2 taken 172 times.
✓ Branch 3 taken 220 times.
54208 if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
208 344 dst[width-1] = src[width-1];
209
4/4
✓ Branch 0 taken 578 times.
✓ Branch 1 taken 26526 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 428 times.
54208 if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
210 300 dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1];
211
4/4
✓ Branch 0 taken 496 times.
✓ Branch 1 taken 26608 times.
✓ Branch 2 taken 132 times.
✓ Branch 3 taken 364 times.
54208 if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
212 264 dst[stride_dst*(height-1)] = src[stride_src*(height-1)];
213
214 }
215 54208 }
216
217 #undef CMP
218