
    Rf.                       d dl mZ d dlZd dlZd dlZd dlZddlmZmZm	Z	m
Z
  e
j        d          ZerddlmZ dZdZd	 Zd
 Zd Zd Zd Z G d d          Z G d dej                  Zd Zd Z ej        ej        ee            ej        ej        d            ej        ej        e            ej        ej        d           edk    r
 eej                   dk     r e!d            ej"                      e#ej         d         d          5 Z$ ee$          Z%e%j&        d         D ].Z'e'x\  Z(Z)Z*e%_'        e%+                    de( de) de* d           / ej#        ej         d                   5 Z,e,+                    d           ddd           n# 1 swxY w Y   ej-        dk    r ej.        d           ddd           dS # 1 swxY w Y   dS dS )     )annotationsN   )Image	ImageFilePngImagePluginfeaturesjpg_2000)Jpeg2KImagePlugins   icns   c                \    t          j        d|                     t                              S )Nz>4sI)structunpackread
HEADERSIZE)fobjs    E/var/www/html/env/lib/python3.11/site-packages/PIL/IcnsImagePlugin.py
nextheaderr   $   s     =:!6!6777    c                    |\  }}|                      |           |                     d          }|dk    rd}t          |          t          | |dz   |dz
  f|          S )N   s       z'Unknown signature, expecting 0x00000000)seekr   SyntaxErrorread_32)r   start_lengthsizestartlengthsigmsgs          r   read_32tr    (   sj    "OUFIIe
))A,,C
!!!7#4%!)VaZ0$777r   c           
        |\  }}|                      |           |d         |d         z  |d         |d         z  f}|d         |d         z  }||dz  k    r1|                     |          }t          j        d||dddd          }nOt          j        d|d          }t          d          D ](}	g }
|}|dk    r|                     d          }|sn|d         }|dz  rB|d	z
  }|                     d          }t          |          D ]}|
                    |           n-|dz   }|
                    |                     |                     ||z  }|dk    rn|dk    |dk    r"d
t          |           d}t          |          t          j        d|d	                    |
          dddd          }|j
                            |j
        |	           *d|iS )zn
    Read a 32bit RGB icon resource.  Seems to be either uncompressed or
    an RLE packbits-like scheme.
    r      r      RGBrawN   }   zError reading channel [z left]Lr   )r   r   r   
frombuffernewrangeappendreprr   joinimputband)r   r   r   r   r   
pixel_sizesizesqindatar/   band_ixdata	bytesleftbyte	blocksizeir   bands                    r   r   r   3   s   
 #OUFIIeq'DG#T!WtAw%67J]Z]*F!6""eZq!LL Yuj$//Qxx 	, 	,GDIa--yy|| Aw$; 6 $s
I99Q<<D"9-- * *D))))* !%qIKK		) 4 4555Y&	>> a--  A~~GYGGG!#&&&#CSXXd^^UCQRTUVVDEMM$'7++++2;r   c           	        |d         }|                      |           |d         |d         z  |d         |d         z  f}|d         |d         z  }t          j        d||                     |          dddd          }d|iS )Nr   r"   r   r(   r%   A)r   r   r)   r   )r   r   r   r   r1   r2   r:   s          r   read_mkr=   ^   s    OEIIeq'DG#T!WtAw%67J]Z]*FCTYYv->->sAqQQD;r   c                   |\  }}|                      |           |                     d          }|d d         dk    rF|                      |           t          j        |           }t	          j        |j                   d|iS |d d         dk    s|d d         dk    s|dk    rt          sd	}t          |          |                      |           |                     |          }t          j
        |          }	t          j        |	          }t	          j        |j                   |j        dk    r|                    d          }d|iS d
}t          |          )N   r   s   PNG

RGBAr   s   OQs   

s      jP  

zQUnsupported icon subimage format (rebuild PIL with JPEG 2000 support to fix this)z Unsupported icon subimage format)r   r   r   PngImageFiler   _decompression_bomb_checkr   enable_jpeg2k
ValueErrorioBytesIOr
   Jpeg2KImageFilemodeconvert)
r   r   r   r   r   r   r/   r   
jp2kstreamfs
             r   read_png_or_jpeg2000rL   h   sa   "OUFIIe
))B--C
2A2w,,,		%(..'000|BQB&&&rr7)))999 	"6  S//!		%YYv&&
Jz"".q11'0007fF##B|0oor   c                      e Zd Zdefgdefgdefgdefgdefgdefdefdefgd	efgd
efgdefdefgdefdefdefgdefgdefdefdefgdZd Zd Z	d Z
d ZddZdS )IcnsFile   ic10   ic09   ic14   ic08   ic13   ic07s   it32s   t8mks   icp6   ic12s   ih32s   h8mks   icp5s   il32s   l8mk   ic11s   icp4s   is32s   s8mk))   rW   r"   )rW   rW   r   )   rX   r"   )rX   rX   r   )r&   r&   r"   )r&   r&   r   )@   rY   r   )    rZ   r"   )0   r[   r   )rZ   rZ   r   )   r\   r"   )r\   r\   r   c                   i x| _         }|| _        t          |          \  }}t          |          sd}t	          |          t
          }||k     rqt          |          \  }}|dk    rd}t	          |          |t
          z  }|t
          z  }||f||<   |                    |t          j                   ||z  }||k     odS dS )z@
        fobj is a file-like object as an icns resource
        znot an icns filer   zinvalid block headerN)	dctr   r   _acceptr   r   r   rE   SEEK_CUR)selfr   r^   r   filesizer   r9   r8   s           r   __init__zIcnsFile.__init__   s    
 3	"4((Xs|| 	#$Cc"""(ll'--NCA~~,!#&&&OA#I9~CHIIi---NA (llllllr   c                    g }| j                                         D ]-\  }}|D ]%\  }}|| j        v r|                    |            n&.|S N)SIZESitemsr^   r,   )ra   sizesr   fmtsfmtreaders         r   	itersizeszIcnsFile.itersizes   sj    ***,, 	 	JD$#  V$(??LL&&&E # r   c                n    |                                  }|sd}t          |          t          |          S )NzNo 32bit icon resources found)rl   r   max)ra   rh   r   s      r   bestsizezIcnsFile.bestsize   s8       	#1Cc"""5zzr   c                    i }| j         |         D ]F\  }}| j                            |          }|%|                     || j        ||                     G|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.
        )rf   r^   getupdater   )ra   r   r^   coderk   descs         r   dataforsizezIcnsFile.dataforsize   sd      Jt, 	: 	:LD&8<<%%D

66$)T488999
r   Nc                   ||                                  }t          |          dk    r|d         |d         df}|                     |          }|                    dd           }|r|S |                    d                                          }	 |                    |d                    n# t          $ r Y nw xY w|S )Nr"   r   r   r@   r$   r<   )ro   lenru   rq   copyputalphaKeyError)ra   r   channelsr/   s       r   getimagezIcnsFile.getimage   s    <==??Dt99>>GT!Wa(D##D))\\&$'' 	I\\%  %%''	KK&&&& 	 	 	D		s   B. .
B;:B;re   )__name__
__module____qualname__rL   r    r=   r   rf   rc   rl   ro   ru   r|    r   r   rN   rN      s@        "678 "678 "678 "678 "678*+hg

  456 456(7G*<=*+gg

  456*+gg
) E6  .           r   rN   c                  \    e Zd ZdZdZdZd Zed             Zej	        d             Zd 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.
    ICNSzMac OS icns resourcec                :   t          | j                  | _        d| _        | j                                        | j        d<   | j                                        | _        | j        d         | j        d         z  | j        d         | j        d         z  f| _        d S )Nr@   rh   r   r"   r   )	rN   fpicns_moderl   inforo   	best_sizer   ra   s    r   _openzIcnsImageFile._open   s    TW%%	
!Y0022	'++--N1q 11N1q 11
			r   c                    | j         S re   )_sizer   s    r   r   zIcnsImageFile.size	  s
    zr   c                   |}|| j         d         vr$t          |          dk    r|d         |d         df}|| j         d         vr`t          |          dk    rM|d         dk    rAd | j         d         D             }||v r&| j         d         |                    |                   }|| j         d         vrd}t          |          || _        d S )Nrh   r"   r   r   r#   c                R    g | ]$}|d          |d         z  |d         |d         z  f%S )r   r"   r   r   ).0r   s     r   
<listcomp>z&IcnsImageFile.size.<locals>.<listcomp>  sD       ;?a47"DGd1g$56  r   z2This is not one of the allowed sizes of this image)r   rw   indexrD   r   )ra   value	info_sizesimple_sizesr   s        r   r   zIcnsImageFile.size  s    	DIg...3y>>Q3F3F"1y|Q7ITYw///I!##!!! CG9WCU  L $$ Ig.|/A/A%/H/HI	DIg...FCS//!


r   c                   t          | j                  dk    rG| j        | _        | j        d         | j        d         z  | j        d         | j        d         z  f| _        t          j                            |           }| j        | j        j        | j        k    r|S |                                  | j                            | j                  }|                                }|j        | _        |j	        | _
        |j        | _        |S )Nr#   r   r"   r   )rw   r   r   r   loadr/   load_preparer   r|   rH   r   )ra   pxr/   s      r   r   zIcnsImageFile.load!  s    ty>>Q!YDNq!DN1$55q!DN1$55DI
 [d##747<49#<#<IY// WWYY%W
G		r   N)r}   r~   r   __doc__formatformat_descriptionr   propertyr   setterr   r   r   r   r   r      s          F/
 
 
   X 
[  [&    r   r   c           	        t          |d          r|                                 ddddddddd}d	 | j                            d
g           D             }i }t	          |                                          D ]e}||v r||         n|                     ||f          }t          j                    }|	                    |d           |
                                ||<   fg }	|                                D ];\  }
}||         }|	                    |
t          t          |          z   |d           <|                    t                      t          }|t          dt          |	          z  z   z  }|t#          d |	D                       z  }|                    t%          j        d|                     |                    d           |                    t%          j        dt          t          |	          t          z  z                        |	D ]K}|                    |d                    |                    t%          j        d|d                              L|	D ]f}|                    |d                    |                    t%          j        d|d                              |                    |d                    gt          |d          r|                                 dS dS )za
    Saves the image as a series of PNG files,
    that are then combined into a .icns file.
    flushr&   rX   rW   i   rZ   rY   )rT   rR   rP   rO   rV   rU   rS   rQ   c                    i | ]
}|j         |S r   )width)r   r/   s     r   
<dictcomp>z_save.<locals>.<dictcomp>M  s    VVVrxVVVr   append_imagespng)typer   streamr   c              3  &   K   | ]}|d          V  dS )r   Nr   )r   entrys     r   	<genexpr>z_save.<locals>.<genexpr>e  s&      ::uV}::::::r   z>is   TOC r   r   r   N)hasattrr   encoderinforq   setvaluesresizerE   rF   savegetvaluerg   r,   r   rw   writeMAGICsumr   pack)r/   r   filenamerh   provided_imagessize_streamsr   imagetempentriesr   r   file_lengthr   s                 r   _saver   ;  s   
 r7 



 	 	E WVbn.@.@RT.U.UVVVOLELLNN## 	- 	- && D!!D$<(( 	 z||

4!]]__TGkkmm 
 

dd#:F#;vNN	
 	
 	
 	

 HHUOOOK:CLL 000K3::'::::::KHHV[{++,,, HHWHHV[zCLL:,EEFFGGG 3 3
v
T5=112222  " "
v
T5=11222
x!!!!r7 





 r   c                (    | d d         t           k    S )Nr   )r   )prefixs    r   r_   r_   y  s    "1":r   z.icnsz
image/icns__main__r"   z)Syntax: python3 IcnsImagePlugin.py [file]rbrh   zout--z.pngzout.pngwindows)/
__future__r   rE   osr   sys r   r   r   r   check_codecrC   r
   r   r   r   r    r   r=   rL   rN   r   r   r_   register_openr   register_extensionregister_saveregister_mimer}   rw   argvprintexitopenr   imfr   r   r   heightscaler   r/   platform	startfiler   r   r   <module>r      s  & # " " " " " 				 				  



 8 8 8 8 8 8 8 8 8 8 8 8$$Z00 $######
8 8 88 8 8( ( (V    D` ` ` ` ` ` ` `NG G G G GI' G G GT; ; ;|    M(- A A A  -w 7 7 7  M(% 0 0 0  M(, 7 7 7z
s38}}q9:::


	chqk4	 	  $BmBHW% 	: 	:D.22 E6538HH8E88F88U8889999UZ$$ 	GGI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	<9$$BL###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ s7   A#G<FGF"	"G%F"	&GGG