
    :h                        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y)    )annotations   )Imagec                       e Zd ZdZddZddZy)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.
    c                    || _         y Ndc)selfr   s     J/var/www/urcfiles/bundle/venv/lib/python3.12/site-packages/PIL/ImageWin.py__init__zHDC.__init__   s	        c                    | j                   S r	   r
   r   s    r   __int__zHDC.__int__"   s    wwr   N)r   intreturnNoner   r   __name__
__module____qualname____doc__r   r    r   r   r   r      s    r   r   c                       e Zd ZdZddZddZy)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.
    c                    || _         y r	   wnd)r   r!   s     r   r   zHWND.__init__-   s	    r   c                    | j                   S r	   r    r   s    r   r   zHWND.__int__0   s    xxr   N)r!   r   r   r   r   r   r   r   r   r   r   &   s    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
y)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.
    Nc                ^   t        |t              r|}d}|%d}t        |      |j                  }|j                  }|dvrt        j                  |      }t
        j                  j                  ||      | _	        || _        || _        |r$t        |t              rJ | j                  |       y y )N z+If first argument is mode, size is required)1LPRGB)
isinstancestr
ValueErrormodesizer   getmodebasecoredisplayimagepaste)r   r3   r/   r.   msgs        r   r   zDib.__init__H   s     eS!DE|C o%::D::D--$$T*DZZ''d3
		!%---JJu r   c                Z   t        |      }t        |t              rT| j                  j	                  |      }	 | j                  j                  |       | j                  j                  ||       y| j                  j                  |       y# | j                  j                  ||       w xY w)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   r3   getdcexpose	releasedc)r   handle
handle_intr   s       r   r8   z
Dib.expose]   s     [
fd#!!*-B5

!!"%

$$Z4JJj) 

$$Z4s   B B*c                   |d| j                   z   }t        |      }t        |t              rV| j                  j                  |      }	 | j                  j                  |||       | j                  j                  ||       y| j                  j                  |||       y# | j                  j                  ||       w xY w)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   r3   r7   drawr9   )r   r:   dstsrcr;   r   s         r   r=   zDib.drawo   s     ;499$C[
fd#!!*-B5

C-

$$Z4JJOOJS1 

$$Z4s   	B! !B?c                ^   t        |      }t        |t              rU| j                  j	                  |      }	 | j                  j                  |      }| j                  j                  ||       |S | j                  j                  |      }|S # | j                  j                  ||       w xY w)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   r3   r7   query_paletter9   )r   r:   r;   results       r   rA   zDib.query_palette   s     [
fd#ZZ%%j1F511&9

$$VV4  ZZ--j9F 

$$VV4s   B B,c                (   |j                          | j                  |j                  k7  r|j                  | j                        }|r'| j                  j	                  |j
                  |       y| j                  j	                  |j
                         y)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.   convertr3   r4   im)r   rF   boxs      r   r4   z	Dib.paste   s`     		99DII&BJJRUUC(JJRUU#r   c                :    | j                   j                  |       y)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)r3   	frombytes)r   buffers     r   rI   zDib.frombytes   s     	

V$r   c                6    | j                   j                         S )zy
        Copy display memory contents to bytes object.

        :return: A bytes object containing display data.
        )r3   tobytesr   s    r   rL   zDib.tobytes   s     zz!!##r   r	   )r3   zImage.Image | strr/   ztuple[int, int] | Noner   r   )r:   int | HDC | HWNDr   r   )r:   rM   r>   ztuple[int, int, int, int]r?    tuple[int, int, int, int] | Noner   r   )r:   rM   r   r   )rF   zImage.ImagerG   rN   r   r   )rJ   bytesr   r   )r   rO   )r   r   r   r   r   r8   r=   rA   r4   rI   rL   r   r   r   r$   r$   4   s    ( HL&.D	**, 15	2 2 '2 .	2
 
266 HL$$$D$	$,%$r   r$   c                  b    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y)Windowz*Create a Window with the given title size.Nc                v    t         j                  j                  || j                  |xs d|xs d      | _        y )Nr   )r   r1   createwindow_Window__dispatcherhwnd)r   titlewidthheights       r   r   zWindow.__init__   s1     JJ++4$$ejq&+A
	r   c                (     t        | d|       |  y )N
ui_handle_)getattr)r   actionargss      r   __dispatcherzWindow.__dispatcher   s    ,
6(+,d3r   c                     y r	   r   r   r   x0y0x1y1s         r   ui_handle_clearzWindow.ui_handle_clear       r   c                     y r	   r   )r   ra   rb   rc   rd   s        r   ui_handle_damagezWindow.ui_handle_damage   rf   r   c                     y r	   r   r   s    r   ui_handle_destroyzWindow.ui_handle_destroy   rf   r   c                     y r	   r   r`   s         r   ui_handle_repairzWindow.ui_handle_repair   rf   r   c                     y r	   r   )r   rW   rX   s      r   ui_handle_resizezWindow.ui_handle_resize   rf   r   c                @    t         j                  j                          y r	   )r   r1   	eventloopr   s    r   mainloopzWindow.mainloop   s    

r   )PILNN)rV   r,   rW   
int | NonerX   rs   r   r   )r\   r,   r]   r   r   r   r   r   ra   r   rb   r   rc   r   rd   r   r   r   )
ra   r   rb   r   rc   r   rd   r   r   r   )r   r   )rW   r   rX   r   r   r   )r   r   r   r   r   rT   re   rh   rj   rl   rn   rq   r   r   r   rQ   rQ      sT    4 RV

)3
DN
	
4r   rQ   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.c                    t        |t              st        |      }|| _        |j                  \  }}t        |   |||       y )N)rW   rX   )r+   r$   r3   r/   superr   )r   r3   rV   rW   rX   	__class__s        r   r   zImageWindow.__init__   s>    %%JE


veF;r   c                D    | j                   j                  |||||f       y r	   )r3   r=   r`   s         r   rl   zImageWindow.ui_handle_repair   s    

RR,-r   )rr   )r3   zImage.Image | DibrV   r,   r   r   rt   )r   r   r   r   r   rl   __classcell__)ry   s   @r   rv   rv      s    @<.r   rv   N)	
__future__r   r&   r   r   r   r$   rQ   rv   r   r   r   <module>r}      sE   & #   U$ U$p @.& .r   