o
    'j6h0                     @  s  d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	m
Z
 ddlmZmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ dZd%ddZd&ddZG dd de
ZG dd  d ZG d!d" d"ejZe ej!ee e"ej!e e#ej!d# e$ej!d$ dS )'    )annotationsN)BytesIO)ceillog)IO
NamedTuple   )BmpImagePluginImage	ImageFilePngImagePlugin)i16le)i32le)o8)o16le)o32les      imImage.Imagefp	IO[bytes]filenamestr | bytesreturnNonec                 C  s  | t | jddk}| jdg d}g }| g| jdg  }| j\}}tt|D ]m}	|	d |ksG|	d |ksG|	d dksG|	d dkrHq-|D ]<}
|
j|	krRqJ||
 |rtj	|
j
 d }|g}|D ]}|j|	krnqftj	|j
 d }||vr|| || qf n|
 }|j|	tjjd d	 || q-| tt| | t|d
  }|D ]}|j\}}| t|dk r|nd | t|dk r|nd |rtj	|j
 dd  nd\}}| t| | d | d | t| t }|r!||d |dkr td|	}t||tdd|	 ddg n||d |d | }|rE|d d t|d  |dd   }t|}| t| | t| | }|| | | || }|| qd S )Nbitmap_formatbmpsizes))   r   )   r   )    r   )0   r    )@   r!   )   r"   )   r#   append_imagesr   r   r#   )reducing_gapr   )r   r       s     dibr   1rawr   r   )r(   r   png         )write_MAGICencoderinfogetsizesortedsetappendr	   SAVEmodecopy	thumbnailr
   
ResamplingLANCZOSo16lentellr   r   savenewr   _save_Tileseekreado32)r   r   r   r   r   framesprovided_imswidthheightr4   provided_imbits	bits_usedother_imframeoffsetcolorsimage_ioand_maskimage_bytes	bytes_lencurrent rX   a/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/PIL/IcoImagePlugin.pyrC   +   s   

0






 



$

rC   prefixbytesboolc                 C  s
   |  tS N)
startswithr1   )rZ   rX   rX   rY   _acceptx   s   
r_   c                   @  sf   e Zd ZU ded< ded< ded< ded< ded< ded< ded< ded	< d
ed< ded< ded< dS )
IconHeaderintrJ   rK   nb_colorreservedplanesbppr4   rQ   tuple[int, int]dimsquarecolor_depthN)__name__
__module____qualname____annotations__rX   rX   rX   rY   r`   |   s   
 r`   c                   @  sB   e Zd ZdddZddd	ZddddZddddZdddZdS )IcoFilebufr   r   r   c           
      C  s  | d}t|sd}t||| _g | _t|d| _t| jD ]P}| d}|d p,d}|d p2d}|d }t|d}t||||d	 t|dt|dt	|d
t	|d||f|| |pg|dkrft
t|dpgdd}	| j|	 q t| jdd d| _t| jdd dd| _dS )zL
        Parse image from file-like object containing ico file data
           znot an ICO file   r   r   r#   r   r.      r-   r/   )rJ   rK   rb   rc   rd   re   r4   rQ   rg   rh   ri   c                 S     | j S r]   )ri   xrX   rX   rY   <lambda>       z"IcoFile.__init__.<locals>.<lambda>)keyc                 S  rs   r]   )rh   rt   rX   rX   rY   rv      rw   T)rx   reverseN)rF   r_   SyntaxErrorro   entryi16nb_itemsranger`   i32r   r   r7   r5   )
selfro   smsgirJ   rK   rb   re   icon_headerrX   rX   rY   __init__   s:   


zIcoFile.__init__set[tuple[int, int]]c                 C  s   dd | j D S )zI
        Get a set of all available icon sizes and color depths.
        c                 S  s   h | ]}|j |jfqS rX   )rJ   rK   ).0hrX   rX   rY   	<setcomp>   s    z IcoFile.sizes.<locals>.<setcomp>)r{   r   rX   rX   rY   r      s   zIcoFile.sizesFr4   rf   re   
int | boolra   c                 C  s<   t | jD ]\}}||jkr|du s||jkr|  S qdS )NFr   )	enumerater{   rg   ri   )r   r4   re   r   r   rX   rX   rY   getentryindex   s
   zIcoFile.getentryindexr   c                 C  s   |  | ||S )z,
        Get an image from the icon
        )rP   r   )r   r4   re   rX   rX   rY   getimage   s   zIcoFile.getimageidxc              
   C  s  | j | }| j|j | jd}| j|j |dd tjkr0t| j}t	|j
 |S t| j}t	|j
 |j
d t|j
d d f|_|jd \}}}}t|d|j
 |||jd< |jdkr| j| | j|j
d |j
d  d d	dd }	ztd
|j
|	dd}
W ni ty   tjrd}
n Y nZw |j
d }|d dkr|d|j
d d  7 }t||j
d  d }|j|j
 | }| j| | j|}ztd|j
|ddt|d df}
W n ty   tjrd}
n Y nw |
r|d}||
 |S )z-
        Get an image from frame idx
        r-   Nr   r   r.   r*   r   rq   rr   Lr)   )r   r   r+   r(   z1;Ir+   RGBA)r{   ro   rE   rQ   rF   r   r1   PngImageFiler
   _decompression_bomb_checkr4   r	   DibImageFilera   _sizetiler   rD   re   
frombuffer
ValueErrorLOAD_TRUNCATED_IMAGESconvertputalpha)r   r   headerdatar   deoaalpha_bytesmaskwtotal_bytesand_mask_offset	mask_datarX   rX   rY   rP      sn   
K
*
	

zIcoFile.frameN)ro   r   r   r   )r   r   )F)r4   rf   re   r   r   ra   )r4   rf   re   r   r   r   )r   ra   r   r   )rj   rk   rl   r   r   r   r   rP   rX   rX   rX   rY   rn      s    

2rn   c                   @  sT   e Zd ZdZdZdZdddZedd	d
Zej	ddd
ZdddZ
dddZdS )IcoImageFilea  
    PIL read-only image support for Microsoft Windows .ico files.

    By default the largest resolution image in the file will be loaded. This
    can be changed by altering the 'size' attribute before calling 'load'.

    The info dictionary has a key 'sizes' that is a list of the sizes available
    in the icon file.

    Handles classic, XP and Vista icon formats.

    When saving, PNG compression is used. Support for this was only added in
    Windows Vista. If you are unable to view the icon in Windows, convert the
    image to "RGBA" mode before saving.

    This plugin is a refactored version of Win32IconImagePlugin by Bryan Davis
    <casadebender@gmail.com>.
    https://code.google.com/archive/p/casadebender/wikis/Win32IconImagePlugin.wiki
    ICOzWindows Iconr   r   c                 C  s8   t | j| _| j | jd< | jjd j| _|   d S )Nr   r   )	rn   r   icor   infor{   rg   r4   loadr   rX   rX   rY   _openH  s   zIcoImageFile._openrf   c                 C  rs   r]   )r   r   rX   rX   rY   r4   N  s   zIcoImageFile.sizevaluec                 C  s$   || j d vrd}t||| _d S )Nr   z2This is not one of the allowed sizes of this image)r   r   r   )r   r   r   rX   rX   rY   r4   R  s   
Image.core.PixelAccess | Nonec                 C  s   | j d ur| jj| jkrtj| S | j| j}|  |j| _|j| _|j	r,|j	| _	|j| jkrUt
d | j| j}t| jd }|j||< t|| jd< |j| _d S )NzImage was not the expected sizer   )_imr   r4   r
   r   r   r   r9   _modepalettewarningswarnr   listr   r6   )r   r   indexr   rX   rX   rY   r   Y  s    

zIcoImageFile.loadposra   c                 C  s   d S r]   rX   )r   r   rX   rX   rY   	load_seeko  s   zIcoImageFile.load_seekN)r   r   )r   rf   )r   rf   r   r   )r   r   )r   ra   r   r   )rj   rk   rl   __doc__formatformat_descriptionr   propertyr4   setterr   r   rX   rX   rX   rY   r   0  s    

r   z.icozimage/x-icon)r   r   r   r   r   r   r   r   )rZ   r[   r   r\   )%
__future__r   r   ior   mathr   r   typingr   r    r	   r
   r   r   _binaryr   r|   r   r   r   r   r>   r   rG   r1   rC   r_   r`   rn   r   register_openr   register_saveregister_extensionregister_mimerX   rX   rX   rY   <module>   s,   

M 'I