Commit 7cbb32e4 authored by Reimar Döffinger's avatar Reimar Döffinger

Use an int MotionVector for find_block_motion.

Using the double variant causes several pointless conversions between
double and int.
Worse, one of the conversions is in an inner loop together with a
function using MMX, resulting in undefined behaviour.
Based on debugging by Ray Simard.
Signed-off-by: 's avatarReimar Döffinger <Reimar.Doeffinger@gmx.de>
Tested-by: 's avatarRay Simard <rhs.ffmpeg@sylvan-glade.com>
parent 742b660e
...@@ -66,6 +66,11 @@ enum SearchMethod { ...@@ -66,6 +66,11 @@ enum SearchMethod {
SEARCH_COUNT SEARCH_COUNT
}; };
typedef struct {
int x; ///< Horizontal shift
int y; ///< Vertical shift
} IntMotionVector;
typedef struct { typedef struct {
double x; ///< Horizontal shift double x; ///< Horizontal shift
double y; ///< Vertical shift double y; ///< Vertical shift
...@@ -129,7 +134,7 @@ static double clean_mean(double *values, int count) ...@@ -129,7 +134,7 @@ static double clean_mean(double *values, int count)
*/ */
static void find_block_motion(DeshakeContext *deshake, uint8_t *src1, static void find_block_motion(DeshakeContext *deshake, uint8_t *src1,
uint8_t *src2, int cx, int cy, int stride, uint8_t *src2, int cx, int cy, int stride,
MotionVector *mv) IntMotionVector *mv)
{ {
int x, y; int x, y;
int diff; int diff;
...@@ -222,7 +227,7 @@ static int block_contrast(uint8_t *src, int x, int y, int stride, int blocksize) ...@@ -222,7 +227,7 @@ static int block_contrast(uint8_t *src, int x, int y, int stride, int blocksize)
/** /**
* Find the rotation for a given block. * Find the rotation for a given block.
*/ */
static double block_angle(int x, int y, int cx, int cy, MotionVector *shift) static double block_angle(int x, int y, int cx, int cy, IntMotionVector *shift)
{ {
double a1, a2, diff; double a1, a2, diff;
...@@ -247,7 +252,7 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2, ...@@ -247,7 +252,7 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
int width, int height, int stride, Transform *t) int width, int height, int stride, Transform *t)
{ {
int x, y; int x, y;
MotionVector mv = {0, 0}; IntMotionVector mv = {0, 0};
int counts[128][128]; int counts[128][128];
int count_max_value = 0; int count_max_value = 0;
int contrast; int contrast;
...@@ -278,7 +283,7 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2, ...@@ -278,7 +283,7 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
//av_log(NULL, AV_LOG_ERROR, "%d\n", contrast); //av_log(NULL, AV_LOG_ERROR, "%d\n", contrast);
find_block_motion(deshake, src1, src2, x, y, stride, &mv); find_block_motion(deshake, src1, src2, x, y, stride, &mv);
if (mv.x != -1 && mv.y != -1) { if (mv.x != -1 && mv.y != -1) {
counts[(int)(mv.x + deshake->rx)][(int)(mv.y + deshake->ry)] += 1; counts[mv.x + deshake->rx][mv.y + deshake->ry] += 1;
if (x > deshake->rx && y > deshake->ry) if (x > deshake->rx && y > deshake->ry)
angles[pos++] = block_angle(x, y, 0, 0, &mv); angles[pos++] = block_angle(x, y, 0, 0, &mv);
......
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