Merge pull request #1985 from pijyoi/workaround_float_lut

delegate float luts to makeARGB()
This commit is contained in:
Ogi Moore 2021-09-07 21:48:15 -07:00 committed by GitHub
commit 126b7e0925
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division
import numpy
from .GraphicsObject import GraphicsObject
@ -11,11 +9,8 @@ from ..Point import Point
from ..Qt import QtGui, QtCore
from ..util.cupy_helper import getCupy
try:
from collections.abc import Callable
except ImportError:
# fallback for python < 3.3
from collections import Callable
import warnings
from collections.abc import Callable
translate = QtCore.QCoreApplication.translate
@ -535,7 +530,19 @@ class ImageItem(GraphicsObject):
levels = self.levels
augmented_alpha = False
if image.dtype.kind == 'f':
if lut is not None and lut.dtype != self._xp.uint8:
# Both _try_rescale_float() and _try_combine_lut() assume that
# lut is of type uint8. It is considered a usage error if that
# is not the case.
# However, the makeARGB() codepath has previously allowed such
# a usage to work. Rather than fail outright, we delegate this
# case to makeARGB().
warnings.warn(
"Using non-uint8 LUTs is an undocumented accidental feature and may "
"be removed at some point in the future. Please open an issue if you "
"instead believe this to be worthy of protected inclusion in pyqtgraph.",
DeprecationWarning, stacklevel=2)
elif image.dtype.kind == 'f':
image, levels, lut, augmented_alpha = self._try_rescale_float(image, levels, lut)
# if we succeeded, we will have an uint8 image with levels None.
# lut if not None will have <= 256 entries