
    zvg#                    N   U d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZ ddlmZmZ ddlmZ dd	lmZ d
ed<   	 ej        j        Zn# e$ r dZY nw xY we	rddlmZmZ eeeedf         e f         Z!	  G d d          Z"d0d1dZ#	 d2d3dZ$	 	 d4d5d%Z%d6d,Z&d7d/Z'dS )8    )annotationsN)Sequence)
ModuleType)TYPE_CHECKINGAnyAnyStrCallableUnioncast   )Image
ImageColor)	deprecate)Coordsz(Callable[[], Image.core._Outline] | NoneOutline)
ImageDraw2	ImageFont.c                     e Zd ZU dZded<   dZd[d
Zd\dZd]dZ	 dZd^dZ	 	 d_d`dZ		 dZdad Z
	 	 	 dbdcd"Z	 	 	 dbddd#Z	 	 	 dbded&Z	 	 	 dfdgd)Z	 	 dhdid,Z	 	 	 dbdcd-ZdZdjd.Z	 	 	 dbddd/Z	 	 	 	 dkdld4Z	 	 	 dbddd5Z	 	 	 	 dkdd6dmd9Zdnd=Zdod?ZdpdBZ	 	 	 	 	 	 	 	 	 	 	 dqdrdSZ	 	 	 	 	 	 	 	 	 	 	 dqddTdsdUZ	 	 	 	 	 dtddTdudVZ	 	 	 	 	 	 	 	 	 dvddTdwdXZ	 	 	 	 	 	 	 	 	 dvddTdwdYZdS )x	ImageDrawNNImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont | NonefontimImage.Imagemode
str | NonereturnNonec                P   |                                  |j        r|                                 d}||j        }||j        k    r%|dk    r|j        dk    rd}nd}t	          |          |dk    r|j        | _        nd| _        || _        |j        | _        t          j	        
                    | j        |          | _
        || _        |dv r | j
                            d          | _        n| j
                            d	          | _        |d
v rd| _        nd| _        d| _        dS )a  
        Create a drawing instance.

        :param im: The image to draw in.
        :param mode: Optional mode to use for color values.  For RGB
           images, this argument can be RGB or RGBA (to blend the
           drawing into the image).  For all other modes, this argument
           must be the same as the image mode.  If omitted, the mode
           defaults to the mode of the image.
        r   NRGBARGBr   zmode mismatchP)IF)1r!   r"   r#   r%   LF)loadreadonly_copyr   
ValueErrorpalette_imager   r   coredrawdraw_inkinkfontmodefill)selfr   r   blendmsgs        J/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/PIL/ImageDraw.py__init__zImageDraw.__init__E   s    				; 	HHJJJ<7D27??v~~"'U"2"2% oo%3;;:DLLDL%JOODGU33		:y))!,,DHHy))"--DH'''DMMDM			    GImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFontc                R    | j         sddlm}  |j                    | _         | j         S )a=  
        Get the current default font.

        To set the default font for this ImageDraw instance::

            from PIL import ImageDraw, ImageFont
            draw.font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")

        To set the default font for all future ImageDraw instances::

            from PIL import ImageDraw, ImageFont
            ImageDraw.ImageDraw.font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")

        If the current default font is ``None``,
        it is initialized with ``ImageFont.load_default()``.

        :returns: An image font.r   r   )r    r   load_default)r3   r   s     r6   getfontzImageDraw.getfonto   s:    ( y 	1######.	.00DIyr8   	font_sizefloat | Nonec                Z    |ddl m}  |j        |          S |                                 S )Nr   r;   )r<   r   r=   r>   )r3   r?   r   s      r6   _getfontzImageDraw._getfont   s=      ######)9))444<<>>!r8   r0   _Ink | Noner2   tuple[int | None, int | None]c                h   d }d }||| j         r	| j        }n| j        }n|t          |t                    rt	          j        || j                  }| j        r5t          |t                    r | j                            || j	                  }| j
                            |          }|t          |t                    rt	          j        || j                  }| j        r5t          |t                    r | j                            || j	                  }| j
                            |          }||fS N)r2   r0   
isinstancestrr   getcolorr   r+   tupler,   r.   r/   )r3   r0   r2   
result_inkresult_fills        r6   _getinkzImageDraw._getink   s,    
;4<y &"h!X

c3'' >$-c49==C< BJsE$:$: B,//T[AAC!Y//44
dC(( @%.tTY??D< DJtU$;$; D<00t{CCD"i0066;&&r8   r   xyr   startfloatendwidthintc                z    |                      |          \  }}| | j                            |||||           dS dS )zDraw an arc.N)rM   r.   draw_arc)r3   rN   rO   rQ   r2   rR   r0   s          r6   arczImageDraw.arc   sI     LL&&	T?Ir5#sE::::: ?r8   Sequence[int]bitmapc                    |                                  |                     |          \  }}||}|#| j                            ||j        |           dS dS )zDraw a bitmap.N)r'   rM   r.   draw_bitmapr   )r3   rN   rX   r2   r0   s        r6   rX   zImageDraw.bitmap   s^     	LL&&	T;C?I!!"fi55555 ?r8   outlinec                    |                      ||          \  }}|| j                            ||||d           |-||k    r)|dk    r%| j                            ||||d|           dS dS dS dS )zDraw a chord.Nr   r   )rM   r.   
draw_chord	r3   rN   rO   rQ   r2   r[   rR   r0   fill_inks	            r6   chordzImageDraw.chord   s     Wd33XI  UC1===?sh5A::I  UCa????? ?::r8   c                    |                      ||          \  }}|| j                            ||d           |+||k    r'|dk    r#| j                            ||d|           dS dS dS dS )zDraw an ellipse.Nr   r   )rM   r.   draw_ellipser3   rN   r2   r[   rR   r0   r_   s          r6   ellipsezImageDraw.ellipse   s     Wd33XI""2x333?sh5A::I""2sAu55555 ?::r8   Sequence[float]radiusc                    |d         |z
  |d         |z
  |d         |z   |d         |z   f}|                      ||||           dS )z4Draw a circle given center coordinates and a radius.r   r   N)rd   )r3   rN   rf   r2   r[   rR   
ellipse_xys          r6   circlezImageDraw.circle   sP     efnbefnbefnbefnU
Zw66666r8   r   jointc                   |                      |          d         }|b| j                            |           |dk    rAdk    r<t          d         t          t
          f          r,t          t          t          t                                      }n*fdt          dt                    d          D             }t          dt          |          dz
            D ]}||         }d ||dz
           |f|||dz            ffD             }	|	d         |	d         k    rBdfd}
|	d         |	d         k    o|	d         dz
  |	d         k    p&|	d         |	d         k     o|	d         dz   |	d         k    }|d         dz  z
  dz   |d         dz  z
  dz   f|d         dz  z   dz
  |d         dz  z   dz
  fg}|r|	d         dz   |	d         dz   }}n|	d         dz
  |	d         dz
  }}|                     ||dz
  |dz
  |           dk    rq|r, |
||	d         dz             | |
||	d         dz             g}n+ |
||	d         dz
            | |
||	d         dz
            g}|                     ||d           dS dS dS dS )z6Draw a line, or a connected sequence of line segments.r   Ncurve   c                    g | ]:}t          t          t                   t          ||d z                                ;S )   )r   r   rP   rJ   ).0irN   s     r6   
<listcomp>z"ImageDraw.line.<locals>.<listcomp>   sK        Xe_eBq1q5yM.B.BCC  r8   ro   r   c           
         g | ]M\  }}t          j        t          j        |d          |d          z
  |d         |d         z
                      dz  NS )r   r   h  )mathdegreesatan2)rp   rO   rQ   s      r6   rr   z"ImageDraw.line.<locals>.<listcomp>  sg        'E3 TZAq0A58cRSfCT%U%UVV  r8   coordre   anglerP   r   tuple[float, ...]c                   | \  }}|dz  }dz  dz
  }t          d ||t          j        t          j        |                    z  f||t          j        t          j        |                    z  ffD                       S )NZ   ro   r   c              3  ~   K   | ]8\  }}||d k    rt          j        |          nt          j        |          z   V  9dS )r   N)ru   floorceil)rp   pp_ds      r6   	<genexpr>z9ImageDraw.line.<locals>.coord_at_angle.<locals>.<genexpr>  s[       % % &3 C!GGC3P% % % % % %r8   )rJ   ru   cosradianssin)rx   ry   xydistancerR   s        r6   coord_at_anglez&ImageDraw.line.<locals>.coord_at_angle  s      %1#(19q=$ % % "#HtxU8K8K/L/L$L M!"HtxU8K8K/L/L$L M+% % %     r8      r|         )rR   )rx   re   ry   rP   r   rz   )rM   r.   
draw_linesrG   listrJ   r   r   rP   rangelenpiesliceline)r3   rN   r2   rR   rj   r0   pointsrq   pointanglesr   flippedcoordsrO   rQ   
gap_coordss    ` `            r6   r   zImageDraw.line   s7    ll4  #?I  S%000EAIIbedE]33 !(8E?";R@@FF   !&q#b''1!5!5  F q#f++/22 7= 7=A"1IE  $AE]E2"F1q5M2+  F ayF1I--       q	F1I-M&)c/F1I2MQ )fQi/OF1IOfQi4O  qEAI-158eai3G!3KLqEAI-158eai3G!3KLF  F&,Qi"nfQi"ns&,Qi"nfQi"nsMM&%"*cBhEEEqyy"  .ufQi"n E E % .ufQi"n E E*JJ !/ufQi"n E E % .ufQi"n E E*J
 		*d!	<<<E ?II7= 7=r8   shapeImage.core._Outlinec                    |                                  |                     ||          \  }}|| j                            ||d           |$||k    r | j                            ||d           dS dS dS )z(Experimental) Draw a shape.Nr   r   )closerM   r.   draw_outline)r3   r   r2   r[   r0   r_   s         r6   r   zImageDraw.shape<  s     	Wd33XI""5(A666?shI""5#q11111 ?r8   c                    |                      ||          \  }}|| j                            ||||d           |-||k    r)|dk    r%| j                            ||||d|           dS dS dS dS )zDraw a pieslice.Nr   r   )rM   r.   draw_pieslicer^   s	            r6   r   zImageDraw.piesliceJ  s     Wd33XI##BsHa@@@?sh5A::I##BsCEBBBBB ?::r8   c                t    |                      |          \  }}|| j                            ||           dS dS )z#Draw one or more individual pixels.N)rM   r.   draw_points)r3   rN   r2   r0   s       r6   r   zImageDraw.pointZ  sA    LL&&	T?I!!"c***** ?r8   c                   |                      ||          \  }}|| j                            ||d           |||k    r|dk    r|dk    r| j                            ||d|           dS | j        ^t	          j        d| j        j                  }|                      d          d         }|                                }	t          |	          }
|
j                            ||d           |                                }t          |          }
|dz  dz
  }|
j                            ||d|           |	                    ||	           t	          j        | j
        | j        j                  }t          |          }
|
j                            ||d|           | j        	                    |j        d|j        z   |j                   dS dS dS dS dS )zDraw a polygon.Nr   r   r%   ro   )maskr   r   )rM   r.   draw_polygonr   r   newsizecopyDrawpaster   )r3   rN   r2   r[   rR   r0   r_   r   mask_inkfill_imr.   ink_imr   s                r6   polygonzImageDraw.polygon`  s    Wd33XI""2x333?sh5A::zz	&&r3599999$ ydgl33<<??1-))++G}}	&&r8Q777F||	A	&&r8Q>>>

6
000Yty$',77Bxx	&&r35999beVbg%5tw?????/ ?:: %$r8   bounding_circle!Sequence[Sequence[float] | float]n_sidesrotationc                X    t          |||          }|                     ||||           dS )zDraw a regular polygon.N)!_compute_regular_polygon_verticesr   )r3   r   r   r   r2   r[   rR   rN   s           r6   regular_polygonzImageDraw.regular_polygon  s3     /RRRw.....r8   c                    |                      ||          \  }}|| j                            ||d           |+||k    r'|dk    r#| j                            ||d|           dS dS dS dS )zDraw a rectangle.Nr   r   )rM   r.   draw_rectanglerc   s          r6   	rectanglezImageDraw.rectangle  s     Wd33XI$$R1555?sh5A::I$$Ra77777 ?::r8   )cornersr   $tuple[bool, bool, bool, bool] | Nonec               $	    t          |d         t          t          f          r5t          t          t          t
                            |          \  \  \  n%t          t          t
                   |          \  k     rd}t          |          k     rd}t          |          d|dz  t                    t                    t                    t                    d\  t                    rBz
  dz
  k    rz
  z
  dz
  k    rz
  rr 	                    |||          S dk    st                    s                     |||          S t          dz            }                     ||          \  d fd}	2 |	d           r- j                            |z   dz   |z
  dz
  fd           n>|z
  dz
  |z   dz   k    r, j                            |z   dz   |z
  dz
  fd           ss|z   g}
d         r|
dxx         |dz   z  cc<   d         r|
dxx         |dz   z  cc<    j                            |
d           |z
  g}d         r|dxx         |dz   z  cc<   d         r|dxx         |dz   z  cc<    j                            |d           k    rdk    r |	d           sz   dz
  g}d         r|dxx         |dz   z  cc<   d         r|dxx         |dz   z  cc<    j                            |d           z
  dz   g}d         r|dxx         |dz   z  cc<   d         r|dxx         |dz   z  cc<    j                            |d           sĉz   dz
  g}
d         r|
dxx         |dz   z  cc<   d         r|
dxx         |dz   z  cc<    j                            |
d           z
  dz   g}d         r|dxx         |dz   z  cc<   d         r|dxx         |dz   z  cc<    j                            |d           dS dS dS dS dS )zDraw a rounded rectangle.r   z&x1 must be greater than or equal to x0z&y1 must be greater than or equal to y0N)TTTTro   )FFr   r   boolr   r   c                   rz   z   fddfz
  z   fddff}nrz   z   fddfz
  z   fddff}n`t          fdt          z   z   fddfz
  z   fddfz
  z
  fddfz
  z   fddff          D                       }|D ]-}| r 	j        j        |dfz      	j        j        |
fz     .d S )Nr   rt   r   r|     c              3  2   K   | ]\  }}|         |V  d S rF    )rp   rq   partr   s      r6   r   zDImageDraw.rounded_rectangle.<locals>.draw_corners.<locals>.<genexpr>  sG        4 qz     r8   r   )rJ   	enumerater.   r   rU   )r   partsr   r   dr_   full_xfull_yr0   r3   rR   x0x1y0y1s      r6   draw_cornersz1ImageDraw.rounded_rectangle.<locals>.draw_corners  s     "b1fb1f-sC8"q&"q&"-q#6   "b1fb1f-r371fb"b1f-sB7     #, "b1fb1f5sC@ 1fb"b1f5sC@ 1fb1fb"5q"= "q&"q&"5r3?	$ $      ? ? ?+DI+dh].BDDD&DI&e)<>>>	? ?r8   Tr   F)r   r   r   r   )rG   r   rJ   r   r   rP   r*   roundallrd   anyr   rS   rM   r.   r   )r3   rN   rf   r2   r[   rR   r   r5   rr   leftrighttopbottomr   r_   r   r   r0   r   r   r   r   s   `    ``       @@@@@@@@@r6   rounded_rectanglezImageDraw.rounded_rectangle  s    bedE]++ 	7!%hx&?!D!DHRhr22!(5/266NBB77:CS//!77:CS//!?.GQJ2YY2YY2YY2YY%w<< 	>"r'A+%F G"r'A+%F G >& >||Bgu===66W6 >>"dGU;;;QKKWd33X 	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?D L X	(("b1fqj"b1fqj)I8UVWWWWa!b1fqj((	(("q&1*b"q&1*b)I8UVWWW =& =BQ+1: %GGGq1u$GGG1: %GGGq1u$GGG	((x;;;aR,1: &!HHHA%HHH1: &!HHHA%HHH	((!<<<?sh5A::L 92r2:>21: $FFFa!eOFFF1: $FFFa!eOFFF	((c1555b5j1nb"51: '1IIIQ&III1: '1IIIQ&III	((a888 8BU
Q31: %GGGq1u$GGG1: %GGGq1u$GGG	((sA666eaR41: &!HHHA%HHH1: &!HHHA%HHH	((Q77777= ?::"8 8r8   textr   r   c                <    t          |t                    rdnd}||v S N
   
)rG   rH   )r3   r   split_characters      r6   _multiline_checkzImageDraw._multiline_check+  s%    ",T3"7"7B$$U$&&r8   list[AnyStr]c                Z    |                     t          |t                    rdnd          S r   )splitrG   rH   )r3   r   s     r6   _multiline_splitzImageDraw._multiline_split0  s'    zz*T3"7"7B$$UCCCr8   spacingstroke_widthc                L    |                      dd||          d         |z   |z   S )Nr   A)r   r   )textbbox)r3   r   r   r   s       r6   _multiline_spacingzImageDraw._multiline_spacing3  s5     MM&#t,MGGJ	
r8   rm   r   Ftuple[float, float]anchoralignrH   	directionfeatureslist[str] | Nonelanguagestroke_fillembedded_colorargsr   kwargsc                   	
 r j         dvrd}t          |          (                                         d                                                   r!                     |||	
||          S d fd	}dd	
 fd} ||          }|<d}|r| ||          n|}| |||            ||d
           dS  ||           dS dS )z
Draw text.r    r   3Embedded color supported only in RGB and RGBA modesNr?   r2   rC   r   rS   c                H                         |           \  }}||J |S |S rF   )rM   )r2   r0   r_   r3   s      r6   getinkzImageDraw.text.<locals>.getinko  s3     LL..MC{+++Jr8   r   r0   r   rP   r   c                   j         }|dk    rrd}g }t          d          D ]*}|                    t          |                              +t	          j        d                   d         t	          j        d                   d         f}	  j        |gR || |d\  }}|d         |d         z   |d         |d         z   g}nQ# t          $ rD 	  j        ||| gR d|i}n%# t          $ r                               }Y nw xY wY nw xY w|dk    r||
                    d          }}t          j        d|           d         }	|                    d|	           |\  }
}j        >j                            ||
||
|j        d         z   ||j        d         z   f|           d S d S j                            |||            d S )	Nr   r   ro   r   )r   r   r   r   r   r0   rO   rO   r   rq   )r1   r   appendrS   ru   modfgetmask2AttributeErrorgetmask	TypeErrorgetbandstructpackfillbandr   r   r   r.   rZ   )r0   r   r   rx   rq   rO   r   offsetcolor	ink_alphar   r   r   r   r   r   r   r   r   r   r3   r   rN   s               r6   	draw_textz!ImageDraw.text.<locals>.draw_textv  s   =Dq  ^ E1XX ) )SAZZ((((Yr!u%%a($)BqE*:*:1*=>E.,t}      (%%!-!       f qF1I-uQx&)/CD! . . ..'4<!  $    $ ! DD ! . . .<<--DDD.." v~~ #DLLOOt"KS11!4	q),,,17&GMM1a$)A,&6DIaL8HI4     '&
 	%%eT377777s6   ?C 
DC65D6DDDDD)r2   rC   r   rS   )r   )r0   rS   r   rP   r   r   )r   r*   rB   getr   multiline_text)r3   rN   r   r2   r   r   r   r   r   r   r   r   r   r   r   r   r5   r   r  r0   
stroke_inks   ``` ``  ```  ```     r6   r   zImageDraw.text?  s   0  	"di>>GCS//!<==K!8!899D  && 	&&   	 	 	 	 	 	4	8 4	8 4	8 4	8 4	8 4	8 4	8 4	8 4	8 4	8 4	8 4	8 4	8 4	8 4	8 4	8 4	8l fTll?J U4?4KVVK000QT
%	*l333 	#q!!!!! 	# ?r8   )r?   c                  |dk    rd}t          |          |d}n?t          |          dk    rd}t          |          |d         dv rd}t          |          ||                     |          }g }d	}|                     |          }|                     |||          }|D ]A}|                     ||||	|

          }|                    |           t          ||          }B|d         }|d         dk    r|t          |          dz
  |z  dz  z  }n$|d         dk    r|t          |          dz
  |z  z  }t          |          D ]\  }}|d	         }|||         z
  }|d	         dk    r	||dz  z  }n|d	         dk    r||z  }|dk    rn,|dk    r	||dz  z  }n|dk    r||z  }nd}t          |          | 	                    ||f||||||	|
|||           ||z  }d S )Nttb/ttb direction is unsupported for multiline textlaro   #anchor must be a 2 character stringr   tb'anchor not supported for multiline textr   )r   r   r   m       @r   r   r   centerr   )align must be "left", "center" or "right")r   r   r   r   r   r   )
r*   r   rB   r   r   
textlengthr   maxr   r   )r3   rN   r   r2   r   r   r   r   r   r   r   r   r   r   r?   r5   widths	max_widthlinesline_spacingr   
line_widthr   idxr   width_differences                             r6   r  zImageDraw.multiline_text  s   . CCS//!>FF[[A7CS//!AY$;CS//!<==++D	%%d++..tWlKK 	3 	3Ddi(X )  J MM*%%%Iz22IIe!9CJJNl2S88CCAY#CJJNl22C"5)) "	  "	 ICa5D(6#;6 ayC(3..c!!(( (""(3..'!!((A oo%IIs#!!)'-     <CCE"	  "	 r8   c                   |                      |          rd}t          |          |r| j        dvrd}t          |          ||                     |          }|rdn| j        }	|                    ||	|||          S )z@Get the length of a given string, in pixels with 1/64 precision.z&can't measure length of multiline textr   r   Nr   )r   r*   r   rB   r1   	getlength)
r3   r   r   r   r   r   r   r?   r5   r   s
             r6   r  zImageDraw.textlength  s    "   && 	":CS//! 	"di>>GCS//!<==++D':vvT]~~dD)XxHHHr8   !tuple[float, float, float, float]c                  |r| j         dvrd}t          |          ||                     |          }|                     |          r|                     |||||||||	|
|          S |rdn| j        }|                    |||||	|
|          }|d         |d         z   |d         |d         z   |d         |d         z   |d         |d         z   fS )	z2Get the bounding box of a given string, in pixels.r   r   Nr   r   r   ro   r   )r   r*   rB   r   multiline_textbboxr1   getbbox)r3   rN   r   r   r   r   r   r   r   r   r   r   r?   r5   r   bboxs                   r6   r   zImageDraw.textbbox5  s   ,  	"di>>GCS//!<==++D  && 	**   (:vvT]||$	8X|V
 
 AwAQ"Q%a2a5$q'BqE/QQr8   c                  |dk    rd}t          |          |d}n?t          |          dk    rd}t          |          |d         dv rd}t          |          ||                     |          }g }d	}|                     |          }|                     |||
          }|D ]B}|                     |||||	|
          }|                    |           t          ||          }C|d         }|d         dk    r|t          |          dz
  |z  dz  z  }n$|d         dk    r|t          |          dz
  |z  z  }d }t          |          D ]
\  }}|d	         }|||         z
  }|d	         dk    r	||dz  z  }n|d	         dk    r||z  }|dk    rn,|dk    r	||dz  z  }n|dk    r||z  }nd}t          |          | 	                    ||f||||||	|
|	  	        }||}nnt          |d	         |d	                   t          |d         |d                   t          |d         |d                   t          |d         |d                   f}||z  }||d	         |d         |d	         |d         fS |S )Nr	  r
  r  ro   r  r   r  r  r   )r   r   r   r   r  r  r   r   r   r  r   r  )r   r   r   r   r   r   )r*   r   rB   r   r   r  r   r  r   r   min)r3   rN   r   r   r   r   r   r   r   r   r   r   r?   r5   r  r  r  r  r   r  r   r"  r  r   r  	bbox_lines                             r6   r   zImageDraw.multiline_textbboxg  s   * CCS//!>FF[[A7CS//!AY$;CS//!<==++D	%%d++..tWlKK 
	3 
	3D#!!- )  J MM*%%%Iz22IIe!9CJJNl2S88CCAY#CJJNl22C9="5)) *	  *	 ICa5D(6#;6 ayC(3..c!!(( (""(3..'!!((A oo%s#!!)- & 
 
I |  Q1..Q1..Q1..Q1..	 <CC<a5"Q%A1--r8   rF   )r   r   r   r   r   r   )r   r9   )r?   r@   r   r9   )r0   rC   r2   rC   r   rD   )Nr   )rN   r   rO   rP   rQ   rP   r2   rC   rR   rS   r   r   )rN   rW   rX   r   r2   rC   r   r   )NNr   )rN   r   rO   rP   rQ   rP   r2   rC   r[   rC   rR   rS   r   r   )
rN   r   r2   rC   r[   rC   rR   rS   r   r   )rN   re   rf   rP   r2   rC   r[   rC   rR   rS   r   r   )Nr   N)
rN   r   r2   rC   rR   rS   rj   r   r   r   NN)r   r   r2   rC   r[   rC   r   r   )rN   r   r2   rC   r   r   )r   NNr   )r   r   r   rS   r   rP   r2   rC   r[   rC   rR   rS   r   r   )rN   r   rf   rP   r2   rC   r[   rC   rR   rS   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r9   r   rP   r   rP   r   rP   )NNNrm   r   NNNr   NF) rN   r   r   r   r2   rC   r   r   r   r   r   rP   r   rH   r   r   r   r   r   r   r   rP   r   rC   r   r   r   r   r   r   r   r   )rN   r   r   r   r2   rC   r   r   r   r   r   rP   r   rH   r   r   r   r   r   r   r   rP   r   rC   r   r   r?   r@   r   r   )NNNNF)r   r   r   r   r   r   r   r   r   r   r   r   r?   r@   r   rP   )	NNrm   r   NNNr   F)rN   r   r   r   r   r   r   r   r   rP   r   rH   r   r   r   r   r   r   r   rP   r   r   r?   r@   r   r  )__name__
__module____qualname__r   __annotations__r7   r>   rB   rM   rV   rX   r`   rd   ri   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r   r8   r6   r   r   @   s;         	 	    ( ( ( ( (T   6" " " " 59' ' ' ' '< !; ; ; ; ; KO	6 	6 	6 	6 	6  !#@ @ @ @ @& !#6 6 6 6 6$ !#
7 
7 
7 
7 
7 ! K= K= K= K= K=` !#	2 2 2 2 2& !#C C C C C + + + + + !#"@ "@ "@ "@ "@P  #/ / / / /  !#8 8 8 8 8"  #J8 9=J8 J8 J8 J8 J8 J8X' ' ' '
D D D D

 

 

 

  ! ! $%)##'$'{ { { { {B ! ! $%)##'$'Z * #'+Z  Z  Z  Z  Z  Z H  $%)#$I #'I I I I I IL ! $%)#$#0R& #''0R 0R 0R 0R 0R 0Rv ! $%)#$#k& #''k k k k k k k kr8   r   r   r   r   r   r   c                v    	  t          | d          |          S # t          $ r t          | |          cY S w xY w)a  
    A simple 2D drawing interface for PIL images.

    :param im: The image to draw in.
    :param mode: Optional mode to use for color values.  For RGB
       images, this argument can be RGB or RGBA (to blend the
       drawing into the image).  For all other modes, this argument
       must be the same as the image mode.  If omitted, the mode
       defaults to the mode of the image.
    getdraw)getattrr   r   )r   r   s     r6   r   r     sR    #%wr9%%d+++ # # #T"""""#s    88Image.Image | Nonehintsr   )tuple[ImageDraw2.Draw | None, ModuleType]c                b    |t          dd           ddlm} |  |j        |           nd}||fS )z
    :param im: The image to draw in.
    :param hints: An optional list of hints. Deprecated.
    :returns: A (drawing context, drawing resource factory) tuple.
    Nz'hints' parameter   r   )r   )r   r<   r   r   )r   r/  r   r.   s       r6   r,  r,    sR     %r***"$.?:?2dDr8   imagerN   tuple[int, int]valuefloat | tuple[int, ...]borderfloat | tuple[int, ...] | NonethreshrP   r   c                z   |                                  }|J |\  }}	 |||f         }t          ||          |k    rdS ||||f<   n# t          t          f$ r Y dS w xY w||fh}	t	                      }
|	rt	                      }|	D ]\  }}|dz   |f|dz
  |f||dz   f||dz
  ffD ]\  }}||f|
v s|dk     s|dk     r	 |||f         }|
                    ||f           |t          ||          |k    }n|||fv}|r||||f<   |                    ||f           x# t          t          f$ r Y w xY w|	}
|}	|	dS dS )a  
    .. warning:: This method is experimental.

    Fills a bounded region with a given color.

    :param image: Target image.
    :param xy: Seed position (a 2-item coordinate tuple). See
        :ref:`coordinate-system`.
    :param value: Fill color.
    :param border: Optional border value.  If given, the region consists of
        pixels with a color different from the border color.  If not given,
        the region consists of pixels having the same color as the seed
        pixel.
    :param thresh: Optional threshold value which specifies a maximum
        tolerable difference of a pixel value from the 'background' in
        order for it to be replaced. Useful for filling regions of
        non-homogeneous, but similar, colors.
    Nr   r   )r'   _color_diffr*   
IndexErrorsetadd)r3  rN   r5  r7  r9  pixelr   r   
backgroundedge	full_edgenew_edgestr   r2   s                   r6   	floodfillrF    s   6 JJLLEDAq1a4[
uj))V33Fad
#   F8D I
 55 	- 	-DAqa%a!eQZ!QUaQZH - -1q6Y&&!a%%1q55-adA MM1a&)))~*1j99VC 7 -&+ad aV,,, #J/   D-" 	+      s(   A A AA<
DD/.D/r   r   r   rS   r   list[tuple[float, float]]c                  	 t          |t                    sd}t          |          |dk     rd}t          |          t          | t          t
          f          sd}t          |          t          |           dk    r\t          d | D                       sd}t          |          t          t          t                   t	          |                     ^ 	nt          |           dk    rt          | d         t          t
          f          rt          d	 | d         D                       r"t          | d
         t          t          f          sd}t          |          t          | d                   dk    rd}t          |          t          t          t                   t	          | d                             t          t          | d
                   	nd}t          |          	dk    rd}t          |          t          |t          t          f          sd}t          |          dfdd	fddd} |||          }fd|D             S ) u  
    Generate a list of vertices for a 2D regular polygon.

    :param bounding_circle: The bounding circle is a sequence defined
        by a point and radius. The polygon is inscribed in this circle.
        (e.g. ``bounding_circle=(x, y, r)`` or ``((x, y), r)``)
    :param n_sides: Number of sides
        (e.g. ``n_sides=3`` for a triangle, ``6`` for a hexagon)
    :param rotation: Apply an arbitrary rotation to the polygon
        (e.g. ``rotation=90``, applies a 90 degree rotation)
    :return: List of regular polygon vertices
        (e.g. ``[(25, 50), (50, 50), (50, 25), (25, 25)]``)

    How are the vertices computed?
    1. Compute the following variables
        - theta: Angle between the apothem & the nearest polygon vertex
        - side_length: Length of each polygon edge
        - centroid: Center of bounding circle (1st, 2nd elements of bounding_circle)
        - polygon_radius: Polygon radius (last element of bounding_circle)
        - angles: Location of each polygon vertex in polar grid
            (e.g. A square with 0 degree rotation => [225.0, 315.0, 45.0, 135.0])

    2. For each angle in angles, get the polygon vertex at that angle
        The vertex is computed using the equation below.
            X= xcos(φ) + ysin(φ)
            Y= −xsin(φ) + ycos(φ)

        Note:
            φ = angle in degrees
            x = 0
            y = polygon_radius

        The formula above assumes rotation around the origin.
        In our case, we are rotating around the centroid.
        To account for this, we use the formula below
            X = xcos(φ) + ysin(φ) + centroid_x
            Y = −xsin(φ) + ycos(φ) + centroid_y
    zn_sides should be an intr   zn_sides should be an int > 2z$bounding_circle should be a sequencec              3  N   K   | ] }t          |t          t          f          V  !d S rF   rG   rS   rP   rp   rq   s     r6   r   z4_compute_regular_polygon_vertices.<locals>.<genexpr>o  s0      HH1:a#u..HHHHHHr8   z0bounding_circle should only contain numeric dataro   r   c              3  N   K   | ] }t          |t          t          f          V  !d S rF   rJ  rK  s     r6   r   z4_compute_regular_polygon_vertices.<locals>.<genexpr>u  sA       
 
,-Jq3,''
 
 
 
 
 
r8   r   zBbounding_circle centre should contain 2D coordinates (e.g. (x, y))z[bounding_circle should contain 2D coordinates and a radius (e.g. (x, y, r) or ((x, y), r) )z$bounding_circle radius should be > 0z"rotation should be an int or floatr   list[float]rv   rP   r   r   c                   t          | d         t          j        t          j        d|z
                      z  | d         t          j        t          j        d|z
                      z  z
  d         z   d          t          | d         t          j        t          j        d|z
                      z  | d         t          j        t          j        d|z
                      z  z   d         z   d          fS )Nr   rt   r   ro   )r   ru   r   r   r   )r   rv   centroids     r6   _apply_rotationz:_compute_regular_polygon_vertices.<locals>._apply_rotation  s    a48DLw$?$?@@@(TXdl3=&A&ABBBC1+ 	  a48DLw$?$?@@@(TXdl3=&A&ABBBC1+ 	 
 	
r8   ry   c                $    dg} ||           S Nr   r   )ry   start_pointrP  polygon_radiuss     r6   _compute_polygon_vertexzB_compute_regular_polygon_vertices.<locals>._compute_polygon_vertex  s    %q){E222r8   r   rS   r   c                    g }d| z  }dd|z  z
  |z   }t          d|           D ]'}|                    |           ||z  }|dk    r|dz  }(|S )Nrt   r   g      ?r   )r   r   )r   r   r   rv   current_angle_s         r6   _get_anglesz6_compute_regular_polygon_vertices.<locals>._get_angles  ss    -sW},8q'"" 	% 	%AMM-(((W$Ms""$r8   c                &    g | ]} |          S r   r   )rp   ry   rU  s     r6   rr   z5_compute_regular_polygon_vertices.<locals>.<listcomp>  s%    ???u##E**???r8   )r   rM  rv   rP   r   r   )ry   rP   r   r   )r   rS   r   rP   r   rM  )
rG   rS   r   r*   r   rJ   r   r   r   rP   )
r   r   r   r5   rY  r   rP  rU  rO  rT  s
         @@@@r6   r   r   7  s   V gs## (nn{{,oo oe}55 4nn
?q  HHHHHHH 	"DCS//!$(ed?6K6K$L$L!>>	_			"	"z/!2DtUm'T'T	" 
 
1@1C
 
 
 
 
 	"OA.e==	" ECS//!q!""a''VCS//!UT/!*<%=%=>>e_Q%788< 	 oo4oo he-- 2oo
 
 
 
 
 
 3 3 3 3 3 3 3
 
 
 
 [(++F @???????r8   color1color2c           	         t          | t                    r| n| ft          |t                    r|n|ft          fdt          dt	                              D                       S )zJ
    Uses 1-norm distance to calculate difference between two values.
    c              3  T   K   | ]"}t          |         |         z
            V  #d S rF   )abs)rp   rq   firstseconds     r6   r   z_color_diff.<locals>.<genexpr>  s8      HHQs58fQi'((HHHHHHr8   r   )rG   rJ   sumr   r   )r[  r\  r`  ra  s     @@r6   r;  r;    sp     !//>FFfYE!&%00?VVviFHHHHH%3v;;2G2GHHHHHHr8   rF   )r   r   r   r   r   r   r&  )r   r.  r/  r   r   r0  rR  )r3  r   rN   r4  r5  r6  r7  r8  r9  rP   r   r   )r   r   r   rS   r   rP   r   rG  )r[  r6  r\  r6  r   rP   )(
__future__r   ru   r   collections.abcr   typesr   typingr   r   r   r	   r
   r   r<   r   r   
_deprecater   _typingr   r*  r-   r[   r   r   r   r   rP   rJ   rS   rH   _Inkr   r   r,  rF  r   r;  r   r8   r6   <module>rj     s  @ # " " " " " "   $ $ $ $ $ $       D D D D D D D D D D D D D D D D         ! ! ! ! ! !       2 1 1 1j GG   GGG  (''''''''UE#s(OS()R R R R R R R Rj# # # # #$ >B    ( .2> > > > >B@ @ @ @D	I 	I 	I 	I 	I 	Is   A AA