Commit 7a9ad9c8 authored by Debargha Mukherjee's avatar Debargha Mukherjee Committed by Gerrit Code Review
Browse files

Merge "Misc. refactoring of loop restoration" into nextgenv2

parents 8f71e396 5d89a63a
......@@ -85,14 +85,10 @@ void av1_free_ref_frame_buffers(BufferPool *pool) {
void av1_free_restoration_buffers(AV1_COMMON *cm) {
aom_free(cm->rst_info.restoration_type);
cm->rst_info.restoration_type = NULL;
aom_free(cm->rst_info.bilateral_level);
cm->rst_info.bilateral_level = NULL;
aom_free(cm->rst_info.vfilter);
cm->rst_info.vfilter = NULL;
aom_free(cm->rst_info.hfilter);
cm->rst_info.hfilter = NULL;
aom_free(cm->rst_info.wiener_level);
cm->rst_info.wiener_level = NULL;
aom_free(cm->rst_info.bilateral_info);
cm->rst_info.bilateral_info = NULL;
aom_free(cm->rst_info.wiener_info);
cm->rst_info.wiener_info = NULL;
}
#endif // CONFIG_LOOP_RESTORATION
......
......@@ -1655,9 +1655,11 @@ void av1_setup_past_independence(AV1_COMMON *cm) {
// To force update of the sharpness
lf->last_sharpness_level = -1;
#if CONFIG_LOOP_RESTORATION
if (cm->rst_info.bilateral_level) {
if (cm->rst_info.bilateral_info) {
int s;
for (i = 0; i < cm->rst_internal.ntiles; ++i)
cm->rst_info.bilateral_level[i] = -1;
for (s = 0; s < BILATERAL_SUBTILES; ++s)
cm->rst_info.bilateral_info[i].level[s] = -1;
}
#endif // CONFIG_LOOP_RESTORATION
......
......@@ -151,33 +151,35 @@ void av1_loop_restoration_init(RestorationInternal *rst, RestorationInfo *rsi,
&rst->nhtiles, &rst->nvtiles);
if (rsi->frame_restoration_type == RESTORE_WIENER) {
for (tile_idx = 0; tile_idx < rst->ntiles; ++tile_idx) {
rsi->vfilter[tile_idx][RESTORATION_HALFWIN] =
rsi->hfilter[tile_idx][RESTORATION_HALFWIN] = RESTORATION_FILT_STEP;
rsi->wiener_info[tile_idx].vfilter[RESTORATION_HALFWIN] =
rsi->wiener_info[tile_idx].hfilter[RESTORATION_HALFWIN] =
RESTORATION_FILT_STEP;
for (i = 0; i < RESTORATION_HALFWIN; ++i) {
rsi->vfilter[tile_idx][RESTORATION_WIN - 1 - i] =
rsi->vfilter[tile_idx][i];
rsi->hfilter[tile_idx][RESTORATION_WIN - 1 - i] =
rsi->hfilter[tile_idx][i];
rsi->vfilter[tile_idx][RESTORATION_HALFWIN] -=
2 * rsi->vfilter[tile_idx][i];
rsi->hfilter[tile_idx][RESTORATION_HALFWIN] -=
2 * rsi->hfilter[tile_idx][i];
rsi->wiener_info[tile_idx].vfilter[RESTORATION_WIN - 1 - i] =
rsi->wiener_info[tile_idx].vfilter[i];
rsi->wiener_info[tile_idx].hfilter[RESTORATION_WIN - 1 - i] =
rsi->wiener_info[tile_idx].hfilter[i];
rsi->wiener_info[tile_idx].vfilter[RESTORATION_HALFWIN] -=
2 * rsi->wiener_info[tile_idx].vfilter[i];
rsi->wiener_info[tile_idx].hfilter[RESTORATION_HALFWIN] -=
2 * rsi->wiener_info[tile_idx].hfilter[i];
}
}
} else if (rsi->frame_restoration_type == RESTORE_SWITCHABLE) {
for (tile_idx = 0; tile_idx < rst->ntiles; ++tile_idx) {
if (rsi->restoration_type[tile_idx] == RESTORE_WIENER) {
rsi->vfilter[tile_idx][RESTORATION_HALFWIN] =
rsi->hfilter[tile_idx][RESTORATION_HALFWIN] = RESTORATION_FILT_STEP;
rsi->wiener_info[tile_idx].vfilter[RESTORATION_HALFWIN] =
rsi->wiener_info[tile_idx].hfilter[RESTORATION_HALFWIN] =
RESTORATION_FILT_STEP;
for (i = 0; i < RESTORATION_HALFWIN; ++i) {
rsi->vfilter[tile_idx][RESTORATION_WIN - 1 - i] =
rsi->vfilter[tile_idx][i];
rsi->hfilter[tile_idx][RESTORATION_WIN - 1 - i] =
rsi->hfilter[tile_idx][i];
rsi->vfilter[tile_idx][RESTORATION_HALFWIN] -=
2 * rsi->vfilter[tile_idx][i];
rsi->hfilter[tile_idx][RESTORATION_HALFWIN] -=
2 * rsi->hfilter[tile_idx][i];
rsi->wiener_info[tile_idx].vfilter[RESTORATION_WIN - 1 - i] =
rsi->wiener_info[tile_idx].vfilter[i];
rsi->wiener_info[tile_idx].hfilter[RESTORATION_WIN - 1 - i] =
rsi->wiener_info[tile_idx].hfilter[i];
rsi->wiener_info[tile_idx].vfilter[RESTORATION_HALFWIN] -=
2 * rsi->wiener_info[tile_idx].vfilter[i];
rsi->wiener_info[tile_idx].hfilter[RESTORATION_HALFWIN] -=
2 * rsi->wiener_info[tile_idx].hfilter[i];
}
}
}
......@@ -195,8 +197,7 @@ static void loop_bilateral_filter_tile(uint8_t *data, int tile_idx, int width,
for (subtile_idx = 0; subtile_idx < BILATERAL_SUBTILES; ++subtile_idx) {
uint8_t *data_p, *tmpdata_p;
const int level =
rst->rsi->bilateral_level[tile_idx * BILATERAL_SUBTILES + subtile_idx];
const int level = rst->rsi->bilateral_info[tile_idx].level[subtile_idx];
uint8_t(*wx_lut)[RESTORATION_WIN];
uint8_t *wr_lut_;
......@@ -282,7 +283,7 @@ static void loop_wiener_filter_tile(uint8_t *data, int tile_idx, int width,
int h_start, h_end, v_start, v_end;
uint8_t *data_p, *tmpdata_p;
if (rst->rsi->wiener_level[tile_idx] == 0) return;
if (rst->rsi->wiener_info[tile_idx].level == 0) return;
// Filter row-wise
av1_get_rest_tile_limits(tile_idx, 0, 0, rst->nhtiles, rst->nvtiles,
tile_width, tile_height, width, height, 1, 0,
......@@ -291,7 +292,8 @@ static void loop_wiener_filter_tile(uint8_t *data, int tile_idx, int width,
tmpdata_p = tmpdata + h_start + v_start * tmpstride;
for (i = 0; i < (v_end - v_start); ++i) {
for (j = 0; j < (h_end - h_start); ++j) {
*tmpdata_p++ = hor_sym_filter(data_p++, rst->rsi->hfilter[tile_idx]);
*tmpdata_p++ =
hor_sym_filter(data_p++, rst->rsi->wiener_info[tile_idx].hfilter);
}
data_p += stride - (h_end - h_start);
tmpdata_p += tmpstride - (h_end - h_start);
......@@ -304,8 +306,8 @@ static void loop_wiener_filter_tile(uint8_t *data, int tile_idx, int width,
tmpdata_p = tmpdata + h_start + v_start * tmpstride;
for (i = 0; i < (v_end - v_start); ++i) {
for (j = 0; j < (h_end - h_start); ++j) {
*data_p++ =
ver_sym_filter(tmpdata_p++, tmpstride, rst->rsi->vfilter[tile_idx]);
*data_p++ = ver_sym_filter(tmpdata_p++, tmpstride,
rst->rsi->wiener_info[tile_idx].vfilter);
}
data_p += stride - (h_end - h_start);
tmpdata_p += tmpstride - (h_end - h_start);
......@@ -370,8 +372,7 @@ static void loop_bilateral_filter_tile_highbd(uint16_t *data, int tile_idx,
for (subtile_idx = 0; subtile_idx < BILATERAL_SUBTILES; ++subtile_idx) {
uint16_t *data_p, *tmpdata_p;
const int level =
rst->rsi->bilateral_level[tile_idx * BILATERAL_SUBTILES + subtile_idx];
const int level = rst->rsi->bilateral_info[tile_idx].level[subtile_idx];
uint8_t(*wx_lut)[RESTORATION_WIN];
uint8_t *wr_lut_;
......@@ -462,7 +463,7 @@ static void loop_wiener_filter_tile_highbd(uint16_t *data, int tile_idx,
int i, j;
uint16_t *data_p, *tmpdata_p;
if (rst->rsi->wiener_level[tile_idx] == 0) return;
if (rst->rsi->wiener_info[tile_idx].level == 0) return;
// Filter row-wise
av1_get_rest_tile_limits(tile_idx, 0, 0, rst->nhtiles, rst->nvtiles,
tile_width, tile_height, width, height, 1, 0,
......@@ -472,7 +473,7 @@ static void loop_wiener_filter_tile_highbd(uint16_t *data, int tile_idx,
for (i = 0; i < (v_end - v_start); ++i) {
for (j = 0; j < (h_end - h_start); ++j) {
*tmpdata_p++ = hor_sym_filter_highbd(
data_p++, rst->rsi->hfilter[tile_idx], bit_depth);
data_p++, rst->rsi->wiener_info[tile_idx].hfilter, bit_depth);
}
data_p += stride - (h_end - h_start);
tmpdata_p += tmpstride - (h_end - h_start);
......@@ -486,7 +487,8 @@ static void loop_wiener_filter_tile_highbd(uint16_t *data, int tile_idx,
for (i = 0; i < (v_end - v_start); ++i) {
for (j = 0; j < (h_end - h_start); ++j) {
*data_p++ = ver_sym_filter_highbd(tmpdata_p++, tmpstride,
rst->rsi->vfilter[tile_idx], bit_depth);
rst->rsi->wiener_info[tile_idx].vfilter,
bit_depth);
}
data_p += stride - (h_end - h_start);
tmpdata_p += tmpstride - (h_end - h_start);
......
......@@ -57,14 +57,20 @@ extern "C" {
#define WIENER_FILT_TAP2_MAXV \
(WIENER_FILT_TAP2_MINV - 1 + (1 << WIENER_FILT_TAP2_BITS))
typedef struct { int level[BILATERAL_SUBTILES]; } BilateralInfo;
typedef struct {
int level;
int vfilter[RESTORATION_WIN], hfilter[RESTORATION_WIN];
} WienerInfo;
typedef struct {
RestorationType frame_restoration_type;
RestorationType *restoration_type;
// Bilateral filter
int *bilateral_level;
BilateralInfo *bilateral_info;
// Wiener filter
int *wiener_level;
int (*vfilter)[RESTORATION_WIN], (*hfilter)[RESTORATION_WIN];
WienerInfo *wiener_info;
} RestorationInfo;
typedef struct {
......
......@@ -1920,101 +1920,96 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) {
rsi->restoration_type = (RestorationType *)aom_realloc(
rsi->restoration_type, sizeof(*rsi->restoration_type) * ntiles);
if (rsi->frame_restoration_type == RESTORE_SWITCHABLE) {
rsi->bilateral_level = (int *)aom_realloc(
rsi->bilateral_level,
sizeof(*rsi->bilateral_level) * ntiles * BILATERAL_SUBTILES);
assert(rsi->bilateral_level != NULL);
rsi->wiener_level = (int *)aom_realloc(
rsi->wiener_level, sizeof(*rsi->wiener_level) * ntiles);
assert(rsi->wiener_level != NULL);
rsi->vfilter = (int(*)[RESTORATION_WIN])aom_realloc(
rsi->vfilter, sizeof(*rsi->vfilter) * ntiles);
assert(rsi->vfilter != NULL);
rsi->hfilter = (int(*)[RESTORATION_WIN])aom_realloc(
rsi->hfilter, sizeof(*rsi->hfilter) * ntiles);
assert(rsi->hfilter != NULL);
rsi->bilateral_info = (BilateralInfo *)aom_realloc(
rsi->bilateral_info, sizeof(*rsi->bilateral_info) * ntiles);
assert(rsi->bilateral_info != NULL);
rsi->wiener_info = (WienerInfo *)aom_realloc(
rsi->wiener_info, sizeof(*rsi->wiener_info) * ntiles);
assert(rsi->wiener_info != NULL);
for (i = 0; i < ntiles; ++i) {
rsi->restoration_type[i] = aom_read_tree(
rb, av1_switchable_restore_tree, cm->fc->switchable_restore_prob);
if (rsi->restoration_type[i] == RESTORE_WIENER) {
rsi->wiener_level[i] = 1;
rsi->vfilter[i][0] = aom_read_literal(rb, WIENER_FILT_TAP0_BITS) +
rsi->wiener_info[i].level = 1;
rsi->wiener_info[i].vfilter[0] =
aom_read_literal(rb, WIENER_FILT_TAP0_BITS) +
WIENER_FILT_TAP0_MINV;
rsi->vfilter[i][1] = aom_read_literal(rb, WIENER_FILT_TAP1_BITS) +
rsi->wiener_info[i].vfilter[1] =
aom_read_literal(rb, WIENER_FILT_TAP1_BITS) +
WIENER_FILT_TAP1_MINV;
rsi->vfilter[i][2] = aom_read_literal(rb, WIENER_FILT_TAP2_BITS) +
rsi->wiener_info[i].vfilter[2] =
aom_read_literal(rb, WIENER_FILT_TAP2_BITS) +
WIENER_FILT_TAP2_MINV;
rsi->hfilter[i][0] = aom_read_literal(rb, WIENER_FILT_TAP0_BITS) +
rsi->wiener_info[i].hfilter[0] =
aom_read_literal(rb, WIENER_FILT_TAP0_BITS) +
WIENER_FILT_TAP0_MINV;
rsi->hfilter[i][1] = aom_read_literal(rb, WIENER_FILT_TAP1_BITS) +
rsi->wiener_info[i].hfilter[1] =
aom_read_literal(rb, WIENER_FILT_TAP1_BITS) +
WIENER_FILT_TAP1_MINV;
rsi->hfilter[i][2] = aom_read_literal(rb, WIENER_FILT_TAP2_BITS) +
rsi->wiener_info[i].hfilter[2] =
aom_read_literal(rb, WIENER_FILT_TAP2_BITS) +
WIENER_FILT_TAP2_MINV;
} else if (rsi->restoration_type[i] == RESTORE_BILATERAL) {
int s;
for (s = 0; s < BILATERAL_SUBTILES; ++s) {
const int j = i * BILATERAL_SUBTILES + s;
#if BILATERAL_SUBTILES == 0
rsi->bilateral_level[j] =
rsi->bilateral_info[i].level[s] =
aom_read_literal(rb, av1_bilateral_level_bits(cm));
#else
if (aom_read(rb, RESTORE_NONE_BILATERAL_PROB)) {
rsi->bilateral_level[j] =
rsi->bilateral_info[i].level[s] =
aom_read_literal(rb, av1_bilateral_level_bits(cm));
} else {
rsi->bilateral_level[j] = -1;
rsi->bilateral_info[i].level[s] = -1;
}
#endif
}
}
}
} else if (rsi->frame_restoration_type == RESTORE_WIENER) {
rsi->wiener_level = (int *)aom_realloc(
rsi->wiener_level, sizeof(*rsi->wiener_level) * ntiles);
assert(rsi->wiener_level != NULL);
rsi->vfilter = (int(*)[RESTORATION_WIN])aom_realloc(
rsi->vfilter, sizeof(*rsi->vfilter) * ntiles);
assert(rsi->vfilter != NULL);
rsi->hfilter = (int(*)[RESTORATION_WIN])aom_realloc(
rsi->hfilter, sizeof(*rsi->hfilter) * ntiles);
assert(rsi->hfilter != NULL);
rsi->wiener_info = (WienerInfo *)aom_realloc(
rsi->wiener_info, sizeof(*rsi->wiener_info) * ntiles);
assert(rsi->wiener_info != NULL);
for (i = 0; i < ntiles; ++i) {
if (aom_read(rb, RESTORE_NONE_WIENER_PROB)) {
rsi->wiener_level[i] = 1;
rsi->wiener_info[i].level = 1;
rsi->restoration_type[i] = RESTORE_WIENER;
rsi->vfilter[i][0] = aom_read_literal(rb, WIENER_FILT_TAP0_BITS) +
rsi->wiener_info[i].vfilter[0] =
aom_read_literal(rb, WIENER_FILT_TAP0_BITS) +
WIENER_FILT_TAP0_MINV;
rsi->vfilter[i][1] = aom_read_literal(rb, WIENER_FILT_TAP1_BITS) +
rsi->wiener_info[i].vfilter[1] =
aom_read_literal(rb, WIENER_FILT_TAP1_BITS) +
WIENER_FILT_TAP1_MINV;
rsi->vfilter[i][2] = aom_read_literal(rb, WIENER_FILT_TAP2_BITS) +
rsi->wiener_info[i].vfilter[2] =
aom_read_literal(rb, WIENER_FILT_TAP2_BITS) +
WIENER_FILT_TAP2_MINV;
rsi->hfilter[i][0] = aom_read_literal(rb, WIENER_FILT_TAP0_BITS) +
rsi->wiener_info[i].hfilter[0] =
aom_read_literal(rb, WIENER_FILT_TAP0_BITS) +
WIENER_FILT_TAP0_MINV;
rsi->hfilter[i][1] = aom_read_literal(rb, WIENER_FILT_TAP1_BITS) +
rsi->wiener_info[i].hfilter[1] =
aom_read_literal(rb, WIENER_FILT_TAP1_BITS) +
WIENER_FILT_TAP1_MINV;
rsi->hfilter[i][2] = aom_read_literal(rb, WIENER_FILT_TAP2_BITS) +
rsi->wiener_info[i].hfilter[2] =
aom_read_literal(rb, WIENER_FILT_TAP2_BITS) +
WIENER_FILT_TAP2_MINV;
} else {
rsi->wiener_level[i] = 0;
rsi->wiener_info[i].level = 0;
rsi->restoration_type[i] = RESTORE_NONE;
}
}
} else {
rsi->frame_restoration_type = RESTORE_BILATERAL;
rsi->bilateral_level = (int *)aom_realloc(
rsi->bilateral_level,
sizeof(*rsi->bilateral_level) * ntiles * BILATERAL_SUBTILES);
assert(rsi->bilateral_level != NULL);
rsi->bilateral_info = (BilateralInfo *)aom_realloc(
rsi->bilateral_info, sizeof(*rsi->bilateral_info) * ntiles);
assert(rsi->bilateral_info != NULL);
for (i = 0; i < ntiles; ++i) {
int s;
rsi->restoration_type[i] = RESTORE_BILATERAL;
for (s = 0; s < BILATERAL_SUBTILES; ++s) {
const int j = i * BILATERAL_SUBTILES + s;
if (aom_read(rb, RESTORE_NONE_BILATERAL_PROB)) {
rsi->bilateral_level[j] =
rsi->bilateral_info[i].level[s] =
aom_read_literal(rb, av1_bilateral_level_bits(cm));
} else {
rsi->bilateral_level[j] = -1;
rsi->bilateral_info[i].level[s] = -1;
}
}
}
......
......@@ -2455,74 +2455,83 @@ static void encode_restoration_mode(AV1_COMMON *cm,
static void encode_restoration(AV1_COMMON *cm, aom_writer *wb) {
int i;
RestorationInfo *rst = &cm->rst_info;
if (rst->frame_restoration_type != RESTORE_NONE) {
if (rst->frame_restoration_type == RESTORE_SWITCHABLE) {
RestorationInfo *rsi = &cm->rst_info;
if (rsi->frame_restoration_type != RESTORE_NONE) {
if (rsi->frame_restoration_type == RESTORE_SWITCHABLE) {
// RESTORE_SWITCHABLE
for (i = 0; i < cm->rst_internal.ntiles; ++i) {
av1_write_token(
wb, av1_switchable_restore_tree, cm->fc->switchable_restore_prob,
&switchable_restore_encodings[rst->restoration_type[i]]);
if (rst->restoration_type[i] == RESTORE_NONE) {
} else if (rst->restoration_type[i] == RESTORE_BILATERAL) {
&switchable_restore_encodings[rsi->restoration_type[i]]);
if (rsi->restoration_type[i] == RESTORE_BILATERAL) {
int s;
for (s = 0; s < BILATERAL_SUBTILES; ++s) {
const int j = i * BILATERAL_SUBTILES + s;
#if BILATERAL_SUBTILES == 0
aom_write_literal(wb, rst->bilateral_level[j],
aom_write_literal(wb, rsi->bilateral_info[i].level[s],
av1_bilateral_level_bits(cm));
#else
aom_write(wb, rst->bilateral_level[j] >= 0,
aom_write(wb, rsi->bilateral_info[i].level[s] >= 0,
RESTORE_NONE_BILATERAL_PROB);
if (rst->bilateral_level[j] >= 0) {
aom_write_literal(wb, rst->bilateral_level[j],
if (rsi->bilateral_info[i].level[s] >= 0) {
aom_write_literal(wb, rsi->bilateral_info[i].level[s],
av1_bilateral_level_bits(cm));
}
#endif
}
} else {
aom_write_literal(wb, rst->vfilter[i][0] - WIENER_FILT_TAP0_MINV,
} else if (rsi->restoration_type[i] == RESTORE_WIENER) {
aom_write_literal(
wb, rsi->wiener_info[i].vfilter[0] - WIENER_FILT_TAP0_MINV,
WIENER_FILT_TAP0_BITS);
aom_write_literal(wb, rst->vfilter[i][1] - WIENER_FILT_TAP1_MINV,
aom_write_literal(
wb, rsi->wiener_info[i].vfilter[1] - WIENER_FILT_TAP1_MINV,
WIENER_FILT_TAP1_BITS);
aom_write_literal(wb, rst->vfilter[i][2] - WIENER_FILT_TAP2_MINV,
aom_write_literal(
wb, rsi->wiener_info[i].vfilter[2] - WIENER_FILT_TAP2_MINV,
WIENER_FILT_TAP2_BITS);
aom_write_literal(wb, rst->hfilter[i][0] - WIENER_FILT_TAP0_MINV,
aom_write_literal(
wb, rsi->wiener_info[i].hfilter[0] - WIENER_FILT_TAP0_MINV,
WIENER_FILT_TAP0_BITS);
aom_write_literal(wb, rst->hfilter[i][1] - WIENER_FILT_TAP1_MINV,
aom_write_literal(
wb, rsi->wiener_info[i].hfilter[1] - WIENER_FILT_TAP1_MINV,
WIENER_FILT_TAP1_BITS);
aom_write_literal(wb, rst->hfilter[i][2] - WIENER_FILT_TAP2_MINV,
aom_write_literal(
wb, rsi->wiener_info[i].hfilter[2] - WIENER_FILT_TAP2_MINV,
WIENER_FILT_TAP2_BITS);
}
}
} else if (rst->frame_restoration_type == RESTORE_BILATERAL) {
} else if (rsi->frame_restoration_type == RESTORE_BILATERAL) {
for (i = 0; i < cm->rst_internal.ntiles; ++i) {
int s;
for (s = 0; s < BILATERAL_SUBTILES; ++s) {
const int j = i * BILATERAL_SUBTILES + s;
aom_write(wb, rst->bilateral_level[j] >= 0,
aom_write(wb, rsi->bilateral_info[i].level[s] >= 0,
RESTORE_NONE_BILATERAL_PROB);
if (rst->bilateral_level[j] >= 0) {
aom_write_literal(wb, rst->bilateral_level[j],
if (rsi->bilateral_info[i].level[s] >= 0) {
aom_write_literal(wb, rsi->bilateral_info[i].level[s],
av1_bilateral_level_bits(cm));
}
}
}
} else if (rst->frame_restoration_type == RESTORE_WIENER) {
} else if (rsi->frame_restoration_type == RESTORE_WIENER) {
for (i = 0; i < cm->rst_internal.ntiles; ++i) {
aom_write(wb, rst->wiener_level[i] != 0, RESTORE_NONE_WIENER_PROB);
if (rst->wiener_level[i]) {
aom_write_literal(wb, rst->vfilter[i][0] - WIENER_FILT_TAP0_MINV,
aom_write(wb, rsi->wiener_info[i].level != 0, RESTORE_NONE_WIENER_PROB);
if (rsi->wiener_info[i].level) {
aom_write_literal(
wb, rsi->wiener_info[i].vfilter[0] - WIENER_FILT_TAP0_MINV,
WIENER_FILT_TAP0_BITS);
aom_write_literal(wb, rst->vfilter[i][1] - WIENER_FILT_TAP1_MINV,
aom_write_literal(
wb, rsi->wiener_info[i].vfilter[1] - WIENER_FILT_TAP1_MINV,
WIENER_FILT_TAP1_BITS);
aom_write_literal(wb, rst->vfilter[i][2] - WIENER_FILT_TAP2_MINV,
aom_write_literal(
wb, rsi->wiener_info[i].vfilter[2] - WIENER_FILT_TAP2_MINV,
WIENER_FILT_TAP2_BITS);
aom_write_literal(wb, rst->hfilter[i][0] - WIENER_FILT_TAP0_MINV,
aom_write_literal(
wb, rsi->wiener_info[i].hfilter[0] - WIENER_FILT_TAP0_MINV,
WIENER_FILT_TAP0_BITS);
aom_write_literal(wb, rst->hfilter[i][1] - WIENER_FILT_TAP1_MINV,
aom_write_literal(
wb, rsi->wiener_info[i].hfilter[1] - WIENER_FILT_TAP1_MINV,
WIENER_FILT_TAP1_BITS);
aom_write_literal(wb, rst->hfilter[i][2] - WIENER_FILT_TAP2_MINV,
aom_write_literal(
wb, rsi->wiener_info[i].hfilter[2] - WIENER_FILT_TAP2_MINV,
WIENER_FILT_TAP2_BITS);
}
}
......
......@@ -28,6 +28,11 @@
#include "av1/encoder/pickrst.h"
#include "av1/encoder/quantize.h"
typedef double (*search_restore_type)(const YV12_BUFFER_CONFIG *src,
AV1_COMP *cpi, int filter_level,
int partial_frame, RestorationInfo *info,
double *best_tile_cost);
const int frame_level_restore_bits[RESTORE_TYPES] = { 2, 2, 2, 2 };
static int64_t sse_restoration_tile(const YV12_BUFFER_CONFIG *src,
......@@ -95,16 +100,15 @@ static int64_t try_restoration_frame(const YV12_BUFFER_CONFIG *src,
return filt_err;
}
static int search_bilateral_level(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi,
static double search_bilateral(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi,
int filter_level, int partial_frame,
int *bilateral_level, double *best_cost_ret,
double *best_tile_cost) {
RestorationInfo *info, double *best_tile_cost) {
BilateralInfo *bilateral_info = info->bilateral_info;
AV1_COMMON *const cm = &cpi->common;
int i, j, tile_idx;
int i, tile_idx, subtile_idx;
int64_t err;
int bits;
double cost, best_cost, cost_norestore, cost_bilateral,
cost_norestore_subtile;
double cost, best_cost, cost_bilateral, cost_norestore_subtile;
const int bilateral_level_bits = av1_bilateral_level_bits(&cpi->common);
const int bilateral_levels = 1 << bilateral_level_bits;
MACROBLOCK *x = &cpi->td.mb;
......@@ -120,29 +124,19 @@ static int search_bilateral_level(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi,
1, partial_frame);
aom_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_db);
// RD cost associated with no restoration
rsi.frame_restoration_type = RESTORE_NONE;
err = try_restoration_frame(src, cpi, &rsi, partial_frame);
// err = sse_restoration_tile(src, cm, 0, cm->width, 0, cm->height);
bits = frame_level_restore_bits[rsi.frame_restoration_type]
<< AV1_PROB_COST_SHIFT;
cost_norestore = RDCOST_DBL(x->rdmult, x->rddiv, (bits >> 4), err);
// RD cost associated with bilateral filtering
rsi.frame_restoration_type = RESTORE_BILATERAL;
rsi.bilateral_level = (int *)aom_malloc(sizeof(*rsi.bilateral_level) *
ntiles * BILATERAL_SUBTILES);
assert(rsi.bilateral_level != NULL);
rsi.bilateral_info =
(BilateralInfo *)aom_malloc(sizeof(*rsi.bilateral_info) * ntiles);
assert(rsi.bilateral_info != NULL);
for (j = 0; j < ntiles * BILATERAL_SUBTILES; ++j) bilateral_level[j] = -1;
for (tile_idx = 0; tile_idx < ntiles; ++tile_idx)
for (subtile_idx = 0; subtile_idx < BILATERAL_SUBTILES; ++subtile_idx)
bilateral_info[tile_idx].level[subtile_idx] =
rsi.bilateral_info[tile_idx].level[subtile_idx] = -1;
// TODO(debargha): This is a pretty inefficient way to find the best
// parameters per tile. Needs fixing.
// Find best filter for each tile
for (tile_idx = 0; tile_idx < ntiles; ++tile_idx) {
int subtile_idx;
for (subtile_idx = 0; subtile_idx < BILATERAL_SUBTILES; ++subtile_idx) {
const int fulltile_idx = tile_idx * BILATERAL_SUBTILES + subtile_idx;
av1_get_rest_tile_limits(tile_idx, subtile_idx, BILATERAL_SUBTILE_BITS,
nhtiles, nvtiles, tile_width, tile_height,
cm->width, cm->height, 0, 0, &h_start, &h_end,
......@@ -158,34 +152,31 @@ static int search_bilateral_level(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi,
cost_norestore_subtile =
RDCOST_DBL(x->rdmult, x->rddiv, (bits >> 4), err);
best_cost = cost_norestore_subtile;
for (j = 0; j < ntiles * BILATERAL_SUBTILES; ++j)
rsi.bilateral_level[j] = -1;
for (i = 0; i < bilateral_levels; ++i) {
rsi.bilateral_level[fulltile_idx] = i;
rsi.bilateral_info[tile_idx].level[subtile_idx] = i;
err = try_restoration_tile(src, cpi, &rsi, partial_frame, tile_idx,
subtile_idx, BILATERAL_SUBTILE_BITS);
bits = bilateral_level_bits << AV1_PROB_COST_SHIFT;
bits += av1_cost_bit(RESTORE_NONE_BILATERAL_PROB, 1);
cost = RDCOST_DBL(x->rdmult, x->rddiv, (bits >> 4), err);
if (cost < best_cost) {
bilateral_level[fulltile_idx] = i;
bilateral_info[tile_idx].level[subtile_idx] = i;
best_cost = cost;
}
rsi.bilateral_info[tile_idx].level[subtile_idx] = -1;
}
}
if (best_tile_cost) {
bits = 0;
for (j = 0; j < ntiles * BILATERAL_SUBTILES; ++j)
rsi.bilateral_level[j] = -1;
for (subtile_idx = 0; subtile_idx < BILATERAL_SUBTILES; ++subtile_idx) {
const int fulltile_idx = tile_idx * BILATERAL_SUBTILES + subtile_idx;
rsi.bilateral_level[fulltile_idx] = bilateral_level[fulltile_idx];
if (rsi.bilateral_level[fulltile_idx] >= 0)
rsi.bilateral_info[tile_idx].level[subtile_idx] =
bilateral_info[tile_idx].level[subtile_idx];
if (rsi.bilateral_info[tile_idx].level[subtile_idx] >= 0)
bits += bilateral_level_bits << AV1_PROB_COST_SHIFT;
#if BILATERAL_SUBTILES
bits += av1_cost_bit(RESTORE_NONE_BILATERAL_PROB,
rsi.bilateral_level[fulltile_idx] >= 0);
bits +=
av1_cost_bit(RESTORE_NONE_BILATERAL_PROB,
rsi.bilateral_info[tile_idx].level[subtile_idx] >= 0);
#endif
}
err = try_restoration_tile(src, cpi, &rsi, partial_frame, tile_idx, 0, 0);
......@@ -193,146 +184,30 @@ static int search_bilateral_level(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi,
x->rdmult, x->rddiv,
(bits + cpi->switchable_restore_cost[RESTORE_BILATERAL]) >> 4, err);