Commit 994ccd7f authored by Debargha Mukherjee's avatar Debargha Mukherjee

Add tiled version of UV wiener restoration

Slight improvement in midres and hdres sets of 0.02% and 0.0.9%
respectively.

This is also a better design anyways.

Change-Id: I15b60b8836070a2132641e5b1d8e9f68df426c08
parent 8b28d867
......@@ -146,7 +146,7 @@ static void loop_wiener_filter_tile(uint8_t *data, int tile_idx, int width,
DECLARE_ALIGNED(16, InterpKernel, hkernel);
DECLARE_ALIGNED(16, InterpKernel, vkernel);
if (rst->rsi->wiener_info[tile_idx].level == 0) {
if (rst->rsi->restoration_type[tile_idx] == RESTORE_NONE) {
loop_copy_tile(data, tile_idx, 0, 0, width, height, stride, rst, dst,
dst_stride);
return;
......@@ -632,7 +632,7 @@ static void loop_sgrproj_filter_tile(uint8_t *data, int tile_idx, int width,
int h_start, h_end, v_start, v_end;
uint8_t *data_p, *dst_p;
if (rst->rsi->sgrproj_info[tile_idx].level == 0) {
if (rst->rsi->restoration_type[tile_idx] == RESTORE_NONE) {
loop_copy_tile(data, tile_idx, 0, 0, width, height, stride, rst, dst,
dst_stride);
return;
......@@ -791,7 +791,7 @@ static void loop_domaintxfmrf_filter_tile(uint8_t *data, int tile_idx,
int h_start, h_end, v_start, v_end;
int32_t *tmpbuf = (int32_t *)rst->tmpbuf;
if (rst->rsi->domaintxfmrf_info[tile_idx].level == 0) {
if (rst->rsi->restoration_type[tile_idx] == RESTORE_NONE) {
loop_copy_tile(data, tile_idx, 0, 0, width, height, stride, rst, dst,
dst_stride);
return;
......@@ -886,7 +886,7 @@ static void loop_wiener_filter_tile_highbd(uint16_t *data, int tile_idx,
DECLARE_ALIGNED(16, InterpKernel, hkernel);
DECLARE_ALIGNED(16, InterpKernel, vkernel);
if (rst->rsi->wiener_info[tile_idx].level == 0) {
if (rst->rsi->restoration_type[tile_idx] == RESTORE_NONE) {
loop_copy_tile_highbd(data, tile_idx, 0, 0, width, height, stride, rst, dst,
dst_stride);
return;
......@@ -979,7 +979,7 @@ static void loop_sgrproj_filter_tile_highbd(uint16_t *data, int tile_idx,
int h_start, h_end, v_start, v_end;
uint16_t *data_p, *dst_p;
if (rst->rsi->sgrproj_info[tile_idx].level == 0) {
if (rst->rsi->restoration_type[tile_idx] == RESTORE_NONE) {
loop_copy_tile_highbd(data, tile_idx, 0, 0, width, height, stride, rst, dst,
dst_stride);
return;
......@@ -1109,7 +1109,7 @@ static void loop_domaintxfmrf_filter_tile_highbd(
int h_start, h_end, v_start, v_end;
int32_t *tmpbuf = (int32_t *)rst->tmpbuf;
if (rst->rsi->domaintxfmrf_info[tile_idx].level == 0) {
if (rst->rsi->restoration_type[tile_idx] == RESTORE_NONE) {
loop_copy_tile_highbd(data, tile_idx, 0, 0, width, height, stride, rst, dst,
dst_stride);
return;
......
......@@ -114,10 +114,7 @@ extern "C" {
// Max of SGRPROJ_EXTBUF_SIZE, DOMAINTXFMRF_EXTBUF_SIZE, WIENER_EXTBUF_SIZE
#define RESTORATION_EXTBUF_SIZE (DOMAINTXFMRF_EXTBUF_SIZE)
typedef struct {
int level;
int vfilter[WIENER_WIN], hfilter[WIENER_WIN];
} WienerInfo;
typedef struct { int vfilter[WIENER_WIN], hfilter[WIENER_WIN]; } WienerInfo;
typedef struct {
int r1;
......@@ -127,15 +124,11 @@ typedef struct {
} sgr_params_type;
typedef struct {
int level;
int ep;
int xqd[2];
} SgrprojInfo;
typedef struct {
int level;
int sigma_r;
} DomaintxfmrfInfo;
typedef struct { int sigma_r; } DomaintxfmrfInfo;
typedef struct {
RestorationType frame_restoration_type;
......
......@@ -2359,7 +2359,7 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) {
const int ntiles =
av1_get_rest_ntiles(cm->width, cm->height, NULL, NULL, NULL, NULL);
const int ntiles_uv = av1_get_rest_ntiles(cm->width >> cm->subsampling_x,
cm->height >> cm->subsampling_x,
cm->height >> cm->subsampling_y,
NULL, NULL, NULL, NULL);
RestorationInfo *rsi = &cm->rst_info[0];
if (rsi->frame_restoration_type != RESTORE_NONE) {
......@@ -2369,13 +2369,10 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) {
aom_read_tree(rb, av1_switchable_restore_tree,
cm->fc->switchable_restore_prob, ACCT_STR);
if (rsi->restoration_type[i] == RESTORE_WIENER) {
rsi->wiener_info[i].level = 1;
read_wiener_filter(&rsi->wiener_info[i], rb);
} else if (rsi->restoration_type[i] == RESTORE_SGRPROJ) {
rsi->sgrproj_info[i].level = 1;
read_sgrproj_filter(&rsi->sgrproj_info[i], rb);
} else if (rsi->restoration_type[i] == RESTORE_DOMAINTXFMRF) {
rsi->domaintxfmrf_info[i].level = 1;
read_domaintxfmrf_filter(&rsi->domaintxfmrf_info[i], rb);
}
}
......@@ -2383,10 +2380,8 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) {
for (i = 0; i < ntiles; ++i) {
if (aom_read(rb, RESTORE_NONE_WIENER_PROB, ACCT_STR)) {
rsi->restoration_type[i] = RESTORE_WIENER;
rsi->wiener_info[i].level = 1;
read_wiener_filter(&rsi->wiener_info[i], rb);
} else {
rsi->wiener_info[i].level = 0;
rsi->restoration_type[i] = RESTORE_NONE;
}
}
......@@ -2394,10 +2389,8 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) {
for (i = 0; i < ntiles; ++i) {
if (aom_read(rb, RESTORE_NONE_SGRPROJ_PROB, ACCT_STR)) {
rsi->restoration_type[i] = RESTORE_SGRPROJ;
rsi->sgrproj_info[i].level = 1;
read_sgrproj_filter(&rsi->sgrproj_info[i], rb);
} else {
rsi->sgrproj_info[i].level = 0;
rsi->restoration_type[i] = RESTORE_NONE;
}
}
......@@ -2405,10 +2398,8 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) {
for (i = 0; i < ntiles; ++i) {
if (aom_read(rb, RESTORE_NONE_DOMAINTXFMRF_PROB, ACCT_STR)) {
rsi->restoration_type[i] = RESTORE_DOMAINTXFMRF;
rsi->domaintxfmrf_info[i].level = 1;
read_domaintxfmrf_filter(&rsi->domaintxfmrf_info[i], rb);
} else {
rsi->domaintxfmrf_info[i].level = 0;
rsi->restoration_type[i] = RESTORE_NONE;
}
}
......@@ -2417,13 +2408,16 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) {
for (p = 1; p < MAX_MB_PLANE; ++p) {
rsi = &cm->rst_info[p];
if (rsi->frame_restoration_type == RESTORE_WIENER) {
rsi->restoration_type[0] = RESTORE_WIENER;
rsi->wiener_info[0].level = 1;
read_wiener_filter(&rsi->wiener_info[0], rb);
for (i = 1; i < ntiles_uv; ++i) {
rsi->restoration_type[i] = RESTORE_WIENER;
memcpy(&rsi->wiener_info[i], &rsi->wiener_info[0],
sizeof(rsi->wiener_info[0]));
for (i = 0; i < ntiles_uv; ++i) {
if (ntiles_uv > 1)
rsi->restoration_type[i] =
aom_read(rb, RESTORE_NONE_WIENER_PROB, ACCT_STR) ? RESTORE_WIENER
: RESTORE_NONE;
else
rsi->restoration_type[i] = RESTORE_WIENER;
if (rsi->restoration_type[i] == RESTORE_WIENER) {
read_wiener_filter(&rsi->wiener_info[i], rb);
}
}
}
}
......
......@@ -3088,6 +3088,9 @@ static void encode_restoration(AV1_COMMON *cm, aom_writer *wb) {
int i, p;
const int ntiles =
av1_get_rest_ntiles(cm->width, cm->height, NULL, NULL, NULL, NULL);
const int ntiles_uv = av1_get_rest_ntiles(cm->width >> cm->subsampling_x,
cm->height >> cm->subsampling_y,
NULL, NULL, NULL, NULL);
RestorationInfo *rsi = &cm->rst_info[0];
if (rsi->frame_restoration_type != RESTORE_NONE) {
if (rsi->frame_restoration_type == RESTORE_SWITCHABLE) {
......@@ -3106,24 +3109,25 @@ static void encode_restoration(AV1_COMMON *cm, aom_writer *wb) {
}
} else if (rsi->frame_restoration_type == RESTORE_WIENER) {
for (i = 0; i < ntiles; ++i) {
aom_write(wb, rsi->wiener_info[i].level != 0, RESTORE_NONE_WIENER_PROB);
if (rsi->wiener_info[i].level) {
aom_write(wb, rsi->restoration_type[i] != RESTORE_NONE,
RESTORE_NONE_WIENER_PROB);
if (rsi->restoration_type[i] != RESTORE_NONE) {
write_wiener_filter(&rsi->wiener_info[i], wb);
}
}
} else if (rsi->frame_restoration_type == RESTORE_SGRPROJ) {
for (i = 0; i < ntiles; ++i) {
aom_write(wb, rsi->sgrproj_info[i].level != 0,
aom_write(wb, rsi->restoration_type[i] != RESTORE_NONE,
RESTORE_NONE_SGRPROJ_PROB);
if (rsi->sgrproj_info[i].level) {
if (rsi->restoration_type[i] != RESTORE_NONE) {
write_sgrproj_filter(&rsi->sgrproj_info[i], wb);
}
}
} else if (rsi->frame_restoration_type == RESTORE_DOMAINTXFMRF) {
for (i = 0; i < ntiles; ++i) {
aom_write(wb, rsi->domaintxfmrf_info[i].level != 0,
aom_write(wb, rsi->restoration_type[i] != RESTORE_NONE,
RESTORE_NONE_DOMAINTXFMRF_PROB);
if (rsi->domaintxfmrf_info[i].level) {
if (rsi->restoration_type[i] != RESTORE_NONE) {
write_domaintxfmrf_filter(&rsi->domaintxfmrf_info[i], wb);
}
}
......@@ -3132,7 +3136,14 @@ static void encode_restoration(AV1_COMMON *cm, aom_writer *wb) {
for (p = 1; p < MAX_MB_PLANE; ++p) {
rsi = &cm->rst_info[p];
if (rsi->frame_restoration_type == RESTORE_WIENER) {
write_wiener_filter(&rsi->wiener_info[0], wb);
for (i = 0; i < ntiles_uv; ++i) {
if (ntiles_uv > 1)
aom_write(wb, rsi->restoration_type[i] != RESTORE_NONE,
RESTORE_NONE_WIENER_PROB);
if (rsi->restoration_type[i] != RESTORE_NONE) {
write_wiener_filter(&rsi->wiener_info[i], wb);
}
}
} else if (rsi->frame_restoration_type != RESTORE_NONE) {
assert(0);
}
......
This diff is collapsed.
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