Commit 9febfc16 authored by Debargha Mukherjee's avatar Debargha Mukherjee

Some refactoring/cleanup of global motion costing

Change-Id: Ib44c713ebcccc621d4f3b9f22e8dbb638c50ff52
parent 49a76560
......@@ -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,
......
......@@ -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;
......
......@@ -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,
......
......@@ -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
......
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