Commit 3981be93 authored by Debargha Mukherjee's avatar Debargha Mukherjee

Add domain transform recursive filter

This filter is meant to replace the bilateral filter,
but is currently added in addition to the bilateral filter
for testing.

Change-Id: Ia529701e69833d47c11b3367d5bf804eb8498079
parent eee4315e
......@@ -91,6 +91,8 @@ void av1_free_restoration_buffers(AV1_COMMON *cm) {
cm->rst_info.wiener_info = NULL;
aom_free(cm->rst_info.sgrproj_info);
cm->rst_info.sgrproj_info = NULL;
aom_free(cm->rst_info.domaintxfmrf_info);
cm->rst_info.domaintxfmrf_info = NULL;
}
#endif // CONFIG_LOOP_RESTORATION
......
......@@ -1186,11 +1186,20 @@ static const aom_prob default_tx_size_prob[MAX_TX_DEPTH][TX_SIZE_CONTEXTS]
#if CONFIG_LOOP_RESTORATION
const aom_tree_index av1_switchable_restore_tree[TREE_SIZE(
RESTORE_SWITCHABLE_TYPES)] = {
-RESTORE_NONE, 2, -RESTORE_SGRPROJ, 4, -RESTORE_BILATERAL, -RESTORE_WIENER,
// -RESTORE_NONE, 2, -RESTORE_SGRPROJ, 4, -RESTORE_BILATERAL, -RESTORE_WIENER,
-RESTORE_NONE,
2,
4,
6,
-RESTORE_SGRPROJ,
-RESTORE_DOMAINTXFMRF,
-RESTORE_BILATERAL,
-RESTORE_WIENER,
};
static const aom_prob default_switchable_restore_prob[RESTORE_SWITCHABLE_TYPES -
1] = { 32, 85, 128 };
1] = { 32, 128, 128,
128 };
#endif // CONFIG_LOOP_RESTORATION
#if CONFIG_PALETTE
......
......@@ -346,6 +346,7 @@ extern const aom_tree_index av1_motion_mode_tree[TREE_SIZE(MOTION_MODES)];
#define RESTORE_NONE_SGRPROJ_PROB 64
#define RESTORE_NONE_BILATERAL_PROB 16
#define RESTORE_NONE_WIENER_PROB 64
#define RESTORE_NONE_DOMAINTXFMRF_PROB 64
extern const aom_tree_index
av1_switchable_restore_tree[TREE_SIZE(RESTORE_SWITCHABLE_TYPES)];
#endif // CONFIG_LOOP_RESTORATION
......
......@@ -485,7 +485,8 @@ typedef enum {
RESTORE_SGRPROJ = 1,
RESTORE_BILATERAL = 2,
RESTORE_WIENER = 3,
RESTORE_SWITCHABLE = 4,
RESTORE_DOMAINTXFMRF = 4,
RESTORE_SWITCHABLE = 5,
RESTORE_SWITCHABLE_TYPES = RESTORE_SWITCHABLE,
RESTORE_TYPES,
} RestorationType;
......
This diff is collapsed.
......@@ -21,12 +21,27 @@
extern "C" {
#endif
#define CLIP(x, lo, hi) ((x) < (lo) ? (lo) : (x) > (hi) ? (hi) : (x))
#define RINT(x) ((x) < 0 ? (int)((x)-0.5) : (int)((x) + 0.5))
#define RESTORATION_TILESIZE_SML 128
#define RESTORATION_TILESIZE_BIG 256
#define RESTORATION_TILEPELS_MAX \
(RESTORATION_TILESIZE_BIG * RESTORATION_TILESIZE_BIG * 9 / 4)
#define SGRPROJ_TMPBUF_SIZE (RESTORATION_TILEPELS_MAX * 6 * 8)
#define DOMAINTXFMRF_PARAMS_BITS 6
#define DOMAINTXFMRF_PARAMS (1 << DOMAINTXFMRF_PARAMS_BITS)
#define DOMAINTXFMRF_SIGMA_SCALEBITS 4
#define DOMAINTXFMRF_SIGMA_SCALE (1 << DOMAINTXFMRF_SIGMA_SCALEBITS)
#define DOMAINTXFMRF_ITERS 3
#define DOMAINTXFMRF_VTABLE_PRECBITS 8
#define DOMAINTXFMRF_VTABLE_PREC (1 << DOMAINTXFMRF_VTABLE_PRECBITS)
#define DOMAINTXFMRF_MULT \
sqrt(((1 << (DOMAINTXFMRF_ITERS * 2)) - 1) * 2.0 / 3.0)
#define DOMAINTXFMRF_TMPBUF_SIZE (RESTORATION_TILEPELS_MAX)
#define DOMAINTXFMRF_BITS (DOMAINTXFMRF_PARAMS_BITS)
#define SGRPROJ_TMPBUF_SIZE (RESTORATION_TILEPELS_MAX * 6 * 8)
#define SGRPROJ_PARAMS_BITS 3
#define SGRPROJ_PARAMS (1 << SGRPROJ_PARAMS_BITS)
......@@ -99,6 +114,11 @@ typedef struct {
int xqd[2];
} SgrprojInfo;
typedef struct {
int level;
int sigma_r;
} DomaintxfmrfInfo;
typedef struct {
RestorationType frame_restoration_type;
RestorationType *restoration_type;
......@@ -108,6 +128,8 @@ typedef struct {
WienerInfo *wiener_info;
// Selfguided proj filter
SgrprojInfo *sgrproj_info;
// Domain transform filter
DomaintxfmrfInfo *domaintxfmrf_info;
} RestorationInfo;
typedef struct {
......@@ -181,6 +203,12 @@ extern const sgr_params_type sgr_params[SGRPROJ_PARAMS];
void av1_selfguided_restoration(int64_t *dgd, int width, int height, int stride,
int bit_depth, int r, int eps, void *tmpbuf);
void av1_domaintxfmrf_restoration(uint8_t *dgd, int width, int height,
int stride, int param);
#if CONFIG_AOM_HIGHBITDEPTH
void av1_domaintxfmrf_restoration_highbd(uint16_t *dgd, int width, int height,
int stride, int param, int bit_depth);
#endif // CONFIG_AOM_HIGHBITDEPTH
void decode_xq(int *xqd, int *xq);
int av1_bilateral_level_bits(const struct AV1Common *const cm);
void av1_loop_restoration_init(RestorationInternal *rst, RestorationInfo *rsi,
......
......@@ -2317,7 +2317,9 @@ static void decode_restoration_mode(AV1_COMMON *cm,
rsi->frame_restoration_type =
(aom_rb_read_bit(rb) ? RESTORE_WIENER : RESTORE_BILATERAL);
else
rsi->frame_restoration_type = RESTORE_SGRPROJ;
rsi->frame_restoration_type =
(aom_rb_read_bit(rb) ? RESTORE_DOMAINTXFMRF : RESTORE_SGRPROJ);
// rsi->frame_restoration_type = RESTORE_SGRPROJ;
} else {
rsi->frame_restoration_type =
aom_rb_read_bit(rb) ? RESTORE_SWITCHABLE : RESTORE_NONE;
......@@ -2353,6 +2355,12 @@ static void read_sgrproj_filter(SgrprojInfo *sgrproj_info, aom_reader *rb) {
aom_read_literal(rb, SGRPROJ_PRJ_BITS, ACCT_STR) + SGRPROJ_PRJ_MIN1;
}
static void read_domaintxfmrf_filter(DomaintxfmrfInfo *domaintxfmrf_info,
aom_reader *rb) {
domaintxfmrf_info->sigma_r =
aom_read_literal(rb, DOMAINTXFMRF_PARAMS_BITS, ACCT_STR);
}
static void read_bilateral_filter(const AV1_COMMON *cm,
BilateralInfo *bilateral_info,
aom_reader *rb) {
......@@ -2385,6 +2393,9 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) {
rsi->sgrproj_info = (SgrprojInfo *)aom_realloc(
rsi->sgrproj_info, sizeof(*rsi->sgrproj_info) * ntiles);
assert(rsi->sgrproj_info != NULL);
rsi->domaintxfmrf_info = (DomaintxfmrfInfo *)aom_realloc(
rsi->domaintxfmrf_info, sizeof(*rsi->domaintxfmrf_info) * ntiles);
assert(rsi->domaintxfmrf_info != NULL);
for (i = 0; i < ntiles; ++i) {
rsi->restoration_type[i] =
aom_read_tree(rb, av1_switchable_restore_tree,
......@@ -2402,6 +2413,9 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *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);
}
}
} else if (rsi->frame_restoration_type == RESTORE_WIENER) {
......@@ -2440,6 +2454,20 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) {
rsi->restoration_type[i] = RESTORE_NONE;
}
}
} else if (rsi->frame_restoration_type == RESTORE_DOMAINTXFMRF) {
rsi->domaintxfmrf_info = (DomaintxfmrfInfo *)aom_realloc(
rsi->domaintxfmrf_info, sizeof(*rsi->domaintxfmrf_info) * ntiles);
assert(rsi->domaintxfmrf_info != NULL);
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;
}
}
}
}
}
......
......@@ -2986,9 +2986,21 @@ static void encode_restoration_mode(AV1_COMMON *cm,
aom_wb_write_bit(wb, 0);
aom_wb_write_bit(wb, 1);
break;
/*
case RESTORE_SGRPROJ:
aom_wb_write_bit(wb, 1);
aom_wb_write_bit(wb, 0);
break;
*/
case RESTORE_SGRPROJ:
aom_wb_write_bit(wb, 1);
aom_wb_write_bit(wb, 0);
aom_wb_write_bit(wb, 0);
break;
case RESTORE_DOMAINTXFMRF:
aom_wb_write_bit(wb, 1);
aom_wb_write_bit(wb, 0);
aom_wb_write_bit(wb, 1);
break;
case RESTORE_BILATERAL:
aom_wb_write_bit(wb, 1);
......@@ -3027,6 +3039,11 @@ static void write_sgrproj_filter(SgrprojInfo *sgrproj_info, aom_writer *wb) {
SGRPROJ_PRJ_BITS);
}
static void write_domaintxfmrf_filter(DomaintxfmrfInfo *domaintxfmrf_info,
aom_writer *wb) {
aom_write_literal(wb, domaintxfmrf_info->sigma_r, DOMAINTXFMRF_PARAMS_BITS);
}
static void write_bilateral_filter(const AV1_COMMON *cm,
BilateralInfo *bilateral_info,
aom_writer *wb) {
......@@ -3061,6 +3078,8 @@ static void encode_restoration(AV1_COMMON *cm, aom_writer *wb) {
write_wiener_filter(&rsi->wiener_info[i], wb);
} else if (rsi->restoration_type[i] == RESTORE_SGRPROJ) {
write_sgrproj_filter(&rsi->sgrproj_info[i], wb);
} else if (rsi->restoration_type[i] == RESTORE_DOMAINTXFMRF) {
write_domaintxfmrf_filter(&rsi->domaintxfmrf_info[i], wb);
}
}
} else if (rsi->frame_restoration_type == RESTORE_BILATERAL) {
......@@ -3082,6 +3101,14 @@ static void encode_restoration(AV1_COMMON *cm, aom_writer *wb) {
write_sgrproj_filter(&rsi->sgrproj_info[i], wb);
}
}
} else if (rsi->frame_restoration_type == RESTORE_DOMAINTXFMRF) {
for (i = 0; i < cm->rst_internal.ntiles; ++i) {
aom_write(wb, rsi->domaintxfmrf_info[i].level != 0,
RESTORE_NONE_DOMAINTXFMRF_PROB);
if (rsi->domaintxfmrf_info[i].level) {
write_domaintxfmrf_filter(&rsi->domaintxfmrf_info[i], wb);
}
}
}
}
}
......
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