Speedups for making ARGB arrays
This commit is contained in:
parent
f6ed67fc33
commit
85d7116482
|
@ -733,7 +733,7 @@ def makeRGBA(*args, **kwds):
|
||||||
kwds['useRGBA'] = True
|
kwds['useRGBA'] = True
|
||||||
return makeARGB(*args, **kwds)
|
return makeARGB(*args, **kwds)
|
||||||
|
|
||||||
def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False, transpose=False):
|
||||||
"""
|
"""
|
||||||
Convert an array of values into an ARGB array suitable for building QImages, OpenGL textures, etc.
|
Convert an array of values into an ARGB array suitable for building QImages, OpenGL textures, etc.
|
||||||
|
|
||||||
|
@ -774,6 +774,7 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||||
The default is False, which returns in ARGB order for use with QImage
|
The default is False, which returns in ARGB order for use with QImage
|
||||||
(Note that 'ARGB' is a term used by the Qt documentation; the _actual_ order
|
(Note that 'ARGB' is a term used by the Qt documentation; the _actual_ order
|
||||||
is BGRA).
|
is BGRA).
|
||||||
|
transpose Whether to pre-transpose the data in preparation for use in Qt
|
||||||
============ ==================================================================================
|
============ ==================================================================================
|
||||||
"""
|
"""
|
||||||
prof = debug.Profiler('functions.makeARGB', disabled=True)
|
prof = debug.Profiler('functions.makeARGB', disabled=True)
|
||||||
|
@ -865,9 +866,10 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||||
|
|
||||||
|
|
||||||
## copy data into ARGB ordered array
|
## copy data into ARGB ordered array
|
||||||
|
if transpose:
|
||||||
|
imgData = np.empty((data.shape[1], data.shape[0], 4), dtype=np.ubyte)
|
||||||
|
else:
|
||||||
imgData = np.empty(data.shape[:2]+(4,), dtype=np.ubyte)
|
imgData = np.empty(data.shape[:2]+(4,), dtype=np.ubyte)
|
||||||
if data.ndim == 2:
|
|
||||||
data = data[..., np.newaxis]
|
|
||||||
|
|
||||||
prof.mark('4')
|
prof.mark('4')
|
||||||
|
|
||||||
|
@ -876,20 +878,32 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||||
else:
|
else:
|
||||||
order = [2,1,0,3] ## for some reason, the colors line up as BGR in the final image.
|
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:
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
imgData[..., order[i]] = data[..., 0]
|
if transpose:
|
||||||
|
imgData[..., i] = data.T
|
||||||
|
else:
|
||||||
|
imgData[..., i] = data
|
||||||
|
elif data.shape[2] == 1:
|
||||||
|
for i in range(3):
|
||||||
|
if transpose:
|
||||||
|
imgData[..., i] = data[..., 0].T
|
||||||
|
else:
|
||||||
|
imgData[..., i] = data[..., 0]
|
||||||
else:
|
else:
|
||||||
for i in range(0, data.shape[2]):
|
for i in range(0, data.shape[2]):
|
||||||
imgData[..., order[i]] = data[..., i]
|
if transpose:
|
||||||
|
imgData[..., order[i]] = data[..., order[i]].T
|
||||||
|
else:
|
||||||
|
imgData[..., order[i]] = data[..., order[i]]
|
||||||
|
|
||||||
prof.mark('5')
|
prof.mark('5')
|
||||||
|
|
||||||
if data.shape[2] == 4:
|
if data.ndim == 2 or data.shape[2] == 3:
|
||||||
alpha = True
|
|
||||||
else:
|
|
||||||
alpha = False
|
alpha = False
|
||||||
imgData[..., 3] = 255
|
imgData[..., 3] = 255
|
||||||
|
else:
|
||||||
|
alpha = True
|
||||||
|
|
||||||
prof.mark('6')
|
prof.mark('6')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user