Commit 11f0e40d authored by Debargha Mukherjee's avatar Debargha Mukherjee

A few fixes for global motion

Handles a rare divisin by 0 case.
Also adds a check on global motion parameters to disable
if the parameters obtained are outside the range that the
shear supports. This fixes a rare assert failure.
Also changes the recode loop threshold somewhat.

Change-Id: I4c6e74b914ac653cd9caa0563d78b0a19a2a8627
parent 4c5b0204
......@@ -139,17 +139,6 @@ typedef struct {
#define GM_ALPHA_MIN -GM_ALPHA_MAX
#define GM_ROW3HOMO_MIN -GM_ROW3HOMO_MAX
// Maximum number of bits used for different models
#define GM_IDENTITY_BITS 0
#define GM_TRANSLATION_BITS ((GM_ABS_TRANS_BITS + 2) * 2)
#define GM_ROTZOOM_BITS (GM_TRANSLATION_BITS + (GM_ABS_ALPHA_BITS + 2) * 2)
#define GM_AFFINE_BITS (GM_ROTZOOM_BITS + (GM_ABS_ALPHA_BITS + 2) * 2)
#define GM_HOMOGRAPHY_BITS (GM_AFFINE_BITS + (GM_ABS_ROW3HOMO_BITS + 2) * 2)
#define GM_HORTRAPEZOID_BITS \
(GM_AFFINE_BITS - GM_ABS_ALPHA_BITS + GM_ABS_ROW3HOMO_BITS)
#define GM_VERTRAPEZOID_BITS \
(GM_AFFINE_BITS - GM_ABS_ALPHA_BITS + GM_ABS_ROW3HOMO_BITS)
// Use global motion parameters for sub8x8 blocks
#define GLOBAL_SUB8X8_USED 0
......
......@@ -661,8 +661,8 @@ static int is_affine_valid(WarpedMotionParams *wm) {
static int is_affine_shear_allowed(int32_t alpha, int32_t beta, int32_t gamma,
int32_t delta) {
if ((4 * abs(alpha) + 7 * abs(beta) >= (1 << WARPEDMODEL_PREC_BITS)) ||
(4 * abs(gamma) + 4 * abs(delta) >= (1 << WARPEDMODEL_PREC_BITS)))
if ((4 * abs(alpha) + 7 * abs(beta) > (1 << WARPEDMODEL_PREC_BITS)) ||
(4 * abs(gamma) + 4 * abs(delta) > (1 << WARPEDMODEL_PREC_BITS)))
return 0;
else
return 1;
......@@ -683,9 +683,15 @@ static int get_shear_params(WarpedMotionParams *wm, int32_t *alpha,
v = ((int64_t)mat[3] * mat[4]) * y;
*delta = mat[5] - ROUND_POWER_OF_TWO_SIGNED_64(v, shift) -
(1 << WARPEDMODEL_PREC_BITS);
if (!is_affine_shear_allowed(*alpha, *beta, *gamma, *delta)) return 0;
return 1;
}
int is_shearable_params(WarpedMotionParams *wm) {
int32_t alpha, beta, gamma, delta;
return get_shear_params(wm, &alpha, &beta, &gamma, &delta);
}
#if CONFIG_AOM_HIGHBITDEPTH
static INLINE void highbd_get_subcolumn(int taps, uint16_t *ref, int32_t *col,
int stride, int x, int y_start) {
......@@ -869,10 +875,6 @@ static void highbd_warp_plane(WarpedMotionParams *wm, uint8_t *ref8, int width,
assert(0 && "Warped motion model is incompatible with shear warp filter");
return;
}
if (!is_affine_shear_allowed(alpha, beta, gamma, delta)) {
assert(0 && "Warped motion model is incompatible with shear warp filter");
return;
}
for (i = p_row; i < p_row + p_height; i += 8) {
for (j = p_col; j < p_col + p_width; j += 8) {
......@@ -1204,10 +1206,6 @@ static void warp_plane(WarpedMotionParams *wm, uint8_t *ref, int width,
assert(0 && "Warped motion model is incompatible with shear warp filter");
return;
}
if (!is_affine_shear_allowed(alpha, beta, gamma, delta)) {
assert(0 && "Warped motion model is incompatible with shear warp filter");
return;
}
// printf("%d %d %d %d\n", mat[2], mat[3], mat[4], mat[5]);
av1_warp_affine(mat, ref, width, height, stride, pred, p_col, p_row,
......@@ -1561,7 +1559,6 @@ int find_projection(const int np, int *pts1, int *pts2, BLOCK_SIZE bsize,
// check compatibility with the fast warp filter
int32_t alpha, beta, gamma, delta;
if (!get_shear_params(wm_params, &alpha, &beta, &gamma, &delta)) return 1;
if (!is_affine_shear_allowed(alpha, beta, gamma, delta)) return 1;
}
}
......
......@@ -89,4 +89,6 @@ void av1_warp_plane(WarpedMotionParams *wm,
int find_projection(const int np, int *pts1, int *pts2, BLOCK_SIZE bsize,
int mvy, int mvx, WarpedMotionParams *wm_params, int mi_row,
int mi_col);
int is_shearable_params(WarpedMotionParams *wm);
#endif // AV1_COMMON_WARPED_MOTION_H_
......@@ -5139,6 +5139,9 @@ static void encode_frame_internal(AV1_COMP *cpi) {
}
}
}
if (cm->global_motion[frame].wmtype <= AFFINE)
if (!is_shearable_params(&cm->global_motion[frame]))
set_default_gmparams(&cm->global_motion[frame]);
// If the best error advantage found doesn't meet the threshold for
// this motion type, revert to IDENTITY.
......
......@@ -3038,7 +3038,7 @@ static int scale_down(AV1_COMP *cpi, int q) {
}
#if CONFIG_GLOBAL_MOTION
#define GM_RECODE_LOOP_NUM4X4_FACTOR 256
#define GM_RECODE_LOOP_NUM4X4_FACTOR 192
static int recode_loop_test_global_motion(AV1_COMP *cpi) {
int i;
int recode = 0;
......
......@@ -454,7 +454,7 @@ static void normalize_homography(double *pts, int n, double *T) {
msqe += sqrt(p[0] * p[0] + p[1] * p[1]);
}
msqe /= n;
scale = sqrt(2) / msqe;
scale = (msqe == 0 ? 1.0 : sqrt(2) / msqe);
T[0] = scale;
T[1] = 0;
T[2] = -scale * mean[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