a
    Df                     @  s  d Z ddlmZ ddlZddlZddlZdZdZ	de e	 Z
dd Zejd	d
d
d
ddd Zejdd
d
d
ddd ZejdddkZere  e  i Zdd Zedd Zedd Zedd Zedd Zdd Zedd  Zed!d" Zed#d$ Zed%d& ZdS )'z~
Binary graphical composition operators

See https://www.cairographics.org/operators/; more could easily be added from there.
    )annotationsN)overaddsaturatesource)add_arrmax_arrmin_arr
source_arr)composite_op_lookupvalidate_operatorc                 C  sj   |r| n| d }|r>|t vrftd| ddd t D f n(|tvrftd| ddd tD f d S )NZ_arrz8Operator %r not one of the supported image operators: %sz, c                 s  s   | ]}t |V  qd S Nrepr.0el r   a/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/datashader/composite.py	<genexpr>       z$validate_operator.<locals>.<genexpr>z8Operator %r not one of the supported array operators: %sc                 s  s   | ]}t |d d V  qd S )Nr   r   r   r   r   r      r   )image_operators
ValueErrorjoinarray_operators)howZis_imagenamer   r   r   r      s    r   z	(uint32,)T)ZnopythonZnogilcachec                 C  s`   t | d@ d }t | d? d@ d }t | d? d@ d }t | d? d@ d }||||fS )z2Extract components as float64 values in [0.0, 1.0]            )npfloat64)xrgbar   r   r   extract_scaled   s
    r*   z$(float64, float64, float64, float64)c                 C  sr   t dt| d }t dt|d }t dt|d }t dt|d }t|d> |d> B |d> B |B S )z+Combine components in [0, 1] to rgba uint32r   r"   r!   r    )minr#   uint32)r&   r'   r(   r)   Zr2Zg2b2Za2r   r   r   combine_scaled'   s
    r.   ZNUMBA_DISABLE_JIT0c                 C  sD   t r,t| }|tjjtjjf d|_n
t| }|t| j	< |S )z2Define and register a new image composite operatorT)
jit_enablednb	vectorize_compile_for_argtystypesr,   _frozenr#   r   __name__ff2r   r   r   operator=   s    


r:   c                 C  s   | d@ r| S |S d S )Nl      ~ r   srcdstr   r   r   r   K   s    r   c                 C  s   t | \}}}}t |\}}}}	d| }
||	|
  }|dkrFtdS || ||	 |
  | }|| ||	 |
  | }|| ||	 |
  | }t||||S N   r   )r*   r#   r,   r.   )r<   r=   srsgsbsadrdgdbdafactorr)   r&   r'   r(   r   r   r   r   S   s    
r   c                 C  s   t | \}}}}t |\}}}}	td||	 }
|
dkr@tdS || ||	  |
 }|| ||	  |
 }|| ||	  |
 }t||||
S r>   r*   r+   r#   r,   r.   )r<   r=   r@   rA   rB   rC   rD   rE   rF   rG   r)   r&   r'   r(   r   r   r   r   b   s    
r   c                 C  s   t | \}}}}t |\}}}}	td||	 }
|
dkr@tdS t|d|	 }|| ||	  |
 }|| ||	  |
 }|| ||	  |
 }t||||
S r>   rI   )r<   r=   r@   rA   rB   rC   rD   rE   rF   rG   r)   rH   r&   r'   r(   r   r   r   r   p   s    
r   c                 C  s   t rnt| }|tjjtjjf |tjjtjjf |tjjtjjf |tjjtjjf d|_	n
t
| }|t| j< |S )z2Define and register a new array composite operatorT)r0   r1   r2   r3   r4   int32int64float32r$   r5   r#   r   r6   r7   r   r   r   arr_operator   s$    


rM   c                 C  s   | r| S |S d S r   r   r;   r   r   r   r
      s    r
   c                 C  s   | | S r   r   r;   r   r   r   r      s    r   c                 C  s   t | |gS r   )maxr;   r   r   r   r      s    r   c                 C  s   t | |gS r   )r+   r;   r   r   r   r	      s    r	   )__doc__
__future__r   Znumbar1   numpyr#   osr   r   __all__r   Zjitr*   r.   environgetr0   Zdisable_compiler   r:   r   r   r   r   rM   r
   r   r   r	   r   r   r   r   <module>   sJ   
	
	






