%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/PIL/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/PIL/__pycache__/ImageDraw.cpython-312.pyc

�

��eS����ddlmZddlZddlZddlZddlmZmZ	Gd�d�Zdd�Z		ejjZd
d�Zdd	�Zd
�Zd�Zy#e
$rdZY�wxYw)�)�annotationsN�)�Image�
ImageColorc�B�eZdZdZdd�Zd�Zd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zd d�Z
dd�Zdd
�Zdd�Z	d!d�Zdd�Z	d!dd�d�Zd�Zd�Zd�Z											d"d�Z											d"dd�d�Z					d#dd�d�Z									d$dd�d�Z									d$dd�d�Zy)%�	ImageDrawNc��|j�|jr|j�d}|�|j}||jk7r$|dk(r|jdk(rd}n
d}t	|��|dk(r|j
|_nd|_||_|j|_tjj|j|�|_
||_|dvr!|jjd�|_n |jjd	�|_|d
vrd|_
d
|_yd|_
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.
        rN�RGBA�RGBrz
mode mismatch�P)�I�F���)�1rr
rr�LF)�load�readonly�_copy�mode�
ValueError�palette�_image�imr�core�draw�draw_ink�ink�fontmode�fill)�selfrr�blend�msgs     �//usr/lib/python3/dist-packages/PIL/ImageDraw.py�__init__zImageDraw.__init__3s
��	���	�
�;�;��H�H�J����<��7�7�D��2�7�7�?��v�~�"�'�'�U�"2���%�� ��o�%��3�;��:�:�D�L��D�L�����%�%����J�J�O�O�D�G�G�U�3��	���	��:���y�y�)�)�!�,�D�H��y�y�)�)�"�-�D�H��'�'��D�M���	� �D�M���	�c�h�|jsddlm}|j�|_|jS)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��	ImageFont)�font�r(�load_default)r r(s  r#�getfontzImageDraw.getfont]s(��$�y�y�#�!�.�.�0�D�I��y�y�r%c�\�|�ddlm}|j|�}|S|j�}|S)Nrr')r*r(r+r,)r �	font_sizer(r)s    r#�_getfontzImageDraw._getfontvs4��� �#��)�)�)�4�D����<�<�>�D��r%c���|�.|�,|jr|j}||fS|j}||fS|��t|t�r t	j
||j�}|jr@t|tj�s&|jj||j�}|jj|�}|��t|t�r t	j
||j�}|jr@t|tj�s&|jj||j�}|jj|�}||fS�N)
rr�
isinstance�strr�getcolorrr�numbers�Numberrrr)r rrs   r#�_getinkzImageDraw._getinks���;�4�<��y�y��x�x�� �D�y���h�h���D�y�����c�3�'�$�-�-�c�4�9�9�=�C��<�<�
�3����(G��,�,�/�/��T�[�[�A�C��i�i�(�(��-�����d�C�(�%�.�.�t�T�Y�Y�?�D��<�<�
�4����(H��<�<�0�0��t�{�{�C�D��y�y�)�)�$�/���D�y�r%c�p�|j|�\}}|� |jj|||||�yy)zDraw an arc.N)r7r�draw_arc)r �xy�start�endr�widthrs       r#�arcz
ImageDraw.arc�s8���L�L��&�	��T��?��I�I���r�5�#�s�E�:�r%c��|j�|j|�\}}|�|}|�(|jj||j|�yy)zDraw a bitmap.N)rr7r�draw_bitmapr)r r:�bitmaprrs     r#rAzImageDraw.bitmap�sK�����
��L�L��&�	��T��;��C��?��I�I�!�!�"�f�i�i��5�r%c���|j||�\}}|�|jj||||d�|�-||k7r'|dk7r!|jj||||d|�yyyy)z
Draw a chord.Nrr)r7r�
draw_chord�r r:r;r<r�outliner=rs        r#�chordzImageDraw.chord�sl���L�L��$�/�	��T����I�I� � ��U�C��q�9��?�s�d�{�u��z��I�I� � ��U�C��a��?�0:�{�?r%c���|j||�\}}|�|jj||d�|�+||k7r%|dk7r|jj||d|�yyyy)zDraw an ellipse.Nrr)r7r�draw_ellipse�r r:rrEr=rs      r#�ellipsezImageDraw.ellipse�sd���L�L��$�/�	��T����I�I�"�"�2�t�Q�/��?�s�d�{�u��z��I�I�"�"�2�s�A�u�5�0:�{�?r%c
�x��|j|�d}|��|jj||��|dk(�r�dkD�r�t|dtt
f�s2t
dt|�d�D�cgc]}t|||dz���}}t
dt|�dz
�D�]�}||}||dz
|f|||dzffD��	cgc]C\}}	tjtj|	d|dz
|d|	dz
��dz��E}
}}	|
d|
dk(r�w�fd�}|
d|
dkDxr|
dd	z
|
dkDxs|
d|
dkxr|
dd	z|
dkD}|d�dzz
dz|d�dzz
dzf|d�dzzdz
|d�dzzdz
fg}
|r|
dd
z|
dd
z}	}n|
dd
z
|
dd
z
}	}|j|
|d
z
|	d
z
|��dkDs��0|r |||
dd
z�||||
dd
z�g}n|||
dd
z
�||||
dd
z
�g}|j||d�
����yyyycc}wcc}	}w)z6Draw a line, or a connected sequence of line segments.rN�curve��r�hc���|\}}|dz}�dzdz
}td�||tjtj|��zf||tjtj|��zffD��S)N�ZrNrc3�K�|]9\}}||dkDrtj|�ntj|�z���;y�w�rN)�math�floor�ceil)�.0�p�p_ds   r#�	<genexpr>z9ImageDraw.line.<locals>.coord_at_angle.<locals>.<genexpr>�s9����%� &��3��C�!�G����C�����3��P�%�s�?A)�tuplerT�cos�radians�sin)�coord�angle�x�y�distancer=s     �r#�coord_at_anglez&ImageDraw.line.<locals>.coord_at_angle�s~���$���1�����#(�1�9�q�=��$�%�"#�H�t�x�x����U�8K�/L�$L� M�!"�H�t�x�x����U�8K�/L�$L� M�+�%� �r%�rQ��)r=)
r7r�
draw_linesr2�listr[�range�lenrT�degrees�atan2�pieslice�line)r r:rr=�jointr�i�pointr;r<�anglesrd�flipped�coords�
gap_coordss   `           r#rozImageDraw.line�s�����l�l�4� ��#���?��I�I� � ��S�%�0����E�A�I�!�"�Q�%�$���7�8=�a��R��!�8L�M�1�%��1�q�1�u�
�.�M�B�M��q�#�b�'�A�+�.�2=�A��q�E�E�-/�q�1�u�I�u�+=��r�!�a�%�y�?Q�*R��'�E�3����T�Z�Z��A���q��0A�5��8�c�RS�f�CT�%U�V����F��
�a�y�F�1�I�-� �
��q�	�F�1�I�-�M�&��)�c�/�F�1�I�2M�Q� ��)�f�Q�i�/�O�F�1�I��O�f�Q�i�4O���q��E�A�I�-��1�5��8�e�a�i�3G�!�3K�L��q��E�A�I�-��1�5��8�e�a�i�3G�!�3K�L��F��&,�Q�i�"�n�f�Q�i�"�n�s��&,�Q�i�"�n�f�Q�i�"�n�s���M�M�&�%�"�*�c�B�h��E��q�y�"� .�u�f�Q�i�"�n� E� %� .�u�f�Q�i�"�n� E�*�J�!/�u�f�Q�i�"�n� E� %� .�u�f�Q�i�"�n� E�*�J�
�	�	�*�d�!�	�<�e2=�%.����N��s
�3H1�AH6c���|j�|j||�\}}|�|jj||d�|�$||k7r|jj||d�yyy)z(Experimental) Draw a shape.Nrr)�closer7r�draw_outline)r �shaperrErs     r#rzzImageDraw.shape�sc��
���
��L�L��$�/�	��T����I�I�"�"�5�$��2��?�s�d�{��I�I�"�"�5�#�q�1� +�?r%c���|j||�\}}|�|jj||||d�|�-||k7r'|dk7r!|jj||||d|�yyyy)zDraw a pieslice.Nrr)r7r�
draw_pieslicerDs        r#rnzImageDraw.pieslice�sl���L�L��$�/�	��T����I�I�#�#�B��s�D�!�<��?�s�d�{�u��z��I�I�#�#�B��s�C��E�B�0:�{�?r%c�j�|j|�\}}|�|jj||�yy)z#Draw one or more individual pixels.N)r7r�draw_points)r r:rrs    r#rrzImageDraw.points2���L�L��&�	��T��?��I�I�!�!�"�c�*�r%c��|j||�\}}|�|jj||d�|���||k7�r�|dk7�r�|dk(r|jj||d|�ytjd|j
j�}|jd�d}|j�}t|�}	|	jj||d�|j�}
t|
�}	|dzdz
}|	jj||d|�|j|
|��tj|j|j
j�}t|�}	|	jj||d|�|j
j|j
d|jz|j
�yyyy)zDraw a polygon.NrrrrN)�mask�rr)r7r�draw_polygonr�newr�size�copy�Draw�paster)r r:rrEr=rr��mask_ink�fill_imr�ink_imrs            r#�polygonzImageDraw.polygonsl���L�L��$�/�	��T����I�I�"�"�2�t�Q�/��?�s�d�{�u��z���z��	�	�&�&�r�3��5�9��y�y��d�g�g�l�l�3���<�<��?�1�-���)�)�+���G�}���	�	�&�&�r�8�Q�7�������F�|����	�A�
���	�	�&�&�r�8�Q��>��
�
�6��
�0��Y�Y�t�y�y�$�'�'�,�,�7���B�x���	�	�&�&�r�3��5�9����
�
�b�e�e�V�b�g�g�%5�t�w�w�?�/0:�{�?r%c�F�t|||�}|j||||�y)zDraw a regular polygon.N)�!_compute_regular_polygon_verticesr�)r �bounding_circle�n_sides�rotationrrEr=r:s        r#�regular_polygonzImageDraw.regular_polygon$s$��/����
R�����R��w��.r%c���|j||�\}}|�|jj||d�|�+||k7r%|dk7r|jj||d|�yyyy)zDraw a rectangle.Nrr)r7r�draw_rectanglerIs      r#�	rectanglezImageDraw.rectangle+sd���L�L��$�/�	��T����I�I�$�$�R��q�1��?�s�d�{�u��z��I�I�$�$�R��a��7�0:�{�?r%)�cornersc���������������t|dttf�r|\\��\��n|\������kr
d}t|����kr
d}t|����d�|dz�d\��t	��r<���z
dz
k\��r��z
����z
dz
k\��r��z
��r�r�j|�|��S�dk(st
��s�j|�|��S�dz}�j|��\��������������fd	�}	���	|	d
��r.�jj��|zdz��|z
dz
f�d�n-�jj�|zdz��|z
dz
�f�d��s��s����|z�g}
�dr|
dxx|dzz
cc<�dr|
dxx|dzzcc<�jj|
�d��|z
���g}�dr|dxx|dzz
cc<�dr|dxx|dzzcc<�jj|�d����h��k7�ra�dk7�rZ|	d��s������zdz
g}�dr|dxx|dzz
cc<�dr|dxx|dzzcc<�jj|�d����z
dz��g}
�dr|
dxx|dzz
cc<�dr|
dxx|dzzcc<�jj|
�d��s�����zdz
�g}
�dr|
dxx|dzz
cc<�dr|
dxx|dzzcc<�jj|
�d���z
dz���g}�dr|dxx|dzz
cc<�dr|dxx|dzzcc<�jj|�d�yyyyy)
zDraw a rounded rectangle.rz&x1 must be greater than or equal to x0z&y1 must be greater than or equal to y0N)TTTTrN)FFrc	�����r����z��zfddf���z
��z�fddff}n��r����z��zfddf�
�z
��
��zfddff}ndg}t����z��zfddf�
�z
��
��zfddf�
�z
��z
�
�fddf���z
��z�fddff�D]\}}�|s�|j|��|D]A}|r�
jj|�dfz��$�
jj|�	�fz��Cy)NrerOrrQ�r)�	enumerate�appendrr|r9)rn�partsrq�partr��dr�full_x�full_yrr r=�x0�x1�y0�y1s    ������������r#�draw_cornersz1ImageDraw.rounded_rectangle.<locals>.draw_corners]s|�����"�b�1�f�b�1�f�-�s�C�8��"�q�&�"�q�&�"�-�q�#�6�����"�b�1�f�b�1�f�-�r�3�7��1�f�b�"�b�1�f�-�s�B�7�����(��b�"�q�&�"�q�&�1�3��<��q�&�"�b�"�q�&�1�3��<��q�&�"�q�&�"�b�1�1�b�9��b�1�f�b�1�f�b�1�2�s�;�	� �	+�G�A�t��q�z����T�*�	+��
?���+�D�I�I�+�+�d�d�A�Y�.>�@�&�D�I�I�&�&���e��)<�>�	
?r%TrgF)r2rir[r�allrJ�anyr�r7rr�)r r:�radiusrrEr=r�r"�rr��left�right�top�bottomr�r�r�rr�r�r�r�s`  ` ``       @@@@@@@@r#�rounded_rectanglezImageDraw.rounded_rectangle3s������b��e�d�E�]�+�!#��H�R��h�r�2��N�B��B��
��7�:�C��S�/�!�
��7�:�C��S�/�!��?�.�G��Q�J��%�����w�<��"�r�'�A�+�%�F����G���"�r�'�A�+�%�F����G���&��|�|�B��g�u�=�=���6��W���>�>�"�d�G�U�;�;�
��F���L�L��$�/�	��T�	?�	?�@�������	�	�(�(�"�b�1�f�q�j�"�b�1�f�q�j�)I�4�QR�S��	�	�(�(�"�q�&�1�*�b�"�q�&�1�*�b�)I�4�QR�S��&��B��Q���+���1�:���G�q�1�u�$�G��1�:���G�q�1�u�$�G��	�	�(�(��t�Q�7��a���R��,���1�:��!�H��A��%�H��1�:��!�H��A��%�H��	�	�(�(���a�8��?�s�d�{�u��z������2�r�2��:��>�2���1�:���F�a�!�e�O�F��1�:���F�a�!�e�O�F��	�	�(�(��c�1�5��b�5�j�1�n�b�"�5���1�:��1�I��Q��&�I��1�:��1�I��Q��&�I��	�	�(�(���a�8���B��U�
�Q���3���1�:���G�q�1�u�$�G��1�:���G�q�1�u�$�G��	�	�(�(��s�A�6��e��a���R��4���1�:��!�H��A��%�H��1�:��!�H��A��%�H��	�	�(�(���Q�7��#0:�{�?r%c�2�t|t�rdnd}||vS�N�
�
)r2r3�r �text�split_characters   r#�_multiline_checkzImageDraw._multiline_check�s��",�T�3�"7�$�U���$�&�&r%c�L�t|t�rdnd}|j|�Sr�)r2r3�splitr�s   r#�_multiline_splitzImageDraw._multiline_split�s!��",�T�3�"7�$�U���z�z�/�*�*r%c�>�|jdd||��d|z|zS)Nr��A)�stroke_widthrg)�textbbox)r r)�spacingr�s    r#�_multiline_spacingzImageDraw._multiline_spacing�s0���M�M�&�#�t�,�M�G��J��
��
�	
r%c��������	�
�
����
r�jdvr
d}t|���� �j�jd����j	��r�j��|��||��	�
||�
�
S�fd�}d����
�	���
���fd�	}||�}|�.d}|r|�||�n|}|�|||�||d�y||�yy)	z
Draw text.�rr
�3Embedded color supported only in RGB and RGBA modesNr.c�8���j|�\}}|�|S|Sr1)r7)rrr s  �r#�getinkzImageDraw.text.<locals>.getink�s$������T�*�I�C���{����Jr%rc�x���j}|dk(r�rd}g}g}td�D]I}|jt�|��|jt	j
�|�d��K	�j�|g������|�
||d����\}}|d|dz|d|dzf}|r|d|dz|d|dzf}|dk(r�||jd�}}	tjd|�d}
|	jd|
�|\}}�jj|	||||j dz||j dzf|�y�j"j%|||�y#t$rE	�j�|���|�
|g���d|i���}n #t$r�j��}YnwxYwY��
wxYw)	Nrr
rN)�	direction�features�languager��anchorrr;rr;rgrq)rrjr��intrT�modf�getmask2�AttributeError�getmask�	TypeError�getband�struct�pack�fillbandrr�r�rr@)rr��
stroke_offsetrr_r;rqr��offset�color�	ink_alphararbr��argsr��embedded_colorr�r)�kwargsr�r r�r:s             �����������r#�	draw_textz!ImageDraw.text.<locals>.draw_text�s����=�=�D��q� �^����E��E��1�X�
2�����S��A��Z�(����T�Y�Y�r�!�u�-�a�0�1�
2�
.�,�t�}�}��� �� �(�%�%�!-�!��� �� ���f��a��6�!�9�,�e�A�h����.B�B��$��a��=��#3�3�U�1�X�
�a�@P�5P�P���v�~�#�D�L�L��O�t��"�K�K��S�1�!�4�	����q�)�,����1����
�
�e�a��A��	�	�!��,<�a�$�)�)�A�,�>N�%O�QU�V��	�	�%�%�e�T�3�7��9"�
.�.�'�4�<�<���!� � �$������$��!��D��!�.��<�<��-�D�.��
.�s6�38E+�+	F9�5F�F9�F2�/F9�1F2�2F9�8F9rS)rrr/�getr��multiline_text)r r:r�rr)r�r��alignr�r�r�r��stroke_fillr�r�r�r"r�r�r�
stroke_inks``` ``  ```  ```     r#r�zImageDraw.text�s�����&�d�i�i��>�G�C��S�/�!��<��=�=����K�!8�9�D�� � ��&��&�&���������������
� 	�4	8�4	8�l�T�l���?��J��4?�4K�V�K�0�QT�
��%��*�l�3��#�q�!��#��r%)r.c��|dk(r
d}t|��|�d}n/t|�dk7r
d}t|��|ddvr
d}t|��|�|j|�}g}d	}|j|�}|j	|||�}|D]5}|j||||	|
�
�}|j
|�t||�}�7|d}|ddk(r|t|�dz
|zdzz}n|dd
k(r|t|�dz
|zz}t|�D]\}}|d	}|||z
}|d	dk(r	||dzz}n
|d	dk(r||z}|dk(rn&|dk(r	||dzz
}n|dk(r||z
}n
d}t|��|j||f||||||	|
|||
��||z
}��y)N�ttb�/ttb direction is unsupported for multiline text�larN�#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�)
rrkr/r�r��
textlengthr��maxr�r�)r r:r�rr)r�r�r�r�r�r�r�r�r�r.r"�widths�	max_width�lines�line_spacingro�
line_widthr��idxr��width_differences                          r#r�zImageDraw.multiline_text:s'��$���C�C��S�/�!��>��F�
��[�A�
�7�C��S�/�!�
�A�Y�$�
�;�C��S�/�!��<��=�=��+�D����	��%�%�d�+���.�.�t�W�l�K���	3�D�����d�i�(�X�)��J�
�M�M�*�%��I�z�2�I�	3���e���!�9����C��J��N�l�2�S�8�8�C�
�A�Y�#�
��C��J��N�l�2�2�C�"�5�)�"	 �I�C���a�5�D�(�6�#�;�6���a�y�C���(�3�.�.�����c�!��(�(�������(�"��(�3�.�.���'�!��(�(��A�� ��o�%��I�I��s������#�!�!�)�'�-�
�
�
�<��C�E"	 r%c���|j|�r
d}t|��|r|jdvr
d}t|��|�|j|�}|rdn|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�rrr/r�	getlength)
r r�r)r�r�r�r�r.r"rs
          r#r�zImageDraw.textlength�su��� � ��&�:�C��S�/�!��d�i�i��>�G�C��S�/�!��<��=�=��+�D�'�v�T�]�]���~�~�d�D�)�X�x�H�Hr%c
�\�|r|jdvr
d}
t|
��|�|j|�}|j|�r|j	|||||||||	|
|�S|rdn|j
}|j
|||||	|
|�}|d|dz|d|dz|d|dz|d|dzfS)z2Get the bounding box of a given string, in pixels.r�r�r
rrrNrg)rrr/r��multiline_textbboxr�getbbox)r r:r�r)r�r�r�r�r�r�r�r�r.r"r�bboxs                r#r�zImageDraw.textbbox�s���"�d�i�i��>�G�C��S�/�!��<��=�=��+�D�� � ��&��*�*�������������
�(�v�T�]�]���|�|��$�	�8�X�|�V�
���A�w��A����Q��"�Q�%���a��2�a�5��$�q�'�B�q�E�/�Q�Qr%c���|dk(r
d}
t|
��|�d}n/t|�dk7r
d}
t|
��|ddvr
d}
t|
��|�|j|�}g}d	}|j|�}|j	|||
�}|D]6}|j|||||	|�
�}|j
|�t||�}�8|d}|ddk(r|t|�dz
|zdzz}n|dd
k(r|t|�dz
|zz}d}t|�D]�\}}|d	}|||z
}|d	dk(r	||dzz}n
|d	dk(r||z}|dk(rn&|dk(r	||dzz
}n|dk(r||z
}n
d}
t|
��|j||f||||||	|
|��	}|�|}nFt|d	|d	�t|d|d�t|d|d�t|d|d�f}||z
}��|�|d	|d|d	|dfS|S)Nr�r�r�rNr�rr�r�r)r�r�r�r�r�r�r�r�r�r�r�r�)r�r�r�r�r�rg)rrkr/r�r�r�r�r�r�r��min)r r:r�r)r�r�r�r�r�r�r�r�r.r"r�r�r�r�ror�r�r�r�r�r��	bbox_lines                          r#r�zImageDraw.multiline_textbbox�s��� ���C�C��S�/�!��>��F�
��[�A�
�7�C��S�/�!�
�A�Y�$�
�;�C��S�/�!��<��=�=��+�D����	��%�%�d�+���.�.�t�W�l�K���
	3�D������#�!�!�-�
)��J�
�M�M�*�%��I�z�2�I�
	3���e���!�9����C��J��N�l�2�S�8�8�C�
�A�Y�#�
��C��J��N�l�2�2�C���"�5�)�*	 �I�C���a�5�D�(�6�#�;�6���a�y�C���(�3�.�.�����c�!��(�(�������(�"��(�3�.�.���'�!��(�(��A�� ��o�%��
�
��s�����#�!�!�)�-�&�
�I��|� ����Q���1��.���Q���1��.���Q���1��.���Q���1��.�	��
�<��C�U*	 �X�<��a�5�"�Q�%��A���1��-�-��r%r1)Nr)NNr)NrN�NN)rNNr)NNNrMr�NNNrNF)NNNNF)	NNrMr�NNNrF)�__name__�
__module__�__qualname__r)r$r,r/r7r>rArFrJrorzrnrrr�r�r�r�r�r�r�r�r�r�r�r��r%r#rr0s`���D�(�T�2��*;�6�@�6�:=�x2�C�+�@�>TU�/�8�<=�}8�IM�}8�~'�
+�

��
����������u�v�
����������U � �!U �t�����I��I�8���������+R��+R�b���������f��fr%rc�\�	|j|�S#t$rt||�cYSwxYw)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.
    )�getdrawr�r)rrs  r#r�r�?s2��#��z�z�$�����#���T�"�"�#�s��+�+c�|�d}|rd|vr	ddlm}|�ddlm}|r|j	|�}||fS#t$rY�*wxYw)a
    (Experimental) A more advanced 2D drawing interface for PIL images,
    based on the WCK interface.

    :param im: The image to draw in.
    :param hints: An optional list of hints.
    :returns: A (drawing context, drawing resource factory) tuple.
    N�nicestr)�_imagingagg)�
ImageDraw2)r*r�ImportErrorrr�)r�hints�handlers   r#rrWsT���G��H��%�	�0���+�	�
�\�\�"�
��
�w�;���
�	��	�s�/�	;�;c� �|j�}|\}}	|||f}t||�|kry||||f<||fh}	t	�}
|	r�t	�}|	D]�\}}|dz|f|dz
|f||dzf||dz
ffD]f\}}
||
f|
vs
|dks|
dkr�	|||
f}|
j||
f�|�t||�|k}n|||fv}|s�M||||
f<|j||
f��h��|	}
|}	|	r��yy#ttf$rYywxYw#ttf$rY��wxYw)a�
    (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.
    Nrr)r�_color_diffr�
IndexError�set�add)�imager:�value�border�thresh�pixelrarb�
background�edge�	full_edge�new_edge�s�trXrs                r#�	floodfillros}��&
�J�J�L�E�
�D�A�q���1�a�4�[�
��u�j�)�V�3����a��d����F�8�D���I�
��5���	-�D�A�q��a�%���a�!�e�Q�Z�!�Q��U��a��Q��Z�H�
-���1��q�6�Y�&�!�a�%�1�q�5��-��a��d��A��M�M�1�a�&�)��~�*�1�j�9�V�C�� ����7���&+��a��d�� ���a��V�,�!
-�	-�$�	���+��

�
�#�����#�J�/����s(�C&�C&�
C;�&C8�7C8�;D
�D
c�\�
�t|t�s
d}t|��|dkr
d}t|��t|tt
f�s
d}t|��t
|�dk(r|�^}}n!t
|�dk(r|\}}n
d}t|��td�g|�|��D��s
d}t|��t
|�dk(s
d	}t|��|d
kr
d}t|��t|ttf�s
d}t|��d
��
�
fd�}d�}|||�}|D�	cgc]}	||||	���c}	Scc}	w)u�
    Generate a list of vertices for a 2D regular polygon.

    :param bounding_circle: The bounding circle is a tuple 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
    zn_sides should be an intrgzn_sides should be an int > 2z!bounding_circle should be a tuplerNz[bounding_circle should contain 2D coordinates and a radius (e.g. (x, y, r) or ((x, y), r) )c3�HK�|]}t|ttf����y�wr1)r2r��float)rWrqs  r#rZz4_compute_regular_polygon_vertices.<locals>.<genexpr>�s����P�q�z�!�c�5�\�*�P�s� "z0bounding_circle should only contain numeric datazBbounding_circle centre should contain 2D coordinates (e.g. (x, y))rz$bounding_circle radius should be > 0z"rotation should be an int or floatc���t|dtjtjd|z
��z|dtjtjd|z
��zz
|dzd�t|dtjtjd|z
��z|dtjtjd|z
��zz|dzd�fS)NrrOrrN)�roundrTr\r]r^)rrrl�centroids   r#�_apply_rotationz:_compute_regular_polygon_vertices.<locals>._apply_rotation�s�����a��4�8�8�D�L�L��w��$?�@�@���(�T�X�X�d�l�l�3��=�&A�B�B�C��1�+���	
�
��a��4�8�8�D�L�L��w��$?�@�@���(�T�X�X�d�l�l�3��=�&A�B�B�C��1�+���	
�

�
	
r%c� ��|dg}�|||�S�Nrr)r!�polygon_radiusr`�start_pointr"s    �r#�_compute_polygon_vertexzB_compute_regular_polygon_vertices.<locals>._compute_polygon_vertex	s���%�q�)���{�E�8�<�<r%c��g}d|z}dd|zz
|z}td|�D]#}|j|�||z
}|dkDs�|dz}�%|S)NrOr�g�?r)rjr�)r�r�rsrl�
current_angle�_s      r#�_get_anglesz6_compute_regular_polygon_vertices.<locals>._get_angles
sh������-���s�W�}�,��8�
��q�'�"�	%�A��M�M�-�(��W�$�M��s�"���$�
�		%�
�
r%)	r2r�r�rrir[rkr�r)r�r�r�r"r!r%r'r+rsr`r"s          @r#r�r��sY���R�g�s�#�(����n����{�,����o���o��e�}�5�1����n��
�?��q� �$3�!��>�	�_�	��	"�#2� ��.�
<�	���o���P�4O�h�4O��4O�P�P�@����o���x�=�A��R����o�����4����o���h��e��-�2����o��
� =�
���(�
+�F�OU��EJ���.�%�@����s�D)c	����t�t�r(t��fd�tdt	���D��St��z
�S)zJ
    Uses 1-norm distance to calculate difference between two values.
    c3�F�K�|]}t�|�|z
����y�wr1)�abs)rWrq�color1�color2s  ��r#rZz_color_diff.<locals>.<genexpr>'s#�����M�!�3�v�a�y�6�!�9�,�-�M�s�!r)r2r[�sumrjrkr.)r/r0s``r#rr"s:����&�%� ��M�u�Q��F��7L�M�M�M��6�F�?�#�#r%r1r�r$)�
__future__rrTr5r�r*rrrr�rrE�Outliner�rrr�rrr%r#�<module>r4sp��@#���
���L�L�^#�$��j�j� � �G�
�05�px�v$��_���G��s�A�A�A

Zerion Mini Shell 1.0