예제 #1
0
 def run(self):
     if not self.image:
         self.home.clearProperty('TMDbHelper.ListItem.BlurImage')
         return
     filename = '{}{}.png'.format(utils.md5hash(self.image), self.radius)
     blurname = self.blur(self.image, filename)
     self.home.setProperty('TMDbHelper.ListItem.BlurImage', blurname)
    def colors(self, source):
        filename = '{}.png'.format(utils.md5hash(source))
        destination = self.save_path + filename

        try:
            if xbmcvfs.exists(destination):
                os.utime(destination, None)
                img = Image.open(xbmcvfs.translatepath(destination))
            else:
                img = _openimage(source, self.save_path, filename)
                img.thumbnail((256, 256))
                img = img.convert('RGB')
                img.save(destination)

            avg_rgb = self.get_avg_color(img)
            maincolor_rgb = self.get_maincolor(*avg_rgb)
            maincolor_hex = self.rgb_to_hex(*self.get_color_lumsat(
                *maincolor_rgb))
            compcolor_rgb = self.get_compcolor(*avg_rgb)
            compcolor_hex = self.rgb_to_hex(*self.get_color_lumsat(
                *compcolor_rgb))

            maincolor_propname = self.save_prop + '.Main'
            maincolor_propchek = self.save_prop + '.MainCheck'
            maincolor_propvalu = _homewindow.getProperty(maincolor_propname)
            if not maincolor_propvalu:
                _homewindow.setProperty(maincolor_propname, maincolor_hex)
            else:
                _homewindow.setProperty(maincolor_propchek, maincolor_propvalu)
                thread_maincolor = Thread(target=self.set_prop_colorgradient,
                                          args=[
                                              maincolor_propname,
                                              maincolor_propvalu,
                                              maincolor_hex, maincolor_propchek
                                          ])
                thread_maincolor.start()

            compcolor_propname = self.save_prop + '.Comp'
            compcolor_propchek = self.save_prop + '.CompCheck'
            compcolor_propvalu = _homewindow.getProperty(compcolor_propname)
            if not compcolor_propvalu:
                _homewindow.setProperty(compcolor_propname, compcolor_hex)
            else:
                _homewindow.setProperty(compcolor_propchek, compcolor_propvalu)
                thread_compcolor = Thread(target=self.set_prop_colorgradient,
                                          args=[
                                              compcolor_propname,
                                              compcolor_propvalu,
                                              compcolor_hex, compcolor_propchek
                                          ])
                thread_compcolor.start()

            img.close()
            return maincolor_hex

        except Exception as exc:
            utils.kodi_log(exc, 1)
            return ''
    def desaturate(self, source):
        filename = '{}.png'.format(utils.md5hash(source))
        destination = self.save_path + filename
        try:
            if xbmcvfs.exists(destination):
                os.utime(destination, None)
            else:
                img = _openimage(source, self.save_path, filename)
                img = img.convert('LA')
                img.save(destination)
                img.close()

            return destination

        except Exception:
            return ''
    def crop(self, source):
        filename = 'cropped-{}.png'.format(utils.md5hash(source))
        destination = self.save_path + filename
        try:
            if xbmcvfs.exists(destination):
                os.utime(destination, None)
            else:
                img = _openimage(source, self.save_path, filename)
                img = img.crop(img.convert('RGBa').getbbox())
                img.save(destination)
                img.close()

            return destination

        except Exception:
            return ''
    def blur(self, source, radius=20):
        filename = '{}{}.png'.format(utils.md5hash(source), radius)
        destination = self.save_path + filename
        try:
            if xbmcvfs.exists(destination):
                os.utime(destination, None)
            else:
                img = _openimage(source, self.save_path, filename)
                img.thumbnail((256, 256))
                img = img.convert('RGB')
                img = img.filter(ImageFilter.GaussianBlur(radius))
                img.save(destination)
                img.close()

            return destination

        except Exception:
            return ''