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   úL/var/www/html/premium_crap/venv/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   Ú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   r4   Ú
handle_intr   r   r   r   r7   ]   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"   r6   Údrawr8   )r   r4   r:   r<   r9   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"   r6   Úquery_paletter8   )r   r4   r9   Ú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"   r2   rA   )r   rA   rC   r   r   r   r2   ¤   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   rF   r   r   r   rH   º   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   rI   Ã   s   
zDib.tobytesr   )r"   r#   r$   r%   r	   r
   )r4   r5   r	   r
   )r4   r5   r:   r;   r<   r=   r	   r
   )r4   r5   r	   r   )rA   rB   rC   r=   r	   r
   )rF   rG   r	   r
   )r	   rG   )r   r   r   r   r   r7   r>   r?   r2   rH   rI   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   r0   ÚcreatewindowÚ_Window__dispatcherÚhwnd)r   rL   rM   rO   r   r   r   r   Ï   s   
ÿzWindow.__init__ÚactionÚargsr   c                 G  s   t | d|› �ƒ|Ž  d S )NÚ
ui_handle_)Úgetattr)r   rS   rT   r   r   r   Ú__dispatcherÖ   s   zWindow.__dispatcherr   Úx0Úy0Úx1Úy1c                 C  ó   d S r   r   ©r   r   rX   rY   rZ   r[   r   r   r   Úui_handle_clearÙ   ó   zWindow.ui_handle_clearc                 C  r\   r   r   )r   rX   rY   rZ   r[   r   r   r   Úui_handle_damageÜ   r_   zWindow.ui_handle_damagec                 C  r\   r   r   r   r   r   r   Úui_handle_destroyß   r_   zWindow.ui_handle_destroyc                 C  r\   r   r   r]   r   r   r   Úui_handle_repairâ   r_   zWindow.ui_handle_repairc                 C  r\   r   r   )r   rM   rO   r   r   r   Úui_handle_resizeå   r_   zWindow.ui_handle_resizec                 C  s   t j ¡  d S r   )r   r0   Ú	eventloopr   r   r   r   Úmainloopè   s   zWindow.mainloop)rK   NN)rL   r,   rM   rN   rO   rN   r	   r
   )rS   r,   rT   r   r	   r
   ©r   r   rX   r   rY   r   rZ   r   r[   r   r	   r
   )
rX   r   rY   r   rZ   r   r[   r   r	   r
   )r	   r
   )rM   r   rO   r   r	   r
   )r   r   r   r   r   rQ   r^   r`   ra   rb   rc   re   r   r   r   r   rJ   Ì   s    ÿ





rJ   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.rK   r"   úImage.Image | DibrL   r,   r	   r
   c                   s8   t |tƒs	t|ƒ}|| _|j\}}tƒ j|||d� d S )N)rM   rO   )r+   r!   r"   r$   Úsuperr   )r   r"   rL   rM   rO   ©Ú	__class__r   r   r   ï   s
   

zImageWindow.__init__r   r   rX   rY   rZ   r[   c                 C  s   | j  |||||f¡ d S r   )r"   r>   r]   r   r   r   rb   ö   s   zImageWindow.ui_handle_repair)rK   )r"   rh   rL   r,   r	   r
   rf   )r   r   r   r   r   rb   Ú__classcell__r   r   rj   r   rg   ì   s    rg   N)	Ú
__future__r   r&   r   r   r   r!   rJ   rg   r   r   r   r   Ú<module>   s     