o �J�h54� @s&ddlmZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z ddl mZe �d�Zer;ddlmZd Zd Zd;dd�Zd<dd�Zd<dd�Zd<dd�Zd<dd�ZGdd�d�ZGd d!�d!e j �Zd=d(d)�Zd>d-d.�Ze �ejee�e �ejd/�e � eje�e �!ejd0�e"d1k�re#ej$�d2kr�e%d3�e�&�e'ej$dd4��[Z(ee(�Z)e)j*d5D]Z+e+\Z,Z-Z.e)_+e)�/d6e,�d7e-�d7e.�d8��q�e �'ej$d�� Z0e0�/d9�Wd�n1s�wYej1d:kr�e�2d9�Wd�dSWd�dS1�s wYdSdS)?�)� annotationsN)�IO�)�Image� ImageFile�PngImagePlugin�features)� deprecateZjpg_2000)�Jpeg2KImagePluginsicns��fobj� IO[bytes]�return�tuple[bytes, int]cCst�d|�t��S)Nz>4sI)�struct�unpack�read� HEADERSIZE)r �r�QC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\PIL\IcnsImagePlugin.py� nextheader&sr� start_length�tuple[int, int]�size�tuple[int, int, int]�dict[str, Image.Image]cCsH|\}}|�|�|�d�}|dkrd}t|��t||d|df|�S)N�sz'Unknown signature, expecting 0x00000000)�seekr� SyntaxError�read_32)r rr�start�length�sig�msgrrr�read_32t*s  r$c Cst|\}}|�|�|d|d|d|df}|d|d}||dkr;|�|�}t�d||dddd�}d|iSt�d|d�}td�D]o} g} |} | dkr�|�d�} | sXn7| d} | d@rv| d }|�d�} t|�D]}| �| �qmn | d}| �|�|��| |8} | dkr�n| dksP| dkr�d t| ��d �}t|��t�d |d � | �dd dd�}|j � |j | �qFd|iS)zn Read a 32bit RGB icon resource. Seems to be either uncompressed or an RLE packbits-like scheme. r�r��RGB�rawN��}zError reading channel [z left]�L�) rrr� frombuffer�new�range�append�reprr�join�im�putband)r rrr r!� pixel_size�sizesqZindatar3Zband_ix�dataZ bytesleft�byteZbyte_int� blocksize�ir#�bandrrrr7sF    �     ��rc Csf|d}|�|�|d|d|d|df}|d|d}t�d||�|�dddd�}d|iS)Nrr%rr+r(�A)rrr-r)r rrr r5r6r;rrr�read_mkds   r=c Cs�|\}}|�|�|�d�}|dd�dkr*|�|�t�|�}t�|j�d|iS|dd�dks>|dd�dks>|dkrntsFd }t|��|�|�|�|�}t � |�} t � | �}t�|j�|j dkrj|�d�}d|iSd }t|��) N� r s�PNG  �RGBArs�O�Qs � s jP � zQUnsupported icon subimage format (rebuild PIL with JPEG 2000 support to fix this)z Unsupported icon subimage format)rrr� PngImageFiler�_decompression_bomb_checkr� enable_jpeg2k� ValueError�io�BytesIOr ZJpeg2KImageFile�mode�convert) r rrr r!r"r3r#Z jp2kstream�frrr�read_png_or_jpeg2000ps2     �       rIc@s�eZdZdefgdefgdefgdefgdefgdefdefdefgd efgd efgd efd efgd efdefdefgdefgdefdefdefgd� Zd*dd�Zd+dd�Z d,dd �Z d-d#d$�Z %d.d/d(d)�Z d%S)0�IcnsFile�ic10�ic09�ic14�ic08�ic13�ic07sit32st8mksicp6�ic12sih32sh8mksicp5sil32sl8mk�ic11sicp4sis32ss8mk) )�rSr%)rSrSr)�rTr%)rTrTr)r)r)r%)r)r)r)�@rUr)� rVr%)�0rWr)rVrVr)�rXr%)rXrXrr r r�NonecCs�i|_||_t|�\}}t|�sd}t|��t}||krLt|�\}}|dkr,d}t|��|t7}|t8}||f|j|<|�|tj�||7}||ksdSdS)z@ fobj is a file-like object as an icns resource znot an icns filerzinvalid block headerN) �dctr r�_acceptrrrrD�SEEK_CUR)�selfr r"�filesizer#r:r9rrr�__init__�s$  �zIcnsFile.__init__�list[tuple[int, int, int]]cCsBg}|j��D]\}}|D]\}}||jvr|�|�nq q|S�N)�SIZES�itemsrZr0)r]�sizesrZfmts�fmt�readerrrr� itersizes�s   ��zIcnsFile.itersizesrcCs |��}|s d}t|��t|�S)NzNo 32bit icon resources found)rgr�max)r]rdr#rrr�bestsize�s zIcnsFile.bestsizerrcCsDi}|j|D]\}}|j�|�}|dur|�||j||��q|S)z� Get an icon resource as {channel: array}. Note that the arrays are bottom-up like windows bitmaps and will likely need to be flipped or transposed in some way. N)rbrZ�get�updater )r]rrZ�coderf�descrrr� dataforsize�s �zIcnsFile.dataforsizeN�-tuple[int, int] | tuple[int, int, int] | None� Image.ImagecCs�|dur |��}nt|�dkr|d|ddf}|�|�}|�d�}|r&|S|d��}z |�|d�W|Sty@Y|Sw)Nr%rrr?r'r<)ri�lenrnrj�copy�putalpha�KeyError)r]r�channelsr3rrr�getimage�s       ��zIcnsFile.getimage)r r rrY)rr`)rr)rrrrra)rrorrp) �__name__� __module__� __qualname__rIr$r=rrbr_rgrirnrvrrrrrJ�s:����   �rJc@sLeZdZdZdZdZddd�Zedd d ��Zej dd d ��Zdddd�Z d S)� IcnsImageFilea! PIL image support for Mac OS .icns files. Chooses the best resolution, but will possibly load a different size image if you mutate the size attribute before calling 'load'. The info dictionary has a key 'sizes' that is a list of sizes that the icns file has. ZICNSzMac OS icns resourcerrYcCs\t|j�|_d|_|j��|jd<|j��|_|jd|jd|jd|jdf|_dS)Nr?rdrr%r) rJ�fp�icns�_moderg�infori� best_sizer�r]rrr�_open s   �zIcnsImageFile._open�&tuple[int, int] | tuple[int, int, int]cCs|jSra)�_sizer�rrrrszIcnsImageFile.size�valuecCs�t|�dkrtddd�||jdvr||_dSn0|jdD]*}|d|d|d|df}|d|d}|d|d|krH||_dSqd }t|��) Nr&z&Setting size to (width, height, scale)r>z load(scale)rdrr%rz2This is not one of the allowed sizes of this image)rqr r~r�rC)r]r�rZ simple_size�scaler#rrrrs  � �Nr�� int | None�Image.core.PixelAccess | NonecCs�|dus t|j�dkr9|durt|j�dkr|jd}|dus!J�|jdd�\}}||||f|_|||f|_tj�|�}|jdurM|jj|jkrM|S|��|j� |j�}|��}|j|_|j |_ |j|_|S)Nr&r%) rqrrr�load�_imr3� load_preparer|rvrFr})r]r��width�height�pxr3rrrr�.s"    zIcnsImageFile.load)rrY)rr�)r�r�rrYra)r�r�rr�) rwrxry�__doc__�format�format_descriptionr��propertyr�setterr�rrrrrz�s    rzr3rpr{�filename� str | bytesrYc Cs�t|d�r |��ddddddddd�}d d �|j�d g�D�}i}t|���D]!}||vr2||n|�||f�}t��}|� |d �|� �||<q(g} |� �D]\} }||} | � | t t| �| f�qP|�t�t } | t d t| �7} | tdd�| D��7} |�t�d| ��|�d�|�t�dt t| �t ��| D]} |�| d�|�t�d| d��q�| D]} |�| d�|�t�d| d��|�| d�q�t|d�r�|��dSdS)za Saves the image as a series of PNG files, that are then combined into a .icns file. �flushr)rTrSirVrU)rPrNrLrKrRrQrOrMcSsi|]}|j|�qSr)r�)�.0r3rrr� <dictcomp>[sz_save.<locals>.<dictcomp>� append_images�pngr css�|]}|dVqdS)rNr)r��entryrrr� <genexpr>qs�z_save.<locals>.<genexpr>z>isTOC rrr%N)�hasattrr�� encoderinforj�set�values�resizerDrE�save�getvaluercr0rrq�write�MAGIC�sumr�pack)r3r{r�rdZprovided_imagesZ size_streamsr�image�temp�entries�type�stream� file_lengthr�rrr�_saveIsT � � �     �r��prefix�bytes�boolcCs|dd�tkS)Nr)r�)r�rrrr[�sr[z.icnsz image/icns�__main__r%z)Syntax: python3 IcnsImagePlugin.py [file]�rbrdzout-�-z.pngzout.png�windows)r r rr)r r rrrrrr)r3rpr{r r�r�rrY)r�r�rr�)3� __future__rrD�osr�sys�typingr�rrrr� _deprecater Z check_codecrBr r�rrr$rr=rIrJrzr�r[� register_openr��register_extension� register_save� register_mimerwrq�argv�print�exit�openr{Zimfr~rr�r�r�r�r3�platform� startfilerrrr�<module>sX        - &i J <   �  �$��
Memory