Commit 1e8e6b95 authored by David Barker's avatar David Barker Committed by Debargha Mukherjee

Miscellaneous cleaning up for loop-restoration

* Change Wiener filter storage to match the format expected
  by the convolve functions

Change-Id: I4d1fb08a13cfc31e69e12c1cb4b2e510c6d8ae30
parent f77d4ad3
...@@ -55,6 +55,7 @@ int av1_alloc_restoration_struct(RestorationInfo *rst_info, int width, ...@@ -55,6 +55,7 @@ int av1_alloc_restoration_struct(RestorationInfo *rst_info, int width,
rst_info->wiener_info = (WienerInfo *)aom_realloc( rst_info->wiener_info = (WienerInfo *)aom_realloc(
rst_info->wiener_info, sizeof(*rst_info->wiener_info) * ntiles); rst_info->wiener_info, sizeof(*rst_info->wiener_info) * ntiles);
assert(rst_info->wiener_info != NULL); assert(rst_info->wiener_info != NULL);
memset(rst_info->wiener_info, 0, sizeof(*rst_info->wiener_info) * ntiles);
rst_info->sgrproj_info = (SgrprojInfo *)aom_realloc( rst_info->sgrproj_info = (SgrprojInfo *)aom_realloc(
rst_info->sgrproj_info, sizeof(*rst_info->sgrproj_info) * ntiles); rst_info->sgrproj_info, sizeof(*rst_info->sgrproj_info) * ntiles);
assert(rst_info->sgrproj_info != NULL); assert(rst_info->sgrproj_info != NULL);
...@@ -143,25 +144,11 @@ static void loop_wiener_filter_tile(uint8_t *data, int tile_idx, int width, ...@@ -143,25 +144,11 @@ static void loop_wiener_filter_tile(uint8_t *data, int tile_idx, int width,
const int tile_height = rst->tile_height; const int tile_height = rst->tile_height;
int i, j; int i, j;
int h_start, h_end, v_start, v_end; int h_start, h_end, v_start, v_end;
DECLARE_ALIGNED(16, InterpKernel, hkernel);
DECLARE_ALIGNED(16, InterpKernel, vkernel);
if (rst->rsi->restoration_type[tile_idx] == RESTORE_NONE) { if (rst->rsi->restoration_type[tile_idx] == RESTORE_NONE) {
loop_copy_tile(data, tile_idx, 0, 0, width, height, stride, rst, dst, loop_copy_tile(data, tile_idx, 0, 0, width, height, stride, rst, dst,
dst_stride); dst_stride);
return; return;
} }
// TODO(david.barker): Store hfilter/vfilter as an InterpKernel
// instead of the current format. Then this can be removed.
assert(WIENER_WIN == SUBPEL_TAPS - 1);
for (i = 0; i < WIENER_WIN; ++i) {
hkernel[i] = rst->rsi->wiener_info[tile_idx].hfilter[i];
vkernel[i] = rst->rsi->wiener_info[tile_idx].vfilter[i];
}
hkernel[WIENER_WIN] = 0;
vkernel[WIENER_WIN] = 0;
hkernel[3] -= 128;
vkernel[3] -= 128;
av1_get_rest_tile_limits(tile_idx, 0, 0, rst->nhtiles, rst->nvtiles, av1_get_rest_tile_limits(tile_idx, 0, 0, rst->nhtiles, rst->nvtiles,
tile_width, tile_height, width, height, 0, 0, tile_width, tile_height, width, height, 0, 0,
&h_start, &h_end, &v_start, &v_end); &h_start, &h_end, &v_start, &v_end);
...@@ -173,8 +160,9 @@ static void loop_wiener_filter_tile(uint8_t *data, int tile_idx, int width, ...@@ -173,8 +160,9 @@ static void loop_wiener_filter_tile(uint8_t *data, int tile_idx, int width,
int h = AOMMIN(MAX_SB_SIZE, (v_end - i + 15) & ~15); int h = AOMMIN(MAX_SB_SIZE, (v_end - i + 15) & ~15);
const uint8_t *data_p = data + i * stride + j; const uint8_t *data_p = data + i * stride + j;
uint8_t *dst_p = dst + i * dst_stride + j; uint8_t *dst_p = dst + i * dst_stride + j;
aom_convolve8_add_src(data_p, stride, dst_p, dst_stride, hkernel, 16, aom_convolve8_add_src(data_p, stride, dst_p, dst_stride,
vkernel, 16, w, h); rst->rsi->wiener_info[tile_idx].hfilter, 16,
rst->rsi->wiener_info[tile_idx].vfilter, 16, w, h);
} }
} }
...@@ -1028,25 +1016,12 @@ static void loop_wiener_filter_tile_highbd(uint16_t *data, int tile_idx, ...@@ -1028,25 +1016,12 @@ static void loop_wiener_filter_tile_highbd(uint16_t *data, int tile_idx,
const int tile_height = rst->tile_height; const int tile_height = rst->tile_height;
int h_start, h_end, v_start, v_end; int h_start, h_end, v_start, v_end;
int i, j; int i, j;
DECLARE_ALIGNED(16, InterpKernel, hkernel);
DECLARE_ALIGNED(16, InterpKernel, vkernel);
if (rst->rsi->restoration_type[tile_idx] == RESTORE_NONE) { if (rst->rsi->restoration_type[tile_idx] == RESTORE_NONE) {
loop_copy_tile_highbd(data, tile_idx, 0, 0, width, height, stride, rst, dst, loop_copy_tile_highbd(data, tile_idx, 0, 0, width, height, stride, rst, dst,
dst_stride); dst_stride);
return; return;
} }
// TODO(david.barker): Store hfilter/vfilter as an InterpKernel
// instead of the current format. Then this can be removed.
assert(WIENER_WIN == SUBPEL_TAPS - 1);
for (i = 0; i < WIENER_WIN; ++i) {
hkernel[i] = rst->rsi->wiener_info[tile_idx].hfilter[i];
vkernel[i] = rst->rsi->wiener_info[tile_idx].vfilter[i];
}
hkernel[WIENER_WIN] = 0;
vkernel[WIENER_WIN] = 0;
hkernel[3] -= 128;
vkernel[3] -= 128;
av1_get_rest_tile_limits(tile_idx, 0, 0, rst->nhtiles, rst->nvtiles, av1_get_rest_tile_limits(tile_idx, 0, 0, rst->nhtiles, rst->nvtiles,
tile_width, tile_height, width, height, 0, 0, tile_width, tile_height, width, height, 0, 0,
&h_start, &h_end, &v_start, &v_end); &h_start, &h_end, &v_start, &v_end);
...@@ -1058,9 +1033,10 @@ static void loop_wiener_filter_tile_highbd(uint16_t *data, int tile_idx, ...@@ -1058,9 +1033,10 @@ static void loop_wiener_filter_tile_highbd(uint16_t *data, int tile_idx,
int h = AOMMIN(MAX_SB_SIZE, (v_end - i + 15) & ~15); int h = AOMMIN(MAX_SB_SIZE, (v_end - i + 15) & ~15);
const uint16_t *data_p = data + i * stride + j; const uint16_t *data_p = data + i * stride + j;
uint16_t *dst_p = dst + i * dst_stride + j; uint16_t *dst_p = dst + i * dst_stride + j;
aom_highbd_convolve8_add_src(CONVERT_TO_BYTEPTR(data_p), stride, aom_highbd_convolve8_add_src(
CONVERT_TO_BYTEPTR(dst_p), dst_stride, CONVERT_TO_BYTEPTR(data_p), stride, CONVERT_TO_BYTEPTR(dst_p),
hkernel, 16, vkernel, 16, w, h, bit_depth); dst_stride, rst->rsi->wiener_info[tile_idx].hfilter, 16,
rst->rsi->wiener_info[tile_idx].vfilter, 16, w, h, bit_depth);
} }
} }
......
...@@ -114,7 +114,17 @@ extern "C" { ...@@ -114,7 +114,17 @@ extern "C" {
// Max of SGRPROJ_EXTBUF_SIZE, DOMAINTXFMRF_EXTBUF_SIZE, WIENER_EXTBUF_SIZE // Max of SGRPROJ_EXTBUF_SIZE, DOMAINTXFMRF_EXTBUF_SIZE, WIENER_EXTBUF_SIZE
#define RESTORATION_EXTBUF_SIZE (DOMAINTXFMRF_EXTBUF_SIZE) #define RESTORATION_EXTBUF_SIZE (DOMAINTXFMRF_EXTBUF_SIZE)
typedef struct { int vfilter[WIENER_WIN], hfilter[WIENER_WIN]; } WienerInfo; // Check the assumptions of the existing code
#if SUBPEL_TAPS != WIENER_WIN + 1
#error "Wiener filter currently only works if SUBPEL_TAPS == WIENER_WIN + 1"
#endif
#if WIENER_FILT_PREC_BITS != 7
#error "Wiener filter currently only works if WIENER_FILT_PREC_BITS == 7"
#endif
typedef struct {
DECLARE_ALIGNED(16, InterpKernel, vfilter);
DECLARE_ALIGNED(16, InterpKernel, hfilter);
} WienerInfo;
typedef struct { typedef struct {
int r1; int r1;
......
...@@ -2471,10 +2471,11 @@ static void read_wiener_filter(WienerInfo *wiener_info, aom_reader *rb) { ...@@ -2471,10 +2471,11 @@ static void read_wiener_filter(WienerInfo *wiener_info, aom_reader *rb) {
wiener_info->vfilter[2] = wiener_info->vfilter[WIENER_WIN - 3] = wiener_info->vfilter[2] = wiener_info->vfilter[WIENER_WIN - 3] =
aom_read_literal(rb, WIENER_FILT_TAP2_BITS, ACCT_STR) + aom_read_literal(rb, WIENER_FILT_TAP2_BITS, ACCT_STR) +
WIENER_FILT_TAP2_MINV; WIENER_FILT_TAP2_MINV;
// The central element has an implicit +WIENER_FILT_STEP
wiener_info->vfilter[WIENER_HALFWIN] = wiener_info->vfilter[WIENER_HALFWIN] =
WIENER_FILT_STEP - -2 * (wiener_info->vfilter[0] + wiener_info->vfilter[1] +
2 * (wiener_info->vfilter[0] + wiener_info->vfilter[1] + wiener_info->vfilter[2]);
wiener_info->vfilter[2]);
wiener_info->hfilter[0] = wiener_info->hfilter[WIENER_WIN - 1] = wiener_info->hfilter[0] = wiener_info->hfilter[WIENER_WIN - 1] =
aom_read_literal(rb, WIENER_FILT_TAP0_BITS, ACCT_STR) + aom_read_literal(rb, WIENER_FILT_TAP0_BITS, ACCT_STR) +
WIENER_FILT_TAP0_MINV; WIENER_FILT_TAP0_MINV;
...@@ -2484,10 +2485,10 @@ static void read_wiener_filter(WienerInfo *wiener_info, aom_reader *rb) { ...@@ -2484,10 +2485,10 @@ static void read_wiener_filter(WienerInfo *wiener_info, aom_reader *rb) {
wiener_info->hfilter[2] = wiener_info->hfilter[WIENER_WIN - 3] = wiener_info->hfilter[2] = wiener_info->hfilter[WIENER_WIN - 3] =
aom_read_literal(rb, WIENER_FILT_TAP2_BITS, ACCT_STR) + aom_read_literal(rb, WIENER_FILT_TAP2_BITS, ACCT_STR) +
WIENER_FILT_TAP2_MINV; WIENER_FILT_TAP2_MINV;
// The central element has an implicit +WIENER_FILT_STEP
wiener_info->hfilter[WIENER_HALFWIN] = wiener_info->hfilter[WIENER_HALFWIN] =
WIENER_FILT_STEP - -2 * (wiener_info->hfilter[0] + wiener_info->hfilter[1] +
2 * (wiener_info->hfilter[0] + wiener_info->hfilter[1] + wiener_info->hfilter[2]);
wiener_info->hfilter[2]);
} }
static void read_sgrproj_filter(SgrprojInfo *sgrproj_info, aom_reader *rb) { static void read_sgrproj_filter(SgrprojInfo *sgrproj_info, aom_reader *rb) {
......
...@@ -905,7 +905,8 @@ static int wiener_decompose_sep_sym(double *M, double *H, double *a, ...@@ -905,7 +905,8 @@ static int wiener_decompose_sep_sym(double *M, double *H, double *a,
// Computes the function x'*H*x - x'*M for the learned 2D filter x, and compares // Computes the function x'*H*x - x'*M for the learned 2D filter x, and compares
// against identity filters; Final score is defined as the difference between // against identity filters; Final score is defined as the difference between
// the function values // the function values
static double compute_score(double *M, double *H, int *vfilt, int *hfilt) { static double compute_score(double *M, double *H, InterpKernel vfilt,
InterpKernel hfilt) {
double ab[WIENER_WIN * WIENER_WIN]; double ab[WIENER_WIN * WIENER_WIN];
int i, k, l; int i, k, l;
double P = 0, Q = 0; double P = 0, Q = 0;
...@@ -936,7 +937,7 @@ static double compute_score(double *M, double *H, int *vfilt, int *hfilt) { ...@@ -936,7 +937,7 @@ static double compute_score(double *M, double *H, int *vfilt, int *hfilt) {
return Score - iScore; return Score - iScore;
} }
static void quantize_sym_filter(double *f, int *fi) { static void quantize_sym_filter(double *f, InterpKernel fi) {
int i; int i;
for (i = 0; i < WIENER_HALFWIN; ++i) { for (i = 0; i < WIENER_HALFWIN; ++i) {
fi[i] = RINT(f[i] * WIENER_FILT_STEP); fi[i] = RINT(f[i] * WIENER_FILT_STEP);
...@@ -949,7 +950,8 @@ static void quantize_sym_filter(double *f, int *fi) { ...@@ -949,7 +950,8 @@ static void quantize_sym_filter(double *f, int *fi) {
fi[WIENER_WIN - 1] = fi[0]; fi[WIENER_WIN - 1] = fi[0];
fi[WIENER_WIN - 2] = fi[1]; fi[WIENER_WIN - 2] = fi[1];
fi[WIENER_WIN - 3] = fi[2]; fi[WIENER_WIN - 3] = fi[2];
fi[3] = WIENER_FILT_STEP - 2 * (fi[0] + fi[1] + fi[2]); // The central element has an implicit +WIENER_FILT_STEP
fi[3] = -2 * (fi[0] + fi[1] + fi[2]);
} }
static double search_wiener_uv(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi, static double search_wiener_uv(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi,
......
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