class_docstr: **Bases:** :class:`GraphicsObject <pyqtgraph.GraphicsObject>`
class_docstr_tok: ["*","*","Bases",":","*","*",":","class",":","`","GraphicsObject","<","pyqtgraph.GraphicsObject",">","`"]
code: def _try_combine_lut(self, image, levels, lut):
      augmented_alpha = False
      xp = self._xp
  
      can_handle = False
      while True:
          if levels is not None and levels.ndim != 1:
              # can't handle multi-channel levels
              break
          if (
              image.dtype == xp.uint16
              and levels is None
              and image.ndim == 3
              and image.shape[2] == 3
          ):
              # uint16 rgb can't be directly displayed, so make it
              # pass through effective lut processing
              levels = [0, 65535]
          if levels is None and lut is None:
              # nothing to combine
              break
  
          can_handle = True
          break
  
      if not can_handle:
          return image, levels, lut, augmented_alpha
  
      # distinguish between lut for levels and colors
      levels_lut = None
      colors_lut = lut
  
      eflsize = 2 ** (image.itemsize * 8)
      if levels is None:
          info = xp.iinfo(image.dtype)
          minlev, maxlev = info.min, info.max
      else:
          minlev, maxlev = levels
      levdiff = maxlev - minlev
      levdiff = (
          1 if levdiff == 0 else levdiff
      )  # don't allow division by 0
  
      if colors_lut is None:
          if image.dtype == xp.ubyte and image.ndim == 2:
              # uint8 mono image
              ind = xp.arange(eflsize)
              levels_lut = fn.rescaleData(
                  ind,
                  scale=255.0 / levdiff,
                  offset=minlev,
                  dtype=xp.ubyte,
              )
              # image data is not scaled. instead, levels_lut is used
              # as (grayscale) Indexed8 ColorTable to get the same effect.
              # due to the small size of the input to rescaleData(), we
              # do not bother caching the result
              return image, None, levels_lut, augmented_alpha
          else:
              # uint16 mono, uint8 rgb, uint16 rgb
              # rescale image data by computation instead of by memory lookup
              image = fn.rescaleData(
                  image,
                  scale=255.0 / levdiff,
                  offset=minlev,
                  dtype=xp.ubyte,
              )
              return image, None, colors_lut, augmented_alpha
      else:
          num_colors = colors_lut.shape[0]
          effscale = num_colors / levdiff
          lutdtype = xp.min_scalar_type(num_colors - 1)
  
          if image.dtype == xp.ubyte or lutdtype != xp.ubyte:
              # combine if either:
              #   1) uint8 mono image
              #   2) colors_lut has more entries than will fit within 8-bits
              if self._effectiveLut is None:
                  ind = xp.arange(eflsize)
                  levels_lut = fn.rescaleData(
                      ind,
                      scale=effscale,
                      offset=minlev,
                      dtype=lutdtype,
                      clip=(0, num_colors - 1),
                  )
                  efflut = colors_lut[levels_lut]
                  self._effectiveLut = efflut
              efflut = self._effectiveLut
  
              # apply the effective lut early for the following types:
              if image.dtype == xp.uint16 and image.ndim == 2:
                  (
                      image,
                      augmented_alpha,
                  ) = self._apply_lut_for_uint16_mono(image, efflut)
                  efflut = None
              return image, None, efflut, augmented_alpha
          else:
              # uint16 image with colors_lut <= 256 entries
              # don't combine, we will use QImage ColorTable
              image = fn.rescaleData(
                  image,
                  scale=effscale,
                  offset=minlev,
                  dtype=lutdtype,
                  clip=(0, num_colors - 1),
              )
              return image, None, colors_lut, augmented_alpha
  
imports: import warnings
  from collections.abc import Callable
  import numpy
  from ..None import colormap
  from ..None import debug
  from ..None import functions
  from ..None import getConfigOption
  from ..Point import Point
  from ..Qt import QtCore, QtGui, QtWidgets
  from ..util.cupy_helper import getCupy
  from .GraphicsObject import GraphicsObject
label_desc: Use image node_id 29 for calling the ImageItem obj's underlying member method code with example usage: obj._try_combine_lut(image, levels, lut) and returns: image,  levels,  lut,  augmented_alpha, image,  None,  levels_lut,  augmented_alpha, image,  None,  colors_lut,  augmented_alpha, image,  None,  efflut,  augmented_alpha, image,  None,  colors_lut,  augmented_alpha