2019-07-06 23:40:53 +03:00
|
|
|
from PIL import Image, ImageQt
|
|
|
|
|
2019-02-03 18:34:53 +03:00
|
|
|
from .helper import PillowTestCase, hopper
|
2019-01-13 20:00:12 +03:00
|
|
|
from .test_imageqt import PillowQtTestCase
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
class TestFromQImage(PillowQtTestCase, PillowTestCase):
|
|
|
|
|
2015-09-17 16:32:15 +03:00
|
|
|
files_to_test = [
|
|
|
|
hopper(),
|
2019-06-13 18:54:24 +03:00
|
|
|
Image.open("Tests/images/transparent.png"),
|
|
|
|
Image.open("Tests/images/7x13.png"),
|
2015-09-17 16:32:15 +03:00
|
|
|
]
|
2015-12-10 01:35:35 +03:00
|
|
|
|
2014-09-15 22:24:56 +04:00
|
|
|
def roundtrip(self, expected):
|
2015-09-16 23:59:52 +03:00
|
|
|
# PIL -> Qt
|
|
|
|
intermediate = expected.toqimage()
|
|
|
|
# Qt -> PIL
|
|
|
|
result = ImageQt.fromqimage(intermediate)
|
|
|
|
|
|
|
|
if intermediate.hasAlphaChannel():
|
2019-06-13 18:54:24 +03:00
|
|
|
self.assert_image_equal(result, expected.convert("RGBA"))
|
2015-09-16 23:59:52 +03:00
|
|
|
else:
|
2019-06-13 18:54:24 +03:00
|
|
|
self.assert_image_equal(result, expected.convert("RGB"))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def test_sanity_1(self):
|
2015-09-17 16:32:15 +03:00
|
|
|
for im in self.files_to_test:
|
2019-06-13 18:54:24 +03:00
|
|
|
self.roundtrip(im.convert("1"))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def test_sanity_rgb(self):
|
2015-09-17 16:32:15 +03:00
|
|
|
for im in self.files_to_test:
|
2019-06-13 18:54:24 +03:00
|
|
|
self.roundtrip(im.convert("RGB"))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def test_sanity_rgba(self):
|
2015-09-17 16:32:15 +03:00
|
|
|
for im in self.files_to_test:
|
2019-06-13 18:54:24 +03:00
|
|
|
self.roundtrip(im.convert("RGBA"))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def test_sanity_l(self):
|
2015-09-17 16:32:15 +03:00
|
|
|
for im in self.files_to_test:
|
2019-06-13 18:54:24 +03:00
|
|
|
self.roundtrip(im.convert("L"))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def test_sanity_p(self):
|
2015-09-17 16:32:15 +03:00
|
|
|
for im in self.files_to_test:
|
2019-06-13 18:54:24 +03:00
|
|
|
self.roundtrip(im.convert("P"))
|