
    Bwg#                       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.                  j0                  Ze	rddlmZmZ eeeedf   e f   Z!	  G d d      Z"dddZ#	 d	 	 	 	 	 ddZ$	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ%	 	 	 	 	 	 	 	 ddZ&	 	 	 	 	 	 ddZ'y# e$ r dZY dw xY w)    )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<   dd dZ	 	 d!dZ	 	 	 	 d"dZ	 d	 	 	 	 	 d#dZ	 	 d$	 	 	 	 	 	 	 	 	 	 	 d%dZ		 d	 	 	 	 	 	 	 d&d	Z
	 	 	 d'	 	 	 	 	 	 	 	 	 	 	 	 	 d(d
Z	 	 	 d'	 	 	 	 	 	 	 	 	 d)dZ	 	 	 d'	 	 	 	 	 	 	 	 	 	 	 d*dZ	 	 	 d+	 	 	 	 	 	 	 	 	 d,dZ	 	 d-	 	 	 	 	 	 	 d.dZ	 	 	 d'	 	 	 	 	 	 	 	 	 	 	 	 	 d(dZdd/dZ	 	 	 d'	 	 	 	 	 	 	 	 	 d)dZ	 	 	 	 d0	 	 	 	 	 	 	 	 	 	 	 	 	 d1dZ	 	 	 d'	 	 	 	 	 	 	 	 	 d)dZ	 	 	 	 d0dd	 	 	 	 	 	 	 	 	 	 	 	 	 d2dZd3dZd4dZ	 	 	 	 	 	 	 	 d5dZ	 	 	 	 	 	 	 	 	 	 	 d6	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d7dZ	 	 	 	 	 	 	 	 	 	 	 d6dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d8dZ	 	 	 	 	 d9dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d:dZ	 	 	 	 	 	 	 	 	 d;dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d<dZ	 	 	 	 	 	 	 	 	 d;dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d<dZy)=	ImageDrawNNImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont | Nonefontc                   |j                          |j                  r|j                          d}||j                  }||j                  k7  r$|dk(  r|j                  dk(  rd}nd}t	        |      |dk(  r|j
                  | _        nd| _        || _        |j                  | _        t        j                  j                  | j                  |      | _
        || _        |dv r!| j                  j                  d      | _        n | j                  j                  d	      | _        |d
v rd| _        d| _        yd| _        d| _        y)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_copymode
ValueErrorpalette_imageimr   coredrawdraw_inkinkfontmodefill)selfr(   r$   blendmsgs        D/var/www/horilla/myenv/lib/python3.12/site-packages/PIL/ImageDraw.py__init__zImageDraw.__init__E   s
    		;;HHJ<77D277?v~"''U"2% o%3;::DLDL%%JJOODGGU3		:yy))!,DHyy))"-DH''DM 	  DM	    c                j    | 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)r/   r   s     r2   getfontzImageDraw.getfonto   s*    ( yy#.	..0DIyyr4   c                V    |ddl m}  |j                  |      S | j                         S )Nr   r6   )r7   r   r8   r9   )r/   	font_sizer   s      r2   _getfontzImageDraw._getfont   s,      #)9)))44<<>!r4   c                   d }d }|.|,| j                   r| j                  }||fS | j                  }||fS |t        |t              r t	        j
                  || j                        }| j                  r6t        |t              r&| j                  j                  || j                        }| j                  j                  |      }|t        |t              r t	        j
                  || j                        }| j                  r6t        |t              r&| j                  j                  || j                        }| j                  j                  |      }||fS N)r.   r,   
isinstancestrr   getcolorr$   r&   tupler'   r*   r+   )r/   r,   r.   
result_inkresult_fills        r2   _getinkzImageDraw._getink   s     
;4<yy"hh  ;&& "XX
 ;&& c3'$--c499=C<<JsE$:,,//T[[AC!YY//4
dC(%..tTYY?D<<JtU$;<<00t{{CD"ii006;&&r4   c                p    | j                  |      \  }}| | j                  j                  |||||       yy)zDraw an arc.N)rE   r*   draw_arc)r/   xystartendr.   widthr,   s          r2   arczImageDraw.arc   s:     LL&	T?IIr5#sE: r4   c                    |j                          | j                  |      \  }}||}|(| j                  j                  ||j                  |       yy)zDraw a bitmap.N)r!   rE   r*   draw_bitmapr(   )r/   rH   bitmapr.   r,   s        r2   rO   zImageDraw.bitmap   sM     	LL&	T;C?II!!"fii5 r4   c                    | j                  ||      \  }}|| j                  j                  ||||d       |-||k7  r'|dk7  r!| j                  j                  ||||d|       yyyy)zDraw a chord.Nr   r   )rE   r*   
draw_chord	r/   rH   rI   rJ   r.   outlinerK   r,   fill_inks	            r2   chordzImageDraw.chord   sn     Wd3XII  UC1=?sh5A:II  UCa? 4>?r4   c                    | j                  ||      \  }}|| j                  j                  ||d       |+||k7  r%|dk7  r| j                  j                  ||d|       yyyy)zDraw an ellipse.Nr   r   )rE   r*   draw_ellipser/   rH   r.   rS   rK   r,   rT   s          r2   ellipsezImageDraw.ellipse   sf     Wd3XII""2x3?sh5A:II""2sAu5 4>?r4   c                h    |d   |z
  |d   |z
  |d   |z   |d   |z   f}| j                  ||||       y)z4Draw a circle given center coordinates and a radius.r   r   N)rY   )r/   rH   radiusr.   rS   rK   
ellipse_xys          r2   circlezImageDraw.circle   sD     efnbefnbefnbefnU
Zw6r4   c                   | j                  |      d   }|R| j                  j                  ||       |dk(  r.dkD  r't        |d   t        t
        f      rt        t        t        t              |      }nGt        dt        |      d      D cg c](  }t        t        t           t        |||dz                * }}t        dt        |      dz
        D ]  }||   }||dz
     |f|||dz      ffD 	
cg c]C  \  }	}
t        j                  t        j                  |
d   |	d   z
  |	d   |
d   z
              dz  E }}	}
|d   |d   k(  rw	 	 	 	 	 	 dfd}|d   |d   kD  xr |d   d	z
  |d   kD  xs |d   |d   k  xr |d   d	z   |d   kD  }|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
  }
}	| j                  ||	d
z
  |
d
z
  |       dkD  s7|r  |||d   d
z         | |||d   d
z         g}n |||d   d
z
        | |||d   d
z
        g}| j                  ||d        yyyyc c}w c c}
}	w )z6Draw a line, or a connected sequence of line segments.r   Ncurve      r   h  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   ra   r   c              3     K   | ]9  \  }}||d kD  rt        j                  |      nt        j                  |      z    ; yw)r   N)mathfloorceil).0pp_ds      r2   	<genexpr>z9ImageDraw.line.<locals>.coord_at_angle.<locals>.<genexpr>  s9      % &3 C!GC3P%s   ?A)rB   rf   cosradianssin)coordanglexydistancerK   s        r2   coord_at_anglez&ImageDraw.line.<locals>.coord_at_angle  s      %1#(19q=$ % "#HtxxU8K/L$L M!"HtxxU8K/L$L M+%   r4      rd         )rK   )rp   Sequence[float]rq   floatreturnztuple[float, ...])rE   r*   
draw_linesr?   listrB   r   r   rz   rangelenrf   degreesatan2piesliceline)r/   rH   r.   rK   jointr,   pointsipointrI   rJ   anglesru   flippedcoords
gap_coordss      `            r2   r   zImageDraw.line   s&    ll4 #?II  S%0EAIbedE]3!(8E?";R@F "'q#b'1!5 Xe_eBq1q5M.BCF  q#f+/2 7=A"1IE
 $AE]E2"F1q5M2+ 'E3 TZZAq0A58cRSfCT%UVF  ayF1I- .7<* q	F1I-M&)c/F1I2MQ )fQi/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" .ufQi"n E % .ufQi"n E*J !/ufQi"n E % .ufQi"n E*J
 		*d!	<o7= %. s   -I,9AI1c                    |j                          | j                  ||      \  }}|| j                  j                  ||d       |$||k7  r| j                  j                  ||d       yyy)z(Experimental) Draw a shape.Nr   r   )closerE   r*   draw_outline)r/   shaper.   rS   r,   rT   s         r2   r   zImageDraw.shape<  se     	Wd3XII""5(A6?shII""5#q1  /?r4   c                    | j                  ||      \  }}|| j                  j                  ||||d       |-||k7  r'|dk7  r!| j                  j                  ||||d|       yyyy)zDraw a pieslice.Nr   r   )rE   r*   draw_pieslicerR   s	            r2   r   zImageDraw.piesliceJ  sn     Wd3XII##BsHa@?sh5A:II##BsCEB 4>?r4   c                j    | j                  |      \  }}|| j                  j                  ||       yy)z#Draw one or more individual pixels.N)rE   r*   draw_points)r/   rH   r.   r,   s       r2   r   zImageDraw.pointZ  s2    LL&	T?II!!"c* r4   c                   | j                  ||      \  }}|| j                  j                  ||d       |||k7  r|dk7  r|dk(  r| j                  j                  ||d|       y| j                  ft	        j
                  d| j                  j                        }| j                  d      d   }|j                         }	t        |	      }
|
j                  j                  ||d       |j                         }t        |      }
|dz  dz
  }|
j                  j                  ||d|       |j                  ||	       t	        j
                  | j                  | j                  j                        }t        |      }
|
j                  j                  ||d|       | j                  j                  |j                  d|j                  z   |j                         yyyyy)zDraw a polygon.Nr   r   r   ra   )maskr   r   )rE   r*   draw_polygonr(   r   newsizecopyDrawpaster$   )r/   rH   r.   rS   rK   r,   rT   r   mask_inkfill_imr*   ink_imr(   s                r2   polygonzImageDraw.polygon`  s}    Wd3XII""2x3?sh5A:z		&&r359$ yydggll3<<?1-))+G}		&&r8Q7F|	A		&&r8Q>

6
0YYtyy$'',,7Bx		&&r359beeVbgg%5tww?) % 4>?r4   c                F    t        |||      }| j                  ||||       y)zDraw a regular polygon.N)!_compute_regular_polygon_verticesr   )r/   bounding_circlen_sidesrotationr.   rS   rK   rH   s           r2   regular_polygonzImageDraw.regular_polygon  s$     /RRw.r4   c                    | j                  ||      \  }}|| j                  j                  ||d       |+||k7  r%|dk7  r| j                  j                  ||d|       yyyy)zDraw a rectangle.Nr   r   )rE   r*   draw_rectanglerX   s          r2   	rectanglezImageDraw.rectangle  sf     Wd3XII$$R15?sh5A:II$$Ra7 4>?r4   )cornersc                   t        |d   t        t        f      r(t        t        t        t
              |      \  \  \  nt        t        t
           |      \  k  rd}t        |      k  rd}t        |      d|dz  t              t              t              t              d\  t              r<z
  dz
  k\  rz
  z
  dz
  k\  rz
  rr j                  |||      S dk(  st              s j                  |||      S t        dz        } j                  ||      \  d fd	}	 |	d
       r. j                  j                  |z   dz   |z
  dz
  fd       n>|z
  dz
  |z   dz   kD  r- j                  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                  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                  j                  |d       hk7  radk7  rZ |	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                  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                  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                  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                  j                  |d       yyyyy)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)TTTTra   )FFr   c                   rz   z   fddfz
  z   fddff}nvrz   z   fddfz
  z   fddff}nUt        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 ]A  }| r 	j                  j                  |dfz     $ 	j                  j                  |
fz     C y )Nrv   rb   r   rd     c              3  2   K   | ]  \  }}|   r|  y wr>    )ri   r   partr   s      r2   rl   zDImageDraw.rounded_rectangle.<locals>.draw_corners.<locals>.<genexpr>  s&      4 qz s   r   )rB   	enumerater*   r   rG   )r   partsr   r   drT   full_xfull_yr,   r/   rK   x0x1y0y1s      r2   draw_cornersz1ImageDraw.rounded_rectangle.<locals>.draw_corners  sf    "b1fb1f-sC8"q&"q&"-q#6  "b1fb1f-r371fb"b1f-sB7  #, "b1fb1f5sC@ 1fb"b1f5sC@ 1fb1fb"5q"= "q&"q&"5r3?	$   ?+DII++dh].BD&DII&&e)<>	?r4   Trx   F)r   boolr{   None)r?   r}   rB   r   r   rz   r%   roundallrY   anyr   intrE   r*   r   )r/   rH   r[   r.   rS   rK   r   r1   rr   leftrighttopbottomr   rT   r   r   r,   r   r   r   r   s   `    ``       @@@@@@@@@r2   rounded_rectanglezImageDraw.rounded_rectangle  sW    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&||Bgu==6W >>"dGU;;QKWd3X 	?  	?  	?D 		(("b1fqj"b1fqj)I8UVWa!b1fqj(		(("q&1*b"q&1*b)I8UVW&BQ+1:Gq1u$G1:Gq1u$G		((x;aR,1:!HA%H1:!HA%H		((!<?sh5A:2r2:>21:Fa!eOF1:Fa!eOF		((c15b5j1nb"51:1IQ&I1:1IQ&I		((a8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>?r4   c                2    t        |t              rdnd}||v S N
   
)r?   r@   )r/   textsplit_characters      r2   _multiline_checkzImageDraw._multiline_check+  s    ",T3"7$U$&&r4   c                P    |j                  t        |t              rd      S d      S r   )splitr?   r@   )r/   r   s     r2   _multiline_splitzImageDraw._multiline_split0  s"    zz*T3"7$CCUCCr4   c                >    | j                  dd||      d   |z   |z   S )Nr   A)stroke_widthrx   )textbbox)r/   r   spacingr   s       r2   _multiline_spacingzImageDraw._multiline_spacing3  s2     MM&#t,MGJ	
r4   c                   	
 r j                   dvrd}t        |        j                  j                  d             j	                        r j                  |||	
||      S d fd}d	d
	
 fd} ||      }|.d}|r| ||      n|}| |||        ||d       y ||       yy)z
Draw text.r   r   3Embedded color supported only in RGB and RGBA modesNr;   c                @    j                  |       \  }}||J |S |S r>   )rE   )r.   r,   rT   r/   s      r2   getinkzImageDraw.text.<locals>.getinko  s0     LL.MC{+++Jr4   r   c                v   j                   }|dk(  rrd}g }t        d      D ]  }|j                  t        |                ! t	        j
                  d         d   t	        j
                  d         d   f}	  j                  |g|| |d\  }}|d   |d   z   |d   |d   z   g}|dk(  r||j                  d      }}t        j                  d|       d   }	|j                  d|	       |\  }
}j                  Bj                  j                  ||
||
|j                   d   z   ||j                   d   z   f|       y y j"                  j%                  |||        y # t        $ rE 	  j                  ||| gd|i}n # t        $ r j                        }Y nw xY wY w xY w)	Nr   r   ra   r   )	directionfeatureslanguager   anchorr,   rI   rI   rx   r   )r-   r~   appendr   rf   modfgetmask2AttributeErrorgetmask	TypeErrorgetbandstructpackfillbandr(   r   r   r*   rN   )r,   r   r$   rp   r   rI   r   offsetcolor	ink_alpharr   rs   r   argsr   embedded_colorr   r   kwargsr   r/   r   rH   s               r2   	draw_textz!ImageDraw.text.<locals>.draw_textv  s   ==Dq ^E1X )SAZ()YYr!u%a($))BqE*:1*=>E.,t}}    (%%!-!   f qF1I-uQx&)/CD$ v~ #DLLOt"KKS1!4	q),177&GGMM1a$))A,&6DIIaL8HI4 '
 		%%eT37; " ..'4<<!  $  $ !D ! .<<-D..s6   =8E* *	F84FF8F1.F80F11F87F8)r.   _Ink | Noner{   r   )r   )r,   r   r   rz   r{   r   )r$   r%   r<   getr   multiline_text)r/   rH   r   r.   r   r   r   alignr   r   r   r   stroke_fillr   r   r   r1   r   r   r,   
stroke_inks   ``` ``  ```  ```     r2   r   zImageDraw.text?  s    0 dii>GCS/!<==K!89D  &&&  	4	8 4	8 4	8l Tl?J4?4KVK0QT
%*l3 #q! # r4   )r;   c                  |dk(  rd}t        |      |d}n/t        |      dk7  rd}t        |      |d   dv rd}t        |      || j                  |      }g }d	}| j                  |      }| j	                  |||      }|D ]5  }| j                  ||||	|

      }|j                  |       t        ||      }7 |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        |      | j                  ||f||||||	|
|||       ||z  } y )Nttb/ttb direction is unsupported for multiline textlara   #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   r<   r   r   
textlengthr   maxr   r   )r/   rH   r   r.   r   r   r   r   r   r   r   r   r   r   r;   r1   widths	max_widthlinesline_spacingr   
line_widthr   idxr   width_differences                             r2   r   zImageDraw.multiline_text  s'   . CCS/!>F[A7CS/!AY$;CS/!<==+D	%%d+..tWlK 	3Ddi(X ) J MM*%Iz2I	3 e!9CJNl2S88CAY#CJNl22C"5) "	 ICa5D(6#;6 ayC(3..c!(( ("(3..'!((A o%IIs#!!)'-   <CE"	 r4   c                   | j                  |      rd}t        |      |r| j                  dvrd}t        |      || j                  |      }|rdn| j                  }	|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   r   )r   r%   r$   r<   r-   	getlength)
r/   r   r   r   r   r   r   r;   r1   r$   s
             r2   r  zImageDraw.textlength  su    "   &:CS/!dii>GCS/!<==+D'vT]]~~dD)XxHHr4   c               \   |r| j                   dvrd}t        |      || j                  |      }| j                  |      r| j	                  |||||||||	|
|      S |rdn| j
                  }|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   r   r   r   ra   rx   )r$   r%   r<   r   multiline_textbboxr-   getbbox)r/   rH   r   r   r   r   r   r   r   r   r   r   r;   r1   r$   bboxs                   r2   r   zImageDraw.textbbox5  s    , dii>GCS/!<==+D  &**  (vT]]||$	8X|V
 AwAQ"Q%a2a5$q'BqE/QQr4   c                  |dk(  rd}t        |      |d}n/t        |      dk7  rd}t        |      |d   dv rd}t        |      || j                  |      }g }d	}| j                  |      }| j	                  |||
      }|D ]6  }| j                  |||||	|
      }|j                  |       t        ||      }8 |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        |      | j                  ||f||||||	|
|	      }||}nFt        |d	   |d	         t        |d   |d         t        |d   |d         t        |d   |d         f}||z  } ||d	   |d   |d	   |d   fS |S )Nr   r   r   ra   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r  r   r  )r   r   r   r   r   rx   )r%   r   r<   r   r   r  r   r  r   r   min)r/   rH   r   r   r   r   r   r   r   r   r   r   r;   r1   r  r  r  r  r   r	  r   r  r
  r   r  	bbox_lines                             r2   r  zImageDraw.multiline_textbboxg  s   * CCS/!>F[A7CS/!AY$;CS/!<==+D	%%d+..tWlK 
	3D#!!- ) J MM*%Iz2I
	3 e!9CJNl2S88CAY#CJNl22C9="5) *	 ICa5D(6#;6 ayC(3..c!(( ("(3..'!((A o%s#!!)- & 
I |  Q1.Q1.Q1.Q1.	 <CU*	 X <a5"Q%A1--r4   r>   )r(   Image.Imager$   
str | Noner{   r   )r{   GImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont)r;   float | Noner{   r  )r,   r   r.   r   r{   ztuple[int | None, int | None])Nr   )rH   r   rI   rz   rJ   rz   r.   r   rK   r   r{   r   )rH   zSequence[int]rO   r  r.   r   r{   r   )NNr   )rH   r   rI   rz   rJ   rz   r.   r   rS   r   rK   r   r{   r   )
rH   r   r.   r   rS   r   rK   r   r{   r   )rH   ry   r[   rz   r.   r   rS   r   rK   r   r{   r   )Nr   N)
rH   r   r.   r   rK   r   r   r  r{   r   NN)r   zImage.core._Outliner.   r   rS   r   r{   r   )rH   r   r.   r   r{   r   )r   NNr   )r   !Sequence[Sequence[float] | float]r   r   r   rz   r.   r   rS   r   rK   r   r{   r   )rH   r   r[   rz   r.   r   rS   r   rK   r   r   z$tuple[bool, bool, bool, bool] | Noner{   r   )r   r   r{   r   )r   r   r{   zlist[AnyStr])r   r  r   rz   r   rz   r{   rz   )NNNr`   r   NNNr   NF) rH   tuple[float, float]r   r   r.   r   r   r   r   r  r   rz   r   r@   r   r  r   list[str] | Noner   r  r   rz   r   r   r   r   r   r   r   r   r{   r   )rH   r  r   r   r.   r   r   r   r   r  r   rz   r   r@   r   r  r   r  r   r  r   rz   r   r   r   r   r;   r  r{   r   )NNNNF)r   r   r   r   r   r  r   r  r   r  r   r   r;   r  r{   rz   )	NNr`   r   NNNr   F)rH   r  r   r   r   r   r   r  r   rz   r   r@   r   r  r   r  r   r  r   rz   r   r   r;   r  r{   z!tuple[float, float, float, float])__name__
__module____qualname__r   __annotations__r3   r9   r<   rE   rL   rO   rU   rY   r]   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r   r4   r2   r   r   @   s    	 	V(T	P6"%"	P" 59''&1'	&'< !;; ; 	;
 ; ; 
; KO	6	6)4	6<G	6		6  !#@@ @ 	@
 @ @ @ 
@& !#66 6 	6
 6 
6$ !#
7
7 
7 	
7
 
7 
7 

7 ! K=K= K= 	K=
 K= 
K=` !#	2"2 2 	2
 
2& !#CC C 	C
 C C C 
C + !#"@"@ "@ 	"@
 "@ 
"@P  #/:/ / 	/
 / / / 
/  !#88 8 	8
 8 
8"  #J8 9=J8J8 J8 	J8
 J8 J8 6J8 
J8X'
D

U

 

 	


 


  ! ! $%)##'$'{{ { 	{{ { { { { #{  !{" #{$ !%{& '{( ){* +{, 
-{B ! ! $%)##'$'Z * #'+Z Z  Z  	Z Z  Z  Z  Z  Z  #Z   !Z " #Z $ !%Z & 'Z *  +Z , 
-Z H  $%)#$I #'II	I I #I I I  I 
IL ! $%)#$#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v ! $%)#$#k& #''kk k
k k k k k #k k  !k" #k&  'k( 
+)kr4   r   c                ^    	  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     r2   r   r     s7    #%wr9%d++ #T""#s    ,,c                ^    |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   r7   r   r   )r(   hintsr   r*   s       r2   r"  r"    s9     %r*"$.?:??2dDr4   c                (   | j                         }|J |\  }}	 |||f   }t        ||      |k  ry||||f<   ||fh}	t	               }
|	rt	               }|	D ]  \  }}|dz   |f|dz
  |f||dz   f||dz
  ffD ]f  \  }}||f|
v s
|dk  s|dk  r	 |||f   }|
j                  ||f       |t        ||      |k  }n|||fv}|sM||||f<   |j                  ||f       h  |	}
|}	|	ryy# t        t        f$ r Y yw xY w# t        t        f$ r Y w xY w)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)imagerH   valueborderthreshpixelrr   rs   
backgroundedge	full_edgenew_edgestrj   r.   s                   r2   	floodfillr7    s   6 JJLEDAq1a4[
uj)V3ad F8D I
5 	-DAqa%a!eQZ!QUaQZH -1q6Y&!a%1q5-adA MM1a&)~*1j9VC 7&+ad aV,!-	-$ 	+  
#  #J/ s(   C* C* C?*C<;C<?DDc                  	
 t        |t              sd}t        |      |dk  rd}t        |      t        | t        t
        f      sd}t        |      t        |       dk(  rCt        d | D              sd}t        |      t        t        t           t	        |             ^ 	
nt        |       dk(  rt        | d   t        t
        f      rt        d	 | d   D              rt        | d
   t        t        f      sd}t        |      t        | d         dk7  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} |||      }|D cg c]
  } ||       c}S c c}w )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 intrx   zn_sides should be an int > 2z$bounding_circle should be a sequencec              3  H   K   | ]  }t        |t        t        f        y wr>   r?   r   rz   ri   r   s     r2   rl   z4_compute_regular_polygon_vertices.<locals>.<genexpr>o  s     H1:a#u.H    "z0bounding_circle should only contain numeric datara   r   c              3  H   K   | ]  }t        |t        t        f        y wr>   r:  r;  s     r2   rl   z4_compute_regular_polygon_vertices.<locals>.<genexpr>u  s       
,-Jq3,'
r<  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 floatc                   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   rb   r   ra   )r   rf   rm   rn   ro   )r   r   centroids     r2   _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+ 	
 	
r4   c                    dg} ||       S Nr   r   )rq   start_pointr@  polygon_radiuss     r2   _compute_polygon_vertexzB_compute_regular_polygon_vertices.<locals>._compute_polygon_vertex  s    %q){E22r4   c                    g }d| z  }dd|z  z
  |z   }t        d|       D ]#  }|j                  |       ||z  }|dkD  s|dz  }% |S )Nrb   r   g      ?r   )r~   r   )r   r   r   r   current_angle_s         r2   _get_anglesz6_compute_regular_polygon_vertices.<locals>._get_angles  sh    -sW},8q'" 	%AMM-(W$Ms"$		%
 r4   )r   list[float]r   rz   r{   r  )rq   rz   r{   r  )r   r   r   rz   r{   rJ  )
r?   r   r   r%   r}   rB   r   r   r   rz   )r   r   r   r1   rE  rI  r   rq   r@  r?  rD  s           @@@r2   r   r   7  s   V gs#(n{,o oe}54n
?q HHHDCS/!$(ed?6K$L!>	_		"z/!2DtUm'T 
1@1C
 
OA.e=DCS/!q!"a'VCS/!UT/!*<%=>e_Q%78< 	 o4o he-2o
 3
 (+F 9??u#E*???s   >Gc           	         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  F   K   | ]  }t        |   |   z
          y wr>   )abs)ri   r   firstseconds     r2   rl   z_color_diff.<locals>.<genexpr>  s#     HQs58fQi'(Hs   !r   )r?   rB   sumr~   r   )color1color2rN  rO  s     @@r2   r(  r(    sE     !/FfYE!&%0VviFH%3v;2GHHHr4   r>   )r(   r  r$   r  r{   r   r  )r(   zImage.Image | Noner&  r  r{   z)tuple[ImageDraw2.Draw | None, ModuleType]rB  )r,  r  rH   ztuple[int, int]r-  float | tuple[int, ...]r.  zfloat | tuple[int, ...] | Noner/  rz   r{   r   )r   r  r   r   r   rz   r{   zlist[tuple[float, float]])rQ  rS  rR  rS  r{   rz   )(
__future__r   rf   r   collections.abcr   typesr   typingr   r   r   r	   r
   r   r7   r   r   
_deprecater   _typingr   r   r)   rS   r   r   r   r   rz   rB   r   r@   _Inkr   r   r"  r7  r   r(  r   r4   r2   <module>r[     sK  @ #   $  D D  !  
2 1jj  G 'UE#s(OS()R Rj#$ >B*:.( .2>>> #> +	>
 > 
>B@6@AD@PU@@D	I#	I-D	I
	IS$  Gs   B7 7C C