
    zvg                        d dl mZ ddlmZ  G d d          Z G d d          Z G d d	          Z G d
 d          Z G d de          ZdS )    )annotations   )Imagec                  "    e Zd ZdZd	dZ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                    || _         d S Nr   )selfr   s     I/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/PIL/ImageWin.py__init__zHDC.__init__   s        c                    | j         S r   r   r   s    r   __int__zHDC.__int__"   s	    wr   N)r   r	   r
   r   r
   r	   __name__
__module____qualname____doc__r   r    r   r   r   r      sF                 r   r   c                  "    e Zd ZdZd	dZd
dZdS )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                    || _         d S r   r   )r   r   s     r   r   zHWND.__init__-   s    r   c                    | j         S r   r!   r   s    r   r   zHWND.__int__0   s	    xr   N)r   r	   r
   r   r   r   r   r   r   r   r   &   sF                 r   r   c                  V    e Zd ZdZ	 ddd	ZddZ	 dddZd dZ	 dd!dZd"dZ	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                r   t          |t                    r|}d}|d}t          |          n|j        }|j        }|dvrt          j        |          }t
          j                            ||          | _	        || _        || _        |r.t          |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'   r2   msgs        r   r   zDib.__init__H   s     eS!! 	DE|C oo%  :D:D---$T**DZ''d33
		 	!%-----JJu	 	r   handleint | HDC | HWNDc                f   t          |          }t          |t                    rr| j                            |          }	 | j                            |           | j                            ||           dS # | j                            ||           w xY 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   r8   
handle_intr   s       r   r<   z
Dib.expose]   s     [[
fd## 	*!!*--B5
!!"%%%
$$Z44444
$$Z4444Jj)))))s    A7 7Bdsttuple[int, int, int, int]src tuple[int, int, int, int] | Nonec                   |
d| j         z   }t          |          }t          |t                    rt| j                            |          }	 | j                            |||           | j                            ||           dS # | j                            ||           w xY 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%   r;   drawr=   )r   r8   r?   rA   r>   r   s         r   rD   zDib.drawo   s     ;49$C[[
fd## 	2!!*--B5
C---
$$Z44444
$$Z4444JOOJS11111s   B B"r	   c                d   t          |          }t          |t                    rq| j                            |          }	 | j                            |          }| j                            ||           n:# | j                            ||           w xY 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%   r;   query_paletter=   )r   r8   r>   results       r   rF   zDib.query_palette   s     [[
fd## 	:Z%%j11F511&99
$$VV4444
$$VV4444Z--j99Fs    A6 6BimImage.Imageboxc                   |                                  | 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)loadr2   convertr%   r6   rH   )r   rH   rJ   s      r   r6   z	Dib.paste   sy     				9DI&&B 	$JRUC(((((JRU#####r   bufferbytesc                :    | 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   rN   s     r   rQ   zDib.frombytes   s      	
V$$$$$r   c                4    | j                                         S )zy
        Copy display memory contents to bytes object.

        :return: A bytes object containing display data.
        )r%   tobytesr   s    r   rS   zDib.tobytes   s     z!!###r   r   )r%   r&   r'   r(   r
   r   )r8   r9   r
   r   )r8   r9   r?   r@   rA   rB   r
   r   )r8   r9   r
   r	   )rH   rI   rJ   rB   r
   r   )rN   rO   r
   r   )r
   rO   )r   r   r   r   r   r<   rD   rF   r6   rQ   rS   r   r   r   r$   r$   4   s         ( HL    ** * * *, 15	2 2 2 2 26   6 HL$ $ $ $ $,% % % %$ $ $ $ $ $r   r$   c                  V    e Zd ZdZ	 dddZddZddZddZd dZddZ	d!dZ
d dZdS )"Windowz*Create a Window with the given title size.PILNtitler0   width
int | Noneheightr
   r   c                f    t           j                            || j        |pd|pd          | _        d S )Nr   )r   r4   createwindow_Window__dispatcherhwnd)r   rW   rX   rZ   s       r   r   zWindow.__init__   s5     J++4$ejq&+A
 
			r   actionargsr	   c                2     t          | d|           |  d S )N
ui_handle_)getattr)r   r_   r`   s      r   __dispatcherzWindow.__dispatcher   s(    ,+6++,,d3333r   r   x0y0x1y1c                    d S r   r   r   r   re   rf   rg   rh   s         r   ui_handle_clearzWindow.ui_handle_clear       r   c                    d S r   r   )r   re   rf   rg   rh   s        r   ui_handle_damagezWindow.ui_handle_damage   rl   r   c                    d S r   r   r   s    r   ui_handle_destroyzWindow.ui_handle_destroy   rl   r   c                    d S r   r   rj   s         r   ui_handle_repairzWindow.ui_handle_repair   rl   r   c                    d S r   r   )r   rX   rZ   s      r   ui_handle_resizezWindow.ui_handle_resize   rl   r   c                B    t           j                                         d S r   )r   r4   	eventloopr   s    r   mainloopzWindow.mainloop   s    
r   )rV   NN)rW   r0   rX   rY   rZ   rY   r
   r   )r_   r0   r`   r	   r
   r   r   r	   re   r	   rf   r	   rg   r	   rh   r	   r
   r   )
re   r	   rf   r	   rg   r	   rh   r	   r
   r   )r
   r   )rX   r	   rZ   r	   r
   r   )r   r   r   r   r   r]   rk   rn   rp   rr   rt   rw   r   r   r   rU   rU      s        44 RV
 
 
 
 
4 4 4 4                    r   rU   c                  .     e Zd ZdZdd fd	ZddZ xZS )ImageWindowz6Create an image window which displays the given image.rV   r%   Image.Image | DibrW   r0   r
   r   c                    t          |t                    st          |          }|| _        |j        \  }}t	                                          |||           d S )N)rX   rZ   )r/   r$   r%   r'   superr   )r   r%   rW   rX   rZ   	__class__s        r   r   zImageWindow.__init__   sW    %%% 	JJE

veF;;;;;r   r   r	   re   rf   rg   rh   c                D    | j                             |||||f           d S r   )r%   rD   rj   s         r   rr   zImageWindow.ui_handle_repair   s'    
RR,-----r   )rV   )r%   r{   rW   r0   r
   r   rx   )r   r   r   r   r   rr   __classcell__)r~   s   @r   rz   rz      s\        @@< < < < < < <. . . . . . . .r   rz   N)	
__future__r   r*   r   r   r   r$   rU   rz   r   r   r   <module>r      s	  & # " " " " "                    U$ U$ U$ U$ U$ U$ U$ U$p       @. . . . .& . . . . .r   