Bug-fix and small changes in RawImageWidget.py
1. Bug was in the `def paintGL(self)` method (at least with PySide1): image was mirrored upside down. 2. Added support for `setConfigOptions(imageAxisOrder='row-major')` 3. Small cosmetic changes
This commit is contained in:
parent
8a40c22848
commit
54ddb79e89
@ -1,15 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
RawImageWidget.py
|
||||
Copyright 2010-2016 Luke Campagnola
|
||||
Distributed under MIT/X11 license. See license.txt for more infomation.
|
||||
"""
|
||||
|
||||
from ..Qt import QtCore, QtGui
|
||||
|
||||
try:
|
||||
from ..Qt import QtOpenGL
|
||||
from OpenGL.GL import *
|
||||
|
||||
HAVE_OPENGL = True
|
||||
except Exception:
|
||||
except (ImportError, AttributeError):
|
||||
# Would prefer `except ImportError` here, but some versions of pyopengl generate
|
||||
# AttributeError upon import
|
||||
HAVE_OPENGL = False
|
||||
|
||||
from .. import functions as fn
|
||||
import numpy as np
|
||||
from .. import getConfigOption, functions as fn
|
||||
|
||||
|
||||
class RawImageWidget(QtGui.QWidget):
|
||||
"""
|
||||
@ -17,9 +26,11 @@ class RawImageWidget(QtGui.QWidget):
|
||||
Generally using an ImageItem inside GraphicsView is fast enough.
|
||||
On some systems this may provide faster video. See the VideoSpeedTest example for benchmarking.
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None, scaled=False):
|
||||
"""
|
||||
Setting scaled=True will cause the entire image to be displayed within the boundaries of the widget. This also greatly reduces the speed at which it will draw frames.
|
||||
Setting scaled=True will cause the entire image to be displayed within the boundaries of the widget.
|
||||
This also greatly reduces the speed at which it will draw frames.
|
||||
"""
|
||||
QtGui.QWidget.__init__(self, parent)
|
||||
self.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))
|
||||
@ -67,7 +78,10 @@ if HAVE_OPENGL:
|
||||
"""
|
||||
Similar to RawImageWidget, but uses a GL widget to do all drawing.
|
||||
Perfomance varies between platforms; see examples/VideoSpeedTest for benchmarking.
|
||||
|
||||
Checks if setConfigOptions(imageAxisOrder='row-major') was set.
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None, scaled=False):
|
||||
QtOpenGL.QGLWidget.__init__(self, parent)
|
||||
self.scaled = scaled
|
||||
@ -75,6 +89,7 @@ if HAVE_OPENGL:
|
||||
self.uploaded = False
|
||||
self.smooth = False
|
||||
self.opts = None
|
||||
self.row_major = getConfigOption('imageAxisOrder') == 'row-major'
|
||||
|
||||
def setImage(self, img, *args, **kargs):
|
||||
"""
|
||||
@ -101,14 +116,19 @@ if HAVE_OPENGL:
|
||||
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_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER)
|
||||
shape = self.image.shape
|
||||
|
||||
if self.row_major:
|
||||
image = self.image
|
||||
else:
|
||||
image = self.image.transpose((1, 0, 2))
|
||||
|
||||
# ## Test texture dimensions first
|
||||
# shape = self.image.shape
|
||||
# glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, shape[0], shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, None)
|
||||
# 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])
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shape[0], shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, self.image.transpose((1,0,2)))
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.shape[1], image.shape[0], 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
|
||||
glDisable(GL_TEXTURE_2D)
|
||||
|
||||
def paintGL(self):
|
||||
@ -128,16 +148,13 @@ if HAVE_OPENGL:
|
||||
glColor4f(1, 1, 1, 1)
|
||||
|
||||
glBegin(GL_QUADS)
|
||||
glTexCoord2f(0,0)
|
||||
glVertex3f(-1,-1,0)
|
||||
glTexCoord2f(1,0)
|
||||
glVertex3f(1, -1, 0)
|
||||
glTexCoord2f(1,1)
|
||||
glVertex3f(1, 1, 0)
|
||||
glTexCoord2f(0, 1)
|
||||
glVertex3f(-1, -1, 0)
|
||||
glTexCoord2f(1, 1)
|
||||
glVertex3f(1, -1, 0)
|
||||
glTexCoord2f(1, 0)
|
||||
glVertex3f(1, 1, 0)
|
||||
glTexCoord2f(0, 0)
|
||||
glVertex3f(-1, 1, 0)
|
||||
glEnd()
|
||||
glDisable(GL_TEXTURE_3D)
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user