HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/PIL/__pycache__/ImagePalette.cpython-38.pyc
U

g�
^��@szddlZddlmZmZmZmZGdd�d�Zdd�Zdd	�Zd
d�Z	dd
d�Z
ddd�Zddd�Zddd�Z
dd�ZdS)�N�)�GimpGradientFile�GimpPaletteFile�
ImageColor�PaletteFilec@sFeZdZdZddd�Zdd�Zd	d
�Zdd�ZeZd
d�Z	dd�Z
dS)�ImagePaletteas
    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 and of length ``size``
        times the number of colors in ``mode``. The list must be aligned
        by channel (All R values must be contiguous in the list before G
        and B values.) Defaults to 0 through 255 per channel.
    :param size: An optional palette size. If given, it cannot be equal to
        or greater than 256. Defaults to 0.
    �RGBNrcCsv||_d|_|p$ttd��t|j�|_i|_d|_|dkrTt|j�dt|j�ksj|dkrr|t|j�krrtd��dS)N�rzwrong palette size)	�mode�rawmode�	bytearray�range�len�palette�colors�dirty�
ValueError)�selfr
r�size�r�2/usr/lib/python3/dist-packages/PIL/ImagePalette.py�__init__'s ��zImagePalette.__init__cCsHt�}|j|_|j|_|jdk	r0|jdd�|_|j��|_|j|_|S)N)rr
rrr�copyr)r�newrrrr2s
zImagePalette.copycCs$|jr|j|jfS|jd|��fS)z�
        Get palette contents in format suitable for the low-level
        ``im.putpalette`` primitive.

        .. warning:: This method is experimental.
        z;L)rrr
�tobytes)rrrr�getdata>szImagePalette.getdatacCsH|jrtd��t|jt�r |jSt�d|j�}t|d�r@|��S|��S)zUConvert palette to bytes.

        .. warning:: This method is experimental.
        �!palette contains raw palette data�Br)	rr�
isinstancer�bytes�array�hasattrr�tostring)rZarrrrrrIs
zImagePalette.tobytescCs�|jrtd��t|t�r�z|j|WStk
r�t|jt�rLt|j�|_t	|j�}|dkrftd��||j|<|d|j|<|d|j|d<|d|j|d<d|_
|YSXntd|��d	S)
zgGiven an rgb tuple, allocate palette entry.

        .. warning:: This method is experimental.
        rr	z$cannot allocate more than 256 colorsrr�izunknown color specifier: %rN)rrr�tupler�KeyErrorrrrrr)rZcolor�indexrrr�getcolorZs$


zImagePalette.getcolorc
Cs�|jrtd��t|t�r"t|d�}|�d�|�d|j�td�D]|}|�d|�t|t|j�|dt|j��D]<}z|�d|j	|�Wqxt
k
r�|�d	�YqxXqx|�d
�qD|��dS)zVSave palette to text file.

        .. warning:: This method is experimental.
        r�wz
# Palette
z# Mode: %s
r	z%drz %dz 0�
N)rrr�str�open�writer
r
rr�
IndexError�close)r�fp�i�jrrr�savets


&zImagePalette.save)rNr)�__name__�
__module__�__qualname__�__doc__rrrrr"r'r2rrrrrs
rcCst�}||_||_d|_|S)Nr)rrrr)r�datarrrr�raw�s
r8cCs6g}|dkr.td�D]}|�||d�qnt�|S)Nrr	�)r
�append�NotImplementedError)Zblack�white�lutr0rrr�make_linear_lut�sr>cCs4g}td�D]"}|�t|d|dd��q|S)Nr	g�o@g�?)r
r:�int)Zexpr=r0rrr�make_gamma_lut�s r@rcCs&ttd��}|��t||t|��S�Nr	)�listr
�reverserr)r
rrrr�negative�srDcCs@ddlm}g}tdt|��D]}|�|dd��q t||�S)Nr)�randintr	r9)�randomrEr
rr:r)r
rErr0rrrrF�s
rF�#fff0c0cCs@t�|�\}}}td|�}td|�}td|�}td|||�S)Nrr)rZgetrgbr>r)r<�r�g�brrr�sepia�s



rKcCst|ttd��t|��SrA)rrBr
r)r
rrr�wedge�srLcCsvt|d��b}tjtjtjfD]B}z$|�d�||���}|rBWqhWqttfk
r\YqXqtd��W5QRX|S)N�rbrzcannot load palette)	r+rrr�seekZ
getpalette�SyntaxErrorr�OSError)�filenamer/ZpaletteHandlerr=rrr�load�s�

rR)r)r)rG)r)r �rrrrrr8r>r@rDrFrKrLrRrrrr�<module>sv