o
    'j6hB                     @  s   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
 ddlmZ dZ	 dddZdddZdddZdddZd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.)
    )annotations)logpisinsqrt)IOCallable   )o8g|=middlefloatposreturnc                 C  sL   || kr| t k r
dS d| |  S ||  }d|  } | t k rdS dd| |   S )Ng              ?      ?)EPSILONr   r    r   c/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/PIL/GimpGradientFile.pylinear    s   r   c                 C  s   |t dt t| t  S )Nr   )r   maxr   r   r   r   r   curved/      r   c                 C  s$   t t d tt| |  d d S )Ng       @r   )r   r   r   r   r   r   r   sine3   s   $r   c                 C  s   t dt| |d d  S Nr      r   r   r   r   r   r   sphere_increasing7   r   r   c                 C  s   dt dt| |d   S r   r   r   r   r   r   sphere_decreasing;   r   r   c                   @  s&   e Zd ZU dZded< ddd	d
ZdS )GradientFileNzblist[tuple[float, float, float, list[float], list[float], Callable[[float, float], float]]] | Nonegradient   entriesintr   tuple[bytes, str]c                 C  s~  | j d usJ g }d}| j | \}}}}}}	t|D ]}
|
|d  }||k r9|d7 }| j | \}}}}}}	||k s&|| }|tk rG|	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 }||| | |  qd|dfS )	Nr   r	   r      r          RGBA)r    ranger   r
   r#   appendjoin)selfr"   paletteixx0x1xmrgb0rgb1segmentixwscalergbar   r   r   
getpaletteR   s(   ,,,,zGradientFile.getpalette)r!   )r"   r#   r   r$   )__name__
__module____qualname__r    __annotations__r=   r   r   r   r   r   C   s   
 
r   c                   @  s   e Zd ZdZd	ddZdS )
GimpGradientFilez(File handler for GIMP's gradient format.fp	IO[bytes]r   Nonec              	   C  s   |  dsd}t||  }|dr|   }t|}g | _t|D ]P}|   }dd |d d D }|d |d }}	|d	 }
|d
d }|dd }tt|d  }t|d }|dkrkd}t	|| j
||	|
|||f q'd S )Ns   GIMP Gradientznot a GIMP gradient files   Name: c                 S  s   g | ]}t |qS r   )r   ).0r6   r   r   r   
<listcomp>   s    z-GimpGradientFile.__init__.<locals>.<listcomp>   r   r   r	   r&         zcannot handle HSV colour space)readline
startswithSyntaxErrorstripr#   r    r)   splitSEGMENTSOSErrorr*   )r,   rC   msglinecountr5   sr7   r/   r0   r1   r2   r3   r4   cspacer   r   r   __init__v   s,   
zGimpGradientFile.__init__N)rC   rD   r   rE   )r>   r?   r@   __doc__rW   r   r   r   r   rB   s   s    rB   N)r   r   r   r   r   r   )rX   
__future__r   mathr   r   r   r   typingr   r   _binaryr
   r   r   r   r   r   r   rP   r   rB   r   r   r   r   <module>   s    




0