linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] rounding and overflow fix in cvt,gtf calculations
@ 2015-05-04 10:48 Prashant Laddha
  2015-05-04 10:48 ` [PATCH 1/2] v4l2-ctl-modes: fix hblank, hsync rounding in gtf calculation Prashant Laddha
  2015-05-04 10:48 ` [PATCH 2/2] v4l2-utils: fix overflow in cvt, gtf calculations Prashant Laddha
  0 siblings, 2 replies; 3+ messages in thread
From: Prashant Laddha @ 2015-05-04 10:48 UTC (permalink / raw)
  To: linux-media

Hi,

Please find patches for rounding and overflow fixes in cvt,gtf
timings calculations in v4l2-utils. Similar fixes are posted for
v4l2-dv-timings recently.

Regards,
Prashant

Prashant Laddha (2):
  v4l2-ctl-modes: fix hblank, hsync rounding in gtf calculation
  v4l2-utils: fix overflow in cvt, gtf calculations

 utils/v4l2-ctl/v4l2-ctl-modes.cpp | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] v4l2-ctl-modes: fix hblank, hsync rounding in gtf calculation
  2015-05-04 10:48 [PATCH 0/2] rounding and overflow fix in cvt,gtf calculations Prashant Laddha
@ 2015-05-04 10:48 ` Prashant Laddha
  2015-05-04 10:48 ` [PATCH 2/2] v4l2-utils: fix overflow in cvt, gtf calculations Prashant Laddha
  1 sibling, 0 replies; 3+ messages in thread
From: Prashant Laddha @ 2015-05-04 10:48 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, Prashant Laddha

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.verkuil@cisco.com>
Signed-off-by: Prashant Laddha <prladdha@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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] v4l2-utils: fix overflow in cvt, gtf calculations
  2015-05-04 10:48 [PATCH 0/2] rounding and overflow fix in cvt,gtf calculations Prashant Laddha
  2015-05-04 10:48 ` [PATCH 1/2] v4l2-ctl-modes: fix hblank, hsync rounding in gtf calculation Prashant Laddha
@ 2015-05-04 10:48 ` Prashant Laddha
  1 sibling, 0 replies; 3+ messages in thread
From: Prashant Laddha @ 2015-05-04 10:48 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, Prashant Laddha

Some of the intermediate calculations can exceed 32 bit signed range,
especially for higher resolutions and refresh rates. Type casting the
intermediate values to higher precision to avoid overflow.

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

diff --git a/utils/v4l2-ctl/v4l2-ctl-modes.cpp b/utils/v4l2-ctl/v4l2-ctl-modes.cpp
index 4689006..072763a 100644
--- a/utils/v4l2-ctl/v4l2-ctl-modes.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-modes.cpp
@@ -216,7 +216,7 @@ bool calc_cvt_modeline(int image_width, int image_height,
 		if (ideal_blank_duty_cycle < 20 * HV_FACTOR)
 			ideal_blank_duty_cycle = 20 * HV_FACTOR;
 
-		h_blank = active_h_pixel * ideal_blank_duty_cycle /
+		h_blank = active_h_pixel * (long long)ideal_blank_duty_cycle /
 			 (100 * HV_FACTOR - ideal_blank_duty_cycle);
 		h_blank -= h_blank % (2 * CVT_CELL_GRAN);
 
@@ -430,7 +430,6 @@ bool calc_gtf_modeline(int image_width, int image_height,
 	tmp2 = active_v_lines + GTF_MIN_PORCH + interlace;
 
 	h_period_est = tmp1 / (tmp2 * v_refresh);
-
 	v_sync_bp = GTF_MIN_VSYNC_BP * HV_FACTOR * 100 / h_period_est;
 	v_sync_bp = (v_sync_bp + 50) / 100;
 
@@ -444,7 +443,7 @@ bool calc_gtf_modeline(int image_width, int image_height,
 	v_refresh_est = (HV_FACTOR * (long long)1000000) /
 			(h_period_est * total_v_lines / HV_FACTOR);
 
-	h_period = (h_period_est * v_refresh_est) /
+	h_period = ((long long)h_period_est * v_refresh_est) /
 		   (v_refresh * HV_FACTOR);
 
 	if (!reduced_blanking)
@@ -455,7 +454,7 @@ bool calc_gtf_modeline(int image_width, int image_height,
 				      GTF_S_M_PRIME * h_period / 1000;
 
 
-	h_blank = active_h_pixel * ideal_blank_duty_cycle /
+	h_blank = active_h_pixel * (long long)ideal_blank_duty_cycle /
 			 (100 * HV_FACTOR - ideal_blank_duty_cycle);
 	h_blank = ((h_blank + GTF_CELL_GRAN) / (2 * GTF_CELL_GRAN))
 			  * (2 * GTF_CELL_GRAN);
@@ -467,7 +466,6 @@ bool calc_gtf_modeline(int image_width, int image_height,
 
 	h_fp = h_blank / 2 - h_sync;
 	h_bp = h_fp + h_sync;
-
 	pixel_clock = ((long long)total_h_pixel * HV_FACTOR * 1000000)
 					/ h_period;
 	/* Not sure if clock value needs to be truncated to multiple
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-05-04 11:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-04 10:48 [PATCH 0/2] rounding and overflow fix in cvt,gtf calculations Prashant Laddha
2015-05-04 10:48 ` [PATCH 1/2] v4l2-ctl-modes: fix hblank, hsync rounding in gtf calculation Prashant Laddha
2015-05-04 10:48 ` [PATCH 2/2] v4l2-utils: fix overflow in cvt, gtf calculations Prashant Laddha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).