From e87745d9ec34e76fbe236bd3a6ff1225762e04ad Mon Sep 17 00:00:00 2001 From: Christopher Bruns Date: Mon, 29 Nov 2021 19:38:57 -0800 Subject: [PATCH] Check if installed Qt version supports Format_Grayscale16 --- Tests/test_imageqt.py | 5 ++++- src/PIL/ImageQt.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Tests/test_imageqt.py b/Tests/test_imageqt.py index a7947b0a2..08cab9976 100644 --- a/Tests/test_imageqt.py +++ b/Tests/test_imageqt.py @@ -42,8 +42,11 @@ def test_rgb(): 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(): diff --git a/src/PIL/ImageQt.py b/src/PIL/ImageQt.py index f10de3258..8970314d9 100644 --- a/src/PIL/ImageQt.py +++ b/src/PIL/ImageQt.py @@ -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: