
    |Le                       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z   e	z   Z
d Z ej        dd	d	d	
          d             Z ej        dd	d	d	
          d             Zej                            dd          dk    Zer(e                                 e                                 i Zd Zed             Zed             Zed             Zed             Zd Zed             Zed             Zed             Ze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           	         |r| n| dz   }|rB|t           vr7t          d| dd                    d t           D                                 d S |t          vr7t          d| dd                    d t          D                                 d S )N_arrz	Operator z+ not one of the supported image operators: z, c              3  4   K   | ]}t          |          V  d S Nrepr.0els     4lib/python3.11/site-packages/datashader/composite.py	<genexpr>z$validate_operator.<locals>.<genexpr>   s(      -Q-Q2d2hh-Q-Q-Q-Q-Q-Q    z+ not one of the supported array operators: c              3  D   K   | ]}t          |d d                   V  d S )Nr   r   s     r   r   z$validate_operator.<locals>.<genexpr>   s0      )R)RB$r#2#w--)R)R)R)R)R)Rr   )image_operators
ValueErrorjoinarray_operators)howis_imagenames      r   r   r      s    ,33fD U&&*"ssDII-Q-Q-Q-Q-Q$Q$Q$QS T T T '& 
_	$	$j33		)R)R/)R)R)R R R RT U U 	U 
%	$r   z	(uint32,)T)nopythonnogilcachec                    t          j        | dz  dz            }t          j        | dz	  dz  dz            }t          j        | dz	  dz  dz            }t          j        | dz	  dz  dz            }||||fS )z2Extract components as float64 values in [0.0, 1.0]            )npfloat64)xrgbas        r   extract_scaledr2      s~     	
Q^s*++A

Q1WOs*++A

Q"WOs*++A

Q"WOs*++AaA:r   z$(float64, float64, float64, float64)c                v   t          dt          j        | dz                      }t          dt          j        |dz                      }t          dt          j        |dz                      }t          dt          j        |dz                      }t          j        |dz  |dz  z  |dz  z  |z            S )z+Combine components in [0, 1] to rgba uint32r'   r*   r)   r(   )minr+   uint32)r.   r/   r0   r1   r2g2b2a2s           r   combine_scaledr:   '   s     
S")AG$$	%	%B	S")AG$$	%	%B	S")AG$$	%	%B	S")AG$$	%	%B9bBh28,a82=>>>r   NUMBA_DISABLE_JIT0c                    t           rQt          j        |           }|                    t          j        j        t          j        j        f           d|_        nt          j        |           }|t          | j	        <   |S )z2Define and register a new image composite operatorT)
jit_enablednb	vectorize_compile_for_argtystypesr5   _frozenr+   r   __name__ff2s     r   operatorrH   =   sb      \!__
ABBB

\!__&(
#Ir   c                    | dz  r| S |S )Nl      ~  srcdsts     r   r   r   K   s    
Z 

r   c                *   t          |           \  }}}}t          |          \  }}}}	d|z
  }
||	|
z  z   }|dk    rt          j        d          S ||z  ||	z  |
z  z   |z  }||z  ||	z  |
z  z   |z  }||z  ||	z  |
z  z   |z  }t          ||||          S N   r   )r2   r+   r5   r:   )rL   rM   srsgsbsadrdgdbdafactorr1   r.   r/   r0   s                  r   r   r   S   s    #C((NBB#C((NBBVF
R&[AAvvy||	b27V#	#Q&A	b27V#	#Q&A	b27V#	#Q&A!Q1%%%r   c                $   t          |           \  }}}}t          |          \  }}}}	t          d||	z             }
|
dk    rt          j        d          S ||z  ||	z  z   |
z  }||z  ||	z  z   |
z  }||z  ||	z  z   |
z  }t	          ||||
          S rO   r2   r4   r+   r5   r:   )rL   rM   rQ   rR   rS   rT   rU   rV   rW   rX   r1   r.   r/   r0   s                 r   r   r   b   s    #C((NBB#C((NBBArBwAAvvy||	b27	AA	b27	AA	b27	AA!Q1%%%r   c                J   t          |           \  }}}}t          |          \  }}}}	t          d||	z             }
|
dk    rt          j        d          S t          |d|	z
            }||z  ||	z  z   |
z  }||z  ||	z  z   |
z  }||z  ||	z  z   |
z  }t	          ||||
          S rO   r[   )rL   rM   rQ   rR   rS   rT   rU   rV   rW   rX   r1   rY   r.   r/   r0   s                  r   r   r   p   s    #C((NBB#C((NBBArBwAAvvy||QV__F	"rBw	!A	"rBw	!A	"rBw	!A!Q1%%%r   c                :   t           rt          j        |           }|                    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          j        |           }|t          | j        <   |S )z2Define and register a new array composite operatorT)r>   r?   r@   rA   rB   int32int64float32r,   rC   r+   r   rD   rE   s     r   arr_operatorra      s      \!__
HNBHN+	- 	- 	-
HNBHN+	- 	- 	-
Xrx/0	2 	2 	2
Xrx/0	2 	2 	2

\!__&(
#Ir   c                    | r| S |S r   rJ   rK   s     r   r   r      s    
 

r   c                    | |z   S r   rJ   rK   s     r   r   r      s    9r   c                $    t          | |g          S r   )maxrK   s     r   r	   r	          c{r   c                $    t          | |g          S r   )r4   rK   s     r   r
   r
      rf   r   )__doc__
__future__r   numbar?   numpyr+   osr   r   __all__r   jitr2   r:   environgetr>   disable_compiler   rH   r   r   r   r   ra   r   r   r	   r
   rJ   r   r   <module>rr      s.    # " " " " "         				7A
6
H?
ZU U U d$d;;;  <; .$     ? ?   ? jnn0#66#=  %""$$$""$$$     
  
 
& & 
& 

& 
& 

& 
& & 
&  *              r   