Skip to content

Commit 768c189

Browse files
committed
Correct image by scaling pixels
1 parent e87745d commit 768c189

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Tests/test_imageqt.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from PIL import ImageQt
44

5-
from .helper import hopper
5+
from .helper import assert_image_similar, hopper
66

77
pytestmark = pytest.mark.skipif(
88
not ImageQt.qt_is_installed, reason="Qt bindings are not installed"
@@ -42,11 +42,17 @@ def checkrgb(r, g, b):
4242

4343

4444
def test_image():
45-
for mode in ("1", "RGB", "RGBA", "L", "P"):
46-
ImageQt.ImageQt(hopper(mode))
45+
modes = ["1", "RGB", "RGBA", "L", "P"]
4746
qt_format = ImageQt.QImage.Format if ImageQt.qt_version == "6" else ImageQt.QImage
4847
if hasattr(qt_format, "Format_Grayscale16"): # Qt 5.13+
49-
ImageQt.ImageQt(hopper("I;16"))
48+
modes.append("I;16")
49+
50+
for mode in modes:
51+
im = hopper(mode)
52+
roundtripped_im = ImageQt.fromqimage(ImageQt.ImageQt(im))
53+
if mode not in ("RGB", "RGBA"):
54+
im = im.convert("RGB")
55+
assert_image_similar(roundtripped_im, im, 1)
5056

5157

5258
def test_closed_file():

src/PIL/ImageQt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def _toqclass_helper(im):
168168
data = im.tobytes("raw", "BGRA")
169169
format = qt_format.Format_ARGB32
170170
elif im.mode == "I;16" and hasattr(qt_format, "Format_Grayscale16"): # Qt 5.13+
171+
im = im.point(lambda i: i * 256)
172+
171173
format = qt_format.Format_Grayscale16
172174
else:
173175
if exclusive_fp:

0 commit comments

Comments
 (0)