
    h1#                        S SK Jr  S SKrS SKJr  S SKJr  SSKJrJ	r	J
r
Jr  Sr\(       a  SSKJr   " S	 S
5      rSS jrSS jrSS jrSSS jjrSSS jjrSSS jjrSSS jjrSS jrg)    )annotationsN)Sequence)IO   )GimpGradientFileGimpPaletteFile
ImageColorPaletteFileF)Imagec                     \ rS rSrSr  S     SS jjr\SS j5       r\R                  SS j5       r\SS j5       r	\	R                  SS j5       r	SS	 jr
SS
 jrSS jr\r S     SS jjr S     SS jjrSS jrSrg)ImagePalette   a  
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                \    Xl         S U l        U=(       d
    [        5       U l        S U l        g N)moderawmode	bytearraypalettedirty)selfr   r   s      B/var/www/html/env/lib/python3.13/site-packages/PIL/ImagePalette.py__init__ImagePalette.__init__+   s%    
 	#'-)+!%
    c                    U R                   $ r   )_paletter   s    r   r   ImagePalette.palette5   s    }}r   c                    S U l         Xl        g r   )_colorsr   )r   r   s     r   r   r   9   s    :>r   c                2   U R                   c  [        U R                  5      n0 U l         [        S[        U R                  5      U5       H?  n[        U R                  X"U-    5      nX0R                   ;   a  M.  X!-  U R                   U'   MA     U R                   $ )Nr   )r    lenr   ranger   tuple)r   mode_lenicolors       r   colorsImagePalette.colors>   s|    <<499~HDL1c$,,/:dll18|<=LL(&'mU#	 ;
 ||r   c                    Xl         g r   )r    )r   r(   s     r   r(   r)   J   s    r   c                    [        5       nU R                  Ul        U R                  Ul        U R                  b  U R                  S S  Ul        U R                  Ul        U$ r   )r   r   r   r   r   )r   news     r   copyImagePalette.copyN   sH    n99ll<<#,,q/CKJJ	
r   c                    U R                   (       a  U R                   U R                  4$ U R                  U R                  5       4$ )z
Get palette contents in format suitable for the low-level
``im.putpalette`` primitive.

.. warning:: This method is experimental.
)r   r   r   tobytesr   s    r   getdataImagePalette.getdataY   s3     <<<<--yy$,,.((r   c                    U R                   (       a  Sn[        U5      e[        U R                  [        5      (       a  U R                  $ [
        R
                  " SU R                  5      nUR                  5       $ )zEConvert palette to bytes.

.. warning:: This method is experimental.
!palette contains raw palette dataB)r   
ValueError
isinstancer   bytesarrayr0   )r   msgarrs      r   r0   ImagePalette.tobytesd   sU    
 <<5CS/!dllE**<<kk#t||,{{}r   c                   [        U R                  [        5      (       d  [        U R                  5      U l        [	        U R                  5      S-  nSnU(       aG  UR
                  R                  S5      UR
                  R                  S5      4nX4;   a  US-  nX4;   a  M  US:  a`  U(       aE  [        [        [        UR                  5       5      5      5       H  u  pVUS:X  d  M  XT;  d  M  Un  O   US:  a  Sn[        U5      UeU$ )	N    
backgroundtransparencyr      r   z$cannot allocate more than 256 colors)r7   r   r   r   r"   infogetreversedlist	enumerate	histogramr6   )r   imageeindexspecial_colorsr&   countr:   s           r   _new_color_indexImagePalette._new_color_indext   s     $,,	22%dll3DMDLL!Q&CE

|,

~.N )
 )C< (i8I.J)K LHAza&= ! !M |< o1,r   c                    U R                   (       a  Sn[        U5      e[        U[        5      (       ao  U R                  S:X  a+  [        U5      S:X  a  US   S:w  a  Sn[        U5      eUSS nO$U R                  S:X  a  [        U5      S:X  a  US	-  n U R                  U   $ S[        U5       3n[        U5      e! [         a  nU R                  X$5      n[        U R                  [        5      (       d   eXPR                  U'   US-  [        U R                  5      :  a:  U R                  SUS-   [        U5      -   U R                  US-  S-   S -   U l	        OU =R                  [        U5      -  sl	        S
U l        Us SnA$ SnAff = f)zWGiven an rgb tuple, allocate palette entry.

.. warning:: This method is experimental.
r4   RGB   r>      z/cannot add non-opaque RGBA color to RGB paletteNRGBA)rS   r   zunknown color specifier: )r   r6   r7   r$   r   r"   r(   KeyErrorrN   r   r   r   r8   r   repr)r   r'   rI   r:   rJ   rK   s         r   getcolorImagePalette.getcolor   sn    <<5CS/!eU##yyE!u:?Qx3O(o-!"1IEf$u:?VOE{{5))" .d5k];CS/!#  --e7!$--;;;;%*E"19s4<<00k	2,'--	A89 M MMU5\1M
s   B< <
FB<FFFc                x   U R                   (       a  Sn[        U5      e[        U[        5      (       a  [	        US5      nUR                  S5        UR                  SU R                   S35        [        S5       H  nUR                  U 5        [        U[        U R                  5      -  US-   [        U R                  5      -  5       H%  n UR                  SU R                  U    35        M'     UR                  S5        M     UR                  5         g
! [         a    UR                  S	5         Mm  f = f)zFSave palette to text file.

.. warning:: This method is experimental.
r4   wz
# Palette
z# Mode: 
rB   r    z 0N)r   r6   r7   stropenwriter   r#   r"   r   
IndexErrorclose)r   fpr:   r&   js        r   saveImagePalette.save   s    
 <<5CS/!b#b#B

8DII;b)*sAHHs1s499~-ATYY/GH#HHqa 123 I
 HHTN  	
 " #HHTN#s   !DD98D9)r    r   r   r   r   r   )rQ   N)r   r]   r   z(Sequence[int] | bytes | bytearray | NonereturnNone)rf   !Sequence[int] | bytes | bytearray)r   rh   rf   rg   )rf   dict[tuple[int, ...], int])r(   ri   rf   rg   )rf   r   )rf   z-tuple[str, Sequence[int] | bytes | bytearray])rf   r8   )NN)rI   Image.Image | NonerJ   zException | Nonerf   intr   )r'   ztuple[int, ...]rI   rj   rf   rk   )rb   zstr | IO[str]rf   rg   )__name__
__module____qualname____firstlineno____doc__r   propertyr   setterr(   r-   r1   r0   tostringrN   rW   rd   __static_attributes__r?   r   r   r   r      s    	 <@&& :& 
	&   ^^    	 	 ]] 		) H GK'3C	: %))")" ")" 
	)"Vr   r   c                @    [        5       nXl        Xl        SUl        U$ )Nr   )r   r   r   r   )r   datar   s      r   rawrw      s    nGOOGMNr   c                    U S:X  a*  [        S5       Vs/ s H  n[        X-  S-  5      PM     sn$ Sn[        U5      es  snf )Nr   rB   rS   z"unavailable when black is non-zero)r#   rk   NotImplementedError)blackwhiter&   r:   s       r   make_linear_lutr|      sC    z/4Sz:z!EI$%z::
.C
c
"" ;s   >c                n    [        S5       Vs/ s H  n[        US-  U -  S-  S-   5      PM     sn$ s  snf )NrB   g     o@g      ?)r#   rk   )expr&   s     r   make_gamma_lutr      s6    =B3ZHZC!e)#u,s23ZHHHs   !2c           
         [        [        S[        U 5      -  5      5      nUR                  5         [	        X Vs/ s H  o"[        U 5      -  PM     sn5      $ s  snf NrB   )rF   r#   r"   reverser   r   r   r&   s      r   negativer      sH    5s4y)*GOOw?w!CI~w?@@?s   A
c                    SSK Jn  [        S[        U 5      -  5       Vs/ s H  o!" SS5      PM     nn[	        X5      $ s  snf )Nr   )randintrB   rS   )randomr   r#   r"   r   )r   r   _r   s       r   r   r      s?    (-cCIo(>?(>1wq#(>G?&& @s   ?c           	         [         R                  " U 5       Vs/ s H  n[        SU5      PM     nn[        S[	        S5       Vs/ s H  o2US-     US-     PM     sn5      $ s  snf s  snf )Nr   rQ   i   r>   )r	   getrgbr|   r   r#   )r{   bandbandsr&   s       r   sepiar      sb    2<2C2CE2JK2J$_Q%2JEKeGnMna!eQ!V 4nMNN LMs   A"A'
c           
         [        [        S[        U 5      -  5      5      n[        X Vs/ s H  o"[        U 5      -  PM     sn5      $ s  snf r   )rF   r#   r"   r   r   s      r   wedger      s>    5s4y)*Gw?w!CI~w?@@?s   A
c                p   [        U S5       n[        R                  [        R                  [        R                  /nU H4  n UR	                  S5        U" U5      R                  5       nU(       a    OM6     Sn[        U5      e S S S 5        U$ ! [        [        4 a     Mc  f = f! , (       d  f       W$ = f)Nrbr   zcannot load palette)	r^   r   r   r
   seek
getpaletteSyntaxErrorr6   OSError)filenamerb   paletteHandlerspaletteHandlerlutr:   s         r   loadr     s     
h	 ++--##
 	 .N
$R(335 	 . (C#, # 
0 J  , % 
	0 Js/   5B&.B1B&B#B&"B##B&&
B5)r   r]   rv   rh   rf   r   )rz   rk   r{   floatrf   	list[int])r~   r   rf   r   )rQ   )r   r]   rf   r   )z#fff0c0)r{   r]   rf   r   )r   r]   rf   ztuple[bytes, str])
__future__r   r9   collections.abcr   typingr    r   r   r	   r
   TYPE_CHECKINGr   r   rw   r|   r   r   r   r   r   r   r?   r   r   <module>r      s]   $ #  $  H Hn nj#IA'O
A
r   