From 9e8529ca7a8b2d79b04cc8d120bd035c77d4dcf0 Mon Sep 17 00:00:00 2001 From: JargeZ Date: Fri, 13 Aug 2021 20:54:40 +0300 Subject: [PATCH] Refactor frame render --- app/NtscApp.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/NtscApp.py b/app/NtscApp.py index 65777e0..41bbb10 100755 --- a/app/NtscApp.py +++ b/app/NtscApp.py @@ -558,12 +558,20 @@ def export_import_config(self): self.nt_set_config(config) @QtCore.pyqtSlot(object) - def render_preview(self, img): - image = QtGui.QImage(img.data.tobytes(), img.shape[1], img.shape[0], QtGui.QImage.Format_RGB888) \ + def render_preview(self, img: ndarray): + # https://stackoverflow.com/questions/41596940/qimage-skews-some-images-but-not-others + + height, width, _ = img.shape + # calculate the total number of bytes in the frame + totalBytes = img.nbytes + # divide by the number of rows + bytesPerLine = int(totalBytes / height) + + image = QtGui.QImage(img.tobytes(), width, height, bytesPerLine, QtGui.QImage.Format_RGB888) \ .rgbSwapped() + max_h = self.image_frame.height() - h, w, _ = img.shape - if h > max_h: + if height > max_h: self.image_frame.setPixmap(QtGui.QPixmap.fromImage(image).scaledToHeight(max_h)) else: self.image_frame.setPixmap(QtGui.QPixmap.fromImage(image))