Update of /cvsroot/freevo/freevo/WIP/Dischi
In directory sc8-pr-cvs1:/tmp/cvs-serv29598

Added Files:
        imageitem.py viewer.py 
Log Message:
blend effect added

--- NEW FILE: imageitem.py ---
#if 0 /*
# -----------------------------------------------------------------------
# imageitem.py - Item for image files
# -----------------------------------------------------------------------
# $Id: imageitem.py,v 1.1 2003/11/15 13:46:21 dischi Exp $
#
# Notes:
# Todo:        
#
# -----------------------------------------------------------------------
# $Log: imageitem.py,v $
# Revision 1.1  2003/11/15 13:46:21  dischi
# blend effect added
#
# Revision 1.13  2003/09/13 10:08:22  dischi
# i18n support
#
# Revision 1.12  2003/08/23 12:51:42  dischi
# removed some old CVS log messages
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al. 
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif

import util
import os

import viewer
import mmpython

from item import Item


class ImageItem(Item):
    def __init__(self, filename, parent, name = None, duration = 0):
        if parent and parent.media:
            url = 'cd://%s:%s:%s' % (parent.media.devicename, parent.media.mountdir,
                                     filename[len(parent.media.mountdir)+1:])
        else:
            url = filename

        Item.__init__(self, parent, mmpython.parse(url))
        self.type     = 'image'
        self.filename = filename
        self.image    = filename
        self.duration = duration
        
        # set name
        if name:
            self.name = name
        elif not self.name:
            self.name = util.getname(filename)

        self.image_viewer = viewer.get_singleton()
        self.rotation     = 0
        
    def getattr(self, attr):
        """
        return the specific attribute as string or an empty string
        """
        if attr in [ "geometry" ]:
            try:
                image = self.info
                if attr == 'geometry':
                    print "geometry=%sx%s" % (image.width, image.height)
                    return '%sx%s' % (image.width, image.height)
            except:
                pass
            
        return Item.getattr(self, attr)
        

    def copy(self, obj):
        """
        Special copy value VideoItems
        """
        Item.copy(self, obj)
        if obj.type == 'image':
            self.duration = obj.duration
            self.rotation = obj.rotation
            

    def sort(self, mode=None):
        """
        Returns the string how to sort this item
        """
        if mode == 'date':
            return '%s%s' % (os.stat(self.filename).st_ctime, self.filename)
        return self.filename


    def actions(self):
        """
        return a list of possible actions on this item.
        """
        return [ ( self.view, _('View Image') ) ]


    def cache(self):
        """
        caches (loads) the next image
        """
        self.image_viewer.cache(self)


    def view(self, arg=None, menuw=None):
        """
        view the image
        """
        if not self.menuw:
            self.menuw = menuw
        self.parent.current_item = self

        if self.menuw.visible:
            self.menuw.hide()

        self.image_viewer.view(self, rotation=self.rotation)

        if self.parent and hasattr(self.parent, 'cache_next'):
            self.parent.cache_next()



--- NEW FILE: viewer.py ---
#if 0 /*
# -----------------------------------------------------------------------
# viewer.py - Freevo image viewer
# -----------------------------------------------------------------------
# $Id: viewer.py,v 1.1 2003/11/15 13:46:21 dischi Exp $
#
# Notes:
# Todo:        
#
# -----------------------------------------------------------------------
# $Log: viewer.py,v $
# Revision 1.1  2003/11/15 13:46:21  dischi
# blend effect added
#
# Revision 1.30  2003/09/14 20:09:36  dischi
# removed some TRUE=1 and FALSE=0 add changed some debugs to _debug_
#
# Revision 1.29  2003/09/13 10:08:22  dischi
# i18n support
#
# Revision 1.28  2003/09/01 19:46:02  dischi
# add menuw to eventhandler, it may be needed
#
# Revision 1.27  2003/08/23 12:51:42  dischi
# removed some old CVS log messages
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al. 
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif


import os.path
import Image
import signal
import os
import time

import config # Configuration file. 
import osd    # The OSD class, used to communicate with the OSD daemon
import event as em
import objectcache
import rc
import pygame

from gui.GUIObject import GUIObject
from gui.AlertBox import AlertBox

osd        = osd.get_singleton()  # Create the OSD object


# Module variable that contains an initialized ImageViewer() object
_singleton = None

def get_singleton():
    global _singleton

    # One-time init
    if _singleton == None:
        _singleton = ImageViewer()
        
    return _singleton


class ImageViewer(GUIObject):

    def __init__(self):
        GUIObject.__init__(self)
        self.osd_mode = 0    # Draw file info on the image
        self.zoom = 0   # Image zoom
        self.zoom_btns = { str(em.IMAGE_NO_ZOOM):0, str(em.IMAGE_ZOOM_GRID1):1,
                           str(em.IMAGE_ZOOM_GRID2):2, str(em.IMAGE_ZOOM_GRID3):3,
                           str(em.IMAGE_ZOOM_GRID4):4, str(em.IMAGE_ZOOM_GRID5):5,
                           str(em.IMAGE_ZOOM_GRID6):6, str(em.IMAGE_ZOOM_GRID7):7,
                           str(em.IMAGE_ZOOM_GRID8):8, str(em.IMAGE_ZOOM_GRID9):9 }

        self.slideshow   = TRUE  # currently in slideshow mode
        self.alertbox    = None  # AlertBox active
        self.app_mode    = 'image'
        self.bitmapcache = objectcache.ObjectCache(3, desc='viewer')
        self.last_image  = (None, None)
        
    def view(self, item, zoom=0, rotation=0):
        filename = item.filename

        self.fileitem = item
        self.parent   = item.menuw
        
        self.filename = filename
        self.rotation = rotation

        if filename and len(filename) > 0:
            image = osd.loadbitmap(filename, cache=self.bitmapcache)
        else:
            # Using Container-Image
            image = item.loadimage()

        rc.app(self)

        if not image:
            osd.clearscreen(color=osd.COL_BLACK)
            osd.update()
            self.alertbox = AlertBox(parent=self,
                                     text=_("Can't Open Image\n'%s'") % (filename))
            self.alertbox.show()
            return
        
        width, height = image.get_size()
            
        # Bounding box default values
        bbx = bby = bbw = bbh = 0

        if zoom:
            # Translate the 9-element grid to bounding boxes
            if self.rotation == 90:
                bb = { 1:(2,0), 2:(2,1), 3:(2,2),
                       4:(1,0), 5:(1,1), 6:(1,2),
                       7:(0,0), 8:(0,1), 9:(0,2) }
            elif self.rotation == 180:
                bb = { 1:(2,2), 2:(1,2), 3:(0,2),
                       4:(2,1), 5:(1,1), 6:(0,1),
                       7:(2,0), 8:(1,0), 9:(0,0) }
            elif self.rotation == 270:
                bb = { 1:(0,2), 2:(0,1), 3:(0,0),
                       4:(1,2), 5:(1,1), 6:(1,0),
                       7:(2,2), 8:(2,1), 9:(2,0) }
            else:
                bb = { 1:(0,0), 2:(1,0), 3:(2,0),
                       4:(0,1), 5:(1,1), 6:(2,1),
                       7:(0,2), 8:(1,2), 9:(2,2) }

            h, v = bb[zoom]

            # Bounding box center
            bbcx = ([1, 3, 5][h]) * width / 6
            bbcy = ([1, 3, 5][v]) * height / 6

            if self.rotation % 180:
                # different calculations because image width is screen height
                scale_x = float(osd.width) / (height / 3)
                scale_y = float(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, osd.height), width) / scale
                bbh = min(max((height / 3) * scale, osd.width), height) / scale

            else:
                scale_x = float(osd.width) / (width / 3)
                scale_y = float(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
                # image width (same for height)
                bbw = min(max((width / 3) * scale, osd.width), width) / scale
                bbh = min(max((height / 3) * scale, osd.height), height) / scale
                

            # calculate the beginning of the bounding box
            bbx = max(0, bbcx - bbw/2)
            bby = max(0, bbcy - bbh/2)

            if bbx + bbw > width:  bbx = width - bbw
            if bby + bbh > height: bby = height - bbh

            if self.rotation % 180:
                new_h, new_w = bbw * scale, bbh * scale
            else:
                new_w, new_h = bbw * scale, bbh * scale



        else:
            if self.rotation % 180:  
                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(osd.width) / width
            scale_y = float(osd.height) / height
            
            scale = min(scale_x, scale_y)
            
            new_w, new_h = int(scale*width), int(scale*height)


        # Now we have all necessary informations about zoom yes/no and
        # the kind of rotation
        
        x = (osd.width - new_w) / 2
        y = (osd.height - new_h) / 2
        
        last_image = self.last_image[1]

        # XXX put this into freevo_config.py
        config.IMAGEVIEWER_BLEND_SPEED = 50
        if last_image and self.last_image[0] != item and 
config.IMAGEVIEWER_BLEND_SPEED:
            i1 = osd.zoomsurface(last_image[0], last_image[3], last_image[4],
                                 last_image[5], last_image[6], last_image[7],
                                 rotation = last_image[8]).convert()
            i2 = osd.zoomsurface(image, scale, bbx, bby, bbw, bbh,
                                 rotation = self.rotation).convert()
            for i in range(1, ((255-config.IMAGEVIEWER_BLEND_SPEED) /
                               config.IMAGEVIEWER_BLEND_SPEED)):
                i1.set_alpha(255 - (i * config.IMAGEVIEWER_BLEND_SPEED))
                i2.set_alpha(i * config.IMAGEVIEWER_BLEND_SPEED)
                osd.clearscreen(color=osd.COL_BLACK)
                osd.screen.blit(i1, (last_image[1], last_image[2]))
                osd.screen.blit(i2, (x, y))
                osd.update()

        osd.clearscreen(color=osd.COL_BLACK)
        osd.drawsurface(image, x, y, scale, bbx, bby, bbw, bbh,
                       rotation = self.rotation)

        # update the OSD
        self.drawosd()

        # draw
        osd.update()

        # start timer
        if self.fileitem.duration:
            signal.signal(signal.SIGALRM, self.signalhandler)
            signal.alarm(self.fileitem.duration)

        self.last_image  = (item, (image, x, y, scale, bbx, bby, bbw, bbh,
                                   self.rotation))
        return None


    
    def cache(self, fileitem):
        # cache the next image (most likely we need this)
        osd.loadbitmap(fileitem.filename, cache=self.bitmapcache)
        

    def signalhandler(self, signum, frame):
        if rc.app() == self.eventhandler and self.slideshow:
            self.last_image  = None, None
            rc.app(None)
            self.eventhandler(em.PLAY_END)


    def eventhandler(self, event, menuw=None):
        #if event == rc.SELECT and self.alertbox:
        #    self.alertbox.destroy()
        #    self.alertbox = None
        #    return TRUE
        
        if event == em.PAUSE or event == em.PLAY:
            if self.slideshow:
                self.slideshow = FALSE
                signal.alarm(0)
            else:
                self.slideshow = TRUE
                signal.alarm(1)
            return TRUE
        
        elif event == em.STOP:
            self.last_image  = None, None
            rc.app(None)
            signal.alarm(0)
            self.fileitem.eventhandler(event)
            return TRUE

        # up and down will stop the slideshow and pass the
        # event to the playlist
        elif event == em.PLAYLIST_NEXT or event == em.PLAYLIST_PREV:
            self.slideshow = FALSE
            signal.alarm(0)
            self.fileitem.eventhandler(event)
            return TRUE
            
        # rotate image
        elif event == em.IMAGE_ROTATE:
            if event.arg == 'left':
                self.rotation = (self.rotation + 270) % 360
            else:
                self.rotation = (self.rotation + 90) % 360
            self.fileitem.rotation = self.rotation
            self.view(self.fileitem, zoom=self.zoom, rotation=self.rotation)
            return TRUE

        # print image information
        elif event == em.TOGGLE_OSD:
            self.osd_mode = {0:1, 1:2, 2:0}[self.osd_mode] # Toggle on/off
            # Redraw
            self.view(self.fileitem, zoom=self.zoom, rotation = self.rotation)
            return TRUE

        # zoom to one third of the image
        # 1 is upper left, 9 is lower right, 0 zoom off
        elif str(event) in self.zoom_btns:
            self.zoom = self.zoom_btns[str(event)]
                
            if self.zoom:
                # Zoom one third of the image, don't load the next
                # image in the list
                self.view(self.fileitem, zoom=self.zoom, rotation = self.rotation)
            else:
                # Display entire picture, don't load next image in case
                # the user wants to zoom around some more.
                self.view(self.fileitem, zoom=0, rotation = self.rotation)
            return TRUE                

        # save the image with the current rotation
        elif event == em.IMAGE_SAVE:
            if self.rotation and os.path.splitext(self.filename)[1] == ".jpg":
                cmd = 'jpegtran -copy all -rotate %s -outfile /tmp/freevo-iview %s' \
                      % ((self.rotation + 180) % 360, self.filename)
                os.system(cmd)
                os.system('mv /tmp/freevo-iview %s' % self.filename)
                self.rotation = 0
                osd.bitmapcache.__delitem__(self.filename)
                return TRUE                

        else:
            return self.fileitem.eventhandler(event)

            
    def drawosd(self):

        if not self.osd_mode: return

        elif self.osd_mode == 1:
            # This is where we add a caption.  Only if playlist is empty
            # May need to check the caption too?
            osdstring = ["Title: " + self.fileitem.name]

            # Here we set up the tags that we want to put in the display
            # Using the following fields
            tags_check = [[_('Title: '),'name'],
                          [_('Description: '),'description']
                          ]



        elif self.osd_mode == 2:    
           # This is where we add a caption.  Only if playlist is empty
           # create an array with Exif tags as above
           osdstring = []
           tags_check = [ ['Date:','date'],
                          ['W:','width'],
                          ['H:','height'],
                          ['Model:','hardware'],
                          ['Software:', 'software']
                         ]

           # FIXME: add this informations to mmpython:
           
           # ['Exp:','EXIF ExposureTime','ExposureTime','EXIF'],
           # ['F/','EXIF FNumber','FNumber','EXIF'],
           # ['FL:','EXIF FocalLength','FocalLength','EXIF'],
           # ['ISO:','EXIF ISOSpeedRatings','ISOSpeedRatings','EXIF'],
           # ['Meter:','EXIF MeteringMode','MeteringMode','EXIF'],
           # ['Light:','EXIF LightSource','LightSource','EXIF'],
           # ['Flash:','EXIF Flash','Flash','EXIF'],
           # ['Make:','Image Make','Make','EXIF'],

        for strtag in tags_check:
            i = self.fileitem.getattr(strtag[1])
            if i:
                osdstring.append('%s %s' % (strtag[0], i))

        # If after all that there is nothing then tell the users that
        if osdstring == []:
            osdstring = [_('No information available')]
        
        # Now sort the text into lines of length line_length
        line = 0
        if config.OVERSCAN_X:
            line_length = 35
        else:
            line_length = 60
        prt_line = ['']

        for textstr in osdstring:
            if len(textstr) > line_length:
                # This is to big so just print it for now but wrap later
                if prt_line[line] == '':
                    prt_line[line] = textstr
                else:
                    prt_line.append(textstr)
                    line += 1
            elif len(textstr + '   ' + prt_line[line] )  > line_length:
                # Too long for one line so print the last and then new
                line += 1
                prt_line.append(textstr)
            else:
                if prt_line[line] == '':
                    prt_line[line] = textstr
                else:
                    prt_line[line] += '   ' + textstr

        # Create a black box for text
        osd.drawbox(config.OVERSCAN_X,
                    osd.height - (config.OVERSCAN_X + 25 + (len(prt_line) * 30)),
                    osd.width, osd.height, width=-1, 
                    color=((60 << 24) | osd.COL_BLACK))

        # Now print the Text
        for line in range(len(prt_line)):
            h=osd.height - (40 + config.OVERSCAN_Y + ((len(prt_line) - line - 1) * 30))
            osd.drawstring(prt_line[line], 15 + config.OVERSCAN_X, h,
                           fgcolor=osd.COL_ORANGE)






-------------------------------------------------------
This SF. Net email is sponsored by: GoToMyPC
GoToMyPC is the fast, easy and secure way to access your computer from
any Web browser or wireless device. Click here to Try it Free!
https://www.gotomypc.com/tr/OSDN/AW/Q4_2003/t/g22lp?Target=mm/g22lp.tmpl
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to