add Grayscale16

This commit is contained in:
KIU Shueng Chuan 2021-04-08 16:13:20 +08:00
parent 59b835edf7
commit 38fbb3fa46

View File

@ -471,13 +471,14 @@ class ImageItem(GraphicsObject):
image = image.transpose((1, 0, 2)[:image.ndim]) image = image.transpose((1, 0, 2)[:image.ndim])
ubyte_nolvl = image.dtype == numpy.ubyte and levels is None ubyte_nolvl = image.dtype == numpy.ubyte and levels is None
is_passthru = ubyte_nolvl and lut is None is_passthru8 = ubyte_nolvl and lut is None
is_indexed8 = ubyte_nolvl and image.ndim == 2 and \ is_indexed8 = ubyte_nolvl and image.ndim == 2 and \
lut is not None and lut.shape[0] == 256 lut is not None and lut.shape[0] == 256
can_grayscale16 = image.dtype == numpy.uint16 and image.ndim == 2 and \
levels is None and lut is None and \
hasattr(QtGui.QImage.Format, 'Format_Grayscale16')
# Question: does the user supplied image buffer belong to us? if is_passthru8 or is_indexed8 or can_grayscale16:
if is_passthru or is_indexed8:
# bypass makeARGB for supported combinations # bypass makeARGB for supported combinations
self._processingBuffer = None self._processingBuffer = None
self._displayBuffer = None self._displayBuffer = None
@ -487,7 +488,7 @@ class ImageItem(GraphicsObject):
fmt = None fmt = None
ctbl = None ctbl = None
if is_passthru: if is_passthru8:
# both levels and lut are None # both levels and lut are None
# these images are suitable for display directly # these images are suitable for display directly
if image.ndim == 2: if image.ndim == 2:
@ -505,6 +506,10 @@ class ImageItem(GraphicsObject):
ctbl = [QtGui.qRgb(*rgb) for rgb in lut.tolist()] ctbl = [QtGui.qRgb(*rgb) for rgb in lut.tolist()]
elif lut.shape[1] == 4: elif lut.shape[1] == 4:
ctbl = [QtGui.qRgba(*rgba) for rgba in lut.tolist()] ctbl = [QtGui.qRgba(*rgba) for rgba in lut.tolist()]
elif can_grayscale16:
# single channel uint16
# both levels and lut are None
fmt = QtGui.QImage.Format.Format_Grayscale16
if fmt is None: if fmt is None:
raise ValueError("unsupported image type") raise ValueError("unsupported image type")
self.qimage = fn._ndarray_to_qimage(image, fmt) self.qimage = fn._ndarray_to_qimage(image, fmt)