ó
È4ec           @   sS  d  d l  m Z d d l m Z m Z y d d l m Z e Z Wn e k
 rY e	 Z n Xi e d 6e d 6e d 6Z
 i e d 6e d 6Z i d d 6d d	 6d d
 6Z d „  Z d e j f d „  ƒ  YZ d „  Z d „  Z e j e j e e ƒ e rOe j e j e ƒ e j r&e j e j e ƒ n  e j e j d ƒ e j e j d ƒ n  d S(   iÿÿÿÿ(   t   BytesIOi   (   t   Imaget	   ImageFile(   t   _webpt   RGBXt   RGBAt   RGBs   VP8 t   VP8Xt   VP8Lc         C   sZ   |  d  d k } |  d d !d k } |  d d !t  k } | rV | rV | rV t sR d St Sd  S(   Ni   t   RIFFi   i   t   WEBPi   sE   image file could not be identified because WEBP support not installed(   t   _VP8_MODES_BY_IDENTIFIERt	   SUPPORTEDt   True(   t   prefixt   is_riff_file_formatt   is_webp_filet   is_valid_vp8_mode(    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyt   _accept   s    t   WebPImageFilec           B   s}   e  Z d  Z d Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z	 e
 d „ Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   R
   s
   WebP imagec         C   s)  t  j s¯ t  j |  j j ƒ  ƒ \ } } } |  _ } } | rL | |  j d <n  | rb | |  j d <n  | | f |  _ t | ƒ |  _ d d |  j	 d |  j f g |  _
 d |  _ d  St  j |  j j ƒ  ƒ |  _ |  j j ƒ  \ } } } } } }	 | | f |  _ | |  j d <| d ?d @| d	 ?d @| d
 ?d @| d @f \ }
 } } } | | | |
 f |  j d <| |  _ |	 d k rud n |	 |  _ |	 |  _ g  |  _
 |  j j d ƒ } |  j j d ƒ } |  j j d ƒ } | rÜ| |  j d <n  | rò| |  j d <n  | r| |  j d <n  |  j d t ƒ |  j d ƒ d  S(   Nt   icc_profilet   exift   rawi    i   t   loopi   iÿ   i   i   t
   backgroundR   R   t   ICCPt   EXIFs   XMP t   xmpt   reset(   i    i    (   R   t   HAVE_WEBPANIMt
   WebPDecodet   fpt   readt   modet   infot   _sizeR    t   sizet   tilet	   _n_framest   WebPAnimDecodert   _decodert   get_infot   rawmodet	   get_chunkt   _resett   Falset   seek(   t   selft   datat   widtht   heightR   R   t
   loop_countt   bgcolort   frame_countR!   t   bg_at   bg_rt   bg_gt   bg_bR   (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyt   _open*   sH    	'"	!			c         C   s#   d |  j  k r d  St |  j ƒ  ƒ S(   NR   (   R"   t   Nonet   dictt   getexif(   R/   (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyt   _getexif]   s    c         C   s   |  j  S(   N(   R&   (   R/   (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyt   n_framesb   s    c         C   s   |  j  d k S(   Ni   (   R&   (   R/   (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyt   is_animatedf   s    c         C   se   t  j s t t |  ƒ j | ƒ S| |  j k r= t d ƒ ‚ n  | d k  rX t d ƒ ‚ n  | |  _ d  S(   Ns(   attempted to seek beyond end of sequencei    s!   negative frame index is not valid(   R   R   t   superR   R.   R&   t   EOFErrort   _WebPImageFile__logical_frame(   R/   t   frame(    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyR.   j   s    	c         C   s5   | r |  j  j ƒ  n  d |  _ d |  _ d |  _ d  S(   Ni    iÿÿÿÿ(   R(   R   t   _WebPImageFile__physical_framet   _WebPImageFile__loadedt   _WebPImageFile__timestamp(   R/   R   (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyR,   w   s
    		c         C   s‰   |  j  j ƒ  } |  j d 7_ | d  k rP |  j ƒ  |  j d ƒ t d ƒ ‚ n  | \ } } | |  j } | |  _ | | 8} | | | f S(   Ni   i    s(   failed to decode next frame in WebP file(   R(   t   get_nextRE   R;   R,   R.   RB   RG   (   R/   t   retR0   t	   timestampt   duration(    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyt	   _get_next~   s    
	
c         C   sS   |  j  | k r d  S| |  j  k  r/ |  j ƒ  n  x |  j  | k  rN |  j ƒ  q2 Wd  S(   N(   RE   R,   RL   (   R/   RD   (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyt   _seek’   s    c         C   sÒ   t  j r¿ |  j |  j k r¿ |  j |  j ƒ |  j ƒ  \ } } } | |  j d <| |  j d <|  j |  _ |  j rˆ |  j rˆ |  j j	 ƒ  n  t
 | ƒ |  _ d d |  j d |  j f g |  _ q¿ n  t t |  ƒ j ƒ  S(   NRJ   RK   R   i    (   i    i    (   R   R   RF   RC   RM   RL   R"   R   t   _exclusive_fpt   closeR    R$   R*   R%   RA   R   t   load(   R/   R0   RJ   RK   (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyRP   š   s    	(c         C   s#   t  j s t t |  ƒ j ƒ  S|  j S(   N(   R   R   RA   R   t   tellRC   (   R/   (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyRQ   ­   s    	(   t   __name__t
   __module__t   formatt   format_descriptionR:   R>   t   propertyR?   R@   R.   R   R,   RL   RM   RP   RQ   (    (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyR   %   s   	3					c   '      C   s@  |  j  j ƒ  } t | j d g  ƒ ƒ } d } x+ |  g | D] } | t | d d ƒ 7} q; W| d k r{ t |  | | ƒ d  Sd& } d | k rš | d } nz d |  j k r|  j d } t | t ƒ r|  j	 ƒ  } | r| | d | d d !\ }	 }
 } |	 |
 | d f } qqn  |  j  j d d ƒ } |  j  j d d ƒ } |  j  j d	 t
 ƒ } |  j  j d
 d  ƒ } |  j  j d d  ƒ } |  j  j d t
 ƒ } t
 } |  j  j d t
 ƒ } |  j  j d d ƒ } |  j  j d d ƒ } |  j  j d d ƒ } |  j  j d d ƒ } t | t j ƒ r"| j ƒ  } n  |  j  j d d ƒ } | rFt
 } n  | d  k rg| r^d n d } n  | d  k rˆ| rd n d } n  t | t t f ƒ sÇt | ƒ d k sÇt d „  | Dƒ ƒ ràt d t | ƒ ƒ ‚ n  | \ } } } } | d >| d >B| d >B| d >B} t j |  j d |  j d | | | | | | | ƒ	 } d } d } |  j ƒ  }  zkxd|  g | D]U} t | d d ƒ }! x:t |! ƒ D],}" | j |" ƒ | j ƒ  | }# | j }$ | j t k r8d | j k pd | j k p| j d  k od | j j ƒ  k }% |% r d! n d" }$ | j |$ ƒ }# n  |$ d" k rMd# }$ n  | j  |# j d$ |$ ƒ | |# j d |# j d |$ | | | ƒ t | t t f ƒ r¯| | | 7} n
 | | 7} | d 7} q—WqrWWd  |  j |  ƒ X| j  d  | d d d | | d ƒ | j! | | | ƒ }& |& d  k r/t d% ƒ ‚ n  | j" |& ƒ d  S('   Nt   append_imagesi    R?   i   R   i   RK   R   t   minimize_sizet   kmint   kmaxt   allow_mixedt   losslesst   qualityiP   t   methodR   t    R   R   i	   i   i   i   c         s   s'   |  ] } | d  k o | d k  Vq d S(   i    i   N(    (   t   .0t   v(    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pys	   <genexpr>ê   s    s<   Background color is not an RGBA tuple clamped to (0-255): %si   i   i   t   At   at   PR   R   R   R   s1   cannot write file as WebP (encoder returned None)(   i    i    i    i    (#   t   encoderinfot   copyt   listt   gett   getattrt   _saveR"   t
   isinstancet   intt
   getpaletteR-   R;   R   t   Exift   tobytest   tuplet   lent   allt   IOErrort   strR   t   WebPAnimEncoderR$   RQ   t   rangeR.   RP   R!   t   _VALID_WEBP_MODESt   imt   getpalettemodet   convertt   addt   assemblet   write('   Rx   R   t   filenameRe   RW   t   totalt   imsR   t   palettet   rt   gt   bRK   R   RX   RY   RZ   R[   t   verboseR\   R]   R^   R   R   R   R7   R8   R9   R6   t   enct	   frame_idxRJ   t   cur_idxt   nfrt   idxRD   R*   t   alphaR0   (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyt	   _save_all´   s¾    "	"

	
	$	


"c   
   
   C   si  |  j  j d t ƒ } |  j  j d d ƒ } |  j  j d d ƒ } |  j  j d d ƒ } t | t j ƒ ru | j ƒ  } n  |  j  j d d ƒ } |  j t k rù d |  j k pØ d	 |  j k pØ |  j d
 k oØ d |  j	 j
 ƒ  k } |  j | rí d n d ƒ }  n  t j |  j ƒ  |  j d |  j d | t | ƒ |  j | | | ƒ	 }	 |	 d  k rXt d ƒ ‚ n  | j |	 ƒ d  S(   NR\   R]   iP   R   R_   R   R   Rb   Rc   Rd   R   R   i    i   s1   cannot write file as WebP (encoder returned None)(   Re   Rh   R-   Rk   R   Rn   Ro   R!   t   _VALID_WEBP_LEGACY_MODESRx   Ry   Rz   R   t
   WebPEncodeR$   t   floatR;   Rs   R}   (
   Rx   R   R~   R\   R]   R   R   R   R‹   R0   (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyRj   @  s2    $	

		s   .webps
   image/webpN(   t   ioR    R_   R   R   R   R   R   t   ImportErrorR-   Rw   R   R   R   R   RŒ   Rj   t   register_openRT   t   register_saveR   t   register_save_allt   register_extensiont   register_mime(    (    (    s=   /usr/local/lib/python2.7/dist-packages/PIL/WebPImagePlugin.pyt   <module>   s.   


		Œ	"	