3

h                 @   s   d Z ddlmZmZmZmZ ddlmZ dZdd Z	dd	 Z
d
d Zdd Zdd Ze	e
eeegZG dd dZG dd deZdS )z
Stuff to translate curve segments to palette values (derived from
the corresponding code in GIMP, written by Federico Mena Quintero.
See the GIMP distribution for more information.)
    )logpisinsqrt   )o8g|=c             C   sR   || kr"| t k rdS d| |  S n,||  }d|  } | t k r>dS dd| |   S d S )Ng        g      ?g      ?)EPSILON)middlepos r   T/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/PIL/GimpGradientFile.pylinear   s    r   c             C   s   |t dt t| t  S )Ng      ?)r   maxr   )r	   r
   r   r   r   curved.   s    r   c             C   s$   t t d tt| |  d d S )Ng       @g      ?)r   r   r   )r	   r
   r   r   r   sine2   s    r   c             C   s   t dt| |d d  S )Ng      ?   )r   r   )r	   r
   r   r   r   sphere_increasing6   s    r   c             C   s   dt dt| |d   S )Ng      ?r   )r   r   )r	   r
   r   r   r   sphere_decreasing:   s    r   c               @   s   e Zd ZdZdddZdS )GradientFileN   c             C   sv  g }d}| j | \}}}}}}	xFt|D ]8}
|
|d  }x*||k rf|d7 }| j | \}}}}}}	q>W || }|tk r|	dd}n|	|| | || | }ttd|d |d  | |d   d }ttd|d |d  | |d   d }ttd|d |d  | |d   d }ttd|d |d  | |d   d }|j|| | |  q*W dj|dfS )	Nr   r   g      ?   r          ZRGBA)gradientranger   r   intappendjoin)selfentriesZpaletteixx0x1xmrgb0rgb1segmentixwZscalergbar   r   r   
getpaletteF   s$    
,,,,zGradientFile.getpalette)r   )__name__
__module____qualname__r   r.   r   r   r   r   r   B   s   r   c               @   s   e Zd ZdZdd ZdS )GimpGradientFilez(File handler for GIMP's gradient format.c             C   s   |j  d d dkrtd|j  }|jdr:|j  j }t|}g }xt|D ]}|j  j }dd |d d D }|d |d	  }}	|d
 }
|dd }|dd }tt|d  }t|d }|dkrtd|j	||	|
|||f qPW || _
d S )N   s   GIMP Gradientznot a GIMP gradient files   Name: c             S   s   g | ]}t |qS r   )float).0r(   r   r   r   
<listcomp>}   s    z-GimpGradientFile.__init__.<locals>.<listcomp>   r   r   r   r         zcannot handle HSV colour space)readlineSyntaxError
startswithstripr   r   splitSEGMENTSOSErrorr   r   )r   fplinecountr   r'   sr)   r!   r"   r#   r$   r%   r&   Zcspacer   r   r   __init__k   s(    
zGimpGradientFile.__init__N)r/   r0   r1   __doc__rE   r   r   r   r   r2   h   s   r2   N)rF   mathr   r   r   r   _binaryr   r   r   r   r   r   r   r?   r   r2   r   r   r   r   <module>   s   &