o
     h                     @  sd   d dl mZ ddlmZ G dd dZG dd dZG dd	 d	ZG d
d dZG dd deZdS )    )annotations   )Imagec                   @  $   e Zd ZdZdddZddd	Zd
S )HDCz
    Wraps an HDC integer. The resulting object can be passed to the
    :py:meth:`~PIL.ImageWin.Dib.draw` and :py:meth:`~PIL.ImageWin.Dib.expose`
    methods.
    dcintreturnNonec                 C  
   || _ d S Nr   )selfr    r   R/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/PIL/ImageWin.py__init__      
zHDC.__init__c                 C     | j S r   r   r   r   r   r   __int__"      zHDC.__int__N)r   r   r	   r
   r	   r   __name__
__module____qualname____doc__r   r   r   r   r   r   r          
r   c                   @  r   )HWNDz
    Wraps an HWND integer. The resulting object can be passed to the
    :py:meth:`~PIL.ImageWin.Dib.draw` and :py:meth:`~PIL.ImageWin.Dib.expose`
    methods, instead of a DC.
    wndr   r	   r
   c                 C  r   r   r   )r   r   r   r   r   r   -   r   zHWND.__init__c                 C  r   r   r    r   r   r   r   r   0   r   zHWND.__int__N)r   r   r	   r
   r   r   r   r   r   r   r   &   r   r   c                   @  sb   e Zd ZdZ	d#d$d	d
Zd%ddZ	d#d&ddZd'ddZ	d#d(ddZd)dd Z	d*d!d"Z
dS )+Diba&  
    A Windows bitmap with the given mode and size.  The mode can be one of "1",
    "L", "P", or "RGB".

    If the display requires a palette, this constructor creates a suitable
    palette and associates it with the image. For an "L" image, 128 graylevels
    are allocated. For an "RGB" image, a 6x6x6 colour cube is used, together
    with 20 graylevels.

    To make sure that palettes work properly under Windows, you must call the
    ``palette`` method upon certain events from Windows.

    :param image: Either a PIL image, or a mode string. If a mode string is
                  used, a size must also be given.  The mode can be one of "1",
                  "L", "P", or "RGB".
    :param size: If the first argument is a mode string, this
                 defines the size of the image.
    NimageImage.Image | strsizetuple[int, int] | Noner	   r
   c                 C  s   t |tr|}d}|d u rd}t|n|j}|j}|dvr#t|}tj||| _	|| _|| _|rAt |tr:J | 
| d S d S )N z+If first argument is mode, size is required)1LPRGB)
isinstancestr
ValueErrormoder$   r   Zgetmodebasecoredisplayr"   paste)r   r"   r$   r.   msgr   r   r   r   H   s$   

zDib.__init__handleint | HDC | HWNDc              
   C  s`   t |}t|tr(| j|}z| j| W | j|| dS | j|| w | j| dS )a   
        Copy the bitmap contents to a device context.

        :param handle: Device context (HDC), cast to a Python integer, or an
                       HDC or HWND instance.  In PythonWin, you can use
                       ``CDC.GetHandleAttrib()`` to get a suitable handle.
        N)r   r+   r   r"   getdcexpose	releasedc)r   r3   
handle_intr   r   r   r   r6   ]   s   
"z
Dib.exposedsttuple[int, int, int, int]src tuple[int, int, int, int] | Nonec              
   C  sz   |du r	d| j  }t|}t|tr3| j|}z| j||| W | j|| dS | j|| w | j||| dS )am  
        Same as expose, but allows you to specify where to draw the image, and
        what part of it to draw.

        The destination and source areas are given as 4-tuple rectangles. If
        the source is omitted, the entire image is copied. If the source and
        the destination have different sizes, the image is resized as
        necessary.
        N)r   r   )r$   r   r+   r   r"   r5   drawr7   )r   r3   r9   r;   r8   r   r   r   r   r=   o   s   

"zDib.drawr   c              
   C  s`   t |}t|tr(| j|}z| j|}W | j|| |S | j|| w | j|}|S )at  
        Installs the palette associated with the image in the given device
        context.

        This method should be called upon **QUERYNEWPALETTE** and
        **PALETTECHANGED** events from Windows. If this method returns a
        non-zero value, one or more display palette entries were changed, and
        the image should be redrawn.

        :param handle: Device context (HDC), cast to a Python integer, or an
                       HDC or HWND instance.
        :return: The number of entries that were changed (if one or more entries,
                 this indicates that the image should be redrawn).
        )r   r+   r   r"   r5   query_paletter7   )r   r3   r8   resultr   r   r   r>      s   
zDib.query_paletteimImage.Imageboxc                 C  sJ   |   | j|jkr|| j}|r| j|j| dS | j|j dS )a  
        Paste a PIL image into the bitmap image.

        :param im: A PIL image.  The size must match the target region.
                   If the mode does not match, the image is converted to the
                   mode of the bitmap image.
        :param box: A 4-tuple defining the left, upper, right, and
                    lower pixel coordinate.  See :ref:`coordinate-system`. If
                    None is given instead of a tuple, all of the image is
                    assumed.
        N)loadr.   convertr"   r1   r@   )r   r@   rB   r   r   r   r1      s   z	Dib.pastebufferbytesc                 C  s   | j | dS )z
        Load display memory contents from byte data.

        :param buffer: A buffer containing display data (usually
                       data returned from :py:func:`~PIL.ImageWin.Dib.tobytes`)
        N)r"   	frombytes)r   rE   r   r   r   rG      s   zDib.frombytesc                 C  s
   | j  S )zy
        Copy display memory contents to bytes object.

        :return: A bytes object containing display data.
        )r"   tobytesr   r   r   r   rH      s   
zDib.tobytesr   )r"   r#   r$   r%   r	   r
   )r3   r4   r	   r
   )r3   r4   r9   r:   r;   r<   r	   r
   )r3   r4   r	   r   )r@   rA   rB   r<   r	   r
   )rE   rF   r	   r
   )r	   rF   )r   r   r   r   r   r6   r=   r>   r1   rG   rH   r   r   r   r   r!   4   s    


	r!   c                   @  sd   e Zd ZdZ	d#d$ddZd%ddZd&ddZd'ddZd(ddZd&ddZ	d)dd Z
d(d!d"ZdS )*Windowz*Create a Window with the given title size.PILNtitler,   width
int | Noneheightr	   r
   c                 C  s"   t j|| j|p	d|pd| _d S )Nr   )r   r/   Zcreatewindow_Window__dispatcherZhwnd)r   rK   rL   rN   r   r   r   r      s   
zWindow.__init__actionargsr   c                 G  s   t | d| |  d S )NZ
ui_handle_)getattr)r   rP   rQ   r   r   r   Z__dispatcher   s   zWindow.__dispatcherr   x0y0x1y1c                 C     d S r   r   r   r   rS   rT   rU   rV   r   r   r   ui_handle_clear      zWindow.ui_handle_clearc                 C  rW   r   r   )r   rS   rT   rU   rV   r   r   r   ui_handle_damage   rZ   zWindow.ui_handle_damagec                 C  rW   r   r   r   r   r   r   ui_handle_destroy   rZ   zWindow.ui_handle_destroyc                 C  rW   r   r   rX   r   r   r   ui_handle_repair   rZ   zWindow.ui_handle_repairc                 C  rW   r   r   )r   rL   rN   r   r   r   ui_handle_resize   rZ   zWindow.ui_handle_resizec                 C  s   t j  d S r   )r   r/   Z	eventloopr   r   r   r   mainloop   s   zWindow.mainloop)rJ   NN)rK   r,   rL   rM   rN   rM   r	   r
   )rP   r,   rQ   r   r	   r
   r   r   rS   r   rT   r   rU   r   rV   r   r	   r
   )
rS   r   rT   r   rU   r   rV   r   r	   r
   )r	   r
   )rL   r   rN   r   r	   r
   )r   r   r   r   r   rO   rY   r[   r\   r]   r^   r_   r   r   r   r   rI      s    





rI   c                      s.   e Zd ZdZdd fd	d
ZdddZ  ZS )ImageWindowz6Create an image window which displays the given image.rJ   r"   Image.Image | DibrK   r,   r	   r
   c                   s8   t |ts	t|}|| _|j\}}t j|||d d S )N)rL   rN   )r+   r!   r"   r$   superr   )r   r"   rK   rL   rN   	__class__r   r   r      s
   

zImageWindow.__init__r   r   rS   rT   rU   rV   c                 C  s   | j |||||f d S r   )r"   r=   rX   r   r   r   r]      s   zImageWindow.ui_handle_repair)rJ   )r"   rb   rK   r,   r	   r
   r`   )r   r   r   r   r   r]   __classcell__r   r   rd   r   ra      s    ra   N)	
__future__r   r&   r   r   r   r!   rI   ra   r   r   r   r   <module>   s     