diff --git a/av1/common/mv.h b/av1/common/mv.h index 53b8d632002ac9a41966fdc3358cbb7572ebd22d..a59132970ad75c3207625dabe366c3ca628d6c84 100644 --- a/av1/common/mv.h +++ b/av1/common/mv.h @@ -128,6 +128,13 @@ typedef struct { #define GM_ALPHA_MIN -GM_ALPHA_MAX #define GM_ROW3HOMO_MIN -GM_ROW3HOMO_MAX +// Bits used for different models +#define GM_IDENTITY_BITS 0 +#define GM_TRANSLATION_BITS ((GM_ABS_TRANS_BITS + 1) * 2) +#define GM_ROTZOOM_BITS (GM_TRANSLATION_BITS + (GM_ABS_ALPHA_BITS + 1) * 2) +#define GM_AFFINE_BITS (GM_ROTZOOM_BITS + (GM_ABS_ALPHA_BITS + 1) * 2) +#define GM_HOMOGRAPHY_BITS (GM_AFFINE_BITS + (GM_ABS_ROW3HOMO_BITS + 1) * 2) + // Convert a global motion translation vector (which may have more bits than a // regular motion vector) into a motion vector static INLINE int_mv gm_get_motion_vector(const WarpedMotionParams *gm, diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h index be64d790f90e19760b459d652bb4582e226b0e64..b20b2a1cdc3fa2ba923e904ca3996f44b6700402 100644 --- a/av1/encoder/encoder.h +++ b/av1/encoder/encoder.h @@ -570,6 +570,9 @@ typedef struct AV1_COMP { #if CONFIG_LOOP_RESTORATION int switchable_restore_cost[RESTORE_SWITCHABLE_TYPES]; #endif // CONFIG_LOOP_RESTORATION +#if CONFIG_GLOBAL_MOTION + int gmtype_cost[TRANS_TYPES]; +#endif // CONFIG_GLOBAL_MOTION int multi_arf_allowed; int multi_arf_enabled; diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c index 6a33acb8e472f980f99608862090d73472c4373c..012386c99d7c9a3902878f96ea4bd0b6e3391d60 100644 --- a/av1/encoder/rd.c +++ b/av1/encoder/rd.c @@ -156,6 +156,10 @@ static void fill_mode_costs(AV1_COMP *cpi) { av1_cost_tokens(cpi->switchable_restore_cost, fc->switchable_restore_prob, av1_switchable_restore_tree); #endif // CONFIG_LOOP_RESTORATION +#if CONFIG_GLOBAL_MOTION + av1_cost_tokens(cpi->gmtype_cost, fc->global_motion_types_prob, + av1_global_motion_types_tree); +#endif // CONFIG_GLOBAL_MOTION } void av1_fill_token_costs(av1_coeff_cost *c, diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c index 08e49696cf569e4eeaba0e45a6d6acc6ec2f41f2..b7faf030d7b9e067dd3a0d93f141f4f69a55fcf5 100644 --- a/av1/encoder/rdopt.c +++ b/av1/encoder/rdopt.c @@ -4336,35 +4336,22 @@ static int get_interinter_compound_type_bits(BLOCK_SIZE bsize, #define GLOBAL_MOTION_COST_AMORTIZATION_BLKS 8 #if GLOBAL_MOTION_COST_AMORTIZATION_BLKS > 0 -static int get_gmbitcost(const WarpedMotionParams *gm, const aom_prob *probs) { - int gmtype_cost[TRANS_TYPES]; - int bits; - TransformationType type = gm->wmtype; - av1_cost_tokens(gmtype_cost, probs, av1_global_motion_types_tree); - switch (type) { - case HOMOGRAPHY: - bits = (GM_ABS_TRANS_BITS + 1) * 2 + (GM_ABS_ALPHA_BITS + 1) * 4 + - (GM_ABS_ROW3HOMO_BITS + 1) * 2; - break; - case AFFINE: - bits = (GM_ABS_TRANS_BITS + 1) * 2 + (GM_ABS_ALPHA_BITS + 1) * 4; - break; - case ROTZOOM: - bits = (GM_ABS_TRANS_BITS + 1) * 2 + (GM_ABS_ALPHA_BITS + 1) * 2; - break; - case TRANSLATION: bits = (GM_ABS_TRANS_BITS + 1) * 2; break; - case IDENTITY: bits = 0; break; - default: assert(0); return 0; - } - assert(type < GLOBAL_TRANS_TYPES); - return bits ? (bits << AV1_PROB_COST_SHIFT) + gmtype_cost[type] : 0; +static int get_gmbitcost(const AV1_COMP *const cpi, + const WarpedMotionParams *gm) { + static const int gm_params_cost[TRANS_TYPES] = { + GM_IDENTITY_BITS, GM_TRANSLATION_BITS, GM_ROTZOOM_BITS, + GM_AFFINE_BITS, GM_HOMOGRAPHY_BITS, + }; + const int cost = (gm_params_cost[gm->wmtype] << AV1_PROB_COST_SHIFT) + + cpi->gmtype_cost[gm->wmtype]; + assert(gm->wmtype < GLOBAL_TRANS_TYPES); + return cost; } #define GLOBAL_MOTION_RATE(ref) \ (cpi->global_motion_used[ref] >= GLOBAL_MOTION_COST_AMORTIZATION_BLKS \ ? 0 \ - : get_gmbitcost(&cm->global_motion[(ref)], \ - cm->fc->global_motion_types_prob) / \ + : get_gmbitcost(cpi, &cm->global_motion[(ref)]) / \ GLOBAL_MOTION_COST_AMORTIZATION_BLKS) #else #define GLOBAL_MOTION_RATE(ref) 0