| Line | Branch | Exec | Source | 
|---|---|---|---|
| 1 | /* | ||
| 2 | * VVC filters | ||
| 3 | * | ||
| 4 | * Copyright (C) 2021 Nuo Mi | ||
| 5 | * | ||
| 6 | * This file is part of FFmpeg. | ||
| 7 | * | ||
| 8 | * FFmpeg is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with FFmpeg; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | #include "libavutil/frame.h" | ||
| 23 | #include "libavutil/imgutils.h" | ||
| 24 | |||
| 25 | #include "ctu.h" | ||
| 26 | #include "data.h" | ||
| 27 | #include "filter.h" | ||
| 28 | #include "refs.h" | ||
| 29 | |||
| 30 | #define LEFT 0 | ||
| 31 | #define TOP 1 | ||
| 32 | #define RIGHT 2 | ||
| 33 | #define BOTTOM 3 | ||
| 34 | #define MAX_EDGES 4 | ||
| 35 | |||
| 36 | #define DEFAULT_INTRA_TC_OFFSET 2 | ||
| 37 | |||
| 38 | #define POS(c_idx, x, y) \ | ||
| 39 | &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \ | ||
| 40 | (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)] | ||
| 41 | |||
| 42 | //Table 43 Derivation of threshold variables beta' and tc' from input Q | ||
| 43 | static const uint16_t tctable[66] = { | ||
| 44 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 45 | 0, 0, 3, 4, 4, 4, 4, 5, 5, 5, 5, 7, 7, 8, 9, 10, | ||
| 46 | 10, 11, 13, 14, 15, 17, 19, 21, 24, 25, 29, 33, 36, 41, 45, 51, | ||
| 47 | 57, 64, 71, 80, 89, 100, 112, 125, 141, 157, 177, 198, 222, 250, 280, 314, | ||
| 48 | 352, 395, | ||
| 49 | }; | ||
| 50 | |||
| 51 | //Table 43 Derivation of threshold variables beta' and tc' from input Q | ||
| 52 | static const uint8_t betatable[64] = { | ||
| 53 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 54 | 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, | ||
| 55 | 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, | ||
| 56 | 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, | ||
| 57 | }; | ||
| 58 | |||
| 59 | // One vertical and one horizontal virtual boundary in a CTU at most. The CTU will be divided into 4 subblocks. | ||
| 60 | #define MAX_VBBS 4 | ||
| 61 | |||
| 62 | 5036867 | static int get_virtual_boundary(const VVCFrameContext *fc, const int ctu_pos, const int vertical) | |
| 63 | { | ||
| 64 | 5036867 | const VVCSPS *sps = fc->ps.sps; | |
| 65 | 5036867 | const VVCPH *ph = &fc->ps.ph; | |
| 66 | 2/2✓ Branch 0 taken 2552010 times. ✓ Branch 1 taken 2484857 times. | 5036867 | const uint16_t *vbs = vertical ? ph->vb_pos_x : ph->vb_pos_y; | 
| 67 | 2/2✓ Branch 0 taken 2552010 times. ✓ Branch 1 taken 2484857 times. | 5036867 | const uint8_t nb_vbs = vertical ? ph->num_ver_vbs : ph->num_hor_vbs; | 
| 68 | 5036867 | const int pos = ctu_pos << sps->ctb_log2_size_y; | |
| 69 | |||
| 70 | 2/2✓ Branch 0 taken 329281 times. ✓ Branch 1 taken 4707586 times. | 5036867 | if (sps->r->sps_virtual_boundaries_enabled_flag) { | 
| 71 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 329281 times. | 329281 | for (int i = 0; i < nb_vbs; i++) { | 
| 72 | ✗ | const int o = vbs[i] - pos; | |
| 73 | ✗ | if (o >= 0 && o < sps->ctb_size_y) | |
| 74 | ✗ | return vbs[i]; | |
| 75 | } | ||
| 76 | } | ||
| 77 | 5036867 | return 0; | |
| 78 | } | ||
| 79 | |||
| 80 | 4947935 | static int is_virtual_boundary(const VVCFrameContext *fc, const int pos, const int vertical) | |
| 81 | { | ||
| 82 | 4947935 | return get_virtual_boundary(fc, pos >> fc->ps.sps->ctb_log2_size_y, vertical) == pos; | |
| 83 | } | ||
| 84 | |||
| 85 | 9287968 | static int get_qPc(const VVCFrameContext *fc, const int x0, const int y0, const int chroma) | |
| 86 | { | ||
| 87 | 9287968 | const int x = x0 >> MIN_TU_LOG2; | |
| 88 | 9287968 | const int y = y0 >> MIN_TU_LOG2; | |
| 89 | 9287968 | const int min_tu_width = fc->ps.pps->min_tu_width; | |
| 90 | 9287968 | return fc->tab.qp[chroma][x + y * min_tu_width]; | |
| 91 | } | ||
| 92 | |||
| 93 | 57715 | static void copy_ctb(uint8_t *dst, const uint8_t *src, const int width, const int height, | |
| 94 | const ptrdiff_t dst_stride, const ptrdiff_t src_stride) | ||
| 95 | { | ||
| 96 | 2/2✓ Branch 0 taken 5647556 times. ✓ Branch 1 taken 57715 times. | 5705271 | for (int y = 0; y < height; y++) { | 
| 97 | 5647556 | memcpy(dst, src, width); | |
| 98 | |||
| 99 | 5647556 | dst += dst_stride; | |
| 100 | 5647556 | src += src_stride; | |
| 101 | } | ||
| 102 | 57715 | } | |
| 103 | |||
| 104 | 30739 | static void copy_pixel(uint8_t *dst, const uint8_t *src, const int pixel_shift) | |
| 105 | { | ||
| 106 | 2/2✓ Branch 0 taken 28523 times. ✓ Branch 1 taken 2216 times. | 30739 | if (pixel_shift) | 
| 107 | 28523 | *(uint16_t *)dst = *(uint16_t *)src; | |
| 108 | else | ||
| 109 | 2216 | *dst = *src; | |
| 110 | 30739 | } | |
| 111 | |||
| 112 | 334517 | static void copy_vert(uint8_t *dst, const uint8_t *src, const int pixel_shift, const int height, | |
| 113 | const ptrdiff_t dst_stride, const ptrdiff_t src_stride) | ||
| 114 | { | ||
| 115 | int i; | ||
| 116 | 2/2✓ Branch 0 taken 8743 times. ✓ Branch 1 taken 325774 times. | 334517 | if (pixel_shift == 0) { | 
| 117 | 2/2✓ Branch 0 taken 370688 times. ✓ Branch 1 taken 8743 times. | 379431 | for (i = 0; i < height; i++) { | 
| 118 | 370688 | *dst = *src; | |
| 119 | 370688 | dst += dst_stride; | |
| 120 | 370688 | src += src_stride; | |
| 121 | } | ||
| 122 | } else { | ||
| 123 | 2/2✓ Branch 0 taken 31357464 times. ✓ Branch 1 taken 325774 times. | 31683238 | for (i = 0; i < height; i++) { | 
| 124 | 31357464 | *(uint16_t *)dst = *(uint16_t *)src; | |
| 125 | 31357464 | dst += dst_stride; | |
| 126 | 31357464 | src += src_stride; | |
| 127 | } | ||
| 128 | } | ||
| 129 | 334517 | } | |
| 130 | |||
| 131 | 316218 | static void copy_ctb_to_hv(VVCFrameContext *fc, const uint8_t *src, | |
| 132 | const ptrdiff_t src_stride, const int x, const int y, const int width, const int height, | ||
| 133 | const int c_idx, const int rx, const int ry, const int top) | ||
| 134 | { | ||
| 135 | 316218 | const int ps = fc->ps.sps->pixel_shift; | |
| 136 | 316218 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
| 137 | 316218 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
| 138 | |||
| 139 | 2/2✓ Branch 0 taken 158109 times. ✓ Branch 1 taken 158109 times. | 316218 | if (top) { | 
| 140 | /* top */ | ||
| 141 | 158109 | memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry) * w + x) << ps), | |
| 142 | 158109 | src, width << ps); | |
| 143 | } else { | ||
| 144 | /* bottom */ | ||
| 145 | 158109 | memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry + 1) * w + x) << ps), | |
| 146 | 158109 | src + src_stride * (height - 1), width << ps); | |
| 147 | |||
| 148 | /* copy vertical edges */ | ||
| 149 | 158109 | copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * rx) * h + y) << ps), src, ps, height, 1 << ps, src_stride); | |
| 150 | 158109 | copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * rx + 1) * h + y) << ps), src + ((width - 1) << ps), ps, height, 1 << ps, src_stride); | |
| 151 | } | ||
| 152 | 316218 | } | |
| 153 | |||
| 154 | 106110 | static void sao_copy_ctb_to_hv(VVCLocalContext *lc, const int rx, const int ry, const int top) | |
| 155 | { | ||
| 156 | 106110 | VVCFrameContext *fc = lc->fc; | |
| 157 | 106110 | const int ctb_size_y = fc->ps.sps->ctb_size_y; | |
| 158 | 106110 | const int x0 = rx << fc->ps.sps->ctb_log2_size_y; | |
| 159 | 106110 | const int y0 = ry << fc->ps.sps->ctb_log2_size_y; | |
| 160 | |||
| 161 | 4/4✓ Branch 0 taken 420216 times. ✓ Branch 1 taken 2112 times. ✓ Branch 2 taken 316218 times. ✓ Branch 3 taken 106110 times. | 422328 | for (int c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) { | 
| 162 | 316218 | const int x = x0 >> fc->ps.sps->hshift[c_idx]; | |
| 163 | 316218 | const int y = y0 >> fc->ps.sps->vshift[c_idx]; | |
| 164 | 316218 | const ptrdiff_t src_stride = fc->frame->linesize[c_idx]; | |
| 165 | 316218 | const int ctb_size_h = ctb_size_y >> fc->ps.sps->hshift[c_idx]; | |
| 166 | 316218 | const int ctb_size_v = ctb_size_y >> fc->ps.sps->vshift[c_idx]; | |
| 167 | 316218 | const int width = FFMIN(ctb_size_h, (fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]) - x); | |
| 168 | 316218 | const int height = FFMIN(ctb_size_v, (fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]) - y); | |
| 169 | 316218 | const uint8_t *src = POS(c_idx, x0, y0); | |
| 170 | 316218 | copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, c_idx, rx, ry, top); | |
| 171 | } | ||
| 172 | 106110 | } | |
| 173 | |||
| 174 | 53055 | void ff_vvc_sao_copy_ctb_to_hv(VVCLocalContext *lc, const int rx, const int ry, const int last_row) | |
| 175 | { | ||
| 176 | 2/2✓ Branch 0 taken 44652 times. ✓ Branch 1 taken 8403 times. | 53055 | if (ry) | 
| 177 | 44652 | sao_copy_ctb_to_hv(lc, rx, ry - 1, 0); | |
| 178 | |||
| 179 | 53055 | sao_copy_ctb_to_hv(lc, rx, ry, 1); | |
| 180 | |||
| 181 | 2/2✓ Branch 0 taken 8403 times. ✓ Branch 1 taken 44652 times. | 53055 | if (last_row) | 
| 182 | 8403 | sao_copy_ctb_to_hv(lc, rx, ry, 0); | |
| 183 | 53055 | } | |
| 184 | |||
| 185 | 328570 | static int sao_can_cross_slices(const VVCFrameContext *fc, const int rx, const int ry, const int dx, const int dy) | |
| 186 | { | ||
| 187 | 328570 | const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag; | |
| 188 | |||
| 189 | 4/4✓ Branch 0 taken 325450 times. ✓ Branch 1 taken 3120 times. ✓ Branch 2 taken 322718 times. ✓ Branch 3 taken 2732 times. | 328570 | return lfase || CTB(fc->tab.slice_idx, rx, ry) == CTB(fc->tab.slice_idx, rx + dx, ry + dy); | 
| 190 | } | ||
| 191 | |||
| 192 | 53055 | static void sao_get_edges(uint8_t vert_edge[2], uint8_t horiz_edge[2], uint8_t diag_edge[4], int *restore, | |
| 193 | const VVCLocalContext *lc, const int edges[4], const int rx, const int ry) | ||
| 194 | { | ||
| 195 | 53055 | const VVCFrameContext *fc = lc->fc; | |
| 196 | 53055 | const VVCSPS *sps = fc->ps.sps; | |
| 197 | 53055 | const H266RawSPS *rsps = sps->r; | |
| 198 | 53055 | const VVCPPS *pps = fc->ps.pps; | |
| 199 | 53055 | const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; | |
| 200 | 53055 | const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag; | |
| 201 | 4/4✓ Branch 0 taken 5081 times. ✓ Branch 1 taken 47974 times. ✓ Branch 2 taken 1662 times. ✓ Branch 3 taken 3419 times. | 53055 | const uint8_t no_tile_filter = pps->r->num_tiles_in_pic > 1 && !pps->r->pps_loop_filter_across_tiles_enabled_flag; | 
| 202 | 4/4✓ Branch 0 taken 2103 times. ✓ Branch 1 taken 50952 times. ✓ Branch 2 taken 1137 times. ✓ Branch 3 taken 966 times. | 53055 | const uint8_t no_subpic_filter = rsps->sps_num_subpics_minus1 && !rsps->sps_loop_filter_across_subpic_enabled_flag[subpic_idx]; | 
| 203 | 53055 | uint8_t lf_edge[] = { 0, 0, 0, 0 }; | |
| 204 | |||
| 205 | 8/8✓ Branch 0 taken 51918 times. ✓ Branch 1 taken 1137 times. ✓ Branch 2 taken 51366 times. ✓ Branch 3 taken 552 times. ✓ Branch 4 taken 3162 times. ✓ Branch 5 taken 48204 times. ✓ Branch 6 taken 184 times. ✓ Branch 7 taken 2978 times. | 53055 | *restore = no_subpic_filter || no_tile_filter || !lfase || rsps->sps_virtual_boundaries_enabled_flag; | 
| 206 | |||
| 207 | 2/2✓ Branch 0 taken 2978 times. ✓ Branch 1 taken 50077 times. | 53055 | if (!*restore) | 
| 208 | 2978 | return; | |
| 209 | |||
| 210 | 2/2✓ Branch 0 taken 45447 times. ✓ Branch 1 taken 4630 times. | 50077 | if (!edges[LEFT]) { | 
| 211 | 4/4✓ Branch 0 taken 1458 times. ✓ Branch 1 taken 43989 times. ✓ Branch 2 taken 612 times. ✓ Branch 3 taken 846 times. | 45447 | lf_edge[LEFT] = no_tile_filter && pps->ctb_to_col_bd[rx] == rx; | 
| 212 | 4/4✓ Branch 0 taken 1017 times. ✓ Branch 1 taken 44430 times. ✓ Branch 2 taken 309 times. ✓ Branch 3 taken 708 times. | 45447 | lf_edge[LEFT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] == rx; | 
| 213 | 45447 | lf_edge[LEFT] |= is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1); | |
| 214 | 4/4✓ Branch 1 taken 45148 times. ✓ Branch 2 taken 299 times. ✓ Branch 3 taken 322 times. ✓ Branch 4 taken 44826 times. | 45447 | vert_edge[0] = !sao_can_cross_slices(fc, rx, ry, -1, 0) || lf_edge[LEFT]; | 
| 215 | } | ||
| 216 | 2/2✓ Branch 0 taken 45447 times. ✓ Branch 1 taken 4630 times. | 50077 | if (!edges[RIGHT]) { | 
| 217 | 4/4✓ Branch 0 taken 1458 times. ✓ Branch 1 taken 43989 times. ✓ Branch 2 taken 612 times. ✓ Branch 3 taken 846 times. | 45447 | lf_edge[RIGHT] = no_tile_filter && pps->ctb_to_col_bd[rx] != pps->ctb_to_col_bd[rx + 1]; | 
| 218 | 4/4✓ Branch 0 taken 996 times. ✓ Branch 1 taken 44451 times. ✓ Branch 2 taken 288 times. ✓ Branch 3 taken 708 times. | 45447 | lf_edge[RIGHT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] + rsps->sps_subpic_width_minus1[subpic_idx] == rx; | 
| 219 | 45447 | lf_edge[RIGHT] |= is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1); | |
| 220 | 4/4✓ Branch 1 taken 45148 times. ✓ Branch 2 taken 299 times. ✓ Branch 3 taken 318 times. ✓ Branch 4 taken 44830 times. | 45447 | vert_edge[1] = !sao_can_cross_slices(fc, rx, ry, 1, 0) || lf_edge[RIGHT]; | 
| 221 | } | ||
| 222 | 2/2✓ Branch 0 taken 42008 times. ✓ Branch 1 taken 8069 times. | 50077 | if (!edges[TOP]) { | 
| 223 | 4/4✓ Branch 0 taken 1356 times. ✓ Branch 1 taken 40652 times. ✓ Branch 2 taken 564 times. ✓ Branch 3 taken 792 times. | 42008 | lf_edge[TOP] = no_tile_filter && pps->ctb_to_row_bd[ry] == ry; | 
| 224 | 4/4✓ Branch 0 taken 852 times. ✓ Branch 1 taken 41156 times. ✓ Branch 2 taken 222 times. ✓ Branch 3 taken 630 times. | 42008 | lf_edge[TOP] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] == ry; | 
| 225 | 42008 | lf_edge[TOP] |= is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0); | |
| 226 | 4/4✓ Branch 1 taken 41655 times. ✓ Branch 2 taken 353 times. ✓ Branch 3 taken 282 times. ✓ Branch 4 taken 41373 times. | 42008 | horiz_edge[0] = !sao_can_cross_slices(fc, rx, ry, 0, -1) || lf_edge[TOP]; | 
| 227 | } | ||
| 228 | 2/2✓ Branch 0 taken 42008 times. ✓ Branch 1 taken 8069 times. | 50077 | if (!edges[BOTTOM]) { | 
| 229 | 4/4✓ Branch 0 taken 1356 times. ✓ Branch 1 taken 40652 times. ✓ Branch 2 taken 564 times. ✓ Branch 3 taken 792 times. | 42008 | lf_edge[BOTTOM] = no_tile_filter && pps->ctb_to_row_bd[ry] != pps->ctb_to_row_bd[ry + 1]; | 
| 230 | 4/4✓ Branch 0 taken 915 times. ✓ Branch 1 taken 41093 times. ✓ Branch 2 taken 285 times. ✓ Branch 3 taken 630 times. | 42008 | lf_edge[BOTTOM] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] + rsps->sps_subpic_height_minus1[subpic_idx] == ry; | 
| 231 | 42008 | lf_edge[BOTTOM] |= is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0); | |
| 232 | 4/4✓ Branch 1 taken 41655 times. ✓ Branch 2 taken 353 times. ✓ Branch 3 taken 294 times. ✓ Branch 4 taken 41361 times. | 42008 | horiz_edge[1] = !sao_can_cross_slices(fc, rx, ry, 0, 1) || lf_edge[BOTTOM]; | 
| 233 | } | ||
| 234 | |||
| 235 | 4/4✓ Branch 0 taken 45447 times. ✓ Branch 1 taken 4630 times. ✓ Branch 2 taken 38415 times. ✓ Branch 3 taken 7032 times. | 50077 | if (!edges[LEFT] && !edges[TOP]) | 
| 236 | 6/6✓ Branch 1 taken 38058 times. ✓ Branch 2 taken 357 times. ✓ Branch 3 taken 37806 times. ✓ Branch 4 taken 252 times. ✓ Branch 5 taken 144 times. ✓ Branch 6 taken 37662 times. | 38415 | diag_edge[0] = !sao_can_cross_slices(fc, rx, ry, -1, -1) || lf_edge[LEFT] || lf_edge[TOP]; | 
| 237 | |||
| 238 | 4/4✓ Branch 0 taken 42008 times. ✓ Branch 1 taken 8069 times. ✓ Branch 2 taken 38415 times. ✓ Branch 3 taken 3593 times. | 50077 | if (!edges[TOP] && !edges[RIGHT]) | 
| 239 | 6/6✓ Branch 1 taken 38058 times. ✓ Branch 2 taken 357 times. ✓ Branch 3 taken 37806 times. ✓ Branch 4 taken 252 times. ✓ Branch 5 taken 144 times. ✓ Branch 6 taken 37662 times. | 38415 | diag_edge[1] = !sao_can_cross_slices(fc, rx, ry, 1, -1) || lf_edge[RIGHT] || lf_edge[TOP]; | 
| 240 | |||
| 241 | 4/4✓ Branch 0 taken 45447 times. ✓ Branch 1 taken 4630 times. ✓ Branch 2 taken 38415 times. ✓ Branch 3 taken 7032 times. | 50077 | if (!edges[RIGHT] && !edges[BOTTOM]) | 
| 242 | 6/6✓ Branch 1 taken 38058 times. ✓ Branch 2 taken 357 times. ✓ Branch 3 taken 37806 times. ✓ Branch 4 taken 252 times. ✓ Branch 5 taken 152 times. ✓ Branch 6 taken 37654 times. | 38415 | diag_edge[2] = !sao_can_cross_slices(fc, rx, ry, 1, 1) || lf_edge[RIGHT] || lf_edge[BOTTOM]; | 
| 243 | |||
| 244 | 4/4✓ Branch 0 taken 45447 times. ✓ Branch 1 taken 4630 times. ✓ Branch 2 taken 38415 times. ✓ Branch 3 taken 7032 times. | 50077 | if (!edges[LEFT] && !edges[BOTTOM]) | 
| 245 | 6/6✓ Branch 1 taken 38058 times. ✓ Branch 2 taken 357 times. ✓ Branch 3 taken 37802 times. ✓ Branch 4 taken 256 times. ✓ Branch 5 taken 152 times. ✓ Branch 6 taken 37650 times. | 38415 | diag_edge[3] = !sao_can_cross_slices(fc, rx, ry, -1, 1) || lf_edge[LEFT] || lf_edge[BOTTOM]; | 
| 246 | } | ||
| 247 | |||
| 248 | 16738 | static void sao_copy_hor(uint8_t *dst, const ptrdiff_t dst_stride, | |
| 249 | const uint8_t *src, const ptrdiff_t src_stride, const int width, const int edges[4], const int ps) | ||
| 250 | { | ||
| 251 | 16738 | const int left = 1 - edges[LEFT]; | |
| 252 | 16738 | const int right = 1 - edges[RIGHT]; | |
| 253 | 16738 | int pos = 0; | |
| 254 | |||
| 255 | 16738 | src -= left << ps; | |
| 256 | 16738 | dst -= left << ps; | |
| 257 | |||
| 258 | 2/2✓ Branch 0 taken 15291 times. ✓ Branch 1 taken 1447 times. | 16738 | if (left) { | 
| 259 | 15291 | copy_pixel(dst, src, ps); | |
| 260 | 15291 | pos += (1 << ps); | |
| 261 | } | ||
| 262 | 16738 | memcpy(dst + pos, src + pos, width << ps); | |
| 263 | 2/2✓ Branch 0 taken 15448 times. ✓ Branch 1 taken 1290 times. | 16738 | if (right) { | 
| 264 | 15448 | pos += width << ps; | |
| 265 | 15448 | copy_pixel(dst + pos, src + pos, ps); | |
| 266 | } | ||
| 267 | 16738 | } | |
| 268 | |||
| 269 | 10076 | static void sao_extends_edges(uint8_t *dst, const ptrdiff_t dst_stride, | |
| 270 | const uint8_t *src, const ptrdiff_t src_stride, const int width, const int height, | ||
| 271 | const VVCFrameContext *fc, const int x0, const int y0, const int rx, const int ry, const int edges[4], const int c_idx) | ||
| 272 | { | ||
| 273 | 10076 | const uint8_t *sao_h = fc->tab.sao_pixel_buffer_h[c_idx]; | |
| 274 | 10076 | const uint8_t *sao_v = fc->tab.sao_pixel_buffer_v[c_idx]; | |
| 275 | 10076 | const int x = x0 >> fc->ps.sps->hshift[c_idx]; | |
| 276 | 10076 | const int y = y0 >> fc->ps.sps->vshift[c_idx]; | |
| 277 | 10076 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
| 278 | 10076 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
| 279 | 10076 | const int ps = fc->ps.sps->pixel_shift; | |
| 280 | |||
| 281 | 2/2✓ Branch 0 taken 8376 times. ✓ Branch 1 taken 1700 times. | 10076 | if (!edges[TOP]) | 
| 282 | 8376 | sao_copy_hor(dst - dst_stride, dst_stride, sao_h + (((2 * ry - 1) * w + x) << ps), src_stride, width, edges, ps); | |
| 283 | |||
| 284 | 2/2✓ Branch 0 taken 8362 times. ✓ Branch 1 taken 1714 times. | 10076 | if (!edges[BOTTOM]) | 
| 285 | 8362 | sao_copy_hor(dst + height * dst_stride, dst_stride, sao_h + (((2 * ry + 2) * w + x) << ps), src_stride, width, edges, ps); | |
| 286 | |||
| 287 | 2/2✓ Branch 0 taken 9120 times. ✓ Branch 1 taken 956 times. | 10076 | if (!edges[LEFT]) | 
| 288 | 9120 | copy_vert(dst - (1 << ps), sao_v + (((2 * rx - 1) * h + y) << ps), ps, height, dst_stride, 1 << ps); | |
| 289 | |||
| 290 | 2/2✓ Branch 0 taken 9179 times. ✓ Branch 1 taken 897 times. | 10076 | if (!edges[RIGHT]) | 
| 291 | 9179 | copy_vert(dst + (width << ps), sao_v + (((2 * rx + 2) * h + y) << ps), ps, height, dst_stride, 1 << ps); | |
| 292 | |||
| 293 | 10076 | copy_ctb(dst, src, width << ps, height, dst_stride, src_stride); | |
| 294 | 10076 | } | |
| 295 | |||
| 296 | ✗ | static void sao_restore_vb(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *src, ptrdiff_t src_stride, | |
| 297 | const int width, const int height, const int vb_pos, const int ps, const int vertical) | ||
| 298 | { | ||
| 299 | ✗ | int w = 2; | |
| 300 | ✗ | int h = (vertical ? height : width); | |
| 301 | ✗ | int dx = vb_pos - 1; | |
| 302 | ✗ | int dy = 0; | |
| 303 | |||
| 304 | ✗ | if (!vertical) { | |
| 305 | ✗ | FFSWAP(int, w, h); | |
| 306 | ✗ | FFSWAP(int, dx, dy); | |
| 307 | } | ||
| 308 | ✗ | dst += dy * dst_stride +(dx << ps); | |
| 309 | ✗ | src += dy * src_stride +(dx << ps); | |
| 310 | |||
| 311 | ✗ | av_image_copy_plane(dst, dst_stride, src, src_stride, w << ps, h); | |
| 312 | ✗ | } | |
| 313 | |||
| 314 | 53055 | void ff_vvc_sao_filter(VVCLocalContext *lc, int x0, int y0) | |
| 315 | { | ||
| 316 | 53055 | VVCFrameContext *fc = lc->fc; | |
| 317 | 53055 | const VVCSPS *sps = fc->ps.sps; | |
| 318 | 53055 | const int rx = x0 >> sps->ctb_log2_size_y; | |
| 319 | 53055 | const int ry = y0 >> sps->ctb_log2_size_y; | |
| 320 | 53055 | const int edges[4] = { !rx, !ry, rx == fc->ps.pps->ctb_width - 1, ry == fc->ps.pps->ctb_height - 1 }; | |
| 321 | 53055 | const SAOParams *sao = &CTB(fc->tab.sao, rx, ry); | |
| 322 | // flags indicating unfilterable edges | ||
| 323 | 53055 | uint8_t vert_edge[] = { 0, 0 }; | |
| 324 | 53055 | uint8_t horiz_edge[] = { 0, 0 }; | |
| 325 | 53055 | uint8_t diag_edge[] = { 0, 0, 0, 0 }; | |
| 326 | 53055 | int restore, vb_x = 0, vb_y = 0;; | |
| 327 | |||
| 328 | 2/2✓ Branch 0 taken 1029 times. ✓ Branch 1 taken 52026 times. | 53055 | if (sps->r->sps_virtual_boundaries_enabled_flag) { | 
| 329 | 1029 | vb_x = get_virtual_boundary(fc, rx, 1); | |
| 330 | 1029 | vb_y = get_virtual_boundary(fc, ry, 0); | |
| 331 | } | ||
| 332 | |||
| 333 | 53055 | sao_get_edges(vert_edge, horiz_edge, diag_edge, &restore, lc, edges, rx, ry); | |
| 334 | |||
| 335 | 4/4✓ Branch 0 taken 210108 times. ✓ Branch 1 taken 1056 times. ✓ Branch 2 taken 158109 times. ✓ Branch 3 taken 53055 times. | 211164 | for (int c_idx = 0; c_idx < (sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) { | 
| 336 | static const uint8_t sao_tab[16] = { 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8 }; | ||
| 337 | 158109 | const ptrdiff_t src_stride = fc->frame->linesize[c_idx]; | |
| 338 | 158109 | uint8_t *src = POS(c_idx, x0, y0); | |
| 339 | 158109 | const int hs = sps->hshift[c_idx]; | |
| 340 | 158109 | const int vs = sps->vshift[c_idx]; | |
| 341 | 158109 | const int ps = sps->pixel_shift; | |
| 342 | 158109 | const int width = FFMIN(sps->ctb_size_y, fc->ps.pps->width - x0) >> hs; | |
| 343 | 158109 | const int height = FFMIN(sps->ctb_size_y, fc->ps.pps->height - y0) >> vs; | |
| 344 | 158109 | const int tab = sao_tab[(FFALIGN(width, 8) >> 3) - 1]; | |
| 345 | 158109 | const int sao_eo_class = sao->eo_class[c_idx]; | |
| 346 | |||
| 347 | 3/3✓ Branch 0 taken 5836 times. ✓ Branch 1 taken 10076 times. ✓ Branch 2 taken 142197 times. | 158109 | switch (sao->type_idx[c_idx]) { | 
| 348 | 5836 | case SAO_BAND: | |
| 349 | 5836 | fc->vvcdsp.sao.band_filter[tab](src, src, src_stride, src_stride, | |
| 350 | 5836 | sao->offset_val[c_idx], sao->band_position[c_idx], width, height); | |
| 351 | 5836 | break; | |
| 352 | 10076 | case SAO_EDGE: | |
| 353 | { | ||
| 354 | 10076 | const ptrdiff_t dst_stride = 2 * MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE; | |
| 355 | 10076 | uint8_t *dst = lc->sao_buffer + dst_stride + AV_INPUT_BUFFER_PADDING_SIZE; | |
| 356 | |||
| 357 | 10076 | sao_extends_edges(dst, dst_stride, src, src_stride, width, height, fc, x0, y0, rx, ry, edges, c_idx); | |
| 358 | |||
| 359 | 10076 | fc->vvcdsp.sao.edge_filter[tab](src, dst, src_stride, sao->offset_val[c_idx], | |
| 360 | 10076 | sao->eo_class[c_idx], width, height); | |
| 361 | 10076 | fc->vvcdsp.sao.edge_restore[restore](src, dst, src_stride, dst_stride, | |
| 362 | sao, edges, width, height, c_idx, vert_edge, horiz_edge, diag_edge); | ||
| 363 | |||
| 364 | 1/4✗ Branch 0 not taken. ✓ Branch 1 taken 10076 times. ✗ Branch 2 not taken. ✗ Branch 3 not taken. | 10076 | if (vb_x > x0 && sao_eo_class != SAO_EO_VERT) | 
| 365 | ✗ | sao_restore_vb(src, src_stride, dst, dst_stride, width, height, (vb_x - x0) >> hs, ps, 1); | |
| 366 | 1/4✗ Branch 0 not taken. ✓ Branch 1 taken 10076 times. ✗ Branch 2 not taken. ✗ Branch 3 not taken. | 10076 | if (vb_y > y0 && sao_eo_class != SAO_EO_HORIZ) | 
| 367 | ✗ | sao_restore_vb(src, src_stride, dst, dst_stride, width, height, (vb_y - y0) >> vs, ps, 0); | |
| 368 | |||
| 369 | 10076 | break; | |
| 370 | } | ||
| 371 | } | ||
| 372 | } | ||
| 373 | 53055 | } | |
| 374 | |||
| 375 | #define TAB_BS(t, x, y) (t)[((y) >> MIN_TU_LOG2) * (fc->ps.pps->min_tu_width) + ((x) >> MIN_TU_LOG2)] | ||
| 376 | #define TAB_MAX_LEN(t, x, y) (t)[((y) >> MIN_TU_LOG2) * (fc->ps.pps->min_tu_width) + ((x) >> MIN_TU_LOG2)] | ||
| 377 | |||
| 378 | //8 samples a time | ||
| 379 | #define DEBLOCK_STEP 8 | ||
| 380 | #define LUMA_GRID 4 | ||
| 381 | #define CHROMA_GRID 8 | ||
| 382 | |||
| 383 | 11489264 | static int boundary_strength(const VVCLocalContext *lc, const MvField *curr, const MvField *neigh, | |
| 384 | const RefPicList *neigh_rpl) | ||
| 385 | { | ||
| 386 | 11489264 | RefPicList *rpl = lc->sc->rpl; | |
| 387 | |||
| 388 | 2/2✓ Branch 0 taken 8974 times. ✓ Branch 1 taken 11480290 times. | 11489264 | if (curr->pred_flag == PF_PLT) | 
| 389 | 8974 | return 0; | |
| 390 | |||
| 391 | 2/2✓ Branch 0 taken 111582 times. ✓ Branch 1 taken 11368708 times. | 11480290 | if (curr->pred_flag == PF_IBC) | 
| 392 | 4/4✓ Branch 0 taken 66652 times. ✓ Branch 1 taken 44930 times. ✓ Branch 2 taken 5166 times. ✓ Branch 3 taken 61486 times. | 111582 | return FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8; | 
| 393 | |||
| 394 | 4/4✓ Branch 0 taken 5528656 times. ✓ Branch 1 taken 5840052 times. ✓ Branch 2 taken 5188379 times. ✓ Branch 3 taken 340277 times. | 11368708 | if (curr->pred_flag == PF_BI && neigh->pred_flag == PF_BI) { | 
| 395 | // same L0 and L1 | ||
| 396 | 2/2✓ Branch 0 taken 5106279 times. ✓ Branch 1 taken 82100 times. | 5188379 | if (rpl[L0].refs[curr->ref_idx[L0]].poc == neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc && | 
| 397 | 2/2✓ Branch 0 taken 554793 times. ✓ Branch 1 taken 4551486 times. | 5106279 | rpl[L0].refs[curr->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc && | 
| 398 | 2/2✓ Branch 0 taken 551249 times. ✓ Branch 1 taken 3544 times. | 554793 | neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc) { | 
| 399 | 4/4✓ Branch 0 taken 503952 times. ✓ Branch 1 taken 47297 times. ✓ Branch 2 taken 478187 times. ✓ Branch 3 taken 25765 times. | 551249 | if ((FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 || | 
| 400 | 4/4✓ Branch 0 taken 474364 times. ✓ Branch 1 taken 3823 times. ✓ Branch 2 taken 3253 times. ✓ Branch 3 taken 471111 times. | 478187 | FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8) && | 
| 401 | 4/4✓ Branch 0 taken 19736 times. ✓ Branch 1 taken 60402 times. ✓ Branch 2 taken 4909 times. ✓ Branch 3 taken 14827 times. | 80138 | (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 || | 
| 402 | 4/4✓ Branch 0 taken 2557 times. ✓ Branch 1 taken 2352 times. ✓ Branch 2 taken 2041 times. ✓ Branch 3 taken 516 times. | 4909 | FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8)) | 
| 403 | 79622 | return 1; | |
| 404 | else | ||
| 405 | 471627 | return 0; | |
| 406 | 2/2✓ Branch 0 taken 4555030 times. ✓ Branch 1 taken 82100 times. | 4637130 | } else if (neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc && | 
| 407 | 2/2✓ Branch 0 taken 4534658 times. ✓ Branch 1 taken 20372 times. | 4555030 | neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) { | 
| 408 | 4/4✓ Branch 0 taken 3995874 times. ✓ Branch 1 taken 538784 times. ✓ Branch 2 taken 3838199 times. ✓ Branch 3 taken 157675 times. | 4534658 | if (FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 || | 
| 409 | 4/4✓ Branch 0 taken 3803900 times. ✓ Branch 1 taken 34299 times. ✓ Branch 2 taken 21517 times. ✓ Branch 3 taken 3782383 times. | 3838199 | FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8) | 
| 410 | 752275 | return 1; | |
| 411 | else | ||
| 412 | 3782383 | return 0; | |
| 413 | 2/2✓ Branch 0 taken 28007 times. ✓ Branch 1 taken 74465 times. | 102472 | } else if (neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc && | 
| 414 | 2/2✓ Branch 0 taken 8707 times. ✓ Branch 1 taken 19300 times. | 28007 | neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) { | 
| 415 | 4/4✓ Branch 0 taken 2997 times. ✓ Branch 1 taken 5710 times. ✓ Branch 2 taken 1184 times. ✓ Branch 3 taken 1813 times. | 8707 | if (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 || | 
| 416 | 4/4✓ Branch 0 taken 869 times. ✓ Branch 1 taken 315 times. ✓ Branch 2 taken 180 times. ✓ Branch 3 taken 689 times. | 1184 | FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8) | 
| 417 | 8018 | return 1; | |
| 418 | else | ||
| 419 | 689 | return 0; | |
| 420 | } else { | ||
| 421 | 93765 | return 1; | |
| 422 | } | ||
| 423 | 4/4✓ Branch 0 taken 5840052 times. ✓ Branch 1 taken 340277 times. ✓ Branch 2 taken 5492576 times. ✓ Branch 3 taken 347476 times. | 6180329 | } else if ((curr->pred_flag != PF_BI) && (neigh->pred_flag != PF_BI)){ // 1 MV | 
| 424 | Mv A, B; | ||
| 425 | int ref_A, ref_B; | ||
| 426 | |||
| 427 | 2/2✓ Branch 0 taken 4250897 times. ✓ Branch 1 taken 1241679 times. | 5492576 | if (curr->pred_flag & 1) { | 
| 428 | 4250897 | A = curr->mv[0]; | |
| 429 | 4250897 | ref_A = rpl[L0].refs[curr->ref_idx[L0]].poc; | |
| 430 | } else { | ||
| 431 | 1241679 | A = curr->mv[1]; | |
| 432 | 1241679 | ref_A = rpl[L1].refs[curr->ref_idx[L1]].poc; | |
| 433 | } | ||
| 434 | |||
| 435 | 2/2✓ Branch 0 taken 4249354 times. ✓ Branch 1 taken 1243222 times. | 5492576 | if (neigh->pred_flag & 1) { | 
| 436 | 4249354 | B = neigh->mv[0]; | |
| 437 | 4249354 | ref_B = neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc; | |
| 438 | } else { | ||
| 439 | 1243222 | B = neigh->mv[1]; | |
| 440 | 1243222 | ref_B = neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc; | |
| 441 | } | ||
| 442 | |||
| 443 | 2/2✓ Branch 0 taken 5326415 times. ✓ Branch 1 taken 166161 times. | 5492576 | if (ref_A == ref_B) { | 
| 444 | 4/4✓ Branch 0 taken 4953740 times. ✓ Branch 1 taken 372675 times. ✓ Branch 2 taken 160902 times. ✓ Branch 3 taken 4792838 times. | 5326415 | if (FFABS(A.x - B.x) >= 8 || FFABS(A.y - B.y) >= 8) | 
| 445 | 533577 | return 1; | |
| 446 | else | ||
| 447 | 4792838 | return 0; | |
| 448 | } else | ||
| 449 | 166161 | return 1; | |
| 450 | } | ||
| 451 | |||
| 452 | 687753 | return 1; | |
| 453 | } | ||
| 454 | |||
| 455 | //part of 8.8.3.3 Derivation process of transform block boundary | ||
| 456 | 12295809 | static void derive_max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy, | |
| 457 | const int size_q, const int has_subblock, const int vertical, uint8_t *max_len_p, uint8_t *max_len_q) | ||
| 458 | { | ||
| 459 | 2/2✓ Branch 0 taken 5895410 times. ✓ Branch 1 taken 6400399 times. | 12295809 | const int px = vertical ? qx - 1 : qx; | 
| 460 | 2/2✓ Branch 0 taken 6400399 times. ✓ Branch 1 taken 5895410 times. | 12295809 | const int py = !vertical ? qy - 1 : qy; | 
| 461 | 2/2✓ Branch 0 taken 5895410 times. ✓ Branch 1 taken 6400399 times. | 12295809 | const uint8_t *tb_size = vertical ? fc->tab.tb_width[LUMA] : fc->tab.tb_height[LUMA]; | 
| 462 | 12295809 | const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)]; | |
| 463 | 12295809 | const int min_cb_log2 = fc->ps.sps->min_cb_log2_size_y; | |
| 464 | 12295809 | const int off_p = (py >> min_cb_log2) * fc->ps.pps->min_cb_width + (px >> min_cb_log2); | |
| 465 | |||
| 466 | 4/4✓ Branch 0 taken 10363420 times. ✓ Branch 1 taken 1932389 times. ✓ Branch 2 taken 867487 times. ✓ Branch 3 taken 9495933 times. | 12295809 | if (size_p <= 4 || size_q <= 4) { | 
| 467 | 2799876 | *max_len_p = *max_len_q = 1; | |
| 468 | } else { | ||
| 469 | 9495933 | *max_len_p = *max_len_q = 3; | |
| 470 | 2/2✓ Branch 0 taken 6280116 times. ✓ Branch 1 taken 3215817 times. | 9495933 | if (size_p >= 32) | 
| 471 | 6280116 | *max_len_p = 7; | |
| 472 | 2/2✓ Branch 0 taken 6106506 times. ✓ Branch 1 taken 3389427 times. | 9495933 | if (size_q >= 32) | 
| 473 | 6106506 | *max_len_q = 7; | |
| 474 | } | ||
| 475 | 2/2✓ Branch 0 taken 1397326 times. ✓ Branch 1 taken 10898483 times. | 12295809 | if (has_subblock) | 
| 476 | 1397326 | *max_len_q = FFMIN(5, *max_len_q); | |
| 477 | 4/4✓ Branch 0 taken 11029694 times. ✓ Branch 1 taken 1266115 times. ✓ Branch 2 taken 260568 times. ✓ Branch 3 taken 10769126 times. | 12295809 | if (fc->tab.msf[off_p] || fc->tab.iaf[off_p]) | 
| 478 | 1526683 | *max_len_p = FFMIN(5, *max_len_p); | |
| 479 | 12295809 | } | |
| 480 | |||
| 481 | 167228 | static void vvc_deblock_subblock_bs(const VVCLocalContext *lc, | |
| 482 | const int cb, int x0, int y0, int width, int height, const int vertical) | ||
| 483 | { | ||
| 484 | 167228 | const VVCFrameContext *fc = lc->fc; | |
| 485 | 167228 | const MvField *tab_mvf = fc->tab.mvf; | |
| 486 | 167228 | const RefPicList *rpl = lc->sc->rpl; | |
| 487 | 167228 | int stridea = fc->ps.pps->min_pu_width; | |
| 488 | 167228 | int strideb = 1; | |
| 489 | 167228 | const int log2_min_pu_size = MIN_PU_LOG2; | |
| 490 | |||
| 491 | 2/2✓ Branch 0 taken 84021 times. ✓ Branch 1 taken 83207 times. | 167228 | if (!vertical) { | 
| 492 | 84021 | FFSWAP(int, x0, y0); | |
| 493 | 84021 | FFSWAP(int, width, height); | |
| 494 | 84021 | FFSWAP(int, stridea, strideb); | |
| 495 | } | ||
| 496 | |||
| 497 | // bs for TU internal vertical PU boundaries | ||
| 498 | 2/2✓ Branch 0 taken 605893 times. ✓ Branch 1 taken 167228 times. | 773121 | for (int i = 8 - ((x0 - cb) % 8); i < width; i += 8) { | 
| 499 | 605893 | const int is_vb = is_virtual_boundary(fc, x0 + i, vertical); | |
| 500 | 605893 | const int xp_pu = (x0 + i - 1) >> log2_min_pu_size; | |
| 501 | 605893 | const int xq_pu = (x0 + i) >> log2_min_pu_size; | |
| 502 | |||
| 503 | 2/2✓ Branch 0 taken 6497682 times. ✓ Branch 1 taken 605893 times. | 7103575 | for (int j = 0; j < height; j += 4) { | 
| 504 | 6497682 | const int y_pu = (y0 + j) >> log2_min_pu_size; | |
| 505 | 6497682 | const MvField *mvf_p = &tab_mvf[y_pu * stridea + xp_pu * strideb]; | |
| 506 | 6497682 | const MvField *mvf_q = &tab_mvf[y_pu * stridea + xq_pu * strideb]; | |
| 507 | 1/2✓ Branch 0 taken 6497682 times. ✗ Branch 1 not taken. | 6497682 | const int bs = is_vb ? 0 : boundary_strength(lc, mvf_q, mvf_p, rpl); | 
| 508 | 6497682 | int x = x0 + i; | |
| 509 | 6497682 | int y = y0 + j; | |
| 510 | 6497682 | uint8_t max_len_p = 0, max_len_q = 0; | |
| 511 | |||
| 512 | 2/2✓ Branch 0 taken 3230782 times. ✓ Branch 1 taken 3266900 times. | 6497682 | if (!vertical) | 
| 513 | 3230782 | FFSWAP(int, x, y); | |
| 514 | |||
| 515 | 6497682 | TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs; | |
| 516 | |||
| 517 | 4/4✓ Branch 0 taken 6496102 times. ✓ Branch 1 taken 1580 times. ✓ Branch 2 taken 1816 times. ✓ Branch 3 taken 6494286 times. | 6497682 | if (i == 4 || i == width - 4) | 
| 518 | 3396 | max_len_p = max_len_q = 1; | |
| 519 | 4/4✓ Branch 0 taken 5054010 times. ✓ Branch 1 taken 1440276 times. ✓ Branch 2 taken 1201958 times. ✓ Branch 3 taken 3852052 times. | 6494286 | else if (i == 8 || i == width - 8) | 
| 520 | 2642234 | max_len_p = max_len_q = 2; | |
| 521 | else | ||
| 522 | 3852052 | max_len_p = max_len_q = 3; | |
| 523 | |||
| 524 | 6497682 | TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p; | |
| 525 | 6497682 | TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q; | |
| 526 | } | ||
| 527 | } | ||
| 528 | 167228 | } | |
| 529 | |||
| 530 | 48299129 | static av_always_inline int deblock_bs(const VVCLocalContext *lc, | |
| 531 | const int x_p, const int y_p, const int x_q, const int y_q, const CodingUnit *cu, const TransformUnit *tu, | ||
| 532 | const RefPicList *rpl_p, const int c_idx, const int off_to_cb, const uint8_t has_sub_block) | ||
| 533 | { | ||
| 534 | 48299129 | const VVCFrameContext *fc = lc->fc; | |
| 535 | 48299129 | const MvField *tab_mvf = fc->tab.mvf; | |
| 536 | 48299129 | const int log2_min_pu_size = MIN_PU_LOG2; | |
| 537 | 48299129 | const int log2_min_tu_size = MIN_TU_LOG2; | |
| 538 | 48299129 | const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y; | |
| 539 | 48299129 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
| 540 | 48299129 | const int min_tu_width = fc->ps.pps->min_tu_width; | |
| 541 | 48299129 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
| 542 | 48299129 | const int pu_p = (y_p >> log2_min_pu_size) * min_pu_width + (x_p >> log2_min_pu_size); | |
| 543 | 48299129 | const int pu_q = (y_q >> log2_min_pu_size) * min_pu_width + (x_q >> log2_min_pu_size); | |
| 544 | 48299129 | const MvField *mvf_p = &tab_mvf[pu_p]; | |
| 545 | 48299129 | const MvField *mvf_q = &tab_mvf[pu_q]; | |
| 546 | 48299129 | const uint8_t chroma = !!c_idx; | |
| 547 | 48299129 | const int tu_p = (y_p >> log2_min_tu_size) * min_tu_width + (x_p >> log2_min_tu_size); | |
| 548 | 48299129 | const int cb_p = (y_p >> log2_min_cb_size) * min_cb_width + (x_p >> log2_min_cb_size); | |
| 549 | 4/4✓ Branch 0 taken 67992 times. ✓ Branch 1 taken 48231137 times. ✓ Branch 2 taken 30213 times. ✓ Branch 3 taken 37779 times. | 48299129 | const uint8_t pcmf = fc->tab.pcmf[chroma][cb_p] && cu->bdpcm_flag[chroma]; | 
| 550 | 4/4✓ Branch 0 taken 37566736 times. ✓ Branch 1 taken 10732393 times. ✓ Branch 2 taken 1013967 times. ✓ Branch 3 taken 36552769 times. | 48299129 | const uint8_t intra = fc->tab.cpm[chroma][cb_p] == MODE_INTRA || cu->pred_mode == MODE_INTRA; | 
| 551 | 48299129 | const uint8_t same_mode = fc->tab.cpm[chroma][cb_p] == cu->pred_mode; | |
| 552 | |||
| 553 | 2/2✓ Branch 0 taken 30213 times. ✓ Branch 1 taken 48268916 times. | 48299129 | if (pcmf) | 
| 554 | 30213 | return 0; | |
| 555 | |||
| 556 | 6/6✓ Branch 0 taken 36552769 times. ✓ Branch 1 taken 11716147 times. ✓ Branch 2 taken 36166089 times. ✓ Branch 3 taken 386680 times. ✓ Branch 4 taken 302791 times. ✓ Branch 5 taken 35863298 times. | 48268916 | if (intra || mvf_p->ciip_flag || mvf_q->ciip_flag) | 
| 557 | 12405618 | return 2; | |
| 558 | |||
| 559 | 2/2✓ Branch 0 taken 27877352 times. ✓ Branch 1 taken 7985946 times. | 35863298 | if (chroma) { | 
| 560 | 55081326 | return fc->tab.tu_coded_flag[c_idx][tu_p] || | |
| 561 | 2/2✓ Branch 0 taken 26978936 times. ✓ Branch 1 taken 225038 times. | 27203974 | fc->tab.tu_joint_cbcr_residual_flag[tu_p] || | 
| 562 | 4/4✓ Branch 0 taken 27203974 times. ✓ Branch 1 taken 673378 times. ✓ Branch 2 taken 26715256 times. ✓ Branch 3 taken 263680 times. | 81796582 | tu->coded_flag[c_idx] || | 
| 563 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 26715256 times. | 26715256 | tu->joint_cbcr_residual_flag; | 
| 564 | } | ||
| 565 | |||
| 566 | 4/4✓ Branch 0 taken 7095465 times. ✓ Branch 1 taken 890481 times. ✓ Branch 2 taken 416842 times. ✓ Branch 3 taken 6678623 times. | 7985946 | if (fc->tab.tu_coded_flag[LUMA][tu_p] || tu->coded_flag[LUMA]) | 
| 567 | 1307323 | return 1; | |
| 568 | |||
| 569 | 6/6✓ Branch 0 taken 2012353 times. ✓ Branch 1 taken 4666270 times. ✓ Branch 2 taken 1998410 times. ✓ Branch 3 taken 13943 times. ✓ Branch 4 taken 1621280 times. ✓ Branch 5 taken 377130 times. | 6678623 | if ((off_to_cb && ((off_to_cb % 8) || !has_sub_block))) | 
| 570 | 1635223 | return 0; // inside a cu, not aligned to 8 or with no subblocks | |
| 571 | |||
| 572 | 2/2✓ Branch 0 taken 51818 times. ✓ Branch 1 taken 4991582 times. | 5043400 | if (!same_mode) | 
| 573 | 51818 | return 1; | |
| 574 | |||
| 575 | 4991582 | return boundary_strength(lc, mvf_q, mvf_p, rpl_p); | |
| 576 | } | ||
| 577 | |||
| 578 | 4735496 | static int deblock_is_boundary(const VVCLocalContext *lc, const int boundary, | |
| 579 | const int pos, const int rs, const int vertical) | ||
| 580 | { | ||
| 581 | 4735496 | const VVCFrameContext *fc = lc->fc; | |
| 582 | 4735496 | const H266RawSPS *rsps = fc->ps.sps->r; | |
| 583 | 4735496 | const H266RawPPS *rpps = fc->ps.pps->r; | |
| 584 | int flag; | ||
| 585 | 4/4✓ Branch 0 taken 4182331 times. ✓ Branch 1 taken 553165 times. ✓ Branch 2 taken 681734 times. ✓ Branch 3 taken 3500597 times. | 4735496 | if (boundary && (pos % fc->ps.sps->ctb_size_y) == 0) { | 
| 586 | 2/2✓ Branch 0 taken 368634 times. ✓ Branch 1 taken 313100 times. | 681734 | flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE; | 
| 587 | 2/2✓ Branch 0 taken 20714 times. ✓ Branch 1 taken 661020 times. | 681734 | if (lc->boundary_flags & flag && | 
| 588 | 2/2✓ Branch 0 taken 8259 times. ✓ Branch 1 taken 12455 times. | 20714 | !rpps->pps_loop_filter_across_slices_enabled_flag) | 
| 589 | 8259 | return 0; | |
| 590 | |||
| 591 | 2/2✓ Branch 0 taken 364644 times. ✓ Branch 1 taken 308831 times. | 673475 | flag = vertical ? BOUNDARY_LEFT_TILE : BOUNDARY_UPPER_TILE; | 
| 592 | 2/2✓ Branch 0 taken 29697 times. ✓ Branch 1 taken 643778 times. | 673475 | if (lc->boundary_flags & flag && | 
| 593 | 2/2✓ Branch 0 taken 9204 times. ✓ Branch 1 taken 20493 times. | 29697 | !rpps->pps_loop_filter_across_tiles_enabled_flag) | 
| 594 | 9204 | return 0; | |
| 595 | |||
| 596 | 2/2✓ Branch 0 taken 359065 times. ✓ Branch 1 taken 305206 times. | 664271 | flag = vertical ? BOUNDARY_LEFT_SUBPIC : BOUNDARY_UPPER_SUBPIC; | 
| 597 | 2/2✓ Branch 0 taken 363 times. ✓ Branch 1 taken 663908 times. | 664271 | if (lc->boundary_flags & flag) { | 
| 598 | 2/2✓ Branch 0 taken 313 times. ✓ Branch 1 taken 50 times. | 363 | const int q_rs = rs - (vertical ? 1 : fc->ps.pps->ctb_width); | 
| 599 | 363 | const SliceContext *q_slice = lc->fc->slices[lc->fc->tab.slice_idx[q_rs]]; | |
| 600 | |||
| 601 | 2/2✓ Branch 0 taken 253 times. ✓ Branch 1 taken 110 times. | 363 | if (!rsps->sps_loop_filter_across_subpic_enabled_flag[q_slice->sh.r->curr_subpic_idx] || | 
| 602 | 2/2✓ Branch 0 taken 50 times. ✓ Branch 1 taken 203 times. | 253 | !rsps->sps_loop_filter_across_subpic_enabled_flag[lc->sc->sh.r->curr_subpic_idx]) | 
| 603 | 160 | return 0; | |
| 604 | } | ||
| 605 | } | ||
| 606 | 4717873 | return boundary; | |
| 607 | } | ||
| 608 | |||
| 609 | 2949962 | static void vvc_deblock_bs_luma(const VVCLocalContext *lc, | |
| 610 | const int x0, const int y0, const int width, const int height, | ||
| 611 | const CodingUnit *cu, const TransformUnit *tu, int rs, const int vertical) | ||
| 612 | { | ||
| 613 | 2949962 | const VVCFrameContext *fc = lc->fc; | |
| 614 | 2949962 | const PredictionUnit *pu = &cu->pu; | |
| 615 | 2949962 | const int mask = LUMA_GRID - 1; | |
| 616 | 2/2✓ Branch 0 taken 1474981 times. ✓ Branch 1 taken 1474981 times. | 2949962 | const int pos = vertical ? x0 : y0; | 
| 617 | 2/2✓ Branch 0 taken 1474981 times. ✓ Branch 1 taken 1474981 times. | 2949962 | const int cb = vertical ? cu->x0 : cu->y0; | 
| 618 | 2949962 | const int is_intra = cu->pred_mode == MODE_INTRA; | |
| 619 | 2/2✓ Branch 0 taken 1474981 times. ✓ Branch 1 taken 1474981 times. | 2949962 | const int cb_size = vertical ? cu->cb_width : cu->cb_height; | 
| 620 | 8/8✓ Branch 0 taken 1405244 times. ✓ Branch 1 taken 1544718 times. ✓ Branch 2 taken 1239734 times. ✓ Branch 3 taken 165510 times. ✓ Branch 4 taken 29860 times. ✓ Branch 5 taken 1209874 times. ✓ Branch 6 taken 167228 times. ✓ Branch 7 taken 28142 times. | 2949962 | const int has_sb = !is_intra && (pu->merge_subblock_flag || pu->inter_affine_flag) && cb_size > 8; | 
| 621 | |||
| 622 | 6/6✓ Branch 0 taken 2893061 times. ✓ Branch 1 taken 56901 times. ✓ Branch 2 taken 2839985 times. ✓ Branch 3 taken 53076 times. ✓ Branch 5 taken 2829589 times. ✓ Branch 6 taken 120373 times. | 2949962 | if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) { | 
| 623 | 2829589 | const int is_vb = is_virtual_boundary(fc, pos, vertical); | |
| 624 | 2/2✓ Branch 0 taken 1431707 times. ✓ Branch 1 taken 1397882 times. | 2829589 | const int size = vertical ? height : width; | 
| 625 | 2/2✓ Branch 0 taken 1431707 times. ✓ Branch 1 taken 1397882 times. | 2829589 | const int size_q = vertical ? width : height; | 
| 626 | 2829589 | const int off = cb - pos; | |
| 627 | 2/2✓ Branch 0 taken 1431707 times. ✓ Branch 1 taken 1397882 times. | 2829589 | const int flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE; | 
| 628 | 2829589 | const RefPicList *rpl_p = | |
| 629 | 2/2✓ Branch 0 taken 73777 times. ✓ Branch 1 taken 2755812 times. | 2829589 | (lc->boundary_flags & flag) ? ff_vvc_get_ref_list(fc, fc->ref, x0 - vertical, y0 - !vertical) : lc->sc->rpl; | 
| 630 | |||
| 631 | 2/2✓ Branch 0 taken 12295809 times. ✓ Branch 1 taken 2829589 times. | 15125398 | for (int i = 0; i < size; i += 4) { | 
| 632 | 12295809 | const int x = x0 + i * !vertical; | |
| 633 | 12295809 | const int y = y0 + i * vertical; | |
| 634 | uint8_t max_len_p, max_len_q; | ||
| 635 | 1/2✓ Branch 0 taken 12295809 times. ✗ Branch 1 not taken. | 12295809 | const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, cu, tu, rpl_p, LUMA, off, has_sb); | 
| 636 | |||
| 637 | 12295809 | TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs; | |
| 638 | |||
| 639 | 12295809 | derive_max_filter_length_luma(fc, x, y, size_q, has_sb, vertical, &max_len_p, &max_len_q); | |
| 640 | 12295809 | TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p; | |
| 641 | 12295809 | TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q; | |
| 642 | } | ||
| 643 | } | ||
| 644 | |||
| 645 | 2/2✓ Branch 0 taken 167228 times. ✓ Branch 1 taken 2782734 times. | 2949962 | if (has_sb) | 
| 646 | 167228 | vvc_deblock_subblock_bs(lc, cb, x0, y0, width, height, vertical); | |
| 647 | 2949962 | } | |
| 648 | |||
| 649 | 1785534 | static void vvc_deblock_bs_chroma(const VVCLocalContext *lc, | |
| 650 | const int x0, const int y0, const int width, const int height, | ||
| 651 | const CodingUnit *cu, const TransformUnit *tu, const int rs, const int vertical) | ||
| 652 | { | ||
| 653 | 1785534 | const VVCFrameContext *fc = lc->fc; | |
| 654 | 2/2✓ Branch 0 taken 892767 times. ✓ Branch 1 taken 892767 times. | 1785534 | const int shift = (vertical ? fc->ps.sps->hshift : fc->ps.sps->vshift)[CHROMA]; | 
| 655 | 1785534 | const int mask = (CHROMA_GRID << shift) - 1; | |
| 656 | 2/2✓ Branch 0 taken 892767 times. ✓ Branch 1 taken 892767 times. | 1785534 | const int pos = vertical ? x0 : y0; | 
| 657 | |||
| 658 | 6/6✓ Branch 0 taken 1739054 times. ✓ Branch 1 taken 46480 times. ✓ Branch 2 taken 1342346 times. ✓ Branch 3 taken 396708 times. ✓ Branch 5 taken 1335119 times. ✓ Branch 6 taken 450415 times. | 1785534 | if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) { | 
| 659 | 1335119 | const int is_vb = is_virtual_boundary(fc, pos, vertical); | |
| 660 | 2/2✓ Branch 0 taken 671866 times. ✓ Branch 1 taken 663253 times. | 1335119 | const int size = vertical ? height : width; | 
| 661 | |||
| 662 | 2/2✓ Branch 0 taken 2670238 times. ✓ Branch 1 taken 1335119 times. | 4005357 | for (int c_idx = CB; c_idx <= CR; c_idx++) { | 
| 663 | 2/2✓ Branch 0 taken 36003320 times. ✓ Branch 1 taken 2670238 times. | 38673558 | for (int i = 0; i < size; i += 2) { | 
| 664 | 36003320 | const int x = x0 + i * !vertical; | |
| 665 | 36003320 | const int y = y0 + i * vertical; | |
| 666 | 1/2✓ Branch 0 taken 36003320 times. ✗ Branch 1 not taken. | 36003320 | const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, cu, tu, NULL, c_idx, 0, 0); | 
| 667 | |||
| 668 | 36003320 | TAB_BS(fc->tab.bs[vertical][c_idx], x, y) = bs; | |
| 669 | } | ||
| 670 | } | ||
| 671 | } | ||
| 672 | 1785534 | } | |
| 673 | |||
| 674 | typedef void (*deblock_bs_fn)(const VVCLocalContext *lc, const int x0, const int y0, | ||
| 675 | const int width, const int height, const int rs, const int vertical); | ||
| 676 | |||
| 677 | 53471 | void ff_vvc_deblock_bs(VVCLocalContext *lc, const int rx, const int ry, const int rs) | |
| 678 | { | ||
| 679 | 53471 | const VVCFrameContext *fc = lc->fc; | |
| 680 | 53471 | const VVCSPS *sps = fc->ps.sps; | |
| 681 | 53471 | const int x0 = rx << sps->ctb_log2_size_y; | |
| 682 | 53471 | const int y0 = ry << sps->ctb_log2_size_y; | |
| 683 | |||
| 684 | 53471 | ff_vvc_decode_neighbour(lc, x0, y0, rx, ry, rs); | |
| 685 | 2/2✓ Branch 0 taken 1343669 times. ✓ Branch 1 taken 53471 times. | 1397140 | for (const CodingUnit *cu = fc->tab.cus[rs]; cu; cu = cu->next) { | 
| 686 | 2/2✓ Branch 0 taken 1662977 times. ✓ Branch 1 taken 1343669 times. | 3006646 | for (const TransformUnit *tu = cu->tus.head; tu; tu = tu->next) { | 
| 687 | 2/2✓ Branch 0 taken 3325954 times. ✓ Branch 1 taken 1662977 times. | 4988931 | for (int vertical = 0; vertical <= 1; vertical++) { | 
| 688 | 2/2✓ Branch 0 taken 2949962 times. ✓ Branch 1 taken 375992 times. | 3325954 | if (tu->avail[LUMA]) | 
| 689 | 2949962 | vvc_deblock_bs_luma(lc, tu->x0, tu->y0, tu->width, tu->height, cu, tu, rs, vertical); | |
| 690 | 2/2✓ Branch 0 taken 1785534 times. ✓ Branch 1 taken 1540420 times. | 3325954 | if (tu->avail[CHROMA]) { | 
| 691 | 3/4✓ Branch 0 taken 11254 times. ✓ Branch 1 taken 1774280 times. ✓ Branch 2 taken 11254 times. ✗ Branch 3 not taken. | 1785534 | if (cu->isp_split_type != ISP_NO_SPLIT && cu->tree_type == SINGLE_TREE) | 
| 692 | 11254 | vvc_deblock_bs_chroma(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height, cu, tu, rs, vertical); | |
| 693 | else | ||
| 694 | 1774280 | vvc_deblock_bs_chroma(lc, tu->x0, tu->y0, tu->width, tu->height, cu, tu, rs, vertical); | |
| 695 | } | ||
| 696 | } | ||
| 697 | } | ||
| 698 | } | ||
| 699 | 53471 | } | |
| 700 | |||
| 701 | //part of 8.8.3.3 Derivation process of transform block boundary | ||
| 702 | 7958214 | static void max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy, | |
| 703 | const int vertical, uint8_t *max_len_p, uint8_t *max_len_q) | ||
| 704 | { | ||
| 705 | 7958214 | *max_len_p = TAB_MAX_LEN(fc->tab.max_len_p[vertical], qx, qy); | |
| 706 | 7958214 | *max_len_q = TAB_MAX_LEN(fc->tab.max_len_q[vertical], qx, qy); | |
| 707 | 7958214 | } | |
| 708 | |||
| 709 | //part of 8.8.3.3 Derivation process of transform block boundary | ||
| 710 | 4643984 | static void max_filter_length_chroma(const VVCFrameContext *fc, const int qx, const int qy, | |
| 711 | const int vertical, const int horizontal_ctu_edge, const int bs, uint8_t *max_len_p, uint8_t *max_len_q) | ||
| 712 | { | ||
| 713 | 2/2✓ Branch 0 taken 2235053 times. ✓ Branch 1 taken 2408931 times. | 4643984 | const int px = vertical ? qx - 1 : qx; | 
| 714 | 2/2✓ Branch 0 taken 2408931 times. ✓ Branch 1 taken 2235053 times. | 4643984 | const int py = !vertical ? qy - 1 : qy; | 
| 715 | 2/2✓ Branch 0 taken 2235053 times. ✓ Branch 1 taken 2408931 times. | 4643984 | const uint8_t *tb_size = vertical ? fc->tab.tb_width[CHROMA] : fc->tab.tb_height[CHROMA]; | 
| 716 | |||
| 717 | 4643984 | const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)]; | |
| 718 | 4643984 | const int size_q = tb_size[(qy >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (qx >> MIN_TU_LOG2)]; | |
| 719 | 4/4✓ Branch 0 taken 3767465 times. ✓ Branch 1 taken 876519 times. ✓ Branch 2 taken 3221967 times. ✓ Branch 3 taken 545498 times. | 4643984 | if (size_p >= 8 && size_q >= 8) { | 
| 720 | 3221967 | *max_len_p = *max_len_q = 3; | |
| 721 | 2/2✓ Branch 0 taken 382269 times. ✓ Branch 1 taken 2839698 times. | 3221967 | if (horizontal_ctu_edge) | 
| 722 | 382269 | *max_len_p = 1; | |
| 723 | } else { | ||
| 724 | //part of 8.8.3.6.4 Decision process for chroma block edges | ||
| 725 | 1422017 | *max_len_p = *max_len_q = (bs == 2); | |
| 726 | } | ||
| 727 | 4643984 | } | |
| 728 | |||
| 729 | 12602198 | static void max_filter_length(const VVCFrameContext *fc, const int qx, const int qy, | |
| 730 | const int c_idx, const int vertical, const int horizontal_ctu_edge, const int bs, uint8_t *max_len_p, uint8_t *max_len_q) | ||
| 731 | { | ||
| 732 | 2/2✓ Branch 0 taken 7958214 times. ✓ Branch 1 taken 4643984 times. | 12602198 | if (!c_idx) | 
| 733 | 7958214 | max_filter_length_luma(fc, qx, qy, vertical, max_len_p, max_len_q); | |
| 734 | else | ||
| 735 | 4643984 | max_filter_length_chroma(fc, qx, qy, vertical, horizontal_ctu_edge, bs, max_len_p, max_len_q); | |
| 736 | 12602198 | } | |
| 737 | |||
| 738 | #define TC_CALC(qp, bs) \ | ||
| 739 | tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \ | ||
| 740 | (tc_offset & -2), \ | ||
| 741 | 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)] | ||
| 742 | |||
| 743 | // part of 8.8.3.6.2 Decision process for luma block edges | ||
| 744 | 7958214 | static int get_qp_y(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int vertical) | |
| 745 | { | ||
| 746 | 7958214 | const VVCSPS *sps = fc->ps.sps; | |
| 747 | 7958214 | const int qp = (ff_vvc_get_qPy(fc, x - vertical, y - !vertical) + ff_vvc_get_qPy(fc, x, y) + 1) >> 1; | |
| 748 | 7958214 | int qp_offset = 0; | |
| 749 | int level; | ||
| 750 | |||
| 751 | 2/2✓ Branch 0 taken 7486335 times. ✓ Branch 1 taken 471879 times. | 7958214 | if (!sps->r->sps_ladf_enabled_flag) | 
| 752 | 7486335 | return qp; | |
| 753 | |||
| 754 | 471879 | level = fc->vvcdsp.lf.ladf_level[vertical](src, fc->frame->linesize[LUMA]); | |
| 755 | 471879 | qp_offset = sps->r->sps_ladf_lowest_interval_qp_offset; | |
| 756 | 4/4✓ Branch 0 taken 932712 times. ✓ Branch 1 taken 437994 times. ✓ Branch 2 taken 898827 times. ✓ Branch 3 taken 33885 times. | 1370706 | for (int i = 0; i < sps->num_ladf_intervals - 1 && level > sps->ladf_interval_lower_bound[i + 1]; i++) | 
| 757 | 898827 | qp_offset = sps->r->sps_ladf_qp_offset[i]; | |
| 758 | |||
| 759 | 471879 | return qp + qp_offset; | |
| 760 | } | ||
| 761 | |||
| 762 | // part of 8.8.3.6.2 Decision process for luma block edges | ||
| 763 | 4643984 | static int get_qp_c(const VVCFrameContext *fc, const int x, const int y, const int c_idx, const int vertical) | |
| 764 | { | ||
| 765 | 4643984 | const VVCSPS *sps = fc->ps.sps; | |
| 766 | 4643984 | return (get_qPc(fc, x - vertical, y - !vertical, c_idx) + get_qPc(fc, x, y, c_idx) - 2 * sps->qp_bd_offset + 1) >> 1; | |
| 767 | } | ||
| 768 | |||
| 769 | 12602198 | static int get_qp(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int c_idx, const int vertical) | |
| 770 | { | ||
| 771 | 2/2✓ Branch 0 taken 7958214 times. ✓ Branch 1 taken 4643984 times. | 12602198 | if (!c_idx) | 
| 772 | 7958214 | return get_qp_y(fc, src, x, y, vertical); | |
| 773 | 4643984 | return get_qp_c(fc, x, y, c_idx, vertical); | |
| 774 | } | ||
| 775 | |||
| 776 | 106942 | static void vvc_deblock(const VVCLocalContext *lc, int x0, int y0, const int rs, const int vertical) | |
| 777 | { | ||
| 778 | 106942 | VVCFrameContext *fc = lc->fc; | |
| 779 | 106942 | const VVCSPS *sps = fc->ps.sps; | |
| 780 | 2/2✓ Branch 0 taken 105886 times. ✓ Branch 1 taken 1056 times. | 106942 | const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1; | 
| 781 | 106942 | const int ctb_size = fc->ps.sps->ctb_size_y; | |
| 782 | 106942 | const DBParams *params = fc->tab.deblock + rs; | |
| 783 | 106942 | int x_end = FFMIN(x0 + ctb_size, fc->ps.pps->width); | |
| 784 | 106942 | int y_end = FFMIN(y0 + ctb_size, fc->ps.pps->height); | |
| 785 | 106942 | const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y; | |
| 786 | 106942 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
| 787 | |||
| 788 | 2/2✓ Branch 0 taken 53471 times. ✓ Branch 1 taken 53471 times. | 106942 | if (!vertical) { | 
| 789 | 53471 | FFSWAP(int, x_end, y_end); | |
| 790 | 53471 | FFSWAP(int, x0, y0); | |
| 791 | } | ||
| 792 | |||
| 793 | 2/2✓ Branch 0 taken 318714 times. ✓ Branch 1 taken 106942 times. | 425656 | for (int c_idx = 0; c_idx < c_end; c_idx++) { | 
| 794 | 2/2✓ Branch 0 taken 159357 times. ✓ Branch 1 taken 159357 times. | 318714 | const int hs = (vertical ? sps->hshift : sps->vshift)[c_idx]; | 
| 795 | 2/2✓ Branch 0 taken 159357 times. ✓ Branch 1 taken 159357 times. | 318714 | const int vs = (vertical ? sps->vshift : sps->hshift)[c_idx]; | 
| 796 | 2/2✓ Branch 0 taken 211772 times. ✓ Branch 1 taken 106942 times. | 318714 | const int grid = c_idx ? (CHROMA_GRID << hs) : LUMA_GRID; | 
| 797 | 318714 | const int tc_offset = params->tc_offset[c_idx]; | |
| 798 | 318714 | const int beta_offset = params->beta_offset[c_idx]; | |
| 799 | 318714 | const int src_stride = fc->frame->linesize[c_idx]; | |
| 800 | |||
| 801 | 2/2✓ Branch 0 taken 3795281 times. ✓ Branch 1 taken 318714 times. | 4113995 | for (int y = y0; y < y_end; y += (DEBLOCK_STEP << vs)) { | 
| 802 | 4/4✓ Branch 0 taken 3350121 times. ✓ Branch 1 taken 445160 times. ✓ Branch 2 taken 74070180 times. ✓ Branch 3 taken 3795281 times. | 77865461 | for (int x = x0 ? x0 : grid; x < x_end; x += grid) { | 
| 803 | 4/4✓ Branch 0 taken 36976042 times. ✓ Branch 1 taken 37094138 times. ✓ Branch 2 taken 1638292 times. ✓ Branch 3 taken 35337750 times. | 74070180 | const uint8_t horizontal_ctu_edge = !vertical && !(x % ctb_size); | 
| 804 | 74070180 | int32_t bs[4], beta[4], tc[4] = { 0 }, all_zero_bs = 1; | |
| 805 | uint8_t max_len_p[4], max_len_q[4]; | ||
| 806 | 74070180 | uint8_t no_p[4] = { 0 }; | |
| 807 | 74070180 | uint8_t no_q[4] = { 0 }; | |
| 808 | |||
| 809 | 2/2✓ Branch 0 taken 163729220 times. ✓ Branch 1 taken 74070180 times. | 237799400 | for (int i = 0; i < DEBLOCK_STEP >> (2 - vs); i++) { | 
| 810 | 163729220 | int tx = x; | |
| 811 | 163729220 | int ty = y + (i << 2); | |
| 812 | 163729220 | const int end = ty >= y_end; | |
| 813 | |||
| 814 | 2/2✓ Branch 0 taken 82290836 times. ✓ Branch 1 taken 81438384 times. | 163729220 | if (!vertical) | 
| 815 | 82290836 | FFSWAP(int, tx, ty); | |
| 816 | |||
| 817 | 2/2✓ Branch 0 taken 163647752 times. ✓ Branch 1 taken 81468 times. | 163729220 | bs[i] = end ? 0 : TAB_BS(fc->tab.bs[vertical][c_idx], tx, ty); | 
| 818 | 2/2✓ Branch 0 taken 12602198 times. ✓ Branch 1 taken 151127022 times. | 163729220 | if (bs[i]) { | 
| 819 | 12602198 | const int qp = get_qp(fc, POS(c_idx, tx, ty), tx, ty, c_idx, vertical); | |
| 820 | 12602198 | beta[i] = betatable[av_clip(qp + beta_offset, 0, MAX_QP)]; | |
| 821 | 12602198 | tc[i] = TC_CALC(qp, bs[i]) ; | |
| 822 | 12602198 | max_filter_length(fc, tx, ty, c_idx, vertical, horizontal_ctu_edge, bs[i], &max_len_p[i], &max_len_q[i]); | |
| 823 | 12602198 | all_zero_bs = 0; | |
| 824 | |||
| 825 | 2/2✓ Branch 0 taken 759484 times. ✓ Branch 1 taken 11842714 times. | 12602198 | if (sps->r->sps_palette_enabled_flag) { | 
| 826 | 759484 | const int cu_q = (ty >> log2_min_cb_size) * min_cb_width + (tx >> log2_min_cb_size); | |
| 827 | 759484 | const int cu_p = (ty - !vertical >> log2_min_cb_size) * min_cb_width + (tx - vertical >> log2_min_cb_size); | |
| 828 | 759484 | no_q[i] = fc->tab.cpm[!!c_idx][cu_q] == MODE_PLT; | |
| 829 | 3/4✓ Branch 0 taken 759484 times. ✗ Branch 1 not taken. ✓ Branch 2 taken 34199 times. ✓ Branch 3 taken 725285 times. | 759484 | no_p[i] = cu_p >= 0 && fc->tab.cpm[!!c_idx][cu_p] == MODE_PLT; | 
| 830 | } | ||
| 831 | } | ||
| 832 | } | ||
| 833 | |||
| 834 | 2/2✓ Branch 0 taken 5504785 times. ✓ Branch 1 taken 68565395 times. | 74070180 | if (!all_zero_bs) { | 
| 835 | 2/2✓ Branch 0 taken 2663812 times. ✓ Branch 1 taken 2840973 times. | 5504785 | uint8_t *src = vertical ? POS(c_idx, x, y) : POS(c_idx, y, x); | 
| 836 | 2/2✓ Branch 0 taken 4082054 times. ✓ Branch 1 taken 1422731 times. | 5504785 | if (!c_idx) | 
| 837 | 4082054 | fc->vvcdsp.lf.filter_luma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, horizontal_ctu_edge); | |
| 838 | else | ||
| 839 | 1422731 | fc->vvcdsp.lf.filter_chroma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, vs); | |
| 840 | } | ||
| 841 | } | ||
| 842 | } | ||
| 843 | } | ||
| 844 | 106942 | } | |
| 845 | |||
| 846 | 53471 | void ff_vvc_deblock_vertical(const VVCLocalContext *lc, const int x0, const int y0, const int rs) | |
| 847 | { | ||
| 848 | 53471 | vvc_deblock(lc, x0, y0, rs, 1); | |
| 849 | 53471 | } | |
| 850 | |||
| 851 | 53471 | void ff_vvc_deblock_horizontal(const VVCLocalContext *lc, const int x0, const int y0, const int rs) | |
| 852 | { | ||
| 853 | 53471 | vvc_deblock(lc, x0, y0, rs, 0); | |
| 854 | 53471 | } | |
| 855 | |||
| 856 | 677973 | static void alf_copy_border(uint8_t *dst, const uint8_t *src, | |
| 857 | const int pixel_shift, int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride) | ||
| 858 | { | ||
| 859 | 677973 | width <<= pixel_shift; | |
| 860 | 2/2✓ Branch 0 taken 34991665 times. ✓ Branch 1 taken 677973 times. | 35669638 | for (int i = 0; i < height; i++) { | 
| 861 | 34991665 | memcpy(dst, src, width); | |
| 862 | 34991665 | dst += dst_stride; | |
| 863 | 34991665 | src += src_stride; | |
| 864 | } | ||
| 865 | 677973 | } | |
| 866 | |||
| 867 | 10889 | static void alf_extend_vert(uint8_t *_dst, const uint8_t *_src, | |
| 868 | const int pixel_shift, const int width, const int height, ptrdiff_t stride) | ||
| 869 | { | ||
| 870 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 10889 times. | 10889 | if (pixel_shift == 0) { | 
| 871 | ✗ | for (int i = 0; i < height; i++) { | |
| 872 | ✗ | memset(_dst, *_src, width); | |
| 873 | ✗ | _src += stride; | |
| 874 | ✗ | _dst += stride; | |
| 875 | } | ||
| 876 | } else { | ||
| 877 | 10889 | const uint16_t *src = (const uint16_t *)_src; | |
| 878 | 10889 | uint16_t *dst = (uint16_t *)_dst; | |
| 879 | 10889 | stride >>= pixel_shift; | |
| 880 | |||
| 881 | 2/2✓ Branch 0 taken 1068596 times. ✓ Branch 1 taken 10889 times. | 1079485 | for (int i = 0; i < height; i++) { | 
| 882 | 2/2✓ Branch 0 taken 2750808 times. ✓ Branch 1 taken 1068596 times. | 3819404 | for (int j = 0; j < width; j++) | 
| 883 | 2750808 | dst[j] = *src; | |
| 884 | 1068596 | src += stride; | |
| 885 | 1068596 | dst += stride; | |
| 886 | } | ||
| 887 | } | ||
| 888 | 10889 | } | |
| 889 | |||
| 890 | 48844 | static void alf_extend_horz(uint8_t *dst, const uint8_t *src, | |
| 891 | const int pixel_shift, int width, const int height, const ptrdiff_t stride) | ||
| 892 | { | ||
| 893 | 48844 | width <<= pixel_shift; | |
| 894 | 2/2✓ Branch 0 taken 120145 times. ✓ Branch 1 taken 48844 times. | 168989 | for (int i = 0; i < height; i++) { | 
| 895 | 120145 | memcpy(dst, src, width); | |
| 896 | 120145 | dst += stride; | |
| 897 | } | ||
| 898 | 48844 | } | |
| 899 | |||
| 900 | 129255 | static void alf_copy_ctb_to_hv(VVCFrameContext *fc, const uint8_t *src, const ptrdiff_t src_stride, | |
| 901 | const int x, const int y, const int width, const int height, const int rx, const int ry, const int c_idx) | ||
| 902 | { | ||
| 903 | 129255 | const int ps = fc->ps.sps->pixel_shift; | |
| 904 | 129255 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
| 905 | 129255 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
| 906 | 2/2✓ Branch 0 taken 43437 times. ✓ Branch 1 taken 85818 times. | 129255 | const int border_pixels = (c_idx == 0) ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA; | 
| 907 | 129255 | const int offset_h[] = { 0, height - border_pixels }; | |
| 908 | 129255 | const int offset_v[] = { 0, width - border_pixels }; | |
| 909 | |||
| 910 | /* copy horizontal edges */ | ||
| 911 | 2/2✓ Branch 0 taken 258510 times. ✓ Branch 1 taken 129255 times. | 387765 | for (int i = 0; i < FF_ARRAY_ELEMS(offset_h); i++) { | 
| 912 | 258510 | alf_copy_border(fc->tab.alf_pixel_buffer_h[c_idx][i] + ((border_pixels * ry * w + x)<< ps), | |
| 913 | 258510 | src + offset_h[i] * src_stride, ps, width, border_pixels, w << ps, src_stride); | |
| 914 | } | ||
| 915 | /* copy vertical edges */ | ||
| 916 | 2/2✓ Branch 0 taken 258510 times. ✓ Branch 1 taken 129255 times. | 387765 | for (int i = 0; i < FF_ARRAY_ELEMS(offset_v); i++) { | 
| 917 | 258510 | alf_copy_border(fc->tab.alf_pixel_buffer_v[c_idx][i] + ((h * rx + y) * (border_pixels << ps)), | |
| 918 | 258510 | src + (offset_v[i] << ps), ps, border_pixels, height, border_pixels << ps, src_stride); | |
| 919 | } | ||
| 920 | 129255 | } | |
| 921 | |||
| 922 | 95278 | static void alf_fill_border_h(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, const ptrdiff_t src_stride, | |
| 923 | const uint8_t *border, const int width, const int border_pixels, const int ps, const int edge) | ||
| 924 | { | ||
| 925 | 2/2✓ Branch 0 taken 18714 times. ✓ Branch 1 taken 76564 times. | 95278 | if (edge) | 
| 926 | 18714 | alf_extend_horz(dst, border, ps, width, border_pixels, dst_stride); | |
| 927 | else | ||
| 928 | 76564 | alf_copy_border(dst, src, ps, width, border_pixels, dst_stride, src_stride); | |
| 929 | 95278 | } | |
| 930 | |||
| 931 | 95278 | static void alf_fill_border_v(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, | |
| 932 | const uint8_t *border, const int border_pixels, const int height, const int pixel_shift, const int *edges, const int edge) | ||
| 933 | { | ||
| 934 | 95278 | const ptrdiff_t src_stride = (border_pixels << pixel_shift); | |
| 935 | |||
| 936 | 2/2✓ Branch 0 taken 10889 times. ✓ Branch 1 taken 84389 times. | 95278 | if (edge) { | 
| 937 | 10889 | alf_extend_vert(dst, border, pixel_shift, border_pixels, height + 2 * border_pixels, dst_stride); | |
| 938 | 10889 | return; | |
| 939 | } | ||
| 940 | |||
| 941 | //left/right | ||
| 942 | 84389 | alf_copy_border(dst + dst_stride * border_pixels * edges[TOP], src + src_stride * border_pixels * edges[TOP], | |
| 943 | 84389 | pixel_shift, border_pixels, height + (!edges[TOP] + !edges[BOTTOM]) * border_pixels, dst_stride, src_stride); | |
| 944 | |||
| 945 | //top left/right | ||
| 946 | 2/2✓ Branch 0 taken 13714 times. ✓ Branch 1 taken 70675 times. | 84389 | if (edges[TOP]) | 
| 947 | 13714 | alf_extend_horz(dst, dst + dst_stride * border_pixels, pixel_shift, border_pixels, border_pixels, dst_stride); | |
| 948 | |||
| 949 | //bottom left/right | ||
| 950 | 2/2✓ Branch 0 taken 16416 times. ✓ Branch 1 taken 67973 times. | 84389 | if (edges[BOTTOM]) { | 
| 951 | 16416 | dst += dst_stride * (border_pixels + height); | |
| 952 | 16416 | alf_extend_horz(dst, dst - dst_stride, pixel_shift, border_pixels, border_pixels, dst_stride); | |
| 953 | } | ||
| 954 | } | ||
| 955 | |||
| 956 | 47639 | static void alf_prepare_buffer(VVCFrameContext *fc, uint8_t *_dst, const uint8_t *_src, const int x, const int y, | |
| 957 | const int rx, const int ry, const int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride, | ||
| 958 | const int c_idx, const int *edges) | ||
| 959 | { | ||
| 960 | 47639 | const int ps = fc->ps.sps->pixel_shift; | |
| 961 | 47639 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
| 962 | 47639 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
| 963 | 2/2✓ Branch 0 taken 21430 times. ✓ Branch 1 taken 26209 times. | 47639 | const int border_pixels = c_idx == 0 ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA; | 
| 964 | uint8_t *dst, *src; | ||
| 965 | |||
| 966 | 47639 | copy_ctb(_dst, _src, width << ps, height, dst_stride, src_stride); | |
| 967 | |||
| 968 | //top | ||
| 969 | 47639 | src = fc->tab.alf_pixel_buffer_h[c_idx][1] + (((border_pixels * w) << ps) * (ry - 1) + (x << ps)); | |
| 970 | 47639 | dst = _dst - border_pixels * dst_stride; | |
| 971 | 47639 | alf_fill_border_h(dst, dst_stride, src, w << ps, _dst, width, border_pixels, ps, edges[TOP]); | |
| 972 | |||
| 973 | //bottom | ||
| 974 | 47639 | src = fc->tab.alf_pixel_buffer_h[c_idx][0] + (((border_pixels * w) << ps) * (ry + 1) + (x << ps)); | |
| 975 | 47639 | dst = _dst + height * dst_stride; | |
| 976 | 47639 | alf_fill_border_h(dst, dst_stride, src, w << ps, _dst + (height - 1) * dst_stride, width, border_pixels, ps, edges[BOTTOM]); | |
| 977 | |||
| 978 | |||
| 979 | //left | ||
| 980 | 47639 | src = fc->tab.alf_pixel_buffer_v[c_idx][1] + (h * (rx - 1) + y - border_pixels) * (border_pixels << ps); | |
| 981 | 47639 | dst = _dst - (border_pixels << ps) - border_pixels * dst_stride; | |
| 982 | 47639 | alf_fill_border_v(dst, dst_stride, src, dst + (border_pixels << ps), border_pixels, height, ps, edges, edges[LEFT]); | |
| 983 | |||
| 984 | //right | ||
| 985 | 47639 | src = fc->tab.alf_pixel_buffer_v[c_idx][0] + (h * (rx + 1) + y - border_pixels) * (border_pixels << ps); | |
| 986 | 47639 | dst = _dst + (width << ps) - border_pixels * dst_stride; | |
| 987 | 47639 | alf_fill_border_v(dst, dst_stride, src, dst - (1 << ps), border_pixels, height, ps, edges, edges[RIGHT]); | |
| 988 | 47639 | } | |
| 989 | |||
| 990 | #define ALF_MAX_BLOCKS_IN_CTU (MAX_CTU_SIZE * MAX_CTU_SIZE / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE) | ||
| 991 | #define ALF_MAX_FILTER_SIZE (ALF_MAX_BLOCKS_IN_CTU * ALF_NUM_COEFF_LUMA) | ||
| 992 | |||
| 993 | 20795 | static void alf_get_coeff_and_clip(VVCLocalContext *lc, int16_t *coeff, int16_t *clip, | |
| 994 | const uint8_t *src, ptrdiff_t src_stride, int width, int height, int vb_pos, const ALFParams *alf) | ||
| 995 | { | ||
| 996 | 20795 | const VVCFrameContext *fc = lc->fc; | |
| 997 | 20795 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
| 998 | 20795 | uint8_t fixed_clip_set[ALF_NUM_FILTERS_LUMA][ALF_NUM_COEFF_LUMA] = { 0 }; | |
| 999 | const int16_t *coeff_set; | ||
| 1000 | const uint8_t *clip_idx_set; | ||
| 1001 | const uint8_t *class_to_filt; | ||
| 1002 | 20795 | const int size = width * height / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE; | |
| 1003 | int class_idx[ALF_MAX_BLOCKS_IN_CTU]; | ||
| 1004 | int transpose_idx[ALF_MAX_BLOCKS_IN_CTU]; | ||
| 1005 | |||
| 1006 | 2/2✓ Branch 0 taken 2791 times. ✓ Branch 1 taken 18004 times. | 20795 | if (alf->ctb_filt_set_idx_y < 16) { | 
| 1007 | 2791 | coeff_set = &ff_vvc_alf_fix_filt_coeff[0][0]; | |
| 1008 | 2791 | clip_idx_set = &fixed_clip_set[0][0]; | |
| 1009 | 2791 | class_to_filt = ff_vvc_alf_class_to_filt_map[alf->ctb_filt_set_idx_y]; | |
| 1010 | } else { | ||
| 1011 | 18004 | const int id = rsh->sh_alf_aps_id_luma[alf->ctb_filt_set_idx_y - 16]; | |
| 1012 | 18004 | const VVCALF *aps = fc->ps.alf_list[id]; | |
| 1013 | 18004 | coeff_set = &aps->luma_coeff[0][0]; | |
| 1014 | 18004 | clip_idx_set = &aps->luma_clip_idx[0][0]; | |
| 1015 | 18004 | class_to_filt = ff_vvc_alf_aps_class_to_filt_map; | |
| 1016 | } | ||
| 1017 | 20795 | fc->vvcdsp.alf.classify(class_idx, transpose_idx, src, src_stride, width, height, | |
| 1018 | 20795 | vb_pos, lc->alf_gradient_tmp); | |
| 1019 | 20795 | fc->vvcdsp.alf.recon_coeff_and_clip(coeff, clip, class_idx, transpose_idx, size, | |
| 1020 | coeff_set, clip_idx_set, class_to_filt); | ||
| 1021 | 20795 | } | |
| 1022 | |||
| 1023 | 20795 | static void alf_filter_luma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src, | |
| 1024 | const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int x0, const int y0, | ||
| 1025 | const int width, const int height, const int _vb_pos, const ALFParams *alf) | ||
| 1026 | { | ||
| 1027 | 20795 | const VVCFrameContext *fc = lc->fc; | |
| 1028 | 20795 | int vb_pos = _vb_pos - y0; | |
| 1029 | 20795 | int16_t *coeff = (int16_t*)lc->tmp; | |
| 1030 | 20795 | int16_t *clip = (int16_t *)lc->tmp1; | |
| 1031 | |||
| 1032 | av_assert0(ALF_MAX_FILTER_SIZE <= sizeof(lc->tmp)); | ||
| 1033 | av_assert0(ALF_MAX_FILTER_SIZE * sizeof(int16_t) <= sizeof(lc->tmp1)); | ||
| 1034 | |||
| 1035 | 20795 | alf_get_coeff_and_clip(lc, coeff, clip, src, src_stride, width, height, vb_pos, alf); | |
| 1036 | 20795 | fc->vvcdsp.alf.filter[LUMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos); | |
| 1037 | 20795 | } | |
| 1038 | |||
| 1039 | 157254 | static int alf_clip_from_idx(const VVCFrameContext *fc, const int idx) | |
| 1040 | { | ||
| 1041 | 157254 | const VVCSPS *sps = fc->ps.sps; | |
| 1042 | 157254 | const int offset[] = {0, 3, 5, 7}; | |
| 1043 | |||
| 1044 | 157254 | return 1 << (sps->bit_depth - offset[idx]); | |
| 1045 | } | ||
| 1046 | |||
| 1047 | 26209 | static void alf_filter_chroma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src, | |
| 1048 | const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int c_idx, | ||
| 1049 | const int width, const int height, const int vb_pos, const ALFParams *alf) | ||
| 1050 | { | ||
| 1051 | 26209 | VVCFrameContext *fc = lc->fc; | |
| 1052 | 26209 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
| 1053 | 26209 | const VVCALF *aps = fc->ps.alf_list[rsh->sh_alf_aps_id_chroma]; | |
| 1054 | 26209 | const int idx = alf->alf_ctb_filter_alt_idx[c_idx - 1]; | |
| 1055 | 26209 | const int16_t *coeff = aps->chroma_coeff[idx]; | |
| 1056 | int16_t clip[ALF_NUM_COEFF_CHROMA]; | ||
| 1057 | |||
| 1058 | 2/2✓ Branch 0 taken 157254 times. ✓ Branch 1 taken 26209 times. | 183463 | for (int i = 0; i < ALF_NUM_COEFF_CHROMA; i++) | 
| 1059 | 157254 | clip[i] = alf_clip_from_idx(fc, aps->chroma_clip_idx[idx][i]); | |
| 1060 | |||
| 1061 | 26209 | fc->vvcdsp.alf.filter[CHROMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos); | |
| 1062 | 26209 | } | |
| 1063 | |||
| 1064 | 10527 | static void alf_filter_cc(VVCLocalContext *lc, uint8_t *dst, const uint8_t *luma, | |
| 1065 | const ptrdiff_t dst_stride, const ptrdiff_t luma_stride, const int c_idx, | ||
| 1066 | const int width, const int height, const int hs, const int vs, const int vb_pos, const ALFParams *alf) | ||
| 1067 | { | ||
| 1068 | 10527 | const VVCFrameContext *fc = lc->fc; | |
| 1069 | 10527 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
| 1070 | 10527 | const int idx = c_idx - 1; | |
| 1071 | 2/2✓ Branch 0 taken 5379 times. ✓ Branch 1 taken 5148 times. | 10527 | const int cc_aps_id = c_idx == CB ? rsh->sh_alf_cc_cb_aps_id : rsh->sh_alf_cc_cr_aps_id; | 
| 1072 | 10527 | const VVCALF *aps = fc->ps.alf_list[cc_aps_id]; | |
| 1073 | |||
| 1074 | 1/2✓ Branch 0 taken 10527 times. ✗ Branch 1 not taken. | 10527 | if (aps) { | 
| 1075 | 10527 | const int16_t *coeff = aps->cc_coeff[idx][alf->ctb_cc_idc[idx] - 1]; | |
| 1076 | |||
| 1077 | 10527 | fc->vvcdsp.alf.filter_cc(dst, dst_stride, luma, luma_stride, width, height, hs, vs, coeff, vb_pos); | |
| 1078 | } | ||
| 1079 | 10527 | } | |
| 1080 | |||
| 1081 | 43437 | void ff_vvc_alf_copy_ctu_to_hv(VVCLocalContext* lc, const int x0, const int y0) | |
| 1082 | { | ||
| 1083 | 43437 | VVCFrameContext *fc = lc->fc; | |
| 1084 | 43437 | const int rx = x0 >> fc->ps.sps->ctb_log2_size_y; | |
| 1085 | 43437 | const int ry = y0 >> fc->ps.sps->ctb_log2_size_y; | |
| 1086 | 43437 | const int ctb_size_y = fc->ps.sps->ctb_size_y; | |
| 1087 | 2/2✓ Branch 0 taken 42909 times. ✓ Branch 1 taken 528 times. | 43437 | const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1; | 
| 1088 | |||
| 1089 | 2/2✓ Branch 0 taken 129255 times. ✓ Branch 1 taken 43437 times. | 172692 | for (int c_idx = 0; c_idx < c_end; c_idx++) { | 
| 1090 | 129255 | const int hs = fc->ps.sps->hshift[c_idx]; | |
| 1091 | 129255 | const int vs = fc->ps.sps->vshift[c_idx]; | |
| 1092 | 129255 | const int x = x0 >> hs; | |
| 1093 | 129255 | const int y = y0 >> vs; | |
| 1094 | 129255 | const int width = FFMIN(fc->ps.pps->width - x0, ctb_size_y) >> hs; | |
| 1095 | 129255 | const int height = FFMIN(fc->ps.pps->height - y0, ctb_size_y) >> vs; | |
| 1096 | |||
| 1097 | 129255 | const int src_stride = fc->frame->linesize[c_idx]; | |
| 1098 | 129255 | uint8_t *src = POS(c_idx, x0, y0); | |
| 1099 | |||
| 1100 | 129255 | alf_copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, rx, ry, c_idx); | |
| 1101 | } | ||
| 1102 | 43437 | } | |
| 1103 | |||
| 1104 | 43437 | static void alf_get_edges(const VVCLocalContext *lc, int edges[MAX_EDGES], const int rx, const int ry) | |
| 1105 | { | ||
| 1106 | 43437 | VVCFrameContext *fc = lc->fc; | |
| 1107 | 43437 | const VVCSPS *sps = fc->ps.sps; | |
| 1108 | 43437 | const VVCPPS *pps = fc->ps.pps; | |
| 1109 | 43437 | const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; | |
| 1110 | |||
| 1111 | // we can't use |= instead of || in this function; |= is not a shortcut operator | ||
| 1112 | |||
| 1113 | 2/2✓ Branch 0 taken 40018 times. ✓ Branch 1 taken 3419 times. | 43437 | if (!pps->r->pps_loop_filter_across_tiles_enabled_flag) { | 
| 1114 | 4/4✓ Branch 0 taken 36166 times. ✓ Branch 1 taken 3852 times. ✓ Branch 2 taken 612 times. ✓ Branch 3 taken 35554 times. | 40018 | edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_TILE); | 
| 1115 | 4/4✓ Branch 0 taken 33194 times. ✓ Branch 1 taken 6824 times. ✓ Branch 2 taken 564 times. ✓ Branch 3 taken 32630 times. | 40018 | edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_TILE); | 
| 1116 | 4/4✓ Branch 0 taken 36166 times. ✓ Branch 1 taken 3852 times. ✓ Branch 2 taken 612 times. ✓ Branch 3 taken 35554 times. | 40018 | edges[RIGHT] = edges[RIGHT] || pps->ctb_to_col_bd[rx] != pps->ctb_to_col_bd[rx + 1]; | 
| 1117 | 4/4✓ Branch 0 taken 33194 times. ✓ Branch 1 taken 6824 times. ✓ Branch 2 taken 564 times. ✓ Branch 3 taken 32630 times. | 40018 | edges[BOTTOM] = edges[BOTTOM] || pps->ctb_to_row_bd[ry] != pps->ctb_to_row_bd[ry + 1]; | 
| 1118 | } | ||
| 1119 | |||
| 1120 | 2/2✓ Branch 0 taken 39969 times. ✓ Branch 1 taken 3468 times. | 43437 | if (!pps->r->pps_loop_filter_across_slices_enabled_flag) { | 
| 1121 | 4/4✓ Branch 0 taken 35638 times. ✓ Branch 1 taken 4331 times. ✓ Branch 2 taken 5 times. ✓ Branch 3 taken 35633 times. | 39969 | edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SLICE); | 
| 1122 | 4/4✓ Branch 0 taken 32714 times. ✓ Branch 1 taken 7255 times. ✓ Branch 2 taken 71 times. ✓ Branch 3 taken 32643 times. | 39969 | edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SLICE); | 
| 1123 | 4/4✓ Branch 0 taken 35638 times. ✓ Branch 1 taken 4331 times. ✓ Branch 2 taken 5 times. ✓ Branch 3 taken 35633 times. | 39969 | edges[RIGHT] = edges[RIGHT] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx + 1, ry); | 
| 1124 | 4/4✓ Branch 0 taken 32714 times. ✓ Branch 1 taken 7255 times. ✓ Branch 2 taken 71 times. ✓ Branch 3 taken 32643 times. | 39969 | edges[BOTTOM] = edges[BOTTOM] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx, ry + 1); | 
| 1125 | } | ||
| 1126 | |||
| 1127 | 2/2✓ Branch 0 taken 42471 times. ✓ Branch 1 taken 966 times. | 43437 | if (!sps->r->sps_loop_filter_across_subpic_enabled_flag[subpic_idx]) { | 
| 1128 | 4/4✓ Branch 0 taken 38100 times. ✓ Branch 1 taken 4371 times. ✓ Branch 2 taken 4 times. ✓ Branch 3 taken 38096 times. | 42471 | edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SUBPIC); | 
| 1129 | 3/4✓ Branch 0 taken 34986 times. ✓ Branch 1 taken 7485 times. ✗ Branch 2 not taken. ✓ Branch 3 taken 34986 times. | 42471 | edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SUBPIC); | 
| 1130 | 3/4✓ Branch 0 taken 38096 times. ✓ Branch 1 taken 4375 times. ✗ Branch 2 not taken. ✓ Branch 3 taken 38096 times. | 42471 | edges[RIGHT] = edges[RIGHT] || fc->ps.sps->r->sps_subpic_ctu_top_left_x[subpic_idx] + fc->ps.sps->r->sps_subpic_width_minus1[subpic_idx] == rx; | 
| 1131 | 4/4✓ Branch 0 taken 34998 times. ✓ Branch 1 taken 7473 times. ✓ Branch 2 taken 12 times. ✓ Branch 3 taken 34986 times. | 42471 | edges[BOTTOM] = edges[BOTTOM] || fc->ps.sps->r->sps_subpic_ctu_top_left_y[subpic_idx] + fc->ps.sps->r->sps_subpic_height_minus1[subpic_idx] == ry; | 
| 1132 | } | ||
| 1133 | |||
| 1134 | 2/2✓ Branch 0 taken 1029 times. ✓ Branch 1 taken 42408 times. | 43437 | if (sps->r->sps_virtual_boundaries_enabled_flag) { | 
| 1135 | 3/4✓ Branch 0 taken 621 times. ✓ Branch 1 taken 408 times. ✗ Branch 3 not taken. ✓ Branch 4 taken 621 times. | 1029 | edges[LEFT] = edges[LEFT] || is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1); | 
| 1136 | 3/4✓ Branch 0 taken 595 times. ✓ Branch 1 taken 434 times. ✗ Branch 3 not taken. ✓ Branch 4 taken 595 times. | 1029 | edges[TOP] = edges[TOP] || is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0); | 
| 1137 | 3/4✓ Branch 0 taken 625 times. ✓ Branch 1 taken 404 times. ✗ Branch 3 not taken. ✓ Branch 4 taken 625 times. | 1029 | edges[RIGHT] = edges[RIGHT] || is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1); | 
| 1138 | 3/4✓ Branch 0 taken 583 times. ✓ Branch 1 taken 446 times. ✗ Branch 3 not taken. ✓ Branch 4 taken 583 times. | 1029 | edges[BOTTOM] = edges[BOTTOM] || is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0); | 
| 1139 | } | ||
| 1140 | 43437 | } | |
| 1141 | |||
| 1142 | 43437 | static void alf_init_subblock(VVCRect *sb, int sb_edges[MAX_EDGES], const VVCRect *b, const int edges[MAX_EDGES]) | |
| 1143 | { | ||
| 1144 | 43437 | *sb = *b; | |
| 1145 | 43437 | memcpy(sb_edges, edges, sizeof(int) * MAX_EDGES); | |
| 1146 | 43437 | } | |
| 1147 | |||
| 1148 | 43437 | static void alf_get_subblock(VVCRect *sb, int edges[MAX_EDGES], const int bx, const int by, const int vb_pos[2], const int has_vb[2]) | |
| 1149 | { | ||
| 1150 | 43437 | int *pos[] = { &sb->l, &sb->t, &sb->r, &sb->b }; | |
| 1151 | |||
| 1152 | 2/2✓ Branch 0 taken 86874 times. ✓ Branch 1 taken 43437 times. | 130311 | for (int vertical = 0; vertical <= 1; vertical++) { | 
| 1153 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 86874 times. | 86874 | if (has_vb[vertical]) { | 
| 1154 | ✗ | const int c = vertical ? (bx ? LEFT : RIGHT) : (by ? TOP : BOTTOM); | |
| 1155 | ✗ | *pos[c] = vb_pos[vertical]; | |
| 1156 | ✗ | edges[c] = 1; | |
| 1157 | } | ||
| 1158 | } | ||
| 1159 | 43437 | } | |
| 1160 | |||
| 1161 | 43437 | static void alf_get_subblocks(const VVCLocalContext *lc, VVCRect sbs[MAX_VBBS], int sb_edges[MAX_VBBS][MAX_EDGES], int *nb_sbs, | |
| 1162 | const int x0, const int y0, const int rx, const int ry) | ||
| 1163 | { | ||
| 1164 | 43437 | VVCFrameContext *fc = lc->fc; | |
| 1165 | 43437 | const VVCSPS *sps = fc->ps.sps; | |
| 1166 | 43437 | const VVCPPS *pps = fc->ps.pps; | |
| 1167 | 43437 | const int ctu_size_y = sps->ctb_size_y; | |
| 1168 | 43437 | const int vb_pos[] = { get_virtual_boundary(fc, ry, 0), get_virtual_boundary(fc, rx, 1) }; | |
| 1169 | 43437 | const int has_vb[] = { vb_pos[0] > y0, vb_pos[1] > x0 }; | |
| 1170 | 43437 | const VVCRect b = { x0, y0, FFMIN(x0 + ctu_size_y, pps->width), FFMIN(y0 + ctu_size_y, pps->height) }; | |
| 1171 | 43437 | int edges[MAX_EDGES] = { !rx, !ry, rx == pps->ctb_width - 1, ry == pps->ctb_height - 1 }; | |
| 1172 | 43437 | int i = 0; | |
| 1173 | |||
| 1174 | 43437 | alf_get_edges(lc, edges, rx, ry); | |
| 1175 | |||
| 1176 | 2/2✓ Branch 0 taken 43437 times. ✓ Branch 1 taken 43437 times. | 86874 | for (int by = 0; by <= has_vb[0]; by++) { | 
| 1177 | 2/2✓ Branch 0 taken 43437 times. ✓ Branch 1 taken 43437 times. | 86874 | for (int bx = 0; bx <= has_vb[1]; bx++, i++) { | 
| 1178 | 43437 | alf_init_subblock(sbs + i, sb_edges[i], &b, edges); | |
| 1179 | 43437 | alf_get_subblock(sbs + i, sb_edges[i], bx, by, vb_pos, has_vb); | |
| 1180 | } | ||
| 1181 | } | ||
| 1182 | 43437 | *nb_sbs = i; | |
| 1183 | 43437 | } | |
| 1184 | |||
| 1185 | 43437 | void ff_vvc_alf_filter(VVCLocalContext *lc, const int x0, const int y0) | |
| 1186 | { | ||
| 1187 | 43437 | VVCFrameContext *fc = lc->fc; | |
| 1188 | 43437 | const VVCSPS *sps = fc->ps.sps; | |
| 1189 | 43437 | const int rx = x0 >> sps->ctb_log2_size_y; | |
| 1190 | 43437 | const int ry = y0 >> sps->ctb_log2_size_y; | |
| 1191 | 43437 | const int ps = sps->pixel_shift; | |
| 1192 | 43437 | const int padded_stride = EDGE_EMU_BUFFER_STRIDE << ps; | |
| 1193 | 43437 | const int padded_offset = padded_stride * ALF_PADDING_SIZE + (ALF_PADDING_SIZE << ps); | |
| 1194 | 2/2✓ Branch 0 taken 42909 times. ✓ Branch 1 taken 528 times. | 43437 | const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1; | 
| 1195 | 43437 | const int has_chroma = !!sps->r->sps_chroma_format_idc; | |
| 1196 | 43437 | const int ctu_end = y0 + sps->ctb_size_y; | |
| 1197 | 43437 | const ALFParams *alf = &CTB(fc->tab.alf, rx, ry); | |
| 1198 | int sb_edges[MAX_VBBS][MAX_EDGES], nb_sbs; | ||
| 1199 | VVCRect sbs[MAX_VBBS]; | ||
| 1200 | |||
| 1201 | 43437 | alf_get_subblocks(lc, sbs, sb_edges, &nb_sbs, x0, y0, rx, ry); | |
| 1202 | |||
| 1203 | 2/2✓ Branch 0 taken 43437 times. ✓ Branch 1 taken 43437 times. | 86874 | for (int i = 0; i < nb_sbs; i++) { | 
| 1204 | 43437 | const VVCRect *sb = sbs + i; | |
| 1205 | 2/2✓ Branch 0 taken 129255 times. ✓ Branch 1 taken 43437 times. | 172692 | for (int c_idx = 0; c_idx < c_end; c_idx++) { | 
| 1206 | 129255 | const int hs = fc->ps.sps->hshift[c_idx]; | |
| 1207 | 129255 | const int vs = fc->ps.sps->vshift[c_idx]; | |
| 1208 | 129255 | const int x = sb->l >> hs; | |
| 1209 | 129255 | const int y = sb->t >> vs; | |
| 1210 | 129255 | const int width = (sb->r - sb->l) >> hs; | |
| 1211 | 129255 | const int height = (sb->b - sb->t) >> vs; | |
| 1212 | 129255 | const int src_stride = fc->frame->linesize[c_idx]; | |
| 1213 | 129255 | uint8_t *src = POS(c_idx, sb->l, sb->t); | |
| 1214 | uint8_t *padded; | ||
| 1215 | |||
| 1216 | 10/10✓ Branch 0 taken 82251 times. ✓ Branch 1 taken 47004 times. ✓ Branch 2 taken 22642 times. ✓ Branch 3 taken 59609 times. ✓ Branch 4 taken 22472 times. ✓ Branch 5 taken 170 times. ✓ Branch 6 taken 21936 times. ✓ Branch 7 taken 536 times. ✓ Branch 8 taken 99 times. ✓ Branch 9 taken 21837 times. | 129255 | if (alf->ctb_flag[c_idx] || (!c_idx && has_chroma && (alf->ctb_cc_idc[0] || alf->ctb_cc_idc[1]))) { | 
| 1217 | 2/2✓ Branch 0 taken 26209 times. ✓ Branch 1 taken 21430 times. | 47639 | padded = (c_idx ? lc->alf_buffer_chroma : lc->alf_buffer_luma) + padded_offset; | 
| 1218 | 47639 | alf_prepare_buffer(fc, padded, src, x, y, rx, ry, width, height, | |
| 1219 | 47639 | padded_stride, src_stride, c_idx, sb_edges[i]); | |
| 1220 | } | ||
| 1221 | 2/2✓ Branch 0 taken 47004 times. ✓ Branch 1 taken 82251 times. | 129255 | if (alf->ctb_flag[c_idx]) { | 
| 1222 | 2/2✓ Branch 0 taken 20795 times. ✓ Branch 1 taken 26209 times. | 47004 | if (!c_idx) { | 
| 1223 | 20795 | alf_filter_luma(lc, src, padded, src_stride, padded_stride, x, y, | |
| 1224 | width, height, ctu_end - ALF_VB_POS_ABOVE_LUMA, alf); | ||
| 1225 | } else { | ||
| 1226 | 26209 | alf_filter_chroma(lc, src, padded, src_stride, padded_stride, c_idx, | |
| 1227 | 26209 | width, height, ((ctu_end - sb->t) >> vs) - ALF_VB_POS_ABOVE_CHROMA, alf); | |
| 1228 | } | ||
| 1229 | } | ||
| 1230 | 4/4✓ Branch 0 taken 85818 times. ✓ Branch 1 taken 43437 times. ✓ Branch 2 taken 10527 times. ✓ Branch 3 taken 75291 times. | 129255 | if (c_idx && alf->ctb_cc_idc[c_idx - 1]) { | 
| 1231 | 10527 | padded = lc->alf_buffer_luma + padded_offset; | |
| 1232 | 10527 | alf_filter_cc(lc, src, padded, src_stride, padded_stride, c_idx, | |
| 1233 | 10527 | width, height, hs, vs, ctu_end - sb->t - ALF_VB_POS_ABOVE_LUMA, alf); | |
| 1234 | } | ||
| 1235 | } | ||
| 1236 | } | ||
| 1237 | 43437 | } | |
| 1238 | |||
| 1239 | |||
| 1240 | 53475 | void ff_vvc_lmcs_filter(const VVCLocalContext *lc, const int x, const int y) | |
| 1241 | { | ||
| 1242 | 53475 | const SliceContext *sc = lc->sc; | |
| 1243 | 53475 | const VVCFrameContext *fc = lc->fc; | |
| 1244 | 53475 | const int ctb_size = fc->ps.sps->ctb_size_y; | |
| 1245 | 53475 | const int width = FFMIN(fc->ps.pps->width - x, ctb_size); | |
| 1246 | 53475 | const int height = FFMIN(fc->ps.pps->height - y, ctb_size); | |
| 1247 | 53475 | uint8_t *data = POS(LUMA, x, y); | |
| 1248 | 2/2✓ Branch 0 taken 20255 times. ✓ Branch 1 taken 33220 times. | 53475 | if (sc->sh.r->sh_lmcs_used_flag) | 
| 1249 | 20255 | fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, &fc->ps.lmcs.inv_lut); | |
| 1250 | 53475 | } | |
| 1251 |