Merge pull request #1597 from pijyoi/fix_dim2

RawImageWidget: transpose did not handle luminance only images
This commit is contained in:
Ogi Moore 2021-02-20 09:24:18 -08:00 committed by GitHub
commit 5b1ac7acaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,10 +6,10 @@ Distributed under MIT/X11 license. See license.txt for more infomation.
""" """
from .. import getConfigOption, functions as fn, getCupy from .. import getConfigOption, functions as fn, getCupy
from ..Qt import QtCore, QtGui from ..Qt import QtCore, QtGui, QtWidgets
try: try:
from ..Qt import QtWidgets QOpenGLWidget = QtWidgets.QOpenGLWidget
from OpenGL.GL import * from OpenGL.GL import *
HAVE_OPENGL = True HAVE_OPENGL = True
@ -43,8 +43,8 @@ class RawImageWidget(QtGui.QWidget):
img must be ndarray of shape (x,y), (x,y,3), or (x,y,4). img must be ndarray of shape (x,y), (x,y,3), or (x,y,4).
Extra arguments are sent to functions.makeARGB Extra arguments are sent to functions.makeARGB
""" """
if getConfigOption('imageAxisOrder') == 'row-major': if getConfigOption('imageAxisOrder') == 'col-major':
img = img.transpose((1, 0, 2)) img = img.swapaxes(0, 1)
self.opts = (img, args, kargs) self.opts = (img, args, kargs)
self.image = None self.image = None
self.update() self.update()
@ -56,7 +56,7 @@ class RawImageWidget(QtGui.QWidget):
argb, alpha = fn.makeARGB(self.opts[0], *self.opts[1], **self.opts[2]) argb, alpha = fn.makeARGB(self.opts[0], *self.opts[1], **self.opts[2])
if self._cp and self._cp.get_array_module(argb) == self._cp: if self._cp and self._cp.get_array_module(argb) == self._cp:
argb = argb.get() # transfer GPU data back to the CPU argb = argb.get() # transfer GPU data back to the CPU
self.image = fn.makeQImage(argb, alpha) self.image = fn.makeQImage(argb, alpha, copy=False, transpose=False)
self.opts = () self.opts = ()
# if self.pixmap is None: # if self.pixmap is None:
# self.pixmap = QtGui.QPixmap.fromImage(self.image) # self.pixmap = QtGui.QPixmap.fromImage(self.image)
@ -78,7 +78,7 @@ class RawImageWidget(QtGui.QWidget):
if HAVE_OPENGL: if HAVE_OPENGL:
class RawImageGLWidget(QtWidgets.QOpenGLWidget): class RawImageGLWidget(QOpenGLWidget):
""" """
Similar to RawImageWidget, but uses a GL widget to do all drawing. Similar to RawImageWidget, but uses a GL widget to do all drawing.
Performance varies between platforms; see examples/VideoSpeedTest for benchmarking. Performance varies between platforms; see examples/VideoSpeedTest for benchmarking.
@ -87,7 +87,7 @@ if HAVE_OPENGL:
""" """
def __init__(self, parent=None, scaled=False): def __init__(self, parent=None, scaled=False):
QtWidgets.QOpenGLWidget.__init__(self, parent) QOpenGLWidget.__init__(self, parent)
self.scaled = scaled self.scaled = scaled
self.image = None self.image = None
self.uploaded = False self.uploaded = False
@ -99,6 +99,8 @@ if HAVE_OPENGL:
img must be ndarray of shape (x,y), (x,y,3), or (x,y,4). img must be ndarray of shape (x,y), (x,y,3), or (x,y,4).
Extra arguments are sent to functions.makeARGB Extra arguments are sent to functions.makeARGB
""" """
if getConfigOption('imageAxisOrder') == 'col-major':
img = img.swapaxes(0, 1)
self.opts = (img, args, kargs) self.opts = (img, args, kargs)
self.image = None self.image = None
self.uploaded = False self.uploaded = False
@ -119,10 +121,6 @@ if HAVE_OPENGL:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER)
# glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER) # glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER)
if getConfigOption('imageAxisOrder') == 'row-major':
image = self.image
else:
image = self.image.transpose((1, 0, 2))
## Test texture dimensions first ## Test texture dimensions first
# shape = self.image.shape # shape = self.image.shape
@ -130,7 +128,8 @@ if HAVE_OPENGL:
# if glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH) == 0: # if glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH) == 0:
# raise Exception("OpenGL failed to create 2D texture (%dx%d); too large for this hardware." % shape[:2]) # raise Exception("OpenGL failed to create 2D texture (%dx%d); too large for this hardware." % shape[:2])
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.shape[1], image.shape[0], 0, GL_RGBA, GL_UNSIGNED_BYTE, image) h, w = self.image.shape[:2]
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, self.image)
glDisable(GL_TEXTURE_2D) glDisable(GL_TEXTURE_2D)
self.uploaded = True self.uploaded = True