ó
È4ec           @  sD  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z d „  Z d d d d d	 d
 g Z	 d „  Z
 d „  Z d e j f d „  ƒ  YZ d d „ Z d „  Z d „  Z d „  Z e j e j e ƒ e j e j e ƒ e d k r@e e j ƒ d k  re d ƒ e j ƒ  n  e j d Z e e ƒ sKe d ƒ e j ƒ  n  e j e ƒ Z e d e e ƒ ƒ e d e e j ƒ ƒ e d e e j ƒ ƒ e d e e j ƒ ƒ e d d d ƒe e j  ƒ  ƒ e e j ƒ d k r@e j d Z! e j" e j# ƒ Z e d e j$ j% e ƒ e! f ƒ e j& e! e j ƒ q@n  d S(   iÿÿÿÿ(   t   print_functionN(   t   Imaget	   ImageFilec         C  sG   y( t  |  ƒ } |  | d k r# d Sd SWn t t f k
 rB d SXd  S(   Ni    i   (   t   intt
   ValueErrort   OverflowError(   t   ft   i(    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   isInt-   s    i   i   iõÿÿÿiôÿÿÿiëÿÿÿiêÿÿÿc         C  s¬   d
 |  } x7 d d d d d d d g D] } t  | | ƒ s& d	 Sq& Wt | d ƒ } | t k rd d	 St | d ƒ } t | d ƒ } t | d ƒ } | | | k r¨ d	 S| S(   Nic   i   i   i   i   i   i   i   i    (   ic   (   R   R   t   iforms(   t   tt   hR   t   iformt   labrect   labbytt   lenbyt(    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   isSpiderHeaderA   s    
"c         C  sv   t  |  d ƒ  } | j d ƒ } Wd  QXt j d | ƒ } t | ƒ } | d k rr t j d | ƒ } t | ƒ } n  | S(   Nt   rbi\   s   >23fi    s   <23f(   t   opent   readt   structt   unpackR   (   t   filenamet   fpR   R
   t   hdrlen(    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   isSpiderImageU   s    t   SpiderImageFilec           B  sq   e  Z d  Z d Z e Z d „  Z e d „  ƒ Z e d „  ƒ Z	 d „  Z
 d „  Z d d „ Z d	 „  Z d
 „  Z RS(   t   SPIDERs   Spider 2D imagec         C  s  d } |  j  j | ƒ } y| d |  _ t j d | ƒ } t | ƒ } | d k rx d |  _ t j d | ƒ } t | ƒ } n  | d k r“ t d ƒ ‚ n  Wn  t j k
 r¶ t d ƒ ‚ n Xd | } t | d	 ƒ } | d k rì t d
 ƒ ‚ n  t | d ƒ t | d ƒ f |  _	 t | d ƒ |  _
 t | d ƒ |  _ |  j
 d k re|  j d k re| } d |  _ n¸ |  j
 d k rÚ|  j d k rÚt | d ƒ t | d ƒ d |  _ | |  _ t | d ƒ |  _ | d } d |  _ nC |  j
 d k r|  j d k r| |  j } d |  _
 n t d ƒ ‚ |  j r2d |  _ n	 d |  _ d |  _ d d |  j | |  j d d f f g |  _ |  j  |  _ d  S(   Ni   i   i   s   >27fi    s   <27fs   not a valid Spider fileic   i   s   not a Spider 2D imagei   i   i   i   s    inconsistent stack header valuess   F;32BFs   F;32Ft   Ft   rawil   (   ic   (   i    i    (   R   R   t	   bigendianR   R   R   t   SyntaxErrort   errorR   t   _sizet   istackt	   imgnumbert   _nimagest   imgbytesR   t	   stkoffsett   rawmodet   modet   sizet   tilet   _SpiderImageFile__fp(   t   selft   nR   R
   R   R   R   t   offset(    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   _openf   sP    		
#%	
			+c         C  s   |  j  S(   N(   R$   (   R,   (    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   n_frames   s    c         C  s   |  j  d k S(   Ni   (   R$   (   R,   (    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   is_animated¡   s    c         C  s"   |  j  d k  r d S|  j  d Sd  S(   Ni   i    (   R#   (   R,   (    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   tell¦   s    c         C  s|   |  j  d k r t d ƒ ‚ n  |  j | ƒ s1 d  S|  j | |  j |  j |  _ |  j |  _ |  j j |  j ƒ |  j	 ƒ  d  S(   Ni    s#   attempt to seek in a non-stack file(
   R"   t   EOFErrort   _seek_checkR   R%   R&   R+   R   t   seekR/   (   R,   t   frame(    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyR5   ¬   s    iÿ   c         C  s_   |  j  ƒ  \ } } d } | | k r5 | | | } n  | | } |  j | | d „ ƒ j d ƒ S(   Ni   c         S  s   |  | | S(   N(    (   R   t   mt   b(    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   <lambda>½   t    t   L(   t
   getextremat   pointt   convert(   R,   t   deptht   minimumt   maximumR7   R8   (    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   convert2byte·   s    c         C  s)   d d l  m } | j |  j ƒ  d d ƒS(   Niÿÿÿÿ(   t   ImageTkt   palettei   (   t   PILRC   t
   PhotoImageRB   (   R,   RC   (    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   tkPhotoImageÀ   s    c         C  sO   z> y& |  j  |  j k r( |  j  j ƒ  n  Wn t k
 r< n XWd  d  |  _  Xd  S(   N(   R+   R   t   closet   AttributeErrort   None(   R,   (    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt
   _close__fpÅ   s     (   t   __name__t
   __module__t   formatt   format_descriptiont   Falset!   _close_exclusive_fp_after_loadingR/   t   propertyR0   R1   R2   R5   RB   RG   RK   (    (    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyR   `   s   	7				c         C  sÊ   |  d k s t |  ƒ d k  r" d Sg  } x› |  D]“ } t j j | ƒ s[ t d | ƒ q/ n  y t j | ƒ j ƒ  } Wn1 t	 k
 r§ t
 | ƒ s/ t | d ƒ q/ q/ n X| | j d <| j | ƒ q/ W| S(   sJ   create a list of :py:class:`~PIL.Image.Image` objects for use in a montagei   Ns   unable to find %ss    is not a Spider image fileR   (   RJ   t   lent   ost   patht   existst   printR   R   RB   t	   ExceptionR   t   infot   append(   t   filelistt   imglistt   imgt   im(    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   loadImageSeriesÓ   s     c         C  sO  |  j  \ } } | d } t d | ƒ } d | d k rF | d 7} n  | | } g  } t | d ƒ } x! t | ƒ D] } | j d ƒ qs Wt | ƒ d k  r  g  Sd | d <t | ƒ | d <d | d	 <t | ƒ | d
 <t | ƒ | d <t | ƒ | d <t | ƒ | d <| d } | j d ƒ g  }	 x' | D] }
 |	 j t j d |
 ƒ ƒ q(W|	 S(   Ni   i   i    i   g        i   g      ð?i   i   i   i   i   R   (   R)   R   t   rangeRZ   RS   t   floatR   t   pack(   R^   t   nsamt   nrowR   R   R   t   hdrt   nvaluesR   t   hdrstrt   v(    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   makeSpiderHeaderì   s2    




c      	   C  s›   |  j  d d k r% |  j d ƒ }  n  t |  ƒ } t | ƒ d k  rR t d ƒ ‚ n  | j | ƒ d } t j |  | d d |  j d | d d f f g ƒ d  S(	   Ni    R   i   s   Error creating Spider headers   F;32NFR   i   (   i    i    (	   R(   R>   Ri   RS   t   IOErrort
   writelinesR   t   _saveR)   (   R^   R   R   Re   R'   (    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyRl     s    c         C  s=   t  j j | ƒ d } t j t j | ƒ t |  | | ƒ d  S(   Ni   (   RT   RU   t   splitextR   t   register_extensionR   RN   Rl   (   R^   R   R   t   ext(    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   _save_spider  s    t   __main__i   s6   Syntax: python SpiderImagePlugin.py [infile] [outfile]s$   input image must be in Spider formats   image: s   format: s   size: s   mode: s
   max, min: t   endt    s%   saving a flipped version of %s as %s ('   t
   __future__R    RT   R   t   sysRE   R   R   R   R	   R   R   R   RJ   R_   Ri   Rl   Rp   t   register_openRN   t   register_saveRL   RS   t   argvRW   t   exitR   R   R^   t   strR)   R(   R<   t   outfilet	   transposet   FLIP_LEFT_RIGHTRU   t   basenamet   save(    (    (    s?   /usr/local/lib/python2.7/dist-packages/PIL/SpiderImagePlugin.pyt   <module>$   sJ   				s	"		


