Commit fa0506e4 authored by Mickaël Raulet's avatar Mickaël Raulet Committed by Michael Niedermayer

hevc/rext: update boundary strength for chroma deblocking filter

cherry picked from commit 7d05c95ac5a63d7675bf645e74b4cf1fffff4796
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 4ec1cb24
......@@ -89,8 +89,8 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
int ctb_count = sps->ctb_width * sps->ctb_height;
int min_pu_size = sps->min_pu_width * sps->min_pu_height;
s->bs_width = width >> 3;
s->bs_height = height >> 3;
s->bs_width = (width >> 2) + 1;
s->bs_height = (height >> 2) + 1;
s->sao = av_mallocz_array(ctb_count, sizeof(*s->sao));
s->deblock = av_mallocz_array(ctb_count, sizeof(*s->deblock));
......@@ -104,7 +104,7 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
s->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);
s->tab_ipm = av_mallocz(min_pu_size);
s->is_pcm = av_malloc(min_pu_size);
s->is_pcm = av_malloc((sps->min_pu_width + 1) * (sps->min_pu_height + 1));
if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm)
goto fail;
......@@ -116,8 +116,8 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address)
goto fail;
s->horizontal_bs = av_mallocz_array(2 * s->bs_width, (s->bs_height + 1));
s->vertical_bs = av_mallocz_array(2 * s->bs_width, (s->bs_height + 1));
s->horizontal_bs = av_mallocz_array(s->bs_width, s->bs_height);
s->vertical_bs = av_mallocz_array(s->bs_width, s->bs_height);
if (!s->horizontal_bs || !s->vertical_bs)
goto fail;
......@@ -2584,10 +2584,10 @@ static int hevc_frame_start(HEVCContext *s)
((s->sps->height >> s->sps->log2_min_cb_size) + 1);
int ret;
memset(s->horizontal_bs, 0, 2 * s->bs_width * (s->bs_height + 1));
memset(s->vertical_bs, 0, 2 * s->bs_width * (s->bs_height + 1));
memset(s->horizontal_bs, 0, s->bs_width * s->bs_height);
memset(s->vertical_bs, 0, s->bs_width * s->bs_height);
memset(s->cbf_luma, 0, s->sps->min_tb_width * s->sps->min_tb_height);
memset(s->is_pcm, 0, s->sps->min_pu_width * s->sps->min_pu_height);
memset(s->is_pcm, 0, (s->sps->min_pu_width + 1) * (s->sps->min_pu_height + 1));
memset(s->tab_slice_address, -1, pic_size_in_ctb * sizeof(*s->tab_slice_address));
s->is_decoded = 0;
......
......@@ -345,7 +345,7 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
uint8_t no_q[2] = { 0 };
int log2_ctb_size = s->sps->log2_ctb_size;
int x_end, y_end;
int x_end, x_end2, y_end;
int ctb_size = 1 << log2_ctb_size;
int ctb = (x0 >> log2_ctb_size) +
(y0 >> log2_ctb_size) * s->sps->ctb_width;
......@@ -378,8 +378,8 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
// 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];
const int bs0 = s->vertical_bs[(x + y * s->bs_width) >> 2];
const int bs1 = s->vertical_bs[(x + (y + 4) * s->bs_width) >> 2];
if (bs0 || bs1) {
const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1;
const int qp1 = (get_qPy(s, x - 1, y + 4) + get_qPy(s, x, y + 4) + 1) >> 1;
......@@ -411,8 +411,8 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
int v = 1 << s->sps->vshift[chroma];
for (y = y0; y < y_end; y += (8 * v)) {
for (x = x0 ? x0 : 8 * h; x < x_end; x += (8 * h)) {
const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width];
const int bs1 = s->vertical_bs[(x >> 3) + ((y + (4 * v)) >> 2) * s->bs_width];
const int bs0 = s->vertical_bs[(x + y * s->bs_width) >> 2];
const int bs1 = s->vertical_bs[(x + (y + (4 * v)) * s->bs_width) >> 2];
if ((bs0 == 2) || (bs1 == 2)) {
const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1;
......@@ -439,12 +439,13 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
}
// horizontal filtering luma
x_end2 = x_end;
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];
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;
......@@ -477,27 +478,17 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
for (chroma = 1; chroma <= 2; chroma++) {
int h = 1 << s->sps->hshift[chroma];
int v = 1 << s->sps->vshift[chroma];
for (y = y0 ? y0 : 8 * v; y < y_end; y += (8 * v)) {
for (x = x0 - 8; x < x_end; x += (8 * h)) {
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 + (4 * h) + y * s->bs_width) >> 2];
} else if (x >= x_end - 4 * h) {
bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
bs1 = 0;
} else {
bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
bs1 = s->horizontal_bs[(x + (4 * h) + y * s->bs_width) >> 2];
}
if (x_end2 != s->sps->width)
x_end = x_end2 - 8 * h;
for (y = y0 ? y0 : 8 * v; y < y_end; y += (8 * v)) {
tc_offset = x0 ? left_tc_offset : cur_tc_offset;
for (x = x0 ? x0 - 8 * h : 0; x < x_end; x += (8 * h)) {
const int bs0 = s->horizontal_bs[( x + y * s->bs_width) >> 2];
const int bs1 = s->horizontal_bs[((x + 4 * h) + y * s->bs_width) >> 2];
if ((bs0 == 2) || (bs1 == 2)) {
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 + (4 * h), y - 1) + get_qPy(s, x + (4 * h), y) + 1) >> 1 : 0;
tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
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 >> s->sps->vshift[1]) * s->frame->linesize[chroma] + ((x >> s->sps->hshift[1]) << s->sps->pixel_shift)];
......@@ -658,7 +649,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
bs = 1;
else
bs = boundary_strength(s, curr, left, left_refPicList);
s->vertical_bs[(x0 >> 3) + ((y0 + i) >> 2) * s->bs_width] = bs;
s->vertical_bs[(x0 + (y0 + i) * s->bs_width) >> 2] = bs;
}
}
}
......@@ -693,7 +684,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
bs = boundary_strength(s, curr, left, refPicList);
s->vertical_bs[((x0 + i) >> 3) + ((y0 + j) >> 2) * s->bs_width] = bs;
s->vertical_bs[((x0 + i) + (y0 + j) * s->bs_width) >> 2] = bs;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment