CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
IcnsImagePlugin.cpython-310.pyc115 linesDownload Raw Back to __pycache__
1o

2��Yi*2�@sddlmZddlZddlZddlZddlZddlmZddlm	Z	m3Z4mZmZe�
d�Zer5ddlmZdZd	Zd:dd�Zd;dd�Zd;dd�Zd;dd�Zd;dd�ZGdd�d�ZGdd �d e5j6�Zd<d'd(�Zd=d,d-�Ze	�ejee�e	�ejd.�e	�eje�e	�ejd/�e d0k�re!ej"�d1kr�e#d2�e�$�e%ej"dd3��[Z&ee&�Z'e'j(d4D]Z)e)\Z*Z+Z,e'_)e'�-d5e*�d6e+�d6e,�d7��q�e	�%ej"d��
Z.e.�-d8�Wd�n1s�wYej/d9kr�e�0d8�Wd�dSWd�dS1�swYdSdS)>�)�annotationsN)�IO�)�Image�	ImageFile�PngImagePlugin�featuresZjpg_2000)�Jpeg2KImagePluginsicns��fobj�	IO[bytes]�return�tuple[bytes, int]cCst�d|�t��S)Nz>4sI)�struct�unpack�read�7HEADERSIZE)r�r�}E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\PIL/IcnsImagePlugin.py�8nextheader%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)rrr�start�length�sig�msgrrr�read_32t)s910r#c11Cst|\}}|�|�|d|d|d|df}|d|d}||dkr;|�|�}t�d||dddd�}d|iSt�d|d�}td�D]o}	g}12|}|dkr�|�d�}|sXn7|d}
|
d@rv|
d	}|�d�}t|�D]}|13�|�qmn|
d}|14�|�|��||8}|dkr�n|dksP|dkr�d15t|��d�}t|��t�d|d
�	|16�dddd�}|j17�|j18|	�qFd|iS)zn19    Read a 32bit RGB icon resource.  Seems to be either uncompressed or20    an RLE packbits-like scheme.21    r�r��RGB�rawN��}zError reading channel [z left]�L�)rrr�22frombuffer�new�range�append�reprr�join�imZputband)rrrrr �23pixel_size�sizesqZindatar2Zband_ix�dataZ	bytesleft�byteZbyte_int�	blocksize�ir"�bandrrrr6sF24 25�2627��rc	Csf|d}|�|�|d|d|d|df}|d|d}t�d||�|�dddd�}d|iS)Nrr$rr*r'�A)rrr,r)rrrrr3r4r9rrr�read_mkcs28 r;c29Cs�|\}}|�|�|�d�}|�d�r'|�|�t�|�}t�|j�d|iS|�d�s0|dkr`ts8d}t	|��|�|�|�|�}t30�|�}	t�
|	�}t�|j�|jdkr\|�d�}d|iSd}t	|��)N�s�PNG
3132�RGBA)s�O�Qs
3334sjP  
3536zQUnsupported icon subimage format (rebuild PIL with JPEG 2000 support to fix this)z Unsupported icon subimage format)rr�37startswithrZPngImageFilerZ_decompression_bomb_checkr�
enable_jpeg2k�38ValueError�io�BytesIOr	ZJpeg2KImageFile�mode�convert)39rrrrr r!r2r"Z40jp2kstream�frrr�read_png_or_jpeg2000os24142434445��464748495051rFc@s�eZdZdefgdefgdefgdefgdefgdefdefdefgd	efgd52efgdefdefgd
efdefdefgdefgdefdefdefgd�Zd*dd�Zd+dd�Z	d,dd �Z53d-d#d$�Z	%d.d/d(d)�Zd%S)0�IcnsFile�ic10�ic09�ic14�ic08�ic13�ic07sit32st8mksicp6�ic12sih32sh8mksicp5sil32sl8mk�ic11sicp4sis32ss8mk))�rPr$)rPrPr)�rQr$)rQrQr)r(r(r$)r(r(r)�@rRr)� rSr$)�0rTr)rSrSr)�rUr$)rUrUrrrr
�NonecCs�i|_||_t|�\}}t|�sd}t|��t}||krLt|�\}}|dkr,d}t|��|t7}|t8}||f|j|<|�|tj�||7}||ksdSdS)z@54        fobj is a file-like object as an icns resource55        znot an icns filerzinvalid block headerN)	�dctrr�_acceptrrrrA�SEEK_CUR)�selfrr!�filesizer"r8r7rrr�__init__�s$�zIcnsFile.__init__�list[tuple[int, int, int]]cCsBg}|j��D]\}}|D]\}}||jvr|�|�nq
q|S�N)�SIZES�itemsrWr/)rZ�sizesrZfmts�fmt�readerrrr�	itersizes�s5657��zIcnsFile.itersizesrcCs |��}|sd}t|��t|�S)NzNo 32bit icon resources found)rdr�max)rZrar"rrr�bestsize�s58zIcnsFile.bestsizerrcCsDi}|j|D]\}}|j�|�}|dur|�||j||��q|S)z�59        Get an icon resource as {channel: array}.  Note that60        the arrays are bottom-up like windows bitmaps and will likely61        need to be flipped or transposed in some way.62        N)r_rW�get�updater)rZrrW�coderc�descrrr�dataforsize�s�zIcnsFile.dataforsizeN�-tuple[int, int] | tuple[int, int, int] | None�Image.ImagecCs�|dur	|��}nt|�dkr|d|ddf}|�|�}|�d�}|r&|S|d��}z63|�|d�W|Sty@Y|Sw)Nr$rrr=r&r:)rf�lenrkrg�copyZputalpha�KeyError)rZrZchannelsr2rrr�getimage�s 646566��zIcnsFile.getimage)rrr
rV)r
r])r
r)rrr
rr^)rrlr
rm)
�__name__�67__module__�__qualname__rFr#r;rr_r\rdrfrkrqrrrrrG�s:����686970	71�rGc@sLeZdZdZdZdZddd�Zedd	d72��Zej	ddd73��Zdddd�Z74d
S)�
IcnsImageFilea!75    PIL image support for Mac OS .icns files.76    Chooses the best resolution, but will possibly load77    a different size image if you mutate the size attribute78    before calling 'load'.79 80    The info dictionary has a key 'sizes' that is a list81    of sizes that the icns file has.82    ZICNSzMac OS icns resourcer
rVcCsj|jdusJ�t|j�|_d|_|j��|jd<|j��|_|jd|jd|jd|jdf|_dS)Nr=rarr$r)	�fprG�icns�_moderd�inforf�	best_sizer�rZrrr�_opens83�zIcnsImageFile._openrcCs|jSr^)�_sizer{rrrrszIcnsImageFile.size�valuecCsl|jdD]*}|d|d|d|df}|d|d}|d|d|kr/||_dSqd}t|��)Nrarr$rz2This is not one of the allowed sizes of this image)ryr}r@)rZr~rZsimple_size�scaler"rrrrs �Nr�84int | None�Image.core.PixelAccess | NonecCs�|dur|jdd�\}}||||f|_|||f|_tj�|�}|jdur0|jj|jkr0|S|��|j�|j�}|��}|j|_|j	|_85|j|_|S)Nr$)rrzr�loadZ_imr2Zload_preparerwrqrCrx)rZr�width�heightZpxr2rrrr�'szIcnsImageFile.load)r
rV)r
r)r~rr
rVr^)rr�r
r�)rrrsrt�__doc__�format�format_descriptionr|�propertyr�setterr�rrrrru�s8687rur2rmrv�filename�str | bytesrVc	Cs�t|d�r	|��ddddddddd�}d	d88�|j�dg�D�}i}t|���D]!}||vr2||n|�||f�}t��}|�	|d�|�89�||<q(g}	|��D]\}90}||}|	�|91t
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)za92    Saves the image as a series of PNG files,93    that are then combined into a .icns file.94    �flushr(rQrPirSrR)rMrKrIrHrOrNrLrJcSsi|]}|j|�qSr)r�)�.0r2rrr�95<dictcomp>Qsz_save.<locals>.<dictcomp>Z
append_imagesZpngr96css�|]}|dVqdS)rNr)r��entryrrr�	<genexpr>gs�z_save.<locals>.<genexpr>z>isTOC rrr$N)�hasattrr�Zencoderinforg�set�values�resizerArB�save�getvaluer`r/rrn�write�MAGIC�sumr�pack)r2rvr�raZprovided_imagesZsize_streamsr�image�temp�entries�type�streamZfile_lengthr�rrr�_save?sT97�98��99100101�r��prefix�bytes�boolcCs102|�t�Sr^)r>r�)r�rrrrX{s103rXz.icnsz104image/icns�__main__r$z)Syntax: python3 IcnsImagePlugin.py [file]�rbrazout-�-z.pngzout.png�windows)rrr
r)rrrrrrr
r)r2rmrvrr�r�r
rV)r�r�r
r�)1�105__future__rrA�osr�sys�typingr�rrrrZcheck_codecr?r	r�rrr#rr;rFrGrur�rXZ
register_openr�Zregister_extensionZ
register_saveZ
register_mimerrrn�argv�print�exit�openrvZimfryrr�r�rr�r2�platform�	startfilerrrr�<module>sV106107108109
110-111%i112B113<114 �115�$��
Aluode/PerceptionLabPortable · CoolFace