diff --git a/av1/common/mv.h b/av1/common/mv.h index 22a47f763c41f2ce18c65f87bdfbabff77be950c..a02d59866209ff9615c59f1b743b01659bf560bf 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 146a14d8ed6dd0f6e121c0c4e014c5b64029c4c1..2e550cb0d6fd9835bc8be47c6cdd76313ad52af9 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 6e52c79d947ab8e82f2b6c700562bb3cc6446874..031ddbc72d030fd780cce111fe785c6b3a8a2377 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 49f1b44c38e12ad2c9dd3920b4df953e0bdec675..6578c0cffc9169058ce451ff37da812d71dfac92 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 8796ac9c23614dc4b1d4ef15e87ac0102afb92e4..4b93ab65b4605b838a329de555c91e043b4c712e 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 aad8cc4f0b4b4c09da1a90044297225df5928606..fa4f79117c3c8737361788932aa80a253a56414c 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 a3072bc0237cbaab1bd5862d7a7ce3a89974d9ec..81c1c21eb755688bd9c9a8687e42832591304447 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) {