ó
È4ec           @   s  d  d l  Z  d  d l Z d  d l m Z d  d l m Z m Z d d l m Z m	 Z	 m
 Z
 m Z d d l m Z m Z m Z d Z d Z d	 „  Z d
 „  Z d e f d „  ƒ  YZ d e
 j
 f d „  ƒ  YZ e	 j e j e e ƒ e	 j e j e ƒ e	 j e j d ƒ e	 j e j d ƒ d S(   iÿÿÿÿN(   t   BytesIO(   t   ceilt   logi   (   t   BmpImagePlugint   Imaget	   ImageFilet   PngImagePlugin(   t   i8t   i16let   i32les   0.1s      c      
      s)  | j  t ƒ |  j j d d d d d d d d g ƒ } |  j \ ‰ ‰  t ‡  ‡ f d	 †  | ƒ } t | ƒ } | j  t j d
 t	 | ƒ ƒ ƒ | j
 ƒ  t	 | ƒ d } x|| D]t} | \ ‰ ‰  | j  t j d ˆ d k  rà ˆ n d ƒ ƒ | j  t j d ˆ  d k  rˆ  n d ƒ ƒ | j  d ƒ | j  d ƒ | j  d ƒ | j  t j d
 d ƒ ƒ t ƒ  } |  j ƒ  } | j | t j ƒ | j | d ƒ | j d ƒ | j ƒ  } t	 | ƒ }	 | j  t j d |	 ƒ ƒ | j  t j d | ƒ ƒ | j
 ƒ  }
 | j | ƒ | j  | ƒ | |	 } | j |
 ƒ q­ Wd  S(   Nt   sizesi   i   i    i0   i@   i€   i   c            sH   |  d ˆ k s@ |  d ˆ  k s@ |  d d k s@ |  d d k rD t  St S(   Ni    i   i   (   t   Falset   True(   t   x(   t   heightt   width(    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyt   <lambda>3   s    Ds   <Ht   Bi    s    s     t   pngs   <I(   i   i   (   i   i   (   i    i    (   i0   i0   (   i@   i@   (   i€   i€   (   i   i   (   t   writet   _MAGICt   encoderinfot   gett   sizet   filtert   listt   structt   packt   lent   tellR    t   copyt	   thumbnailR   t   LANCZOSt   savet   seekt   read(   t   imt   fpt   filenameR
   t   offsetR   t   image_iot   tmpt   image_bytest	   bytes_lent   current(    (   R   R   s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyt   _save+   sB    		++	
c         C   s   |  d  t  k S(   Ni   (   R   (   t   prefix(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyt   _acceptU   s    t   IcoFilec           B   s;   e  Z d  „  Z d „  Z e d „ Z e d „ Z d „  Z RS(   c         C   sð  | j  d ƒ } t | ƒ s* t d ƒ ‚ n  | |  _ g  |  _ t | d ƒ |  _ xWt |  j ƒ D]F} | j  d ƒ } i t | d ƒ d 6t | d ƒ d 6t | d	 ƒ d
 6t | d ƒ d 6t | d ƒ d 6t | d ƒ d 6t	 | d ƒ d 6t	 | d ƒ d 6} x% d D] } | | s	d | | <q	q	W| d p`| d
 d k r]t
 t | d
 d	 ƒ ƒ p`d | d <| d | d f | d <| d | d | d <|  j j | ƒ q_ Wt |  j d d „  ƒ|  _ t |  j d d „  ƒ|  _ |  j j ƒ  d S(   sL   
        Parse image from file-like object containing ico file data
        i   s   not an ICO filei   i   i    R   i   R   i   t   nb_colori   t   reservedt   planest   bppi   R   i   R'   i   t   color_deptht   dimt   squaret   keyc         S   s   |  d S(   NR5   (    (   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyR   Ž   t    c         S   s   |  d S(   NR7   (    (   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyR   ‘   R9   N(   R   R   (   R#   R/   t   SyntaxErrort   buft   entryt   i16t   nb_itemst   rangeR   t   i32R   R   t   appendt   sortedt   reverse(   t   selfR;   t   st   it   icon_headert   j(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyt   __init__Z   s<    		


c         C   s   d „  |  j  Dƒ S(   sJ   
        Get a list of all available icon sizes and color depths.
        c         S   s$   h  |  ] } | d  | d f ’ q S(   R   R   (    (   t   .0t   h(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pys	   <setcomp>˜   s   	 (   R<   (   RD   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyR
   ”   s    c         C   sT   xM t  |  j ƒ D]< \ } } | | d k r | t k sH | | d k r | Sq Wd S(   NR6   R5   i    (   t	   enumerateR<   R   (   RD   R   R4   RF   RK   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyt   getentryindexš   s    ,c         C   s   |  j  |  j | | ƒ ƒ S(   s,   
        Get an image from the icon
        (   t   frameRM   (   RD   R   R4   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyt   getimage    s    c      	   C   sž  |  j  | } |  j j | d ƒ |  j j d ƒ } |  j j | d ƒ | d  t j k ro t j |  j ƒ } n+t j |  j ƒ } t	 j
 | j ƒ | j d t | j d d ƒ f | _ | j d \ } } } } | d | j | | f | j d <| d }	 d }
 x7 t j j ƒ  D]& \ } } |	 | d k r| }
 PqqWd |
 k r­|  j j | ƒ |  j j | j d | j d d ƒ d d	 d … } t	 j d
 | j | d d ƒ } nÑ | j d } | d d k ræ| d | j d d 7} n  | t | j d | j d |
 d ƒ } t | | j d d ƒ } |  j j | ƒ |  j j | ƒ } t	 j d | j | d d t | d ƒ d f ƒ } | j d ƒ } | j | ƒ | S(   s-   
        Get an image from frame idx
        R'   i   i    i   i   i    i   i   Nt   Lt   rawiÿÿÿÿg       @t   1s   1;It   RGBA(   i    i    (   RP   i    iÿÿÿÿ(   R<   R;   R"   R#   R   R   t   PngImageFileR   t   DibImageFileR   t   _decompression_bomb_checkR   t   intt   _sizet   tilet   BIT2MODEt   itemst
   frombuffert   convertt   putalpha(   RD   t   idxt   headert   dataR$   t   dt   et   ot   at   modeR4   t   kt   vt   alpha_bytest   maskt   wt   and_mask_offsett   total_bytest	   mask_data(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyRN   ¦   sT    ' 
5*(   t   __name__t
   __module__RI   R
   R   RM   RO   RN   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyR0   Y   s
   	:	t   IcoImageFilec           B   sV   e  Z d  Z d Z d Z d „  Z e d „  ƒ Z e j d „  ƒ Z d „  Z	 d „  Z
 RS(   sš  
    PIL read-only image support for Microsoft Windows .ico files.

    By default the largest resolution image in the file will be loaded. This
    can be changed by altering the 'size' attribute before calling 'load'.

    The info dictionary has a key 'sizes' that is a list of the sizes available
    in the icon file.

    Handles classic, XP and Vista icon formats.

    When saving, PNG compression is used. Support for this was only added in
    Windows Vista.

    This plugin is a refactored version of Win32IconImagePlugin by Bryan Davis
    <casadebender@gmail.com>.
    https://code.google.com/archive/p/casadebender/wikis/Win32IconImagePlugin.wiki
    t   ICOs   Windows Iconc         C   sM   t  |  j ƒ |  _ |  j j ƒ  |  j d <|  j j d d |  _ |  j ƒ  d  S(   NR
   i    R6   (   R0   R%   t   icoR
   t   infoR<   R   t   load(   RD   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyt   _open  s    c         C   s   |  j  S(   N(   RX   (   RD   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyR     s    c         C   s/   | |  j  d k r" t d ƒ ‚ n  | |  _ d  S(   NR
   s2   This is not one of the allowed sizes of this image(   Rt   t
   ValueErrorRX   (   RD   t   value(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyR      s    c         C   sÓ   |  j  r" |  j  j |  j k r" d  S|  j j |  j ƒ } | j ƒ  | j  |  _  | j |  _ | j |  j k rÏ t j d ƒ |  j j |  j ƒ } t	 |  j
 d ƒ } | j | | <t | ƒ |  j
 d <| j |  _ n  d  S(   Ns   Image was not the expected sizeR
   (   R$   R   Rs   RO   Ru   Rf   t   warningst   warnRM   R   Rt   t   set(   RD   R$   t   indexR
   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyRu   &  s    
c         C   s   d  S(   N(    (   RD   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyt	   load_seek9  s    (   Ro   Rp   t   __doc__t   formatt   format_descriptionRv   t   propertyR   t   setterRu   R}   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyRq   ÿ   s   		s   .icos   image/x-icon(   R   Ry   t   ioR    t   mathR   R   R9   R   R   R   R   t   _binaryR   R   R=   R	   R@   t   __version__R   R-   R/   t   objectR0   Rq   t   register_openR   t   register_savet   register_extensiont   register_mime(    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/IcoImagePlugin.pyt   <module>   s   "	*	¦D