Ejemplo n.º 1
0
    def test_sanity(self):
        for mode in ("RGB", "RGBA", "L", "P", "1"):
            src = hopper(mode)
            data = ImageQt.toqimage(src)

            assert isinstance(data, QImage)
            assert not data.isNull()

            # reload directly from the qimage
            rt = ImageQt.fromqimage(data)
            if mode in ("L", "P", "1"):
                assert_image_equal(rt, src.convert("RGB"))
            else:
                assert_image_equal(rt, src)

            if mode == "1":
                # BW appears to not save correctly on QT4 and QT5
                # kicks out errors on console:
                #     libpng warning: Invalid color type/bit depth combination
                #                     in IHDR
                #     libpng error: Invalid IHDR data
                continue

            # Test saving the file
            tempfile = self.tempfile("temp_{}.png".format(mode))
            data.save(tempfile)

            # Check that it actually worked.
            with Image.open(tempfile) as reloaded:
                assert_image_equal(reloaded, src)
Ejemplo n.º 2
0
    def test_sanity(self):
        for mode in ('RGB', 'RGBA', 'L', 'P', '1'):
            src = hopper(mode)
            data = ImageQt.toqimage(src)

            self.assertIsInstance(data, QImage)
            self.assertFalse(data.isNull())

            # reload directly from the qimage
            rt = ImageQt.fromqimage(data)
            if mode in ('L', 'P', '1'):
                self.assert_image_equal(rt, src.convert('RGB'))
            else:
                self.assert_image_equal(rt, src)

            if mode == '1':
                # BW appears to not save correctly on QT4 and QT5
                # kicks out errors on console:
                #     libpng warning: Invalid color type/bit depth combination
                #                     in IHDR
                #     libpng error: Invalid IHDR data
                continue

            # Test saving the file
            tempfile = self.tempfile('temp_{}.png'.format(mode))
            data.save(tempfile)

            # Check that it actually worked.
            reloaded = Image.open(tempfile)
            # Gray images appear to come back in palette mode.
            # They're roughly equivalent
            if QT_VERSION == 4 and mode == 'L':
                src = src.convert('P')
            self.assert_image_equal(reloaded, src)
Ejemplo n.º 3
0
    def test_sanity(self):
        for mode in ('RGB', 'RGBA', 'L', 'P', '1'):
            src = hopper(mode)
            data = ImageQt.toqimage(src)

            self.assertIsInstance(data, QImage)
            self.assertFalse(data.isNull())

            # reload directly from the qimage
            rt = ImageQt.fromqimage(data)
            if mode in ('L', 'P', '1'):
                self.assert_image_equal(rt, src.convert('RGB'))
            else:
                self.assert_image_equal(rt, src)

            if mode == '1':
                # BW appears to not save correctly on QT4 and QT5
                # kicks out errors on console:
                #     libpng warning: Invalid color type/bit depth combination
                #                     in IHDR
                #     libpng error: Invalid IHDR data
                continue

            # Test saving the file
            tempfile = self.tempfile('temp_{}.png'.format(mode))
            data.save(tempfile)

            # Check that it actually worked.
            reloaded = Image.open(tempfile)
            # Gray images appear to come back in palette mode.
            # They're roughly equivalent
            if QT_VERSION == 4 and mode == 'L':
                src = src.convert('P')
            self.assert_image_equal(reloaded, src)
Ejemplo n.º 4
0
    def updateThumb(self, thumbId: int, path: str, pic: Image.Image):
        thumb = ImageQt.toqimage(pic)
        thumb = self.resizeImage(thumb, (self.thumbWidth, self.thumbHeight))
        thumb = QPixmap.fromImage(thumb)

        self.thumbs[path] = thumb
        self.repaintCanvas()
Ejemplo n.º 5
0
    def updateThumb(self, thumbId : int, path : str, pic : Image.Image):
        thumb = ImageQt.toqimage(pic)
        thumb = self.resizeImage(thumb, (self.thumbWidth, self.thumbHeight))
        thumb = QPixmap.fromImage(thumb)

        self.thumbs[path] = thumb
        self.repaintCanvas()
Ejemplo n.º 6
0
    def test_sanity(self):
        PillowQtTestCase.setUp(self)
        for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
            data = ImageQt.toqimage(hopper(mode))

            self.assertIsInstance(data, QImage)
            self.assertFalse(data.isNull())

            # Test saving the file
            tempfile = self.tempfile('temp_{0}.png'.format(mode))
            data.save(tempfile)
Ejemplo n.º 7
0
    def _window_paint(self, event):
        if self.control is None:
            return

        # self._gc is an image context
        w = self._gc.width()
        h = self._gc.height()
        pilimage = Image.frombuffer("RGBA", (w, h), self._gc, "raw", "RGBA", 0,
                                    1)
        image = ImageQt.toqimage(pilimage)
        rect = QtCore.QRectF(0, 0, self.control.width(), self.control.height())
        painter = QtGui.QPainter(self.control)
        painter.drawImage(rect, image)