
    Ug                       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                  j!                  dd      dk(  Zer ej%                          ej%                          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y)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   }|r4|t         vr+t        d| ddj                  d t         D                    y |t        vr+t        d| ddj                  d t        D                    y )N_arrz	Operator z+ not one of the supported image operators: z, c              3  2   K   | ]  }t        |        y wNrepr.0els     4lib/python3.12/site-packages/datashader/composite.py	<genexpr>z$validate_operator.<locals>.<genexpr>   s     -Q2d2hs   z+ not one of the supported array operators: c              3  8   K   | ]  }t        |d d         y w)Nr   r   s     r   r   z$validate_operator.<locals>.<genexpr>   s     )R/B$r#2w-/s   )image_operators
ValueErrorjoinarray_operators)howis_imagenames      r   r   r      s    3fD&"DII-Q-Q$QS T T ' 
_	$		)R/)R RT U 	U 
%    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      sz     	

Q^s*+A


Q1WOs*+A


Q"WOs*+A


Q"WOs*+AaA:r"   z$(float64, float64, float64, float64)c                `   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99bBh28,a82=>>r"   NUMBA_DISABLE_JIT0c                "   t         r`t        j                  |       }|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   =   s_     \\!_
A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Avyy|	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Avyy|	b27	AA	b27	AA	b27	AA!Q1%%r"   c                "   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Avyy|QV_F	"rBw	!A	"rBw	!A	"rBw	!A!Q1%%r"   c                   t         r)t        j                  |       }|j                  t        j                  j
                  t        j                  j
                  f       |j                  t        j                  j                  t        j                  j                  f       |j                  t        j                  j                  t        j                  j                  f       |j                  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     \\!_
HHNNBHHNN+	-
HHNNBHHNN+	-
XXrxx//0	2
XXrxx//0	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      sp   #   	7A
6
H?
ZU d$d; < .$ ? ? jjnn0#6#= ""$""$   
 
 
& 
& 

& 

& 
& 
&*        r"   