diff --git a/av1/common/mv.h b/av1/common/mv.h index 22a47f763..a02d59866 100644 --- a/av1/common/mv.h +++ b/av1/common/mv.h @@ -102,8 +102,8 @@ typedef struct { #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 18 -#define GM_ABS_TRANS_BITS 18 +#define GM_ABS_ALPHA_BITS 8 +#define GM_ABS_TRANS_BITS 8 #define GM_TRANS_MAX (1 << GM_ABS_TRANS_BITS) #define GM_ALPHA_MAX (1 << GM_ABS_ALPHA_BITS) diff --git a/av1/common/warped_motion.c b/av1/common/warped_motion.c index 146a14d8e..2e550cb0d 100644 --- a/av1/common/warped_motion.c +++ b/av1/common/warped_motion.c @@ -95,11 +95,11 @@ void projectPointsAffine(int16_t *mat, int *points, int *proj, const int n, WARPEDDIFF_PREC_BITS); if (subsampling_y) *(proj++) = ROUND_POWER_OF_TWO_SIGNED( - mat[5] * 2 * x + mat[4] * 2 * y + mat[0] + - (mat[5] + mat[4] - (1 << WARPEDMODEL_PREC_BITS)) / 2, + mat[4] * 2 * x + mat[5] * 2 * y + mat[0] + + (mat[4] + mat[5] - (1 << WARPEDMODEL_PREC_BITS)) / 2, WARPEDDIFF_PREC_BITS + 1); else - *(proj++) = ROUND_POWER_OF_TWO_SIGNED(mat[5] * x + mat[4] * y + mat[0], + *(proj++) = ROUND_POWER_OF_TWO_SIGNED(mat[4] * x + mat[5] * y + mat[0], WARPEDDIFF_PREC_BITS); points += stride_points - 2; proj += stride_proj - 2; diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c index 6e52c79d9..031ddbc72 100644 --- a/av1/decoder/decodeframe.c +++ b/av1/decoder/decodeframe.c @@ -3411,12 +3411,12 @@ static void read_global_motion_params(Global_Motion_Params *params, case GLOBAL_ZERO: break; case GLOBAL_AFFINE: params->motion_params.wmmat[2].as_mv.row = + (aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) * + GM_ALPHA_DECODE_FACTOR); + params->motion_params.wmmat[2].as_mv.col = 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[1].as_mv.row = diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c index 49f1b44c3..6578c0cff 100644 --- a/av1/encoder/bitstream.c +++ b/av1/encoder/bitstream.c @@ -3213,11 +3213,11 @@ static void write_global_motion_params(Global_Motion_Params *params, case GLOBAL_ZERO: break; case GLOBAL_AFFINE: aom_write_primitive_symmetric( - w, (params->motion_params.wmmat[2].as_mv.row >> GM_ALPHA_PREC_DIFF) - - (1 << GM_ALPHA_PREC_BITS), + w, (params->motion_params.wmmat[2].as_mv.row >> GM_ALPHA_PREC_DIFF), GM_ABS_ALPHA_BITS); aom_write_primitive_symmetric( - w, (params->motion_params.wmmat[2].as_mv.col >> GM_ALPHA_PREC_DIFF), + w, (params->motion_params.wmmat[2].as_mv.col >> GM_ALPHA_PREC_DIFF) - + (1 << GM_ALPHA_PREC_BITS), GM_ABS_ALPHA_BITS); // fallthrough intended case GLOBAL_ROTZOOM: diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c index 8796ac9c2..4b93ab65b 100644 --- a/av1/encoder/encodeframe.c +++ b/av1/encoder/encodeframe.c @@ -4479,7 +4479,7 @@ static void refine_integerized_param(WarpedMotionParams *wm, static void convert_to_params(double *H, TransformationType type, int16_t *model) { - int i; + int i, diag_value; int alpha_present = 0; int n_params = n_trans_model_params[type]; model[0] = (int16_t)floor(H[0] * (1 << GM_TRANS_PREC_BITS) + 0.5); @@ -4489,11 +4489,13 @@ static void convert_to_params(double *H, TransformationType type, model[1] = (int16_t)clamp(model[1], GM_TRANS_MIN, GM_TRANS_MAX) * GM_TRANS_DECODE_FACTOR; - // TODO(sarahparker) 1 should be subtracted here for (i = 2; i < n_params; ++i) { + diag_value = ((i && 1) ? (1 << GM_ALPHA_PREC_BITS) : 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; + model[i] = + (int16_t)(clamp(model[i] - diag_value, GM_ALPHA_MIN, GM_ALPHA_MAX) + + diag_value) * + GM_ALPHA_DECODE_FACTOR; alpha_present |= (model[i] != 0); } diff --git a/av1/encoder/global_motion.h b/av1/encoder/global_motion.h index aad8cc4f0..fa4f79117 100644 --- a/av1/encoder/global_motion.h +++ b/av1/encoder/global_motion.h @@ -17,7 +17,17 @@ extern "C" { #endif -// compute global motion parameters between two frames +/* + Computes global motion parameters between two frames. The array + "params" should be length 9, where the first 2 slots are translation + parameters in (row, col) order, and the remaining slots correspond + to values in the transformation matrix of the corresponding motion + model. They are arranged in "params" such that values on the tx-matrix + diagonal have odd numbered indices so the folowing matrix: + A | B + C | D + would produce params = [trans row, trans col, B, A, C, D] +*/ int compute_global_motion_feature_based(TransformationType type, YV12_BUFFER_CONFIG *frm, YV12_BUFFER_CONFIG *ref, diff --git a/av1/encoder/ransac.c b/av1/encoder/ransac.c index a3072bc02..81c1c21eb 100644 --- a/av1/encoder/ransac.c +++ b/av1/encoder/ransac.c @@ -615,8 +615,8 @@ static void denormalizeAffine(double *H, double *T1, double *T2) { H[1] = Ha[2]; H[2] = Ha[1]; H[3] = Ha[0]; - H[4] = Ha[4]; - H[5] = Ha[3]; + H[4] = Ha[3]; + H[5] = Ha[4]; } static void denormalizeRotZoom(double *H, double *T1, double *T2) {