ó
P'—^c           @   s¤   d  d l  m Z m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ	 d
 e f d „  ƒ  YZ
 d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   Imaget
   ImageColort   ImageEnhancet   ProcessorPipelinec           B   s   e  Z d  Z d „  Z RS(   s  
    A :class:`list` of other processors. This class allows any object that
    knows how to deal with a single processor to deal with a list of them.
    For example::

        processed_image = ProcessorPipeline([ProcessorA(), ProcessorB()]).process(image)

    c         C   s$   x |  D] } | j  | ƒ } q W| S(   N(   t   process(   t   selft   imgt   proc(    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR      s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR      s   t   Adjustc           B   s,   e  Z d  Z d d d d d „ Z d „  Z RS(   s   
    Performs color, brightness, contrast, and sharpness enhancements on the
    image. See :mod:`PIL.ImageEnhance` for more imformation.

    g      ð?c         C   s(   | |  _  | |  _ | |  _ | |  _ d S(   s·  
        :param color: A number between 0 and 1 that specifies the saturation
            of the image. 0 corresponds to a completely desaturated image
            (black and white) and 1 to the original color.
            See :class:`PIL.ImageEnhance.Color`
        :param brightness: A number representing the brightness; 0 results in
            a completely black image whereas 1 corresponds to the brightness
            of the original. See :class:`PIL.ImageEnhance.Brightness`
        :param contrast: A number representing the contrast; 0 results in a
            completely gray image whereas 1 corresponds to the contrast of
            the original. See :class:`PIL.ImageEnhance.Contrast`
        :param sharpness: A number representing the sharpness; 0 results in a
            blurred image; 1 corresponds to the original sharpness; 2
            results in a sharpened image. See
            :class:`PIL.ImageEnhance.Sharpness`

        N(   t   colort
   brightnesst   contrastt	   sharpness(   R   R   R   R   R   (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyt   __init__   s    			c         C   sÊ   | j  d ƒ } } x° d d d d g D]œ } t |  | j ƒ  ƒ } | d k r& y" t t | ƒ | ƒ j | ƒ } Wn t k
 r‚ qÂ X| d	 k rÂ t j d | j ƒ  d  | j ƒ  d d !ƒ } qÂ q& q& W| S(
   Nt   RGBAt   Colort
   Brightnesst   Contrastt	   Sharpnessg      ð?i   i   (   R   R   (	   t   convertt   getattrt   lowerR   t   enhancet
   ValueErrorR    t   merget   split(   R   R   t   originalt   namet   factor(    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR   0   s    "!(   R   R	   R
   R   R   (    (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR      s   t
   Reflectionc           B   s)   e  Z d  Z d d d d „ Z d „  Z RS(   s.   
    Creates an image with a reflection.

    s   #FFFFFFg        g333333ã?c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   background_colort   sizet   opacity(   R   R!   R"   R#   (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR   H   s    		c         C   s¸  t  j |  j ƒ } | j d ƒ } | j ƒ  j t j ƒ } t j d | j	 | ƒ } t
 d d |  j ƒ } t
 d |  j	 ƒ } d | t | ƒ } t j d d ƒ } xS t d ƒ D]E }	 |	 | k  r× t
 |	 | | ƒ }
 n d }
 | j d |	 f |
 ƒ q® W| j | j	 ƒ } t j | | | ƒ } t
 | j	 d |  j	 ƒ } | j d d | j	 d | f ƒ } t j d | j	 d | j	 d | f | ƒ } | j | d ƒ | j | d | j	 d f ƒ | S(   NR   iÿ   t   Li   i    (   i   iÿ   (   i    i    (   R   t   getrgbR!   R   t   copyt	   transposeR    t   FLIP_TOP_BOTTOMt   newR"   t   intR#   t   floatt   ranget   putpixelt   resizet	   compositet   cropt   paste(   R   R   R!   t
   reflectiont
   backgroundt   startt   stepst	   incrementt   maskt   yt   valt
   alpha_maskt   reflection_heightR/   (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR   M   s*    "-(   R   R	   R
   R   R   (    (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR    C   s   t	   Transposec           B   sµ   e  Z d  Z d Z e j Z e j Z e j	 Z	 e j
 Z
 e j Z e g Z i g  d 6e g d 6e
 g d 6e g d 6e e g d 6e g d 6e	 e g d 6e	 g d	 6Z d
 „  Z d „  Z RS(   s&   
    Rotates or flips the image.

    t   autoi   i   i   i   i   i   i   i   c         G   s)   t  t |  ƒ j ƒ  | r% | |  _ n  d S(   s  
        Possible arguments:
            - Transpose.AUTO
            - Transpose.FLIP_HORIZONTAL
            - Transpose.FLIP_VERTICAL
            - Transpose.ROTATE_90
            - Transpose.ROTATE_180
            - Transpose.ROTATE_270

        The order of the arguments dictates the order in which the
        Transposition steps are taken.

        If Transpose.AUTO is present, all other arguments are ignored, and
        the processor will attempt to rotate the image according to the
        EXIF Orientation data.

        N(   t   superR<   R   t   methods(   R   t   args(    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR   ‰   s    c         C   s‰   |  j  |  j k r\ y! | j ƒ  d } |  j | } Wqe t t t t f k
 rX g  } qe Xn	 |  j } x | D] } | j | ƒ } ql W| S(   Ni  (	   t   AUTOR?   t   _getexift   _EXIF_ORIENTATION_STEPSt
   IndexErrort   KeyErrort	   TypeErrort   AttributeErrorR'   (   R   R   t   orientationt   opst   method(    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR   Ÿ   s    	(   R   R	   R
   RA   R    t   FLIP_LEFT_RIGHTt   FLIP_HORIZONTALR(   t   FLIP_VERTICALt	   ROTATE_90t
   ROTATE_180t
   ROTATE_270R?   RC   R   R   (    (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR<   q   s&   						



	t   Anchorc           B   s˜   e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 d	 Z i	 d e 6d e 6d e 6d e
 6d e	 6d e 6d e 6d e 6d e 6Z e d „  ƒ Z RS(   sQ   
    Defines all the anchor points needed by the various processor classes.

    t   tlt   tt   trt   blt   bt   brt   ct   lt   ri    g      à?i   c         C   s)   |  t  j j ƒ  k r% t  j |  }  n  |  S(   sA   Normalizes anchor values (strings or tuples) to tuples.

        (   RQ   t   _ANCHOR_PTSt   keys(   t   anchor(    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyt	   get_tupleÈ   s    (   i    i    (   g      à?i    (   i   i    (   i    g      à?(   g      à?g      à?(   i   g      à?(   i    i   (   g      à?i   (   i   i   (   R   R	   R
   t   TOP_LEFTt   TOPt	   TOP_RIGHTt   BOTTOM_LEFTt   BOTTOMt   BOTTOM_RIGHTt   CENTERt   LEFTt   RIGHTR[   t   staticmethodR^   (    (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyRQ   ­   s*   
t
   MakeOpaquec           B   s#   e  Z d  Z d d „ Z d „  Z RS(   s‚   
    Pastes the provided image onto an image of a solid color. Used for when you
    want to make transparent images opaque.

    iÿ   c         C   s   | |  _  d  S(   N(   R!   (   R   R!   (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR   Ú   s    c         C   s>   | j  d ƒ } t j d | j |  j ƒ } | j | | ƒ | S(   NR   (   R   R    R)   R"   R!   R1   (   R   R   t   new_img(    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyR   Ý   s    (   iÿ   iÿ   iÿ   (   R   R	   R
   R   R   (    (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyRi   Ô   s   N(   t
   pilkit.libR    R   R   t   listR   t   objectR   R    R<   RQ   Ri   (    (    (    s8   /tmp/pip-unpacked-wheel-gNgxnH/pilkit/processors/base.pyt   <module>   s   0.<'