mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 11:35:52 +03:00
Merge pull request #1429 from ericfrederich/conversion
use png when converting from a QImage to a Pillow Image
This commit is contained in:
commit
eaabb21b4a
|
@ -53,7 +53,12 @@ def rgb(r, g, b, a=255):
|
||||||
def fromqimage(im):
|
def fromqimage(im):
|
||||||
buffer = QBuffer()
|
buffer = QBuffer()
|
||||||
buffer.open(QIODevice.ReadWrite)
|
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()
|
b = BytesIO()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -13,9 +13,15 @@ class TestFromQImage(PillowQtTestCase, PillowTestCase):
|
||||||
]
|
]
|
||||||
|
|
||||||
def roundtrip(self, expected):
|
def roundtrip(self, expected):
|
||||||
result = ImageQt.fromqimage(expected.toqimage())
|
# PIL -> Qt
|
||||||
# Qt saves all images as rgb
|
intermediate = expected.toqimage()
|
||||||
self.assert_image_equal(result, expected.convert('RGB'))
|
# 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):
|
def test_sanity_1(self):
|
||||||
for im in self.files_to_test:
|
for im in self.files_to_test:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user