
    qZh                    l   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 ddlmZmZ ddlmZ dd	lmZ ej*                  j,                  Zd
ed<   d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)    )annotationsN)Sequence)
ModuleType)AnyAnyStrCallableUnioncast   )Image
ImageColor)	deprecate)Coordsz!Callable[[], Image.core._Outline]OutlineF)
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	 	 	 	 d/	 	 	 	 	 	 	 	 	 	 	 	 	 d0dZ	 	 	 d&	 	 	 	 	 	 	 	 	 d(dZ	 	 	 	 d/dd	 	 	 	 	 	 	 	 	 	 	 	 	 d1dZd2dZ	 	 	 	 	 	 	 	 	 	 	 d3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5dZ	 	 	 	 	 	 	 	 	 	 	 d3dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d6dZ	 	 	 	 	 d7dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d8dZ	 	 	 	 	 	 	 	 	 d9dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d:dZ	 	 	 	 	 	 	 	 	 d9d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        i/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/PIL/ImageDraw.py__init__zImageDraw.__init__B   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     r1   getfontzImageDraw.getfontl   s*    ( yy#.	..0DIyyr3   c                V    |ddl m}  |j                  |      S | j                         S )Nr   r5   )r6   r   r7   r8   )r.   	font_sizer   s      r1   _getfontzImageDraw._getfont   s,      #)9)))44<<>!r3   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        r1   _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;&&r3   c                p    | j                  |      \  }}| | j                  j                  |||||       yy)zDraw an arc.N)rD   r)   draw_arc)r.   xystartendr-   widthr+   s          r1   arczImageDraw.arc   s:     LL&	T?IIr5#sE: r3   c                    |j                          | j                  |      \  }}||}|(| j                  j                  ||j                  |       yy)zDraw a bitmap.N)r    rD   r)   draw_bitmapr'   )r.   rG   bitmapr-   r+   s        r1   rN   zImageDraw.bitmap   sM     	LL&	T;C?II!!"fii5 r3   c                    | j                  ||      \  }}|| j                  j                  ||||d       |-||k7  r'|dk7  r!| j                  j                  ||||d|       yyyy)zDraw a chord.Nr   r   )rD   r)   
draw_chord	r.   rG   rH   rI   r-   outlinerJ   r+   fill_inks	            r1   chordzImageDraw.chord   sn     Wd3XII  UC1=?sh5A:II  UCa? 4>?r3   c                    | j                  ||      \  }}|| j                  j                  ||d       |+||k7  r%|dk7  r| j                  j                  ||d|       yyyy)zDraw an ellipse.Nr   r   )rD   r)   draw_ellipser.   rG   r-   rR   rJ   r+   rS   s          r1   ellipsezImageDraw.ellipse   sf     Wd3XII""2x3?sh5A:II""2sAu5 4>?r3   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)rX   )r.   rG   radiusr-   rR   rJ   
ellipse_xys          r1   circlezImageDraw.circle   sD     efnbefnbefnbefnU
Zw6r3   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   r`   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      r1   	<genexpr>z9ImageDraw.line.<locals>.coord_at_angle.<locals>.<genexpr>  s9      % &3 C!GC3P%s   ?A)rA   re   cosradianssin)coordanglexydistancerJ   s        r1   coord_at_anglez&ImageDraw.line.<locals>.coord_at_angle  s      %1#(19q=$ % "#HtxxU8K/L$L M!"HtxxU8K/L$L M+%   r3      rc         )rJ   )ro   Sequence[float]rp   floatreturnztuple[float, ...])rD   r)   
draw_linesr>   listrA   r
   r   ry   rangelenre   degreesatan2piesliceline)r.   rG   r-   rJ   jointr+   pointsipointrH   rI   anglesrt   flippedcoords
gap_coordss      `            r1   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   )closerD   r)   draw_outline)r.   shaper-   rR   r+   rS   s         r1   r   zImageDraw.shape9  se     	Wd3XII""5(A6?shII""5#q1  /?r3   c                    | j                  ||      \  }}|| j                  j                  ||||d       |-||k7  r'|dk7  r!| j                  j                  ||||d|       yyyy)zDraw a pieslice.Nr   r   )rD   r)   draw_pieslicerQ   s	            r1   r   zImageDraw.piesliceG  sn     Wd3XII##BsHa@?sh5A:II##BsCEB 4>?r3   c                j    | j                  |      \  }}|| j                  j                  ||       yy)z#Draw one or more individual pixels.N)rD   r)   draw_points)r.   rG   r-   r+   s       r1   r   zImageDraw.pointW  s2    LL&	T?II!!"c* r3   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   r`   )maskr   r   )rD   r)   draw_polygonr'   r   newsizecopyDrawpaster#   )r.   rG   r-   rR   rJ   r+   rS   r   mask_inkfill_imr)   ink_imr'   s                r1   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>?r3   c                F    t        |||      }| j                  ||||       y)zDraw a regular polygon.N)!_compute_regular_polygon_verticesr   )r.   bounding_circlen_sidesrotationr-   rR   rJ   rG   s           r1   regular_polygonzImageDraw.regular_polygon  s$     /RRw.r3   c                    | j                  ||      \  }}|| j                  j                  ||d       |+||k7  r%|dk7  r| j                  j                  ||d|       yyyy)zDraw a rectangle.Nr   r   )rD   r)   draw_rectanglerW   s          r1   	rectanglezImageDraw.rectangle  sf     Wd3XII$$R15?sh5A:II$$Ra7 4>?r3   )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)TTTTr`   )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 )Nru   ra   r   rc     c              3  2   K   | ]  \  }}|   r|  y wr=    )rh   r   partr   s      r1   rk   zDImageDraw.rounded_rectangle.<locals>.draw_corners.<locals>.<genexpr>  s&      4 qz s   r   )rA   	enumerater)   r   rF   )r   partsr   r   drS   full_xfull_yr+   r.   rJ   x0x1y0y1s      r1   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)<>	?r3   Trw   F)r   boolrz   None)r>   r|   rA   r
   r   ry   r$   roundallrX   anyr   intrD   r)   r   )r.   rG   rZ   r-   rR   rJ   r   r0   rr   leftrighttopbottomr   rS   r   r   r+   r   r   r   r   s   `    ``       @@@@@@@@@r1   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>?r3   c                2    t        |t              rdnd}||v S )N
   
)r>   r?   )r.   textsplit_characters      r1   _multiline_checkzImageDraw._multiline_check(  s    ",T3"7$U$&&r3   c                   	
 r j                   dvrd}t        |        j                  j                  d             j	                        r j                  |||	
||      S d fd}dd		
 fd} ||      }|3d}|r| ||      n|}| |||       ||k7  r	 ||       yy ||       yy)
z
Draw text.r   r   3Embedded color supported only in RGB and RGBA modesNr:   c                @    j                  |       \  }}||J |S |S r=   )rD   )r-   r+   rS   r.   s      r1   getinkzImageDraw.text.<locals>.getink]  s0     LL.MC{+++Jr3   c                x   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   |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   r`   r   T)	directionfeatureslanguagestroke_widthstroke_filledanchorr+   rH   rH   rw   r   )r,   r}   appendr   re   modfgetmask2AttributeErrorgetmask	TypeErrorgetbandstructpackfillbandr'   r   r   r)   rM   )r+   r   r#   ro   r   rH   r   offsetcolor	ink_alpharq   rr   r   argsr   embedded_colorr   r   kwargsr   r.   r   rG   s               r1   	draw_textz!ImageDraw.text.<locals>.draw_textd  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   =9E+ +	F95FF9F2/F91F22F98F9)r-   _Ink | Nonerz   r   )r   )r+   r   r   ry   rz   r   )r#   r$   r;   getr   multiline_text)r.   rG   r   r-   r   r   spacingalignr   r   r   r   stroke_fillr   r   r   r0   r   r   r+   
stroke_inks   ``` ``  ```  ```     r1   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 % # r3   c                   |dk(  rd}t        |      |d}n/t        |      dk7  rd}t        |      |d   dv rd}t        |      || j                  |      }g }d	}|j                  t	        |t
              rd
nd      }| j                  dd||
      d   |
z   |z   }|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  }g }t        |      D ]  \  }}|d	   }|||   z
  }|d	   dk(  r	||dz  z  }n|d	   dk(  r||z  }|dv rn&|dk(  r	||dz  z  }n|dk(  r||z  }nd}t        |      |dk(  r|d	k7  r|j                  t	        |t
              rdnd      }|D cg c]  }| j                  |||||	|       }}|t        |      z
  }t        |      D ]4  \  }}|j                  ||f|f       |||   |t        |      dz
  z  z   z  }6 n|j                  ||f|f       ||z  } |||fS c c}w )Nttbz/ttb direction is unsupported for multiline textlar`   z#anchor must be a 2 character stringr   tbz'anchor not supported for multiline textr   r   r   r   A)r   rw   )r   r   r   r   mg       @r   r   )r   justifycenterr   z4align must be "left", "center", "right" or "justify"r        )r$   r~   r;   splitr>   r?   textbbox
textlengthr   maxr   sum)r.   rG   r   r   r   r   r   r   r   r   r   r   r:   r0   widths	max_widthlinesline_spacingr   
line_widthr   r   idxr   width_differencewordswordword_widthsr   s                                r1   _prepare_multiline_textz!ImageDraw._prepare_multiline_text  s   0 CCS/!>F[A7CS/!AY$;CS/!<==+D	

:dC#84eDMM&#t,MGJ 	  
	3D#!!- ) 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..'!((L o%	!&6!&;

*T3*?3TJ !&
  OO"+!)!)'5 $ 
 
 $-s;/?#? (/ QGAtLL4+t!45KN-=Ua-PPPDQ tSk401<CS)	 V VU"")
s   6I	)r:   c                   | j                  ||||||||	|
|||      \  }}}|D ]!  \  }}| j                  |||||||	|
|||       # y )N)r   r   r   r   r   r   )r	  r   )r.   rG   r   r-   r   r   r   r   r   r   r   r   r   r   r:   r  r   s                    r1   r   zImageDraw.multiline_text  s    . #::
fe  	HBII#!!)'-  	r3   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:   r0   r#   s
             r1   r   zImageDraw.textlengthR  su    "   &:CS/!dii>GCS/!<==+D'vT]]~~dD)XxHHr3   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   r`   rw   )r#   r$   r;   r   multiline_textbboxr,   getbbox)r.   rG   r   r   r   r   r   r   r   r   r   r   r:   r0   r#   bboxs                   r1   r   zImageDraw.textbboxo  s    , dii>GCS/!<==+D  &**  (vT]]||$	8X|V
 AwAQ"Q%a2a5$q'BqE/QQr3   c               P   | j                  |||||||||	|
||      \  }}}d }|D ]j  \  }}| j                  |||||||	|
|	      }||}%t        |d   |d         t        |d   |d         t        |d   |d         t        |d   |d         f}l ||d   |d   |d   |d   fS |S )N)r   r   r   r   r   r   r   r`   rw   )r	  r   minr   )r.   rG   r   r   r   r   r   r   r   r   r   r   r:   r  r  r   	bbox_lines                    r1   r  zImageDraw.multiline_textbbox  s   * #::
fe :> 	HB#!!)- & 
I |  Q1.Q1.Q1.Q1.		, <a5"Q%A1--r3   r=   )r'   Image.Imager#   
str | Nonerz   r   )rz   GImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont)r:   float | Nonerz   r  )r+   r   r-   r   rz   ztuple[int | None, int | None])Nr   )rG   r   rH   ry   rI   ry   r-   r   rJ   r   rz   r   )rG   zSequence[int]rN   r  r-   r   rz   r   )NNr   )rG   r   rH   ry   rI   ry   r-   r   rR   r   rJ   r   rz   r   )
rG   r   r-   r   rR   r   rJ   r   rz   r   )rG   rx   rZ   ry   r-   r   rR   r   rJ   r   rz   r   )Nr   N)
rG   r   r-   r   rJ   r   r   r  rz   r   NN)r   zImage.core._Outliner-   r   rR   r   rz   r   )rG   r   r-   r   rz   r   )r   NNr   )r   !Sequence[Sequence[float] | float]r   r   r   ry   r-   r   rR   r   rJ   r   rz   r   )rG   r   rZ   ry   r-   r   rR   r   rJ   r   r   z$tuple[bool, bool, bool, bool] | Nonerz   r   )r   r   rz   r   )NNNr_   r   NNNr   NF) rG   tuple[float, float]r   r   r-   r   r   r   r   r  r   ry   r   r?   r   r  r   list[str] | Noner   r  r   ry   r   r   r   r   r   r   r   r   rz   r   )rG   r  r   r   r   r   r   r  r   ry   r   r?   r   r  r   r  r   r  r   ry   r   r   r:   r  rz   z}tuple[ImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont, str, list[tuple[tuple[float, float], AnyStr]]])rG   r  r   r   r-   r   r   r   r   r  r   ry   r   r?   r   r  r   r  r   r  r   ry   r   r   r   r   r:   r  rz   r   )NNNNF)r   r   r   r   r   r  r   r  r   r  r   r   r:   r  rz   ry   )	NNr_   r   NNNr   F)rG   r  r   r   r   r   r   r  r   ry   r   r?   r   r  r   r  r   r  r   ry   r   r   r:   r  rz   z!tuple[float, float, float, float])__name__
__module____qualname__r   __annotations__r2   r8   r;   rD   rK   rN   rT   rX   r\   r   r   r   r   r   r   r   r   r   r   r	  r   r   r   r  r   r3   r1   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' ! ! $%)##'$'}} } 	}} } } } } #}  !}" #}$ !%}& '}( )}* +}, 
-}~o#o# o#
o# o# o# o# o# #o# o#  !o#" #o#$  %o#&
'o#j ! ! $%)##'$'3* #'+33 3 	33 3 3 3 3 #3  !3" #3$ !%3& '3*  +3, 
-3z  $%)#$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 ! $%)#$#>& #''>> >
> > > > > #> >  !>" #>&  '>( 
+)>r3   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     r1   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   r6   r   r   )r'   hintsr   r)   s       r1   r!  r!    s9     %r*"$.?:??2dDr3   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)imagerG   valueborderthreshpixelrq   rr   
backgroundedge	full_edgenew_edgestri   r-   s                   r1   	floodfillr6    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 intrw   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   ry   rh   r   s     r1   rk   z4_compute_regular_polygon_vertices.<locals>.<genexpr>|  s     H1:a#u.H    "z0bounding_circle should only contain numeric datar`   r   c              3  H   K   | ]  }t        |t        t        f        y wr=   r9  r:  s     r1   rk   z4_compute_regular_polygon_vertices.<locals>.<genexpr>  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   ra   r   r`   )r   re   rl   rm   rn   )r   r   centroids     r1   _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+ 	
 	
r3   c                    dg} ||       S Nr   r   )rp   start_pointr?  polygon_radiuss     r1   _compute_polygon_vertexzB_compute_regular_polygon_vertices.<locals>._compute_polygon_vertex  s    %q){E22r3   c                    g }d| z  }dd|z  z
  |z   }t        |       D ]#  }|j                  |       ||z  }|dkD  s|dz  }% |S )Nra   r   g      ?)r}   r   )r   r   r   r   current_angle_s         r1   _get_anglesz6_compute_regular_polygon_vertices.<locals>._get_angles  se    -sW},8w 	%AMM-(W$Ms"$		%
 r3   )r   list[float]r   ry   rz   r  )rp   ry   rz   r  )r   r   r   ry   rz   rI  )
r>   r   r   r$   r|   rA   r~   r   r
   ry   )r   r   r   r0   rD  rH  r   rp   r?  r>  rC  s           @@@r1   r   r   D  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        t	                    D              S )zJ
    Uses 1-norm distance to calculate difference between two values.
    c              3  F   K   | ]  }t        |   |   z
          y wr=   )abs)rh   r   firstseconds     r1   rk   z_color_diff.<locals>.<genexpr>  s#     EQs58fQi'(Es   !)r>   rA   r   r}   r~   )color1color2rM  rN  s     @@r1   r'  r'    sC     !/FfYE!&%0VviFE%F2DEEEr3   r=   )r'   r  r#   r  rz   r   r  )r'   zImage.Image | Noner%  r  rz   z)tuple[ImageDraw2.Draw | None, ModuleType]rA  )r+  r  rG   ztuple[int, int]r,  float | tuple[int, ...]r-  zfloat | tuple[int, ...] | Noner.  ry   rz   r   )r   r  r   r   r   ry   rz   zlist[tuple[float, float]])rO  rQ  rP  rQ  rz   ry   )'
__future__r   re   r   collections.abcr   typesr   typingr   r   r   r	   r
   r6   r   r   
_deprecater   _typingr   r(   rR   r   r  TYPE_CHECKINGr   r   ry   rA   r   r?   _Inkr   r   r!  r6  r   r'  r   r3   r1   <module>rZ     s2  @ #   $  5 5  !  .3ZZ-?-?	* ?'UE#s(OS()b bJ#$ >B*:.( .2>>> #> +	>
 > 
>B@6@AD@PU@@D	F#	F-D	F
	Fr3   