[mythtv] Re: Over/Underscan rounding error

Andrew M. Bishop amb at gedanken.demon.co.uk
Sun Feb 1 04:47:15 EST 2004


Nearly a month ago I wrote:

> I have been trying to minimise the amount of scaling that is being
> performed when playing back recordings.  I have found what seems to me
> to be a rounding error in the overscan and underscan code.

The patch below will change the method of rounding from going to the
nearest integer above to the closest integer.  The patch also fixes
some comments and adds in some new diagnostic information.

-------------------- videooutbase.cpp --------------------
diff -u /home/amb/mythtv/v0.14/mythtv/libs/libmythtv/videooutbase.orig.cpp /home/amb/mythtv/v0.14/mythtv/libs/libmythtv/videooutbase.cpp
--- /home/amb/mythtv/v0.14/mythtv/libs/libmythtv/videooutbase.orig.cpp	2004-01-28 20:23:17.000000000 +0000
+++ /home/amb/mythtv/v0.14/mythtv/libs/libmythtv/videooutbase.cpp	2004-02-01 09:36:00.000000000 +0000
@@ -273,9 +273,9 @@
 
     if (img_vscanf > 0) 
     {
-        // Veritcal overscan. Move the Y start point in original image.
-        imgy = (int)ceil(XJ_height * img_vscanf);
-        imgh = (int)ceil(XJ_height * (1 - 2 * img_vscanf));
+        // Vertical overscan. Move the Y start point in original image.
+        imgy = (int)floor(0.5 + XJ_height * img_vscanf);
+        imgh = (int)floor(0.5 + XJ_height * (1 - 2 * img_vscanf));
 
         // If there is an offset, apply it now that we have a room.
         // To move the image down, move the start point up.
@@ -299,8 +299,8 @@
     if (img_hscanf > 0) 
     {
         // Horizontal overscan. Move the X start point in original image.
-        imgx = (int)ceil(XJ_width * img_hscanf);
-        imgw = (int)ceil(XJ_width * (1 - 2 * img_hscanf));
+        imgx = (int)floor(0.5 + XJ_width * img_hscanf);
+        imgw = (int)floor(0.5 + XJ_width * (1 - 2 * img_hscanf));
         if (xoff > 0) 
         {
             if (xoff > imgx) 
@@ -318,11 +318,11 @@
     float vscanf, hscanf;
     if (img_vscanf < 0) 
     {
-        // Veritcal underscan. Move the starting Y point in the display window.
+        // Vertical underscan. Move the starting Y point in the display window.
         // Use the abolute value of scan factor.
         vscanf = fabs(img_vscanf);
-        dispyoff = (int)ceil(disph * vscanf);
-        disphoff = (int)ceil(disph * (1 - 2 * vscanf));
+        dispyoff = (int)floor(0.5 + disph * vscanf);
+        disphoff = (int)floor(0.5 + disph * (1 - 2 * vscanf));
         // Now offset the image within the extra blank space created by
         // underscanning.
         // To move the image down, increase the Y offset inside the display
@@ -345,8 +345,8 @@
     if (img_hscanf < 0) 
     {
         hscanf = fabs(img_hscanf);
-        dispxoff = (int)ceil(dispw * hscanf);
-        dispwoff = (int)ceil(dispw * (1 - 2 * hscanf));
+        dispxoff = (int)floor(0.5 + dispw * hscanf);
+        dispwoff = (int)floor(0.5 + dispw * (1 - 2 * hscanf));
         if (xoff > 0) 
         {
             if (xoff > dispxoff) 
@@ -426,6 +426,14 @@
     //printf("After: %dx%d%+d%+d\n", dispwoff, disphoff, dispxoff, 
     //dispyoff);
 
+    VERBOSE(VB_PLAYBACK,
+            QString("Image size. dispxoff %1, dispxoff: %2, dispwoff: %3, disphoff: %4")
+            .arg(dispxoff).arg(dispyoff).arg(dispwoff).arg(disphoff));
+
+    VERBOSE(VB_PLAYBACK,
+            QString("Image size. imgx %1, imgy: %2, imgw: %3, imgh: %4")
+           .arg(imgx).arg(imgy).arg(imgw).arg(imgh));
+
     DrawUnusedRects();
 }
 
-------------------- videooutbase.cpp --------------------

-- 
Andrew.
----------------------------------------------------------------------
Andrew M. Bishop                             amb at gedanken.demon.co.uk
                                      http://www.gedanken.demon.co.uk/


More information about the mythtv-dev mailing list