Merge branch 'faster-make-argb' into develop
- Speed improvements in functions.makeARGB - ImageItem is faster by avoiding makeQImage(transpose=True)
This commit is contained in:
commit
c1f72b29c6
@ -782,25 +782,6 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||
if levels is not None and not isinstance(levels, np.ndarray):
|
||||
levels = np.array(levels)
|
||||
|
||||
## sanity checks
|
||||
#if data.ndim == 3:
|
||||
#if data.shape[2] not in (3,4):
|
||||
#raise Exception("data.shape[2] must be 3 or 4")
|
||||
##if lut is not None:
|
||||
##raise Exception("can not use lookup table with 3D data")
|
||||
#elif data.ndim != 2:
|
||||
#raise Exception("data must be 2D or 3D")
|
||||
|
||||
#if lut is not None:
|
||||
##if lut.ndim == 2:
|
||||
##if lut.shape[1] :
|
||||
##raise Exception("lut.shape[1] must be 3 or 4")
|
||||
##elif lut.ndim != 1:
|
||||
##raise Exception("lut must be 1D or 2D")
|
||||
#if lut.dtype != np.ubyte:
|
||||
#raise Exception('lookup table must have dtype=ubyte (got %s instead)' % str(lut.dtype))
|
||||
|
||||
|
||||
if levels is not None:
|
||||
if levels.ndim == 1:
|
||||
if len(levels) != 2:
|
||||
@ -813,16 +794,6 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||
else:
|
||||
print(levels)
|
||||
raise Exception("levels argument must be 1D or 2D.")
|
||||
#levels = np.array(levels)
|
||||
#if levels.shape == (2,):
|
||||
#pass
|
||||
#elif levels.shape in [(3,2), (4,2)]:
|
||||
#if data.ndim == 3:
|
||||
#raise Exception("Can not use 2D levels with 3D data.")
|
||||
#if lut is not None:
|
||||
#raise Exception('Can not use 2D levels and lookup table together.')
|
||||
#else:
|
||||
#raise Exception("Levels must have shape (2,) or (3,2) or (4,2)")
|
||||
|
||||
prof.mark('1')
|
||||
|
||||
@ -865,8 +836,6 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||
|
||||
## copy data into ARGB ordered array
|
||||
imgData = np.empty(data.shape[:2]+(4,), dtype=np.ubyte)
|
||||
if data.ndim == 2:
|
||||
data = data[..., np.newaxis]
|
||||
|
||||
prof.mark('4')
|
||||
|
||||
@ -875,20 +844,26 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||
else:
|
||||
order = [2,1,0,3] ## for some reason, the colors line up as BGR in the final image.
|
||||
|
||||
if data.shape[2] == 1:
|
||||
if data.ndim == 2:
|
||||
# This is tempting:
|
||||
# imgData[..., :3] = data[..., np.newaxis]
|
||||
# ..but it turns out this is faster:
|
||||
for i in range(3):
|
||||
imgData[..., order[i]] = data[..., 0]
|
||||
imgData[..., i] = data
|
||||
elif data.shape[2] == 1:
|
||||
for i in range(3):
|
||||
imgData[..., i] = data[..., 0]
|
||||
else:
|
||||
for i in range(0, data.shape[2]):
|
||||
imgData[..., order[i]] = data[..., i]
|
||||
imgData[..., i] = data[..., order[i]]
|
||||
|
||||
prof.mark('5')
|
||||
|
||||
if data.shape[2] == 4:
|
||||
alpha = True
|
||||
else:
|
||||
if data.ndim == 2 or data.shape[2] == 3:
|
||||
alpha = False
|
||||
imgData[..., 3] = 255
|
||||
else:
|
||||
alpha = True
|
||||
|
||||
prof.mark('6')
|
||||
|
||||
|
@ -260,8 +260,8 @@ class ImageItem(GraphicsObject):
|
||||
#print lut.shape
|
||||
#print self.lut
|
||||
|
||||
argb, alpha = fn.makeARGB(self.image, lut=lut, levels=self.levels)
|
||||
self.qimage = fn.makeQImage(argb, alpha)
|
||||
argb, alpha = fn.makeARGB(self.image.transpose((1, 0, 2)[:self.image.ndim]), lut=lut, levels=self.levels)
|
||||
self.qimage = fn.makeQImage(argb, alpha, transpose=False)
|
||||
prof.finish()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user