示例#1
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)
示例#2
0
    def roundtrip(self, expected):
        # PIL2 -> Qt
        intermediate = expected.toqimage()
        # Qt -> PIL2
        result = ImageQt.fromqimage(intermediate)

        if intermediate.hasAlphaChannel():
            self.assert_image_equal(result, expected.convert('RGBA'))
        else:
            self.assert_image_equal(result, expected.convert('RGB'))
示例#3
0
    def test_sanity(self):
        for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
            data = ImageQt.toqpixmap(hopper(mode))

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

            # Test saving the file
            tempfile = self.tempfile('temp_{}.png'.format(mode))
            data.save(tempfile)
示例#4
0
        def __init__(self):
            super(Example, self).__init__()

            img = hopper().resize((1000, 1000))

            qimage = ImageQt.ImageQt(img)

            pixmap1 = QtGui.QPixmap.fromImage(qimage)

            hbox = QHBoxLayout(self)

            lbl = QLabel(self)
            # Segfault in the problem
            lbl.setPixmap(pixmap1.copy())
示例#5
0
 def roundtrip(self, expected):
     result = ImageQt.fromqpixmap(ImageQt.toqpixmap(expected))
     # Qt saves all pixmaps as rgb
     self.assert_image_equal(result, expected.convert('RGB'))
示例#6
0
 def test_image(self):
     for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
         ImageQt.ImageQt(hopper(mode))
示例#7
0
 def checkrgb(r, g, b):
     val = ImageQt.rgb(r, g, b)
     val = val % 2**24  # drop the alpha
     self.assertEqual(val >> 16, r)
     self.assertEqual(((val >> 8) % 2**8), g)
     self.assertEqual(val % 2**8, b)