Commit d3d0615e authored by Rupert Swarbrick's avatar Rupert Swarbrick

General tidy-ups in loop restoration code

This refactors the iteration in restoration.c so that all the scary
stuff lies in a pair of general functions, filter_frame and
filter_rest_unit.

filter_frame is currently very simple, iterating over the restoration
units in the frame. Once we've made it so that restoration units don't
span tile boundaries, this function is the one we'll need to update to
iterate over tiles and then restoration units within the tile.

filter_rest_unit replaces the outer loop of the loop_*_filter_tile*
functions. It deals with chopping the restoration unit into stripes of
height procunit_height. When CONFIG_STRIPED_LOOP_RESTORATION is true,
it also deals with calling setup_processing_stripe_boundary and
restore_processing_stripe_boundary to use boundary data from the
deblocked output.

Some of the ugly #if/#endif blocks have been elided in the wiener
filter code (both low and high bit depth), by defining a convolve
alias based on USE_WIENER_HIGH_INTERMEDIATE_PRECISION.

There are also changes to extend const-ness for the source frame. I've
adopted the convention that the frame input is called "data" (as it
was before) while it's non-const. This is true as far as
filter_rest_unit. Then each "process one stripe" function takes a
const pointer to the source frame, at which point it's called "src".

The intention is that, once filter_rest_unit no longer needs a
RestorationInternal pointer, this function can be exposed in
restoration.h and can be used by pickrst.c

Change-Id: I18043a172ef0ca1154d87cf7f63e3a80944627cd
parent a45b104a
......@@ -615,23 +615,23 @@ if (aom_config("CONFIG_GLOBAL_MOTION") eq "yes" &&
# LOOP_RESTORATION functions
if (aom_config("CONFIG_LOOP_RESTORATION") eq "yes") {
add_proto qw/void apply_selfguided_restoration/, "uint8_t *dat, int width, int height, int stride, int eps, int *xqd, uint8_t *dst, int dst_stride, int32_t *tmpbuf";
add_proto qw/void apply_selfguided_restoration/, "const uint8_t *dat, int width, int height, int stride, int eps, int *xqd, uint8_t *dst, int dst_stride, int32_t *tmpbuf";
specialize qw/apply_selfguided_restoration sse4_1/;
add_proto qw/void av1_selfguided_restoration/, "uint8_t *dgd, int width, int height, int stride, int32_t *dst, int dst_stride, int r, int eps";
add_proto qw/void av1_selfguided_restoration/, "const uint8_t *dgd, int width, int height, int stride, int32_t *dst, int dst_stride, int r, int eps";
specialize qw/av1_selfguided_restoration sse4_1/;
add_proto qw/void av1_highpass_filter/, "uint8_t *dgd, int width, int height, int stride, int32_t *dst, int dst_stride, int r, int eps";
add_proto qw/void av1_highpass_filter/, "const uint8_t *dgd, int width, int height, int stride, int32_t *dst, int dst_stride, int r, int eps";
specialize qw/av1_highpass_filter sse4_1/;
if (aom_config("CONFIG_HIGHBITDEPTH") eq "yes") {
add_proto qw/void apply_selfguided_restoration_highbd/, "uint16_t *dat, int width, int height, int stride, int bit_depth, int eps, int *xqd, uint16_t *dst, int dst_stride, int32_t *tmpbuf";
add_proto qw/void apply_selfguided_restoration_highbd/, "const uint16_t *dat, int width, int height, int stride, int bit_depth, int eps, int *xqd, uint16_t *dst, int dst_stride, int32_t *tmpbuf";
specialize qw/apply_selfguided_restoration_highbd sse4_1/;
add_proto qw/void av1_selfguided_restoration_highbd/, "uint16_t *dgd, int width, int height, int stride, int32_t *dst, int dst_stride, int bit_depth, int r, int eps";
add_proto qw/void av1_selfguided_restoration_highbd/, "const uint16_t *dgd, int width, int height, int stride, int32_t *dst, int dst_stride, int bit_depth, int r, int eps";
specialize qw/av1_selfguided_restoration_highbd sse4_1/;
add_proto qw/void av1_highpass_filter_highbd/, "uint16_t *dgd, int width, int height, int stride, int32_t *dst, int dst_stride, int r, int eps";
add_proto qw/void av1_highpass_filter_highbd/, "const uint16_t *dgd, int width, int height, int stride, int32_t *dst, int dst_stride, int r, int eps";
specialize qw/av1_highpass_filter_highbd sse4_1/;
}
}
......
This diff is collapsed.
......@@ -289,11 +289,7 @@ int av1_alloc_restoration_struct(struct AV1Common *cm,
void av1_free_restoration_struct(RestorationInfo *rst_info);
void extend_frame(uint8_t *data, int width, int height, int stride,
int border_horz, int border_vert);
#if CONFIG_HIGHBITDEPTH
void extend_frame_highbd(uint16_t *data, int width, int height, int stride,
int border_horz, int border_vert);
#endif // CONFIG_HIGHBITDEPTH
int border_horz, int border_vert, int highbd);
void decode_xq(int *xqd, int *xq);
void av1_loop_restoration_frame(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
RestorationInfo *rsi, int components_pattern,
......
......@@ -60,9 +60,9 @@ static void calc_block(__m128i sum, __m128i sum_sq, __m128i n,
_mm_storeu_si128((__m128i *)&B[idx], b_res);
}
static void selfguided_restoration_1_v(uint8_t *src, int width, int height,
int src_stride, int32_t *A, int32_t *B,
int buf_stride) {
static void selfguided_restoration_1_v(const uint8_t *src, int width,
int height, int src_stride, int32_t *A,
int32_t *B, int buf_stride) {
int i, j;
// Vertical sum
......@@ -234,9 +234,9 @@ static void selfguided_restoration_1_h(int32_t *A, int32_t *B, int width,
}
}
static void selfguided_restoration_2_v(uint8_t *src, int width, int height,
int src_stride, int32_t *A, int32_t *B,
int buf_stride) {
static void selfguided_restoration_2_v(const uint8_t *src, int width,
int height, int src_stride, int32_t *A,
int32_t *B, int buf_stride) {
int i, j;
// Vertical sum
......@@ -435,9 +435,9 @@ static void selfguided_restoration_2_h(int32_t *A, int32_t *B, int width,
}
}
static void selfguided_restoration_3_v(uint8_t *src, int width, int height,
int src_stride, int32_t *A, int32_t *B,
int buf_stride) {
static void selfguided_restoration_3_v(const uint8_t *src, int width,
int height, int src_stride, int32_t *A,
int32_t *B, int buf_stride) {
int i, j;
// Vertical sum over 7-pixel regions, 4 columns at a time
......@@ -664,8 +664,8 @@ static void selfguided_restoration_3_h(int32_t *A, int32_t *B, int width,
}
}
void av1_selfguided_restoration_sse4_1(uint8_t *dgd, int width, int height,
int dgd_stride, int32_t *dst,
void av1_selfguided_restoration_sse4_1(const uint8_t *dgd, int width,
int height, int dgd_stride, int32_t *dst,
int dst_stride, int r, int eps) {
DECLARE_ALIGNED(16, int32_t, A_[RESTORATION_PROC_UNIT_PELS]);
DECLARE_ALIGNED(16, int32_t, B_[RESTORATION_PROC_UNIT_PELS]);
......@@ -682,7 +682,8 @@ void av1_selfguided_restoration_sse4_1(uint8_t *dgd, int width, int height,
// Don't filter tiles with dimensions < 5 on any axis
if ((width < 5) || (height < 5)) return;
uint8_t *dgd0 = dgd - dgd_stride * SGRPROJ_BORDER_VERT - SGRPROJ_BORDER_HORZ;
const uint8_t *dgd0 =
dgd - dgd_stride * SGRPROJ_BORDER_VERT - SGRPROJ_BORDER_HORZ;
if (r == 1) {
selfguided_restoration_1_v(dgd0, width_ext, height_ext, dgd_stride, A, B,
buf_stride);
......@@ -894,9 +895,9 @@ void av1_selfguided_restoration_sse4_1(uint8_t *dgd, int width, int height,
}
}
void av1_highpass_filter_sse4_1(uint8_t *dgd, int width, int height, int stride,
int32_t *dst, int dst_stride, int corner,
int edge) {
void av1_highpass_filter_sse4_1(const uint8_t *dgd, int width, int height,
int stride, int32_t *dst, int dst_stride,
int corner, int edge) {
int i, j;
const int center = (1 << SGRPROJ_RST_BITS) - 4 * (corner + edge);
......@@ -1055,9 +1056,9 @@ void av1_highpass_filter_sse4_1(uint8_t *dgd, int width, int height, int stride,
}
}
void apply_selfguided_restoration_sse4_1(uint8_t *dat, int width, int height,
int stride, int eps, int *xqd,
uint8_t *dst, int dst_stride,
void apply_selfguided_restoration_sse4_1(const uint8_t *dat, int width,
int height, int stride, int eps,
int *xqd, uint8_t *dst, int dst_stride,
int32_t *tmpbuf) {
int xq[2];
int32_t *flt1 = tmpbuf;
......@@ -1136,7 +1137,7 @@ void apply_selfguided_restoration_sse4_1(uint8_t *dat, int width, int height,
#if CONFIG_HIGHBITDEPTH
// Only the vertical sums need to be adjusted for highbitdepth
static void highbd_selfguided_restoration_1_v(uint16_t *src, int width,
static void highbd_selfguided_restoration_1_v(const uint16_t *src, int width,
int height, int src_stride,
int32_t *A, int32_t *B,
int buf_stride) {
......@@ -1193,7 +1194,7 @@ static void highbd_selfguided_restoration_1_v(uint16_t *src, int width,
}
}
static void highbd_selfguided_restoration_2_v(uint16_t *src, int width,
static void highbd_selfguided_restoration_2_v(const uint16_t *src, int width,
int height, int src_stride,
int32_t *A, int32_t *B,
int buf_stride) {
......@@ -1273,7 +1274,7 @@ static void highbd_selfguided_restoration_2_v(uint16_t *src, int width,
}
}
static void highbd_selfguided_restoration_3_v(uint16_t *src, int width,
static void highbd_selfguided_restoration_3_v(const uint16_t *src, int width,
int height, int src_stride,
int32_t *A, int32_t *B,
int buf_stride) {
......@@ -1371,7 +1372,7 @@ static void highbd_selfguided_restoration_3_v(uint16_t *src, int width,
}
}
void av1_selfguided_restoration_highbd_sse4_1(uint16_t *dgd, int width,
void av1_selfguided_restoration_highbd_sse4_1(const uint16_t *dgd, int width,
int height, int dgd_stride,
int32_t *dst, int dst_stride,
int bit_depth, int r, int eps) {
......@@ -1390,7 +1391,8 @@ void av1_selfguided_restoration_highbd_sse4_1(uint16_t *dgd, int width,
// Don't filter tiles with dimensions < 5 on any axis
if ((width < 5) || (height < 5)) return;
uint16_t *dgd0 = dgd - dgd_stride * SGRPROJ_BORDER_VERT - SGRPROJ_BORDER_HORZ;
const uint16_t *dgd0 =
dgd - dgd_stride * SGRPROJ_BORDER_VERT - SGRPROJ_BORDER_HORZ;
if (r == 1) {
highbd_selfguided_restoration_1_v(dgd0, width_ext, height_ext, dgd_stride,
A, B, buf_stride);
......@@ -1605,9 +1607,9 @@ void av1_selfguided_restoration_highbd_sse4_1(uint16_t *dgd, int width,
}
}
void av1_highpass_filter_highbd_sse4_1(uint16_t *dgd, int width, int height,
int stride, int32_t *dst, int dst_stride,
int corner, int edge) {
void av1_highpass_filter_highbd_sse4_1(const uint16_t *dgd, int width,
int height, int stride, int32_t *dst,
int dst_stride, int corner, int edge) {
int i, j;
const int center = (1 << SGRPROJ_RST_BITS) - 4 * (corner + edge);
......@@ -1737,8 +1739,8 @@ void av1_highpass_filter_highbd_sse4_1(uint16_t *dgd, int width, int height,
}
void apply_selfguided_restoration_highbd_sse4_1(
uint16_t *dat, int width, int height, int stride, int bit_depth, int eps,
int *xqd, uint16_t *dst, int dst_stride, int32_t *tmpbuf) {
const uint16_t *dat, int width, int height, int stride, int bit_depth,
int eps, int *xqd, uint16_t *dst, int dst_stride, int32_t *tmpbuf) {
int xq[2];
int32_t *flt1 = tmpbuf;
int32_t *flt2 = flt1 + RESTORATION_TILEPELS_MAX;
......
......@@ -626,14 +626,13 @@ static double search_sgrproj(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi,
// tile at a time.
const AV1_COMMON *const cm = &cpi->common;
#if CONFIG_HIGHBITDEPTH
if (cm->use_highbitdepth)
extend_frame_highbd(CONVERT_TO_SHORTPTR(ctxt.dgd_buffer), ctxt.plane_width,
ctxt.plane_height, ctxt.dgd_stride, SGRPROJ_BORDER_HORZ,
SGRPROJ_BORDER_VERT);
else
const int highbd = cm->use_highbitdepth;
#else
const int highbd = 0;
#endif
extend_frame(ctxt.dgd_buffer, ctxt.plane_width, ctxt.plane_height,
ctxt.dgd_stride, SGRPROJ_BORDER_HORZ, SGRPROJ_BORDER_VERT);
extend_frame(ctxt.dgd_buffer, ctxt.plane_width, ctxt.plane_height,
ctxt.dgd_stride, SGRPROJ_BORDER_HORZ, SGRPROJ_BORDER_VERT,
highbd);
for (int tile_row = 0; tile_row < cm->tile_rows; ++tile_row) {
for (int tile_col = 0; tile_col < cm->tile_cols; ++tile_col) {
......@@ -1237,14 +1236,12 @@ static double search_wiener(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi,
// Note use this border to gather stats even though the actual filter
// may use less border on the top/bottom of a processing unit.
#if CONFIG_HIGHBITDEPTH
if (cm->use_highbitdepth)
extend_frame_highbd(CONVERT_TO_SHORTPTR(ctxt.dgd_buffer), ctxt.plane_width,
ctxt.plane_height, ctxt.dgd_stride, WIENER_HALFWIN,
WIENER_HALFWIN);
else
const int highbd = cm->use_highbitdepth;
#else
const int highbd = 0;
#endif
extend_frame(ctxt.dgd_buffer, ctxt.plane_width, ctxt.plane_height,
ctxt.dgd_stride, WIENER_HALFWIN, WIENER_HALFWIN);
extend_frame(ctxt.dgd_buffer, ctxt.plane_width, ctxt.plane_height,
ctxt.dgd_stride, WIENER_HALFWIN, WIENER_HALFWIN, highbd);
// Compute best Wiener filters for each rtile, one (encoder/decoder)
// tile at a time.
......
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