v4l2-ctl/qv4l2: fix movement counter calculation
authorHans Verkuil <hans.verkuil@cisco.com>
Mon, 11 Aug 2014 14:06:17 +0000 (16:06 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Mon, 11 Aug 2014 14:08:25 +0000 (16:08 +0200)
The calculation that determines the 'scrolling' of the test pattern
could 'jump': the counters could become negative and taking the
modulus of a negative number doesn't always do what you expect.

Ensure that the step values are always positive to prevent this issue.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/v4l2-ctl/vivid-tpg.c

index 13b6e5f..71eeca5 100644 (file)
@@ -1086,7 +1086,8 @@ void tpg_update_mv_step(struct tpg_data *tpg)
                tpg->mv_hor_step = 0;
                break;
        }
-       tpg->mv_hor_step *= factor;
+       if (factor < 0)
+               tpg->mv_hor_step = tpg->src_width - tpg->mv_hor_step;
 
        factor = tpg->mv_vert_mode > TPG_MOVE_NONE ? -1 : 1;
        switch (tpg->mv_vert_mode) {
@@ -1106,7 +1107,8 @@ void tpg_update_mv_step(struct tpg_data *tpg)
                tpg->mv_vert_step = 0;
                break;
        }
-       tpg->mv_vert_step *= factor;
+       if (factor < 0)
+               tpg->mv_vert_step = tpg->src_height - tpg->mv_vert_step;
 }
 
 /* Map the line number relative to the crop rectangle to a frame line number */