Commit efc55fd9 authored by Cheng Chen's avatar Cheng Chen
Browse files

JNT_COMP: 2. assign proper weigths in rdopt

Change-Id: I255be6e0193dd6b91424ce53ed41aeaaeb1c01a7
parent e5cfa6f7
......@@ -275,11 +275,23 @@ MSE(8, 8)
void aom_comp_avg_pred_c(uint8_t *comp_pred, const uint8_t *pred, int width,
int height, const uint8_t *ref, int ref_stride) {
int i, j;
#if CONFIG_JNT_COMP
int bck_offset = pred[4096];
int fwd_offset = pred[4097];
double sum = bck_offset + fwd_offset;
#endif // CONFIG_JNT_COMP
for (i = 0; i < height; ++i) {
for (j = 0; j < width; ++j) {
#if CONFIG_JNT_COMP
int tmp = pred[j] * fwd_offset + ref[j] * bck_offset;
tmp = (int)(0.5 + tmp / sum);
if (tmp > 255) tmp = 255;
comp_pred[j] = (uint8_t)tmp;
#else
const int tmp = pred[j] + ref[j];
comp_pred[j] = ROUND_POWER_OF_TWO(tmp, 1);
#endif // CONFIG_JNT_COMP
}
comp_pred += width;
pred += width;
......@@ -340,12 +352,30 @@ void aom_comp_avg_upsampled_pred_c(uint8_t *comp_pred, const uint8_t *pred,
int subpel_y_q3, const uint8_t *ref,
int ref_stride) {
int i, j;
#if CONFIG_JNT_COMP
int bck_offset = pred[4096];
int fwd_offset = pred[4097];
double sum = bck_offset + fwd_offset;
#endif // CONFIG_JNT_COMP
#if CONFIG_JNT_COMP
aom_upsampled_pred_c(comp_pred, width, height, subpel_x_q3, subpel_y_q3, ref,
ref_stride);
#else
aom_upsampled_pred(comp_pred, width, height, subpel_x_q3, subpel_y_q3, ref,
ref_stride);
#endif // CONFIG_JNT_COMP
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
#if CONFIG_JNT_COMP
int tmp = pred[j] * fwd_offset + comp_pred[j] * bck_offset;
tmp = (int)(0.5 + tmp / sum);
if (tmp > 255) tmp = 255;
comp_pred[j] = (uint8_t)tmp;
#else
comp_pred[j] = ROUND_POWER_OF_TWO(comp_pred[j] + pred[j], 1);
#endif // CONFIG_JNT_COMP
}
comp_pred += width;
pred += width;
......
......@@ -2840,6 +2840,59 @@ AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
NULL, aom_sad64x128x4d)
#endif // CONFIG_EXT_PARTITION
#if CONFIG_JNT_COMP
BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg_c, aom_variance32x16,
aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL,
aom_sad32x16x4d)
BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg_c, aom_variance16x32,
aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL,
aom_sad16x32x4d)
BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg_c, aom_variance64x32,
aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL,
aom_sad64x32x4d)
BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg_c, aom_variance32x64,
aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL,
aom_sad32x64x4d)
BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg_c, aom_variance32x32,
aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32,
aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d)
BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg_c, aom_variance64x64,
aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64,
aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d)
BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg_c, aom_variance16x16,
aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16,
aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d)
BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg_c, aom_variance16x8,
aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3,
aom_sad16x8x8, aom_sad16x8x4d)
BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg_c, aom_variance8x16,
aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3,
aom_sad8x16x8, aom_sad8x16x4d)
BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg_c, aom_variance8x8,
aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3,
aom_sad8x8x8, aom_sad8x8x4d)
BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg_c, aom_variance8x4,
aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL,
aom_sad8x4x8, aom_sad8x4x4d)
BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg_c, aom_variance4x8,
aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL,
aom_sad4x8x8, aom_sad4x8x4d)
BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg_c, aom_variance4x4,
aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3,
aom_sad4x4x8, aom_sad4x4x4d)
#else
BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16,
aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL,
aom_sad32x16x4d)
......@@ -2891,6 +2944,7 @@ AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4,
aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3,
aom_sad4x4x8, aom_sad4x4x4d)
#endif // CONFIG_JNT_COMP
BFP(BLOCK_2X2, NULL, NULL, aom_variance2x2, NULL, NULL, NULL, NULL, NULL)
BFP(BLOCK_2X4, NULL, NULL, aom_variance2x4, NULL, NULL, NULL, NULL, NULL)
......
......@@ -349,7 +349,11 @@ static unsigned int setup_center_error(
aom_comp_mask_pred(comp_pred, second_pred, w, h, y + offset, y_stride,
mask, mask_stride, invert_mask);
else
#if CONFIG_JNT_COMP
aom_comp_avg_pred_c(comp_pred, second_pred, w, h, y + offset, y_stride);
#else
aom_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride);
#endif // CONFIG_JNT_COMP
besterr = vfp->vf(comp_pred, w, src, src_stride, sse1);
}
} else {
......@@ -365,7 +369,11 @@ static unsigned int setup_center_error(
aom_comp_mask_pred(comp_pred, second_pred, w, h, y + offset, y_stride,
mask, mask_stride, invert_mask);
else
#if CONFIG_JNT_COMP
aom_comp_avg_pred_c(comp_pred, second_pred, w, h, y + offset, y_stride);
#else
aom_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride);
#endif // CONFIG_JNT_COMP
besterr = vfp->vf(comp_pred, w, src, src_stride, sse1);
} else {
besterr = vfp->vf(y + offset, y_stride, src, src_stride, sse1);
......@@ -663,8 +671,13 @@ static int upsampled_pref_error(const MACROBLOCKD *xd,
subpel_y_q3, y, y_stride, mask,
mask_stride, invert_mask);
else
aom_comp_avg_upsampled_pred(pred, second_pred, w, h, subpel_x_q3,
subpel_y_q3, y, y_stride);
#if CONFIG_JNT_COMP
aom_comp_avg_upsampled_pred_c(pred, second_pred, w, h, subpel_x_q3,
subpel_y_q3, y, y_stride);
#else
aom_comp_avg_upsampled_pred(pred, second_pred, w, h, subpel_x_q3,
subpel_y_q3, y, y_stride);
#endif // CONFIG_JNT_COMP
} else {
aom_upsampled_pred(pred, w, h, subpel_x_q3, subpel_y_q3, y, y_stride);
}
......
......@@ -5796,6 +5796,51 @@ static int check_best_zero_mv(
return 1;
}
#if CONFIG_JNT_COMP
static void jnt_comp_weight_assign(const AV1_COMMON *cm,
const MB_MODE_INFO *mbmi, int order_idx,
uint8_t *second_pred) {
int bck_idx = cm->frame_refs[mbmi->ref_frame[0] - LAST_FRAME].idx;
int fwd_idx = cm->frame_refs[mbmi->ref_frame[1] - LAST_FRAME].idx;
int bck_frame_index = 0, fwd_frame_index = 0;
int cur_frame_index = cm->cur_frame->cur_frame_offset;
if (bck_idx >= 0) {
bck_frame_index = cm->buffer_pool->frame_bufs[bck_idx].cur_frame_offset;
}
if (fwd_idx >= 0) {
fwd_frame_index = cm->buffer_pool->frame_bufs[fwd_idx].cur_frame_offset;
}
const double fwd = abs(fwd_frame_index - cur_frame_index);
const double bck = abs(cur_frame_index - bck_frame_index);
int order;
double ratio;
if (COMPOUND_WEIGHT_MODE == DIST) {
if (fwd > bck) {
ratio = (bck != 0) ? fwd / bck : 5.0;
order = 0;
} else {
ratio = (fwd != 0) ? bck / fwd : 5.0;
order = 1;
}
int quant_dist_idx;
for (quant_dist_idx = 0; quant_dist_idx < 4; ++quant_dist_idx) {
if (ratio < quant_dist_category[quant_dist_idx]) break;
}
second_pred[4096] =
quant_dist_lookup_table[order_idx][quant_dist_idx][order];
second_pred[4097] =
quant_dist_lookup_table[order_idx][quant_dist_idx][1 - order];
} else {
second_pred[4096] = (DIST_PRECISION >> 1);
second_pred[4097] = (DIST_PRECISION >> 1);
}
}
#endif // CONFIG_JNT_COMP
static void joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
BLOCK_SIZE bsize, int_mv *frame_mv,
#if CONFIG_COMPOUND_SINGLEREF
......@@ -5864,9 +5909,14 @@ static void joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
// Prediction buffer from second frame.
#if CONFIG_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint16_t, second_pred_alloc_16[MAX_SB_SQUARE]);
#if CONFIG_JNT_COMP
DECLARE_ALIGNED(16, uint16_t, second_pred_alloc_16[MAX_SB_SQUARE + 2]);
uint8_t *second_pred;
#else
DECLARE_ALIGNED(16, uint16_t, second_pred_alloc_16[MAX_SB_SQUARE]);
uint8_t *second_pred;
#endif // CONFIG_JNT_COMP
#else // CONFIG_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint8_t, second_pred[MAX_SB_SQUARE]);
#endif // CONFIG_HIGHBITDEPTH
(void)ref_mv_sub8x8;
......@@ -5942,6 +5992,10 @@ static void joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
// found for the 'other' reference frame is factored in.
const int plane = 0;
ConvolveParams conv_params = get_conv_params(!id, 0, plane);
#if CONFIG_JNT_COMP
conv_params.fwd_offset = -1;
conv_params.bck_offset = -1;
#endif
#if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
WarpTypesAllowed warp_types;
#if CONFIG_GLOBAL_MOTION
......@@ -5962,6 +6016,9 @@ static void joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
? &frame_mv[refs[!id]].as_mv
: &frame_comp_mv[refs[0]].as_mv;
#endif // CONFIG_COMPOUND_SINGLEREF
#if CONFIG_JNT_COMP
InterpFilters interp_filters = EIGHTTAP_REGULAR;
#endif // CONFIG_JNT_COMP
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
......@@ -5973,7 +6030,11 @@ static void joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
#else // !(CONFIG_COMPOUND_SINGLEREF)
&frame_mv[refs[!id]].as_mv,
#endif // CONFIG_COMPOUND_SINGLEREF
#if CONFIG_JNT_COMP
&sf, pw, ph, 0, interp_filters,
#else
&sf, pw, ph, 0, mbmi->interp_filters,
#endif // CONFIG_JNT_COMP
#if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
&warp_types, p_col, p_row,
#endif // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
......@@ -5988,7 +6049,11 @@ static void joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
#else // !(CONFIG_COMPOUND_SINGLEREF)
&frame_mv[refs[!id]].as_mv,
#endif // CONFIG_COMPOUND_SINGLEREF
&sf, pw, ph, &conv_params, mbmi->interp_filters,
#if CONFIG_JNT_COMP
&sf, pw, ph, &conv_params, interp_filters,
#else
&sf, pw, ph, &conv_params, mbmi->interp_filters,
#endif // CONFIG_JNT_COMP
#if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
&warp_types, p_col, p_row, plane, !id,
#endif // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
......@@ -5997,6 +6062,11 @@ static void joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
}
#endif // CONFIG_HIGHBITDEPTH
#if CONFIG_JNT_COMP
const int order_idx = id != 0;
jnt_comp_weight_assign(cm, mbmi, order_idx, second_pred);
#endif // CONFIG_JNT_COMP
// Do compound motion search on the current reference frame.
if (id) xd->plane[plane].pre[0] = ref_yv12[id];
av1_set_mv_search_range(&x->mv_limits, &ref_mv[id].as_mv);
......@@ -6744,6 +6814,10 @@ static void build_second_inter_pred(const AV1_COMP *cpi, MACROBLOCK *x,
}
#endif // CONFIG_HIGHBITDEPTH
#if CONFIG_JNT_COMP
jnt_comp_weight_assign(cm, mbmi, 0, second_pred);
#endif // CONFIG_JNT_COMP
if (scaled_ref_frame) {
// Restore the prediction frame pointers to their unscaled versions.
int i;
......@@ -6910,7 +6984,11 @@ static void compound_single_motion_search_interinter(
// Prediction buffer from second frame.
#if CONFIG_HIGHBITDEPTH
#if CONFIG_JNT_COMP
DECLARE_ALIGNED(16, uint16_t, second_pred_alloc_16[MAX_SB_SQUARE + 2]);
#else
DECLARE_ALIGNED(16, uint16_t, second_pred_alloc_16[MAX_SB_SQUARE]);
#endif // CONFIG_JNT_COMP
uint8_t *second_pred;
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
second_pred = CONVERT_TO_BYTEPTR(second_pred_alloc_16);
......
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