Commit 5ebdf40d authored by Sarah Parker's avatar Sarah Parker Committed by Gerrit Code Review
Browse files

Merge "Add global motion experiment to rdopt" into nextgenv2

parents 40da2c89 e5299865
......@@ -14,9 +14,6 @@
#include "av1/common/common.h"
#include "aom_dsp/aom_filter.h"
#if CONFIG_GLOBAL_MOTION
#include "av1/common/warped_motion.h"
#endif // CONFIG_GLOBAL_MOTION
#ifdef __cplusplus
extern "C" {
......@@ -37,6 +34,41 @@ typedef struct mv32 {
int32_t col;
} MV32;
#if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
// Bits of precision used for the model
#define WARPEDMODEL_PREC_BITS 8
#define WARPEDMODEL_ROW3HOMO_PREC_BITS 12
// Bits of subpel precision for warped interpolation
#define WARPEDPIXEL_PREC_BITS 6
#define WARPEDPIXEL_PREC_SHIFTS (1 << WARPEDPIXEL_PREC_BITS)
// Taps for ntap filter
#define WARPEDPIXEL_FILTER_TAPS 6
// Precision of filter taps
#define WARPEDPIXEL_FILTER_BITS 7
#define WARPEDDIFF_PREC_BITS (WARPEDMODEL_PREC_BITS - WARPEDPIXEL_PREC_BITS)
typedef enum {
UNKNOWN_TRANSFORM = -1,
HOMOGRAPHY, // homography, 8-parameter
AFFINE, // affine, 6-parameter
ROTZOOM, // simplified affine with rotation and zoom only, 4-parameter
TRANSLATION, // translational motion 2-parameter
TRANS_TYPES
} TransformationType;
// number of parameters used by each transformation in TransformationTypes
static const int n_trans_model_params[TRANS_TYPES] = { 9, 6, 4, 2 };
typedef struct {
TransformationType wmtype;
int_mv wmmat[4]; // For homography wmmat[9] is assumed to be 1
} WarpedMotionParams;
#endif // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
#if CONFIG_GLOBAL_MOTION
// ALPHA here refers to parameters a and b in rotzoom model:
// | a b|
......@@ -62,16 +94,16 @@ typedef struct mv32 {
//
// XX_MIN, XX_MAX are also computed to avoid repeated computation
#define GM_TRANS_PREC_BITS 5
#define GM_TRANS_PREC_BITS 8
#define GM_TRANS_PREC_DIFF (WARPEDMODEL_PREC_BITS - GM_TRANS_PREC_BITS)
#define GM_TRANS_DECODE_FACTOR (1 << GM_TRANS_PREC_DIFF)
#define GM_ALPHA_PREC_BITS 5
#define GM_ALPHA_PREC_BITS 8
#define GM_ALPHA_PREC_DIFF (WARPEDMODEL_PREC_BITS - GM_ALPHA_PREC_BITS)
#define GM_ALPHA_DECODE_FACTOR (1 << GM_ALPHA_PREC_DIFF)
#define GM_ABS_ALPHA_BITS 8
#define GM_ABS_TRANS_BITS 8
#define GM_ABS_ALPHA_BITS 18
#define GM_ABS_TRANS_BITS 18
#define GM_TRANS_MAX (1 << GM_ABS_TRANS_BITS)
#define GM_ALPHA_MAX (1 << GM_ABS_ALPHA_BITS)
......@@ -103,11 +135,10 @@ static INLINE TransformationType gm_to_trans_type(GLOBAL_MOTION_TYPE gmtype) {
}
static INLINE GLOBAL_MOTION_TYPE get_gmtype(const Global_Motion_Params *gm) {
if (gm->motion_params.wmmat[4] == 0 && gm->motion_params.wmmat[5] == 0) {
if (gm->motion_params.wmmat[2] == 0 && gm->motion_params.wmmat[3] == 0) {
return ((gm->motion_params.wmmat[0] | gm->motion_params.wmmat[1])
? GLOBAL_TRANSLATION
: GLOBAL_ZERO);
if (!gm->motion_params.wmmat[2].as_int) {
if (!gm->motion_params.wmmat[1].as_int) {
return (gm->motion_params.wmmat[0].as_int ? GLOBAL_TRANSLATION
: GLOBAL_ZERO);
} else {
return GLOBAL_ROTZOOM;
}
......
......@@ -26,7 +26,7 @@ static ProjectPointsType get_project_points_type(TransformationType type) {
}
}
void projectPointsTranslation(int *mat, int *points, int *proj, const int n,
void projectPointsTranslation(int16_t *mat, int *points, int *proj, const int n,
const int stride_points, const int stride_proj,
const int subsampling_x,
const int subsampling_y) {
......@@ -35,24 +35,24 @@ void projectPointsTranslation(int *mat, int *points, int *proj, const int n,
const int x = *(points++), y = *(points++);
if (subsampling_x)
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(
((x << (WARPEDMODEL_PREC_BITS + 1)) + mat[0]),
((x << (WARPEDMODEL_PREC_BITS + 1)) + mat[1]),
WARPEDDIFF_PREC_BITS + 1);
else
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(
((x << WARPEDMODEL_PREC_BITS)) + mat[0], WARPEDDIFF_PREC_BITS);
((x << WARPEDMODEL_PREC_BITS) + mat[1]), WARPEDDIFF_PREC_BITS);
if (subsampling_y)
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(
((y << (WARPEDMODEL_PREC_BITS + 1)) + mat[1]),
((y << (WARPEDMODEL_PREC_BITS + 1)) + mat[0]),
WARPEDDIFF_PREC_BITS + 1);
else
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(
((y << WARPEDMODEL_PREC_BITS)) + mat[1], WARPEDDIFF_PREC_BITS);
((y << WARPEDMODEL_PREC_BITS)) + mat[0], WARPEDDIFF_PREC_BITS);
points += stride_points - 2;
proj += stride_proj - 2;
}
}
void projectPointsRotZoom(int *mat, int *points, int *proj, const int n,
void projectPointsRotZoom(int16_t *mat, int *points, int *proj, const int n,
const int stride_points, const int stride_proj,
const int subsampling_x, const int subsampling_y) {
int i;
......@@ -60,26 +60,26 @@ void projectPointsRotZoom(int *mat, int *points, int *proj, const int n,
const int x = *(points++), y = *(points++);
if (subsampling_x)
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(
mat[2] * 2 * x + mat[3] * 2 * y + mat[0] +
(mat[2] + mat[3] - (1 << WARPEDMODEL_PREC_BITS)) / 2,
mat[3] * 2 * x + mat[2] * 2 * y + mat[1] +
(mat[3] + mat[2] - (1 << WARPEDMODEL_PREC_BITS)) / 2,
WARPEDDIFF_PREC_BITS + 1);
else
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(mat[2] * x + mat[3] * y + mat[0],
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(mat[3] * x + mat[2] * y + mat[1],
WARPEDDIFF_PREC_BITS);
if (subsampling_y)
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(
-mat[3] * 2 * x + mat[2] * 2 * y + mat[1] +
(-mat[3] + mat[2] - (1 << WARPEDMODEL_PREC_BITS)) / 2,
-mat[2] * 2 * x + mat[3] * 2 * y + mat[0] +
(-mat[2] + mat[3] - (1 << WARPEDMODEL_PREC_BITS)) / 2,
WARPEDDIFF_PREC_BITS + 1);
else
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(-mat[3] * x + mat[2] * y + mat[1],
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(-mat[2] * x + mat[3] * y + mat[0],
WARPEDDIFF_PREC_BITS);
points += stride_points - 2;
proj += stride_proj - 2;
}
}
void projectPointsAffine(int *mat, int *points, int *proj, const int n,
void projectPointsAffine(int16_t *mat, int *points, int *proj, const int n,
const int stride_points, const int stride_proj,
const int subsampling_x, const int subsampling_y) {
int i;
......@@ -87,26 +87,26 @@ void projectPointsAffine(int *mat, int *points, int *proj, const int n,
const int x = *(points++), y = *(points++);
if (subsampling_x)
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(
mat[2] * 2 * x + mat[3] * 2 * y + mat[0] +
(mat[2] + mat[3] - (1 << WARPEDMODEL_PREC_BITS)) / 2,
mat[3] * 2 * x + mat[2] * 2 * y + mat[1] +
(mat[3] + mat[2] - (1 << WARPEDMODEL_PREC_BITS)) / 2,
WARPEDDIFF_PREC_BITS + 1);
else
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(mat[2] * x + mat[3] * y + mat[0],
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(mat[3] * x + mat[2] * y + mat[1],
WARPEDDIFF_PREC_BITS);
if (subsampling_y)
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(
mat[4] * 2 * x + mat[5] * 2 * y + mat[1] +
(mat[4] + mat[5] - (1 << WARPEDMODEL_PREC_BITS)) / 2,
mat[5] * 2 * x + mat[4] * 2 * y + mat[0] +
(mat[5] + mat[4] - (1 << WARPEDMODEL_PREC_BITS)) / 2,
WARPEDDIFF_PREC_BITS + 1);
else
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(mat[4] * x + mat[5] * y + mat[1],
*(proj++) = ROUND_POWER_OF_TWO_SIGNED(mat[5] * x + mat[4] * y + mat[0],
WARPEDDIFF_PREC_BITS);
points += stride_points - 2;
proj += stride_proj - 2;
}
}
void projectPointsHomography(int *mat, int *points, int *proj, const int n,
void projectPointsHomography(int16_t *mat, int *points, int *proj, const int n,
const int stride_points, const int stride_proj,
const int subsampling_x, const int subsampling_y) {
int i;
......@@ -117,11 +117,11 @@ void projectPointsHomography(int *mat, int *points, int *proj, const int n,
x = (subsampling_x ? 4 * x + 1 : 2 * x);
y = (subsampling_y ? 4 * y + 1 : 2 * y);
Z = (mat[6] * x + mat[7] * y + (1 << (WARPEDMODEL_ROW3HOMO_PREC_BITS + 1)));
xp = (mat[0] * x + mat[1] * y + 2 * mat[2])
Z = (mat[7] * x + mat[6] * y + (1 << (WARPEDMODEL_ROW3HOMO_PREC_BITS + 1)));
xp = (mat[1] * x + mat[0] * y + 2 * mat[3])
<< (WARPEDPIXEL_PREC_BITS + WARPEDMODEL_ROW3HOMO_PREC_BITS -
WARPEDMODEL_PREC_BITS);
yp = (mat[3] * x + mat[4] * y + 2 * mat[5])
yp = (mat[2] * x + mat[5] * y + 2 * mat[4])
<< (WARPEDPIXEL_PREC_BITS + WARPEDMODEL_ROW3HOMO_PREC_BITS -
WARPEDMODEL_PREC_BITS);
......@@ -483,7 +483,8 @@ static double highbd_warp_erroradv(WarpedMotionParams *wm, uint8_t *ref8,
int in[2], out[2];
in[0] = j;
in[1] = i;
projectpoints(wm->wmmat, in, out, 1, 2, 2, subsampling_x, subsampling_y);
projectpoints((int16_t *)wm->wmmat, in, out, 1, 2, 2, subsampling_x,
subsampling_y);
out[0] = ROUND_POWER_OF_TWO_SIGNED(out[0] * x_scale, 4);
out[1] = ROUND_POWER_OF_TWO_SIGNED(out[1] * y_scale, 4);
gm_err = dst[(j - p_col) + (i - p_row) * p_stride] -
......@@ -514,7 +515,8 @@ static void highbd_warp_plane(WarpedMotionParams *wm, uint8_t *ref8, int width,
int in[2], out[2];
in[0] = j;
in[1] = i;
projectpoints(wm->wmmat, in, out, 1, 2, 2, subsampling_x, subsampling_y);
projectpoints((int16_t *)wm->wmmat, in, out, 1, 2, 2, subsampling_x,
subsampling_y);
out[0] = ROUND_POWER_OF_TWO_SIGNED(out[0] * x_scale, 4);
out[1] = ROUND_POWER_OF_TWO_SIGNED(out[1] * y_scale, 4);
pred[(j - p_col) + (i - p_row) * p_stride] = highbd_warp_interpolate(
......@@ -538,7 +540,8 @@ static double warp_erroradv(WarpedMotionParams *wm, uint8_t *ref, int width,
int in[2], out[2];
in[0] = j;
in[1] = i;
projectpoints(wm->wmmat, in, out, 1, 2, 2, subsampling_x, subsampling_y);
projectpoints((int16_t *)wm->wmmat, in, out, 1, 2, 2, subsampling_x,
subsampling_y);
out[0] = ROUND_POWER_OF_TWO_SIGNED(out[0] * x_scale, 4);
out[1] = ROUND_POWER_OF_TWO_SIGNED(out[1] * y_scale, 4);
gm_err = dst[(j - p_col) + (i - p_row) * p_stride] -
......@@ -565,7 +568,8 @@ static void warp_plane(WarpedMotionParams *wm, uint8_t *ref, int width,
int in[2], out[2];
in[0] = j;
in[1] = i;
projectpoints(wm->wmmat, in, out, 1, 2, 2, subsampling_x, subsampling_y);
projectpoints((int16_t *)wm->wmmat, in, out, 1, 2, 2, subsampling_x,
subsampling_y);
out[0] = ROUND_POWER_OF_TWO_SIGNED(out[0] * x_scale, 4);
out[1] = ROUND_POWER_OF_TWO_SIGNED(out[1] * y_scale, 4);
pred[(j - p_col) + (i - p_row) * p_stride] =
......@@ -620,22 +624,28 @@ void av1_integerize_model(const double *model, TransformationType wmtype,
switch (wmtype) {
case HOMOGRAPHY:
assert(fabs(model[8] - 1.0) < 1e-12);
wm->wmmat[7] =
(int)lrint(model[7] * (1 << WARPEDMODEL_ROW3HOMO_PREC_BITS));
wm->wmmat[6] =
(int)lrint(model[6] * (1 << WARPEDMODEL_ROW3HOMO_PREC_BITS));
wm->wmmat[3].as_mv.row =
(int16_t)lrint(model[6] * (1 << WARPEDMODEL_ROW3HOMO_PREC_BITS));
wm->wmmat[3].as_mv.col =
(int16_t)lrint(model[7] * (1 << WARPEDMODEL_ROW3HOMO_PREC_BITS));
/* fallthrough intended */
case AFFINE:
wm->wmmat[5] = (int)lrint(model[5] * (1 << WARPEDMODEL_PREC_BITS));
wm->wmmat[4] = (int)lrint(model[4] * (1 << WARPEDMODEL_PREC_BITS));
wm->wmmat[2].as_mv.row =
(int16_t)lrint(model[4] * (1 << WARPEDMODEL_PREC_BITS));
wm->wmmat[2].as_mv.col =
(int16_t)lrint(model[5] * (1 << WARPEDMODEL_PREC_BITS));
/* fallthrough intended */
case ROTZOOM:
wm->wmmat[3] = (int)lrint(model[3] * (1 << WARPEDMODEL_PREC_BITS));
wm->wmmat[2] = (int)lrint(model[2] * (1 << WARPEDMODEL_PREC_BITS));
wm->wmmat[1].as_mv.row =
(int16_t)lrint(model[2] * (1 << WARPEDMODEL_PREC_BITS));
wm->wmmat[1].as_mv.col =
(int16_t)lrint(model[3] * (1 << WARPEDMODEL_PREC_BITS));
/* fallthrough intended */
case TRANSLATION:
wm->wmmat[1] = (int)lrint(model[1] * (1 << WARPEDMODEL_PREC_BITS));
wm->wmmat[0] = (int)lrint(model[0] * (1 << WARPEDMODEL_PREC_BITS));
wm->wmmat[0].as_mv.row =
(int16_t)lrint(model[0] * (1 << WARPEDMODEL_PREC_BITS));
wm->wmmat[0].as_mv.col =
(int16_t)lrint(model[1] * (1 << WARPEDMODEL_PREC_BITS));
break;
default: assert(0 && "Invalid TransformationType");
}
......
......@@ -20,6 +20,7 @@
#include "./aom_config.h"
#include "aom_ports/mem.h"
#include "aom_dsp/aom_dsp_common.h"
#include "av1/common/mv.h"
// Bits of precision used for the model
#define WARPEDMODEL_PREC_BITS 8
......@@ -37,49 +38,36 @@
#define WARPEDDIFF_PREC_BITS (WARPEDMODEL_PREC_BITS - WARPEDPIXEL_PREC_BITS)
typedef void (*ProjectPointsType)(int *mat, int *points, int *proj, const int n,
const int stride_points,
typedef void (*ProjectPointsType)(int16_t *mat, int *points, int *proj,
const int n, const int stride_points,
const int stride_proj,
const int subsampling_x,
const int subsampling_y);
void projectPointsHomography(int *mat, int *points, int *proj, const int n,
void projectPointsHomography(int16_t *mat, int *points, int *proj, const int n,
const int stride_points, const int stride_proj,
const int subsampling_x, const int subsampling_y);
void projectPointsAffine(int *mat, int *points, int *proj, const int n,
void projectPointsAffine(int16_t *mat, int *points, int *proj, const int n,
const int stride_points, const int stride_proj,
const int subsampling_x, const int subsampling_y);
void projectPointsRotZoom(int *mat, int *points, int *proj, const int n,
void projectPointsRotZoom(int16_t *mat, int *points, int *proj, const int n,
const int stride_points, const int stride_proj,
const int subsampling_x, const int subsampling_y);
void projectPointsTranslation(int *mat, int *points, int *proj, const int n,
void projectPointsTranslation(int16_t *mat, int *points, int *proj, const int n,
const int stride_points, const int stride_proj,
const int subsampling_x, const int subsampling_y);
typedef enum {
UNKNOWN_TRANSFORM = -1,
HOMOGRAPHY, // homography, 8-parameter
AFFINE, // affine, 6-parameter
ROTZOOM, // simplified affine with rotation and zoom only, 4-parameter
TRANSLATION, // translational motion 2-parameter
TRANS_TYPES
} TransformationType;
// number of parameters used by each transformation in TransformationTypes
static const int n_trans_model_params[TRANS_TYPES] = { 9, 6, 4, 2 };
typedef struct {
TransformationType wmtype;
int wmmat[8]; // For homography wmmat[9] is assumed to be 1
} WarpedMotionParams;
double av1_warp_erroradv(WarpedMotionParams *wm,
#if CONFIG_AOM_HIGHBITDEPTH
int use_hbd, int bd,
#endif // CONFIG_AOM_HIGHBITDEPTH
uint8_t *ref, int width, int height, int stride,
uint8_t *dst, int p_col, int p_row, int p_width,
int p_height, int p_stride, int subsampling_x,
int subsampling_y, int x_scale, int y_scale);
#if CONFIG_VP9_HIGHBITDEPTH
int use_hbd, int bd,
#endif // CONFIG_VP9_HIGHBITDEPTH
uint8_t *ref, int width, int height, int stride,
uint8_t *dst, int p_col, int p_row, int p_width,
int p_height, int p_stride, int subsampling_x,
int subsampling_y, int x_scale, int y_scale);
void av1_warp_plane(WarpedMotionParams *wm,
#if CONFIG_AOM_HIGHBITDEPTH
......
......@@ -3411,28 +3411,28 @@ static void read_global_motion_params(Global_Motion_Params *params,
switch (gmtype) {
case GLOBAL_ZERO: break;
case GLOBAL_AFFINE:
params->motion_params.wmmat[4] =
(aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) *
GM_ALPHA_DECODE_FACTOR);
params->motion_params.wmmat[5] =
params->motion_params.wmmat[2].as_mv.row =
aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) *
GM_ALPHA_DECODE_FACTOR +
(1 << WARPEDMODEL_PREC_BITS);
params->motion_params.wmmat[2].as_mv.col =
(aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) *
GM_ALPHA_DECODE_FACTOR);
// fallthrough intended
case GLOBAL_ROTZOOM:
params->motion_params.wmmat[2] =
params->motion_params.wmmat[1].as_mv.row =
aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) *
GM_ALPHA_DECODE_FACTOR;
params->motion_params.wmmat[1].as_mv.col =
(aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) *
GM_ALPHA_DECODE_FACTOR) +
(1 << WARPEDMODEL_PREC_BITS);
params->motion_params.wmmat[3] =
aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) *
GM_ALPHA_DECODE_FACTOR;
// fallthrough intended
case GLOBAL_TRANSLATION:
params->motion_params.wmmat[0] =
params->motion_params.wmmat[0].as_mv.row =
aom_read_primitive_symmetric(r, GM_ABS_TRANS_BITS) *
GM_TRANS_DECODE_FACTOR;
params->motion_params.wmmat[1] =
params->motion_params.wmmat[0].as_mv.col =
aom_read_primitive_symmetric(r, GM_ABS_TRANS_BITS) *
GM_TRANS_DECODE_FACTOR;
break;
......@@ -3446,6 +3446,14 @@ static void read_global_motion(AV1_COMMON *cm, aom_reader *r) {
for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) {
read_global_motion_params(&cm->global_motion[frame],
cm->fc->global_motion_types_prob, r);
/*
printf("Dec Ref %d [%d]: %d %d %d %d\n",
frame, cm->current_video_frame,
cm->global_motion[frame].motion_params.wmmat[0].as_mv.row,
cm->global_motion[frame].motion_params.wmmat[0].as_mv.col,
cm->global_motion[frame].motion_params.wmmat[1].as_mv.row,
cm->global_motion[frame].motion_params.wmmat[1].as_mv.col);
*/
}
}
#endif // CONFIG_GLOBAL_MOTION
......
......@@ -939,6 +939,7 @@ static INLINE int is_mv_valid(const MV *mv) {
static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
PREDICTION_MODE mode,
MV_REFERENCE_FRAME ref_frame[2],
#if CONFIG_REF_MV
int block,
#endif
......@@ -953,6 +954,7 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
int_mv *pred_mv =
(bsize >= BLOCK_8X8) ? mbmi->pred_mv : xd->mi[0]->bmi[block].pred_mv_s8;
#endif
(void)ref_frame;
switch (mode) {
#if CONFIG_EXT_INTER
......@@ -1007,8 +1009,16 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
break;
}
case ZEROMV: {
#if CONFIG_GLOBAL_MOTION
mv[0].as_int =
cm->global_motion[ref_frame[0]].motion_params.wmmat[0].as_int;
if (is_compound)
mv[1].as_int =
cm->global_motion[ref_frame[1]].motion_params.wmmat[0].as_int;
#else
mv[0].as_int = 0;
if (is_compound) mv[1].as_int = 0;
#endif // CONFIG_GLOBAL_MOTION
#if CONFIG_REF_MV
pred_mv[0].as_int = 0;
......@@ -1429,7 +1439,7 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
(void)ref_mv_s8;
#endif
if (!assign_mv(cm, xd, b_mode,
if (!assign_mv(cm, xd, b_mode, mbmi->ref_frame,
#if CONFIG_REF_MV
j,
#endif
......@@ -1481,7 +1491,7 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
}
xd->corrupted |=
!assign_mv(cm, xd, mbmi->mode,
!assign_mv(cm, xd, mbmi->mode, mbmi->ref_frame,
#if CONFIG_REF_MV
0,
#endif
......
......@@ -3196,29 +3196,29 @@ static void write_global_motion_params(Global_Motion_Params *params,
switch (gmtype) {
case GLOBAL_ZERO: break;
case GLOBAL_AFFINE:
av1_write_primitive_symmetric(
w, params->motion_params.wmmat[4] >> GM_ALPHA_PREC_DIFF,
GM_ABS_ALPHA_BITS);
av1_write_primitive_symmetric(
w, (params->motion_params.wmmat[5] >> GM_ALPHA_PREC_DIFF) -
aom_write_primitive_symmetric(
w, (params->motion_params.wmmat[2].as_mv.row >> GM_ALPHA_PREC_DIFF) -
(1 << GM_ALPHA_PREC_BITS),
GM_ABS_ALPHA_BITS);
aom_write_primitive_symmetric(
w, (params->motion_params.wmmat[2].as_mv.col >> GM_ALPHA_PREC_DIFF),
GM_ABS_ALPHA_BITS);
// fallthrough intended
case GLOBAL_ROTZOOM:
aom_write_primitive_symmetric(
w, (params->motion_params.wmmat[2] >> GM_ALPHA_PREC_DIFF) -
(1 << GM_ALPHA_PREC_BITS),
w, (params->motion_params.wmmat[1].as_mv.row >> GM_ALPHA_PREC_DIFF),
GM_ABS_ALPHA_BITS);
aom_write_primitive_symmetric(
w, params->motion_params.wmmat[3] >> GM_ALPHA_PREC_DIFF,
w, (params->motion_params.wmmat[1].as_mv.col >> GM_ALPHA_PREC_DIFF) -
(1 << GM_ALPHA_PREC_BITS),
GM_ABS_ALPHA_BITS);
// fallthrough intended
case GLOBAL_TRANSLATION:
aom_write_primitive_symmetric(
w, params->motion_params.wmmat[0] >> GM_TRANS_PREC_DIFF,
w, (params->motion_params.wmmat[0].as_mv.row >> GM_TRANS_PREC_DIFF),
GM_ABS_TRANS_BITS);
aom_write_primitive_symmetric(
w, params->motion_params.wmmat[1] >> GM_TRANS_PREC_DIFF,
w, (params->motion_params.wmmat[0].as_mv.col >> GM_TRANS_PREC_DIFF),
GM_ABS_TRANS_BITS);
break;
default: assert(0);
......@@ -3234,6 +3234,14 @@ static void write_global_motion(AV1_COMP *cpi, aom_writer *w) {
}
write_global_motion_params(&cm->global_motion[frame],
cm->fc->global_motion_types_prob, w);
/*
printf("Enc Ref %d [%d] (used %d): %d %d %d %d\n",
frame, cm->current_video_frame, cpi->global_motion_used[frame],
cm->global_motion[frame].motion_params.wmmat[0].as_mv.row,
cm->global_motion[frame].motion_params.wmmat[0].as_mv.col,
cm->global_motion[frame].motion_params.wmmat[1].as_mv.row,
cm->global_motion[frame].motion_params.wmmat[1].as_mv.col);
*/
}
}
#endif
......
......@@ -41,6 +41,7 @@
#include "av1/encoder/cost.h"
#endif
#if CONFIG_GLOBAL_MOTION
#include "av1/common/warped_motion.h"
#include "av1/encoder/global_motion.h"
#endif
#include "av1/encoder/encodeframe.h"
......@@ -4402,37 +4403,30 @@ static int input_fpmb_stats(FIRSTPASS_MB_STATS *firstpass_mb_stats,
#if CONFIG_GLOBAL_MOTION
#define MIN_TRANS_THRESH 8
#define GLOBAL_MOTION_ADVANTAGE_THRESH 0.60
#define GLOBAL_MOTION_MODEL ROTZOOM
#define GLOBAL_MOTION_MODEL TRANSLATION
static void convert_to_params(double *H, TransformationType type,
Global_Motion_Params *model) {
int16_t *model) {
int i;
int alpha_present = 0;
int n_params = n_trans_model_params[type];
model->motion_params.wmmat[0] =
(int)floor(H[0] * (1 << GM_TRANS_PREC_BITS) + 0.5);
model->motion_params.wmmat[1] =
(int)floor(H[1] * (1 << GM_TRANS_PREC_BITS) + 0.5);
model->motion_params.wmmat[0] =
clamp(model->motion_params.wmmat[0], GM_TRANS_MIN, GM_TRANS_MAX) *
GM_TRANS_DECODE_FACTOR;
model->motion_params.wmmat[1] =
clamp(model->motion_params.wmmat[1], GM_TRANS_MIN, GM_TRANS_MAX) *
GM_TRANS_DECODE_FACTOR;
model[0] = (int16_t)floor(H[0] * (1 << GM_TRANS_PREC_BITS) + 0.5);
model[1] = (int16_t)floor(H[1] * (1 << GM_TRANS_PREC_BITS) + 0.5);
model[0] = (int16_t)clamp(model[0], GM_TRANS_MIN, GM_TRANS_MAX) *
GM_TRANS_DECODE_FACTOR;
model[1] = (int16_t)clamp(model[1], GM_TRANS_MIN, GM_TRANS_MAX) *
GM_TRANS_DECODE_FACTOR;
for (i = 2; i < n_params; ++i) {
model->motion_params.wmmat[i] =
(int)floor(H[i] * (1 << GM_ALPHA_PREC_BITS) + 0.5);
model->motion_params.wmmat[i] =
clamp(model->motion_params.wmmat[i], GM_ALPHA_MIN, GM_ALPHA_MAX) *
GM_ALPHA_DECODE_FACTOR;
alpha_present |= (model->motion_params.wmmat[i] != 0);
model[i] = (int16_t)floor(H[i] * (1 << GM_ALPHA_PREC_BITS) + 0.5);
model[i] = (int16_t)clamp(model[i], GM_ALPHA_MIN, GM_ALPHA_MAX) *
GM_ALPHA_DECODE_FACTOR;
alpha_present |= (model[i] != 0);
}
if (!alpha_present) {
if (abs(model->motion_params.wmmat[0]) < MIN_TRANS_THRESH &&
abs(model->motion_params.wmmat[1]) < MIN_TRANS_THRESH) {
model->motion_params.wmmat[0] = 0;
model->motion_params.wmmat[1] = 0;
if (abs(model[0]) < MIN_TRANS_THRESH && abs(model[1]) < MIN_TRANS_THRESH) {
model[0] = 0;
model[1] = 0;
}
}
}
......@@ -4440,7 +4434,8 @@ static void convert_to_params(double *H, TransformationType type,
static void convert_model_to_params(double *H, TransformationType type,
Global_Motion_Params *model) {
// TODO(sarahparker) implement for homography
if (type > HOMOGRAPHY) convert_to_params(H, type, model);
if (type > HOMOGRAPHY)
convert_to_params(H, type, (int16_t *)model->motion_params.wmmat);
model->gmtype = get_gmtype(model);
model->motion_params.wmtype = gm_to_trans_type(model->gmtype);
}
...