This patch fixes problems with rounding errors caused by the X-Servers
rounding of the DisplaySize configuration parameter.

The patch also adds a new Aspect setting "Fill" which will take the incoming Video and "fill" the display with the picture cropping as necessary.

In the current MythTv, the Aspect rounding errors, cause the display size to not exactly match the incomming picture size, even when the display has the same aspect and number of pixels as the Video being displayed. This results in some scaling being applied to the Video
stream even when un-necessary.


On my system I am trying to set MythTv to not scale the incoming 720x576
DVB DTV image when displaying on my 720x576 TV display to improve the display quality. This is especially necessary as an interlaced TV is being used for output and if any scaling is used motion artifacts start
to appear.


For information the XServer rounds the DisplaySize configuration parameter as thus:

    Displaysize is set in mi/miscrinit.c
       pScreen->mmWidth = (xsize * 254 + dpix * 5) / (dpix * 10);
       pScreen->mmHeight = (ysize * 254 + dpiy * 5) / (dpiy * 10);

After using this patch the xorg.conf file's DisplaySize parameter can be
set to: "300 225" for 4:3 and "400 225" for 16:9.

Could someone check this code to make sure it will not break anything ?
The patch works well for me, I now have a good quality picture on my
Via EPIA M10K box with a digital TV source.

Cheers

Terry

Index: libs/libmythtv/tv_play.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_play.cpp,v
retrieving revision 1.232
diff -u -r1.232 tv_play.cpp
--- libs/libmythtv/tv_play.cpp	29 Nov 2004 22:04:35 -0000	1.232
+++ libs/libmythtv/tv_play.cpp	4 Jan 2005 15:54:32 -0000
@@ -3381,11 +3381,13 @@
 
     switch (letterbox)
     {
-        case kLetterbox_4_3: default: text = tr("4:3"); break;
+        case kLetterbox_4_3:          text = tr("4:3"); break;
         case kLetterbox_16_9:         text = tr("16:9"); break;
         case kLetterbox_4_3_Zoom:     text = tr("4:3 Zoom"); break;
         case kLetterbox_16_9_Zoom:    text = tr("16:9 Zoom"); break;
         case kLetterbox_16_9_Stretch: text = tr("16:9 Stretch"); break;
+        case kLetterbox_Fill:         text = tr("Fill"); break;
+	default:                      text = tr("Off"); break;
     }
 
     if (osd && !browsemode && !osd->IsRunningTreeMenu())
Index: libs/libmythtv/videooutbase.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/videooutbase.cpp,v
retrieving revision 1.65
diff -u -r1.65 videooutbase.cpp
--- libs/libmythtv/videooutbase.cpp	2 Dec 2004 06:29:11 -0000	1.65
+++ libs/libmythtv/videooutbase.cpp	4 Jan 2005 15:54:34 -0000
@@ -276,19 +276,26 @@
            break;
         case 1:
            XJ_aspect = (16.0 / 9);
-           letterbox = 0;
+           letterbox = kLetterbox_4_3;
            break;
         case 2:
            XJ_aspect = (4.0 / 3);
-           letterbox = 1;
+           letterbox = kLetterbox_16_9;
            break;
         case 3:
-           XJ_aspect = (16.0 / 9);
-           letterbox = 2;
+           XJ_aspect = (4.0 / 3);
+           letterbox = kLetterbox_16_9_Zoom;
            break;
         case 4:
+           XJ_aspect = (16.0 / 9);
+           letterbox = kLetterbox_4_3_Zoom;
+           break;
+        case 5:
            XJ_aspect = (4.0 / 3);
-           letterbox = 3;
+           letterbox = kLetterbox_16_9_Stretch;
+           break;
+        case 6:
+           letterbox = kLetterbox_Fill;
            break;
     }
 }
@@ -399,6 +406,7 @@
 void VideoOutput::MoveResize(void)
 {
     int yoff, xoff;
+    float displayAspect;
 
     // Preset all image placement and sizing variables.
     imgx = 0; imgy = 0;
@@ -409,6 +417,17 @@
     if (imgw == 1920 && imgh == 1088)
         imgh = 1080; // ATSC 1920x1080
 
+    // Get display aspect and correct for rounding errors
+    displayAspect = GetDisplayAspect();
+
+    // Check if close to 4:3
+    if(fabs(displayAspect - 1.333333) < 0.1)
+        displayAspect = 1.333333;
+
+    // Check if close to 16:9
+    if(fabs(displayAspect - 1.777777) < 0.1)
+        displayAspect = 1.777777;
+
 /*
     Here we apply playback over/underscanning and offsetting (if any apply).
 
@@ -533,19 +552,39 @@
             letterbox = kLetterbox_16_9;
     }
 
-    if (GetDisplayAspect() > XJ_aspect)
-    {
-        float pixNeeded = (h_mm * XJ_aspect) * ((float)dispwoff / w_mm);
+    if ((fabs(displayAspect - XJ_aspect) / displayAspect) > 0.1){
+        if(letterbox == kLetterbox_Fill){
+            if (displayAspect > XJ_aspect)
+            {
+                float pixNeeded = ((displayAspect / XJ_aspect) * (float)disphoff) + 0.5;
 
-        dispxoff += (dispwoff - (int)pixNeeded) / 2;
-        dispwoff = (int)pixNeeded;
-    }
-    else
-    {
-        float pixNeeded = (w_mm / XJ_aspect) * ((float)disphoff / h_mm);
+                dispyoff += (disphoff - (int)pixNeeded) / 2;
+                disphoff = (int)pixNeeded;
+            }
+            else
+            {
+                float pixNeeded = ((XJ_aspect / displayAspect) * (float)dispwoff) + 0.5;
+
+                dispxoff += (dispwoff - (int)pixNeeded) / 2;
+                dispwoff = (int)pixNeeded;
+            }
+        }
+        else {
+            if (displayAspect > XJ_aspect)
+            {
+                float pixNeeded = ((XJ_aspect / displayAspect) * (float)dispwoff) + 0.5;
 
-        dispyoff += (disphoff - (int)pixNeeded) / 2;
-        disphoff = (int)pixNeeded;
+                dispxoff += (dispwoff - (int)pixNeeded) / 2;
+                dispwoff = (int)pixNeeded;
+            }
+            else
+            {
+                float pixNeeded = ((displayAspect / XJ_aspect) * (float)disphoff) + 0.5;
+
+                dispyoff += (disphoff - (int)pixNeeded) / 2;
+                disphoff = (int)pixNeeded;
+            }
+        }
     }
 
     if ((letterbox == kLetterbox_4_3_Zoom) ||
@@ -595,7 +634,6 @@
 
     //printf("After: %dx%d%+d%+d\n", dispwoff, disphoff, dispxoff, 
     //dispyoff);
-
  
     VERBOSE(VB_PLAYBACK,
             QString("Image size. dispxoff %1, dispyoff: %2, dispwoff: %3, "
Index: libs/libmythtv/videooutbase.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/videooutbase.h,v
retrieving revision 1.42
diff -u -r1.42 videooutbase.h
--- libs/libmythtv/videooutbase.h	2 Dec 2004 06:29:11 -0000	1.42
+++ libs/libmythtv/videooutbase.h	4 Jan 2005 15:54:34 -0000
@@ -73,6 +73,7 @@
     kLetterbox_4_3_Zoom,
     kLetterbox_16_9_Zoom,
     kLetterbox_16_9_Stretch,
+    kLetterbox_Fill,
     kLetterbox_END
 };
 
Index: programs/mythfrontend/globalsettings.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/globalsettings.cpp,v
retrieving revision 1.205
diff -u -r1.205 globalsettings.cpp
--- programs/mythfrontend/globalsettings.cpp	8 Dec 2004 17:41:45 -0000	1.205
+++ programs/mythfrontend/globalsettings.cpp	4 Jan 2005 15:54:38 -0000
@@ -1099,7 +1099,9 @@
     gc->addSelection(QObject::tr("16/9 Anamorphic"), "1");
     gc->addSelection(QObject::tr("4/3 Normal"), "2");
     gc->addSelection(QObject::tr("16/9 Zoom"), "3");
-    gc->addSelection(QObject::tr("4/3 Zoom"), "3");
+    gc->addSelection(QObject::tr("4/3 Zoom"), "4");
+    gc->addSelection(QObject::tr("16/9 Stretch"), "5");
+    gc->addSelection(QObject::tr("Fill"), "6");
     gc->setHelpText(QObject::tr("This will override any aspect ratio in the "
                     "recorded stream, the same as pressing the W Key "
                     "during playback."));
_______________________________________________
mythtv-dev mailing list
[email protected]
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev

Reply via email to