Commit 5b401364 authored by Rupert Swarbrick's avatar Rupert Swarbrick

Refactor border treatment in loop restoration

Previously we were calling aom_extend_frame_borders to generate
extended pixels for use in loop-restoration. This generates quite a
large border, when we only need 3 pixels.

In addition, we were also calling extend_frame, which does the same
thing but with a smaller border, once (in the decoder) or multiple
times (in the encoder) per plane.

This patch tidies all of this up so that we only call extend_frame
once per plane, with the largest border size we need (3px).

It also adds two new #defines. RESTORATION_BORDER is the 3 pixel
border needed to do filtering for a processing
unit. RESTORATION_CTX_VERT is the number of rows saved for each stripe
when doing striped loop restoration.

Change-Id: I2c3ffcc19808f79db195f76d857e2f23da5d8a84
parent 8b68e100
......@@ -156,7 +156,7 @@ void av1_alloc_restoration_buffers(AV1_COMMON *cm) {
int stride = ALIGN_POWER_OF_TWO(w + 2 * RESTORATION_EXTRA_HORZ, align_bits);
int num_stripes = (height + 63) / 64;
// for each processing stripe: 2 lines above, 2 below
int buf_size = num_stripes * 2 * stride;
int buf_size = num_stripes * RESTORATION_CTX_VERT * stride;
uint8_t *above_buf, *below_buf;
RestorationStripeBoundaries *boundaries = &cm->rst_info[p].boundaries;
......
This diff is collapsed.
......@@ -61,7 +61,14 @@ extern "C" {
#define RESTORATION_BORDER_HORZ (WIENER_BORDER_HORZ)
#endif // SGRPROJ_BORDER_VERT >= WIENER_BORDER_VERT
// How many border pixels do we need for each processing unit?
#define RESTORATION_BORDER 3
#if CONFIG_STRIPED_LOOP_RESTORATION
// How many rows of deblocked pixels do we save above/below each processing
// stripe?
#define RESTORATION_CTX_VERT 2
// Additional pixels to the left and right in above/below buffers
// It is RESTORATION_BORDER_HORZ rounded up to get nicer buffer alignment
#define RESTORATION_EXTRA_HORZ 4
......@@ -221,8 +228,8 @@ typedef struct {
typedef struct {
// Temporary buffers to save/restore 3 lines above/below the restoration
// stripe.
uint16_t tmp_save_above[3][RESTORATION_LINEBUFFER_WIDTH];
uint16_t tmp_save_below[3][RESTORATION_LINEBUFFER_WIDTH];
uint16_t tmp_save_above[RESTORATION_BORDER][RESTORATION_LINEBUFFER_WIDTH];
uint16_t tmp_save_below[RESTORATION_BORDER][RESTORATION_LINEBUFFER_WIDTH];
} RestorationLineBuffers;
typedef struct {
......
......@@ -3852,7 +3852,6 @@ void av1_decode_tg_tiles_and_wrapup(AV1Decoder *pbi, const uint8_t *data,
if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
aom_extend_frame_borders((YV12_BUFFER_CONFIG *)xd->cur_buf);
av1_loop_restoration_filter_frame((YV12_BUFFER_CONFIG *)xd->cur_buf, cm,
cm->rst_info, 7, NULL);
}
......
......@@ -4649,7 +4649,6 @@ static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) {
#endif // CONFIG_FRAME_SUPERRES
#if CONFIG_LOOP_RESTORATION
aom_extend_frame_borders(cm->frame_to_show);
av1_pick_filter_restoration(cpi->source, cpi);
if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
......
......@@ -1137,20 +1137,6 @@ static double search_rest_type(RestSearchCtxt *rsc, RestorationType rtype) {
static const rest_unit_visitor_t funs[RESTORE_TYPES] = {
search_norestore, search_wiener, search_sgrproj, search_switchable
};
static const int hborders[RESTORE_TYPES] = { 0, WIENER_HALFWIN,
SGRPROJ_BORDER_HORZ, 0 };
static const int vborders[RESTORE_TYPES] = { 0, WIENER_HALFWIN,
SGRPROJ_BORDER_VERT, 0 };
if (hborders[rtype] || vborders[rtype]) {
#if CONFIG_HIGHBITDEPTH
const int highbd = rsc->cm->use_highbitdepth;
#else
const int highbd = 0;
#endif
extend_frame(rsc->dgd_buffer, rsc->plane_width, rsc->plane_height,
rsc->dgd_stride, hborders[rtype], vborders[rtype], highbd);
}
reset_rsc(rsc);
av1_foreach_rest_unit_in_frame(rsc->cm, rsc->plane, rsc_on_tile, funs[rtype],
......@@ -1186,6 +1172,15 @@ void av1_pick_filter_restoration(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi) {
double best_cost = 0;
RestorationType best_rtype = RESTORE_NONE;
#if CONFIG_HIGHBITDEPTH
const int highbd = rsc.cm->use_highbitdepth;
#else
const int highbd = 0;
#endif
extend_frame(rsc.dgd_buffer, rsc.plane_width, rsc.plane_height,
rsc.dgd_stride, RESTORATION_BORDER, RESTORATION_BORDER,
highbd);
for (RestorationType r = 0; r < num_rtypes; ++r) {
if ((force_restore_type != RESTORE_TYPES) && (r != RESTORE_NONE) &&
(r != force_restore_type))
......
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