preserve alpha during conversion; add tests; found bug and added TODOs

This commit is contained in:
Eric L Frederich 2015-09-16 16:59:52 -04:00 committed by Eric L Frederich
parent 86e775daa3
commit e67a4c4270
2 changed files with 15 additions and 4 deletions

View File

@ -53,6 +53,11 @@ def rgb(r, g, b, a=255):
def fromqimage(im):
buffer = QBuffer()
buffer.open(QIODevice.ReadWrite)
# preserve alha channel with png
# otherwise ppm is more friendly with Image.open
if im.hasAlphaChannel():
im.save(buffer, 'png')
else:
im.save(buffer, 'ppm')
b = BytesIO()

View File

@ -13,8 +13,14 @@ class TestFromQImage(PillowQtTestCase, PillowTestCase):
]
def roundtrip(self, expected):
result = ImageQt.fromqimage(expected.toqimage())
# Qt saves all images as rgb
# PIL -> Qt
intermediate = expected.toqimage()
# Qt -> PIL
result = ImageQt.fromqimage(intermediate)
if intermediate.hasAlphaChannel():
self.assert_image_equal(result, expected.convert('RGBA'))
else:
self.assert_image_equal(result, expected.convert('RGB'))
def test_sanity_1(self):