HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/PIL/__pycache__/ImagePalette.cpython-310.pyc
o

we��@szddlZddlmZmZmZmZGdd�d�Zdd�Zdd	�Zd
d�Z	dd
d�Z
ddd�Zddd�Zddd�Z
dd�ZdS)�N�)�GimpGradientFile�GimpPaletteFile�
ImageColor�PaletteFilec@s|eZdZdZddd�Zedd��Zejdd��Zed	d
��Zejdd
��Zdd
�Z	dd�Z
dd�ZeZddd�Z
dd�ZdS)�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.
    �RGBNcCs"||_d|_|p
t�|_d|_dS�N)�mode�rawmode�	bytearray�palette�dirty)�selfr
r
�r�I/home/arjun/projects/env/lib/python3.10/site-packages/PIL/ImagePalette.py�__init__$s
zImagePalette.__init__cCs|jSr	)�_palette�rrrrr
*szImagePalette.palettecCsd|_||_dSr	)�_colorsr)rr
rrrr
.s
cCsh|jdur1t|j�}i|_tdt|j�|�D]}t|j|||��}||jvr)q|||j|<q|jS)Nr)r�lenr
�ranger
�tuple)r�mode_len�i�colorrrr�colors3s


zImagePalette.colorscCs
||_dSr	)r)rrrrrr?s
cCs<t�}|j|_|j|_|jdur|jdd�|_|j|_|Sr	)rr
rr
r)r�newrrr�copyCs
zImagePalette.copycCs |jr	|j|jfS|j|��fS)z�
        Get palette contents in format suitable for the low-level
        ``im.putpalette`` primitive.

        .. warning:: This method is experimental.
        )rr
r
�tobytesrrrr�getdataNszImagePalette.getdatacCs:|jr	d}t|��t|jt�r|jSt�d|j�}|��S)zUConvert palette to bytes.

        .. warning:: This method is experimental.
        �!palette contains raw palette data�B)r�
ValueError�
isinstancer
�bytes�arrayr)r�msg�arrrrrrYszImagePalette.tobytesc	
Cs�|jr	d}t|��t|t�r�|jdkr,t|�dkr+|ddkr%d}t|��|dd�}n|jdkr;t|�dkr;|d	7}z|j|WSty�}z�t|jt	�sUt	|j�|_
t|j�d}d
}|rl|j�d�|j�d�f}||vrx|d
7}||vsp|dkr�|r�t
tt|�����D]\}}|dkr�||vr�|}nq�|dkr�d}t|�|�||j|<|dt|j�kr�|jd|d�t|�|j|ddd�|_
n	|j
t|�7_
d
|_|WYd}~Sd}~wwdt|���}t|��)zgGiven an rgb tuple, allocate palette entry.

        .. warning:: This method is experimental.
        r!r���z/cannot add non-opaque RGBA color to RGB paletteN�RGBA)r+r�
background�transparencyr�rz$cannot allocate more than 256 colorszunknown color specifier: )rr#r$rr
rr�KeyErrorr
rr�info�get�reversed�list�	enumerate�	histogramr%r�repr)	rr�imager'�e�index�special_colorsr�countrrr�getcolorisj

�


���

�����#zImagePalette.getcolorc
Cs�|jr	d}t|��t|t�rt|d�}|�d�|�d|j�d��td�D]<}|�|��t|t|j�|dt|j��D]}z
|�d|j	|���Wq?t
y\|�d	�Yq?w|�d�q&|��d
S)zVSave palette to text file.

        .. warning:: This method is experimental.
        r!�wz
# Palette
z# Mode: �
r/r� z 0N)rr#r$�str�open�writer
rrr
�
IndexError�close)r�fpr'r�jrrr�save�s"


&�zImagePalette.save)rNr	)�__name__�
__module__�__qualname__�__doc__r�propertyr
�setterrrr r�tostringr=rHrrrrrs"





:rcCst�}||_||_d|_|S)Nr)rrr
r)r�datar
rrr�raw�s
rQcCs4g}|dkrtd�D]}|�||d�q
|St�)Nrr/r+)r�append�NotImplementedError)�black�white�lutrrrr�make_linear_lut�s�rWcCs4g}td�D]}|�t|d|dd��q|S)Nr/g�o@g�?)rrR�int)�exprVrrrr�make_gamma_lut�s rZrcs4ttdt����}|��t��fdd�|D��S)Nr/c�g|]}|t���qSr�r��.0r�r
rr�
<listcomp>��znegative.<locals>.<listcomp>)r4rr�reverser�r
r
rr_r�negative�srdcCs@ddlm}g}tdt|��D]
}|�|dd��qt||�S)Nr)�randintr/r+)�randomrerrrRr)r
rer
rrrrrf�s

rf�#fff0c0cs0dd�t�|�D��td�fdd�td�D��S)NcSsg|]}td|��qS)r)rW)r^�bandrrrr`�szsepia.<locals>.<listcomp>rcs g|]}�|d|d�qS)r*rr]��bandsrrr`�s i)r�getrgbrr)rUrrir�sepia�srlcs,ttdt����}t��fdd�|D��S)Nr/cr[rr\r]r_rrr`�razwedge.<locals>.<listcomp>)r4rrrrcrr_r�wedge�srmcCs�t|d��7}tjtjtjfD]}z|�d�||���}|r!WnWqttfy-Yqwd}t|��Wd�|S1s?wY|S)N�rbrzcannot load palette)	rBrrr�seek�
getpalette�SyntaxErrorr#�OSError)�filenamerF�paletteHandlerrVr'rrr�load�s*�
���
��ru)r)rg)r&�rrrrrrQrWrZrdrfrlrmrurrrr�<module>s'