Skip to content

Commit

Permalink
Check if installed Qt version supports Format_Grayscale16
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbruns authored and radarhere committed Dec 14, 2021
1 parent b1cc094 commit e87745d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Tests/test_imageqt.py
Expand Up @@ -42,8 +42,11 @@ def checkrgb(r, g, b):


def test_image():
for mode in ("1", "RGB", "RGBA", "L", "P", "I;16"):
for mode in ("1", "RGB", "RGBA", "L", "P"):
ImageQt.ImageQt(hopper(mode))
qt_format = ImageQt.QImage.Format if ImageQt.qt_version == "6" else ImageQt.QImage
if hasattr(qt_format, "Format_Grayscale16"): # Qt 5.13+
ImageQt.ImageQt(hopper("I;16"))


def test_closed_file():
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageQt.py
Expand Up @@ -167,7 +167,7 @@ def _toqclass_helper(im):
elif im.mode == "RGBA":
data = im.tobytes("raw", "BGRA")
format = qt_format.Format_ARGB32
elif im.mode == "I;16":
elif im.mode == "I;16" and hasattr(qt_format, "Format_Grayscale16"): # Qt 5.13+
format = qt_format.Format_Grayscale16
else:
if exclusive_fp:
Expand Down

0 comments on commit e87745d

Please sign in to comment.