ó
î Xc           @   sÊ  d  d l  m Z m Z m Z m Z d  d l Z d  d l Z e e j d ƒ Z	 e	 re d  d l  m
 Z
 n  e j Z d Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d d d „  ƒ  YZ d e j f d „  ƒ  YZ e j d e d „  ƒ e j d d ƒ e d k rÆd  d l Z d  d l Z e e e j d d ƒ ƒ Z xB e j d D]3 Z e e _ e j ƒ  e j Z e j  d e ƒ qAWe j e e j d d ƒ ƒ Z e j  d ƒ e j! d k rÆe j" d ƒ qÆn  d S(   iÿÿÿÿ(   t   Imaget	   ImageFilet   PngImagePlugint   _binaryNt   jp2klib_version(   t   Jpeg2KImagePlugini   c         C   s   t  j d |  j t ƒ ƒ S(   Ns   >4sI(   t   structt   unpackt   readt
   HEADERSIZE(   t   fobj(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt
   nextheader   s    c         C   sa   | \ } } |  j  | ƒ |  j d ƒ } | d k rC t d ƒ ‚ n  t |  | d | d f | ƒ S(   Ni   t       s'   Unknown signature, expecting 0x00000000(   t   seekR   t   SyntaxErrort   read_32(   R
   t   start_lengtht   sizet   startt   lengtht   sig(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt   read_32t#   s    c      	   C   sð  | \ } } |  j  | ƒ | d | d | d | d f } | d | d } | | d k r’ |  j | ƒ } t j d | | d d d d ƒ } nSt j d | d ƒ } x;t d ƒ D]-}	 g  }
 | } x¹ | d k r|  j d ƒ } | sî Pn  t | ƒ } | d @rD| d } |  j d ƒ } xD t | ƒ D] } |
 j | ƒ q*Wn  | d } |
 j |  j | ƒ ƒ | | 8} | d k rÉ PqÉ qÉ W| d k r¡t	 d	 | ƒ ‚ n  t j d
 | d j
 |
 ƒ d d
 d d ƒ } | j j | j |	 ƒ q´ Wi | d 6S(   sn   
    Read a 32bit RGB icon resource.  Seems to be either uncompressed or
    an RLE packbits-like scheme.
    i    i   i   i   t   RGBt   rawi€   i}   s   Error reading channel [%r left]t   Lt    N(   R   R   R    t
   frombuffert   newt   Nonet   ranget   i8t   appendR   t   joint   imt   putband(   R
   R   R   R   R   t
   pixel_sizet   sizesqt   indataR!   t   band_ixt   datat	   bytesleftt   bytet	   blocksizet   it   band(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyR   -   sB    $$



$c         C   s„   | \ } } |  j  | ƒ | d | d | d | d f } | d | d } t j d | |  j | ƒ d d d d ƒ } i | d 6S(   Ni    i   i   R   R   t   A(   R   R    R   R   (   R
   R   R   R   R   R#   R$   R,   (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt   read_mk[   s    $$c   	      C   s  | \ } } |  j  | ƒ |  j d ƒ } | d  d k r_ |  j  | ƒ t j |  ƒ } i | d 6S| d  d k s‹ | d  d k s‹ | d k rt s  t d	 ƒ ‚ n  |  j  | ƒ |  j | ƒ } t j | ƒ } t j	 | ƒ } | j
 d k rû | j d ƒ } n  i | d 6St d
 ƒ ‚ d  S(   Ni   i   s   ‰PNG

t   RGBAi   s   ÿOÿQs   
‡
t      jP  
‡
sQ   Unsupported icon subimage format (rebuild PIL with JPEG 2000 support to fix this)s    Unsupported icon subimage format(   R   R   R   t   PngImageFilet   enable_jpeg2kt
   ValueErrort   iot   BytesIOR   t   Jpeg2KImageFilet   modet   convert(	   R
   R   R   R   R   R   R!   t
   jp2kstreamt   f(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt   read_png_or_jpeg2000g   s(    t   IcnsFilec           B   s=  e  Z i d  e f g d! 6d e f g d" 6d e f g d# 6d e f g d$ 6d e f g d% 6d
 e f d e f d e f g d& 6d e f g d' 6d e f g d( 6d e f d e f g d) 6d e f d e f d e f g d* 6d e f g d+ 6d e f d e f d e f g d, 6Z d „  Z d „  Z d „  Z	 d „  Z
 d- d  „ Z RS(.   t   ic10i   i   t   ic09i   t   ic14i   t   ic08t   ic13i€   t   ic07t   it32t   t8mkt   icp6i@   t   ic12i    t   ih32t   h8mki0   t   icp5t   il32t   l8mkt   ic11i   t   icp4t   is32t   s8mkc         C   sË   i  |  _  } | |  _ t | ƒ \ } } | d k rC t d ƒ ‚ n  t } x{ | | k  rÆ t | ƒ \ } } | d k r… t d ƒ ‚ n  | t 7} | t 8} | | f | | <| j | d ƒ | | 7} qL Wd S(   s@   
        fobj is a file-like object as an icns resource
        t   icnss   not an icns filei    s   invalid block headeri   N(   t   dctR
   R   R   R	   R   (   t   selfR
   RQ   R   t   filesizeR+   R*   (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt   __init__±   s    	

c         C   sa   g  } xT |  j  j ƒ  D]C \ } } x4 | D], \ } } | |  j k r) | j | ƒ Pq) q) Wq W| S(   N(   t   SIZESt   itemsRQ   R   (   RR   t   sizesR   t   fmtst   fmtt   reader(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt	   itersizesÆ   s    c         C   s+   |  j  ƒ  } | s! t d ƒ ‚ n  t | ƒ S(   Ns   No 32bit icon resources found(   R[   R   t   max(   RR   RW   (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt   bestsizeÏ   s    c         C   se   i  } xX |  j  | D]I \ } } |  j j | ƒ } | d k	 r | j | |  j | | ƒ ƒ q q W| 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(   RU   RQ   t   getR   t   updateR
   (   RR   R   RQ   t   codeRZ   t   desc(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt   dataforsizeÕ   s    #c         C   s´   | d  k r |  j ƒ  } n  t | ƒ d k rG | d | d d f } n  |  j | ƒ } | j d d  ƒ } | rr | S| j d ƒ j ƒ  } y | j | d ƒ Wn t k
 r¯ n X| S(   Ni   i    i   R/   R   R-   (   R   R]   t   lenRb   R^   t   copyt   putalphat   KeyError(   RR   R   t   channelsR!   (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt   getimageâ   s    (   i   i   i   (   i   i   i   (   i   i   i   (   i   i   i   (   i€   i€   i   (   i€   i€   i   (   i@   i@   i   (   i    i    i   (   i0   i0   i   (   i    i    i   (   i   i   i   (   i   i   i   N(   t   __name__t
   __module__R;   R   R.   R   RU   RT   R[   R]   Rb   R   Rh   (    (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyR<      s2   												t   IcnsImageFilec           B   s,   e  Z d  Z d Z d Z d „  Z d „  Z RS(   s+  
    PIL read-only 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.
    t   ICNSs   Mac OS icns resourcec         C   sƒ   t  |  j ƒ |  _ d |  _ |  j j ƒ  |  _ |  j d |  j d |  j d |  j d f |  _ |  j j ƒ  |  j d <d |  _	 d  S(   NR/   i    i   i   RW   R   (   R   (
   R<   t   fpRP   R7   R]   t	   best_sizeR   R[   t   infot   tile(   RR   (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt   _open  s    	c         C   sê   t  |  j ƒ d k rW |  j |  _ |  j d |  j d |  j d |  j d f |  _ n  t j j |  ƒ |  j st d  S|  j ƒ  |  j j |  j ƒ } | j ƒ  | j	 |  _	 | j
 |  _
 | j |  _ d  |  _ d  |  _ d |  _ |  j ƒ  d  S(   Ni   i    i   i   (    (   Rc   R   Rn   R    t   loadRp   t   load_prepareRP   Rh   R!   R7   R   Rm   t   load_end(   RR   R!   (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyRr     s"    !	

			(   Ri   Rj   t   __doc__t   formatt   format_descriptionRq   Rr   (    (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyRk   ø   s
   		
Rl   c         C   s   |  d  d k S(   Ni   RP   (    (   t   x(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt   <lambda>(  s    s   .icnst   __main__i   t   rbRW   s   out-%s-%s-%s.pngs   out.pngt   windows(    (#   t   PILR    R   R   R   R4   R   t   hasattrt   coreR2   R   R   R	   R   R   R   R.   R;   R<   Rk   t   register_opent   register_extensionRi   t   ost   syst   opent   argvt   imfRo   R   Rr   R!   t   savet   platformt	   startfile(    (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IcnsImagePlugin.pyt   <module>   s:   "			
	.		w0	
	