2013-10-12 11:55:48 +02:00
|
|
|
/*
|
2013-11-02 11:59:02 +01:00
|
|
|
* HEVC video decoder
|
2013-10-12 11:55:48 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2012 - 2013 Guillaume Martres
|
|
|
|
* Copyright (C) 2013 Seppo Tomperi
|
|
|
|
* Copyright (C) 2013 Wassim Hamidouche
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavutil/common.h"
|
|
|
|
#include "libavutil/internal.h"
|
|
|
|
|
|
|
|
#include "cabac_functions.h"
|
|
|
|
#include "golomb.h"
|
|
|
|
#include "hevc.h"
|
2013-11-02 11:43:43 +01:00
|
|
|
|
2013-10-12 11:55:48 +02:00
|
|
|
#include "bit_depth_template.c"
|
|
|
|
|
|
|
|
#define LUMA 0
|
|
|
|
#define CB 1
|
|
|
|
#define CR 2
|
|
|
|
|
|
|
|
static const uint8_t tctable[54] = {
|
2013-11-02 00:31:49 +01:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // QP 0...18
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, // QP 19...37
|
|
|
|
5, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 24 // QP 38...53
|
2013-10-12 11:55:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const uint8_t betatable[52] = {
|
2013-11-02 00:31:49 +01:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, // QP 0...18
|
|
|
|
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, // QP 19...37
|
|
|
|
38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64 // QP 38...51
|
2013-10-12 11:55:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset)
|
|
|
|
{
|
2013-11-02 00:31:49 +01:00
|
|
|
static const int qp_c[] = {
|
|
|
|
29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37
|
|
|
|
};
|
2013-11-02 11:59:02 +01:00
|
|
|
int qp, qp_i, offset, idxt;
|
2013-10-12 11:55:48 +02:00
|
|
|
|
|
|
|
// slice qp offset is not used for deblocking
|
|
|
|
if (c_idx == 1)
|
|
|
|
offset = s->pps->cb_qp_offset;
|
|
|
|
else
|
|
|
|
offset = s->pps->cr_qp_offset;
|
|
|
|
|
|
|
|
qp_i = av_clip_c(qp_y + offset, 0, 57);
|
|
|
|
if (qp_i < 30)
|
|
|
|
qp = qp_i;
|
|
|
|
else if (qp_i > 43)
|
|
|
|
qp = qp_i - 6;
|
|
|
|
else
|
|
|
|
qp = qp_c[qp_i - 30];
|
|
|
|
|
|
|
|
idxt = av_clip_c(qp + DEFAULT_INTRA_TC_OFFSET + tc_offset, 0, 53);
|
|
|
|
return tctable[idxt];
|
|
|
|
}
|
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
static int get_qPy_pred(HEVCContext *s, int xC, int yC,
|
|
|
|
int xBase, int yBase, int log2_cb_size)
|
2013-10-12 11:55:48 +02:00
|
|
|
{
|
2013-10-21 11:49:35 +02:00
|
|
|
HEVCLocalContext *lc = s->HEVClc;
|
2013-10-12 11:55:48 +02:00
|
|
|
int ctb_size_mask = (1 << s->sps->log2_ctb_size) - 1;
|
2013-11-02 00:31:49 +01:00
|
|
|
int MinCuQpDeltaSizeMask = (1 << (s->sps->log2_ctb_size -
|
|
|
|
s->pps->diff_cu_qp_delta_depth)) - 1;
|
|
|
|
int xQgBase = xBase - (xBase & MinCuQpDeltaSizeMask);
|
|
|
|
int yQgBase = yBase - (yBase & MinCuQpDeltaSizeMask);
|
2013-10-27 12:56:48 +01:00
|
|
|
int min_cb_width = s->sps->min_cb_width;
|
|
|
|
int x_cb = xQgBase >> s->sps->log2_min_cb_size;
|
|
|
|
int y_cb = yQgBase >> s->sps->log2_min_cb_size;
|
2013-11-02 00:31:49 +01:00
|
|
|
int availableA = (xBase & ctb_size_mask) &&
|
|
|
|
(xQgBase & ctb_size_mask);
|
|
|
|
int availableB = (yBase & ctb_size_mask) &&
|
|
|
|
(yQgBase & ctb_size_mask);
|
2013-11-02 11:59:02 +01:00
|
|
|
int qPy_pred, qPy_a, qPy_b;
|
2013-10-12 11:55:48 +02:00
|
|
|
|
|
|
|
// qPy_pred
|
2014-01-11 04:22:50 +01:00
|
|
|
if (lc->first_qp_group || (!xQgBase && !yQgBase)) {
|
2013-10-12 11:55:48 +02:00
|
|
|
lc->first_qp_group = !lc->tu.is_cu_qp_delta_coded;
|
|
|
|
qPy_pred = s->sh.slice_qp;
|
|
|
|
} else {
|
2014-02-07 23:28:22 +01:00
|
|
|
qPy_pred = lc->qPy_pred;
|
2013-10-12 11:55:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// qPy_a
|
|
|
|
if (availableA == 0)
|
|
|
|
qPy_a = qPy_pred;
|
|
|
|
else
|
2013-10-27 12:56:48 +01:00
|
|
|
qPy_a = s->qp_y_tab[(x_cb - 1) + y_cb * min_cb_width];
|
2013-10-12 11:55:48 +02:00
|
|
|
|
|
|
|
// qPy_b
|
|
|
|
if (availableB == 0)
|
|
|
|
qPy_b = qPy_pred;
|
|
|
|
else
|
2013-10-27 12:56:48 +01:00
|
|
|
qPy_b = s->qp_y_tab[x_cb + (y_cb - 1) * min_cb_width];
|
2013-10-12 11:55:48 +02:00
|
|
|
|
2014-02-07 01:55:17 +01:00
|
|
|
av_assert2(qPy_a >= -s->sps->qp_bd_offset && qPy_a < 52);
|
|
|
|
av_assert2(qPy_b >= -s->sps->qp_bd_offset && qPy_b < 52);
|
|
|
|
|
2013-10-12 11:55:48 +02:00
|
|
|
return (qPy_a + qPy_b + 1) >> 1;
|
|
|
|
}
|
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC,
|
|
|
|
int xBase, int yBase, int log2_cb_size)
|
2013-10-12 11:55:48 +02:00
|
|
|
{
|
|
|
|
int qp_y = get_qPy_pred(s, xC, yC, xBase, yBase, log2_cb_size);
|
|
|
|
|
2013-10-21 11:49:35 +02:00
|
|
|
if (s->HEVClc->tu.cu_qp_delta != 0) {
|
2013-10-12 11:55:48 +02:00
|
|
|
int off = s->sps->qp_bd_offset;
|
2014-01-06 02:51:20 +01:00
|
|
|
s->HEVClc->qp_y = FFUMOD(qp_y + s->HEVClc->tu.cu_qp_delta + 52 + 2 * off,
|
|
|
|
52 + off) - off;
|
2013-10-12 11:55:48 +02:00
|
|
|
} else
|
2013-10-21 11:49:35 +02:00
|
|
|
s->HEVClc->qp_y = qp_y;
|
2013-10-12 11:55:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_qPy(HEVCContext *s, int xC, int yC)
|
|
|
|
{
|
2013-10-27 12:56:48 +01:00
|
|
|
int log2_min_cb_size = s->sps->log2_min_cb_size;
|
2013-10-12 11:55:48 +02:00
|
|
|
int x = xC >> log2_min_cb_size;
|
|
|
|
int y = yC >> log2_min_cb_size;
|
2013-10-27 12:56:48 +01:00
|
|
|
return s->qp_y_tab[x + y * s->sps->min_cb_width];
|
2013-10-12 11:55:48 +02:00
|
|
|
}
|
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
static void copy_CTB(uint8_t *dst, uint8_t *src,
|
|
|
|
int width, int height, int stride)
|
2013-10-12 11:55:48 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
for (i = 0; i < height; i++) {
|
2013-10-12 11:55:48 +02:00
|
|
|
memcpy(dst, src, width);
|
|
|
|
dst += stride;
|
|
|
|
src += stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CTB(tab, x, y) ((tab)[(y) * s->sps->ctb_width + (x)])
|
|
|
|
|
2013-10-11 22:07:00 +02:00
|
|
|
static void sao_filter_CTB(HEVCContext *s, int x, int y)
|
2013-10-12 11:55:48 +02:00
|
|
|
{
|
|
|
|
// TODO: This should be easily parallelizable
|
|
|
|
// TODO: skip CBs when (cu_transquant_bypass_flag || (pcm_loop_filter_disable_flag && pcm_flag))
|
|
|
|
int c_idx = 0;
|
|
|
|
int class = 1, class_index;
|
2013-11-02 00:31:49 +01:00
|
|
|
int edges[4]; // 0 left 1 top 2 right 3 bottom
|
2013-10-12 11:55:48 +02:00
|
|
|
SAOParams *sao[4];
|
|
|
|
int classes[4];
|
|
|
|
int x_shift = 0, y_shift = 0;
|
2013-11-02 00:31:49 +01:00
|
|
|
int x_ctb = x >> s->sps->log2_ctb_size;
|
|
|
|
int y_ctb = y >> s->sps->log2_ctb_size;
|
2013-10-12 11:55:48 +02:00
|
|
|
int ctb_addr_rs = y_ctb * s->sps->ctb_width + x_ctb;
|
|
|
|
int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[ctb_addr_rs];
|
|
|
|
|
|
|
|
// flags indicating unfilterable edges
|
2013-11-02 00:31:49 +01:00
|
|
|
uint8_t vert_edge[] = { 0, 0, 0, 0 };
|
|
|
|
uint8_t horiz_edge[] = { 0, 0, 0, 0 };
|
|
|
|
uint8_t diag_edge[] = { 0, 0, 0, 0 };
|
2013-10-12 11:55:48 +02:00
|
|
|
uint8_t lfase[3]; // current, above, left
|
2013-11-02 00:31:49 +01:00
|
|
|
uint8_t no_tile_filter = s->pps->tiles_enabled_flag &&
|
|
|
|
!s->pps->loop_filter_across_tiles_enabled_flag;
|
2013-10-12 11:55:48 +02:00
|
|
|
uint8_t left_tile_edge = 0;
|
|
|
|
uint8_t up_tile_edge = 0;
|
|
|
|
|
|
|
|
sao[0] = &CTB(s->sao, x_ctb, y_ctb);
|
|
|
|
edges[0] = x_ctb == 0;
|
|
|
|
edges[1] = y_ctb == 0;
|
2013-11-02 11:59:02 +01:00
|
|
|
edges[2] = x_ctb == s->sps->ctb_width - 1;
|
|
|
|
edges[3] = y_ctb == s->sps->ctb_height - 1;
|
2013-10-12 11:55:48 +02:00
|
|
|
lfase[0] = CTB(s->filter_slice_edges, x_ctb, y_ctb);
|
|
|
|
classes[0] = 0;
|
|
|
|
|
|
|
|
if (!edges[0]) {
|
|
|
|
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]];
|
|
|
|
sao[class] = &CTB(s->sao, x_ctb - 1, y_ctb);
|
|
|
|
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;
|
|
|
|
vert_edge[2] = vert_edge[0];
|
|
|
|
lfase[2] = CTB(s->filter_slice_edges, x_ctb - 1, y_ctb);
|
|
|
|
classes[class] = 2;
|
|
|
|
class++;
|
|
|
|
x_shift = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!edges[1]) {
|
|
|
|
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]];
|
|
|
|
sao[class] = &CTB(s->sao, x_ctb, y_ctb - 1);
|
|
|
|
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;
|
|
|
|
horiz_edge[1] = horiz_edge[0];
|
|
|
|
lfase[1] = CTB(s->filter_slice_edges, x_ctb, y_ctb - 1);
|
|
|
|
classes[class] = 1;
|
|
|
|
class++;
|
|
|
|
y_shift = 4;
|
|
|
|
|
|
|
|
if (!edges[0]) {
|
|
|
|
classes[class] = 3;
|
|
|
|
sao[class] = &CTB(s->sao, x_ctb - 1, y_ctb - 1);
|
|
|
|
class++;
|
|
|
|
|
|
|
|
// Tile check here is done current CTB row/col, not above/left like you'd expect,
|
|
|
|
//but that is because the tile boundary always extends through the whole pic
|
|
|
|
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;
|
|
|
|
vert_edge[3] = vert_edge[1];
|
|
|
|
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;
|
|
|
|
horiz_edge[3] = horiz_edge[2];
|
|
|
|
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;
|
|
|
|
diag_edge[3] = diag_edge[0];
|
|
|
|
|
|
|
|
// Does left CTB comes after above CTB?
|
2013-11-02 00:31:49 +01:00
|
|
|
if (CTB(s->tab_slice_address, x_ctb - 1, y_ctb) >
|
|
|
|
CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) {
|
2013-10-12 11:55:48 +02:00
|
|
|
diag_edge[2] = !lfase[2] || left_tile_edge || up_tile_edge;
|
|
|
|
diag_edge[1] = diag_edge[2];
|
2013-11-02 00:31:49 +01:00
|
|
|
} else if (CTB(s->tab_slice_address, x_ctb - 1, y_ctb) <
|
|
|
|
CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) {
|
2013-10-12 11:55:48 +02:00
|
|
|
diag_edge[1] = !lfase[1] || left_tile_edge || up_tile_edge;
|
|
|
|
diag_edge[2] = diag_edge[1];
|
|
|
|
} else {
|
|
|
|
// Same slice, only consider tiles
|
|
|
|
diag_edge[2] = left_tile_edge || up_tile_edge;
|
|
|
|
diag_edge[1] = diag_edge[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (c_idx = 0; c_idx < 3; c_idx++) {
|
|
|
|
int chroma = c_idx ? 1 : 0;
|
|
|
|
int x0 = x >> chroma;
|
|
|
|
int y0 = y >> chroma;
|
|
|
|
int stride = s->frame->linesize[c_idx];
|
|
|
|
int ctb_size = (1 << (s->sps->log2_ctb_size)) >> s->sps->hshift[c_idx];
|
|
|
|
int width = FFMIN(ctb_size,
|
|
|
|
(s->sps->width >> s->sps->hshift[c_idx]) - x0);
|
|
|
|
int height = FFMIN(ctb_size,
|
|
|
|
(s->sps->height >> s->sps->vshift[c_idx]) - y0);
|
|
|
|
|
|
|
|
uint8_t *src = &s->frame->data[c_idx][y0 * stride + (x0 << s->sps->pixel_shift)];
|
|
|
|
uint8_t *dst = &s->sao_frame->data[c_idx][y0 * stride + (x0 << s->sps->pixel_shift)];
|
|
|
|
int offset = (y_shift >> chroma) * stride + ((x_shift >> chroma) << s->sps->pixel_shift);
|
|
|
|
|
|
|
|
copy_CTB(dst - offset, src - offset,
|
|
|
|
(edges[2] ? width + (x_shift >> chroma) : width) << s->sps->pixel_shift,
|
|
|
|
(edges[3] ? height + (y_shift >> chroma) : height), stride);
|
|
|
|
|
2013-10-11 22:07:00 +02:00
|
|
|
for (class_index = 0; class_index < class; class_index++) {
|
|
|
|
|
2013-10-12 11:55:48 +02:00
|
|
|
switch (sao[class_index]->type_idx[c_idx]) {
|
|
|
|
case SAO_BAND:
|
2013-11-02 00:31:49 +01:00
|
|
|
s->hevcdsp.sao_band_filter[classes[class_index]](dst, src,
|
|
|
|
stride,
|
|
|
|
sao[class_index],
|
|
|
|
edges, width,
|
|
|
|
height, c_idx);
|
|
|
|
break;
|
2013-10-12 11:55:48 +02:00
|
|
|
case SAO_EDGE:
|
2013-11-02 00:31:49 +01:00
|
|
|
s->hevcdsp.sao_edge_filter[classes[class_index]](dst, src,
|
|
|
|
stride,
|
|
|
|
sao[class_index],
|
|
|
|
edges, width,
|
|
|
|
height, c_idx,
|
|
|
|
vert_edge[classes[class_index]],
|
|
|
|
horiz_edge[classes[class_index]],
|
|
|
|
diag_edge[classes[class_index]]);
|
2013-10-12 11:55:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_pcm(HEVCContext *s, int x, int y)
|
|
|
|
{
|
2013-10-27 12:56:48 +01:00
|
|
|
int log2_min_pu_size = s->sps->log2_min_pu_size;
|
2014-02-19 22:21:43 +01:00
|
|
|
int x_pu, y_pu;
|
2013-10-12 11:55:48 +02:00
|
|
|
|
2014-02-19 22:21:43 +01:00
|
|
|
if (x < 0 || y < 0)
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
x_pu = x >> log2_min_pu_size;
|
|
|
|
y_pu = y >> log2_min_pu_size;
|
|
|
|
|
|
|
|
if (x_pu >= s->sps->min_pu_width || y_pu >= s->sps->min_pu_height)
|
2013-10-12 11:55:48 +02:00
|
|
|
return 2;
|
2013-10-27 12:56:48 +01:00
|
|
|
return s->is_pcm[y_pu * s->sps->min_pu_width + x_pu];
|
2013-10-12 11:55:48 +02:00
|
|
|
}
|
|
|
|
|
2013-11-02 11:59:02 +01:00
|
|
|
#define TC_CALC(qp, bs) \
|
|
|
|
tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \
|
|
|
|
(tc_offset >> 1 << 1), \
|
|
|
|
0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
|
2013-10-12 11:55:48 +02:00
|
|
|
|
|
|
|
static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
|
|
|
|
{
|
|
|
|
uint8_t *src;
|
|
|
|
int x, y;
|
|
|
|
int chroma;
|
2013-11-02 11:59:02 +01:00
|
|
|
int c_tc[2], beta[2], tc[2];
|
2013-11-02 00:31:49 +01:00
|
|
|
uint8_t no_p[2] = { 0 };
|
|
|
|
uint8_t no_q[2] = { 0 };
|
2013-10-12 11:55:48 +02:00
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
int log2_ctb_size = s->sps->log2_ctb_size;
|
2013-10-12 11:55:48 +02:00
|
|
|
int x_end, y_end;
|
2013-11-02 00:31:49 +01:00
|
|
|
int ctb_size = 1 << log2_ctb_size;
|
|
|
|
int ctb = (x0 >> log2_ctb_size) +
|
|
|
|
(y0 >> log2_ctb_size) * s->sps->ctb_width;
|
2013-10-12 11:55:48 +02:00
|
|
|
int cur_tc_offset = s->deblock[ctb].tc_offset;
|
|
|
|
int cur_beta_offset = s->deblock[ctb].beta_offset;
|
|
|
|
int left_tc_offset, left_beta_offset;
|
|
|
|
int tc_offset, beta_offset;
|
2013-11-02 00:31:49 +01:00
|
|
|
int pcmf = (s->sps->pcm_enabled_flag &&
|
|
|
|
s->sps->pcm.loop_filter_disable_flag) ||
|
|
|
|
s->pps->transquant_bypass_enable_flag;
|
2013-10-12 11:55:48 +02:00
|
|
|
|
2013-10-20 21:19:15 +02:00
|
|
|
if (x0) {
|
2013-11-02 00:31:49 +01:00
|
|
|
left_tc_offset = s->deblock[ctb - 1].tc_offset;
|
|
|
|
left_beta_offset = s->deblock[ctb - 1].beta_offset;
|
2013-10-12 11:55:48 +02:00
|
|
|
}
|
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
x_end = x0 + ctb_size;
|
2013-10-12 11:55:48 +02:00
|
|
|
if (x_end > s->sps->width)
|
|
|
|
x_end = s->sps->width;
|
2013-11-02 00:31:49 +01:00
|
|
|
y_end = y0 + ctb_size;
|
2013-10-12 11:55:48 +02:00
|
|
|
if (y_end > s->sps->height)
|
|
|
|
y_end = s->sps->height;
|
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
tc_offset = cur_tc_offset;
|
2013-10-12 11:55:48 +02:00
|
|
|
beta_offset = cur_beta_offset;
|
|
|
|
|
|
|
|
// vertical filtering luma
|
|
|
|
for (y = y0; y < y_end; y += 8) {
|
|
|
|
for (x = x0 ? x0 : 8; x < x_end; x += 8) {
|
|
|
|
const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width];
|
|
|
|
const int bs1 = s->vertical_bs[(x >> 3) + ((y + 4) >> 2) * s->bs_width];
|
|
|
|
if (bs0 || bs1) {
|
2013-11-02 00:31:49 +01:00
|
|
|
const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1;
|
2013-10-12 11:55:48 +02:00
|
|
|
const int qp1 = (get_qPy(s, x - 1, y + 4) + get_qPy(s, x, y + 4) + 1) >> 1;
|
|
|
|
|
2014-02-19 20:38:53 +01:00
|
|
|
beta[0] = betatable[av_clip(qp0 + beta_offset, 0, MAX_QP)];
|
|
|
|
beta[1] = betatable[av_clip(qp1 + beta_offset, 0, MAX_QP)];
|
2013-11-02 00:31:49 +01:00
|
|
|
tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0;
|
|
|
|
tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0;
|
|
|
|
src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)];
|
2013-10-12 11:55:48 +02:00
|
|
|
if (pcmf) {
|
|
|
|
no_p[0] = get_pcm(s, x - 1, y);
|
|
|
|
no_p[1] = get_pcm(s, x - 1, y + 4);
|
|
|
|
no_q[0] = get_pcm(s, x, y);
|
|
|
|
no_q[1] = get_pcm(s, x, y + 4);
|
2013-11-02 00:31:49 +01:00
|
|
|
s->hevcdsp.hevc_v_loop_filter_luma_c(src,
|
|
|
|
s->frame->linesize[LUMA],
|
|
|
|
beta, tc, no_p, no_q);
|
2013-10-12 11:55:48 +02:00
|
|
|
} else
|
2013-11-02 00:31:49 +01:00
|
|
|
s->hevcdsp.hevc_v_loop_filter_luma(src,
|
|
|
|
s->frame->linesize[LUMA],
|
|
|
|
beta, tc, no_p, no_q);
|
2013-10-12 11:55:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// vertical filtering chroma
|
|
|
|
for (chroma = 1; chroma <= 2; chroma++) {
|
|
|
|
for (y = y0; y < y_end; y += 16) {
|
2013-11-02 00:31:49 +01:00
|
|
|
for (x = x0 ? x0 : 16; x < x_end; x += 16) {
|
|
|
|
const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width];
|
2013-10-12 11:55:48 +02:00
|
|
|
const int bs1 = s->vertical_bs[(x >> 3) + ((y + 8) >> 2) * s->bs_width];
|
|
|
|
if ((bs0 == 2) || (bs1 == 2)) {
|
2013-11-02 00:31:49 +01:00
|
|
|
const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1;
|
2013-10-12 11:55:48 +02:00
|
|
|
const int qp1 = (get_qPy(s, x - 1, y + 8) + get_qPy(s, x, y + 8) + 1) >> 1;
|
|
|
|
|
|
|
|
c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0;
|
|
|
|
c_tc[1] = (bs1 == 2) ? chroma_tc(s, qp1, chroma, tc_offset) : 0;
|
2013-11-02 11:59:02 +01:00
|
|
|
src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)];
|
2013-10-12 11:55:48 +02:00
|
|
|
if (pcmf) {
|
|
|
|
no_p[0] = get_pcm(s, x - 1, y);
|
|
|
|
no_p[1] = get_pcm(s, x - 1, y + 8);
|
|
|
|
no_q[0] = get_pcm(s, x, y);
|
|
|
|
no_q[1] = get_pcm(s, x, y + 8);
|
2013-11-02 00:31:49 +01:00
|
|
|
s->hevcdsp.hevc_v_loop_filter_chroma_c(src,
|
|
|
|
s->frame->linesize[chroma],
|
|
|
|
c_tc, no_p, no_q);
|
2013-10-12 11:55:48 +02:00
|
|
|
} else
|
2013-11-02 00:31:49 +01:00
|
|
|
s->hevcdsp.hevc_v_loop_filter_chroma(src,
|
|
|
|
s->frame->linesize[chroma],
|
|
|
|
c_tc, no_p, no_q);
|
2013-10-12 11:55:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// horizontal filtering luma
|
|
|
|
if (x_end != s->sps->width)
|
|
|
|
x_end -= 8;
|
|
|
|
for (y = y0 ? y0 : 8; y < y_end; y += 8) {
|
|
|
|
for (x = x0 ? x0 - 8 : 0; x < x_end; x += 8) {
|
|
|
|
const int bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
|
|
|
|
const int bs1 = s->horizontal_bs[(x + 4 + y * s->bs_width) >> 2];
|
|
|
|
if (bs0 || bs1) {
|
|
|
|
const int qp0 = (get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1;
|
|
|
|
const int qp1 = (get_qPy(s, x + 4, y - 1) + get_qPy(s, x + 4, y) + 1) >> 1;
|
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
|
2013-10-12 11:55:48 +02:00
|
|
|
beta_offset = x >= x0 ? cur_beta_offset : left_beta_offset;
|
|
|
|
|
2014-02-19 20:38:53 +01:00
|
|
|
beta[0] = betatable[av_clip(qp0 + beta_offset, 0, MAX_QP)];
|
|
|
|
beta[1] = betatable[av_clip(qp1 + beta_offset, 0, MAX_QP)];
|
2013-11-02 00:31:49 +01:00
|
|
|
tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0;
|
|
|
|
tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0;
|
|
|
|
src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)];
|
2013-10-12 11:55:48 +02:00
|
|
|
if (pcmf) {
|
|
|
|
no_p[0] = get_pcm(s, x, y - 1);
|
|
|
|
no_p[1] = get_pcm(s, x + 4, y - 1);
|
|
|
|
no_q[0] = get_pcm(s, x, y);
|
|
|
|
no_q[1] = get_pcm(s, x + 4, y);
|
2013-11-02 00:31:49 +01:00
|
|
|
s->hevcdsp.hevc_h_loop_filter_luma_c(src,
|
|
|
|
s->frame->linesize[LUMA],
|
|
|
|
beta, tc, no_p, no_q);
|
2013-10-12 11:55:48 +02:00
|
|
|
} else
|
2013-11-02 00:31:49 +01:00
|
|
|
s->hevcdsp.hevc_h_loop_filter_luma(src,
|
|
|
|
s->frame->linesize[LUMA],
|
|
|
|
beta, tc, no_p, no_q);
|
2013-10-12 11:55:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// horizontal filtering chroma
|
|
|
|
for (chroma = 1; chroma <= 2; chroma++) {
|
|
|
|
for (y = y0 ? y0 : 16; y < y_end; y += 16) {
|
|
|
|
for (x = x0 - 8; x < x_end; x += 16) {
|
|
|
|
int bs0, bs1;
|
|
|
|
// to make sure no memory access over boundary when x = -8
|
|
|
|
// TODO: simplify with row based deblocking
|
|
|
|
if (x < 0) {
|
|
|
|
bs0 = 0;
|
|
|
|
bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2];
|
|
|
|
} else if (x >= x_end - 8) {
|
2013-11-02 00:31:49 +01:00
|
|
|
bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
|
2013-10-12 11:55:48 +02:00
|
|
|
bs1 = 0;
|
|
|
|
} else {
|
2013-11-02 00:31:49 +01:00
|
|
|
bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
|
2013-10-12 11:55:48 +02:00
|
|
|
bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((bs0 == 2) || (bs1 == 2)) {
|
2013-11-02 11:59:02 +01:00
|
|
|
const int qp0 = bs0 == 2 ? (get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1 : 0;
|
|
|
|
const int qp1 = bs1 == 2 ? (get_qPy(s, x + 8, y - 1) + get_qPy(s, x + 8, y) + 1) >> 1 : 0;
|
2013-10-12 11:55:48 +02:00
|
|
|
|
|
|
|
tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
|
2013-11-02 11:59:02 +01:00
|
|
|
c_tc[0] = bs0 == 2 ? chroma_tc(s, qp0, chroma, tc_offset) : 0;
|
|
|
|
c_tc[1] = bs1 == 2 ? chroma_tc(s, qp1, chroma, cur_tc_offset) : 0;
|
|
|
|
src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)];
|
2013-10-12 11:55:48 +02:00
|
|
|
if (pcmf) {
|
|
|
|
no_p[0] = get_pcm(s, x, y - 1);
|
|
|
|
no_p[1] = get_pcm(s, x + 8, y - 1);
|
|
|
|
no_q[0] = get_pcm(s, x, y);
|
|
|
|
no_q[1] = get_pcm(s, x + 8, y);
|
2013-11-02 00:31:49 +01:00
|
|
|
s->hevcdsp.hevc_h_loop_filter_chroma_c(src,
|
|
|
|
s->frame->linesize[chroma],
|
|
|
|
c_tc, no_p, no_q);
|
2013-10-12 11:55:48 +02:00
|
|
|
} else
|
2013-11-02 00:31:49 +01:00
|
|
|
s->hevcdsp.hevc_h_loop_filter_chroma(src,
|
|
|
|
s->frame->linesize[chroma],
|
|
|
|
c_tc, no_p, no_q);
|
2013-10-12 11:55:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int boundary_strength(HEVCContext *s, MvField *curr,
|
|
|
|
uint8_t curr_cbf_luma, MvField *neigh,
|
2013-11-02 00:31:49 +01:00
|
|
|
uint8_t neigh_cbf_luma,
|
|
|
|
RefPicList *neigh_refPicList,
|
2013-10-12 11:55:48 +02:00
|
|
|
int tu_border)
|
|
|
|
{
|
|
|
|
int mvs = curr->pred_flag[0] + curr->pred_flag[1];
|
|
|
|
|
|
|
|
if (tu_border) {
|
|
|
|
if (curr->is_intra || neigh->is_intra)
|
|
|
|
return 2;
|
|
|
|
if (curr_cbf_luma || neigh_cbf_luma)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mvs == neigh->pred_flag[0] + neigh->pred_flag[1]) {
|
|
|
|
if (mvs == 2) {
|
|
|
|
// same L0 and L1
|
2013-11-02 00:31:49 +01:00
|
|
|
if (s->ref->refPicList[0].list[curr->ref_idx[0]] == neigh_refPicList[0].list[neigh->ref_idx[0]] &&
|
2013-10-12 11:55:48 +02:00
|
|
|
s->ref->refPicList[0].list[curr->ref_idx[0]] == s->ref->refPicList[1].list[curr->ref_idx[1]] &&
|
|
|
|
neigh_refPicList[0].list[neigh->ref_idx[0]] == neigh_refPicList[1].list[neigh->ref_idx[1]]) {
|
|
|
|
if ((abs(neigh->mv[0].x - curr->mv[0].x) >= 4 || abs(neigh->mv[0].y - curr->mv[0].y) >= 4 ||
|
|
|
|
abs(neigh->mv[1].x - curr->mv[1].x) >= 4 || abs(neigh->mv[1].y - curr->mv[1].y) >= 4) &&
|
|
|
|
(abs(neigh->mv[1].x - curr->mv[0].x) >= 4 || abs(neigh->mv[1].y - curr->mv[0].y) >= 4 ||
|
|
|
|
abs(neigh->mv[0].x - curr->mv[1].x) >= 4 || abs(neigh->mv[0].y - curr->mv[1].y) >= 4))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
} else if (neigh_refPicList[0].list[neigh->ref_idx[0]] == s->ref->refPicList[0].list[curr->ref_idx[0]] &&
|
|
|
|
neigh_refPicList[1].list[neigh->ref_idx[1]] == s->ref->refPicList[1].list[curr->ref_idx[1]]) {
|
|
|
|
if (abs(neigh->mv[0].x - curr->mv[0].x) >= 4 || abs(neigh->mv[0].y - curr->mv[0].y) >= 4 ||
|
|
|
|
abs(neigh->mv[1].x - curr->mv[1].x) >= 4 || abs(neigh->mv[1].y - curr->mv[1].y) >= 4)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
} else if (neigh_refPicList[1].list[neigh->ref_idx[1]] == s->ref->refPicList[0].list[curr->ref_idx[0]] &&
|
|
|
|
neigh_refPicList[0].list[neigh->ref_idx[0]] == s->ref->refPicList[1].list[curr->ref_idx[1]]) {
|
|
|
|
if (abs(neigh->mv[1].x - curr->mv[0].x) >= 4 || abs(neigh->mv[1].y - curr->mv[0].y) >= 4 ||
|
|
|
|
abs(neigh->mv[0].x - curr->mv[1].x) >= 4 || abs(neigh->mv[0].y - curr->mv[1].y) >= 4)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else { // 1 MV
|
|
|
|
Mv A, B;
|
2013-11-02 11:59:02 +01:00
|
|
|
int ref_A, ref_B;
|
2013-10-12 11:55:48 +02:00
|
|
|
|
|
|
|
if (curr->pred_flag[0]) {
|
2013-11-02 00:31:49 +01:00
|
|
|
A = curr->mv[0];
|
2013-10-12 11:55:48 +02:00
|
|
|
ref_A = s->ref->refPicList[0].list[curr->ref_idx[0]];
|
|
|
|
} else {
|
2013-11-02 00:31:49 +01:00
|
|
|
A = curr->mv[1];
|
2013-10-12 11:55:48 +02:00
|
|
|
ref_A = s->ref->refPicList[1].list[curr->ref_idx[1]];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (neigh->pred_flag[0]) {
|
2013-11-02 00:31:49 +01:00
|
|
|
B = neigh->mv[0];
|
2013-10-12 11:55:48 +02:00
|
|
|
ref_B = neigh_refPicList[0].list[neigh->ref_idx[0]];
|
|
|
|
} else {
|
2013-11-02 00:31:49 +01:00
|
|
|
B = neigh->mv[1];
|
2013-10-12 11:55:48 +02:00
|
|
|
ref_B = neigh_refPicList[1].list[neigh->ref_idx[1]];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ref_A == ref_B) {
|
|
|
|
if (abs(A.x - B.x) >= 4 || abs(A.y - B.y) >= 4)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
|
|
|
|
int log2_trafo_size,
|
|
|
|
int slice_or_tiles_up_boundary,
|
|
|
|
int slice_or_tiles_left_boundary)
|
2013-10-12 11:55:48 +02:00
|
|
|
{
|
2013-10-27 12:56:48 +01:00
|
|
|
MvField *tab_mvf = s->ref->tab_mvf;
|
|
|
|
int log2_min_pu_size = s->sps->log2_min_pu_size;
|
|
|
|
int log2_min_tu_size = s->sps->log2_min_tb_size;
|
|
|
|
int min_pu_width = s->sps->min_pu_width;
|
|
|
|
int min_tu_width = s->sps->min_tb_width;
|
2013-11-02 00:31:49 +01:00
|
|
|
int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
|
|
|
|
(x0 >> log2_min_pu_size)].is_intra;
|
2013-11-02 11:59:02 +01:00
|
|
|
int i, j, bs;
|
2013-10-12 11:55:48 +02:00
|
|
|
|
|
|
|
if (y0 > 0 && (y0 & 7) == 0) {
|
|
|
|
int yp_pu = (y0 - 1) >> log2_min_pu_size;
|
2013-11-02 00:31:49 +01:00
|
|
|
int yq_pu = y0 >> log2_min_pu_size;
|
2013-10-12 11:55:48 +02:00
|
|
|
int yp_tu = (y0 - 1) >> log2_min_tu_size;
|
2013-11-02 00:31:49 +01:00
|
|
|
int yq_tu = y0 >> log2_min_tu_size;
|
2013-10-12 11:55:48 +02:00
|
|
|
|
|
|
|
for (i = 0; i < (1 << log2_trafo_size); i += 4) {
|
|
|
|
int x_pu = (x0 + i) >> log2_min_pu_size;
|
|
|
|
int x_tu = (x0 + i) >> log2_min_tu_size;
|
2013-10-27 12:56:48 +01:00
|
|
|
MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
|
|
|
|
MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
|
|
|
|
uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu];
|
|
|
|
uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu];
|
2013-11-02 00:31:49 +01:00
|
|
|
RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref,
|
|
|
|
x0 + i, y0 - 1);
|
|
|
|
|
|
|
|
bs = boundary_strength(s, curr, curr_cbf_luma,
|
|
|
|
top, top_cbf_luma, top_refPicList, 1);
|
|
|
|
if (!s->sh.slice_loop_filter_across_slices_enabled_flag &&
|
|
|
|
(slice_or_tiles_up_boundary & 1) &&
|
|
|
|
(y0 % (1 << s->sps->log2_ctb_size)) == 0)
|
2013-10-12 11:55:48 +02:00
|
|
|
bs = 0;
|
2013-11-02 00:31:49 +01:00
|
|
|
else if (!s->pps->loop_filter_across_tiles_enabled_flag &&
|
|
|
|
(slice_or_tiles_up_boundary & 2) &&
|
|
|
|
(y0 % (1 << s->sps->log2_ctb_size)) == 0)
|
2013-10-12 11:55:48 +02:00
|
|
|
bs = 0;
|
|
|
|
if (y0 == 0 || s->sh.disable_deblocking_filter_flag == 1)
|
|
|
|
bs = 0;
|
|
|
|
if (bs)
|
|
|
|
s->horizontal_bs[((x0 + i) + y0 * s->bs_width) >> 2] = bs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// bs for TU internal horizontal PU boundaries
|
|
|
|
if (log2_trafo_size > s->sps->log2_min_pu_size && !is_intra)
|
|
|
|
for (j = 8; j < (1 << log2_trafo_size); j += 8) {
|
|
|
|
int yp_pu = (y0 + j - 1) >> log2_min_pu_size;
|
|
|
|
int yq_pu = (y0 + j) >> log2_min_pu_size;
|
|
|
|
int yp_tu = (y0 + j - 1) >> log2_min_tu_size;
|
|
|
|
int yq_tu = (y0 + j) >> log2_min_tu_size;
|
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
for (i = 0; i < (1 << log2_trafo_size); i += 4) {
|
2013-10-12 11:55:48 +02:00
|
|
|
int x_pu = (x0 + i) >> log2_min_pu_size;
|
|
|
|
int x_tu = (x0 + i) >> log2_min_tu_size;
|
2013-10-27 12:56:48 +01:00
|
|
|
MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
|
|
|
|
MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
|
|
|
|
uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu];
|
|
|
|
uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu];
|
2013-11-02 00:31:49 +01:00
|
|
|
RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref,
|
|
|
|
x0 + i,
|
|
|
|
y0 + j - 1);
|
2013-10-12 11:55:48 +02:00
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
bs = boundary_strength(s, curr, curr_cbf_luma,
|
|
|
|
top, top_cbf_luma, top_refPicList, 0);
|
2013-10-12 11:55:48 +02:00
|
|
|
if (s->sh.disable_deblocking_filter_flag == 1)
|
|
|
|
bs = 0;
|
|
|
|
if (bs)
|
|
|
|
s->horizontal_bs[((x0 + i) + (y0 + j) * s->bs_width) >> 2] = bs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// bs for vertical TU boundaries
|
|
|
|
if (x0 > 0 && (x0 & 7) == 0) {
|
|
|
|
int xp_pu = (x0 - 1) >> log2_min_pu_size;
|
|
|
|
int xq_pu = x0 >> log2_min_pu_size;
|
|
|
|
int xp_tu = (x0 - 1) >> log2_min_tu_size;
|
|
|
|
int xq_tu = x0 >> log2_min_tu_size;
|
|
|
|
|
|
|
|
for (i = 0; i < (1 << log2_trafo_size); i += 4) {
|
2013-11-02 00:31:49 +01:00
|
|
|
int y_pu = (y0 + i) >> log2_min_pu_size;
|
|
|
|
int y_tu = (y0 + i) >> log2_min_tu_size;
|
2013-10-27 12:56:48 +01:00
|
|
|
MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
|
|
|
|
MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
|
2013-10-12 11:55:48 +02:00
|
|
|
|
2013-10-27 12:56:48 +01:00
|
|
|
uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu];
|
|
|
|
uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu];
|
2013-11-02 00:31:49 +01:00
|
|
|
RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref,
|
|
|
|
x0 - 1, y0 + i);
|
|
|
|
|
|
|
|
bs = boundary_strength(s, curr, curr_cbf_luma,
|
|
|
|
left, left_cbf_luma, left_refPicList, 1);
|
|
|
|
if (!s->sh.slice_loop_filter_across_slices_enabled_flag &&
|
|
|
|
(slice_or_tiles_left_boundary & 1) &&
|
|
|
|
(x0 % (1 << s->sps->log2_ctb_size)) == 0)
|
2013-10-12 11:55:48 +02:00
|
|
|
bs = 0;
|
2013-11-02 00:31:49 +01:00
|
|
|
else if (!s->pps->loop_filter_across_tiles_enabled_flag &&
|
|
|
|
(slice_or_tiles_left_boundary & 2) &&
|
|
|
|
(x0 % (1 << s->sps->log2_ctb_size)) == 0)
|
2013-10-12 11:55:48 +02:00
|
|
|
bs = 0;
|
|
|
|
if (x0 == 0 || s->sh.disable_deblocking_filter_flag == 1)
|
|
|
|
bs = 0;
|
|
|
|
if (bs)
|
|
|
|
s->vertical_bs[(x0 >> 3) + ((y0 + i) >> 2) * s->bs_width] = bs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// bs for TU internal vertical PU boundaries
|
2013-10-11 22:07:00 +02:00
|
|
|
if (log2_trafo_size > log2_min_pu_size && !is_intra)
|
2013-10-12 11:55:48 +02:00
|
|
|
for (j = 0; j < (1 << log2_trafo_size); j += 4) {
|
|
|
|
int y_pu = (y0 + j) >> log2_min_pu_size;
|
|
|
|
int y_tu = (y0 + j) >> log2_min_tu_size;
|
|
|
|
|
|
|
|
for (i = 8; i < (1 << log2_trafo_size); i += 8) {
|
|
|
|
int xp_pu = (x0 + i - 1) >> log2_min_pu_size;
|
2013-11-02 00:31:49 +01:00
|
|
|
int xq_pu = (x0 + i) >> log2_min_pu_size;
|
2013-10-12 11:55:48 +02:00
|
|
|
int xp_tu = (x0 + i - 1) >> log2_min_tu_size;
|
2013-11-02 00:31:49 +01:00
|
|
|
int xq_tu = (x0 + i) >> log2_min_tu_size;
|
2013-10-27 12:56:48 +01:00
|
|
|
MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
|
|
|
|
MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
|
|
|
|
uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu];
|
|
|
|
uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu];
|
2013-11-02 00:31:49 +01:00
|
|
|
RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref,
|
|
|
|
x0 + i - 1,
|
|
|
|
y0 + j);
|
2013-10-12 11:55:48 +02:00
|
|
|
|
2013-11-02 00:31:49 +01:00
|
|
|
bs = boundary_strength(s, curr, curr_cbf_luma,
|
|
|
|
left, left_cbf_luma, left_refPicList, 0);
|
2013-10-12 11:55:48 +02:00
|
|
|
if (s->sh.disable_deblocking_filter_flag == 1)
|
|
|
|
bs = 0;
|
|
|
|
if (bs)
|
|
|
|
s->vertical_bs[((x0 + i) >> 3) + ((y0 + j) >> 2) * s->bs_width] = bs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-02 00:31:49 +01:00
|
|
|
|
2013-10-12 11:55:48 +02:00
|
|
|
#undef LUMA
|
|
|
|
#undef CB
|
|
|
|
#undef CR
|
|
|
|
|
|
|
|
void ff_hevc_hls_filter(HEVCContext *s, int x, int y)
|
|
|
|
{
|
|
|
|
deblocking_filter_CTB(s, x, y);
|
|
|
|
if (s->sps->sao_enabled)
|
2013-10-11 22:07:00 +02:00
|
|
|
sao_filter_CTB(s, x, y);
|
2013-10-12 11:55:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ff_hevc_hls_filters(HEVCContext *s, int x_ctb, int y_ctb, int ctb_size)
|
|
|
|
{
|
|
|
|
if (y_ctb && x_ctb)
|
|
|
|
ff_hevc_hls_filter(s, x_ctb - ctb_size, y_ctb - ctb_size);
|
2013-10-27 16:50:20 +01:00
|
|
|
if (y_ctb && x_ctb >= s->sps->width - ctb_size) {
|
2013-10-12 11:55:48 +02:00
|
|
|
ff_hevc_hls_filter(s, x_ctb, y_ctb - ctb_size);
|
2013-10-27 16:50:20 +01:00
|
|
|
if (s->threads_type == FF_THREAD_FRAME )
|
|
|
|
ff_thread_report_progress(&s->ref->tf, y_ctb - ctb_size, 0);
|
|
|
|
}
|
2013-10-12 11:55:48 +02:00
|
|
|
if (x_ctb && y_ctb >= s->sps->height - ctb_size)
|
|
|
|
ff_hevc_hls_filter(s, x_ctb - ctb_size, y_ctb);
|
|
|
|
}
|