-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support 16-bit grayscale ImageQt conversion #5856
Support 16-bit grayscale ImageQt conversion #5856
Conversation
When you say that you created 'a valid QImage', did the output visually match what it should? If I take demo code from https://www.pythonguis.com/faq/adding-images-to-pyqt5-applications/, modify it slightly and run with your PR, I just get black. import sys
from PIL import Image, ImageQt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel
# hopper("I;16")
im = Image.open("Tests/images/hopper.ppm")
im = im.convert("I").convert("I;16")
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
label = QLabel(self)
pixmap = QPixmap(ImageQt.toqpixmap(im))
label.setPixmap(pixmap)
self.setCentralWidget(label)
self.resize(pixmap.width(), pixmap.height())
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_()) |
@radarhere it's not exactly black, it's just really really dark. Presumably im = im.convert("I").convert("I;16").point(lambda i: i * 255) |
I'll move my example into tests. diff --git a/Tests/test_imageqt.py b/Tests/test_imageqt.py
index 08cab9976..48f9f370f 100644
--- a/Tests/test_imageqt.py
+++ b/Tests/test_imageqt.py
@@ -46,7 +46,27 @@ def test_image():
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"))
+ im = ImageQt.ImageQt(hopper("I;16"))
+
+ import sys
+ from PyQt5.QtGui import QPixmap
+ from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel
+
+ class MainWindow(QMainWindow):
+
+ def __init__(self):
+ super(MainWindow, self).__init__()
+
+ label = QLabel(self)
+ pixmap = QPixmap.fromImage(im)
+ label.setPixmap(pixmap)
+ self.setCentralWidget(label)
+ self.resize(pixmap.width(), pixmap.height())
+
+ app = QApplication(sys.argv)
+ w = MainWindow()
+ w.show()
+ app.exec_()
def test_closed_file(): The above code still shows the black, or 'really really dark' image. I'm just saying that while this PR may not generate any errors, it is also not producing correct images. That's likely not a problem you've caused - Pillow does not have very good handling of I;16 in general. |
I've created cmbruns#1 to fix the 'really really dark' image. |
e129fab
to
037354e
Compare
037354e
to
768c189
Compare
Steps to reproduce:
Expected behavior: A valid QImage is created.
Behavior without this code change:
ValueError: unsupported image mode 'I;16'
I verified that a valid QImage is created with this change. Sorry I cannot share the test image I am using.