Exemple #1
0
 def GetImage(self, picture):
     key = picture.GetKey()
     if key not in self._wxImgCache:
         pilImg = PILBackend.GetThumbnail(picture, width=ImageCache.SIZE)
         wxImg = wx.Image(PILBackend.ImageToStream(pilImg), wx.BITMAP_TYPE_JPEG)
         self._wxImgCache[key] = wxImg
     return self._wxImgCache[key]
Exemple #2
0
    def run(self):
        self._abort = False
        for __ in range(20):
            time.sleep(0.1)
            if self._abort:
                return

        pilImg = PILBackend.GetImage(self._picture)
        wxImg = wx.Image(PILBackend.ImageToStream(pilImg), wx.BITMAP_TYPE_JPEG)

        if not self._abort:
            self._callbackOnDone(wxImg)
Exemple #3
0
 def Run(self, jobContext):
     image = jobContext.ProcessSubTask(self.taskLoadPic)
     img = PILBackend.CropAndResize(image,
                                    self.rect,
                                    self.resolution,
                                    self.draft)
     return img
Exemple #4
0
 def __LoadThumbnail(self, pic, picId):
     ImageCache().RegisterPicture(pic)
     return
     thumbNail = None
     if self.__fileRev >= 3:
         cur = self.__GetCursor()
         cur.execute("SELECT * FROM `thumbnail` WHERE picture_id=?", (picId,))
         row = cur.fetchone()
         if row:
             thumbWidth = row["width"]
             thumbHeight = row["height"]
             thumbData = row["data"]
             thumbNail = PILBackend.ImageFromBuffer((thumbWidth, thumbHeight), thumbData)
     if thumbNail is None:
         thumbNail = PILBackend.GetThumbnail(pic, height=120)
     ImageCache().RegisterPicture(pic, thumbNail)
Exemple #5
0
    def Run(self, jobContext):
        image1 = jobContext.ProcessSubTask(self.taskPic1)
        image2 = jobContext.ProcessSubTask(self.taskPic2)
        img = PILBackend.Transition(self.kind,
                                    image1, image2,
                                    self.percentage)

        return img
Exemple #6
0
    def __ThumbToQuery(self, picId, pic):
        pilThumb = PILBackend.GetThumbnail(pic, height=120)
        thumbWidth, thumbHeight = pilThumb.size
        thumbData = pilThumb.tobytes()

        query = "INSERT INTO `thumbnail` (" \
                    "picture_id, width, height, data" \
                ") VALUES (" \
                    "?, ?, ?, ?" \
                ");"
        values = (picId, thumbWidth, thumbHeight, thumbData)
        return query, values
Exemple #7
0
    def GetPreviewThumb(self):
        if not self.Load():
            return None

        img = None
        pics = self._project.GetPictures()
        imgCount = len(pics)
        if imgCount > 0:
            picIdx = random.randint(0, imgCount - 1)
            pic = pics[picIdx]
            if os.path.exists(pic.GetFilename()):
                img = PILBackend.GetThumbnail(pic, width=136, height=70)
                if pic.IsDummy():
                    img = None
        return img
Exemple #8
0
    def run(self):
        while self.active:
            pic = None
            try:
                pic = self.queue.pop(0)
            except IndexError:
                time.sleep(0.1)
                continue

            pilImg = PILBackend.GetThumbnail(pic, height=ImageCache.THUMB_SIZE)
            self.imgCache.RegisterPicture(pic, pilImg)

            if self.imgCache.win:
                evt = ThumbnailReadyEvent(pic)
                wx.PostEvent(self.imgCache.win, evt)
Exemple #9
0
    def GetThumbBmp(self, picture):
        key = picture.GetKey()
        if key not in self._wxBmpCache:
            pilImg = self._pilCache.get(key)
            if pilImg is None:
                self._pilCache[key] = self._inScalingQueue
                self.scaleThread.queue.append(picture)
                return self.thumb
            elif pilImg is self._inScalingQueue:
                return self.thumb
            else:
#                pilImg = self._pilCache[key]
                wxImg = wx.Image(PILBackend.ImageToStream(pilImg), wx.BITMAP_TYPE_JPEG)
                self._wxBmpCache[key] = wxImg.ConvertToBitmap()
        return self._wxBmpCache[key]
Exemple #10
0
    def __init__(self, parent, size=wx.DefaultSize, filename=None):
        self.filename = filename

        if not LinkOpenPfs.BMP_MAP.has_key(filename):
            prjFile = ProjectFile(filename=filename)
            imgCount = prjFile.GetPicCount()
            img = prjFile.GetPreviewThumb()
            if img is not None:
                wxImg = wx.ImageFromStream(PILBackend.ImageToStream(img), wx.BITMAP_TYPE_JPEG)
                bmp = wxImg.ConvertToBitmap()
            else:
                bmp = wx.ArtProvider.GetBitmap("PFS_ICON_48", wx.ART_OTHER)
            descr = "%d images" % imgCount
            LinkOpenPfs.BMP_MAP[filename] = (bmp, descr)

        bmp, descr = LinkOpenPfs.BMP_MAP[filename]

        IconLabelLink.__init__(self, parent, size,
                               os.path.splitext(os.path.basename(filename))[0],
                               bmp,
                               descr)
Exemple #11
0
    def Execute(self):
        try:
            width, height = PILBackend.GetImageSize(
                self.__picture.GetFilename())
        except:
            return

        ratio = Aspect.ToFloat(self.__aspect)
        picRatio = width / float(height)
        if picRatio > ratio:
            scaledWidth = height * ratio
            scaledHeight = height
        else:
            scaledWidth = width
            scaledHeight = width / ratio

        centerRect = (int(round((width - scaledWidth) / 2.0)),
                      int(round((height - scaledHeight) / 2.0)),
                      int(round(scaledWidth)), int(round(scaledHeight)))
        self.__picture.SetStartRect(centerRect)
        self.__picture.SetTargetRect(centerRect)
Exemple #12
0
    def Execute(self):
        try:
            width, height = PILBackend.GetImageSize(
                self.__picture.GetFilename())
        except:
            return

        if self.__picture.GetWidth() == -1:
            # FIXME: stupid if
            self.__picture.SetWidth(width)
            self.__picture.SetHeight(height)

        ratio = Aspect.ToFloat(self.__aspect)
        if width < height:
            # portrait
            startRect = (0, 0, width, width / ratio)
            targetRect = (0, height - (width / ratio), width, width / ratio)
        else:
            scaledWidth = width * 0.75
            startRect = (0, 0, width, width / ratio)
            d = random.randint(0, 3)
            if d == 0:
                targetRect = (0, 0, scaledWidth, scaledWidth / ratio)
            elif d == 1:
                targetRect = (0, height - (scaledWidth / ratio), scaledWidth,
                              scaledWidth / ratio)
            elif d == 2:
                targetRect = (width - scaledWidth, 0, scaledWidth,
                              scaledWidth / ratio)
            elif d == 3:
                targetRect = (width - scaledWidth,
                              height - (scaledWidth / ratio), scaledWidth,
                              scaledWidth / ratio)

        if random.randint(0, 1):
            targetRect, startRect = startRect, targetRect

        self.__picture.SetStartRect(startRect)
        self.__picture.SetTargetRect(targetRect)
Exemple #13
0
 def Run(self, jobContext):
     return PILBackend.GetImage(self.picture)