remove little-endian assumption for image export
This commit is contained in:
parent
6f0ffcbf8f
commit
765f9648cd
@ -1,8 +1,9 @@
|
||||
from .Exporter import Exporter
|
||||
from ..parametertree import Parameter
|
||||
from ..Qt import QtGui, QtCore, QtSvg, QT_LIB
|
||||
from ..Qt import QtCore, QtGui, QtWidgets
|
||||
from .. import functions as fn
|
||||
import numpy as np
|
||||
import sys
|
||||
|
||||
translate = QtCore.QCoreApplication.translate
|
||||
__all__ = ['ImageExporter']
|
||||
@ -73,15 +74,8 @@ class ImageExporter(Exporter):
|
||||
targetRect = QtCore.QRect(0, 0, w, h)
|
||||
sourceRect = self.getSourceRect()
|
||||
|
||||
bg = np.empty((h, w, 4), dtype=np.ubyte)
|
||||
color = self.params['background']
|
||||
bg[:,:,0] = color.blue()
|
||||
bg[:,:,1] = color.green()
|
||||
bg[:,:,2] = color.red()
|
||||
bg[:,:,3] = color.alpha()
|
||||
|
||||
self.png = fn.makeQImage(bg, alpha=True, copy=False, transpose=False)
|
||||
self.bg = bg
|
||||
self.png = QtGui.QImage(w, h, QtGui.QImage.Format.Format_ARGB32)
|
||||
self.png.fill(self.params['background'])
|
||||
|
||||
## set resolution of image:
|
||||
origTargetRect = self.getTargetRect()
|
||||
@ -104,13 +98,18 @@ class ImageExporter(Exporter):
|
||||
painter.end()
|
||||
|
||||
if self.params['invertValue']:
|
||||
mn = bg[...,:3].min(axis=2)
|
||||
mx = bg[...,:3].max(axis=2)
|
||||
bg = fn.qimage_to_ndarray(self.png)
|
||||
if sys.byteorder == 'little':
|
||||
cv = slice(0, 3)
|
||||
else:
|
||||
cv = slice(1, 4)
|
||||
mn = bg[...,cv].min(axis=2)
|
||||
mx = bg[...,cv].max(axis=2)
|
||||
d = (255 - mx) - mn
|
||||
bg[...,:3] += d[...,np.newaxis]
|
||||
bg[...,cv] += d[...,np.newaxis]
|
||||
|
||||
if copy:
|
||||
QtGui.QApplication.clipboard().setImage(self.png)
|
||||
QtWidgets.QApplication.clipboard().setImage(self.png)
|
||||
elif toBytes:
|
||||
return self.png
|
||||
else:
|
||||
|
@ -557,15 +557,11 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
|
||||
pixels[...,3] = 255
|
||||
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels)
|
||||
|
||||
# swap B,R channels for Qt
|
||||
tmp = pixels[...,0].copy()
|
||||
pixels[...,0] = pixels[...,2]
|
||||
pixels[...,2] = tmp
|
||||
pixels = pixels[::-1] # flip vertical
|
||||
|
||||
img = fn.makeQImage(pixels, transpose=False)
|
||||
return img
|
||||
|
||||
pixels = pixels[::-1].copy() # flip vertical
|
||||
|
||||
qimg = fn.ndarray_to_qimage(pixels, QtGui.QImage.Format.Format_RGBA8888)
|
||||
return qimg
|
||||
|
||||
def renderToArray(self, size, format=GL_BGRA, type=GL_UNSIGNED_BYTE, textureSize=1024, padding=256):
|
||||
w,h = map(int, size)
|
||||
|
Loading…
Reference in New Issue
Block a user