
     fj                    R   U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZ ddlmZmZ ddlmZ ddlmZ d	ed
<   	 ej        j        Zn# e$ r dZY nw xY werddlmZmZ eeeedf         e f         Z!	  G d d          Z"d/d0dZ#	 d1d2dZ$	 	 d3d4d$Z%d5d+Z&d6d.Z'dS )7    )annotationsN)
ModuleType)TYPE_CHECKINGAnyStrCallableListSequenceTuple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<   dMdNd
ZdOdZdPdZ	 dMdQdZ	 	 dRdSdZ		 dMdTd Z
	 	 	 dUdVd"Z	 	 	 dUdWd#Z	 	 	 dUdXd&Z	 	 	 dYdZd)Z	 	 d[d\d,Z	 	 	 dUdVd-ZdMd]d.Z	 	 	 dUdWd/Z	 	 	 	 d^d_d4Z	 	 	 dUdWd5Z	 	 	 	 d^dd6d`d9Zdad=Zdbd?Zd@ Z	 	 	 	 	 	 	 	 	 	 	 dcdddFZ	 	 	 	 	 	 	 	 	 	 	 dcddGdddHZ	 	 	 	 	 deddGdfdIZ	 	 	 	 	 	 	 	 	 dgddGdhdKZ	 	 	 	 	 	 	 	 	 dgddGdhdLZdS )i	ImageDrawNNImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont | NonefontimImage.Imagemode
str | NonereturnNonec                P   |                                  |j        r|                                 d}||j        }||j        k    r%|dk    r|j        dk    rd}nd}t	          |          |dk    r|j        | _        nd| _        || _        |j        | _        t          j	        
                    | j        |          | _
        || _        |dv r | j
                            d          | _        n| j
                            d	          | _        |d
v rd| _        nd| _        d| _        dS )a  
        Create a drawing instance.

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

        To set the default font for this ImageDraw instance::

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

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

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

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

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

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

6
000Yty$',77Bxx	&&r35999beVbg%5tw?????/ ?:: %$r9   bounding_circle!Sequence[Sequence[float] | float]n_sidesrotationc                X    t          |||          }|                     ||||           dS )zDraw a regular polygon.N)!_compute_regular_polygon_verticesr   )r4   r   r   r   r3   r]   rT   rP   s           r7   regular_polygonzImageDraw.regular_polygon  s3     /RRRw.....r9   c                    |                      ||          \  }}|| j                            ||d           |+||k    r'|dk    r#| j                            ||d|           dS dS dS dS )zDraw a rectangle.Nr   r   )rO   r/   draw_rectanglere   s          r7   	rectanglezImageDraw.rectangle  s     Wd33XI$$R1555?sh5A::I$$Ra77777 ?::r9   )cornersr   $tuple[bool, bool, bool, bool] | Nonec                	    t          |d         t          t          f          r5t          t          t          t
                            |          \  \  \  n%t          t          t
                   |          \  k     rd}t          |          k     rd}t          |          d|dz  t                    t                    t                    t                    d\  t                    rBz
  dz
  k    rz
  z
  dz
  k    rz
  rr 	                    |||          S dk    st                    s                     |||          S t          dz            }                     ||          \  d fd}	  |	d           r- j                            |z   dz   |z
  dz
  fd           n, j                            |z   dz   |z
  dz
  fd           ss|z   g}
d         r|
dxx         |dz   z  cc<   d         r|
dxx         |dz   z  cc<    j                            |
d           |z
  g}d         r|dxx         |dz   z  cc<   d         r|dxx         |dz   z  cc<    j                            |d           k    rdk    r |	d           sz   dz
  g}d         r|dxx         |dz   z  cc<   d         r|dxx         |dz   z  cc<    j                            |d           z
  dz   g}d         r|dxx         |dz   z  cc<   d         r|dxx         |dz   z  cc<    j                            |d           sĉz   dz
  g}
d         r|
dxx         |dz   z  cc<   d         r|
dxx         |dz   z  cc<    j                            |
d           z
  dz   g}d         r|dxx         |dz   z  cc<   d         r|dxx         |dz   z  cc<    j                            |d           dS dS dS dS dS )zDraw a rounded rectangle.r   z&x1 must be greater than or equal to x0z&y1 must be greater than or equal to y0N)TTTTrq   )FFr   r   boolr   r   c                   rz   z   fddfz
  z   fddff}nrz   z   fddfz
  z   fddff}n`t          fdt          z   z   fddfz
  z   fddfz
  z
  fddfz
  z   fddff          D                       }|D ]-}| r 	j        j        |dfz      	j        j        |
fz     .d S )Nr   rw   r   r     c              3  2   K   | ]\  }}|         |V  d S rG    )rs   rt   partr   s      r7   r   zDImageDraw.rounded_rectangle.<locals>.draw_corners.<locals>.<genexpr>  sG        4 qz     r9   r   )rr   	enumerater/   r   rW   )r   partsr   r   dra   full_xfull_yr1   r4   rT   x0x1y0y1s      r7   draw_cornersz1ImageDraw.rounded_rectangle.<locals>.draw_corners  s     "b1fb1f-sC8"q&"q&"-q#6   "b1fb1f-r371fb"b1f-sB7     #, "b1fb1f5sC@ 1fb"b1f5sC@ 1fb1fb"5q"= "q&"q&"5r3?	$ $      ? ? ?+DI+dh].BDDD&DI&e)<>>>	? ?r9   Tr   F)r   r   r   r   )rH   r   rr   r   r	   rR   r+   roundallrf   anyr   rU   rO   r/   r   )r4   rP   rh   r3   r]   rT   r   r6   rr   leftrighttopbottomr   ra   r   r   r1   r   r   r   r   s   `    ``       @@@@@@@@@r7   rounded_rectanglezImageDraw.rounded_rectangle  s    bedE]++ 	7!%hx&?!D!DHRhr22!(5/266NBB77:CS//!77:CS//!?.GQJ2YY2YY2YY2YY%w<< 	>"r'A+%F G"r'A+%F G >& >||Bgu===66W6 >>"dGU;;;QKKWd33X 	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?  	?D L X	(("b1fqj"b1fqj)I8UVWWWW	(("q&1*b"q&1*b)I8UVWWW =& =BQ+1: %GGGq1u$GGG1: %GGGq1u$GGG	((x;;;aR,1: &!HHHA%HHH1: &!HHHA%HHH	((!<<<?sh5A::L 92r2:>21: $FFFa!eOFFF1: $FFFa!eOFFF	((c1555b5j1nb"51: '1IIIQ&III1: '1IIIQ&III	((a888 8BU
Q31: %GGGq1u$GGG1: %GGGq1u$GGG	((sA666eaR41: &!HHHA%HHH1: &!HHHA%HHH	((Q77777= ?::"8 8r9   textr   r   c                <    t          |t                    rdnd}||v S N
   
)rH   rI   )r4   r   split_characters      r7   _multiline_checkzImageDraw._multiline_check+  s%    ",T3"7"7B$$U$&&r9   list[AnyStr]c                Z    |                     t          |t                    rdnd          S r   )splitrH   rI   )r4   r   s     r7   _multiline_splitzImageDraw._multiline_split0  s'    zz*T3"7"7B$$UCCCr9   c                L    |                      dd||          d         |z   |z   S )Nr   A)stroke_widthr   )textbbox)r4   r   spacingr   s       r7   _multiline_spacingzImageDraw._multiline_spacing3  s3    MM&#t,MGGJ	
r9   ro   r   Ftuple[float, float]rI   c                   	
 r j         dvrd}t          |          (                                         d                                                   r!                     |||	
||          S d fd	}dd	
 fd} ||          }|<d}|r| ||          n|}| |||            ||d
           dS  ||           dS dS )z
Draw text.r!   r    3Embedded color supported only in RGB and RGBA modesNr@   r3   rD   r   rU   c                H                         |           \  }}||J |S |S rG   )rO   )r3   r1   ra   r4   s      r7   getinkzImageDraw.text.<locals>.getinkj  s3     LL..MC{+++Jr9   r   r   c                   j         }|dk    rrd}g }g }t          d          D ]]}|                    t          |                              |                    t	          j        |                   d                    ^	  j        |gR || |d\  }}|d         |d         z   |d         |d         z   g}nQ# t          $ rD 	  j        ||| gR d|i}n%# t          $ r                               }Y nw xY wY nw xY w|r"|d         |d         z   |d         |d         z   g}|dk    r||
                    d          }}	t          j        d|           d         }
|	                    d|
           |\  }}j        >j                            |	||||j        d         z   ||j        d         z   f|           d S d S j                            |||            d S )	Nr   r    rq   )	directionfeatureslanguager   anchorr1   rQ   r   rQ   r   rt   )r2   r   appendrU   rx   modfgetmask2AttributeErrorgetmask	TypeErrorgetbandstructpackfillbandr   r   r   r/   r\   )r1   r   stroke_offsetr   r{   rQ   rt   r   offsetcolor	ink_alphar   r   r   argsr   embedded_colorr   r   kwargsr   r4   r   rP   s                r7   	draw_textz!ImageDraw.text.<locals>.draw_textq  s   =Dq  ^ EE1XX 2 2SAZZ(((TYr!u--a01111.,t}      (%%!-!       f qF1I-uQx&)/CD! . . ..'4<!  $    $ ! DD ! . . .<<--DDD.."  SqM!$44eAhqAQ6QRv~~ #DLLOOt"KS11!4	q),,,17&GMM1a$)A,&6DIaL8HI4     '&
 	%%eT377777s6   ?C 
DC+*D+D
DDDD)r3   rD   r   rU   r   )r   r   )r   r+   rC   getr   multiline_text)r4   rP   r   r3   r   r   r   alignr   r   r   r   stroke_fillr  r  r  r6   r   r  r1   
stroke_inks   ``` ``  ```  ```     r7   r   zImageDraw.text:  s   0  	"di>>GCS//!<==K!8!899D  && 	&&   	 	 	 	 	 	7	8 7	8 7	8 7	8 7	8 7	8 7	8 7	8 7	8 7	8 7	8 7	8 7	8 7	8 7	8 7	8 7	8r fTll?J U4?4KVVK000QT
%	*l333 	#q!!!!! 	# ?r9   )r@   c                  |dk    rd}t          |          |d}n?t          |          dk    rd}t          |          |d         dv rd}t          |          ||                     |          }g }d	}|                     |          }|                     |||          }|D ]A}|                     ||||	|

          }|                    |           t          ||          }B|d         }|d         dk    r|t          |          dz
  |z  dz  z  }n$|d         dk    r|t          |          dz
  |z  z  }t          |          D ]\  }}|d	         }|||         z
  }|d	         dk    r	||dz  z  }n|d	         dk    r||z  }|dk    rn,|dk    r	||dz  z  }n|dk    r||z  }nd}t          |          | 	                    ||f||||||	|
|||           ||z  }d S )Nttb/ttb direction is unsupported for multiline textlarq   #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   rC   r   r   
textlengthr   maxr   r   )r4   rP   r   r3   r   r   r   r	  r   r   r   r   r
  r  r@   r6   widths	max_widthlinesline_spacingr   
line_widthr   idxr   width_differences                             r7   r  zImageDraw.multiline_text  s   . CCS//!>FF[[A7CS//!AY$;CS//!<==++D	%%d++..tWlKK 	3 	3Ddi(X )  J MM*%%%Iz22IIe!9CJJNl2S88CCAY#CJJNl22C"5)) "	  "	 ICa5D(6#;6 ayC(3..c!!(( (""(3..'!!((A oo%IIs#!!)'-     <CCE"	  "	 r9   c                   |                      |          rd}t          |          |r| j        dvrd}t          |          ||                     |          }|rdn| j        }	|                    ||	|||          S )z@Get the length of a given string, in pixels with 1/64 precision.z&can't measure length of multiline textr   r   Nr    )r   r+   r   rC   r2   	getlength)
r4   r   r   r   r   r   r  r@   r6   r   s
             r7   r  zImageDraw.textlength  s    "   && 	":CS//! 	"di>>GCS//!<==++D':vvT]~~dD)XxHHHr9   tuple[int, int, int, int]c                  |r| j         dvrd}t          |          ||                     |          }|                     |          r|                     |||||||||	|
|          S |rdn| j        }|                    |||||	|
|          }|d         |d         z   |d         |d         z   |d         |d         z   |d         |d         z   fS )	z2Get the bounding box of a given string, in pixels.r   r   Nr    r   r   rq   r   )r   r+   rC   r   multiline_textbboxr2   getbbox)r4   rP   r   r   r   r   r	  r   r   r   r   r  r@   r6   r   bboxs                   r7   r   zImageDraw.textbbox3  s   "  	"di>>GCS//!<==++D  && 	**   (:vvT]||$	8X|V
 
 AwAQ"Q%a2a5$q'BqE/QQr9   c                  |dk    rd}t          |          |d}n?t          |          dk    rd}t          |          |d         dv rd}t          |          ||                     |          }g }d	}|                     |          }|                     |||
          }|D ]B}|                     |||||	|
          }|                    |           t          ||          }C|d         }|d         dk    r|t          |          dz
  |z  dz  z  }n$|d         dk    r|t          |          dz
  |z  z  }d }t          |          D ]
\  }}|d	         }|||         z
  }|d	         dk    r	||dz  z  }n|d	         dk    r||z  }|dk    rn,|dk    r	||dz  z  }n|dk    r||z  }nd}t          |          | 	                    ||f||||||	|
|	  	        }||}nnt          |d	         |d	                   t          |d         |d                   t          |d         |d                   t          |d         |d                   f}||z  }||d	         |d         |d	         |d         fS |S )Nr  r  r  rq   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   rC   r   r   r  r   r  r   r   min)r4   rP   r   r   r   r   r	  r   r   r   r   r  r@   r6   r  r  r  r  r   r  r   r&  r  r   r  	bbox_lines                             r7   r$  zImageDraw.multiline_textbbox`  s     CCS//!>FF[[A7CS//!AY$;CS//!<==++D	%%d++..tWlKK 
	3 
	3D#!!- )  J MM*%%%Iz22IIe!9CJJNl2S88CCAY#CJJNl22C15"5)) *	  *	 ICa5D(6#;6 ayC(3..c!!(( (""(3..'!!((A oo%s#!!)- & 
 
I |  Q1..Q1..Q1..Q1..	 <CC<a5"Q%A1--r9   rG   )r   r   r   r   r   r   )r   r:   )r@   rA   r   r:   )r1   rD   r3   rD   r   rE   )Nr   )rP   r   rQ   rR   rS   rR   r3   rD   rT   rU   r   r   )rP   rY   rZ   r   r3   rD   r   r   )NNr   )rP   r   rQ   rR   rS   rR   r3   rD   r]   rD   rT   rU   r   r   )
rP   r   r3   rD   r]   rD   rT   rU   r   r   )rP   rg   rh   rR   r3   rD   r]   rD   rT   rU   r   r   )Nr   N)
rP   r   r3   rD   rT   rU   rl   r   r   r   NN)r   r   r3   rD   r]   rD   r   r   )rP   r   r3   rD   r   r   )r   NNr   )r   r   r   rU   r   rR   r3   rD   r]   rD   rT   rU   r   r   )rP   r   rh   rR   r3   rD   r]   rD   rT   rU   r   r   r   r   )r   r   r   r   )r   r   r   r   )NNNro   r   NNNr   NF)rP   r   r   rI   r   r   r   r   )NNNNF)r   rI   r   r   r   rR   )	NNro   r   NNNr   F)r   r"  )__name__
__module____qualname__r   __annotations__r8   r?   rC   rO   rX   rZ   rb   rf   rk   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r$  r   r9   r7   r   r   @   s6         	 	    ( ( ( ( (T   6" " " " 59' ' ' ' '< !; ; ; ; ; KO	6 	6 	6 	6 	6  !#@ @ @ @ @& !#6 6 6 6 6$ !#
7 
7 
7 
7 
7 ! K= K= K= K= K=` !#	2 2 2 2 2& !#C C C C C + + + + + !#"@ "@ "@ "@ "@P  #/ / / / /  !#8 8 8 8 8"  #J8 9=J8 J8 J8 J8 J8 J8X' ' ' '
D D D D
 
 
  '~ ~ ~ ~ ~H  'Z * +Z  Z  Z  Z  Z  Z H I I I I I I IB +R +R +R +R +R +R +Rb f f f f f f f f fr9   r   r   r   r   r   r   c                v    	  t          | d          |          S # t          $ r t          | |          cY S w xY w)a  
    A simple 2D drawing interface for PIL images.

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

    Fills a bounded region with a given color.

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

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

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

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

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

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