Correct image by scaling pixels

This commit is contained in:
Andrew Murray 2021-12-14 10:13:09 +11:00
parent e87745d9ec
commit 768c189a29
2 changed files with 12 additions and 4 deletions

View File

@ -2,7 +2,7 @@ import pytest
from PIL import ImageQt from PIL import ImageQt
from .helper import hopper from .helper import assert_image_similar, hopper
pytestmark = pytest.mark.skipif( pytestmark = pytest.mark.skipif(
not ImageQt.qt_is_installed, reason="Qt bindings are not installed" not ImageQt.qt_is_installed, reason="Qt bindings are not installed"
@ -42,11 +42,17 @@ def test_rgb():
def test_image(): def test_image():
for mode in ("1", "RGB", "RGBA", "L", "P"): modes = ["1", "RGB", "RGBA", "L", "P"]
ImageQt.ImageQt(hopper(mode))
qt_format = ImageQt.QImage.Format if ImageQt.qt_version == "6" else ImageQt.QImage qt_format = ImageQt.QImage.Format if ImageQt.qt_version == "6" else ImageQt.QImage
if hasattr(qt_format, "Format_Grayscale16"): # Qt 5.13+ if hasattr(qt_format, "Format_Grayscale16"): # Qt 5.13+
ImageQt.ImageQt(hopper("I;16")) modes.append("I;16")
for mode in modes:
im = hopper(mode)
roundtripped_im = ImageQt.fromqimage(ImageQt.ImageQt(im))
if mode not in ("RGB", "RGBA"):
im = im.convert("RGB")
assert_image_similar(roundtripped_im, im, 1)
def test_closed_file(): def test_closed_file():

View File

@ -168,6 +168,8 @@ def _toqclass_helper(im):
data = im.tobytes("raw", "BGRA") data = im.tobytes("raw", "BGRA")
format = qt_format.Format_ARGB32 format = qt_format.Format_ARGB32
elif im.mode == "I;16" and hasattr(qt_format, "Format_Grayscale16"): # Qt 5.13+ elif im.mode == "I;16" and hasattr(qt_format, "Format_Grayscale16"): # Qt 5.13+
im = im.point(lambda i: i * 256)
format = qt_format.Format_Grayscale16 format = qt_format.Format_Grayscale16
else: else:
if exclusive_fp: if exclusive_fp: