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 | 231998 | 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 | 231998 | pixel *dst = (pixel *)_dst; | |
30 | 231998 | const pixel *src = (const pixel *)_src; | |
31 | 231998 | int offset_table[32] = { 0 }; | |
32 | int k, y, x; | ||
33 | 231998 | int shift = BIT_DEPTH - 5; | |
34 | |||
35 | 231998 | stride_dst /= sizeof(pixel); | |
36 | 231998 | stride_src /= sizeof(pixel); | |
37 | |||
38 |
2/2✓ Branch 0 taken 463996 times.
✓ Branch 1 taken 115999 times.
|
1159990 | for (k = 0; k < 4; k++) |
39 | 927992 | offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1]; | |
40 |
2/2✓ Branch 0 taken 4718920 times.
✓ Branch 1 taken 115999 times.
|
9669838 | for (y = 0; y < height; y++) { |
41 |
2/2✓ Branch 0 taken 271420576 times.
✓ Branch 1 taken 4718920 times.
|
552278992 | for (x = 0; x < width; x++) |
42 | 542841152 | dst[x] = av_clip_pixel(src[x] + offset_table[(src[x] >> shift) & 31]); | |
43 | 9437840 | dst += stride_dst; | |
44 | 9437840 | src += stride_src; | |
45 | } | ||
46 | 231998 | } | |
47 | |||
48 | #define CMP(a, b) (((a) > (b)) - ((a) < (b))) | ||
49 | |||
50 | 757498 | 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 | 757498 | pixel *dst = (pixel *)_dst; | |
61 | 757498 | const pixel *src = (const pixel *)_src; | |
62 | int a_stride, b_stride; | ||
63 | int x, y; | ||
64 | 757498 | ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel); | |
65 | 757498 | stride_dst /= sizeof(pixel); | |
66 | |||
67 | 757498 | a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src; | |
68 | 757498 | b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src; | |
69 |
2/2✓ Branch 0 taken 19877680 times.
✓ Branch 1 taken 378749 times.
|
40512858 | for (y = 0; y < height; y++) { |
70 |
2/2✓ Branch 0 taken 1135434144 times.
✓ Branch 1 taken 19877680 times.
|
2310623648 | for (x = 0; x < width; x++) { |
71 | 2270868288 | int diff0 = CMP(src[x], src[x + a_stride]); | |
72 | 2270868288 | int diff1 = CMP(src[x], src[x + b_stride]); | |
73 | 2270868288 | int offset_val = edge_idx[2 + diff0 + diff1]; | |
74 | 2270868288 | dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]); | |
75 | } | ||
76 | 39755360 | src += stride_src; | |
77 | 39755360 | dst += stride_dst; | |
78 | } | ||
79 | 757498 | } | |
80 | |||
81 | 721796 | 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 | 721796 | pixel *dst = (pixel *)_dst; | |
89 | 721796 | const pixel *src = (const pixel *)_src; | |
90 | 721796 | const int16_t *sao_offset_val = sao->offset_val[c_idx]; | |
91 | 721796 | int sao_eo_class = sao->eo_class[c_idx]; | |
92 | 721796 | int init_x = 0, width = _width, height = _height; | |
93 | |||
94 | 721796 | stride_dst /= sizeof(pixel); | |
95 | 721796 | stride_src /= sizeof(pixel); | |
96 | |||
97 |
2/2✓ Branch 0 taken 282968 times.
✓ Branch 1 taken 77930 times.
|
721796 | if (sao_eo_class != SAO_EO_VERT) { |
98 |
2/2✓ Branch 0 taken 13323 times.
✓ Branch 1 taken 269645 times.
|
565936 | if (borders[0]) { |
99 | 26646 | int offset_val = sao_offset_val[0]; | |
100 |
2/2✓ Branch 0 taken 657992 times.
✓ Branch 1 taken 13323 times.
|
1342630 | for (y = 0; y < height; y++) { |
101 | 1315984 | dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val); | |
102 | } | ||
103 | 26646 | init_x = 1; | |
104 | } | ||
105 |
2/2✓ Branch 0 taken 13575 times.
✓ Branch 1 taken 269393 times.
|
565936 | if (borders[2]) { |
106 | 27150 | int offset_val = sao_offset_val[0]; | |
107 | 27150 | int offset = width - 1; | |
108 |
2/2✓ Branch 0 taken 660312 times.
✓ Branch 1 taken 13575 times.
|
1347774 | for (x = 0; x < height; x++) { |
109 | 1320624 | dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val); | |
110 | } | ||
111 | 27150 | width--; | |
112 | } | ||
113 | } | ||
114 |
2/2✓ Branch 0 taken 297223 times.
✓ Branch 1 taken 63675 times.
|
721796 | if (sao_eo_class != SAO_EO_HORIZ) { |
115 |
2/2✓ Branch 0 taken 18509 times.
✓ Branch 1 taken 278714 times.
|
594446 | if (borders[1]) { |
116 | 37018 | int offset_val = sao_offset_val[0]; | |
117 |
2/2✓ Branch 0 taken 911285 times.
✓ Branch 1 taken 18509 times.
|
1859588 | for (x = init_x; x < width; x++) |
118 | 1822570 | dst[x] = av_clip_pixel(src[x] + offset_val); | |
119 | } | ||
120 |
2/2✓ Branch 0 taken 23421 times.
✓ Branch 1 taken 273802 times.
|
594446 | if (borders[3]) { |
121 | 46842 | int offset_val = sao_offset_val[0]; | |
122 | 46842 | ptrdiff_t y_stride_dst = stride_dst * (height - 1); | |
123 | 46842 | ptrdiff_t y_stride_src = stride_src * (height - 1); | |
124 |
2/2✓ Branch 0 taken 1116818 times.
✓ Branch 1 taken 23421 times.
|
2280478 | for (x = init_x; x < width; x++) |
125 | 2233636 | dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val); | |
126 | 46842 | height--; | |
127 | } | ||
128 | } | ||
129 | 721796 | } | |
130 | |||
131 | 51900 | 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 | 51900 | pixel *dst = (pixel *)_dst; | |
139 | 51900 | const pixel *src = (const pixel *)_src; | |
140 | 51900 | const int16_t *sao_offset_val = sao->offset_val[c_idx]; | |
141 | 51900 | int sao_eo_class = sao->eo_class[c_idx]; | |
142 | 51900 | int init_x = 0, init_y = 0, width = _width, height = _height; | |
143 | |||
144 | 51900 | stride_dst /= sizeof(pixel); | |
145 | 51900 | stride_src /= sizeof(pixel); | |
146 | |||
147 |
2/2✓ Branch 0 taken 18266 times.
✓ Branch 1 taken 7684 times.
|
51900 | if (sao_eo_class != SAO_EO_VERT) { |
148 |
2/2✓ Branch 0 taken 1696 times.
✓ Branch 1 taken 16570 times.
|
36532 | if (borders[0]) { |
149 | 3392 | int offset_val = sao_offset_val[0]; | |
150 |
2/2✓ Branch 0 taken 108632 times.
✓ Branch 1 taken 1696 times.
|
220656 | for (y = 0; y < height; y++) { |
151 | 217264 | dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val); | |
152 | } | ||
153 | 3392 | init_x = 1; | |
154 | } | ||
155 |
2/2✓ Branch 0 taken 1191 times.
✓ Branch 1 taken 17075 times.
|
36532 | if (borders[2]) { |
156 | 2382 | int offset_val = sao_offset_val[0]; | |
157 | 2382 | int offset = width - 1; | |
158 |
2/2✓ Branch 0 taken 77296 times.
✓ Branch 1 taken 1191 times.
|
156974 | for (x = 0; x < height; x++) { |
159 | 154592 | dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val); | |
160 | } | ||
161 | 2382 | width--; | |
162 | } | ||
163 | } | ||
164 |
2/2✓ Branch 0 taken 19398 times.
✓ Branch 1 taken 6552 times.
|
51900 | if (sao_eo_class != SAO_EO_HORIZ) { |
165 |
2/2✓ Branch 0 taken 2879 times.
✓ Branch 1 taken 16519 times.
|
38796 | if (borders[1]) { |
166 | 5758 | int offset_val = sao_offset_val[0]; | |
167 |
2/2✓ Branch 0 taken 186764 times.
✓ Branch 1 taken 2879 times.
|
379286 | for (x = init_x; x < width; x++) |
168 | 373528 | dst[x] = av_clip_pixel(src[x] + offset_val); | |
169 | 5758 | init_y = 1; | |
170 | } | ||
171 |
2/2✓ Branch 0 taken 2572 times.
✓ Branch 1 taken 16826 times.
|
38796 | if (borders[3]) { |
172 | 5144 | int offset_val = sao_offset_val[0]; | |
173 | 5144 | ptrdiff_t y_stride_dst = stride_dst * (height - 1); | |
174 | 5144 | ptrdiff_t y_stride_src = stride_src * (height - 1); | |
175 |
2/2✓ Branch 0 taken 174576 times.
✓ Branch 1 taken 2572 times.
|
354296 | for (x = init_x; x < width; x++) |
176 | 349152 | dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val); | |
177 | 5144 | height--; | |
178 | } | ||
179 | } | ||
180 | |||
181 | { | ||
182 |
8/8✓ Branch 0 taken 25674 times.
✓ Branch 1 taken 276 times.
✓ Branch 2 taken 4962 times.
✓ Branch 3 taken 20712 times.
✓ Branch 4 taken 4550 times.
✓ Branch 5 taken 412 times.
✓ Branch 6 taken 4132 times.
✓ Branch 7 taken 418 times.
|
51900 | int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1]; |
183 |
8/8✓ Branch 0 taken 25577 times.
✓ Branch 1 taken 373 times.
✓ Branch 2 taken 6515 times.
✓ Branch 3 taken 19062 times.
✓ Branch 4 taken 5389 times.
✓ Branch 5 taken 1126 times.
✓ Branch 6 taken 5035 times.
✓ Branch 7 taken 354 times.
|
51900 | int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2]; |
184 |
8/8✓ Branch 0 taken 25403 times.
✓ Branch 1 taken 547 times.
✓ Branch 2 taken 4894 times.
✓ Branch 3 taken 20509 times.
✓ Branch 4 taken 4572 times.
✓ Branch 5 taken 322 times.
✓ Branch 6 taken 3894 times.
✓ Branch 7 taken 678 times.
|
51900 | int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3]; |
185 |
8/8✓ Branch 0 taken 25483 times.
✓ Branch 1 taken 467 times.
✓ Branch 2 taken 6543 times.
✓ Branch 3 taken 18940 times.
✓ Branch 4 taken 5769 times.
✓ Branch 5 taken 774 times.
✓ Branch 6 taken 4956 times.
✓ Branch 7 taken 813 times.
|
51900 | 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 118 times.
✓ Branch 1 taken 25832 times.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 28 times.
|
51900 | if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) { |
189 |
2/2✓ Branch 0 taken 7484 times.
✓ Branch 1 taken 90 times.
|
15148 | for(y = init_y+save_upper_left; y< height-save_lower_left; y++) |
190 | 14968 | dst[y*stride_dst] = src[y*stride_src]; | |
191 | } | ||
192 |
4/4✓ Branch 0 taken 216 times.
✓ Branch 1 taken 25734 times.
✓ Branch 2 taken 186 times.
✓ Branch 3 taken 30 times.
|
51900 | if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) { |
193 |
2/2✓ Branch 0 taken 13112 times.
✓ Branch 1 taken 186 times.
|
26596 | for(y = init_y+save_upper_right; y< height-save_lower_right; y++) |
194 | 26224 | dst[y*stride_dst+width-1] = src[y*stride_src+width-1]; | |
195 | } | ||
196 | |||
197 |
4/4✓ Branch 0 taken 221 times.
✓ Branch 1 taken 25729 times.
✓ Branch 2 taken 163 times.
✓ Branch 3 taken 58 times.
|
51900 | if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) { |
198 |
2/2✓ Branch 0 taken 9704 times.
✓ Branch 1 taken 163 times.
|
19734 | for(x = init_x+save_upper_left; x < width-save_upper_right; x++) |
199 | 19408 | dst[x] = src[x]; | |
200 | } | ||
201 |
4/4✓ Branch 0 taken 422 times.
✓ Branch 1 taken 25528 times.
✓ Branch 2 taken 313 times.
✓ Branch 3 taken 109 times.
|
51900 | if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) { |
202 |
2/2✓ Branch 0 taken 19947 times.
✓ Branch 1 taken 313 times.
|
40520 | for(x = init_x+save_lower_left; x < width-save_lower_right; x++) |
203 | 39894 | dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x]; | |
204 | } | ||
205 |
4/4✓ Branch 0 taken 276 times.
✓ Branch 1 taken 25674 times.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 201 times.
|
51900 | if(diag_edge[0] && sao_eo_class == SAO_EO_135D) |
206 | 150 | dst[0] = src[0]; | |
207 |
4/4✓ Branch 0 taken 373 times.
✓ Branch 1 taken 25577 times.
✓ Branch 2 taken 162 times.
✓ Branch 3 taken 211 times.
|
51900 | if(diag_edge[1] && sao_eo_class == SAO_EO_45D) |
208 | 324 | dst[width-1] = src[width-1]; | |
209 |
4/4✓ Branch 0 taken 547 times.
✓ Branch 1 taken 25403 times.
✓ Branch 2 taken 143 times.
✓ Branch 3 taken 404 times.
|
51900 | if(diag_edge[2] && sao_eo_class == SAO_EO_135D) |
210 | 286 | dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1]; | |
211 |
4/4✓ Branch 0 taken 467 times.
✓ Branch 1 taken 25483 times.
✓ Branch 2 taken 134 times.
✓ Branch 3 taken 333 times.
|
51900 | if(diag_edge[3] && sao_eo_class == SAO_EO_45D) |
212 | 268 | dst[stride_dst*(height-1)] = src[stride_src*(height-1)]; | |
213 | |||
214 | } | ||
215 | 51900 | } | |
216 | |||
217 | #undef CMP | ||
218 |