mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
preserve alpha during conversion; add tests; found bug and added TODOs
This commit is contained in:
parent
86e775daa3
commit
e67a4c4270
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user