
    &Th.                        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j0                  ee        ej2                  ej0                  d        ej4                  ej0                  e        ej6                  ej0                  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#jH                  d   D ]  Z%e%e#_%        e#jM                  de%z           ejB                  ej<                  d         5 Z'e'jM                  d       ddd       ejP                  dk(  r ejR                  d       ddd       yy# 1 sw Y   4xY w# 1 sw Y   yxY w)    N   )Image	ImageFilePngImagePluginfeaturesjpg_2000)Jpeg2KImagePlugins   icns   c                 T    t        j                  d| j                  t                    S )Nz>4sI)structunpackread
HEADERSIZE)fobjs    [/home/stella.sw7ft.com/public_html/venv/lib/python3.12/site-packages/PIL/IcnsImagePlugin.py
nextheaderr   #   s    ==:!677    c                     |\  }}| j                  |       | j                  d      }|dk7  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   '   sY    "OUFIIe
))A,C
!!7#4%!)VaZ0$77r   c           
      B   |\  }}| j                  |       |d   |d   z  |d   |d   z  f}|d   |d   z  }||dz  k(  r0| j                  |      }t        j                  d||dddd      }d|iS t        j                  d|d      }t        d      D ]  }	g }
|}|dkD  r| j                  d      }|snx|d   }|dz  r8|d	z
  }| j                  d      }t        |      D ]  }|
j                  |        n%|dz   }|
j                  | j                  |             ||z  }|dk  rn|dkD  r|dk7  rd
t        |       d}t        |      t        j                  d|dj                  |
      dddd      }|j                  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   2   s   
 #OUFIIeq'DG#T!WtAw%67J]Z]*F!6"eZq!L8 2;3 YYuj$/Qx 	,GDIa-yy|Aw$; $s
I99Q<D"9- *D)* !%qIKK		) 45Y&	> a-  A~/Y/@G!#&&##CSXXd^UCQRTUVDEEMM$''7+/	,0 2;r   c           	          |d   }| j                  |       |d   |d   z  |d   |d   z  f}|d   |d   z  }t        j                  d|| j                  |      dddd      }d|iS )Nr   r!   r   r'   r$   A)r   r   r(   r   )r   r   r   r   r0   r1   r9   s          r   read_mkr<   ]   s|    OEIIeq'DG#T!WtAw%67J]Z]*FCTYYv->sAqQD;r   c                 z   |\  }}| j                  |       | j                  d      }|d d dk(  rI| j                  |       t        j                  |       }t	        j
                  |j                         d|iS |d d dk(  s|d d dk(  s|dk(  rt        sd	}t        |      | j                  |       | j                  |      }t        j                  |      }	t        j                  |	      }t	        j
                  |j                         |j                  dk7  r|j                  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_jpeg2000rK   g   s(   "OUFIIe
))B-C
2Aw,,		%((.''0|BQ&&r7))996  S/!		%YYv&
JJz"..q1''077fF#B|0o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y)IcnsFile   ic10   ic09   ic14   ic08   ic13   ic07s   it32s   t8mks   icp6   ic12s   ih32s   h8mks   icp5s   il32s   l8mk   ic11s   icp4s   is32s   s8mk))   rV   r!   )rV   rV   r   )   rW   r!   )rW   rW   r   )r%   r%   r!   )r%   r%   r   )@   rX   r   )    rY   r!   )0   rZ   r   )rY   rY   r   )   r[   r!   )r[   r[   r   c                 P   i x| _         }|| _        t        |      \  }}t        |      sd}t	        |      t
        }||k  ret        |      \  }}|dk  rd}t	        |      |t
        z  }|t
        z  }||f||<   |j                  |t        j                         ||z  }||k  rdyy)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   rD   SEEK_CUR)selfr   r]   r   filesizer   r8   r7   s           r   __init__zIcnsFile.__init__   s    
 3	"4(Xs|$Cc""(l'-NCA~,!#&&OA#I9~CHIIi-NA (lr   c                     g }| j                   j                         D ]0  \  }}|D ]&  \  }}|| j                  v s|j                  |        0 2 |S N)SIZESitemsr]   r+   )r`   sizesr   fmtsfmtreaders         r   	itersizeszIcnsFile.itersizes   s[    ****, 	JD$# V$((?LL&	
 r   c                 V    | j                         }|sd}t        |      t        |      S )NzNo 32bit icon resources found)rk   r   max)r`   rg   r   s      r   bestsizezIcnsFile.bestsize   s+     1Cc""5zr   c                     i }| j                   |   D ]F  \  }}| j                  j                  |      }|$|j                   || j                  ||             H |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.
        )re   r]   getupdater   )r`   r   r]   coderj   descs         r   dataforsizezIcnsFile.dataforsize   s]      JJt, 	:LD&88<<%D

6$))T489	: 
r   Nc                 2   || j                         }t        |      dk(  r|d   |d   df}| j                  |      }|j                  dd       }|r|S |j                  d      j	                         }	 |j                  |d          |S # t        $ r Y |S w xY w)Nr!   r   r   r?   r#   r;   )rn   lenrt   rp   copyputalphaKeyError)r`   r   channelsr.   s       r   getimagezIcnsFile.getimage   s    <==?Dt9>GT!Wa(D##D)\\&$'I\\% %%'	KK& 	  			s   3B	 		BBrd   )__name__
__module____qualname__rK   r   r<   r   re   rb   rk   rn   rt   r{    r   r   rM   rM      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   rM   c                   X    e Zd ZdZdZdZd Zed        Zej                  d        Zd Z
y)	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                 X   t        | j                        | _        d| _        | j                  j	                         | j
                  d<   | j                  j                         | _        | j                  d   | j                  d   z  | j                  d   | j                  d   z  f| _        y )Nr?   rg   r   r!   r   )	rM   fpicnsrG   rk   inforn   	best_sizer   r`   s    r   _openzIcnsImageFile._open   s    TWW%		!YY002		'++-NN1q 11NN1q 11
	r   c                     | j                   S rd   )_sizer   s    r   r   zIcnsImageFile.size  s    zzr   c                    |}|| j                   d   vrt        |      dk(  r|d   |d   df}|| j                   d   vrkt        |      dk(  r]|d   dk(  rU| j                   d   D cg c]  }|d   |d   z  |d   |d   z  f }}||v r!| j                   d   |j                  |         }|| j                   d   vrd}t        |      || _        y c c}w )Nrg   r!   r   r   r"   z2This is not one of the allowed sizes of this image)r   rv   indexrC   r   )r`   value	info_sizer   simple_sizesr   s         r   r   zIcnsImageFile.size  s    	DIIg..3y>Q3F"1y|Q7ITYYw//I!#!! DH99WCU;?a47"DGd1g$56L  $ IIg.|/A/A%/HI	DIIg..FCS/!
s   %Cc                 n   t        | j                        dk(  rT| j                  | _        | j                  d   | j                  d   z  | j                  d   | j                  d   z  f| _        t        j                  j	                  |       }| j
                  %| j
                  j                  | j                  k(  r|S | j                          | j                  j                  | j                        }|j	                         }|j
                  | _        |j                  | _	        |j                  | _        |S )Nr"   r   r!   r   )
rv   r   r   r   loadr.   load_preparer   r{   rG   )r`   pxr.   s      r   r   zIcnsImageFile.load   s    tyy>Q!YYDNq!DNN1$55q!DNN1$55DI
 [[d#77477<<499#<IYY/ WWY%%GG	GG		r   N)r|   r}   r~   __doc__formatformat_descriptionr   propertyr   setterr   r   r   r   r   r      sJ     F/
   
[[ &r   r   c           	         t        |d      r|j                          ddddddddd}| j                  j                  d	g       D  ci c]  } | j                  |  }} i }t        |j                               D ]W  }||v r||   n j                  ||f      }t        j                         }|j                  |d
       |j                         ||<   Y g }	|j                         D ]/  \  }
}||   }|	j                  |
t        t        |      z   |d       1 |j!                  t"               t        }|t        dt        |	      z  z   z  }|t%        d |	D              z  }|j!                  t'        j(                  d|             |j!                  d       |j!                  t'        j(                  dt        t        |	      t        z  z                |	D ]>  }|j!                  |d          |j!                  t'        j(                  d|d                @ |	D ]R  }|j!                  |d          |j!                  t'        j(                  d|d                |j!                  |d          T t        |d      r|j                          yyc c} w )za
    Saves the image as a series of PNG files,
    that are then combined into a .icns file.
    flushr%   rW   rV   i   rY   rX   )rS   rQ   rO   rN   rU   rT   rR   rP   append_imagespng)typer   streamr
   c              3   &   K   | ]	  }|d      yw)r   Nr   ).0entrys     r   	<genexpr>z_save.<locals>.<genexpr>d  s     :uV}:s   z>is   TOC r   r   r   N)hasattrr   encoderinforp   widthsetvaluesresizerD   rE   savegetvaluerf   r+   r   rv   writeMAGICsumr   pack)r.   r   filenamerg   provided_imagessize_streamsr   imagetempentriesr   r   file_lengthr   s                 r   _saver   :  sS   
 r7

 	E /1nn.@.@RT.UVrxx|VOVLELLN# 	- & D!D$<( 	 zz|

4!]]_T	- Gkkm 

dd#:F#;vN	

 HHUOK:CL 000K3:':::KHHV[[{+, HHWHHV[[zCL:,EEFG 3
v
T5=123
  "
v
T5=12
x!"
 r7

 Q Ws   Jc                     | d d t         k(  S )Nr   )r   )prefixs    r   r^   r^   x  s    "1:r   z.icnsz
image/icns__main__r!   z)Syntax: python3 IcnsImagePlugin.py [file]rbrg   zout-%s-%s-%s.pngzout.pngwindows)*rD   osr   sys r   r   r   r   check_codecrB   r	   r   r   r   r   r   r<   rK   rM   r   r   r^   register_openr   register_extensionregister_saveregister_mimer|   rv   argvprintexitopenr   imfr   r   r   r.   platform	startfiler   r   r   <module>r      s  ( 
 	  
 8 8$$$Z0#
88(VD` `NGI'' GT;|   M((- A   --w 7   M((% 0   M((, 7z
388}q9:
	chhqk4	  $BBHHW% 	0DCHHH'$./	0 UZZ$ 	GGI	<<9$BLL#$ $ 	 	$ $s%   -AGG	)G	G	GG