ó
È4ec           @   sQ  d  d l  Z  d  d l Z d d l m Z m Z d d l m Z m Z m	 Z	 d d l
 m Z d Z d „  Z i d d 6d d 6d
 d 6d
 d 6d d  6d d! 6d d" 6d d# 6Z d e j f d „  ƒ  YZ d „  Z d e j f d „  ƒ  YZ e j d e ƒ e j e j e e ƒ e j e j e ƒ e j e j d ƒ e j e j d d d d g ƒ d S($   iÿÿÿÿNi   (   t   Imaget	   ImageFile(   t   i8t   i16bet   o8(   t   py3s   0.3c         C   s"   t  |  ƒ d k o! t |  ƒ d k S(   Ni   iÚ  (   t   lent   i16(   t   prefix(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/SgiImagePlugin.pyt   _accept%   s    t   Li   s   L;16Bt   RGBi   s   RGB;16Bt   RGBAi   s   RGBA;16Bt   SgiImageFilec           B   s   e  Z d  Z d Z d „  Z RS(   t   SGIs   SGI Image File Formatc         C   s  d } |  j  j | ƒ } t | ƒ d k r9 t d ƒ ‚ n  t | d ƒ } t | d ƒ } t | d ƒ } t | d ƒ } t | d ƒ } t | d	 ƒ } | | | f }	 d
 }
 y t |	 }
 Wn t k
 rÏ n X|
 d
 k rë t d ƒ ‚ n  | | f |  _ |
 j d ƒ d |  _	 |  j	 d k r+d |  _
 n  d } | d k rá| | | } | d k r…d d |  j | |  j	 d | f f g |  _ qg  |  _ | } x |  j	 D]< } |  j j d d |  j | | d | f f ƒ | | 7} qžWn7 | d k rd d |  j | |
 | | f f g |  _ n  d  S(   Ni   iÚ  s   Not an SGI image filei   i   i   i   i   i
   t    s   Unsupported SGI image modet   ;i    R   s	   image/rgbiÿÿÿÿt   SGI16t   rawi   t   sgi_rle(   i    i    (   i    i    (   i    i    (   t   fpt   readR   t
   ValueErrorR   t   MODESt   KeyErrort   _sizet   splitt   modet   custom_mimetypet   sizet   tilet   append(   t   selft   headlent   st   compressiont   bpct	   dimensiont   xsizet   ysizet   zsizet   layoutt   rawmodet   orientationt   pagesizet   offsett   layer(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/SgiImagePlugin.pyt   _open<   sF    .		#(   t   __name__t
   __module__t   formatt   format_descriptionR/   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/SgiImagePlugin.pyR   7   s   c         C   sB  |  j  d k r< |  j  d k r< |  j  d k r< t d ƒ ‚ n  |  j } | j d d ƒ } | d k rr t d ƒ ‚ n  d	 } d
 } d } d } |  j \ }	 }
 |  j  d k r½ |
 d k r½ d } n |  j  d k rÕ d } n  t |  j  ƒ } | d k sü | d k rd } n  t |  j ƒ  ƒ | k rBt d | t |  j ƒ  ƒ f ƒ ‚ n  d } d } t j j	 t j j
 | ƒ ƒ d } t r‹| j d d ƒ } n  d } | j t j d | ƒ ƒ | j t | ƒ ƒ | j t | ƒ ƒ | j t j d | ƒ ƒ | j t j d |	 ƒ ƒ | j t j d |
 ƒ ƒ | j t j d | ƒ ƒ | j t j d | ƒ ƒ | j t j d | ƒ ƒ | j t j d d ƒ ƒ | j t j d | ƒ ƒ | j t j d d ƒ ƒ | j t j d | ƒ ƒ | j t j d d ƒ ƒ d } | d k rþd } n  x3 |  j ƒ  D]% } | j | j d | d | ƒ ƒ qW| j ƒ  d  S(   NR   R   R
   s   Unsupported SGI image modeR$   i   i   s%   Unsupported number of bytes per pixeliÿÿÿÿiÚ  i    i   s0   incorrect number of bands in SGI write: %s vs %siÿ   t   asciit   ignores   >hs   >Hs   >lt   4sR   t   79sR"   t   404ss   L;16BR   (   i   i   (   R   R   t   encoderinfot   getR   R   t   getbandst   ost   patht   splitextt   basenameR   t   encodet   writet   structt   packR   R   t   tobytest   close(   t   imR   t   filenamet   infoR$   R+   t   magicNumbert   rlet   dimt   xt   yt   zt   pinmint   pinmaxt   imgNamet   colormapR*   t   channel(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/SgiImagePlugin.pyt   _save‚   s^    -				""	#t   SGI16Decoderc           B   s   e  Z e Z d  „  Z RS(   c   	      C   sÅ   |  j  \ } } } |  j j |  j j } t |  j ƒ } |  j j d ƒ xw t | ƒ D]i } t	 j
 d |  j j |  j j f ƒ } | j |  j j d | ƒ d d | | ƒ |  j j | j | ƒ qT Wd S(	   Ni   R
   i   R   s   L;16Biÿÿÿÿi    (   iÿÿÿÿi    (   t   argst   stateR&   R'   R   R   t   fdt   seekt   rangeR    t   newt	   frombytesR   RF   t   putband(	   R    t   bufferR*   t   strideR+   R,   R(   t   bandRS   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/SgiImagePlugin.pyt   decodeÐ   s    $#(   R0   R1   t   Truet	   _pulls_fdRa   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/SgiImagePlugin.pyRU   Í   s   R   s	   image/sgis   .bws   .rgbs   .rgbas   .sgi(   i   i   i   (   i   i   i   (   i   i   i   (   i   i   i   (   i   i   i   (   i   i   i   (   i   i   i   (   i   i   i   (   R<   RB   R   R    R   t   _binaryR   R   R   R   t   _utilR   t   __version__R	   R   R   RT   t	   PyDecoderRU   t   register_decodert   register_openR2   t   register_savet   register_mimet   register_extensions(    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/SgiImagePlugin.pyt   <module>   s.   	
K	K