+
     i]  c                  sh  a  0 t $ ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
HtHtHtHt ^RIHtHt ^RIHt ^RIHt ]P,                  P.                  tR	]R
&   Rt]'       d	   ^RIHtHt ]]]]R3,          ] 3,          t!  ! R R4      t"RR R llt#RR R llt$RR R llt%R R lt&R R lt'R# )    )annotationsN)Sequence)
ModuleType)AnyAnyStrCallableUnioncast)Image
ImageColor)	deprecate)Coordsz!Callable[[], Image.core._Outline]OutlineF)
ImageDraw2	ImageFont.c                  s   ] tR t^=t$ RtR]R&   R7R R lltR R ltR R	 ltR7R
 R llt	R8R R llt
R7R R lltR9R R lltR9R R lltR9R R lltR:R R lltR;R R lltR9R R lltR7R R lltR9R R lltR<R  R! lltR9R" R# lltR<R$R/R% R& llltR' R( ltR=R) R* lltR+ R, ltR=R-R/R. R/ llltR>R-R/R0 R1 llltR?R-R/R2 R3 llltR?R-R/R4 R5 llltR6tR# )@	ImageDrawNNImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont | Nonefontc               $    V ^8  d   QhRRRRRR/# )   imImage.Imagemode
str | NonereturnNone Zformat   "4/usr/lib64/python3.14/site-packages/PIL/ImageDraw.py__annotate__ImageDraw.__annotate__B   s!     ( (; (j (D (    c                s   VP                  4        VP                  '       d   VP                  4        ^ pVf   VP                  pW!P                  8w  d)   VR8X  d   VP                  R8X  d   ^pMRp\	        V4      hVR8X  d   VP
                  V n        MRV n        Wn        VP                  V n        \        P                  P                  V P                  V4      V n
        W n        VR	9   d"   V P                  P                  ^4      V n        M V P                  P                  R
4      V n        VR9   d	   RV n        MRV n        RV n        R# )aX  
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.
NRGBARGBzmode mismatchP1ZLF)IFi)r%   r$   r&   r'   )loadZreadonlyZ_copyr   
ValueErrorpalette_imager   r	   coredrawdraw_inkinkfontmodefill)selfr   r   Zblendmsg   &&&  r   __init__ZImageDraw.__init__B   s     		;;;HHJ<77D77?v~"''U"2% o%3;::DLDL%%JJOODGGU3		:yy))!,DHyy))"-DH''DMDM	r!   c               s    V ^8  d   QhRR/# )r   r   GImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFontr   r   r   r   r   r    l   s      	Pr!   c                sv    V P                   '       g   ^RIHp VP                  ! 4       V n         V P                   # )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   load_default)r2   r      & r   getfontZImageDraw.getfontl   s*    ( yyy#!..0DIyyr!   c                    V ^8  d   QhRRRR/# )r   	font_sizefloat | Noner   r6   r   r   r   r   r   r       s     " "%"	P"r!   c                	sZ    Ve   ^RI Hp VP                  ! V4      # V P                  4       # )Nr7   )r8   r   r9   r;   )r2   r=   r      && r   _getfontZImageDraw._getfont   s*      #)))44<<>!r!   c               $    V ^8  d   QhRRRRRR/# )r   r/   _Ink | Noner1   r   ztuple[int | None, int | None]r   r   r   r   r   r       s$     ' ''&1'	&'r!   c                	s
   R pR pVf6   Vf2   V P                   '       d   V P                  pW43# V P                  p W43# Ve   \        V\        4      '       d!   \        P
                  ! WP                  4      pV P                  '       d<   \        V\        4      '       d&   V P                  P                  WP                  4      pV P                  P                  V4      pVe   \        V\        4      '       d!   \        P
                  ! W P                  4      pV P                  '       d<   \        V\        4      '       d&   V P                  P                  W P                  4      pV P                  P                  V4      pW43# N)r1   r/   
isinstancestrr
   Zgetcolorr   r*   tupler+   r-   r.   )r2   r/   r1   Z
result_inkZresult_fillr4   r   _getinkZImageDraw._getink   s$    
;4<yyy"hh  && "XX
 && c3''$--c99=C<<<JsE$:$:,,//[[AC!YY//4
dC((%..tYY?D<<<JtU$;$;<<00{{CD"ii006&&r!   c               s0    V ^8  d   QhRRRRRRRRRR	R
R/# )r   xyr   startfloatendr1   rB   widthintr   r   r   r   r   r   r   r       sF     ; ;; ; 	;
 ; ; 
;r!   c                sr    V P                  V4      w  rdVe    V P                  P                  WW6V4       R# R# )zDraw an arc.N)rG   r-   draw_arc)r2   rH   rI   rK   r1   rL   r/      &&&&&& r   arcZImageDraw.arc   s4     LL&	?IIr#E: r!   c               (    V ^8  d   QhRRRRRRRR/# )	r   rH   zSequence[int]bitmapr   r1   rB   r   r   r   r   r   r   r   r       s,     	6 	6	6)4	6<G	6		6r!   c                s    VP                  4        V P                  V4      w  rCVf   TpVe)   V P                  P                  WP                  V4       R# R# )zDraw a bitmap.N)r(   rG   r-   draw_bitmapr   )r2   rH   rR   r1   r/   s   &&&& r   rR   ZImageDraw.bitmap   sI     	LL&	;C?II!!"ii5 r!   c               4    V ^8  d   QhRRRRRRRRRRR	R
RR/# r   rH   r   rI   rJ   rK   r1   rB   outlinerL   rM   r   r   r   r   r   r   r   r       sY     @ @@ @ 	@
 @ @ @ 
@r!   c                    V P                  WT4      w  rxVe   V P                  P                  WW8^4       Ve2   Wx8w  d*   V^ 8w  d!   V P                  P                  WW7^ V4       R# R# R# R# )zDraw a chord.N)rG   r-   Z
draw_chord	r2   rH   rI   rK   r1   rV   rL   r/   fill_ink	   &&&&&&&  r   chordZImageDraw.chord   s`     W3II  C1=?s5A:II  Ca? 4>?r!   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# 
r   rH   r   r1   rB   rV   rL   rM   r   r   r   r   r   r   r   r       s<     6 66 6 	6
 6 
6r!   c                    V P                  W24      w  rVVe   V P                  P                  W^4       Ve1   WV8w  d)   V^ 8w  d    V P                  P                  W^ V4       R# R# R# R# )zDraw an ellipse.N)rG   r-   Zdraw_ellipser2   rH   r1   rV   rL   r/   rY      &&&&&  r   ellipseZImageDraw.ellipse   s\     W3II""23?s5A:II""2Au5 4>?r!   c               s0    V ^8  d   QhRRRRRRRRRR	R
R/# )r   rH   Sequence[float]radiusrJ   r1   rB   rV   rL   rM   r   r   r   r   r   r   r   r       sF     
7 
7
7 
7 	
7
 
7 
7 

7r!   c                s    V^ ,          V,
          V^,          V,
          V^ ,          V,           V^,          V,           3pV P                  WcWE4       R# )z4Draw a circle given center coordinates and a radius.N)ra   )r2   rH   rc   r1   rV   rL   Z
ellipse_xyrO   r   circleZImageDraw.circle   s@     efnbefnbefnbefnU
Zw6r!   c          
     s,    V ^8  d   QhRRRRRRRRR	R
/# )r   rH   r   r1   rB   rL   rM   jointr   r   r   r   r   r   r   r   r       sC     K= K=K= K= 	K=
 K= 
K=r!   c                sL  a V P                  V4      ^ ,          pVEe{   V P                  P                  WS4       VR8X  EdU   S^8  EdK   \        V^ ,          \        \
        34      '       d(   \        \        \        \        ,          ,          V4      pMP\        ^ \        V4      ^4       Uu. uF0  p\        \        \        ,          \        WV^,            4      4      NK2  	  pp\        ^\        V4      ^,
          4       EF  pWg,          pWg^,
          ,          V3WV^,           ,          33 U	U
u. uFa  w  r\        P                  ! \        P                  ! V
^ ,          V	^ ,          ,
          V	^,          V
^,          ,
          4      4      R,          NKc  	  pp	p
V^ ,          V^,          8X  d   K  R V3R llpV^,          V^ ,          8  ;'       d#    V^,          ^,
          V^ ,          8  ;'       g6    V^,          V^ ,          8  ;'       d    V^,          ^,           V^ ,          8  pV^ ,          S^,          ,
          ^,           V^,          S^,          ,
          ^,           3V^ ,          S^,          ,           ^,
          V^,          S^,          ,           ^,
          3.pV'       d!   V^,          ^Z,           V^ ,          ^Z,           rMV^ ,          ^Z,
          V^,          ^Z,
          rV P                  W^Z,
          V
^Z,
          V4       S^8  g   EK  V'       d/   V! W^ ,          ^Z,           4      VV! W^,          ^Z,           4      .pM-V! W^ ,          ^Z,
          4      VV! W^,          ^Z,
          4      .pV P                  W^R7       EK  	  R# R# R# R# u upi u up
p	i )z6Draw a line, or a connected sequence of line segments.NZcurveh  c               r   )r   coordrb   anglerJ   r   ztuple[float, ...]r   r   r   r   r   Z$ImageDraw.line.<locals>.__annotate__  s$      .7<*r!   c                s  < V w  r#V^Z,          pS^,          ^,
          p\         ;QJ dv    . R W$\        P                  ! \        P                  ! V4      4      ,          3W4\        P                  ! \        P                  ! V4      4      ,          33 4       F  NK  	  5# ! R W$\        P                  ! \        P                  ! V4      4      ,          3W4\        P                  ! \        P                  ! V4      4      ,          33 4       4      # )iZ   c              3  s   "   T F@  w  rY^ 8  d   \         P                  ! V4      M\         P                  ! V4      ,           x  KB  	  R# 5i)r    N)mathZfloorZceil).0pZp_ds   &  r   	<genexpr>Z9ImageDraw.line.<locals>.coord_at_angle.<locals>.<genexpr>  s;      %+ !GC3PP+s   AA
)rF   ri   cosradianssin)rg   rh   xyZdistancerL   s   &&   r   coord_at_angleZ&ImageDraw.line.<locals>.coord_at_angle  s      %#(19q=$u % "#txxU8K/L$L M!"txxU8K/L$L M+%u u % "#txxU8K/L$L M!"txxU8K/L$L M+%   r!   )rL   )rG   r-   Z
draw_linesrD   listrF   r   r   rJ   rangelenri   degreesZatan2piesliceline)r2   rH   r1   rL   re   r/   ZpointsipointrI   rK   anglesrr   ZflippedZcoordsZ
gap_coordss   &&&f&           r   rx   ZImageDraw.line   s    ll4 #?II  %0EAIbedE]33!(8E?";R@F "'q#b'1!5!5A Xe_eB1q5M.BC!5   q#f+/2A"IE
 $E]E2"1q5M2++JE TZZAq0A58cRSfCT%UV +   ayF1I-   q	F1I-MM&)c/F1I2MQ Q )fQi/OOF1IOfQi4O  qEAI-158eai3G!3KLqEAI-158eai3G!3KLF &,Qi"nfQi"ns&,Qi"nfQi"nsMM&"*cBhEqy" .uQi"n E % .uQi"n E*J !/uQi"n E % .uQi"n E*J
 		*!	<o 3 %. s   -6N2A'N c               s(    V ^8  d   QhRRRRRRRR/# )r   shapezImage.core._Outliner1   rB   rV   r   r   r   r   r   r   r   r    9  s2     2 2"2 2 	2
 
2r!   c                s    VP                  4        V P                  W24      w  rEVe   V P                  P                  W^4       Ve'   WE8w  d   V P                  P                  W^ 4       R# R# R# )z(Experimental) Draw a shape.N)ZcloserG   r-   Zdraw_outline)r2   r|   r1   rV   r/   rY   s   &&&&  r   r|   ZImageDraw.shape9  s[     	W3II""5A6?sII""5q1  /?r!   c               rT   rU   r   r   r   r   r   r    G  sY     C CC C 	C
 C C C 
Cr!   c                rW   )zDraw a pieslice.N)rG   r-   draw_pieslicerX   rZ   r   rw   ZImageDraw.piesliceG  s`     W3II##Bsa@?s5A:II##BsEB 4>?r!   c               r   )r   rH   r   r1   rB   r   r   r   r   r   r   r   r    W  s!     + + +k +T +r!   c                sn    V P                  V4      w  r2Ve   V P                  P                  W4       R# R# )z#Draw one or more individual pixels.N)rG   r-   Zdraw_points)r2   rH   r1   r/   s   &&& r   rz   ZImageDraw.pointW  s.    LL&	?II!!"* r!   c          
     r\   r]   r   r   r   r   r   r    ]  sC     K KK K 	K
 K 
Kr!   c                sF   V P                  W24      w  rVVe   V P                  P                  W^4       Ve   WV8w  d   V^ 8w  d   V^8X  d    V P                  P                  W^ V4       R# V P                  e   \        P
                  ! RV P                  P                  4      pV P                  ^4      ^ ,          p\        V4      p	V	P                  P                  W^4       V P                  P                  W^ V^,          ^,
          VP                  4       R# R# R# R# R# )zDraw a polygon.Nr%   )rG   r-   Zdraw_polygonr   r	   ZnewsizeDraw)
r2   rH   r1   rV   rL   r/   rY   maskZmask_inkr-   s
   &&&&&     r   polygonZImageDraw.polygon]  s     W3II""23?s5A:z		&&r59$ yydggll3<<?1-Dz		&&rQ7		&&r519q=$''J % 4>?r!   c               s4    V ^8  d   QhRRRRRRRRR	RR
RRR/# )r   bounding_circle!Sequence[Sequence[float] | float]n_sidesrM   rotationrJ   r1   rB   rV   rL   r   r   r   r   r   r   r   r    u  sP     / /:/ / 	/
 / / / 
/r!   c                sB    \        WV4      pV P                  WtWV4       R# )zDraw a regular polygon.N)!_compute_regular_polygon_verticesr   )r2   r   r   r   r1   rV   rL   rH   s   &&&&&&& r   regular_polygonZImageDraw.regular_polygonu  s     /RRw.r!   c          
     r\   r]   r   r   r   r   r   r      s<     8 88 8 	8
 8 
8r!   c                r^   )zDraw a rectangle.N)rG   r-   draw_rectangler_   r`   r   	rectangleZImageDraw.rectangle  s\     W3II$$R15?s5A:II$$Ra7 4>?r!   cornersc               s4    V ^8  d   QhRRRRRRRRRR	R
RRR/# )r   rH   r   rc   rJ   r1   rB   rV   rL   rM   r   z$tuple[bool, bool, bool, bool] | Noner   r   r   r   r   r   r   r      sY     J8 J8J8 J8 	J8
 J8 J8 6J8 
J8r!   c               s  a aaaaaaaaaaa \        V^ ,          \        \        34      '       d1   \        \        \        \
        ,          ,          V4      w  w  oow  ooM \        \        \
        ,          V4      w  ooooSS8  d   Rp\        V4      hSS8  d   Rp\        V4      hSf   RoV^,          o\        S4      o\        S4      o\        S4      o\        S4      oRRuoo\        S4      '       dl   SSS,
          ^,
          8  oS'       d
   SS,
          oSSS,
          ^,
          8  oS'       d
   SS,
          oS'       d   S'       d   S P                  WVS4      # S^ 8X  g   \        S4      '       g   S P                  WVS4      # \        S^,          4      pS P                  WC4      w  ooR VVVVVVV VVVVV3R llp	SEe   V	! R4       S'       d?   S P                  P                  SSV,           ^,           SSV,
          ^,
          3S^4       M`SV,
          ^,
          SV,           ^,           8  d>   S P                  P                  SV,           ^,           SSV,
          ^,
          S3S^4       S'       Eg
   S'       Eg   SSSV,           S.p
S^ ,          '       d   V
^;;,          V^,           ,          uu&   S^,          '       d   V
^;;,          V^,           ,          uu&   S P                  P                  V
S^4       SV,
          SSS.pS^,          '       d   V^;;,          V^,           ,          uu&   S^,          '       d   V^;;,          V^,           ,          uu&   S P                  P                  VS^4       SEeO   SS8w  EdE   S^ 8w  Ed;   V	! R4       S'       Eg   SSSSS,           ^,
          .pS^ ,          '       d   V^ ;;,          V^,           ,          uu&   S^,          '       d   V^;;,          V^,           ,          uu&   S P                  P                  VS^4       SSS,
          ^,           SS.pS^,          '       d   V^ ;;,          V^,           ,          uu&   S^,          '       d   V^;;,          V^,           ,          uu&   S P                  P                  VS^4       S'       Eg   SSSS,           ^,
          S.p
S^ ,          '       d   V
^;;,          V^,           ,          uu&   S^,          '       d   V
^;;,          V^,           ,          uu&   S P                  P                  V
S^4       SS,
          ^,           SSS.pS^,          '       d   V^;;,          V^,           ,          uu&   S^,          '       d   V^;;,          V^,           ,          uu&   S P                  P                  VS^4       R# R# R# R# R# )	zDraw a rounded rectangle.z&x1 must be greater than or equal to x0z&y1 must be greater than or equal to y0NTFc               r<   )r   rw   boolr   r   r   r   r   r   r   Z1ImageDraw.rounded_rectangle.<locals>.__annotate__  s      	?  	?4  	?D  	?r!   c                s  < S'       d1   SSSS,           SS,           3^R3SSS,
          SS,           S3^ ^33pEM+S'       d0   SSSS,           SS,           3^ZR3SS,
          SSSS,           3R^Z33pM\         ;QJ dx    . V3R l\        SSSS,           SS,           3^R3SS,
          SSSS,           3RR3SS,
          SS,
          SS3^ ^Z3SSS,
          SS,           S3^Z^334       4       F  NK  	  5Mq! V3R l\        SSSS,           SS,           3^R3SS,
          SSSS,           3RR3SS,
          SS,
          SS3^ ^Z3SSS,
          SS,           S3^Z^334       4       4      pV FS  pV '       d&   S	P                  P                  ! VS^3,           !   K0  S	P                  P                  ! VSS
3,           !   KU  	  R# )i   rf     c              3  sN   <"   T F  w  rSV,          '       g   K  Vx  K  	  R # 5irC   r   )rj   ry   partr      &  r   rl   ZDImageDraw.rounded_rectangle.<locals>.draw_corners.<locals>.<genexpr>  s+      $ qzz D$s   %
%N)rF   	enumerater-   r}   rN   )rw   partsr   r   drY   full_xfull_yr/   r2   rL   x0x1y0y1s   &  r   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?	$ #, "b1fb1f5sC@ 1fb"b1f5sC@ 1fb1fb"5q"= "q&"q&"5r3?	$  II++dh].BDII&&e)<>	 r!   )TTTT)rD   rs   rF   r   r   rJ   r)   roundallra   Zanyr   rM   rG   r-   r   )r2   rH   rc   r1   rV   rL   r   r3   rr   leftrighttopZbottomr   rY   r   r   r/   r   r   r   r   s   f&&&&fd       @@@@@@@@@r   rounded_rectangleZImageDraw.rounded_rectangle  sz    bedE]++!%hx&?!DHRhr2!(5/26NBB7:CS/!7:CS/!?.GQJ2Y2Y2Y2Yw<<"r'A+%FG"r'A+%FG&||Bgu==6W >>"GU;;QKW3X 	?  	?  	?D 		(("b1fqj"b1fqj)I8UVWa!b1fqj(		(("q&1*b"q&1*b)I8UVW6&&BQ+1::Gq1u$G1::Gq1u$G		((x;aR,1::!HA%H1::!HA%H		((!<?sh5A:62r2:>21::Fa!eOF1::Fa!eOF		((c15b5j1nb"51::1IQ&I1::1IQ&I		((a86BU
Q31::Gq1u$G1::Gq1u$G		((sA6eaR41::!HA%H1::!HA%H		((Q7 # 4>?r!   c               r<   )r   textr   r   r   r   r   r   r   r   r      s     ' 'V ' 'r!   c                	s>    \        V\        4      '       d   R MRpW!9   # )
   
)rD   rE   )r2   r   Zsplit_characterr?   r   _multiline_checkZImageDraw._multiline_check  s    ",T3"7"7$U&&r!   c                sX    V ^8  d   Qh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RRRRRRR/# )r   rH   tuple[float, float]r   r   r1   rB   r   r   anchorr   spacingrJ   alignrE   	directionfeatureslist[str] | Nonelanguagestroke_widthstroke_fillembedded_colorr   argsr   kwargsr   r   r   r   r   r   r   r    !  s     } }} } 	}} } } } } #}  !}" #}$ !%}& '}( )}* +}, 
-}r!   c                s  a aaaaaa	a
aaa S'       d   S P                   R9  d   Rp\        V4      hSf!   S P                  SP                  R4      4      oS P	                  S4      '       d   S P                  SSVSSVVSS	S
VVS4      # R V 3R llpR	R VVVVV	VVV
V VV3R lllpV! V4      pVeC   RpV'       d   Ve	   V! V4      MTpVe   V! VV4       VV8w  d   V! V4       R# R# V! V4       R# R# )
z
Draw text.3Embedded color supported only in RGB and RGBA modesNr=   c               r<   )r   r1   rB   r   rM   r   r   r   r   r   $ImageDraw.text.<locals>.__annotate__Q  s     	 	 	 	r!   c                s:   < SP                  V 4      w  rVf   V# V# rC   )rG   )r1   r/   rY   r2   r   r   getinkZImageDraw.text.<locals>.getinkQ  s"     LL.MC{Jr!   c               r   )r   r/   rM   r   rJ   r   r   r   r   r   r   r   r   X  s!     5	8 5	83 5	8e 5	8D 5	8r!   c                s&  < SP                   pV^ 8X  d   S'       d   Rp. p\        ^4       F$  pVP                  \        SV,          4      4       K&  	  \        P
                  ! S^ ,          4      ^ ,          \        P
                  ! S^,          4      ^ ,          3p SP                  ! SV.SO5RSRSRSRVRRRSR	V R
V/SB w  rgV^ ,          V^ ,          ,           V^,          V^,          ,           .pTR8X  d   YfP                  ^4      rh\        P                  ! RT 4      ^,          p	TP                  ^T	4       Tw  rSP                  eQ   SP                  P                  YYTP                   ^ ,          ,           YP                   ^,          ,           3T4       R# R# SP"                  P%                  Y6T 4       R#   \         dH     SP                  ! STSSSTST .SO5R
T/SB p L  \         d    SP                  S4      p  ELi ; ii ; i)r    r"   r   r   r   r   Zstroke_filledTr   r/   rI   ry   N)r0   rt   appendrM   ri   ZmodfZgetmask2AttributeErrorZgetmask	TypeErrorZgetbandstructZpackZfillbandr   Zpaster~   r-   rS   )r/   r   r   rg   ry   rI   r   ZoffsetZcolorZ	ink_alpharp   rq   r   r   r   r   r   r   r   r   r2   r   rH   s   &&          r   	draw_textZ!ImageDraw.text.<locals>.draw_textX  s)   ==Dq ^E1XSAZ( YYr!u%a($))BqE*:1*=>E .#}}    (  &	 
 &  ".  #'  "         qF1I-uQx&)/CD$ v~ #LLOt"KKS1!4	q),77&GGMM1$))A,&6IIaL8HI4 '
 		%%e37; " ..<<!  $  $ !D ! .<<-D..s+   AF> >H
G++HHHHr#   r"   r    )r   r)   r@   Zgetr   multiline_text)r2   rH   r   r1   r   r   r   r   r   r   r   r   r   r   r   r   r3   r   r   r/   Z
stroke_inks   fff&ff&&fff&&fjl     r   r   ZImageDraw.text!  s   0 dii>GCS/!<==K!89D  &&&&  	 	5	8 5	8 5	8n Tl?J4?4KVK0QT
%*l3 *$cN % # r!   c               L    V ^8  d   Qh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R/# )r   rH   r   r   r   r   r   r   r   r   rJ   r   rE   r   r   r   r   r   r   r   r=   r>   r   z}tuple[ImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont, list[tuple[tuple[float, float], str, AnyStr]]]r   r   r   r   r   r      s     | || |
| | | | | #| |  !|" #|$  %|&
'|r!   c                	sf   Vf   VR8X  d   RMRpM?\        V4      ^8w  d   Rp\        V4      hV^,          R9   d   VR8w  d   Rp\        V4      hVf   V P                  V4      pTP                  \	        V\
        4      '       d   RMR4      pV P                  RR	W:R
7      ^,          V
,           V,           pV^,          p. pVR8X  d6   V^ ,          pV F"  pVP                  VV3VV34       VV,          pK$  	  VV3# . p^ pV F7  pV P                  VVVVV	VR7      pVP                  V4       \        VV4      pK9  	  V^,          R8X  d)   V\        V4      ^,
          V,          R,          ,          pM.V^,          R8X  d!   V\        V4      ^,
          V,          ,          p\        V4       EF  w  ppV^ ,          pVVV,          ,
          pVR9   d   M6VR8X  d   VVR,          ,          pMVR8X  d   VV,          pMRp\        V4      hVR8X  Ed=   V^ 8w  Ed5   V\        V4      ^,
          8w  Ed   TP                  \	        V\
        4      '       d   RMR4      p\        V4      ^8  d   V^ ,          R8X  d   VVR,          ,          pMV^ ,          R8X  d
   VV,          pV Uu. uF  pV P                  VVVVV	VR7      NK  	  ppRV^,          ,           pV\        V4      ,
          p\        V4       FJ  w  ppVP                  VV3VV34       VVV,          V\        V4      ^,
          ,          ,           ,          pKL  	  VV,          pEK  V^ ,          R8X  d   VVR,          ,          pMV^ ,          R8X  d
   VV,          pVP                  VV3VV34       VV,          pEK  	  VV3# u upi )NZttbZltZlaz#anchor must be a 2 character stringZtbz'anchor not supported for multiline textr   r   ZA)r   )r   r   r   r   Zmg       @r   justifyZcenterr   z4align must be "left", "center", "right" or "justify"Z s    r   Zl)r    r    )r   r   )ru   r)   r@   ZsplitrD   rE   textbboxr   
textlengthmaxr   sum)r2   rH   r   r   r   r   r   r   r   r   r   r   r=   r3   linesZline_spacingr   r   r   rx   ZwidthsZ	max_widthZ
line_widthZidxZwidth_differenceZwordsZwordZword_widthsZword_anchorry   s   &&&&&&&&&&&&&                 r   _prepare_multiline_textZ!ImageDraw._prepare_multiline_text  s   . >&%/TTF[A7CS/!AY$9#5;CS/!<==+D

:dC#8#84eDMM&#tMGJ 	 ea5DtSk6489$ \ U{U F I!__'%%#1 - 
 j)	:6	  ayCE
Q,6<<c!E
Q,66&u-	T!u#,vc{#:  //h&,s22Dg%,,DPC$S/) Y&(A-s5zA~- JJjs.C.CsNE5zA~!!9+ IO3D#AY#- I-D ).
' ). !OO $ $*3)1)1/= ,  ). $ 
' '*F1Io+4s;7G+G('0'7GAt!LL4+{D)IJ KN5EUVW5X$XXD (8 |+  !9#,s22DAY#%,,DtSk6489|#k .n U{7
's   ' N.r=   c               sT    V ^8  d   Qh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RRRRR/# )r   rH   r   r   r   r1   rB   r   r   r   r   r   rJ   r   rE   r   r   r   r   r   r   r   r   r=   r>   r   r   r   r   r   r   r   r      s     3 33 3 	33 3 3 3 3 #3  !3" #3$ !%3& '3*  +3, 
-3r!   c               	s    V P                  VVVVVVVV	V
VVV4      w  rOV F"  w  rpV P                  VVVVVVV	V
VVVR 7       K$  	  R# ))r   r   r   r   r   r   N)r   r   )r2   rH   r   r1   r   r   r   r   r   r   r   r   r   r   r=   r   rx   s   &&&&&&&&&&&&&&$  r   r   ZImageDraw.multiline_text  s}    . 22
 !&BII#!!)'-   !&r!   c               s8    V ^8  d   Qh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   r   r   r   r=   r>   r   rJ   r   r   r   r   r   r    S  sd     I II	I I #I I I  I 
Ir!   c               s   V P                  V4      '       d   Rp\        V4      hV'       d   V P                  R9  d   Rp\        V4      hVf   V P                  V4      pV'       d   RMV P                  p	VP                  WW4V4      # )z@Get the length of a given string, in pixels with 1/64 precision.z&can't measure length of multiline textr"   r   r   )r   r)   r   r@   r0   Z	getlength)
r2   r   r   r   r   r   r   r=   r3   r   s
   &&&&&&&$  r   r   ZImageDraw.textlengthS  st    "   &&:CS/!dii>GCS/!<==+D'vT]]~~d)xHHr!   c               r   r   rH   r   r   r   r   r   r   r   r   rJ   r   rE   r   r   r   r   r   r   r   r=   r>   r   z!tuple[float, float, float, float]r   r   r   r   r   r    p  s     0R 0R0R 0R
0R 0R 0R 0R 0R #0R 0R  !0R" #0R&  '0R( 
+)0Rr!   c               s   V'       d   V P                   R9  d   Rp\        V4      hVf   V P                  V4      pV P                  V4      '       d   V P	                  VVVVVVVVV	V
V4      # V'       d   RMV P
                  pVP                  W.WxWV4      pV^ ,          V^ ,          ,           V^,          V^,          ,           V^,          V^ ,          ,           V^,          V^,          ,           3# )z2Get the bounding box of a given string, in pixels.r"   r   r   )r   r)   r@   r   multiline_textbboxr0   Zgetbbox)r2   rH   r   r   r   r   r   r   r   r   r   r   r=   r3   r   bboxs   &&&&&&&&&&&&$   r   r   ZImageDraw.textbboxp  s    , dii>GCS/!<==+D  &&**  (vT]]||	XV
 AwAQ"Q%a2a5$q'BqE/QQr!   c               r   r   r   r   r   r   r   r      s     > >> >
> > > > > #> >  !>" #>&  '>( 
+)>r!   c               	s   V P                  VVVVVVVVV	V
VV4      w  r=R pV F  w  rpV P                  VVVVVVV	V
VR7	      pVf   TpK(  \        V^ ,          V^ ,          4      \        V^,          V^,          4      \        V^,          V^,          4      \        V^,          V^,          4      3pK  	  Vf#   V^ ,          V^,          V^ ,          V^,          3# V# )N)r   r   r   r   r   )r   r   Zminr   )r2   rH   r   r   r   r   r   r   r   r   r   r   r=   r   r   rx   Z	bbox_lines   &&&&&&&&&&&&$    r   r   ZImageDraw.multiline_textbbox  s   * 22
 :> %B#!!)- & 
I |  Q1.Q1.Q1.Q1.	 !&, <a5"Q%A1--r!   )	r+   r-   r1   r   r0   r   r/   r   r*   rC   )N   )NNr   )Nr    NNN)r    NNr   )NNN   r   NNNr    NF)NNNNF)	NNr   r   NNNr    F)Z__name__Z
__module__Z__qualname__Z__firstlineno__r   __annotations__r5   r;   r@   rG   rP   rR   r[   ra   rd   rx   r|   rw   rz   r   r   r   r   r   r   r   r   r   r   r   Z__static_attributes__r   r!   r   r   r   =   s     	 	V(T6"'2;	6@ 6
7K=Z2C +K0/8J8 9=J8 J8X'
}~||3* #'+3 3jI #'I I:0R& #''0R 0Rd>& #''> >r!   r   c               r   )r   r   r   r   r   r   r   r   r   r   r   r   r     s!     # #[ #
 #i #r!   c                s`     \        V R4      ! V4      #   \         d    \        Y4      u # i ; i)ak  
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)Zgetattrr   r   )r   r   s   &&r   r   r     s3    #r9%d++ #""#s    --c               r   )r   r   zImage.Image | Nonehintsr   r   z)tuple[ImageDraw2.Draw | None, ModuleType]r   r   r   r   r   r     s$      *:.r!   c                sd    Ve   \        R^4       ^RIHp V e   VP                  ! V 4      MRpW23# )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   r8   r   r   )r   r   r   r-   s   &&  r   r   r     s5     %r*"$.:??2dDr!   c               s0    V ^8  d   QhRRRRRRRRR	R
RR/# )r   imager   rH   ztuple[int, int]valuefloat | tuple[int, ...]borderzfloat | tuple[int, ...] | NonethreshrJ   r   r   r   r   r   r   r   r     sD     > >>> #> +	>
 > 
>r!   c                st   V P                  4       pVw  rg WVV3,          p\        W(4      V8:  d   R# W%Wg3&   Yg30p	\	        4       p
T	'       d   \	        4       pT	 F  w  rgT^,           T3T^,
          T3Yg^,           3Yg^,
          33 Ft  w  rY3T
9   g   T^ 8  g   T^ 8  d   K   Y\T3,          pT
P                  Y34       Tf   \        Y4      T8*  pMYT39  pT'       d   Y%Y3&   TP                  Y34       Kt  Kv  	  K  	  T	p
Tp	K  R#   \        \        3 d     R# i ; i  \        \        3 d     K  i ; i)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.
N)r(   _color_diffr)   Z
IndexErrorZsetZadd)r   rH   r   r   r   Zpixelrp   rq   Z
backgroundZedgeZ	full_edgeZnew_edgeZsZtrk   r1   s   &&&&&           r   	floodfillr     sU   6 JJLEDAa4[
u)V3ad F8D I
5DAa%a!eQZ!UaQZH6Y&!a%1q5-dA MM1&)~*19VC 7&+ad aV,  I $ 	+  
#  #J/ s(   D
 D
 $
D"
DD"D76D7c               rQ   )	r   r   r   r   rM   r   rJ   r   zlist[tuple[float, float]]r   r   r   r   r   r   E  s8     @ @6@AD@PU@@r!   c                s  aa	a
 \        V\        4      '       g   Rp\        V4      hV^8  d   Rp\        V4      h\        V \        \
        34      '       g   Rp\        V4      h\        V 4      ^8X  dq   \        ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      '       g   Rp\        V4      h\        \        \        ,          \	        V 4      4      Ev o	o
EM \        V 4      ^8X  Ed   \        V ^ ,          \        \
        34      '       d   \        ;QJ d#    R V ^ ,           4       F  '       d   K   RM	  RM! R V ^ ,           4       4      '       d$   \        V ^,          \        \        34      '       g   Rp\        V4      h\        V ^ ,          4      ^8w  d   R	p\        V4      h\        \        \        ,          \	        V ^ ,          4      4      o	\        \        V ^,          4      o
MR
p\        V4      hS
^ 8:  d   Rp\        V4      h\        V\        \        34      '       g   Rp\        V4      hR V	3R lloR VV
3R llpR R lpV! W4      pV Uu. uF
  qt! V4      NK  	  up# u upi )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 intzn_sides should be an int > 2z$bounding_circle should be a sequencec              3  N   "   T F  p\        V\        \        34      x  K  	  R # 5irC   rD   rM   rJ   rj   ry   r:   r   rl   4_compute_regular_polygon_vertices.<locals>.<genexpr>}  s     H1:a#u..   #%FTz0bounding_circle should only contain numeric datac              3  r   rC   r   r   r:   r   rl   r     s"      
1CAJq3,''1Cr   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 floatc               r   )r   rz   list[float]rv   rJ   r   r   r   r   r   r   r   7_compute_regular_polygon_vertices.<locals>.__annotate__  s"     
 
{ 
U 
?R 
r!   c                sp  < \        V ^ ,          \        P                  ! \        P                  ! RV,
          4      4      ,          V ^,          \        P                  ! \        P                  ! RV,
          4      4      ,          ,
          S^ ,          ,           ^4      \        V ^,          \        P                  ! \        P                  ! RV,
          4      4      ,          V ^ ,          \        P                  ! \        P                  ! RV,
          4      4      ,          ,           S^,          ,           ^4      3# )r    rf   )r   ri   rm   rn   ro   )rz   rv   centroids   &&r   _apply_rotationZ:_compute_regular_polygon_vertices.<locals>._apply_rotation  s    a488DLLw$?@@(TXXdll3=&ABBC1+ 	 a488DLLw$?@@(TXXdll3=&ABBC1+ 	
 	
r!   c               r<   )r   rh   rJ   r   r   r   r   r   r   r   r     s     3 3u 31D 3r!   c                s   < S^ .pS! W4      # r   r   )rh   Zstart_pointr   polygon_radius   & r   _compute_polygon_vertexZB_compute_regular_polygon_vertices.<locals>._compute_polygon_vertex  s    %q){22r!   c               r   )r   r   rM   r   rJ   r   r   r   r   r   r   r   r     s!     
 
S 
E 
k 
r!   c                s    . pR V ,          pRRV,          ,
          V,           p\        V 4       F.  pVP                  V4       WC,          pVR 8  g   K%  VR ,          pK0  	  V# )rf   r   g      ?)rt   r   )r   r   r{   rv   Zcurrent_angleZ_s   &&    r   _get_anglesZ6_compute_regular_polygon_vertices.<locals>._get_angles  s^    -sW},8wAMM-($Ms"$	  
 r!   )
rD   rM   r   r)   rs   rF   ru   r   r   rJ   )r   r   r   r3   r   r   r{   rh   r   r   r   s   &&&     @@@r   r   r   E  s   V gs##(n{,o oe}554n
?q sHHsssHHHHDCS/!$(ed?6K$L!>	_		"z/!2DtUm'T'Ts 
1@1C
sss 
1@1C
 
 
OA.e==DCS/!q!"a'VCS/!UT/!*<%=>e_Q%78< 	 o4o he--2o
 
 3 3
 +F 9??u#E*???s   &I9c               rA   )r   color1r   color2r   rJ   r   r   r   r   r   r     s)     	F 	F#	F-D	F
	Fr!   c                s   aa \        V \        4      '       d   T MV 3o\        V\        4      '       d   TMV3o\        VV3R l\        \	        S4      4       4       4      # )zB
Uses 1-norm distance to calculate difference between two values.
c              3  sd   <"   T F%  p\        SV,          SV,          ,
          4      x  K'  	  R # 5irC   )Zabs)rj   ry   firstsecondr   r   rl   Z_color_diff.<locals>.<genexpr>  s(     E2DQs58fQi'((2Ds   -0)rD   rF   r   rt   ru   )r   r   r   r   s   &&@@r   r   r     sI     !//FfYE!&%00VviFE%F2DEEEr!   rC   r   )Nr    )(__conditional_annotations__Z
__future__r   ri   r   Zcollections.abcr   Ztypesr   Ztypingr   r   r   r   r   r8   r	   r
   Z
_deprecater   Z_typingr   r,   rV   r   r   ZTYPE_CHECKINGr   r   rJ   rF   rM   rE   Z_Inkr   r   r   r   r   r   )r   s   @r   <module>r      s   @ # "   $  5 5  !  .3ZZ-?-?	* ?'UE#s(OS()c cL#" >B@D	Fr!   