In gtf modeline calculations, currently hblank and hsync are rounded
down. hblank needs to be rounded to nearest multiple of twice the
cell granularity. hsync needs to be rounded to nearest multiple of
cell granularity. Changed the rounding calculation to match it with
the equations in standards.

Cc: Hans Verkuil <hans.verk...@cisco.com>
Signed-off-by: Prashant Laddha <prlad...@cisco.com>
---
 utils/v4l2-ctl/v4l2-ctl-modes.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/utils/v4l2-ctl/v4l2-ctl-modes.cpp 
b/utils/v4l2-ctl/v4l2-ctl-modes.cpp
index c775bda..4689006 100644
--- a/utils/v4l2-ctl/v4l2-ctl-modes.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-modes.cpp
@@ -457,12 +457,13 @@ bool calc_gtf_modeline(int image_width, int image_height,
 
        h_blank = active_h_pixel * ideal_blank_duty_cycle /
                         (100 * HV_FACTOR - ideal_blank_duty_cycle);
-       h_blank -= h_blank % (2 * GTF_CELL_GRAN);
+       h_blank = ((h_blank + GTF_CELL_GRAN) / (2 * GTF_CELL_GRAN))
+                         * (2 * GTF_CELL_GRAN);
 
        total_h_pixel = active_h_pixel + h_blank;
 
-       h_sync  = (total_h_pixel * GTF_HSYNC_PERCENT) / 100;
-       h_sync -= h_sync % GTF_CELL_GRAN;
+       h_sync = (total_h_pixel * GTF_HSYNC_PERCENT) / 100;
+       h_sync = ((h_sync + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN) * GTF_CELL_GRAN;
 
        h_fp = h_blank / 2 - h_sync;
        h_bp = h_fp + h_sync;
@@ -509,6 +510,5 @@ bool calc_gtf_modeline(int image_width, int image_height,
                gtf->flags |= V4L2_DV_FL_REDUCED_BLANKING;
        } else
                gtf->polarities = V4L2_DV_VSYNC_POS_POL;
-
        return true;
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to