4 * Copyright (C) 2012 - 2013 Guillaume Martres
5 * Copyright (C) 2013 Seppo Tomperi
6 * Copyright (C) 2013 Wassim Hamidouche
8 * This file is part of FFmpeg.
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "libavutil/common.h"
26 #include "libavutil/internal.h"
28 #include "cabac_functions.h"
32 #include "bit_depth_template.c"
38 static const uint8_t tctable[54] = {
39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // QP 0...18
40 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, // QP 19...37
41 5, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 24 // QP 38...53
44 static const uint8_t betatable[52] = {
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, // QP 0...18
46 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, // QP 19...37
47 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64 // QP 38...51
50 static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset)
52 static const int qp_c[] = {
53 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37
55 int qp, qp_i, offset, idxt;
57 // slice qp offset is not used for deblocking
59 offset = s->pps->cb_qp_offset;
61 offset = s->pps->cr_qp_offset;
63 qp_i = av_clip(qp_y + offset, 0, 57);
71 idxt = av_clip(qp + DEFAULT_INTRA_TC_OFFSET + tc_offset, 0, 53);
75 static int get_qPy_pred(HEVCContext *s, int xC, int yC,
76 int xBase, int yBase, int log2_cb_size)
78 HEVCLocalContext *lc = s->HEVClc;
79 int ctb_size_mask = (1 << s->sps->log2_ctb_size) - 1;
80 int MinCuQpDeltaSizeMask = (1 << (s->sps->log2_ctb_size -
81 s->pps->diff_cu_qp_delta_depth)) - 1;
82 int xQgBase = xBase - (xBase & MinCuQpDeltaSizeMask);
83 int yQgBase = yBase - (yBase & MinCuQpDeltaSizeMask);
84 int min_cb_width = s->sps->min_cb_width;
85 int x_cb = xQgBase >> s->sps->log2_min_cb_size;
86 int y_cb = yQgBase >> s->sps->log2_min_cb_size;
87 int availableA = (xBase & ctb_size_mask) &&
88 (xQgBase & ctb_size_mask);
89 int availableB = (yBase & ctb_size_mask) &&
90 (yQgBase & ctb_size_mask);
91 int qPy_pred, qPy_a, qPy_b;
94 if (lc->first_qp_group || (!xQgBase && !yQgBase)) {
95 lc->first_qp_group = !lc->tu.is_cu_qp_delta_coded;
96 qPy_pred = s->sh.slice_qp;
98 qPy_pred = lc->qPy_pred;
105 qPy_a = s->qp_y_tab[(x_cb - 1) + y_cb * min_cb_width];
111 qPy_b = s->qp_y_tab[x_cb + (y_cb - 1) * min_cb_width];
113 av_assert2(qPy_a >= -s->sps->qp_bd_offset && qPy_a < 52);
114 av_assert2(qPy_b >= -s->sps->qp_bd_offset && qPy_b < 52);
116 return (qPy_a + qPy_b + 1) >> 1;
119 void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC,
120 int xBase, int yBase, int log2_cb_size)
122 int qp_y = get_qPy_pred(s, xC, yC, xBase, yBase, log2_cb_size);
124 if (s->HEVClc->tu.cu_qp_delta != 0) {
125 int off = s->sps->qp_bd_offset;
126 s->HEVClc->qp_y = FFUMOD(qp_y + s->HEVClc->tu.cu_qp_delta + 52 + 2 * off,
129 s->HEVClc->qp_y = qp_y;
132 static int get_qPy(HEVCContext *s, int xC, int yC)
134 int log2_min_cb_size = s->sps->log2_min_cb_size;
135 int x = xC >> log2_min_cb_size;
136 int y = yC >> log2_min_cb_size;
137 return s->qp_y_tab[x + y * s->sps->min_cb_width];
140 static void copy_CTB(uint8_t *dst, uint8_t *src,
141 int width, int height, int stride)
145 for (i = 0; i < height; i++) {
146 memcpy(dst, src, width);
152 #define CTB(tab, x, y) ((tab)[(y) * s->sps->ctb_width + (x)])
154 static void sao_filter_CTB(HEVCContext *s, int x, int y)
156 // TODO: This should be easily parallelizable
157 // TODO: skip CBs when (cu_transquant_bypass_flag || (pcm_loop_filter_disable_flag && pcm_flag))
159 int class = 1, class_index;
160 int edges[4]; // 0 left 1 top 2 right 3 bottom
163 int x_shift = 0, y_shift = 0;
164 int x_ctb = x >> s->sps->log2_ctb_size;
165 int y_ctb = y >> s->sps->log2_ctb_size;
166 int ctb_addr_rs = y_ctb * s->sps->ctb_width + x_ctb;
167 int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[ctb_addr_rs];
169 // flags indicating unfilterable edges
170 uint8_t vert_edge[] = { 0, 0, 0, 0 };
171 uint8_t horiz_edge[] = { 0, 0, 0, 0 };
172 uint8_t diag_edge[] = { 0, 0, 0, 0 };
173 uint8_t lfase[3]; // current, above, left
174 uint8_t no_tile_filter = s->pps->tiles_enabled_flag &&
175 !s->pps->loop_filter_across_tiles_enabled_flag;
176 uint8_t left_tile_edge = 0;
177 uint8_t up_tile_edge = 0;
179 sao[0] = &CTB(s->sao, x_ctb, y_ctb);
180 edges[0] = x_ctb == 0;
181 edges[1] = y_ctb == 0;
182 edges[2] = x_ctb == s->sps->ctb_width - 1;
183 edges[3] = y_ctb == s->sps->ctb_height - 1;
184 lfase[0] = CTB(s->filter_slice_edges, x_ctb, y_ctb);
188 left_tile_edge = no_tile_filter && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs-1]];
189 sao[class] = &CTB(s->sao, x_ctb - 1, y_ctb);
190 vert_edge[0] = (!lfase[0] && CTB(s->tab_slice_address, x_ctb, y_ctb) != CTB(s->tab_slice_address, x_ctb - 1, y_ctb)) || left_tile_edge;
191 vert_edge[2] = vert_edge[0];
192 lfase[2] = CTB(s->filter_slice_edges, x_ctb - 1, y_ctb);
199 up_tile_edge = no_tile_filter && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->sps->ctb_width]];
200 sao[class] = &CTB(s->sao, x_ctb, y_ctb - 1);
201 horiz_edge[0] = (!lfase[0] && CTB(s->tab_slice_address, x_ctb, y_ctb) != CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) || up_tile_edge;
202 horiz_edge[1] = horiz_edge[0];
203 lfase[1] = CTB(s->filter_slice_edges, x_ctb, y_ctb - 1);
210 sao[class] = &CTB(s->sao, x_ctb - 1, y_ctb - 1);
213 // Tile check here is done current CTB row/col, not above/left like you'd expect,
214 //but that is because the tile boundary always extends through the whole pic
215 vert_edge[1] = (!lfase[1] && CTB(s->tab_slice_address, x_ctb, y_ctb - 1) != CTB(s->tab_slice_address, x_ctb - 1, y_ctb - 1)) || left_tile_edge;
216 vert_edge[3] = vert_edge[1];
217 horiz_edge[2] = (!lfase[2] && CTB(s->tab_slice_address, x_ctb - 1, y_ctb) != CTB(s->tab_slice_address, x_ctb - 1, y_ctb - 1)) || up_tile_edge;
218 horiz_edge[3] = horiz_edge[2];
219 diag_edge[0] = (!lfase[0] && CTB(s->tab_slice_address, x_ctb, y_ctb) != CTB(s->tab_slice_address, x_ctb - 1, y_ctb - 1)) || left_tile_edge || up_tile_edge;
220 diag_edge[3] = diag_edge[0];
222 // Does left CTB comes after above CTB?
223 if (CTB(s->tab_slice_address, x_ctb - 1, y_ctb) >
224 CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) {
225 diag_edge[2] = !lfase[2] || left_tile_edge || up_tile_edge;
226 diag_edge[1] = diag_edge[2];
227 } else if (CTB(s->tab_slice_address, x_ctb - 1, y_ctb) <
228 CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) {
229 diag_edge[1] = !lfase[1] || left_tile_edge || up_tile_edge;
230 diag_edge[2] = diag_edge[1];
232 // Same slice, only consider tiles
233 diag_edge[2] = left_tile_edge || up_tile_edge;
234 diag_edge[1] = diag_edge[2];
239 for (c_idx = 0; c_idx < 3; c_idx++) {
240 int chroma = c_idx ? 1 : 0;
241 int x0 = x >> chroma;
242 int y0 = y >> chroma;
243 int stride = s->frame->linesize[c_idx];
244 int ctb_size = (1 << (s->sps->log2_ctb_size)) >> s->sps->hshift[c_idx];
245 int width = FFMIN(ctb_size,
246 (s->sps->width >> s->sps->hshift[c_idx]) - x0);
247 int height = FFMIN(ctb_size,
248 (s->sps->height >> s->sps->vshift[c_idx]) - y0);
250 uint8_t *src = &s->frame->data[c_idx][y0 * stride + (x0 << s->sps->pixel_shift)];
251 uint8_t *dst = &s->sao_frame->data[c_idx][y0 * stride + (x0 << s->sps->pixel_shift)];
252 int offset = (y_shift >> chroma) * stride + ((x_shift >> chroma) << s->sps->pixel_shift);
254 copy_CTB(dst - offset, src - offset,
255 (edges[2] ? width + (x_shift >> chroma) : width) << s->sps->pixel_shift,
256 (edges[3] ? height + (y_shift >> chroma) : height), stride);
258 for (class_index = 0; class_index < class; class_index++) {
260 switch (sao[class_index]->type_idx[c_idx]) {
262 s->hevcdsp.sao_band_filter[classes[class_index]](dst, src,
269 s->hevcdsp.sao_edge_filter[classes[class_index]](dst, src,
274 vert_edge[classes[class_index]],
275 horiz_edge[classes[class_index]],
276 diag_edge[classes[class_index]]);
283 static int get_pcm(HEVCContext *s, int x, int y)
285 int log2_min_pu_size = s->sps->log2_min_pu_size;
291 x_pu = x >> log2_min_pu_size;
292 y_pu = y >> log2_min_pu_size;
294 if (x_pu >= s->sps->min_pu_width || y_pu >= s->sps->min_pu_height)
296 return s->is_pcm[y_pu * s->sps->min_pu_width + x_pu];
299 #define TC_CALC(qp, bs) \
300 tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \
301 (tc_offset >> 1 << 1), \
302 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
304 static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
309 int c_tc[2], beta[2], tc[2];
310 uint8_t no_p[2] = { 0 };
311 uint8_t no_q[2] = { 0 };
313 int log2_ctb_size = s->sps->log2_ctb_size;
315 int ctb_size = 1 << log2_ctb_size;
316 int ctb = (x0 >> log2_ctb_size) +
317 (y0 >> log2_ctb_size) * s->sps->ctb_width;
318 int cur_tc_offset = s->deblock[ctb].tc_offset;
319 int cur_beta_offset = s->deblock[ctb].beta_offset;
320 int left_tc_offset, left_beta_offset;
321 int tc_offset, beta_offset;
322 int pcmf = (s->sps->pcm_enabled_flag &&
323 s->sps->pcm.loop_filter_disable_flag) ||
324 s->pps->transquant_bypass_enable_flag;
327 left_tc_offset = s->deblock[ctb - 1].tc_offset;
328 left_beta_offset = s->deblock[ctb - 1].beta_offset;
331 x_end = x0 + ctb_size;
332 if (x_end > s->sps->width)
333 x_end = s->sps->width;
334 y_end = y0 + ctb_size;
335 if (y_end > s->sps->height)
336 y_end = s->sps->height;
338 tc_offset = cur_tc_offset;
339 beta_offset = cur_beta_offset;
341 // vertical filtering luma
342 for (y = y0; y < y_end; y += 8) {
343 for (x = x0 ? x0 : 8; x < x_end; x += 8) {
344 const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width];
345 const int bs1 = s->vertical_bs[(x >> 3) + ((y + 4) >> 2) * s->bs_width];
347 const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1;
348 const int qp1 = (get_qPy(s, x - 1, y + 4) + get_qPy(s, x, y + 4) + 1) >> 1;
350 beta[0] = betatable[av_clip(qp0 + beta_offset, 0, MAX_QP)];
351 beta[1] = betatable[av_clip(qp1 + beta_offset, 0, MAX_QP)];
352 tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0;
353 tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0;
354 src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)];
356 no_p[0] = get_pcm(s, x - 1, y);
357 no_p[1] = get_pcm(s, x - 1, y + 4);
358 no_q[0] = get_pcm(s, x, y);
359 no_q[1] = get_pcm(s, x, y + 4);
360 s->hevcdsp.hevc_v_loop_filter_luma_c(src,
361 s->frame->linesize[LUMA],
362 beta, tc, no_p, no_q);
364 s->hevcdsp.hevc_v_loop_filter_luma(src,
365 s->frame->linesize[LUMA],
366 beta, tc, no_p, no_q);
371 // vertical filtering chroma
372 for (chroma = 1; chroma <= 2; chroma++) {
373 for (y = y0; y < y_end; y += 16) {
374 for (x = x0 ? x0 : 16; x < x_end; x += 16) {
375 const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width];
376 const int bs1 = s->vertical_bs[(x >> 3) + ((y + 8) >> 2) * s->bs_width];
377 if ((bs0 == 2) || (bs1 == 2)) {
378 const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1;
379 const int qp1 = (get_qPy(s, x - 1, y + 8) + get_qPy(s, x, y + 8) + 1) >> 1;
381 c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0;
382 c_tc[1] = (bs1 == 2) ? chroma_tc(s, qp1, chroma, tc_offset) : 0;
383 src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)];
385 no_p[0] = get_pcm(s, x - 1, y);
386 no_p[1] = get_pcm(s, x - 1, y + 8);
387 no_q[0] = get_pcm(s, x, y);
388 no_q[1] = get_pcm(s, x, y + 8);
389 s->hevcdsp.hevc_v_loop_filter_chroma_c(src,
390 s->frame->linesize[chroma],
393 s->hevcdsp.hevc_v_loop_filter_chroma(src,
394 s->frame->linesize[chroma],
401 // horizontal filtering luma
402 if (x_end != s->sps->width)
404 for (y = y0 ? y0 : 8; y < y_end; y += 8) {
405 for (x = x0 ? x0 - 8 : 0; x < x_end; x += 8) {
406 const int bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
407 const int bs1 = s->horizontal_bs[(x + 4 + y * s->bs_width) >> 2];
409 const int qp0 = (get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1;
410 const int qp1 = (get_qPy(s, x + 4, y - 1) + get_qPy(s, x + 4, y) + 1) >> 1;
412 tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
413 beta_offset = x >= x0 ? cur_beta_offset : left_beta_offset;
415 beta[0] = betatable[av_clip(qp0 + beta_offset, 0, MAX_QP)];
416 beta[1] = betatable[av_clip(qp1 + beta_offset, 0, MAX_QP)];
417 tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0;
418 tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0;
419 src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)];
421 no_p[0] = get_pcm(s, x, y - 1);
422 no_p[1] = get_pcm(s, x + 4, y - 1);
423 no_q[0] = get_pcm(s, x, y);
424 no_q[1] = get_pcm(s, x + 4, y);
425 s->hevcdsp.hevc_h_loop_filter_luma_c(src,
426 s->frame->linesize[LUMA],
427 beta, tc, no_p, no_q);
429 s->hevcdsp.hevc_h_loop_filter_luma(src,
430 s->frame->linesize[LUMA],
431 beta, tc, no_p, no_q);
436 // horizontal filtering chroma
437 for (chroma = 1; chroma <= 2; chroma++) {
438 for (y = y0 ? y0 : 16; y < y_end; y += 16) {
439 for (x = x0 - 8; x < x_end; x += 16) {
441 // to make sure no memory access over boundary when x = -8
442 // TODO: simplify with row based deblocking
445 bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2];
446 } else if (x >= x_end - 8) {
447 bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
450 bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
451 bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2];
454 if ((bs0 == 2) || (bs1 == 2)) {
455 const int qp0 = bs0 == 2 ? (get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1 : 0;
456 const int qp1 = bs1 == 2 ? (get_qPy(s, x + 8, y - 1) + get_qPy(s, x + 8, y) + 1) >> 1 : 0;
458 tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
459 c_tc[0] = bs0 == 2 ? chroma_tc(s, qp0, chroma, tc_offset) : 0;
460 c_tc[1] = bs1 == 2 ? chroma_tc(s, qp1, chroma, cur_tc_offset) : 0;
461 src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)];
463 no_p[0] = get_pcm(s, x, y - 1);
464 no_p[1] = get_pcm(s, x + 8, y - 1);
465 no_q[0] = get_pcm(s, x, y);
466 no_q[1] = get_pcm(s, x + 8, y);
467 s->hevcdsp.hevc_h_loop_filter_chroma_c(src,
468 s->frame->linesize[chroma],
471 s->hevcdsp.hevc_h_loop_filter_chroma(src,
472 s->frame->linesize[chroma],
480 static int boundary_strength(HEVCContext *s, MvField *curr, MvField *neigh,
481 RefPicList *neigh_refPicList)
483 if (curr->pred_flag == PF_BI && neigh->pred_flag == PF_BI) {
485 if (s->ref->refPicList[0].list[curr->ref_idx[0]] == neigh_refPicList[0].list[neigh->ref_idx[0]] &&
486 s->ref->refPicList[0].list[curr->ref_idx[0]] == s->ref->refPicList[1].list[curr->ref_idx[1]] &&
487 neigh_refPicList[0].list[neigh->ref_idx[0]] == neigh_refPicList[1].list[neigh->ref_idx[1]]) {
488 if ((FFABS(neigh->mv[0].x - curr->mv[0].x) >= 4 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 4 ||
489 FFABS(neigh->mv[1].x - curr->mv[1].x) >= 4 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 4) &&
490 (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 4 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 4 ||
491 FFABS(neigh->mv[0].x - curr->mv[1].x) >= 4 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 4))
495 } else if (neigh_refPicList[0].list[neigh->ref_idx[0]] == s->ref->refPicList[0].list[curr->ref_idx[0]] &&
496 neigh_refPicList[1].list[neigh->ref_idx[1]] == s->ref->refPicList[1].list[curr->ref_idx[1]]) {
497 if (FFABS(neigh->mv[0].x - curr->mv[0].x) >= 4 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 4 ||
498 FFABS(neigh->mv[1].x - curr->mv[1].x) >= 4 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 4)
502 } else if (neigh_refPicList[1].list[neigh->ref_idx[1]] == s->ref->refPicList[0].list[curr->ref_idx[0]] &&
503 neigh_refPicList[0].list[neigh->ref_idx[0]] == s->ref->refPicList[1].list[curr->ref_idx[1]]) {
504 if (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 4 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 4 ||
505 FFABS(neigh->mv[0].x - curr->mv[1].x) >= 4 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 4)
512 } else if ((curr->pred_flag != PF_BI) && (neigh->pred_flag != PF_BI)){ // 1 MV
516 if (curr->pred_flag & 1) {
518 ref_A = s->ref->refPicList[0].list[curr->ref_idx[0]];
521 ref_A = s->ref->refPicList[1].list[curr->ref_idx[1]];
524 if (neigh->pred_flag & 1) {
526 ref_B = neigh_refPicList[0].list[neigh->ref_idx[0]];
529 ref_B = neigh_refPicList[1].list[neigh->ref_idx[1]];
532 if (ref_A == ref_B) {
533 if (FFABS(A.x - B.x) >= 4 || FFABS(A.y - B.y) >= 4)
544 void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
547 HEVCLocalContext *lc = s->HEVClc;
548 MvField *tab_mvf = s->ref->tab_mvf;
549 int log2_min_pu_size = s->sps->log2_min_pu_size;
550 int log2_min_tu_size = s->sps->log2_min_tb_size;
551 int min_pu_width = s->sps->min_pu_width;
552 int min_tu_width = s->sps->min_tb_width;
553 int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
554 (x0 >> log2_min_pu_size)].pred_flag == PF_INTRA;
557 if (y0 > 0 && (y0 & 7) == 0) {
558 int bd_ctby = y0 & ((1 << s->sps->log2_ctb_size) - 1);
559 int bd_slice = s->sh.slice_loop_filter_across_slices_enabled_flag ||
560 !(lc->slice_or_tiles_up_boundary & 1);
561 int bd_tiles = s->pps->loop_filter_across_tiles_enabled_flag ||
562 !(lc->slice_or_tiles_up_boundary & 2);
563 if (((bd_slice && bd_tiles) || bd_ctby)) {
564 int yp_pu = (y0 - 1) >> log2_min_pu_size;
565 int yq_pu = y0 >> log2_min_pu_size;
566 int yp_tu = (y0 - 1) >> log2_min_tu_size;
567 int yq_tu = y0 >> log2_min_tu_size;
568 RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref,
571 for (i = 0; i < (1 << log2_trafo_size); i += 4) {
572 int x_pu = (x0 + i) >> log2_min_pu_size;
573 int x_tu = (x0 + i) >> log2_min_tu_size;
574 MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
575 MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
576 uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu];
577 uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu];
579 if (curr->pred_flag == PF_INTRA || top->pred_flag == PF_INTRA)
581 else if (curr_cbf_luma || top_cbf_luma)
584 bs = boundary_strength(s, curr, top, top_refPicList);
585 s->horizontal_bs[((x0 + i) + y0 * s->bs_width) >> 2] = bs;
590 // bs for vertical TU boundaries
591 if (x0 > 0 && (x0 & 7) == 0) {
592 int bd_ctbx = x0 & ((1 << s->sps->log2_ctb_size) - 1);
593 int bd_slice = s->sh.slice_loop_filter_across_slices_enabled_flag ||
594 !(lc->slice_or_tiles_left_boundary & 1);
595 int bd_tiles = s->pps->loop_filter_across_tiles_enabled_flag ||
596 !(lc->slice_or_tiles_left_boundary & 2);
597 if (((bd_slice && bd_tiles) || bd_ctbx)) {
598 int xp_pu = (x0 - 1) >> log2_min_pu_size;
599 int xq_pu = x0 >> log2_min_pu_size;
600 int xp_tu = (x0 - 1) >> log2_min_tu_size;
601 int xq_tu = x0 >> log2_min_tu_size;
602 RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref,
605 for (i = 0; i < (1 << log2_trafo_size); i += 4) {
606 int y_pu = (y0 + i) >> log2_min_pu_size;
607 int y_tu = (y0 + i) >> log2_min_tu_size;
608 MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
609 MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
610 uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu];
611 uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu];
613 if (curr->pred_flag == PF_INTRA || left->pred_flag == PF_INTRA)
615 else if (curr_cbf_luma || left_cbf_luma)
618 bs = boundary_strength(s, curr, left, left_refPicList);
619 s->vertical_bs[(x0 >> 3) + ((y0 + i) >> 2) * s->bs_width] = bs;
624 if (log2_trafo_size > log2_min_pu_size && !is_intra) {
625 RefPicList *refPicList = ff_hevc_get_ref_list(s, s->ref,
628 // bs for TU internal horizontal PU boundaries
629 for (j = 8; j < (1 << log2_trafo_size); j += 8) {
630 int yp_pu = (y0 + j - 1) >> log2_min_pu_size;
631 int yq_pu = (y0 + j) >> log2_min_pu_size;
633 for (i = 0; i < (1 << log2_trafo_size); i += 4) {
634 int x_pu = (x0 + i) >> log2_min_pu_size;
635 MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
636 MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
638 bs = boundary_strength(s, curr, top, refPicList);
639 s->horizontal_bs[((x0 + i) + (y0 + j) * s->bs_width) >> 2] = bs;
643 // bs for TU internal vertical PU boundaries
644 for (j = 0; j < (1 << log2_trafo_size); j += 4) {
645 int y_pu = (y0 + j) >> log2_min_pu_size;
647 for (i = 8; i < (1 << log2_trafo_size); i += 8) {
648 int xp_pu = (x0 + i - 1) >> log2_min_pu_size;
649 int xq_pu = (x0 + i) >> log2_min_pu_size;
650 MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
651 MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
653 bs = boundary_strength(s, curr, left, refPicList);
654 s->vertical_bs[((x0 + i) >> 3) + ((y0 + j) >> 2) * s->bs_width] = bs;
664 void ff_hevc_hls_filter(HEVCContext *s, int x, int y)
666 deblocking_filter_CTB(s, x, y);
667 if (s->sps->sao_enabled)
668 sao_filter_CTB(s, x, y);
671 void ff_hevc_hls_filters(HEVCContext *s, int x_ctb, int y_ctb, int ctb_size)
674 ff_hevc_hls_filter(s, x_ctb - ctb_size, y_ctb - ctb_size);
675 if (y_ctb && x_ctb >= s->sps->width - ctb_size) {
676 ff_hevc_hls_filter(s, x_ctb, y_ctb - ctb_size);
677 if (s->threads_type == FF_THREAD_FRAME )
678 ff_thread_report_progress(&s->ref->tf, y_ctb - ctb_size, 0);
680 if (x_ctb && y_ctb >= s->sps->height - ctb_size)
681 ff_hevc_hls_filter(s, x_ctb - ctb_size, y_ctb);