[mythtv] Over/Underscan rounding error

Andrew M. Bishop amb at gedanken.demon.co.uk
Sun Jan 4 03:42:15 EST 2004


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.

I am recording PAL TV at 512x576 resolution and I want to play it back
at 768x576 resolution so that there is only scaling horizontally by a
factor of 1.5.

I have an X resolution of 800x600 so my desired playback resolution is
96% of this (800*0.96=768 and 600*0.96=576).  I initially set the
underscan values to -4 (percent) in the settings screens.  This gives
an image that is too small because the actual underscan used is twice
the amount given in the settings entry (I don't know if this is
obvious to everybody else, but it wasn't to me).

When I used an underscan of -2 (percent) I get the following output
after the scaling is performed:

2004-01-03 17:30:47 Over/underscan. V: -0.02, H: -0.02, XOff: 0, YOff: 0
2004-01-03 17:30:47 Image size. dispxoff 16, dispxoff: 12, dispwoff: 769, disphoff: 577
2004-01-03 17:30:47 Image size. imgx 0, imgy: 0, imgw: 512, imgh: 576

The extra debugging outputs come from the following patch to v0.13
which I think should be added to the next version so that people can
see the actual image size that is used.

-------------------- videobaseout.cpp --------------------
--- videooutbase.cpp~	2003-12-08 19:02:14.000000000 +0000
+++ videooutbase.cpp	2004-01-03 17:42:41.000000000 +0000
@@ -522,6 +522,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();
 }
 
-------------------- videobaseout.cpp --------------------

This shows that the image size that is being used is 769x577 if I
understand the code correctly.  This means that the video card is
being required to perform a small image stretch which will result in
distortion on playback.

The problem is fixed with the following patch although rounding to the
nearest integer might be a better solution.

-------------------- videobaseout.cpp --------------------
--- videooutbase.cpp~	2003-12-08 19:02:14.000000000 +0000
+++ videooutbase.cpp	2004-01-03 17:42:41.000000000 +0000
@@ -418,7 +418,7 @@
         // Use the abolute value of scan factor.
         vscanf = fabs(img_vscanf);
         dispyoff = (int)ceil(disph * vscanf);
-        disphoff = (int)ceil(disph * (1 - 2 * vscanf));
+        disphoff = (int)floor(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
@@ -442,7 +442,7 @@
     {
         hscanf = fabs(img_hscanf);
         dispxoff = (int)ceil(dispw * hscanf);
-        dispwoff = (int)ceil(dispw * (1 - 2 * hscanf));
+        dispwoff = (int)floor(dispw * (1 - 2 * hscanf));
         if (xoff > 0) 
         {
             if (xoff > dispxoff) 
-------------------- videobaseout.cpp --------------------

I haven't looked at overscan, but there might be the same problem
there.

-- 
Andrew.
----------------------------------------------------------------------
Andrew M. Bishop                             amb at gedanken.demon.co.uk


More information about the mythtv-dev mailing list