Ñò
…n+Oc           @   s  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d „  Z d d d d d d g Z d	 „  Z d
 „  Z d e i f d „  ƒ  YZ	 d d „ Z d „  Z d „  Z d „  Z e  i d e	 ƒ e  i d e ƒ e d j o4e i d p d GHe i ƒ  n e i d Z e e ƒ p d GHe i ƒ  n d Z e e i d ƒ d j o e i d Z n e  i e ƒ Z d e e ƒ GHd e e i ƒ GHd e e i ƒ GHd e e i ƒ GHd Ge i ƒ  GHe d j oA e i e  i ƒ Z d e i  i! e ƒ e f GHe i" e d ƒ qn d S(   iÿÿÿÿNc         C   s9   y* t  |  ƒ } |  | d j o d Sd SWn d SXd  S(   Ni    i   (   t   int(   t   ft   i(    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   isInt'   s     i   i   iõÿÿÿiôÿÿÿiëÿÿÿiêÿÿÿc         C   s²   d
 |  } x9 d d d d d d d g D] } t  | | ƒ p d	 Sq& Wt | d ƒ } | t j o d	 St | d ƒ } t | d ƒ } t | d ƒ } | | | j o 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.6/dist-packages/PIL/SpiderImagePlugin.pyt   isSpiderHeader6   s    
  	  c         C   s…   t  |  d ƒ } | i d ƒ } | i ƒ  d } t i d | ƒ } t | ƒ } | d j o( d } t i d | ƒ } t | ƒ } n | S(   Nt   rbi\   i   s   >23fi    s   <23f(   t   opent   readt   closet   structt   unpackR   (   t   filenamet   fpR   t	   bigendianR   t   hdrlen(    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   isSpiderImageG   s    
t   SpiderImageFilec           B   sD   e  Z d  Z d Z d „  Z d „  Z d „  Z d d „ Z d „  Z RS(   t   SPIDERs   Spider 2D imagec      	   C   s†  d } |  i  i | ƒ } y} d |  _ t i d | ƒ } t | ƒ } | d j o+ d |  _ t i d | ƒ } t | ƒ } n | d j o t d ‚ n Wn t i j
 o t d ‚ n Xd | } t | d	 ƒ } | d j o t d
 ‚ n t | d ƒ t | d ƒ f |  _	 t | d ƒ |  _
 t | d ƒ |  _ |  i
 d j o# |  i d j o | } d |  _ n¼ |  i
 d j oh |  i d j oX t | d ƒ t | d ƒ d |  _ | |  _ t | d ƒ |  _ | d } d |  _ nD |  i
 d j o* |  i d j o | |  i } d |  _
 n
 t d ‚ |  i o d |  _ n
 d |  _ d |  _ d d |  i	 | |  i d d f f g |  _ |  i  |  _ 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   R   R   R   R   t   SyntaxErrort   errorR    t   sizet   istackt	   imgnumbert   nimagest   imgbytesR   t	   stkoffsett   rawmodet   modet   tilet   _SpiderImageFile__fp(   t   selft   nR   R   R   R   R   t   offset(    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   _openZ   sR    		
#  %	
 	
		c         C   s$   |  i  d j  o d S|  i  d Sd  S(   Ni   i    (   R   (   R'   (    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   tell“   s    c         C   s}   |  i  d j o d  S| |  i j o t d ‚ n |  i | |  i |  i |  _ |  i |  _ |  i i |  i ƒ |  i	 ƒ  d  S(   Ni    s    attempt to seek past end of file(
   R   R    t   EOFErrorR   R!   R"   R&   R   t   seekR*   (   R'   t   frame(    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyR-   ™   s    iÿ   c         C   sa   |  i  ƒ  \ } } d } | | j o | | | } n | | } |  i | | d „ ƒ i d ƒ S(   Ni   c         S   s   |  | | S(    (    (   R   t   mt   b(    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   <lambda>ª   s    t   L(   t
   getextremat   pointt   convert(   R'   t   deptht   mint   maxR/   R0   (    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   convert2byte¤   s    c         C   s%   d d  k  } | i |  i ƒ  d d ƒS(   Niÿÿÿÿt   palettei   (   t   ImageTkt
   PhotoImageR9   (   R'   R;   (    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   tkPhotoImage­   s    (	   t   __name__t
   __module__t   formatt   format_descriptionR*   R+   R-   R9   R=   (    (    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyR   U   s   	9			c         C   s½   |  d j p t |  ƒ d j  o d Sg  } x‹ |  D]ƒ } t i i | ƒ p d | GHq2 n y t i | ƒ i ƒ  } Wn$ t | ƒ p | d GHq2 q2 n X| | i	 d <| i
 | ƒ q2 W| S(   s2    create a list of Image.images for use in montage i   Ns   unable to find %ss    is not a Spider image fileR   (   t   Nonet   lent   ost   patht   existst   ImageR   R9   R   t   infot   append(   t   filelistt   imglistt   imgt   im(    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   loadImageSeriesµ   s"      	c         C   sG  |  i  \ } } | d } d | } d | d j o | d 7} n | | } g  } | d } x! t | ƒ D] } | i d ƒ qi Wt | ƒ d j  o g  Sd | d <t | ƒ | d <d | d	 <t | ƒ | d
 <t | ƒ | d <t | ƒ | d <t | ƒ | d <| d } | i d ƒ g  }	 x' | D] }
 |	 i t i d |
 ƒ ƒ q W|	 S(   Ni   i   i    i   g        i   g      ð?i   i   i   i   i   R   (   R   t   rangeRI   RC   t   floatR   t   pack(   RM   t   nsamt   nrowR
   R   R	   t   hdrt   nvaluesR   t   hdrstrt   v(    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   makeSpiderHeaderÌ   s6    

 

 


 c         C   sÐ   |  i  d d j o |  i d ƒ }  n t |  ƒ } t | ƒ d j  o t d ‚ n y t | d ƒ } Wn t d | ‚ n X| i | ƒ d } t i |  | d d
 |  i	 d | d d	 f f g ƒ | i
 ƒ  d  S(   Ni    R   i   s   Error creating Spider headert   wbs   Unable to open %s for writings   F;32NFR   i   (   i    i    (   R$   R5   RX   RC   t   IOErrorR   t
   writelinest	   ImageFilet   _saveR   R   (   RM   R   R   RT   R#   (    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyR]   ì   s    2c         C   s<   t  i i | ƒ \ } } t i d | ƒ t |  | | ƒ d  S(   NR   (   RD   RE   t   splitextRG   t   register_extensionR]   (   RM   R   R   t   fnt   ext(    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   _save_spider   s    R   t   __main__s9   Syntax: python SpiderImagePlugin.py Spiderimage [outfile]s$   input image must be in Spider formatt    i   s   image: s   format: s   size: s   mode: s
   max, min: s%   saving a flipped version of %s as %s (#   RG   R\   RD   R   t   sysR   R   R   R   R   RB   RN   RX   R]   Rb   t   register_opent   register_saveR>   t   argvt   exitR   t   outfileRC   R   RM   t   strR@   R   R$   R3   t	   transposet   FLIP_LEFT_RIGHTRE   t   basenamet   save(    (    (    s?   /usr/local/lib/python2.6/dist-packages/PIL/SpiderImagePlugin.pyt   <module>$   sD   $			`	 		