Пример #1
0
def format_image(settings, item, width, height, force=0, anamorphic=0):
    try:
        type = item.display_type
    except:
        try:
            type = item.info['mime'].replace('/', '_')
        except:
            type = item.type

    cname = '%s-%s-%s-%s-%s-%s-%s' % (settings.icon_dir, item.image, type,
                                      item.type, width, height, force)

    if item['rotation']:
        cname = '%s-%s' % (cname, item['rotation'])

    if item.media and item.media.item == item:
        cname = '%s-%s' % (cname, item.media)

    cimage = format_imagecache[cname]

    if cimage:
        return cimage

    image = None
    imagefile = None

    if item.image:
        if isinstance(item.image, imlib2.Image):
            image = osd.loadbitmap(item.image)
        else:
            image = load_imagecache['thumb://%s' % item.image]
            if not image:
                image = osd.loadbitmap('thumb://%s' % item.image)
                load_imagecache['thumb://%s' % item.image] = image

        if not item['rotation']:
            try:
                f = open(item.filename, 'rb')
                tags = exif.process_file(f)
                f.close()
                if tags.has_key('Image Orientation'):
                    orientation = tags['Image Orientation']
                    if str(orientation) == "Rotated 90 CCW":
                        item['rotation'] = 90
                    elif str(orientation) == "Rotated 180":
                        item['rotation'] = 180
                    elif str(orientation) == "Rotated 90 CW":
                        item['rotation'] = 270
            except Exception, e:
                pass

        if image and item['rotation']:
            image = pygame.transform.rotate(image, item['rotation'])
Пример #2
0
    def loadimage(self, image, val, redraw=True):
        """
        load an image (use self.imagecache)
        """
        if image.find(config.ICON_DIR) == 0 and image.find(
                self.settings.icon_dir) == -1:
            new_image = os.path.join(self.settings.icon_dir,
                                     image[len(config.ICON_DIR) + 1:])
            if os.path.isfile(new_image):
                image = new_image

        if isinstance(val, tuple) or isinstance(val, list):
            w = val[0]
            h = val[1]
        else:
            w = val.width
            h = val.height

        cname = '%s-%s-%s' % (image, w, h)
        cimage = self.imagecache[cname]
        if not cimage:
            cimage = osd.loadbitmap(image)
            if not cimage:
                return
            if w == -1:
                w = h * cimage.get_width() / cimage.get_height()
            if h == -1:
                h = w * cimage.get_height() / cimage.get_width()
            if self.xml_settings.anamorphic:
                w = w * 0.75
            if w > 0 and h > 0:
                cimage = pygamesurface_imlib2_scale(cimage, (w, h))
            self.imagecache[cname] = cimage
        return cimage
Пример #3
0
    def loadimage(self, image, val, redraw=True):
        """
        load an image (use self.imagecache)
        """
        if image.find(config.ICON_DIR) == 0 and image.find(self.settings.icon_dir) == -1:
            new_image = os.path.join(self.settings.icon_dir, image[len(config.ICON_DIR)+1:])
            if os.path.isfile(new_image):
                image = new_image

        if isinstance(val, tuple) or isinstance(val, list):
            w = val[0]
            h = val[1]
        else:
            w = val.width
            h = val.height

        cname = '%s-%s-%s' % (image, w, h)
        cimage = self.imagecache[cname]
        if not cimage:
            cimage = osd.loadbitmap(image)
            if not cimage:
                return None, 0, 0
            if w == -1:
                w = h  * cimage.get_width() / cimage.get_height()
            if h == -1:
                h = w  * cimage.get_height() / cimage.get_width()
            if self.xml_settings.anamorphic:
                w = w * 0.75
            w = int(w)
            h = int(h)
            if w > 0 and h > 0:
                cimage = pygamesurface_imlib2_scale(cimage, (w, h))
            self.imagecache[cname] = cimage
        return cimage, w, h
Пример #4
0
 def __init__(self):
     ScreenSaverPlugin.__init__(self)
     self.plugin_name = 'screensaver.bouncing_freevo'
     self.fps = config.BOUNCING_FREEVO_FPS
     self.image = osd.loadbitmap(os.path.join(config.IMAGE_DIR, 'logo.png'))
     self.image_width = 200
     self.image_height = 98
Пример #5
0
 def __init__(self):
     logger.log( 9, 'PluginInterface.__init__()')
     ScreenSaverPlugin.__init__(self)
     self.plugin_name = 'screensaver.bouncing_freevo'
     self.fps = config.BOUNCING_FREEVO_FPS
     self.image = osd.loadbitmap(os.path.join(config.IMAGE_DIR,'logo.png'))
     self.image_width = 200
     self.image_height = 98
Пример #6
0
def text_or_icon(settings, string, x, width, font):
    l = string.split('_')
    if len(l) != 4:
        return string
    try:
        height = font.h
        image = os.path.join(settings.icon_dir, l[2].lower())
        if os.path.isfile(image + '.jpg'):
            image += '.jpg'
        if os.path.isfile(image + '.png'):
            image += '.png'
        else:
            image = None
        if image:
            cname = '%s-%s-%s-%s-%s' % (image, x, l[2], width, height)
            cimage = format_imagecache[cname]
            if cimage:
                return cimage

            image = osd.loadbitmap(image)
            if not image:
                raise KeyError
            i_w, i_h = image.get_size()
            original_width = width
            if int(float(width * i_h) / i_w) > height:
                width = int(float(height * i_w) / i_h)
            else:
                height = int(float(width * i_h) / i_w)

            cimage = pygamesurface_imlib2_scale(image, (width, height))
            cimage.set_alpha(cimage.get_alpha(), RLEACCEL)
            x_mod = 0
            if l[1] == 'CENTER':
                x_mod = (original_width - width) / 2
            if l[1] == 'RIGHT':
                x_mod = original_width - width
            format_imagecache[cname] = x_mod, cimage
            return x_mod, cimage
    except KeyError:
        logger.debug('no image %s', l[2])
        pass

    mod_x = width - font.stringsize(l[3])
    if mod_x < 0:
        mod_x = 0
    if l[1] == 'CENTER':
        return mod_x / 2, l[3]
    if l[1] == 'RIGHT':
        return mod_x, l[3]
    return 0, l[3]
Пример #7
0
def text_or_icon(settings, string, x, width, font):
    l = string.split('_')
    if len(l) != 4:
        return string
    try:
        height = font.h
        image = os.path.join(settings.icon_dir, l[2].lower())
        if os.path.isfile(image + '.jpg'):
            image += '.jpg'
        if os.path.isfile(image + '.png'):
            image += '.png'
        else:
            image = None
        if image:
            cname = '%s-%s-%s-%s-%s' % (image, x, l[2], width, height)
            cimage = format_imagecache[cname]
            if cimage:
                return cimage

            image = osd.loadbitmap(image)
            if not image:
                raise KeyError
            i_w, i_h = image.get_size()
            original_width = width
            if int(float(width * i_h) / i_w) > height:
                width =  int(float(height * i_w) / i_h)
            else:
                height = int(float(width * i_h) / i_w)

            cimage = pygamesurface_imlib2_scale(image, (width, height))
            cimage.set_alpha(cimage.get_alpha(), RLEACCEL)
            x_mod = 0
            if l[1] == 'CENTER':
                x_mod = (original_width - width) / 2
            if l[1] == 'RIGHT':
                x_mod = original_width - width
            format_imagecache[cname] = x_mod, cimage
            return x_mod, cimage
    except KeyError:
        logger.debug('no image %s', l[2])
        pass

    mod_x = width - font.stringsize(l[3])
    if mod_x < 0:
        mod_x = 0
    if l[1] == 'CENTER':
        return mod_x / 2, l[3]
    if l[1] == 'RIGHT':
        return mod_x, l[3]
    return 0, l[3]
Пример #8
0
    def __draw_background__(self):
        """
        draw the <background> of the area
        """
        area = self.area_val

        last_watermark = None

        try:
            if self.watermark:
                last_watermark = self.watermark

                try:
                    if self.menu.selected.image != self.watermark:
                        self.watermark = None
                        self.redraw = True
                except:
                    pass
        except:
            pass

        for bg in self.layout.background:
            bg = copy.copy(bg)
            if isinstance(bg, xml_skin.Image) and bg.visible:
                self.calc_geometry(bg)
                imagefile = ''

                # if this is the real background image, ignore the
                # OVERSCAN to fill the whole screen
                if bg.label == 'background':
                    bg.x -= config.OSD_OVERSCAN_LEFT
                    bg.y -= config.OSD_OVERSCAN_TOP
                    bg.width += (config.OSD_OVERSCAN_LEFT +
                                 config.OSD_OVERSCAN_RIGHT)
                    bg.height += (config.OSD_OVERSCAN_TOP +
                                  config.OSD_OVERSCAN_BOTTOM)

                if bg.label == 'watermark' and self.menu.selected.image:
                    imagefile = self.menu.selected.image
                    if last_watermark != imagefile:
                        self.redraw = True
                    self.watermark = imagefile
                else:
                    imagefile = bg.filename

                # set to 'background' to be added to that image list
                if bg.label != 'top':
                    bg.label = 'background'

                if imagefile:
                    cname = '%s-%s-%s' % (imagefile, bg.width, bg.height)
                    image = self.imagecache[cname]
                    if not image:
                        cache = vfs.getoverlay(
                            '%s.raw-%sx%s' % (imagefile, bg.width, bg.height))
                        if os.path.isfile(cache) and \
                               os.stat(cache)[stat.ST_MTIME] > \
                               os.stat(imagefile)[stat.ST_MTIME]:
                            image = pygame.image.fromstring(
                                file(cache).read(), (bg.width, bg.height),
                                'RGBA')
                            self.imagecache[cname] = image

                    if not image:
                        image = osd.loadbitmap(imagefile)
                        if image:
                            image = pygamesurface_imlib2_scale(
                                image, (bg.width, bg.height))
                            f = vfs.open(cache, 'w')
                            f.write(pygame.image.tostring(image, 'RGBA'))
                            f.close()
                        self.imagecache[cname] = image
                    if image:
                        self.drawimage(image, bg)

            elif isinstance(bg, xml_skin.Rectangle):
                self.calc_geometry(bg)
                self.drawroundbox(bg.x, bg.y, bg.width, bg.height, bg)
Пример #9
0
def format_image(settings,
                 item,
                 width,
                 height,
                 force=False,
                 anamorphic=False,
                 flush_large_image=False):
    logger.log(
        9,
        'format_image(settings=%r, item=%r, width=%r, height=%r, force=%r, anamorphic=%r, flush_large_image=%r)',
        settings, item, width, height, force, anamorphic, flush_large_image)

    cname = generate_cache_key(settings, item, width, height, force)
    cimage = format_imagecache[cname]

    if cimage:
        return cimage

    try:
        type = item.display_type
    except AttributeError:
        try:
            type = item.info['mime'].replace('/', '_')
        except:
            type = item.type
    if type is None:
        type = ''

    image = None
    imagefile = None

    if item.image:
        if isinstance(item.image, imlib2.Image):
            image = osd.loadbitmap(item.image)
        else:
            if not (item.image.startswith('http://')
                    or item.image.startswith('https://')):
                if not os.path.exists(str(item.image)):
                    return None, 0, 0

        image = load_imagecache[item.image]
        if not image:
            image = load_imagecache['thumb://%s' % item.image]

        if not image:
            if item.image.startswith('http://') or item.image.startswith(
                    'https://'):
                image = osd.loadbitmap(item.image)
                load_imagecache[imagefile] = image
            else:
                for folder in ('.thumbs', '.images'):
                    image_parts = os.path.split(str(item.image))
                    ifile = os.path.join(image_parts[0], folder,
                                         image_parts[1])
                    if os.path.exists(ifile):
                        imagefile = ifile
                        break

                if imagefile:
                    image = osd.loadbitmap(imagefile)
                    imagefile = 'thumb://%s' % item.image
                    load_imagecache[imagefile] = image
                else:
                    imagefile = item.image
                    f = open(imagefile, 'rb')
                    tags = exif.process_file(f)
                    f.close()
                    if 'JPEGThumbnail' in tags:
                        sio = StringIO.StringIO(tags['JPEGThumbnail'])
                        image = pygame.image.load(sio)
                        sio.close()
                        imagefile = 'thumb://%s' % item.image
                        load_imagecache[imagefile] = image
                    else:
                        image = osd.loadbitmap(imagefile)
                        load_imagecache[imagefile] = image

            # DJW need to skip this code if the image is from .thumbs or .images as
            # the image has already been rotated in the cache.
            if not item['rotation']:
                try:
                    f = open(imagefile, 'rb')
                    tags = exif.process_file(f)
                    f.close()
                    if tags.has_key('Image Orientation'):
                        orientation = tags['Image Orientation']
                        logger.debug('%s orientation=%s', item['name'],
                                     tags['Image Orientation'])
                        if str(orientation) == "Rotated 90 CCW":
                            item['rotation'] = 270
                        elif str(orientation) == "Rotated 180":
                            item['rotation'] = 180
                        elif str(orientation) == "Rotated 90 CW":
                            item['rotation'] = 90
                except Exception, e:
                    logger.info('%s', e)

            if image and item['rotation']:
                # pygame reverses the image rotation
                if config.IMAGEVIEWER_REVERSED_IMAGES:
                    rotation = item['rotation']
                else:
                    rotation = (360 - item['rotation']) % 360
                image = pygame.transform.rotate(image, rotation)
                load_imagecache[imagefile] = image
Пример #10
0
            imagefile = '%s/mimetypes/%s.png' % (settings.icon_dir, type)

        elif os.path.isfile('%s/mimetypes/%s.png' %
                            (settings.icon_dir, item.type)):
            imagefile = '%s/mimetypes/%s.png' % (settings.icon_dir, item.type)

        elif os.path.isfile('%s/mimetypes/unknown.png' % settings.icon_dir):
            imagefile = '%s/mimetypes/unknown.png' % settings.icon_dir

        if not imagefile:
            return None, 0, 0

        imagefile = 'thumb://%s' % imagefile
        image = load_imagecache[imagefile]
        if not image:
            image = osd.loadbitmap(imagefile)
            load_imagecache[imagefile] = image

        if not image:
            return None, 0, 0

    else:
        force = 0

    if type and len(type) > 4:
        type = type[:5]

    i_w, i_h = image.get_size()
    # this was the original anamorphic code
    #if anamorphic:
    #    i_w  = i_w * 0.75
Пример #11
0
    def __draw_background__(self):
        """
        draw the <background> of the area
        """
        area = self.area_val

        last_watermark = None

        try:
            if self.watermark:
                last_watermark = self.watermark

                try:
                    if self.menu.selected.image != self.watermark:
                        self.watermark = None
                        self.redraw = True
                except:
                    pass
        except:
            pass

        for bg in self.layout.background:
            bg = copy.copy(bg)
            if isinstance(bg, xml_skin.Image) and bg.visible:
                self.calc_geometry(bg)
                imagefile = ''

                # if this is the real background image, ignore the
                # OVERSCAN to fill the whole screen
                if bg.label == 'background':
                    bg.x -= config.OSD_OVERSCAN_LEFT
                    bg.y -= config.OSD_OVERSCAN_TOP
                    bg.width  += (config.OSD_OVERSCAN_LEFT+config.OSD_OVERSCAN_RIGHT)
                    bg.height += (config.OSD_OVERSCAN_TOP+config.OSD_OVERSCAN_BOTTOM)

                if bg.label == 'watermark' and self.menu.selected.image:
                    imagefile = self.menu.selected.image
                    if last_watermark != imagefile:
                        self.redraw = True
                    self.watermark = imagefile
                else:
                    imagefile = bg.filename

                # set to 'background' to be added to that image list
                if bg.label != 'top':
                    bg.label = 'background'

                if imagefile:
                    cname = '%s-%s-%s' % (imagefile, bg.width, bg.height)
                    image = self.imagecache[cname]
                    if not image:
                        cache = vfs.getoverlay('%s.raw-%sx%s' % (imagefile, bg.width, bg.height))
                        if os.path.isfile(cache) and os.stat(cache)[stat.ST_MTIME] > os.stat(imagefile)[stat.ST_MTIME]:
                            image = pygame.image.fromstring(file(cache).read(), (bg.width, bg.height), 'RGBA')
                            self.imagecache[cname] = image

                    if not image:
                        image = osd.loadbitmap(imagefile)
                        if image:
                            image = pygamesurface_imlib2_scale(image, (bg.width, bg.height))
                            f = vfs.open(cache, 'w')
                            f.write(pygame.image.tostring(image, 'RGBA'))
                            f.close()
                        self.imagecache[cname] = image
                    if image:
                        self.drawimage(image, bg)

            elif isinstance(bg, xml_skin.Rectangle):
                self.calc_geometry(bg)
                self.drawroundbox(bg.x, bg.y, bg.width, bg.height, bg)
Пример #12
0
def format_image(settings, item, width, height, force=0, anamorphic=0):
    try:
        type = item.display_type
    except:
        try:
            type = item.info['mime'].replace('/', '_')
        except:
            type = item.type


    if isinstance(item.image, str):
        item_image=Unicode(item.image)
    else:
        item_image=item.image

    cname = '%s-%s-%s-%s-%s-%s-%s' % (settings.icon_dir, item_image, type,
                                      item.type, width, height, force)

    if hasattr(item, 'rotation') and item['rotation']:
        cname = '%s-%s' % (cname, item['rotation'])

    if item.media and item.media.item == item:
        cname = '%s-%s' % (cname, item.media)

    cimage = format_imagecache[cname]

    if cimage:
        return cimage

    image     = None
    imagefile = None

    if item.image:
        if isinstance(item.image, imlib2.Image):
            image = osd.loadbitmap(item.image)
        else:
            #print 'thumb://%r %r' % (item.image, item_image)
            image = load_imagecache['thumb://%s' % item.image]
            if not image:
                image = osd.loadbitmap('thumb://%s' % item.image)
                load_imagecache['thumb://%s' % item.image] = image

        if not item['rotation']:
            try:
                f=open(item.image, 'rb')
                tags=exif.process_file(f)
                f.close()
                if tags.has_key('Image Orientation'):
                    orientation = tags['Image Orientation']
                    _debug_('%s orientation=%s' % (item['name'], tags['Image Orientation']))
                    if str(orientation) == "Rotated 90 CCW":
                        item['rotation'] = 270
                    elif str(orientation) == "Rotated 180":
                        item['rotation'] = 180
                    elif str(orientation) == "Rotated 90 CW":
                        item['rotation'] = 90
            except Exception, e:
                _debug_('%s' % (e), DINFO)

        if image and item['rotation']:
            # pygame reverses the image rotation
            if config.IMAGEVIEWER_REVERSED_IMAGES:
                rotation = (360 - item['rotation']) % 360
            else:
                rotation = item['rotation']
            image = pygame.transform.rotate(image, rotation)
Пример #13
0
        elif os.path.isfile('%s/mimetypes/%s.png' % (settings.icon_dir, type)):
            imagefile = '%s/mimetypes/%s.png' % (settings.icon_dir, type)

        elif os.path.isfile('%s/mimetypes/%s.png' % (settings.icon_dir, item.type)):
            imagefile = '%s/mimetypes/%s.png' % (settings.icon_dir, item.type)

        elif os.path.isfile('%s/mimetypes/unknown.png' % settings.icon_dir):
            imagefile = '%s/mimetypes/unknown.png' % settings.icon_dir

        if not imagefile:
            return None, 0, 0

        image = load_imagecache['thumb://%s' % imagefile]
        if not image:
            image = osd.loadbitmap('thumb://%s' % imagefile)
            load_imagecache['thumb://%s' % imagefile] = image

        if not image:
            return None, 0, 0

    else:
        force = 0

    if type and len(type) > 4:
        type = type[:5]

    i_w, i_h = image.get_size()
    # this was the original anamorphic code
    #if anamorphic:
    #    i_w  = i_w * 0.75
Пример #14
0
def format_image(settings, item, width, height, force=False, anamorphic=False, flush_large_image=False, get_exif_thumbnail=True):
    logger.log( 9, 'format_image(settings=%r, item=%r, width=%r, height=%r, force=%r, anamorphic=%r, flush_large_image=%r, get_exif_thumbnail=%r)', 
        settings, item, width, height, force, anamorphic, flush_large_image, get_exif_thumbnail)

    cname = generate_cache_key(settings, item, width, height, force)
    cimage = format_imagecache[cname]

    if cimage:
        return cimage

    try:
        type = item.display_type
    except AttributeError:
        try:
            type = item.info['mime'].replace('/', '_')
        except:
            type = item.type
    if type is None:
        type = ''

    image     = None
    imagefile = None

    if item.image:
        if isinstance(item.image, imlib2.Image):
            image = osd.loadbitmap(item.image)
        else:
            if not (item.image.startswith('http://') or item.image.startswith('https://')):
                if not os.path.exists(str(item.image)):
                    return None, 0, 0
        
        image = load_imagecache[item.image]
        if not image:
            image = load_imagecache['thumb://%s' % item.image]

        if not image:
            if item.image.startswith('http://') or item.image.startswith('https://'):
                image = osd.loadbitmap(item.image)
                load_imagecache[imagefile] = image
            else:
                for folder in ('.thumbs', '.images'):
                    image_parts = os.path.split(str(item.image))
                    ifile = os.path.join(image_parts[0], folder, image_parts[1])
                    if os.path.exists(ifile):
                        imagefile = ifile
                        break

                if imagefile:
                    image = osd.loadbitmap(imagefile)
                    imagefile = 'thumb://%s' % item.image
                    load_imagecache[imagefile] = image
                else:
                    imagefile = item.image
                    f = open(imagefile, 'rb')
                    tags = exif.process_file(f)
                    f.close()
                    if 'JPEGThumbnail' in tags:
                        sio = StringIO.StringIO(tags['JPEGThumbnail'])
                        image = pygame.image.load(sio)
                        sio.close()
                        imagefile = 'thumb://%s' % item.image
                        load_imagecache[imagefile] = image
                    else:
                        image = osd.loadbitmap(imagefile)
                        load_imagecache[imagefile] = image
                    


            # DJW need to skip this code if the image is from .thumbs or .images as
            # the image has already been rotated in the cache.
            if not item['rotation']:
                try:
                    f = open(imagefile, 'rb')
                    tags = exif.process_file(f)
                    f.close()
                    if tags.has_key('Image Orientation'):
                        orientation = tags['Image Orientation']
                        logger.debug('%s orientation=%s', item['name'], tags['Image Orientation'])
                        if str(orientation) == "Rotated 90 CCW":
                            item['rotation'] = 270
                        elif str(orientation) == "Rotated 180":
                            item['rotation'] = 180
                        elif str(orientation) == "Rotated 90 CW":
                            item['rotation'] = 90
                except Exception, e:
                    logger.info('%s', e)

            if image and item['rotation']:
                # pygame reverses the image rotation
                if config.IMAGEVIEWER_REVERSED_IMAGES:
                    rotation = (360 - item['rotation']) % 360
                else:
                    rotation = item['rotation']
                image = pygame.transform.rotate(image, rotation)
                load_imagecache[imagefile] = image
Пример #15
0
        elif os.path.isfile('%s/mimetypes/%s.png' % (settings.icon_dir, type)):
            imagefile = '%s/mimetypes/%s.png' % (settings.icon_dir, type)

        elif os.path.isfile('%s/mimetypes/%s.png' % (settings.icon_dir, item.type)):
            imagefile = '%s/mimetypes/%s.png' % (settings.icon_dir, item.type)

        elif os.path.isfile('%s/mimetypes/unknown.png' % settings.icon_dir):
            imagefile = '%s/mimetypes/unknown.png' % settings.icon_dir

        if not imagefile:
            return None, 0, 0

        imagefile = 'thumb://%s' % imagefile
        image = load_imagecache[imagefile]
        if not image:
            image = osd.loadbitmap(imagefile)
            load_imagecache[imagefile] = image

        if not image:
            return None, 0, 0

    else:
        force = 0

    if type and len(type) > 4:
        type = type[:5]

    i_w, i_h = image.get_size()
    # this was the original anamorphic code
    #if anamorphic:
    #    i_w  = i_w * 0.75