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,7 +53,12 @@ def rgb(r, g, b, a=255):
def fromqimage(im):
buffer = QBuffer()
buffer.open(QIODevice.ReadWrite)
im.save(buffer, 'ppm')
# 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()
try:

View File

@ -13,9 +13,15 @@ class TestFromQImage(PillowQtTestCase, PillowTestCase):
]
def roundtrip(self, expected):
result = ImageQt.fromqimage(expected.toqimage())
# Qt saves all images as rgb
self.assert_image_equal(result, expected.convert('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):
for im in self.files_to_test: