³ò
djOc        	   @   s{   d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z d e f d „  ƒ  YZ d „  Z	 d d „ Z d S(   iÿÿÿÿN(   t   Imaget   BadImageExceptionc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t   value(   t   selfR   (    (    s:   /home/wjholcomb/.../projects/unsorted/us_map/image_hull.pyt   __init__   s    c         C   s   t  |  i ƒ S(   N(   t   reprR   (   R   (    (    s:   /home/wjholcomb/.../projects/unsorted/us_map/image_hull.pyt   __str__   s    (   t   __name__t
   __module__R   R   (    (    (    s:   /home/wjholcomb/.../projects/unsorted/us_map/image_hull.pyR      s   	c         C   sQ  t  |  t ƒ o t i |  ƒ }  n |  i d j	 o t d |  |  i f ƒ ‚ n g  } |  i d d g } x¿ |  i ƒ  D]± } | d |  i d j o* t } t } d | d <| d c d 7<n | d d j	 o | p | d d j o | o t	 } | i
 | ƒ n | d d j	 } | d c d 7<qv Wt i | ƒ \ } } | i | ƒ | S(   s<   Computes the convex hull for an image with an alpha channel.t   RGBAs'   Format Error: '%s' is %s; RGBA expectedi    iÿÿÿÿi   i   (   t
   isinstancet
   basestringR    t   opent   modeR   t   sizet   getdatat   Falset   Truet   appendt   polygont   convexHullst   extend(   t   imaget
   edgePointst   currentt   pixelt	   edgeFoundt   previousSolidt   uppert   lower(    (    s:   /home/wjholcomb/.../projects/unsorted/us_map/image_hull.pyt	   imageHull   s,     
c         C   s{   t  i |  ƒ } t i t | ƒ ƒ } | d  j o* t i i |  ƒ \ } } | d | } n | i	 | ƒ i
 | ƒ | | f S(   Ns   .trimmed(   R    R   R   t   boundingRectangleR   t   Nonet   ost   patht   splitextt   cropt   save(   t   filenamet   newFilenameR   t   extentst   filet   ext(    (    s:   /home/wjholcomb/.../projects/unsorted/us_map/image_hull.pyt	   trimImage-   s    (   t   sysR!   t   matht   getoptR   t   PILR    t	   ExceptionR   R   R    R+   (    (    (    s:   /home/wjholcomb/.../projects/unsorted/us_map/image_hull.pys   <module>   s   	