Ńň
n+Oc           @   sý   d  d k  Z  d  d k Z d   Z d   Z d   Z d d d  Z d   Z d d  Z e  i	 d	  Z
 d d
  Z d d d  Z e  i d d d  Z d   Z d   Z d   Z d   Z d   Z d d  Z d d  Z e Z d d d d  Z e Z d S(   i˙˙˙˙Nc         C   s   t  |   t  d  j oZ t |   d j o |  \ } } \ } } q t |   d j o |  \ } } } } q n |  } } } } | | | | f S(   Ni   i   (    (   t   typet   len(   t   bordert   leftt   topt   rightt   bottom(    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   _border"   s    c         C   s6   t  i |   o" d d  k } | i |  |  }  n |  S(   Ni˙˙˙˙(   t   Imaget   isStringTypet
   ImageColort   getcolor(   t   colort   modeR
   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   _color,   s    c         C   s   |  i  d j o t d   n] |  i  d j oC |  i  d j o% t |  d j o | | | } n |  i |  St d  d  S(   Nt   Ps   mode P support coming soont   Lt   RGBi   s!   not supported for this image mode(   R   R   (   R   t   NotImplementedErrorR   t   pointt   IOError(   t   imaget   lut(    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   _lut2   s    #i    c         C   sÎ  |  i    } g  } xŹt d t |  d  D]} | | | d !} | d j	 oC y d | | <Wq t j
 o" x | D] } d | | <qu Wq Xn | o-d } x" t d  D] } | | | } qŹ W| | d }	 xk t d  D]] }
 |	 | |
 j o |	 | |
 }	 d | |
 <n | |
 |	 | |
 <d }	 |	 d j o Pqß qß W| | d }	 xu t d d d  D]] } |	 | | j o |	 | | }	 d | | <n | | |	 | | <d }	 |	 d j o PqaqaWn x$ t d  D] }
 | |
 o PqÓqÓWx* t d d d  D] } | | o Pq q W| |
 j o | i t d   q+ d | |
 } |
 | } xc t d  D]U } t | | |  } | d j  o
 d } n | d j o
 d } n | i |  qdWq+ Wt |  |  S(   s+   Maximize image contrast, based on histogrami    i   id   i˙   i˙˙˙˙g     ŕo@N(	   t	   histogramt   rangeR   t   Nonet	   TypeErrort   extendt   intt   appendR   (   R   t   cutofft   ignoreR   R   t   layert   ht   ixt   nt   cutt   lot   hit   scalet   offset(    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   autocontrastL   st        	  	 	 

c         C   sý   |  i  d j p t  t | d  } t | d  } g  } g  } g  } x t d  D] } | i | d | | d | d d  | i | d | | d | d d  | i | d | | d | d d  qT W|  i d  }  t |  | | |  S(   s   Colorize a grayscale imageR   R   i   i    i˙   i   i   (   R   t   AssertionErrorR   R   R   t   convertR   (   R   t   blackt   whitet   redt   greent   bluet   i(    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   colorize   s       ))-c         C   sG   t  |  \ } } } } |  i | | |  i d | |  i d | f  S(   s   Crop border off imagei    i   (   R   t   cropt   size(   R   R   R   R   R   R   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyR4   ­   s    c         C   s%   |  i  |  i t i | i |   |  S(   s%   Deform image using the given deformer(   t	   transformR5   R   t   MESHt   getmesh(   R   t   deformert   resample(    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   deform˝   s    c   	      C   s,  |  i  d j o |  i d  }  n |  i |  } g  } xä t d t |  d  D]Ę } t d	 | | | d ! } t |  d j o | i t d   qQ t t	 i
 |  | d d } | p | i t d   qQ | d } x7 t d  D]) } | i | |  | | | | } qî WqQ Wt |  |  S(
   s   Equalize image histogramR   R   i    i   i   i˙˙˙˙i˙   i   N(   R   R,   R   R   R   t   filterR   R   t   reducet   operatort   addR   R   (	   R   t   maskR"   R   t   bt   histot   stepR$   R2   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   equalizeÍ   s$     
 c   
      C   s   t  |  \ } } } } | |  i d | } | |  i d | } t i |  i | | f t | |  i   }	 |	 i |  | | f  |	 S(   s   Add border to imagei    i   (   R   R5   R   t   newR   R   t   paste(
   R   R   t   fillR   R   R   R   t   widtht   heightt   out(    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   expandę   s    *g        g      ŕ?c         C   sš  t  |  t  g   j o | d | d g } n | d d j p | d d j  o d | d <n | d d j p | d d j  o d | d <n | d j p | d j  o
 d } n t t |  t |  i d  d  t t |  t |  i d  d  f } | d | d |  i d | d d |  i d | d d f } | d | d | d | d f } t | d  t | d  } t | d  t | d  }	 | |	 j o, t |	 t | d  d  }
 | d } n) | d }
 t t | d  |	 d  } t | d t | d |
  | d  } | d j  o
 d } n t | d t | d |  | d  } | d j  o
 d } n |  i | | | |
 | | f  } | i | |  S(	   s   
    This method returns a sized and cropped version of the image,
    cropped to the aspect ratio and size that you request.
    i    i   g      đ?g        g      ŕ?g9îÖ˙ß?i   i   (   R    R   t   floatR5   R4   t   resize(   R   R5   t   methodt   bleedt	   centeringt   bleedPixelst   liveAreat   liveSizet   liveAreaAspectRatiot   aspectRatiot	   cropWidtht
   cropHeightt   leftSidet   topSideRJ   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   fit
  s:    ""
$*$$
*
*
c         C   s   |  i  t i  S(   s   Flip image vertically(   t	   transposeR   t   FLIP_TOP_BOTTOM(   R   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   flipU  s    c         C   s   |  i  d  S(   s   Convert to grayscaleR   (   R,   (   R   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt	   grayscale_  s    c         C   s;   g  } x% t  d  D] } | i d |  q Wt |  |  S(   s   Invert image (negate)i   i˙   (   R   R   R   (   R   R   R2   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   inverti  s
     c         C   s   |  i  t i  S(   s   Flip image horizontally(   R[   R   t   FLIP_LEFT_RIGHT(   R   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   mirrorv  s    c         C   sN   g  } d d | d } x% t  d  D] } | i | | @ q& Wt |  |  S(   s+   Reduce the number of bits per color channeli   i   i   i   (   R   R   R   (   R   t   bitsR   R@   R2   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt	   posterize  s     i   c         C   sY   g  } xC t  d  D]5 } | | j  o | i |  q | i d |  q Wt |  |  S(   s!   Invert all values above thresholdi   i˙   (   R   R   R   (   R   t	   thresholdR   R2   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   solarize  s     c         C   s1   | d j o
 d } n |  i   |  i i |  S(   s    PIL_usm.gblur(im, [radius])g      @N(   R   t   loadt   imt   gaussian_blur(   Rg   t   radius(    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyRh     s    

c         C   se   | d j o
 d } n | d j o
 d } n | d j o
 d } n |  i   |  i i | | |  S(   s.    PIL_usm.usm(im, [radius, percent, threshold])g      @i   i   N(   R   Rf   Rg   t   unsharp_mask(   Rg   Ri   t   percentRd   (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyRj   Š  s    



(   g      ŕ?g      ŕ?(   R   R>   R   R   R   R   R*   R3   R4   t   BILINEARR;   RD   RK   t   NEARESTRZ   R]   R^   R_   Ra   Rc   Re   Rh   t   gblurRj   t   usm(    (    (    s6   /usr/local/lib/python2.6/dist-packages/PIL/ImageOps.pyt   <module>   s*   	
		K	 K	
	
			
