ó <×ď[c@sKddlmZmZmZddlmZddlZddlZddlZddl Z ddl Z ddl Z e ej dƒZerŸddlmZndZd„Zd„Zd „Zd „Zd „Zd efd „ƒYZdejfd„ƒYZd„Zejejed„ƒejejdƒe jdkrnejejeƒejejdƒne dkrGe!e j"ƒdkrĄdGHe j#ƒnee$e j"ddƒƒZ%xBe%j&dD]3Z'e'e%_'e%j(ƒe%j)Z)e)j*de'ƒqËWej$e j"dƒZ)e)j*dƒe jdkrGej+dƒqGndS(i˙˙˙˙(tImaget ImageFiletPngImagePlugin(ti8Ntjp2klib_version(tJpeg2KImagePluginicCstjd|jtƒƒS(Ns>4sI(tstructtunpacktreadt HEADERSIZE(tfobj((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyt nextheader"scCsa|\}}|j|ƒ|jdƒ}|dkrCtdƒ‚nt||d|df|ƒS(Niss'Unknown signature, expecting 0x00000000(tseekRt SyntaxErrortread_32(R t start_lengthtsizetstarttlengthtsig((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pytread_32t&s    c Csđ|\}}|j|ƒ|d|d|d|df}|d|d}||dkr’|j|ƒ}tjd||ddddƒ}nStjd|d ƒ}x;tdƒD]-} g} |} xš| dkr|jdƒ} | sîPnt| ƒ} | d@rD| d} |jdƒ} xDt| ƒD]}| j| ƒq*Wn | d} | j|j| ƒƒ| | 8} | dkrÉPqÉqÉW| dkrĄt d | ƒ‚ntjd |d j | ƒdd ddƒ}|j j |j | ƒq´Wi|d6S( sn Read a 32bit RGB icon resource. Seems to be either uncompressed or an RLE packbits-like scheme. iiiitRGBtrawi€i}sError reading channel [%r left]tLtN( R RRt frombuffertnewtNonetrangeRtappendR tjointimtputband(R RRRRt pixel_sizetsizesqtindataRtband_ixtdatat byteslefttbytet blocksizetitband((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyR0sB  $$       $cCs‚|d}|j|ƒ|d|d|d|df}|d|d}tjd||j|ƒddddƒ}i|d6S(NiiiRRtA(R RRR(R RRRR!R"R*((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pytread_mk^s  $$c Cs|\}}|j|ƒ|jdƒ}|d dkr_|j|ƒtj|ƒ}i|d6S|d dks‹|d dks‹|dkrts td ƒ‚n|j|ƒ|j|ƒ}tj|ƒ}tj |ƒ}|j dkrű|j dƒ}ni|d6Std ƒ‚dS( Ni is‰PNG  tRGBAis˙O˙Qs ‡ s jP ‡ sQUnsupported icon subimage format (rebuild PIL with JPEG 2000 support to fix this)s Unsupported icon subimage format( R RRt PngImageFilet enable_jpeg2kt ValueErrortiotBytesIORtJpeg2KImageFiletmodetconvert( R RRRRRRt jp2kstreamtf((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pytread_png_or_jpeg2000js(       tIcnsFilecBs=eZi defgd!6defgd"6defgd#6defgd$6defgd%6d efd efd efgd&6d efgd'6defgd(6defdefgd)6defdefdefgd*6defgd+6defdefdefgd,6Zd„Zd„Zd„Z d„Z d-d „Z RS(.tic10iitic09itic14itic08tic13i€tic07tit32tt8mkticp6i@tic12i tih32th8mki0ticp5til32tl8mktic11iticp4tis32ts8mkcCsËi|_}||_t|ƒ\}}|dkrCtdƒ‚nt}x{||krĆt|ƒ\}}|dkr…tdƒ‚n|t7}|t8}||f||<|j|dƒ||7}qLWdS(s@ fobj is a file-like object as an icns resource ticnssnot an icns fileisinvalid block headeriN(tdctR R R R R (tselfR RNRtfilesizeR)R(((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyt__init__´s      cCsag}xT|jjƒD]C\}}x4|D],\}}||jkr)|j|ƒPq)q)WqW|S(N(tSIZEStitemsRNR(ROtsizesRtfmtstfmttreader((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyt itersizesÉs  cCs+|jƒ}|s!tdƒ‚nt|ƒS(NsNo 32bit icon resources found(RXR tmax(RORT((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pytbestsizeŇs cCsei}xX|j|D]I\}}|jj|ƒ}|dk r|j||j||ƒƒqqW|S(s 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(RRRNtgetRtupdateR (RORRNtcodeRWtdesc((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyt dataforsizeŘs  #cCs´|dkr|jƒ}nt|ƒdkrG|d|ddf}n|j|ƒ}|jddƒ}|rr|S|jdƒjƒ}y|j|dƒWntk rŻnX|S(NiiiR-RR+(RRZtlenR_R[tcopytputalphatKeyError(RORtchannelsR((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pytgetimageĺs  (iii(iii(iii(iii(i€i€i(i€i€i(i@i@i(i i i(i0i0i(i i i(iii(iiiN( t__name__t __module__R8RR,RRRRQRXRZR_RRe(((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyR9„s2          t IcnsImageFilecBsMeZdZdZdZd„Zed„ƒZejd„ƒZd„Z RS(s! 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. tICNSsMac OS icns resourcecCsƒt|jƒ|_d|_|jjƒ|jd<|jjƒ|_|jd|jd|jd|jdf|_d|_ dS(NR-RTiiiR(R( R9tfpRMR4RXtinfoRZt best_sizeRttile(RO((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyt_open s cCs|jS(N(t_size(RO((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyRscCs|}||jdkrEt|ƒdkrE|d|ddf}n||jdkrät|ƒdkrä|ddkräg|jdD]*}|d|d|d|df^qˆ}||krä|jd|j|ƒ}qän||jdkrtdƒ‚n||_dS(NRTiiiis2This is not one of the allowed sizes of this image(RkR`tindexR0Ro(ROtvaluet info_sizeRt simple_sizes((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyRs%%;   cCsęt|jƒdkrW|j|_|jd|jd|jd|jdf|_ntjj|ƒ|jstdS|jƒ|jj|jƒ}|jƒ|j |_ |j |_ |j|_d|_ d|_d|_|j ƒdS(Niiii((R`RRlRtloadRmt load_prepareRMReRR4RRjtload_end(ROR((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyRt's" !         ( RfRgt__doc__tformattformat_descriptionRntpropertyRtsetterRt(((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyRhűs  c Csút|dƒr|jƒntjdƒ}d„|jjdgƒDƒ}d}xţddddd gD]ç}d j||ƒ}tj j ||d ƒ}||krśt j | |ƒn4|j||j ||ftjƒƒ} | j|ƒtj j ||d ƒ} |j|d |j |d |d ftjƒƒ} | j| ƒ|d }qfWddlm} m} m}dddd||g}ttjdƒ}| |d| d|ƒ}WdQX|jjƒ|jƒ}t j|ƒ|rö|||ƒ‚ndS(sĽ Saves the image as a series of PNG files, that are then converted to a .icns file using the macOS command line utility 'iconutil'. macOS only. tflushs.iconsetcSsi|]}||j“qS((twidth(t.0R((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pys Ms t append_imagesii i€iis icon_{}x{}s.pngs@2x.pngii˙˙˙˙(tPopentPIPEtCalledProcessErrorticonutils-cRMs-otwbtstdouttstderrN(thasattrR|ttempfiletmkdtempt encoderinfoR[RRxtostpathRtshutiltcopyfiletresizeRtLANCZOStsavet subprocessR€RR‚topentdevnullR…tclosetwaittrmtree(RRjtfilenameticonsettprovided_imagestlast_wtwtprefixt first_patht second_pathtim_wtim_w2R€RR‚t convert_cmdR”t convert_proctretcode((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pyt_save@s4  ' 3    cCs|d dkS(NiRM((tx((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pytrss.icnstdarwins image/icnst__main__is(Syntax: python IcnsImagePlugin.py [file]itrbRTsout-%s-%s-%s.pngsout.pngtwindows(,tPILRRRt PIL._binaryRR1R‹RRtsysRˆR‡tcoreR/RR R RRR,R8tobjectR9RhRĽt register_openRxtregister_extensiontplatformt register_savet register_mimeRfR`targvtexitR“timfRkRRtRR‘t startfile(((s3/tmp/pip-build-SKekGm/pillow/PIL/IcnsImagePlugin.pytsN        . wE 1