ó
î Xc           @   sã   d  Z  d d l m Z m Z m Z m Z i	 d d 6d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) d* 6Z e j Z e j Z	 e j
 Z d „  Z d e j f d „  ƒ  YZ d „  Z d „  Z e j d e e ƒ e j d d ƒ d S(+   s   0.4iÿÿÿÿ(   t   Imaget	   ImageFilet   ImagePalettet   _binaryt   1i   i    t   Li   t   Pi   t   RGBi   t   CMYKi   i   t   LABi	   c         C   s   |  d  d k S(   Ni   t   8BPS(    (   t   prefix(    (    s6   /usr/lib/python2.7/dist-packages/PIL/PsdImagePlugin.pyt   _accept/   s    t   PsdImageFilec           B   s8   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z RS(   t   PSDs   Adobe Photoshopc         C   sð  |  j  j } | d ƒ } | d  d k s> t | d ƒ d k rM t d ƒ ‚ n  t | d ƒ } t | d ƒ } t | d ƒ } t | | f \ } } | | k r® t d	 ƒ ‚ n  | |  _ t | d
 ƒ t | d ƒ f |  _ t | d ƒ ƒ } | r1| | ƒ }	 | d k r1| d k r1t	 j
 d |	 ƒ |  _ q1n  g  |  _ t | d ƒ ƒ } | rA|  j  j ƒ  | }
 xÙ |  j  j ƒ  |
 k  r=| d ƒ } t | d ƒ ƒ } | t | d ƒ ƒ ƒ } t | ƒ d @sÐ| d ƒ n  | t | d ƒ ƒ ƒ }	 t |	 ƒ d @r| d ƒ n  |  j j | | |	 f ƒ | d k rh|	 |  j d <qhqhWn  g  |  _ t | d ƒ ƒ } | rµ|  j  j ƒ  | }
 t | d ƒ ƒ } | r¢t |  j  ƒ |  _ n  |  j  j |
 ƒ n  t |  j  | d |  j | ƒ |  _ |  j  |  _ d |  _ d  S(   Ni   i   R
   i   s   not a PSD filei   i   i   s   not enough channelsi   i   R   i   s   RGB;Li   i  t   icc_profilei    (   i    i    (   t   fpt   readt   i16t   SyntaxErrort   MODESt   IOErrort   modet   i32t   sizeR   t   rawt   palettet	   resourcest   tellt   i8t   lent   appendt   infot   layerst
   _layerinfot   seekt	   _maketilet   tilet   _fpt   frame(   t   selfR   t   st   psd_bitst   psd_channelst   psd_modeR   t   channelsR   t   datat   endt	   signaturet   idt   name(    (    s6   /usr/lib/python2.7/dist-packages/PIL/PsdImagePlugin.pyt   _open;   sX    &	#		"c         C   sž   | |  j  k r d  Syg | d k r+ t ‚ n  |  j | d \ } } } } | |  _ | |  _ | |  _  |  j |  _ | | f SWn t k
 r™ t d ƒ ‚ n Xd  S(   Ni    i   s   no such layer(   R'   t
   IndexErrorR!   R   R%   R&   R   t   EOFError(   R(   t   layerR2   R   t   bboxR%   (    (    s6   /usr/lib/python2.7/dist-packages/PIL/PsdImagePlugin.pyR#   ‡   s    				c         C   s   |  j  S(   N(   R'   (   R(   (    (    s6   /usr/lib/python2.7/dist-packages/PIL/PsdImagePlugin.pyR   —   s    c         C   s~   |  j  s4 |  j  j |  j k s4 |  j  j |  j k rX t j j |  j |  j d ƒ |  _  n  |  j d k rz t j j |  ƒ n  d  S(   Ni    R   (   t   imR   R   R    t   coret   fillt   load(   R(   (    (    s6   /usr/lib/python2.7/dist-packages/PIL/PsdImagePlugin.pyt   load_prepare›   s
    
*$(   t   __name__t
   __module__t   formatt   format_descriptionR3   R#   R   R<   (    (    (    s6   /usr/lib/python2.7/dist-packages/PIL/PsdImagePlugin.pyR   6   s   	L		c         C   s“  g  } |  j  } xût t t | d ƒ ƒ ƒ ƒ D]Û} t | d ƒ ƒ } t | d ƒ ƒ } t | d ƒ ƒ } t | d ƒ ƒ } g  } g  }	 t t t | d ƒ ƒ ƒ ƒ }
 t |
 ƒ d k r¾ q. n  xq |
 D]i } t | d ƒ ƒ } | d k rò d } n
 d | } |	 j | ƒ t | d ƒ ƒ } | j | | f ƒ qÅ W|	 j ƒ  |	 d g k rTd }	 nE |	 d d	 d g k rrd
 }	 n' |	 d d d	 d g k r“d }	 n d  }	 | d ƒ } d } t | d ƒ ƒ } d } | rÓt | d ƒ ƒ } | rHt | d ƒ ƒ } t | d ƒ ƒ } t | d ƒ ƒ | } t | d ƒ ƒ | } |  j
 | d d ƒ n  | | d 7} t | d ƒ ƒ } | r|  j
 | d ƒ n  | | d 7} t | d ƒ ƒ } | rÂ| | ƒ j d d ƒ } n  | | d 7} n  |  j
 | | d ƒ | j | |	 | | | | f f ƒ q. Wd } xy | D]q \ } }	 } g  } x9 |	 D]1 } t |  | | d ƒ } | r6| j | ƒ q6q6W| |	 | | f | | <| d 7} qW| S(   Ni   i   iÿÿ  t   At   RGBAt   RR   t   Bt   GR   i   t    i    i   i   s   latin-1t   replace(   R   t   ranget   absR   R   t   listR   R   t   sortt   NoneR#   R   t   decodeR$   t   extend(   t   fileR!   R   t   it   y0t   x0t   y1t   x1R    R   t   typest   typet   mR   t   fillerR2   t   combinedt   lengtht   mask_yt   mask_xt   mask_ht   mask_wR7   R%   t   t(    (    s6   /usr/lib/python2.7/dist-packages/PIL/PsdImagePlugin.pyR"   ¥   sz    	%	

			&c         C   s¹  d  } |  j } t | d ƒ ƒ } | d | d } | d | d } |  j ƒ  }	 | d k rÇ g  } x+t | ƒ D]P }
 | |
 } | d k r™ | d 7} n  | j d | |	 | f ƒ |	 | | }	 qp WnÊ | d k r‘d } g  } | | | d ƒ } |  j ƒ  }	 x t | ƒ D]~ }
 | |
 } | d k r5| d 7} n  | j d | |	 | f ƒ x9 t | ƒ D]+ } |	 t | | | d !ƒ }	 | d 7} q[WqWn  |  j |	 ƒ |	 d @rµ| d ƒ n  | S(	   Ni   i    i   i   R   s   ;IR   t   packbits(   RL   R   R   R   RH   R   R#   (   RO   R   R7   R-   R%   R   t   compressiont   xsizet   ysizet   offsett   channelR6   RP   t	   bytecountt   y(    (    s6   /usr/lib/python2.7/dist-packages/PIL/PsdImagePlugin.pyR$   û   s@    	


R   s   .psdN(   R   i   (   i    i   (   R   i   (   i    i   (   R   i   (   i   i   (   R   i   (   i   i   (   s   RGBi   (   i   i   (   s   CMYKi   (   i   i   (   R   i   (   i   i   (   R   i   (   i   i   (   R	   i   (   i	   i   (   t   __version__t   PILR    R   R   R   R   R   t   i16beR   t   i32beR   R   R   R"   R$   t   register_opent   register_extension(    (    (    s6   /usr/lib/python2.7/dist-packages/PIL/PsdImagePlugin.pyt   <module>   s(   "
				o	V	3