
    e                         d dl Z d dlmZ d dlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZmZmZ ddlmZ ddlmZ ej&                  j(                  ZdgZ G d de      Zy)    N)Callable   )colormap)debug)	functions)functions_qimage)getConfigOption)Point)QtCoreQtGui	QtWidgets)getCupy   )GraphicsObject	ImageItemc                      e Zd ZdZ ej
                         Z ej
                  e      Zd1dZ	d Z
d Zd Zd Zd Zd	 Zd2d
Zd Zd Zd Zd2dZed        Zd2dZd2dZd Zd Zd Zd3dZd4dZd Zd Zd Z d Z!d5dZ"d Z#d Z$d Z%d Z&	 	 d6d Z'd! Z(d" Z)d# Z*d$ Z+d% Z,d& Z-d' Z.d( Z/d) Z0d* Z1d+ Z2d, Z3d1d-Z4d7d.Z5d/ Z6d0 Z7y)8r   zG
    **Bases:** :class:`GraphicsObject <pyqtgraph.GraphicsObject>`
    Nc                    t        j                  |        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _	        d| _
        d| _        d| _        d| _        d| _        d| _        d| _        d| _        t%        d      | _        dx| _        | _        | j-                  | j&                         d| _        d| _        d| _        | | j4                  |fi | y | j6                  di | y)a  
        See :func:`~pyqtgraph.ImageItem.setOpts` for further keyword arguments and 
        and :func:`~pyqtgraph.ImageItem.setImage` for information on supported formats.

        Parameters
        ----------
            image: np.ndarray, optional
                Image data
        NFr   r   TimageAxisOrder )r   __init__menuimageqimage	paintModelevelslutautoDownsample	_colorMap_lastDownsample_processingBuffer_displayBuffer_renderRequired_unrenderable_xp_defferedLevels_imageHasNansr	   	axisOrder_dataTransform_inverseDataTransform_update_data_transforms
drawKernelborder	removablesetImagesetOpts)selfr   kargss      C/usr/lib/python3/dist-packages/pyqtgraph/graphicsItems/ImageItem.pyr   zImageItem.__init__   s     	%	
#%!%"#"#!()9:;??d8$$dnn6DMM%)5)DLL!5!    c                 2    || _         | j                          y)as  
        Change the composition mode of the item. This is useful when overlaying
        multiple items.
        
        Parameters
        ----------
        mode : ``QtGui.QPainter.CompositionMode``
            Composition of the item, often used when overlaying items.  Common
            options include:

            ``QPainter.CompositionMode.CompositionMode_SourceOver`` (Default)
            Image replaces the background if it is opaque. Otherwise, it uses
            the alpha channel to blend the image with the background.

            ``QPainter.CompositionMode.CompositionMode_Overlay`` Image color is
            mixed with the background color to reflect the lightness or
            darkness of the background

            ``QPainter.CompositionMode.CompositionMode_Plus`` Both the alpha
            and color of the image and background pixels are added together.

            ``QPainter.CompositionMode.CompositionMode_Plus`` The output is the
            image color multiplied by the background.

            See ``QPainter::CompositionMode`` in the Qt Documentation for more
            options and details
        N)r   update)r1   modes     r3   setCompositionModezImageItem.setCompositionModeG   s    8 r4   c                 X    t        j                  |      | _        | j                          y)z
        Defines the border drawn around the image. Accepts all arguments supported by 
        :func:`~pyqtgraph.mkPen`.
        N)fnmkPenr-   r6   r1   bs     r3   	setBorderzImageItem.setBorderf   s    
 hhqkr4   c                 t    | j                   y | j                  dk(  rdnd}| j                   j                  |   S )N	col-majorr   r   r   r(   shaper1   axiss     r3   widthzImageItem.widthn   6    ::NNk1qqzz%%r4   c                 t    | j                   y | j                  dk(  rdnd}| j                   j                  |   S )Nr@   r   r   rA   rC   s     r3   heightzImageItem.heightt   rF   r4   c                     | j                   y | j                   j                  dk(  r| j                   j                  d   S dS )N   r   r   )r   ndimrB   r1   s    r3   channelszImageItem.channelsz   s8    ::&*jjoo&:tzz"AAr4   c           	          | j                   t        j                  dddd      S t        j                  ddt        | j	                               t        | j                                     S )N        )r   r   QRectFfloatrE   rH   rL   s    r3   boundingRectzImageItem.boundingRect   sL    ::==RR00}}RU4::<%8%:NOOr4   c                     | j                   || _        || _        y|| j                   j                  |      }|| _        |r| j	                          yy)a  
        Sets image scaling levels. 
        See :func:`makeARGB <pyqtgraph.makeARGB>` for more details on how levels are applied.
        
        Parameters
        ----------
            levels: array_like
                - ``[blackLevel, whiteLevel]`` 
                  sets black and white levels for monochrome data and can be used with a lookup table.
                - ``[[minR, maxR], [minG, maxG], [minB, maxB]]``
                  sets individual scaling for RGB values. Not compatible with lookup tables.
            update: bool, optional
                Controls if image immediately updates to reflect the new levels.
        N)r%   r   r&   asarrayupdateImage)r1   r   r6   s      r3   	setLevelszImageItem.setLevels   sU     88 DK#)D XX%%f-F r4   c                     | j                   S )z
        Returns the list representing the current level settings. See :func:`~setLevels`.
        When ``autoLevels`` is active, the format is ``[blackLevel, whiteLevel]``.
        )r   rL   s    r3   	getLevelszImageItem.getLevels   s    
 {{r4   c                 
   t        |t        j                        r|| _        n6t        |t              rt        j
                  |      | _        nt        d      | j                  | j                  j                  d             y)a  
        Sets a color map for false color display of a monochrome image.

        Parameters
        ----------
        colorMap : :class:`~pyqtgraph.ColorMap` or `str`
            A string argument will be passed to :func:`colormap.get() <pyqtgraph.colormap.get>`
        z.'colorMap' argument must be ColorMap or string   )nPtsN)	
isinstancer   ColorMapr   strget	TypeErrorsetLookupTablegetLookupTable)r1   colorMaps     r3   setColorMapzImageItem.setColorMap   sa     h 1 12%DN#&%\\(3DNLMMT^^:::DFr4   c                     | j                   S )z^
        Returns the assigned :class:`pyqtgraph.ColorMap`, or `None` if not available
        )r   rL   s    r3   getColorMapzImageItem.getColorMap   s     ~~r4   c                     || j                   urC| j                  | j                  || j                        }|| _         |r| j                          yyy)a6  
        Sets lookup table ``lut`` to use for false color display of a monochrome image. See :func:`makeARGB <pyqtgraph.makeARGB>` for more 
        information on how this is used. Optionally, `lut` can be a callable that accepts the current image as an
        argument and returns the lookup table to use.

        Ordinarily, this table is supplied by a :class:`~pyqtgraph.HistogramLUTItem`,
        :class:`~pyqtgraph.GradientEditorItem` or :class:`~pyqtgraph.ColorBarItem`.
        
        Setting ``update = False`` avoids an immediate image update.
        N)r   r%   _ensure_proper_substraterU   )r1   r   r6   s      r3   ra   zImageItem.setLookupTable   sP     dhhxx#33CBDH  " 	 r4   c                 Z   | &t        | t              st        | |j                        r| S t               }||k(  r)t        | |j                        s|j	                  |       } | S |t
        k(  r?|(t        | |j                        r| j                         } | S t        j                  |       } | S N)r\   r   ndarrayr   rT   numpyr_   )data	substratecupys      r3   rh   z"ImageItem._ensure_proper_substrate   s    <:dH5D)J[J[9\KyZdll%C<<%D  %JtT\\$Bxxz  }}T*r4   c                 @    || _         d| _        | j                          y)a  
        Controls automatic downsampling for this ImageItem.

        If `active` is `True`, the image is automatically downsampled to match the
        screen resolution. This improves performance for large images and
        reduces aliasing. If `autoDownsample` is not specified, then ImageItem will
        choose whether to downsample the image based on its size.
        
        `False` disables automatic downsampling.
        TN)r   r#   r6   )r1   actives     r3   setAutoDownsamplezImageItem.setAutoDownsample   s     %#r4   c                 P   d|v r6|d   }|dvrt        d      || _        | j                  | j                         d|v r| j                  |d          d|v r| j	                  |d   |       d|v r| j                  |d   |       d|v r| j                  |d          d	|v r| j                  |d	          d
|v r| j                  |d
          d|v r|d   | _	        d| _
        d|v r| j                  |d          d|v r| j                  |d          |r| j                          yy)a  
        Sets display and processing options for this ImageItem. :func:`~pyqtgraph.ImageItem.__init__` and 
        :func:`~pyqtgraph.ImageItem.setImage` support all keyword arguments listed here.

        Parameters
        ----------
            autoDownsample: bool
                See :func:`~pyqtgraph.ImageItem.setAutoDownsample`.
            axisOrder: str
                | `'col-major'`: The shape of the array represents (width, height) of the image. This is the default.
                | `'row-major'`: The shape of the array represents (height, width).
            border: bool
                Sets a pen to draw to draw an image border. See :func:`~pyqtgraph.ImageItem.setBorder`.
            compositionMode:
                See :func:`~pyqtgraph.ImageItem.setCompositionMode`
            colorMap: :class:`~pyqtgraph.ColorMap` or `str`
                Sets a color map. A string will be passed to :func:`colormap.get() <pyqtgraph.colormap.get()>`
            lut: array_like
                Sets a color lookup table to use when displaying the image.
                See :func:`~pyqtgraph.ImageItem.setLookupTable`.
            levels: array_like
                Shape of (min, max). Sets minimum and maximum values to use when
                rescaling the image data. By default, these will be set to the
                estimated minimum and maximum values in the image. If the image array
                has dtype uint8, no rescaling is necessary. See
                :func:`~pyqtgraph.ImageItem.setLevels`.
            opacity: float
                Overall opacity for an RGB image. Between 0.0-1.0.
            rect: :class:`QRectF`, :class:`QRect` or array_like
                Displays the current image within the specified rectangle in plot
                coordinates. If ``array_like``, should be of the of ``floats 
                (`x`,`y`,`w`,`h`)`` . See :func:`~pyqtgraph.ImageItem.setRect`.
            update : bool, optional
                Controls if image immediately updates to reflect the new options.
        r(   )	row-majorr@   z3axisOrder must be either 'row-major' or 'col-major'rc   r   )r6   r   opacitycompositionModer-   r.   Nr   rect)
ValueErrorr(   r+   rd   ra   rV   
setOpacityr8   r>   r.   r   rr   setRectr6   )r1   r6   r2   vals       r3   r0   zImageItem.setOpts   sH   H %$C44 !VWW DN((8U:./E>eV<uNN5?6N: OOE),-%##E*;$<=uNN5?+%";/DNDIu$""5)9#:;U?LLv'KKM r4   c                 :   t        |      dk(  r| j                          yt        |d   t        j                  t        j
                  f      r|d   }n&t        |d   d      r|d   }t        j                  | }t        j                         }|j                  |j                         |j                                |j                  |j                         | j                         z  |j                         | j                         z         | j                  |       y)a  
        setRect(rect) or setRect(x,y,w,h)
        
        Sets translation and scaling of this ImageItem to display the current image within the rectangle given
        as ``rect`` (:class:`QtCore.QRect` or :class:`QtCore.QRectF`), or described by parameters `x, y, w, h`, 
        defining starting position, width and height.

        This method cannot be used before an image is assigned.
        See the :ref:`examples <ImageItem_examples>` for how to manually set transformations.
        r   N__len__)lenresetTransformr\   r   rP   QRecthasattrr   
QTransform	translatelefttopscalerE   rH   setTransform)r1   argsrw   trs       r3   rz   zImageItem.setRect,  s     t9>!d1gv||<=7DtAwy)Aw==4)D
TYY[$((*-


,dkkmdkkm.KL"r4   c                 r    d| _         | j                          | j                          | j                          y)z,
        Clears the assigned image.
        N)r   prepareGeometryChangeinformViewBoundsChangedr6   rL   s    r3   clearzImageItem.clearE  s,     
""$$$&r4   c                 J   t        j                  |d d dz   t         j                        | _        | j                  t               k(  rD| j                  j                  |d d dz   | j                  j                        | _        d | _        y | j                  | _        d | _        y )Nr   )   dtype)rl   emptyubyter"   r%   r   r!   r   )r1   rB   s     r3   _buildQImageBufferzImageItem._buildQImageBufferN  s~    #kk%)d*:%++N88wy %)XX^^E"1I4DDHHNN^%[D"  &*%8%8D"r4   c                 x   t        j                         }d}|| j                  y| j                  }t	               }|r|j                  |      nt        | _        d}|| j                  k7  }|rd| _        |xs3 | j                  du xs# |j                  | j                  j                  k7  }	|j                         }|| _        d| _
        | j                  j                  d   dkD  s| j                  j                  d   dkD  r	d|vrd|d<   |	r | j                          | j                           |        |	d|v rd}nd}|rm|j                  d	d
      }
| j                  |
      \  }}||k(  s6| j                  j                  |      s| j                  j                  |      rd}d}||g|d<    |         | j                   dddi|  |        d| _        | j%                           |        |r| j&                  j)                          | j*                  %| j*                  }d| _        | j-                  |       yy)a  
        Updates the image displayed by this ImageItem. For more information on how the image
        is processed before displaying, see :func:`~pyqtgraph.makeARGB`.
        
        For backward compatibility, image data is assumed to be in column-major order (column, row) by default.
        However, most data is stored in row-major order (row, column). It can either be transposed before assignment::

            imageitem.setImage(imagedata.T)
        
        or the interpretation of the data can be changed locally through the ``axisOrder`` keyword or by changing the 
        `imageAxisOrder` :ref:`global configuration option <apiref_config>`
        
        All keywords supported by :func:`~pyqtgraph.ImageItem.setOpts` are also allowed here.

        Parameters
        ----------
        image: np.ndarray, optional
            Image data given as NumPy array with an integer or floating
            point dtype of any bit depth. A 2-dimensional array describes single-valued (monochromatic) data.
            A 3-dimensional array is used to give individual color components. The third dimension must
            be of length 3 (RGB) or 4 (RGBA).
        rect: QRectF or QRect or array_like, optional
            If given, sets translation and scaling to display the image within the
            specified rectangle. If ``array_like`` should be the form of floats
            ``[x, y, w, h]`` See :func:`~pyqtgraph.ImageItem.setRect`
        autoLevels: bool, optional
            If `True`, ImageItem will automatically select levels based on the maximum and minimum values encountered 
            in the data. For performance reasons, this search subsamples the images and may miss individual bright or
            or dark points in the data set.
            
            If `False`, the search will be omitted.

            The default is `False` if a ``levels`` keyword argument is given, and `True` otherwise.
        levelSamples: int, default 65536
            When determining minimum and maximum values, ImageItem
            only inspects a subset of pixels no larger than this number.
            Setting this larger than the total number of pixels considers all values.
        FNTr   i  r   r   r   levelSamplesi   )
targetSize   r6   r   )r   Profilerr   r%   r   get_array_modulerl   r!   rB   viewr'   r   r   popquickMinMaxisnanr0   r#   r6   sigImageChangedemitr&   rV   )r1   r   
autoLevelsr2   profile
gotNewDataold_xpcpprocessingSubstrateChangedshapeChangedlevel_samplesmnmxr   s                 r3   r/   zImageItem.setImageV  s   N .."
=zz!XXFB57r**51UDHJ)/488);&))-&6o$**:LoPUP[P[_c_i_i_o_oPoLJJLEDJ!%Dzz"W,

0@0@0Cg0M#50.2E*+**,,,.	5 "
!
!IIne<M%%-%AFBRx488>>"-1C!"gE(O	+E+U+	#	  %%'+))F#'D NNF$ ,r4   c                 d   t        j                         | _        t        j                         | _        | j                  dk(  ro| j                  j                  dd       | j                  j                  d       | j                  j                  dd       | j                  j                  d       yy)zF Sets up the transforms needed to map between input array and display rt   r   iN)r   r   r)   r*   r(   r   rotate)r1   r(   s     r3   r+   z!ImageItem._update_data_transforms  s    #..0%*%5%5%7">>[(%%a,&&s+&&,,Q3&&--c2	 )r4   c                     | j                   S )a  
        Returns the transform that maps from this image's input array to its
        local coordinate system.

        This transform corrects for the transposition that occurs when image data
        is interpreted in row-major order.
        
        :meta private:
        )r)   rL   s    r3   dataTransformzImageItem.dataTransform  s     """r4   c                     | j                   S )zReturn the transform that maps from this image's local coordinate
        system to its input array.

        See dataTransform() for more information.

        :meta private:
        )r*   rL   s    r3   inverseDataTransformzImageItem.inverseDataTransform  s     )))r4   c                 8    | j                   j                  |      S rj   )r*   mapr1   objs     r3   	mapToDatazImageItem.mapToData  s    ))--c22r4   c                 8    | j                   j                  |      S rj   )r)   r   r   s     r3   mapFromDatazImageItem.mapFromData  s    ""&&s++r4   c                 
   | j                   }|dk  rd}	 |j                  dd \  }}||z  |k  rn||kD  r|dddddf   }n|dddddf   }:| j                  j                  |      | j                  j	                  |      fS )a   
        Estimates the min/max values of the image data by subsampling.
        Subsampling is performed at regular strides chosen to evaluate a number of samples
        equal to or less than `targetSize`.
        
        Returns (`min`, `max`).
        r   N)r   rB   r%   nanminnanmax)r1   r   rm   hws        r3   r   zImageItem.quickMinMax  s     zz>J::bq>DAq1u
"E1uCaCG}B!G}  xxt$dhhood&;;;r4   c                 P    ddi}|j                  |        | j                  |i |S )Nr   F)r6   r/   )r1   r   r2   defaultss       r3   rU   zImageItem.updateImage  s4     %
 	t}}d/h//r4   c                    d| _         | j                  | j                  j                  dk(  ry | j                  j                  dk(  s| j                  j                  d   dk(  r| j                  | j                  | j                        | _        t        | j                  t              r7| j                  | j                  | j                  d      | j                        }n| j                  }nd }| j                  r| j                         \  }}|y | j                  dk(  rddgnddg}t        j                  | j                  ||d         }t        j                  |||d         }||f| _        |j                  dk(  ry | j                  }|j                  dk(  r|j                  d	   dk(  r|d
   }| j                  dk(  r|j!                  dd      }| j"                  }| j$                  I|j&                  j(                  dk(  xr) | j                  j+                  |j-                               | _        d }|@|j&                  | j                  j.                  k7  rt1        j2                  dt4        d       n$| j$                  st7        j8                  |||      }|$d | _        d | _        || _        d| _         d| _         y | j:                  )| j:                  j                  d d |j                  d d k7  r| jC                  |j                         t        jD                  |||| j:                         | j                  tG               k(  r&| j:                  jI                  | j<                         t        jJ                  | j<                  tL        jN                  jP                  jR                        | _        d| _         d| _         y )NTr   r   r   rZ   rt   )rD   rJ   r   ).r   r@   fzUsing 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.)
stacklevel)r   r   F)r   r   output)out)*r$   r   sizerK   rB   rh   r   r%   r\   r   r   _computeDownsampleFactorsr(   r:   
downsampler    swapaxesr   r'   r   kindr   minuint8warningswarnDeprecationWarningr   try_make_qimager!   r"   r   r#   r   makeARGBr   r_   ndarray_to_qimager   QImageFormatFormat_ARGB32)r1   r   xdsydsaxesr   r   r   s           r3   renderzImageItem.render   s   !::A!5 ::??a4::#3#3A#6!#;44TXXtxxHDH$((H-33DHHTZZ4MtxxXhhC557HC{!^^{:Aq6ADMM$**cQ@EMM%47;E$':D  zzQJJE ::?u{{2!3&ME >>[(NN1a(E%   C' ,uyy{+ 
 ?syyDHHNN: MMY #q	2 ##%55eFPSTF%)D""&D DK#(D !&D!!)T-C-C-I-I"1-MQVQ\Q\]_^_Q`-`##EKK0
Es6$:P:PQ88wy ""&&4+>+>&?**4+>+>@S@S@a@ab$"r4   c                    t        j                         }| j                  y | j                  r%| j	                          | j
                  ry  |d       | j                  #|j                  | j                          |d       | j                  dk(  r| j                  j                  d d n| j                  j                  d d d d d   }|j                  t        j                  ddg| | j                          |d       | j                  ;|j                  | j                         |j!                  | j#                                y y )Nzrender QImagezset comp moder@   r   r   r   zp.drawImage)r   r   r   r#   r   r$   r   r8   r(   rB   	drawImager   rP   r   r-   setPendrawRectrR   )r1   pr   r   rB   s        r3   paintzImageItem.paintW  s   .."::KKM!!O$>>%  0O$(,+(E

  !$4::K[K[\^]^K_`dbd`dKe	FMM!A-u-t{{;;;"HHT[[!JJt((*+ #r4   c                 v    | j                   r| j                           | j                  j                  |g|  y)z
        Saves this image to file. Note that this saves the visible image (after scale/color changes), not the 
        original data.
        N)r#   r   r   save)r1   fileNamer   s      r3   r   zImageItem.savek  s/    
 KKM)D)r4   c           
      >   | j                   | j                   j                  dk(  ry|dk(  rt        dt        | j                  j                  | j                   j                  d   |z                    t        dt        | j                  j                  | j                   j                  d   |z                    f}| j                  j                  |      r||f}| j                   dd|d   dd|d   f   }t        |t              rT|dk(  rN| j                  j                  |      j                         }| j                  j                  |      j                         }	|	|k(  r|	dz  }	| j                  j                  |      s| j                  j                  |	      ry|j                  j                  dv r[t        | j                  j                  |	|z
  dz              }g }|dkD  rG| j                  j!                  ||	d	|z  z   |t        
      }n| j                  j#                  ||	d      }t%        |      dk(  r| j                  j'                  ||	f      }||d<   t)               }
|rg }t+        |j                  d         D ]  }|d|f   }|| j                  j-                  |         } | j                  j.                  |fi |}|
r;|j1                  |
j3                  |d   dd       |
j3                  |d         f       |j1                  |d   dd |d   f        |S || j                  j-                  |         } | j                  j.                  |fi |}|
r+|
j3                  |d   dd       |
j3                  |d         fS |d   dd |d   fS )a  
        Returns `x` and `y` arrays containing the histogram values for the current image.
        For an explanation of the return format, see :func:`numpy.histogram()`.

        The `step` argument causes pixels to be skipped when computing the histogram to save time.
        If `step` is 'auto', then a step is chosen such that the analyzed data has
        dimensions approximating `targetImageSize` for each axis.

        The `bins` argument and any extra keyword arguments are passed to
        :func:`numpy.histogram()`. If `bins` is `auto`, a bin number is automatically
        chosen based on the image characteristics:

          * Integer images will have approximately `targetHistogramSize` bins,
            with each bin having an integer width.
          * All other types will have `targetHistogramSize` bins.

        If `perChannel` is `True`, then a histogram is computed for each channel, 
        and the output is a list of the results.
        Nr   NNautor   uig     @@rO   g)\(?r     binsr   .)r   r   maxintr%   ceilrB   isscalarr\   r^   r   itemr   r   r   r   arangelinspacer~   rT   r   rangeisfinite	histogramappendasnumpy)r1   r   step
perChanneltargetImageSizetargetHistogramSizekwdsstepDatar   r   r   hististepChanr   s                  r3   getHistogramzImageItem.getHistogramt  s/   , ::A!56>3txx}}TZZ-=-=a-@?-RSTU3txx}}TZZ-=-=a-@?-RSTUWD88T"$<D::iQi4723dC TV^*//1B*//1BRxaxx~~b!TXX^^B%7!~~""d*488=="r'T)9:;#:88??2rD4K/?S?QD xx((R54yA~xx''R1VYD8>>"-. 3#CF+#DHH$5$5h$?@&DHH&&x848KKAaD"I!6

1Q48H IJKK1crAaD 123 K 1 1( ;<H%488%%h7$7Dzz$q'#2,/DG1DDDAws|T!W,,r4   c                 P    | j                  | j                  j                  |       y)aX  
        Sets whether the item ignores transformations and draws directly to screen pixels.
        If `True`, the item will not inherit any scale or rotation transformations from its
        parent items, but its position will be transformed as usual.
        (see ``GraphicsItem::ItemIgnoresTransformations`` in the Qt documentation)
        N)setFlagGraphicsItemFlagItemIgnoresTransformationsr<   s     r3   	setPxModezImageItem.setPxMode  s     	T**EEqIr4   c                 &    | j                  d       y )NF)r  rL   s    r3   setScaledModezImageItem.setScaledMode  s    ur4   c                     | j                   r| j                          | j                  ry t        j                  j                  | j                        S rj   )r#   r   r$   r   QPixmap	fromImager   rL   s    r3   	getPixmapzImageItem.getPixmap  s9    KKM!!}}&&t{{33r4   c                     | j                         }| j                  y|j                         | j                         z  |j                         | j                         z  fS )zG
        Returns the scene-size of a single pixel in the image
        r   )sceneBoundingRectr   rE   rH   )r1   brs     r3   	pixelSizezImageItem.pixelSize  sL     ##%::xxz$**,&		DKKM(AAAr4   c                     | j                   rN| j                         \  }}|d| _        d| _        y ||f| j                  k7  rd| _        | j                          y y y )NT)r   r   r#   r$   r    r6   )r1   r   r   s      r3   viewTransformChangedzImageItem.viewTransformChanged  sb    557HC{'+$%)"SzT111'+$ 2 r4   c                    | j                  t        j                  dd            }| j                  t        j                  dd            }| j                  t        j                  dd            }|yt        ||z
        j	                         }t        ||z
        j	                         }|dk(  s|dk(  ryt        dt        d|z              t        dt        d|z              fS )Nr   r   r   g      ?)mapToDevicer   QPointFr
   lengthr   r   )r1   oxyr   r   s         r3   r   z#ImageItem._computeDownsampleFactors  s    V^^Aq12V^^Aq12V^^Aq129!a%L!!a%L!6Q!V1c#'l#SCaL%999r4   c                 
   |j                         t        j                  j                  j                  k7  r|j                          y | j                  1|j                          | j                  |j                         |       y y rj   )
buttonr   QtMouseButton
LeftButtonignorer,   acceptdrawAtposr1   evs     r3   mouseDragEventzImageItem.mouseDragEvent  sX    99;&))//:::IIK__(IIKKK"% )r4   c                 v   |j                         t        j                  j                  j                  k(  r!| j                  |      r|j                          | j                  W|j                         t        j                  j                  j                  k(  r!| j                  |j                         |       y y y rj   )r  r   r  r  RightButtonraiseContextMenur  r,   r  r  r  r  s     r3   mouseClickEventzImageItem.mouseClickEvent  s{    99;&))//;;;$$R(		??&299;&)):O:O:Z:Z+ZKK"% ,[&r4   c           	      2   | j                         }|y| j                         j                  | ||      }|j                         }|j	                  t        j                  t        |j                               t        |j                                            y)NFT)
getMenusceneaddParentContextMenus	screenPospopupr   QPointr   r  r  )r1   r   r   r  s       r3   r$  zImageItem.raiseContextMenu  sh    ||~<zz|11$bAlln

6==SUUWs3557|<=r4   c                    | j                   | j                  sy t        j                         | _         | j                   j	                  t        dd             t        j                  t        dd      | j                         }|j                  j                  | j                         | j                   j                  |       || j                   _        | j                   S )Nr   ImagezRemove image)r   r.   r   QMenusetTitler   r   QAction	triggeredconnectremoveClicked	addActionremAct)r1   r6  s     r3   r'  zImageItem.getMenu  s    99>>!)DIIIyg>?]]9[.#I499UF$$T%7%78II'%DIIyyr4   c                    |j                         s| j                  |j                  t        j                  j
                  j                        rg|j                  t        j                  j
                  j                         |j                  t        j                  j
                  j                         y |j                         sA| j                  r4|j                  t        j                  j
                  j                         y y y rj   )
isExitr,   acceptDragsr   r  r  r  acceptClicksr#  r.   r  s     r3   
hoverEventzImageItem.hoverEvent  s    yy{t:r~~fiiNcNcNnNn?oOOFII11<<=OOFII11==>OOFII11==> "0r4   c                      y rj   r   r  s     r3   tabletEventzImageItem.tabletEvent  s    r4   c                    | j                   dk(  r3t        |j                               t        |j                               g}n2t        |j                               t        |j                               g}| j                  }| j
                  }d|j                  d   g}d|j                  d   g}|d   |d   z
  |d   |d   z
  |j                  d   z   g}|d   |d   z
  |d   |d   z
  |j                  d   z   g}dD ]  }	t        d||	          }
t        d| j                  j                  d   ||	   z
        }||	xx   |
|z   z  cc<   ||	xx   |
|z   z  cc<   t        d||	          }t        d| j                  j                  d   ||	   z
        }||	xx   ||z   z  cc<   ||	xx   ||z   z  cc<    t        |d   |d         t        |d   |d         f}t        |d   |d         t        |d   |d         f}| j                  }|}t        | j                  t              r!| j                  || j                  ||||       y ||   }| j                  dk(  r@|.||   }| j                  |   d|z
  z  ||z  z   | j                  |<   nO|| j                  |<   n?| j                  dk(  r| j                  |xx   |z  cc<   nt        d| j                  z        | j                          y )Nr@   r   r   )r   r   setaddzUnknown draw mode '%s')r(   r   r  r  r,   drawKernelCenterrB   r   r   slicedrawMaskr\   drawModer   	ExceptionrU   )r1   r  r   dkkcsxsytxtyr   dx1dx2dy1dy2tsssmasksrcs                     r3   r  zImageItem.drawAt%  s   >>[(suuw<SUUW.Csuuw<SUUW.C__""__!fr!unc!fr!unbhhqk9:!fr!unc!fr!unbhhqk9: 		Aq"Q%=.Ca))!,RU23CqESWEqESWEq"Q%=.Ca))!,RU23CqESWEqESWE		 BqE"Q% %1be"45BqE"Q% %1be"45}}dmmX.MM"djj$B;b'C}}%#8D%)ZZ^qv%>t%KDJJrN%(DJJrN%'

2#% 84== HIIr4   c                 <    || _         || _        || _        || _        y rj   )r,   rA  rD  rC  )r1   kernelrR  centerr7   s        r3   setDrawKernelzImageItem.setDrawKernelQ  s      &r4   c                     t        j                         | _        | j                  j                  j	                  | j
                         | j                  j                  d       y )Nr   )r   QTimerremoveTimertimeoutr3  emitRemoveRequestedstartrL   s    r3   r4  zImageItem.removeClickedW  sD    !==?  (()A)ABq!r4   c                     | j                   j                  j                  | j                         | j                  j                  |        y rj   )rZ  r[  
disconnectr\  sigRemoveRequestedr   rL   s    r3   r\  zImageItem.emitRemoveRequested]  s6      ++D,D,DE$$T*r4   rj   )Tr   )r@   )g    .A)r   r   F   r   )NN)r   r   r?  )8__name__
__module____qualname____doc__r   Signalr   objectr`  r   r8   r>   rE   rH   rM   rR   rV   rX   rd   rf   ra   staticmethodrh   rr   r0   rz   r   r   r/   r+   r   r   r   r   r   rU   r   r   r   r   r  r  r  r  r  r   r!  r%  r$  r'  r;  r=  r  rW  r4  r\  r   r4   r3   r   r      s5    $fmmoO&v.("T>&&B
P
2G"#$  @D2`%D3#	*3,<(	0U#n,(* X[),I-VJ4B	:&&
?*X"+r4   )r   collections.abcr   rl    r   r   r   r:   r   r	   r
   r  r   r   r   util.cupy_helperr   r   QCoreApplicationr   __all__r   r   r4   r3   <module>rn     sR     $        ) ) & *##--	-J+ J+r4   