o
    {g                     @   s   d dl Z d dlmZ d dlmZ ddlmZ ddlmZmZ ddl	m
Z
 d	d
 Zd'ddZeddge
dedddgd(ddZeddge
dddde
deddde
ded dde
dedddgd)d!d"Zed#d$gd*d%d&ZdS )+    N)Image)features   )PngRenderer)exporterio_progress   )ExtraOptionc                 C   sX   | j dvr
| d} | d}| djdtjdd} t|dd	 }| jd|d
 | S )N)RGBARGBar
   ARGBP   )palettecolorsc                 S   s   | dkrdS dS )N   r   r    )ar   r   q/var/www/bot.gig.net.ua/public_html/telegram/P1/HellBot/venv/lib/python3.10/site-packages/lottie/exporters/gif.py<lambda>   s    z"_png_gif_prepare.<locals>.<lambda>)mask)modeconvert
getchannelr   ADAPTIVEevalpaste)imagealphar   r   r   r   _png_gif_prepare
   s   


r    c                 C   s4   |d u rt  d|   d S t  d|  || d S )Nz%s frame rendering completedz%s rendering frame)r   report_messagereport_progress)fmtframe_noendr   r   r   
_log_frame   s   r&   GIFgifskip_framesz(Only renderer 1 out of these many frames)typedefaulthelp`   c              
   C   s   t | j}t | j}g }t| |2}t||d |D ]!}td|| t }	|||	 |		d |
tt|	 qW d   n1 sFw   Y  td t d t td| j | d d }
|d j|d|dd d|
dd	d
d dS )z4
    Gif export

    Note that it's a bit slow.
    r   r'   r   NzGIF Writing to file...  
   Tr   r   )formatappend_imagessave_alldurationlooptransparencydisposal)intin_point	out_pointr   ranger&   ioBytesIO	serializeseekappendr    r   openr   r!   round
frame_ratesave)	animationfpdpir)   startr%   framesrendererifiler3   r   r   r   
export_gif   s2   
	



rL   WebPwebplossless
store_truez$If present, use lossless compression)actionr,   qualityP   znCompression effort between 0 and 100
for lossy 0 gives the smallest size
for lossless 0 gives the largest filemethodz1Quality/speed trade-off (0=fast, 6=slower-better)Fc                 C   s   t ds	tdt| j}t| j}g }	t| |0}
t||d |D ]}td|| t	
 }|
|| |d |	t| q#W d   n1 sMw   Y  td t d ttd| j | }|	d j|d|	dd d	|dd
|||d
 dS )zl
    Export WebP

    See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#webp
    	webp_animz,WebP animations not supported in this systemr   rM   r   NzWebP Writing to file...r.   T)r   r   r   r   )	r0   r1   r2   r3   r4   
backgroundrO   rR   rT   )r   check	Exceptionr7   r8   r9   r   r:   r&   r;   r<   r=   r>   r?   r   r@   r   r!   rA   rB   rC   )rD   rE   rF   rO   rR   rT   r)   rG   r%   rH   rI   rJ   rK   r3   r   r   r   export_webp>   s:   





rY   TIFFtiffc           
   	   C   s   t | j}t | j}g }t| |/}t||d D ]}td|| t }||| |	d |
t| qW d   n1 sCw   Y  td t d t td| j }	|d j|d|dd d|	d||fd dS )	z
    Export TIFF
    r   rZ   r   NzTIFF Writing to file...r.   T)r0   r1   r2   r3   r4   rF   )r7   r8   r9   r   r:   r&   r;   r<   r=   r>   r?   r   r@   r   r!   rA   rB   rC   )
rD   rE   rF   rG   r%   rH   rI   rJ   rK   r3   r   r   r   export_tiffm   s0   




r\   )NN)r-   r   )r-   FrS   r   r   )r-   )r;   PILr   r   cairor   baser   r   parsers.baseporterr	   r    r&   r7   rL   rY   r\   r   r   r   r   <module>   s.    

 	
&