Author: duncan
Date: Sun Sep 30 13:43:02 2007
New Revision: 9921

Log:
[ 1805183 ] Image viewer distorts images on TVs
Added IMAGEVIEWER_ASPECT to allow images to be show correctly on TVs
Changed osd to scale the images when displayed, this may break something else
Changed image.viewer to calculate the image width for the non-square pixels


Modified:
   branches/rel-1/freevo/freevo_config.py
   branches/rel-1/freevo/local_conf.py.example
   branches/rel-1/freevo/src/image/viewer.py
   branches/rel-1/freevo/src/osd.py

Modified: branches/rel-1/freevo/freevo_config.py
==============================================================================
--- branches/rel-1/freevo/freevo_config.py      (original)
+++ branches/rel-1/freevo/freevo_config.py      Sun Sep 30 13:43:02 2007
@@ -294,6 +294,7 @@
      Added a plugin that adds a submenu entry for ejecting rom drives and 
binds the default action of an empty drive to the eject action
      Replaced OSD_OVERSCAN_X with OSD_OVERSCAN_LEFT and OSD_OVERSCAN_RIGHT and 
OSD_OVERSCAN_Y with 
      OSD_OVERSCAN_TOP and OSD_OVERSCAN_BOTTOM
+     Added IMAGEVIEW_ASPECT to show images correctly on non-square pixel 
displays, it TVs
      '''),
 ]
 
@@ -1137,6 +1138,18 @@
 IMAGEVIEWER_DURATION = 0
 
 #
+# When viewing images on a TV screen where the pixels are not square
+# the images need to be scaled according to the aspect ratio of the TV
+# Use this setting for 16x9 TVs
+#   IMAGEVIEWER_ASPECT = (float(1024) / float(720))
+# Use this setting for 4x3 TVs
+#   IMAGEVIEWER_ASPECT = (float(768) / float(720))
+# Use this setting for Monitors including HDTVs
+#   IMAGEVIEWER_ASPECT = 1.0
+#
+IMAGEVIEWER_ASPECT = 1.0
+
+#
 # use exif thumbnail your thumbnail review. The quality is lower but
 # it's much faster
 #

Modified: branches/rel-1/freevo/local_conf.py.example
==============================================================================
--- branches/rel-1/freevo/local_conf.py.example (original)
+++ branches/rel-1/freevo/local_conf.py.example Sun Sep 30 13:43:02 2007
@@ -756,6 +756,18 @@
 
 # IMAGEVIEWER_BLEND_MODE = -1
 
+#
+# When viewing images on a TV screen where the pixels are not square
+# the images need to be scaled according to the aspect ratio of the TV
+# Use this setting for 16x9 TVs
+#   IMAGEVIEWER_ASPECT = (float(1024) / float(720))
+# Use this setting for 4x3 TVs
+#   IMAGEVIEWER_ASPECT = (float(768) / float(720))
+# Use this setting for Monitors including HDTVs
+#   IMAGEVIEWER_ASPECT = 1.0
+#
+# IMAGEVIEWER_ASPECT = 1.0
+
 
 
 # ======================================================================

Modified: branches/rel-1/freevo/src/image/viewer.py
==============================================================================
--- branches/rel-1/freevo/src/image/viewer.py   (original)
+++ branches/rel-1/freevo/src/image/viewer.py   Sun Sep 30 13:43:02 2007
@@ -74,6 +74,8 @@
         self.app_mode    = 'image'
         self.last_image  = (None, None)
         self.osd         = osd.get_singleton()
+        self.osd_height  = self.osd.height
+        self.osd_width   = self.osd.width * float(config.IMAGEVIEWER_ASPECT)
 
         self.signal_registered = False
 
@@ -125,14 +127,11 @@
         if not image:
             self.osd.clearscreen(color=self.osd.COL_BLACK)
             self.osd.drawstringframed(_('Can\'t Open Image\n\'%s\'') % 
Unicode(filename),
-                                      config.OSD_OVERSCAN_LEFT + 20,
-                                      config.OSD_OVERSCAN_TOP + 20,
-                                      self.osd.width - 
(config.OSD_OVERSCAN_LEFT+config.OSD_OVERSCAN_RIGHT) - 40,
-                                      self.osd.height - 
(config.OSD_OVERSCAN_TOP+config.OSD_OVERSCAN_BOTTOM) - 40,
-                                      
self.osd.getfont(config.OSD_DEFAULT_FONTNAME,
-                                                       
config.OSD_DEFAULT_FONTSIZE),
-                                      fgcolor=self.osd.COL_ORANGE,
-                                      align_h='center', align_v='center', 
mode='soft')
+                config.OSD_OVERSCAN_LEFT + 20, config.OSD_OVERSCAN_TOP + 20,
+                self.osd.width - 
(config.OSD_OVERSCAN_LEFT+config.OSD_OVERSCAN_RIGHT) - 40,
+                self.osd.height - 
(config.OSD_OVERSCAN_TOP+config.OSD_OVERSCAN_BOTTOM) - 40,
+                self.osd.getfont(config.OSD_DEFAULT_FONTNAME, 
config.OSD_DEFAULT_FONTSIZE),
+                fgcolor=self.osd.COL_ORANGE, align_h='center', 
align_v='center', mode='soft')
             self.osd.update()
             return
 
@@ -171,24 +170,24 @@
 
             if self.rotation % 180:
                 # different calculations because image width is screen height
-                scale_x = float(self.osd.width) / (height / 3)
-                scale_y = float(self.osd.height) / (width / 3)
+                scale_x = float(self.osd_width) / (height / 3)
+                scale_y = float(self.osd_height) / (width / 3)
                 scale = min(scale_x, scale_y)
 
                 # read comment for the bbw and bbh calculations below
-                bbw = min(max((width / 3) * scale, self.osd.height), width) / 
scale
-                bbh = min(max((height / 3) * scale, self.osd.width), height) / 
scale
+                bbw = min(max((width / 3) * scale, self.osd_height), width) / 
scale
+                bbh = min(max((height / 3) * scale, self.osd_width), height) / 
scale
 
             else:
-                scale_x = float(self.osd.width) / (width / 3)
-                scale_y = float(self.osd.height) / (height / 3)
+                scale_x = float(self.osd_width) / (width / 3)
+                scale_y = float(self.osd_height) / (height / 3)
                 scale = min(scale_x, scale_y)
 
                 # the bb width is the width / 3 * scale, to avoid black bars 
left
-                # and right exapand it to the osd.width but not if this is 
more than the
+                # and right exapand it to the osd_width but not if this is 
more than the
                 # image width (same for height)
-                bbw = min(max((width / 3) * scale, self.osd.width), width) / 
scale
-                bbh = min(max((height / 3) * scale, self.osd.height), height) 
/ scale
+                bbw = min(max((width / 3) * scale, self.osd_width), width) / 
scale
+                bbh = min(max((height / 3) * scale, self.osd_height), height) 
/ scale
 
             # calculate the beginning of the bounding box
             bbx = max(0, bbcx - bbw/2)
@@ -207,10 +206,10 @@
                 height, width = width, height
 
             # scale_x = scale_y = 1.0
-            # if width > osd.width: scale_x = float(osd.width) / width
-            # if height > osd.height: scale_y = float(osd.height) / height
-            scale_x = float(self.osd.width) / width
-            scale_y = float(self.osd.height) / height
+            # if width > osd_width: scale_x = float(osd_width) / width
+            # if height > osd_height: scale_y = float(osd_height) / height
+            scale_x = float(self.osd_width) / width
+            scale_y = float(self.osd_height) / height
 
             scale = min(scale_x, scale_y)
 
@@ -220,8 +219,8 @@
         # Now we have all necessary information about zoom yes/no and
         # the kind of rotation
 
-        x = (self.osd.width - new_w) / 2
-        y = (self.osd.height - new_h) / 2
+        x = (self.osd_width - new_w) / 2
+        y = (self.osd_height - new_h) / 2
 
         last_image = self.last_image[1]
 
@@ -463,14 +462,14 @@
                     prt_line[line] += '   ' + textstr
 
         # Create a black box for text
-        self.osd.drawbox(config.OSD_OVERSCAN_LEFT, self.osd.height - \
+        self.osd.drawbox(config.OSD_OVERSCAN_LEFT, self.osd_height - \
                          (config.OSD_OVERSCAN_LEFT + 25 + (len(prt_line) * 
30)),
-                         self.osd.width, self.osd.height, width=-1,
+                         self.osd_width, self.osd_height, width=-1,
                          color=((60 << 24) | self.osd.COL_BLACK), layer=layer)
 
         # Now print the Text
         for line in range(len(prt_line)):
-            h=self.osd.height - (40 + config.OSD_OVERSCAN_TOP + \
+            h=self.osd_height - (40 + config.OSD_OVERSCAN_TOP + \
                                  ((len(prt_line) - line - 1) * 30))
             self.osd.drawstring(prt_line[line], 15 + config.OSD_OVERSCAN_LEFT, 
h,
                                 fgcolor=self.osd.COL_ORANGE, layer=layer)

Modified: branches/rel-1/freevo/src/osd.py
==============================================================================
--- branches/rel-1/freevo/src/osd.py    (original)
+++ branches/rel-1/freevo/src/osd.py    Sun Sep 30 13:43:02 2007
@@ -643,6 +643,7 @@
 
             if not os.path.isfile(filename):
                 _debug_('Bitmap file "%s" doesn\'t exist!' % filename, 
config.DWARNING)
+                #raise 'Bitmap file'
                 return None
 
             try:
@@ -705,10 +706,13 @@
 
 
     def drawsurface(self, image, x=0, y=0, scaling=None,
-                   bbx=0, bby=0, bbw=0, bbh=0, rotation = 0, layer=None):
+                   bbx=0, bby=0, bbw=0, bbh=0, rotation=0, layer=None):
         """
         scales and rotates a surface and then draws it to the screen.
         """
+        _debug_('drawsurface(image=%s, x=%s, y=%s, scaling=%s, bbx=%s, bby=%s, 
bbw=%s, bbh=%s, rotation=%s, layer=%s)' \
+            % (image, x, y, scaling, bbx, bby, bbw, bbh, rotation, layer), 2)
+
         if not pygame.display.get_init():
             return None
 
@@ -716,6 +720,7 @@
         if not image:
             return
 
+        x = int(float(x) / config.IMAGEVIEWER_ASPECT)
         self.mutex.acquire()
         try:
             if layer:
@@ -726,11 +731,13 @@
             self.mutex.release()
 
 
-    def zoomsurface(self, image, scaling=None, bbx=0, bby=0, bbw=0, bbh=0, 
rotation = 0):
+    def zoomsurface(self, image, scaling=None, bbx=0, bby=0, bbw=0, bbh=0, 
rotation=0):
         """
         Zooms a Surface. It gets a Pygame Surface which is rotated and scaled 
according
         to the parameters.
         """
+        _debug_('zoomsurface(image=%s, scaling=%s, bbx=%s, bby=%s, bbw=%s, 
bbh=%s, rotation=%s)' \
+            % (image, scaling, bbx, bby, bbw, bbh, rotation), 2)
         if not image:
             return None
 
@@ -741,10 +748,11 @@
 
         if scaling:
             w, h = image.get_size()
-            w = int(w*scaling)
             h = int(h*scaling)
+            w = int(float(w) * scaling / config.IMAGEVIEWER_ASPECT)
             if rotation:
                 image = pygame.transform.rotozoom(image, rotation, scaling)
+                image = pygame.transform.scale(image, (w, h))
             else:
                 image = pygame.transform.scale(image, (w, h))
 
@@ -758,6 +766,8 @@
         """
         draw a normal box
         """
+        _debug_('drawbox(x0=%s, y0=%s, x1=%s, y1=%s, width=%s, color=%s, 
fill=%s, layer=%s)' \
+            % (x0, y0, x1, y1, width, color, fill, layer), 2)
         self.mutex.acquire()
         try:
             # Make sure the order is top left, bottom right

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to