| 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 | 218918 | 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 | 218918 | pixel *dst = (pixel *)_dst; | |
| 30 | 218918 | const pixel *src = (const pixel *)_src; | |
| 31 | 218918 | int offset_table[32] = { 0 }; | |
| 32 | int k, y, x; | ||
| 33 | 218918 | int shift = BIT_DEPTH - 5; | |
| 34 | |||
| 35 | 218918 | stride_dst /= sizeof(pixel); | |
| 36 | 218918 | stride_src /= sizeof(pixel); | |
| 37 | |||
| 38 |
2/2✓ Branch 0 taken 437836 times.
✓ Branch 1 taken 109459 times.
|
1094590 | for (k = 0; k < 4; k++) |
| 39 | 875672 | offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1]; | |
| 40 |
2/2✓ Branch 0 taken 4559504 times.
✓ Branch 1 taken 109459 times.
|
9337926 | for (y = 0; y < height; y++) { |
| 41 |
2/2✓ Branch 0 taken 273977536 times.
✓ Branch 1 taken 4559504 times.
|
557074080 | for (x = 0; x < width; x++) |
| 42 | 547955072 | dst[x] = av_clip_pixel(src[x] + offset_table[(src[x] >> shift) & 31]); | |
| 43 | 9119008 | dst += stride_dst; | |
| 44 | 9119008 | src += stride_src; | |
| 45 | } | ||
| 46 | 218918 | } | |
| 47 | |||
| 48 | #define CMP(a, b) (((a) > (b)) - ((a) < (b))) | ||
| 49 | |||
| 50 | 1163520 | 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 | 1163520 | pixel *dst = (pixel *)_dst; | |
| 61 | 1163520 | const pixel *src = (const pixel *)_src; | |
| 62 | int a_stride, b_stride; | ||
| 63 | int x, y; | ||
| 64 | 1163520 | ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel); | |
| 65 | 1163520 | stride_dst /= sizeof(pixel); | |
| 66 | |||
| 67 | 1163520 | a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src; | |
| 68 | 1163520 | b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src; | |
| 69 |
2/2✓ Branch 0 taken 26565152 times.
✓ Branch 1 taken 581760 times.
|
54293824 | for (y = 0; y < height; y++) { |
| 70 |
2/2✓ Branch 0 taken 1379774144 times.
✓ Branch 1 taken 26565152 times.
|
2812678592 | for (x = 0; x < width; x++) { |
| 71 | 2759548288 | int diff0 = CMP(src[x], src[x + a_stride]); | |
| 72 | 2759548288 | int diff1 = CMP(src[x], src[x + b_stride]); | |
| 73 | 2759548288 | int offset_val = edge_idx[2 + diff0 + diff1]; | |
| 74 | 2759548288 | dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]); | |
| 75 | } | ||
| 76 | 53130304 | src += stride_src; | |
| 77 | 53130304 | dst += stride_dst; | |
| 78 | } | ||
| 79 | 1163520 | } | |
| 80 | |||
| 81 | 1105926 | 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 | 1105926 | pixel *dst = (pixel *)_dst; | |
| 89 | 1105926 | const pixel *src = (const pixel *)_src; | |
| 90 | 1105926 | const int16_t *sao_offset_val = sao->offset_val[c_idx]; | |
| 91 | 1105926 | int sao_eo_class = sao->eo_class[c_idx]; | |
| 92 | 1105926 | int init_x = 0, width = _width, height = _height; | |
| 93 | |||
| 94 | 1105926 | stride_dst /= sizeof(pixel); | |
| 95 | 1105926 | stride_src /= sizeof(pixel); | |
| 96 | |||
| 97 |
2/2✓ Branch 0 taken 453521 times.
✓ Branch 1 taken 99442 times.
|
1105926 | if (sao_eo_class != SAO_EO_VERT) { |
| 98 |
2/2✓ Branch 0 taken 14438 times.
✓ Branch 1 taken 439083 times.
|
907042 | if (borders[0]) { |
| 99 | 28876 | int offset_val = sao_offset_val[0]; | |
| 100 |
2/2✓ Branch 0 taken 692360 times.
✓ Branch 1 taken 14438 times.
|
1413596 | for (y = 0; y < height; y++) { |
| 101 | 1384720 | dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val); | |
| 102 | } | ||
| 103 | 28876 | init_x = 1; | |
| 104 | } | ||
| 105 |
2/2✓ Branch 0 taken 16650 times.
✓ Branch 1 taken 436871 times.
|
907042 | if (borders[2]) { |
| 106 | 33300 | int offset_val = sao_offset_val[0]; | |
| 107 | 33300 | int offset = width - 1; | |
| 108 |
2/2✓ Branch 0 taken 771128 times.
✓ Branch 1 taken 16650 times.
|
1575556 | for (x = 0; x < height; x++) { |
| 109 | 1542256 | dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val); | |
| 110 | } | ||
| 111 | 33300 | width--; | |
| 112 | } | ||
| 113 | } | ||
| 114 |
2/2✓ Branch 0 taken 458268 times.
✓ Branch 1 taken 94695 times.
|
1105926 | if (sao_eo_class != SAO_EO_HORIZ) { |
| 115 |
2/2✓ Branch 0 taken 18860 times.
✓ Branch 1 taken 439408 times.
|
916536 | if (borders[1]) { |
| 116 | 37720 | int offset_val = sao_offset_val[0]; | |
| 117 |
2/2✓ Branch 0 taken 914627 times.
✓ Branch 1 taken 18860 times.
|
1866974 | for (x = init_x; x < width; x++) |
| 118 | 1829254 | dst[x] = av_clip_pixel(src[x] + offset_val); | |
| 119 | } | ||
| 120 |
2/2✓ Branch 0 taken 24852 times.
✓ Branch 1 taken 433416 times.
|
916536 | if (borders[3]) { |
| 121 | 49704 | int offset_val = sao_offset_val[0]; | |
| 122 | 49704 | ptrdiff_t y_stride_dst = stride_dst * (height - 1); | |
| 123 | 49704 | ptrdiff_t y_stride_src = stride_src * (height - 1); | |
| 124 |
2/2✓ Branch 0 taken 1179228 times.
✓ Branch 1 taken 24852 times.
|
2408160 | for (x = init_x; x < width; x++) |
| 125 | 2358456 | dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val); | |
| 126 | 49704 | height--; | |
| 127 | } | ||
| 128 | } | ||
| 129 | 1105926 | } | |
| 130 | |||
| 131 | 68804 | 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 | 68804 | pixel *dst = (pixel *)_dst; | |
| 139 | 68804 | const pixel *src = (const pixel *)_src; | |
| 140 | 68804 | const int16_t *sao_offset_val = sao->offset_val[c_idx]; | |
| 141 | 68804 | int sao_eo_class = sao->eo_class[c_idx]; | |
| 142 | 68804 | int init_x = 0, init_y = 0, width = _width, height = _height; | |
| 143 | |||
| 144 | 68804 | stride_dst /= sizeof(pixel); | |
| 145 | 68804 | stride_src /= sizeof(pixel); | |
| 146 | |||
| 147 |
2/2✓ Branch 0 taken 22813 times.
✓ Branch 1 taken 11589 times.
|
68804 | if (sao_eo_class != SAO_EO_VERT) { |
| 148 |
2/2✓ Branch 0 taken 1981 times.
✓ Branch 1 taken 20832 times.
|
45626 | if (borders[0]) { |
| 149 | 3962 | int offset_val = sao_offset_val[0]; | |
| 150 |
2/2✓ Branch 0 taken 135128 times.
✓ Branch 1 taken 1981 times.
|
274218 | for (y = 0; y < height; y++) { |
| 151 | 270256 | dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val); | |
| 152 | } | ||
| 153 | 3962 | init_x = 1; | |
| 154 | } | ||
| 155 |
2/2✓ Branch 0 taken 1455 times.
✓ Branch 1 taken 21358 times.
|
45626 | if (borders[2]) { |
| 156 | 2910 | int offset_val = sao_offset_val[0]; | |
| 157 | 2910 | int offset = width - 1; | |
| 158 |
2/2✓ Branch 0 taken 101504 times.
✓ Branch 1 taken 1455 times.
|
205918 | for (x = 0; x < height; x++) { |
| 159 | 203008 | dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val); | |
| 160 | } | ||
| 161 | 2910 | width--; | |
| 162 | } | ||
| 163 | } | ||
| 164 |
2/2✓ Branch 0 taken 24643 times.
✓ Branch 1 taken 9759 times.
|
68804 | if (sao_eo_class != SAO_EO_HORIZ) { |
| 165 |
2/2✓ Branch 0 taken 3402 times.
✓ Branch 1 taken 21241 times.
|
49286 | if (borders[1]) { |
| 166 | 6804 | int offset_val = sao_offset_val[0]; | |
| 167 |
2/2✓ Branch 0 taken 230325 times.
✓ Branch 1 taken 3402 times.
|
467454 | for (x = init_x; x < width; x++) |
| 168 | 460650 | dst[x] = av_clip_pixel(src[x] + offset_val); | |
| 169 | 6804 | init_y = 1; | |
| 170 | } | ||
| 171 |
2/2✓ Branch 0 taken 3185 times.
✓ Branch 1 taken 21458 times.
|
49286 | if (borders[3]) { |
| 172 | 6370 | int offset_val = sao_offset_val[0]; | |
| 173 | 6370 | ptrdiff_t y_stride_dst = stride_dst * (height - 1); | |
| 174 | 6370 | ptrdiff_t y_stride_src = stride_src * (height - 1); | |
| 175 |
2/2✓ Branch 0 taken 219896 times.
✓ Branch 1 taken 3185 times.
|
446162 | for (x = init_x; x < width; x++) |
| 176 | 439792 | dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val); | |
| 177 | 6370 | height--; | |
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | { | ||
| 182 |
8/8✓ Branch 0 taken 33786 times.
✓ Branch 1 taken 616 times.
✓ Branch 2 taken 5392 times.
✓ Branch 3 taken 28394 times.
✓ Branch 4 taken 4920 times.
✓ Branch 5 taken 472 times.
✓ Branch 6 taken 4389 times.
✓ Branch 7 taken 531 times.
|
68804 | int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1]; |
| 183 |
8/8✓ Branch 0 taken 33695 times.
✓ Branch 1 taken 707 times.
✓ Branch 2 taken 7290 times.
✓ Branch 3 taken 26405 times.
✓ Branch 4 taken 6033 times.
✓ Branch 5 taken 1257 times.
✓ Branch 6 taken 5638 times.
✓ Branch 7 taken 395 times.
|
68804 | int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2]; |
| 184 |
8/8✓ Branch 0 taken 33552 times.
✓ Branch 1 taken 850 times.
✓ Branch 2 taken 5349 times.
✓ Branch 3 taken 28203 times.
✓ Branch 4 taken 4959 times.
✓ Branch 5 taken 390 times.
✓ Branch 6 taken 4198 times.
✓ Branch 7 taken 761 times.
|
68804 | int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3]; |
| 185 |
8/8✓ Branch 0 taken 33603 times.
✓ Branch 1 taken 799 times.
✓ Branch 2 taken 7306 times.
✓ Branch 3 taken 26297 times.
✓ Branch 4 taken 6475 times.
✓ Branch 5 taken 831 times.
✓ Branch 6 taken 5571 times.
✓ Branch 7 taken 904 times.
|
68804 | 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 411 times.
✓ Branch 1 taken 33991 times.
✓ Branch 2 taken 301 times.
✓ Branch 3 taken 110 times.
|
68804 | if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) { |
| 189 |
2/2✓ Branch 0 taken 25875 times.
✓ Branch 1 taken 301 times.
|
52352 | for(y = init_y+save_upper_left; y< height-save_lower_left; y++) |
| 190 | 51750 | dst[y*stride_dst] = src[y*stride_src]; | |
| 191 | } | ||
| 192 |
4/4✓ Branch 0 taken 496 times.
✓ Branch 1 taken 33906 times.
✓ Branch 2 taken 377 times.
✓ Branch 3 taken 119 times.
|
68804 | if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) { |
| 193 |
2/2✓ Branch 0 taken 31460 times.
✓ Branch 1 taken 377 times.
|
63674 | for(y = init_y+save_upper_right; y< height-save_lower_right; y++) |
| 194 | 62920 | dst[y*stride_dst+width-1] = src[y*stride_src+width-1]; | |
| 195 | } | ||
| 196 | |||
| 197 |
4/4✓ Branch 0 taken 482 times.
✓ Branch 1 taken 33920 times.
✓ Branch 2 taken 342 times.
✓ Branch 3 taken 140 times.
|
68804 | if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) { |
| 198 |
2/2✓ Branch 0 taken 25650 times.
✓ Branch 1 taken 342 times.
|
51984 | for(x = init_x+save_upper_left; x < width-save_upper_right; x++) |
| 199 | 51300 | dst[x] = src[x]; | |
| 200 | } | ||
| 201 |
4/4✓ Branch 0 taken 665 times.
✓ Branch 1 taken 33737 times.
✓ Branch 2 taken 489 times.
✓ Branch 3 taken 176 times.
|
68804 | if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) { |
| 202 |
2/2✓ Branch 0 taken 37867 times.
✓ Branch 1 taken 489 times.
|
76712 | for(x = init_x+save_lower_left; x < width-save_lower_right; x++) |
| 203 | 75734 | dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x]; | |
| 204 | } | ||
| 205 |
4/4✓ Branch 0 taken 616 times.
✓ Branch 1 taken 33786 times.
✓ Branch 2 taken 143 times.
✓ Branch 3 taken 473 times.
|
68804 | if(diag_edge[0] && sao_eo_class == SAO_EO_135D) |
| 206 | 286 | dst[0] = src[0]; | |
| 207 |
4/4✓ Branch 0 taken 707 times.
✓ Branch 1 taken 33695 times.
✓ Branch 2 taken 229 times.
✓ Branch 3 taken 478 times.
|
68804 | if(diag_edge[1] && sao_eo_class == SAO_EO_45D) |
| 208 | 458 | dst[width-1] = src[width-1]; | |
| 209 |
4/4✓ Branch 0 taken 850 times.
✓ Branch 1 taken 33552 times.
✓ Branch 2 taken 186 times.
✓ Branch 3 taken 664 times.
|
68804 | if(diag_edge[2] && sao_eo_class == SAO_EO_135D) |
| 210 | 372 | dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1]; | |
| 211 |
4/4✓ Branch 0 taken 799 times.
✓ Branch 1 taken 33603 times.
✓ Branch 2 taken 213 times.
✓ Branch 3 taken 586 times.
|
68804 | if(diag_edge[3] && sao_eo_class == SAO_EO_45D) |
| 212 | 426 | dst[stride_dst*(height-1)] = src[stride_src*(height-1)]; | |
| 213 | |||
| 214 | } | ||
| 215 | 68804 | } | |
| 216 | |||
| 217 | #undef CMP | ||
| 218 |