Skip to content

Commit

Permalink
Refactor frame render
Browse files Browse the repository at this point in the history
  • Loading branch information
JargeZ committed Aug 13, 2021
1 parent 56db9a8 commit 9e8529c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/NtscApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 9e8529c

Please sign in to comment.