%PDF- %PDF-
Mini Shell

Mini Shell

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

�

��eS����ddlmZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZddlmZddlmZddlmZGd	�d
e�Zej.Zd�ZGd�d
ej�Zdddd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d'd�Z"d�Z#d�Z$d�Z%dZ&d�Z'd�Z(d�Z)d�Z*d �Z+d!�Z,d"�Z-d(d#�Z.d)d$�Z/e	j`ejbee�e	jdejbe"�e	jfejbe!�e	jhejbd%�e	jjejbd&�y)*�)�annotationsN)�IntEnum�)�Image�
ImageChops�	ImageFile�	ImageMath�ImageOps�ImagePalette�
ImageSequence)�i16le)�o8)�o16lec��eZdZdZdZdZdZy)�LoadingStrategyz.. versionadded:: 9.1.0rr�N)�__name__�
__module__�__qualname__�__doc__�RGB_AFTER_FIRST� RGB_AFTER_DIFFERENT_PALETTE_ONLY�
RGB_ALWAYS���4/usr/lib/python3/dist-packages/PIL/GifImagePlugin.pyrr0s��!��O�'(�$��Jrrc��|dddvS)N�)sGIF87asGIF89ar)�prefixs r�_acceptr ?s���"�1�:�/�/�/rc�z��eZdZdZdZdZdZd�Zd�Zd�Z	e
d��Ze
d	��Zd
�Z
dd�Z�fd�Zd
�Zd�Z�xZS)�GifImageFile�GIFzCompuserve GIFFNc��|jjd�}|r#|dr|jj|d�Sy)Nrr)�fp�read)�self�ss  r�datazGifImageFile.dataOs6���G�G�L�L��O����1���7�7�<�<��!��%�%�rc��tdt|�d�D]*}|dz||cxk(r||dzcxk(r
||dzk(r�'yyy)Nr�rrTF)�range�len)r'�p�is   r�_is_palette_neededzGifImageFile._is_palette_neededUsX���q�#�a�&�!�$�	�A���F�a��d�:�a��A��h�:�!�A��E�(�:��;��	�rc�b�|jjd�}t|�s
d}t|��|dd|jd<t|d�t|d�f|_g|_|d}|dzdz}|d	zre|d
|jd<|jjd|z�}|j|�r$tjd
|�}|x|_|_|j|_
|jj�|_d|_d|_|j%d�y)N�
znot a GIF filer�version��
�r���
backgroundr+�RGBr)r%r&r �SyntaxError�info�i16�_size�tiler0r�raw�global_palette�palette�_fp�tell�_GifImageFile__rewind�	_n_frames�_is_animated�_seek)r'r(�msg�flags�bitsr.s      r�_openzGifImageFile._open[s���G�G�L�L�����q�z�"�C��c�"�"� ��!�u��	�	�)����A�Y��A�q�	�)��
���	��"�����	�Q����3�;�&'��e�D�I�I�l�#������Q�$�Y�'�A��&�&�q�)� �$�$�U�A�.��56�6��#�d�l��7�7����������
���� ����
�
�1�
rc��|j�6|j�}		|j|j�dzd��$|jS#t$r|j�dz|_YnwxYw|j	|��E)NrF)rFrDrH�EOFError�seek�r'�currents  r�n_frameszGifImageFile.n_frameswsw���>�>�!��i�i�k�G�
1���J�J�t�y�y�{�Q���6��
�~�~����
1�!%����q����
1���I�I�g��s�%A�!A3�2A3c�V�|j�||j� |jdk7|_|jS|j�}|rd|_|jS	|jdd�d|_|j|�|jS#t$r
d|_Y�/wxYw)NrTF)rGrFrDrHrNrOrPs  r�is_animatedzGifImageFile.is_animated�s������$��~�~�)�$(�N�N�a�$7��!�� � � ��)�)�+���(,�D�%�� � � �2��
�
�1�e�,�,0��)��I�I�g�&�� � � ��	$�2�,1��)�2�s�B�B(�'B(c�T�|j|�sy||jkrd|_|jd�|j}t	|jdz|dz�D]}	|j|��y#t
$r$}|j
|�d}t|�|�d}~wwxYw)Nrr�no more images in GIF file)�_seek_check�_GifImageFile__frame�imrHr,rNrO)r'�frame�
last_frame�f�erIs      rrOzGifImageFile.seek�s�������&���4�<�<���D�G��J�J�q�M��\�\�
��t�|�|�a�'����3�	+�A�
+��
�
�1�
�	+���
+��	�	�*�%�2���s�m��*��
+�s�&A:�:	B'�B"�"B'c���|dk(r]d�_d�_d�_�jj	�j
�d�_d�jvr,�jd=n�jr|r�j�|�jdzk7rd|��}t|���j�_�jrN�jj	�j��j�r	�j�r�d�_�jjd�}|r|dk(r
d}t|��d}i}d}d}d}		|s�jjd�}|r|dk(r�n�|dk(�rA�jjd�}�j�}
|dd	k(r5|
d}|dzr|
d
}t|
d�dz|d<d
|z}|dz	}|r�|�_n�|ddk(r9d}
|
r|
|
z
}
�j�}
|
r�d|vr|dxxd|
zz
cc<n|
|d<d}��|ddk(rk|dk(rf|
�jj!�f|d<|
dddk(r?�j�}
t#|
�d
k\r!|
ddk(rt|
d��jd<�j��r�	�j�r��ny|dk(�rs�jjd�}t|d�t|d�}}|t|d�z|t|d�z}}|�j$dkDs|�j$dkDrX|rVt'|�j$d�t'|�j$d�f�_t+j,�j(�||||f}	|d}|dzdk7}|dzrP|dzdz}�jjd
|z�}�j/|�rt1j2d|�}nd }�jjd�d}�jj!��_nd}���|�
d!}t|��|�_|syg�_�jr0�j4j7�j�j8�|�|n�j:�_|�_|dk(rl�j<r+t@tBjDk(r|�d"nd�_#nd#�_#nd$�_#|s$�j:rdd%l$m$}|�j:�}|�_%n�jLd#k(r�t@tBjNk7s|r�d�_(d&�jvrw�j4jS�jd&d��j4jUd"t*jVjX��_d"�_#�jd&=n@d�_#�j4jUdt*jVjX��_�fd'�}|	�_	�jdkr	d�_�n��jdk(rljj8\}}}}||z
||z
f}t+j,|�d#}�jj[d&|�}|��jLd(vrBd"}||�d)z}n4�jj[d*d�}�jLd(vr
d}||�}t*j\j_|||��_n��j4�,�ja�j4�j8��_nw|�u�j8\}}}}||z
||z
f}t+j,|�d#}|}�jLd(vr
d"}||�d)z}t*j\j_|||��_|�]d}|�<|dk(r't@tBjDk7r |�jd&<n�jLd(vr|}d+f�j||ffg�_|j[d�r|d�jd<d,D]5}||vr||�j|<�|�jvs�)�j|=�7y#tb$rY��wxYw)-Nr����commentrzcannot seek to frame �;rV�!�r+r5�duration�r�r�
��	extensionr8�NETSCAPE2.0�loop�,�	�rr4�@r7r6r:Fzimage not found in GIF frame�RGBA�P�L)�copy�transparencyc�����jrW|dzdzt�jj�kDrd}t�jj|dz|dzdz�}|S|||f}|S)Nr+r)�_frame_paletter-rB�tuple)�colorr's �r�_rgbz GifImageFile._seek.<locals>._rgbTsv����"�"��1�9�q�=�3�t�':�':�'B�'B�#C�C��E��d�1�1�9�9�%�!�)�e�a�i�RS�m�T�U���L���u�-���Lr�r:rp)rr9�gif)rdri)2�_GifImageFile__offset�disposerXrCrOrE�disposal_methodr<r?�load�
ValueErrorr%r)r&rNr=rDr-�size�maxr>r�_decompression_bomb_checkr0rr@rY�paste�dispose_extentrArv�_frame_transparency�LOADING_STRATEGYrr�_modersrB�moder�pyaccess�putpalettealpha�convert�Dither�FLOYDSTEINBERG�get�core�fill�_crop�AttributeError)r'rZ�update_imagerIr(rBr<�frame_transparency�	interlace�frame_dispose_extent�blockrJ�dispose_bitsr`�x0�y0�x1�y1rKr.rsry�dispose_size�dispose_moderxrt�ks`                          rrHzGifImageFile._seek�s�����A�:��D�M��D�L��D�L��H�H�M�M�$�-�-�(�#$�D� ��D�I�I�%��I�I�i�(��y�y�\��	�	���D�L�L�1�$�$�)�%��1�C��S�/�!��(�(����=�=��G�G�L�L����'��)�)�+���)�)�+��D�M��G�G�L�L��O���A��I�.�C��3�-������!���	�#�����G�G�L�L��O����T�	���d���G�G�L�L��O���	�	����Q�4�3�;�"�!�H�E��q�y�-2�1�X�*�'*�5�!�}�r�'9�D��$�$.��#5�L�#/�1�#4�L�#�
0<��,��q�T�S�[�"�G� ��5�(�� $�	�	��� �!�D�(��Y��5�7�?�:��*1��Y���A���q�T�S�[�U�a�Z�).�t�w�w�|�|�~�(=�D��%��S�b�z�^�3� $�	�	����u�:��?�u�Q�x�1�}�03�E�1�
�D�I�I�f�-��i�i�k���i�i�k��d���G�G�L�L��O���Q���C��1�I�B���c�!�Q�i���c�!�Q�i��B������1��%��d�i�i��l�):��!$�R����1��!6��B��	�	�!��8M�!M�D�J��3�3�D�J�J�?�')�2�r�2�~�$��!���"�R�Z�A�-�	��3�;�!�A�I��?�D������Q�$�Y�/�A��.�.�q�1�".�"2�"2�5�!�"<��"'���w�w�|�|�A��q�)�� $�������
���A�s�v��0�C��3�-���������	��<�<��G�G�M�M�$�,�,��(;�(;�<�)0�)<�g�$�BU�BU���#5�� ��A�:��"�"�#��'A�'A�A�+=�+I��u�D�J�!$�D�J� ��
��t�2�2�%��t�2�2�3��"�D�L��y�y�C��$��(X�(X�X��$(�D�M�%����2����/�/��	�	�.�0I�1�M�"&�'�'�/�/�&�%�,�,�:U�:U�"V���%+��
� �I�I�n�5�%*��
�"&�'�'�/�/�%����9T�9T�"U���	�3���+	��#�#�a�'�#����%�%��*�"&�!4�!4���B��B� "�R���b��1���/�/��=� #���	�	�
�
�n�6H�I���$��y�y�O�3�'-�� $�U��d� 2�� �I�I�M�M�,��:�E��y�y�O�3�',�� $�U���$�z�z���|�\�5�Q����7�7�&�#'�:�:�d�g�g�t�7J�7J�#K�D�L�'�3�%)�%8�%8�N�B��B��$&��G�R�"�W�#5�L��3�3�L�A�#&�L�.�E��y�y�O�3�'-�� $�%7� 8�4� ?��#(�:�:�?�?�<��u�#U�D�L�� ��L�!�-��A�:�'�?�+E�+E�E�4F��	�	�.�1��Y�Y�o�5�#5�L����R��$��M�M��9�l�3�	��D�I��8�8�I��#'�	�?�D�I�I�i� �*�	!�A��D�y�#�A�w��	�	�!���d�i�i���I�I�a�L�		!��-�	��	�s�Fa7�7	b�bc�\��|jrdnd}d|_|jdk(rG|j��tj
j
||j|j�|_n�|jdvr�|j|_|jrptj
j
d|j|jxsd�|_|jj|jj��nd|_||_d|_t�|�9�y)Nrqrrrrz)rv�_prev_imrXr�rr�r�r�rYr��
putpalette�getdatar��super�load_prepare)r'�	temp_mode�	__class__s  �rr�zGifImageFile.load_prepare�s�����.�.�C�C�	���
��<�<�1���'�'�3��*�*�/�/��t�y�y�$�*B�*B�����Y�Y�/�
)� �G�G�D�M��"�"��*�*�/�/�#�t�y�y�$�:R�:R�:W�VW�X���"����"�"�D�$7�$7�$?�$?�$A�B������
�"���
���rc��|jdk(r�|jdk(r�ttjk(r�|j
�.|jj|j
d�d|_nd|_|jj|jtjj�|_y|jsy|j
�B|jj|j
d�|jjd�}n|jjd�}|j||j�}|j|_|jj|_|jdk(r(|jj!||j|�y|jj!||j�y)Nrrqrpr:)rXr�r�rrr�rYr�r�r�rr�r�r�r�r�r�)r'�frame_ims  r�load_endzGifImageFile.load_end�sE���<�<�1���y�y�C��$4��8R�8R�$R��+�+�7��G�G�+�+�D�,D�,D�a�H�!'�D�J�!&�D�J��'�'�/�/�$�)�)�U�\�\�5P�5P�Q�����}�}���#�#�/��G�G�#�#�D�$<�$<�a�@��w�w���v�.�H��w�w���u�-�H��:�:�h��(;�(;�<���-�-����W�W�\�\��
��=�=�F�"��G�G�M�M�(�D�$7�$7��B��G�G�M�M�(�D�$7�$7�8rc��|jS�N)rX)r's rrDzGifImageFile.tell�s���|�|�r)T)rrr�format�format_description�!_close_exclusive_fp_after_loadingrAr)r0rL�propertyrRrTrOrHr�r�rD�
__classcell__)r�s@rr"r"Hsk���
�F�)��(-�%��N����8�	��	��!��!�$+� |!�|�(9�4rr"rrrq)�1rrrqc���|jtvr|j�|Stj|j�dk(r�|jdtjj��}|jjdk(rL|jjD]3}|ddk(s�|jj||jd<|S|S|jd�S)	a
    Takes an image (or frame), returns an image in a mode that is appropriate
    for saving in a Gif.

    It may return the original image, or it may return an image converted to
    palette or 'L' mode.

    :param im: Image object
    :returns: Image object
    r:rq�rBrpr+rrtrr)r��RAWMODErr�getmodebaser��Palette�ADAPTIVErB�colorsr<)rY�rgbas  r�_normalize_moder��s���
�w�w�'��
���	��	�������!�U�*�
�Z�Z��U�]�]�%;�%;�Z�
<��
�:�:�?�?�f�$��
�
�)�)�
����7�a�<�.0�j�j�.?�.?��.E�B�G�G�N�+���	�	
��	�
�:�:�c�?�rc���d}|rXt|tttf�rt|dd�}t|tj�rt|j
�}|jdk(r!|sX|jjd�dd}n9|std�td�D��}t	jd|��|_|r�g}tdt|�d�D]O}t|||dz�}|j
jj|�}||vrd}|j|��Qt|�D],\}}|��	tt|��D]
}||vs�|||<�,�.|j!|�}n@t#||�}|�2|j!||�}d	|vr	|j%|d	�|d	<|S|S||j
_|S#t&$r|d	=Y|SwxYw)
at
    Normalizes the palette for image.
      - Sets the palette to the incoming palette, if provided.
      - Ensures that there's a palette for L mode images
      - Optimizes the palette if necessary/desired.

    :param im: Image object
    :param palette: bytes object containing the source palette, or ....
    :param info: encoderinfo
    :returns: Image object
    Nirqr:c3�&K�|]	}|dz���y�w)r+Nr)�.0r/s  r�	<genexpr>z%_normalize_palette.<locals>.<genexpr>s����&B�!�q�A�v�&B�s�r�rr+rt)�
isinstance�bytes�	bytearray�listrrBr�rY�
getpaletter,r-rwr�r��append�	enumerate�
remap_palette�
_get_optimize�indexr�)	rYrBr<�source_palette�used_palette_colorsr/�source_colorr��js	         r�_normalize_paletter��s����N���g��y�$�7�8�&�w�t��}�5�N��g�|�8�8�9�&�w���7�N�	�w�w�#�~���U�U�-�-�e�4�T�c�:�N��&�&B�u�S�z�&B�B�N�!�.�.�u�n�M��
�� ���q�#�n�-�q�1�	.�A� ���A��E�!:�;�L��J�J�%�%�)�)�,�7�E��+�+����&�&�u�-�	.�"�"5�6�	�H�A�u��}��s�#6�7�8��A�� 3�3�12�+�A�.���	��
�
�1�
2��+�B��5���*��!�!�"5�~�F�B���%�-�+>�+D�+D��^�,�,�D��(�
�I�2�I�'�B�J�J��
�I��"�-��^�,��I�-�s�#G�G!� G!c	��t|�}|jj�D]!\}}|jj	||��#t|||j�}t
||j�D]}|j|��d}t|�r|dz}t||d|�dt|�f|_
tj||dd|jzdt|jfg�|jd�y)Nrro�rrr4r{�)r�r<�items�encoderinfo�
setdefaultr��_get_global_header�write�
get_interlace�_write_local_header�
encoderconfigr�_saver�r�r�)rYr%rB�im_outr��vr(rJs        r�_write_single_framer�2s���
�R�
 �F����!�!�#�(���1�
���!�!�!�Q�'�(�
������
@�F�
�����
7���
������
�E��R����
����B���.��}�R�0�1�F��
�O�O�F�B�%��"�'�'�)9�1�g�f�k�k�>R�!S� T�U��H�H�U�Orc���t|�t|�k7r"|jd�}|jd�}tj||�}||j	d��fS)NrpF)�
alpha_only)�_get_palette_bytesr�r�subtract_modulo�getbbox)�base_im�im_frame�deltas   r�_getbboxr�Gs[���(�#�'9�'�'B�B��#�#�F�+���/�/�&�)���&�&�x��9�E��%�-�-�5�-�1�1�1rc	�	�|jjd�}|jjd|jjd��}g}d}d}d}tj|g|jjdg��D�]�}	tj|	�D�]m}
t|
j��}
|dk(rD|
jj�D]'\}}|dk(r�|jj||��)|jj�}
d|
jvr|
jd|
jd�t|
||
�}
t|ttf�r	|||
d<n"|� d|
jvr|
jd|
d<t|ttf�r|||
d<|dz
}d}|�r.t||
�\}}|s)|
jd�r|dddxx|
dz
cc<��]|
jd�d	k(r�|��|jjd|jjdd
��}t!|
|�}t#j$d|
j&|�}|j)|ddj*�t||
�\}}|
jd
��r;|
j,dk7�r+d|
vr	|
j*j/|
�|
d<d|
v�r|
j�}t#j$d|j&|
d�}|j,dk(r0|j3�\}}}}t5j6d||||��}ng|j,dk(rAt#j$d|j&�}|j9|j;��|}t5j6d|��}|j=|t?j@|���nd}|
}|jC|xs|
||
d����p���tE|�dk(r'd|jvr|ddd|jd<y|D]k}|d}
|ds(tG|
|d�D]}|jI|��d}n&|sd|dd<|
jK|d�}
|ddd	}tM||
||d��my#t0$rY���wxYw)Nrd�disposalr�
append_imagesrtrr_r�r)rrrrqrY�optimizer�rpz-convert(max(max(max(r, g), b), a) * 255, '1'))�r�g�b�arrzconvert(im * 255, '1')�rY)�mask)rY�bboxr�r�r�T�include_color_table)'r�r�r<�	itertools�chainr�Iteratorr�rsr�r�r�r�r�rwr��_get_backgroundr�newr�r�rBr��_new_color_indexr��splitr	�eval�putdatar�r�r
�invertr�r-r�r��crop�_write_frame_data)rYr%rBrdr��	im_frames�previous_im�frame_count�
background_im�
imSequencer�r�r�r��
diff_framer�r�rxr9r�r�r�r�r�r��delta_l�
frame_datar(�offsets                             r�_write_multiple_framesr	Os����~�~�!�!�*�-�H��~�~�!�!�*�b�g�g�k�k�*�.E�F�H��I��K��K��M��o�o�r�d�B�N�N�,>�,>��PR�,S�T�N�
�%�.�.�z�:�M	�H�&�x�}�}��7�H��a��$�M�M�/�/�1�4�D�A�q��N�*� ��N�N�-�-�a��3�4�
�.�.�-�-�/�K�����.��&�&�~�x�}�}�^�7T�U�)�(�G�[�I�H��(�T�5�M�2�*2�;�*?��J�'��!�j�H�M�M�&A�*2�-�-�
�*C��J�'��(�T�5�M�2�*2�;�*?��J�'��1��K��J��&�{�H�=���t��"���z�2�!�"�
�m�4�Z�@�K�&�E��@���?�?�:�.�!�3�$�,� "��� 2� 2�*�B�G�G�K�K��	�,R�!��&5�X�u�%E�
�(-�	�	�#�x�}�}�j�(Q�
�%�0�0��1��d�1C�1K�1K�L�"*�=�(�"C�K�E�4��?�?�:�.�8�=�=�C�3G�%�[�8�!�!)� 0� 0� A� A�(� K�(� .��
&��4�%-�]�]�_�
�$�y�y�����+�n�2M� ��!�:�:��/�).����J�A�q�!�Q�#,�>�>� O�"#�"#�"#�"#�$�D� %�z�z�S�0�*/�)�)�C����*D�� '����
�
�� @�(/��#,�>�>�2J�u�#U�D�"�(�(��H�O�O�D�4I�(�J���"�K����!�-�X�t�K�X�
�WM	�N�`�9�~�������'�)2�1��m�)D�Z�)P�B�N�N�:�&���K�
��d�#���&�!�'��*�]�2K�L�
�������
��F��CG�
�=�)�*?�@��}�}�Z��%7�8�H���'���+�F��"�h��
�=�0I�J�K���k *�!� �!�s�R=�=	S
�	S
c�"�t|||d��y)NT)�save_all)r�)rYr%�filenames   r�	_save_allr
�s��	�"�b�(�T�*rFc�x�d|jvsd|jvr6|jjd|jjd��}nd}|jjdd�|r
t	|||�s
t|||�|j
d�t|d�r|j�yy)NrBr�Tra�flush)	r�r<r�r�r	r�r��hasattrr)rYr%rrrBs     rr�r��s����B�N�N�"�i�2�7�7�&:��.�.�$�$�Y������I�0F�G����
���!�!�*�d�3��1�"�b�'�B��B��G�,��H�H�T�N��r�7��
���
�rc�r�|jjdd�}t|j�dkrd}|S)Nr�r�r)r�r��minr�)rYr�s  rr�r��s5�����"�"�;��2�I��2�7�7�|�b���	��rc��	|jd}d|jvrt|jddz�}nd}t|jjdd��}|�|dk7s|rk|�dnd}||dzz}|j	dtd	�ztd
�zt|�zt
|�zt|xsd�ztd�z�|jjd�}|r"t|�}	t|	�}
|
r
|dz}||
z}|j	d
t
|d�zt
|d�zt
|jd�zt
|jd�zt|�z�|r
r|j	t	��|j	td��y#t$rd}Y���wxYw)Nrtrdr5rr�rrrbrcrnr�r7rlr4)r��KeyError�intr�r�r�o16r��_get_color_table_sizer��_get_header_palette)r%rYrrJrtrdr��packed_flagr��
palette_bytes�color_table_sizes           rr�r��s�����~�~�n�5���R�^�^�#��r�~�~�j�1�B�6�7�����2�>�>�%�%�j�!�4�5�H���8�q�=�H�'�3�a����x�1�}�$��
������g�
���e�
���o�
��(�m�	
�
��"��#�
$���e�

�	
��.�.�,�,�-B�C���*�2�.�
�0��?����C�K�E��,�,�E��H�H��

�f�Q�i�.�	�

�f�Q�i�.�	��b�g�g�a�j�/�	��b�g�g�a�j�/�		�

�U�)�	���/�
���$�]�3�4��H�H�R��U�O��U�����s�F;�;G
�	G
c�$�|j�}	t|d�5}|jdk7r)tjd|g|tj
��n�dd|g}dg}tj|tjtj
��}tj||j|tj
��}|jj�|j�}	|	rtj|	|��|j�}	|	rtj|	|��ddd�	tj|�y#1swY� xYw#t$rYywxYw#	tj|�w#t$rYwwxYwxYw)N�wbr:�ppmtogif)�stdout�stderr�ppmquant�256)�stdinr r!)�_dump�openr��
subprocess�
check_call�DEVNULL�Popen�PIPEr �close�wait�CalledProcessError�os�unlink�OSError)
rYr%r�tempfiler\�	quant_cmd�	togif_cmd�
quant_proc�
togif_proc�retcodes
          r�_save_netpbmr8sf���x�x�z�H�#�
�(�D�
!�	L�Q��w�w�%���%�%���*�1�Z�=O�=O��(���9�	�'�L�	�'�-�-��j�o�o�j�>P�>P��
�(�-�-��$�+�+��%�-�-�	�
��!�!�'�'�)�$�/�/�+���$�7�7���K�K�$�/�/�+���$�7�7���K�K�;	L�>	��I�I�h��A	L�	L��B�	��	��	��I�I�h����	��	�sY�E(�DE
�.E(�7E�
E�E(�	E%�$E%�(F�*F�?F�	F�	F�F�Fc�R�|jdv�r|�r|jd��rtxs|jdk(}|s|j|jzdkr�g}t|j
��D]\}}|s�	|j|��|st|�t|�k\r|St|jj�tj|jj�z}d|dz
j�z}t|�|dzkr|dkDr|Syyyyyy)aL
    Palette optimization is a potentially expensive operation.

    This function determines if the palette should be optimized using
    some heuristics, then returns the list of palette entries in use.

    :param im: Image object
    :param info: encoderinfo
    :returns: list of indexes of palette entries in use, or None
    )rqrrr�rrirrN)r�r��_FORCE_OPTIMIZE�width�heightr��	histogramr�r�r-rBr�getmodebands�
bit_length)rYr<�optimiser�r/�count�num_palette_colors�current_palette_sizes        rr�r�Bs'��
�w�w�*���$�(�(�:�*>�#�4�b�g�g��n���r�x�x�"�)�)�+�i�7�"$��%�b�l�l�n�5�
2���5��'�.�.�q�1�
2��3�2�3�s�;N�7O�O�*�*�!$�R�Z�Z�%7�%7�!8�E�<N�<N��
�
���=�"��$%�);�a�)?�(K�(K�(M�#M� ��'�(�,@�A�,E�E�(�1�,�*�*�-�F�!8�+?��rc��|syt|�dkrytjtjt|�dzd��dz
S)Nrrmrr+r)r-�math�ceil�log)rs rrrpsA����	�]�	�a�	���y�y����#�m�"4��"9�1�=�>��B�Brc�v�t|�}d|zt|�dzz
}|dkDr|td�dz|zz
}|S)z�
    Returns the palette, null padded to the next power of 2 (*3) bytes
    suitable for direct inclusion in the GIF header

    :param palette_bytes: Unpadded palette bytes, in RGBRGB form
    :returns: Null padded palette
    rr+r)rr-r)rr�actual_target_size_diffs   rrrzsR��-�]�;�� !�$4�4��M�8J�a�8O�O����"���A����%<�<�<�
��rc�J�|jr|jjSdS)z�
    Gets the palette for inclusion in the gif header

    :param im: Image object
    :returns: Bytes, len<=768 suitable for inclusion in gif header
    rr�r�s rr�r��s��"$���2�:�:���4��4rc��d}|r1t|t�r	|jj||�}|S|}|S#t$r}t|�dvr�Yd}~|Sd}~wwxYw)Nr)z$cannot allocate more than 256 colorsz/cannot add non-opaque RGBA color to RGB palette)r�rwrB�getcolorr��str)rY�info_backgroundr9r]s    rr�r��sy���J���o�u�-�

��Z�Z�0�0��"�E�
���)�J�����
��q�6�"�������
�s�8�	A�A�Ac��d}|jjd�dk(s9|r9d|vs3|jd��"|jd�s|jd�rd}t||jd��}t|�}t	|�}d	|zt|jd
�zt|jd�zt|dz�t|�td
�zt|�g}|jd��_|jd
td�ztd�zdztd�ztd�zt|d�ztd
�z�|jd�r�d
td�z}|d}t|t�r|j�}td
t|�d�D]$}	||	|	dz}
|tt|
��|
zz
}�&|td
�z
}|j|�|S)z2Return a list of strings representing a GIF headers87ar3s89artrkrdr`r9sGIFrrr7rbrhr8rjr+rf)r<r�r�r�rrr�rrr�r�rM�encoder,r-)rYr<r3r9rr�header�
comment_blockr`r/�subblocks           rr�r��s���G�	�w�w�{�{�9���'���d�"��x�x���+��x�x�
�#��x�x�	�"��� ��T�X�X�l�%;�<�J�&�r�*�M�,�]�;��	�
�	�

�b�g�g�a�j�/�	��b�g�g�a�j�/�	�	��c�!�"�
�:���A����M�*��F��x�x���#��
�
����g�
���f�
��
���e�	
�
��e�
��$�v�,��

 ���e�
�		
��x�x�	���r�#�w��
��y�/���g�s�#��n�n�&�G��q�#�g�,��,�	:�A��q�1�s�7�+�H��R��H�
�.��9�9�M�	:�	��A���
��
�
�m�$��Mrc	���	||_t|||d�tj||dd|jzdt
|jfg�|jd�|`y#|`wxYw)Nrr{r�r�)r�r�rr�r�r�r�r�)r%r�r�paramss    rr�r��sj��!�%���	�B��&�!�4�����b�E�6�H�M�M�#9�1�g�h�m�m�>T�U�V�	
�	������ ��H� �s�A A%�%A)c���t||�}|�i}d|vr d|jvr|jd|d<t|||�}|j|_|j|_t||�}||fS)a
    Legacy Method to get Gif data from image.

    Warning:: May modify image data.

    :param im: Image object
    :param palette: bytes object containing the source palette, or ....
    :param info: encoderinfo
    :returns: tuple of(list of header items, optimized palette)

    r9)r�r<r�rBrYr�)rYrBr<r��im_modrQs      r�	getheaderrX�s}��(��D�1���|����4��L�B�G�G�$;��W�W�\�2��\��
��G�T�
2�F����B�J��I�I�B�E�
��D�
)�F��&�&�&rc�x�Gd�d�}|j�|�}t||||�|jS)a�
    Legacy Method

    Return a list of strings representing this image.
    The first string is a local image header, the rest contains
    encoded image data.

    To specify duration, add the time in milliseconds,
    e.g. ``getdata(im_frame, duration=1000)``

    :param im: Image object
    :param offset: Tuple of (x, y) pixels. Defaults to (0, 0)
    :param \**params: e.g. duration or other encoder info parameters
    :returns: List of bytes containing GIF encoded frame data

    c��eZdZgZd�Zy)�getdata.<locals>.Collectorc�:�|jj|�yr�)r)r�)r'r)s  rr�z getdata.<locals>.Collector.write0s���I�I���T�"rN)rrrr)r�rrr�	Collectorr[-s����	#rr])rr�r))rYrrUr]r%s     rr�r�s5��$#�#��G�G�I�	��B��b�"�f�f�-�
�7�7�Nrz.gifz	image/gif)F)NN)r�)6�
__future__rr�rEr/r'�enumr�rrrr	r
rr�_binaryr
r=rrrrrr�r r"r�r�r�r�r�r	r
r�r�r�r8r:r�rrr�r�r�r�rXr��
register_openr��
register_save�register_save_all�register_extension�
register_mimerrr�<module>rgs`��4#���	������"��!��g��#�2�2��0�K�9�&�&�K�d�#�C�
(���29�x�*2�m�`+��"�-�`,�b��++�\C��$5��.;�|
!�('�8�H����L�'�'��w�?�����L�'�'��/������+�+�Y�7������,�,�f�5�����L�'�'��5r

Zerion Mini Shell 1.0