
    :h.                        d dl mZ d dlZd dlmZ d dlmZmZ ddlm	Z	m
Z
 ddlmZ  G d d	      Zdd
ZddZddZddZddZddZddZeeeeeeedZi f	 	 	 	 	 	 	 ddZi f	 	 	 	 	 	 	 ddZi f	 	 	 	 	 	 	 ddZy)    )annotationsN)CodeType)AnyCallable   )Image_imagingmath)	deprecatec                  8   e Zd ZdZd%dZd&dZ	 	 d'	 	 	 	 	 	 	 	 	 d(dZd)dZd*dZd*dZ	d*d	Z
d+d
Zd+dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZd*dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZ d+d Z!d+d!Z"d+d"Z#d+d#Z$d+d$Z%y),_Operandz4Wraps an image operand, providing standard operatorsc                    || _         y N)im)selfr   s     K/var/www/urcfiles/bundle/venv/lib/python3.12/site-packages/PIL/ImageMath.py__init__z_Operand.__init__   s	        c                    t        |t              r{|j                  j                  dv r|j                  j	                  d      S |j                  j                  dv r|j                  S d|j                  j                   }t        |      t        |t        t        f      rC| j                  j                  dv r+t        j                  d| j                  j                  |      S t        j                  d| j                  j                  |      S )N)1LI)r   Fzunsupported mode: )r   r   r   r   )
isinstancer   r   modeconvert
ValueErrorintfloatr   newsize)r   im1msgs      r   __fixupz_Operand.__fixup!   s    c8$vv{{j(vv~~c**
*vv*366;;-8 o% #U|,1PyydggllC88yydggllC88r   Nc                0   | j                  |      }|t        j                  |xs |j                  |j                  d       }	 t        t        | d|j                         }t        j                  ||j                         |j                                t        |      S | j                  |      }	|j                  |	j                  k7  r@|j                  dk7  r|j                  d      }|	j                  dk7  r|	j                  d      }	|j                  |	j                  k7  rt        |j                  d   |	j                  d         t        |j                  d   |	j                  d         f}
|j                  |
k7  r|j                  d|
z         }|	j                  |
k7  r|	j                  d|
z         }	t        j                  |xs |j                  |j                  d       }	 t        t        | d|j                         }t        j                  ||j                         |j                         |	j                                t        |      S # t        $ r}d| d}t        |      |d }~ww xY w# t        $ r}d| d}t        |      |d }~ww xY w)N_zbad operand type for ''r   r   r   )r   r   )_Operand__fixupr   r   r   r    getattrr	   AttributeError	TypeErrorunopgetimr   mincropbinopr   )r   opr!   im2r   im_1outer"   im_2r    s              r   applyz_Operand.apply3   s)    ||C ;))D-DIItyy$?C,\bT499++>? b#))+tzz|<6 }1 <<$DyyDII%99#<<,D99#<<,DyyDII% 		!diil3		!diil3 99$99Vd]3D99$99Vd]3D))D-DIItyy$?C,\bT499++>? r399;

djjlK}= " ,.rd!4n!+,4 " ,.rd!4n!+,s0   I &I5 	I2I--I25	J>JJc                :    | j                   j                         d uS r   )r   getbboxr   s    r   __bool__z_Operand.__bool__a   s    ww ,,r   c                &    | j                  d|       S )Nabsr6   r9   s    r   __abs__z_Operand.__abs__e       zz%&&r   c                    | S r    r9   s    r   __pos__z_Operand.__pos__h   s    r   c                &    | j                  d|       S )Nnegr=   r9   s    r   __neg__z_Operand.__neg__k   r?   r   c                (    | j                  d| |      S Naddr=   r   others     r   __add__z_Operand.__add__o       zz%u--r   c                (    | j                  d||       S rG   r=   rI   s     r   __radd__z_Operand.__radd__r       zz%--r   c                (    | j                  d| |      S Nsubr=   rI   s     r   __sub__z_Operand.__sub__u   rL   r   c                (    | j                  d||       S rQ   r=   rI   s     r   __rsub__z_Operand.__rsub__x   rO   r   c                (    | j                  d| |      S Nmulr=   rI   s     r   __mul__z_Operand.__mul__{   rL   r   c                (    | j                  d||       S rW   r=   rI   s     r   __rmul__z_Operand.__rmul__~   rO   r   c                (    | j                  d| |      S Ndivr=   rI   s     r   __truediv__z_Operand.__truediv__   rL   r   c                (    | j                  d||       S r]   r=   rI   s     r   __rtruediv__z_Operand.__rtruediv__   rO   r   c                (    | j                  d| |      S Nmodr=   rI   s     r   __mod__z_Operand.__mod__   rL   r   c                (    | j                  d||       S rc   r=   rI   s     r   __rmod__z_Operand.__rmod__   rO   r   c                (    | j                  d| |      S Npowr=   rI   s     r   __pow__z_Operand.__pow__   rL   r   c                (    | j                  d||       S ri   r=   rI   s     r   __rpow__z_Operand.__rpow__   rO   r   c                &    | j                  d|       S )Ninvertr=   r9   s    r   
__invert__z_Operand.__invert__   s    zz(D))r   c                (    | j                  d| |      S Nandr=   rI   s     r   __and__z_Operand.__and__   rL   r   c                (    | j                  d||       S rr   r=   rI   s     r   __rand__z_Operand.__rand__   rO   r   c                (    | j                  d| |      S Norr=   rI   s     r   __or__z_Operand.__or__       zz$e,,r   c                (    | j                  d||       S rx   r=   rI   s     r   __ror__z_Operand.__ror__   s    zz$t,,r   c                (    | j                  d| |      S Nxorr=   rI   s     r   __xor__z_Operand.__xor__   rL   r   c                (    | j                  d||       S r   r=   rI   s     r   __rxor__z_Operand.__rxor__   rO   r   c                (    | j                  d| |      S )Nlshiftr=   rI   s     r   
__lshift__z_Operand.__lshift__       zz(D%00r   c                (    | j                  d| |      S )Nrshiftr=   rI   s     r   
__rshift__z_Operand.__rshift__   r   r   c                (    | j                  d| |      S )Neqr=   rI   s     r   __eq__z_Operand.__eq__   r{   r   c                (    | j                  d| |      S )Nner=   rI   s     r   __ne__z_Operand.__ne__   r{   r   c                (    | j                  d| |      S )Nltr=   rI   s     r   __lt__z_Operand.__lt__   r{   r   c                (    | j                  d| |      S )Nler=   rI   s     r   __le__z_Operand.__le__   r{   r   c                (    | j                  d| |      S )Ngtr=   rI   s     r   __gt__z_Operand.__gt__   r{   r   c                (    | j                  d| |      S )Nger=   rI   s     r   __ge__z_Operand.__ge__   r{   r   )r   Image.Image)r!   _Operand | floatreturnr   )NN)
r0   strr!   r   r1   _Operand | float | Noner   z
str | Noner   r   )r   bool)r   r   )rJ   r   r   r   )&__name__
__module____qualname____doc__r   r'   r6   r:   r>   rB   rE   rK   rN   rS   rU   rY   r[   r_   ra   re   rg   rk   rm   rp   rt   rv   rz   r}   r   r   r   r   r   r   r   r   r   r   rA   r   r   r   r      s    >9, (,++ + %	+
 + 
+\-''............*..--..11------r   r   c                J    t        | j                  j                  d            S )Nr   r   r   r   r9   s    r   imagemath_intr          DGGOOC())r   c                J    t        | j                  j                  d            S )Nr   r   r9   s    r   imagemath_floatr      r   r   c                ,    | j                  d| |d      S )Nr   r   r   r=   rI   s     r   imagemath_equalr          ::dD%c:22r   c                ,    | j                  d| |d      S )Nr   r   r   r=   rI   s     r   imagemath_notequalr      r   r   c                (    | j                  d| |      S )Nr-   r=   rI   s     r   imagemath_minr          ::eT5))r   c                (    | j                  d| |      S )Nmaxr=   rI   s     r   imagemath_maxr      r   r   c                J    t        | j                  j                  |            S r   r   )r   r   s     r   imagemath_convertr      s    DGGOOD)**r   )r   r   equalnotequalr-   r   r   c                Z   |rt        ddd       t        j                         }|j                  |       |j                  |       |j	                         D ].  \  }}t        |t        j                        s!t        |      ||<   0  | |      }	 |j                  S # t        $ r |cY S w xY w)a  
    Returns the result of an image function.

    :py:mod:`~PIL.ImageMath` only supports single-layer images. To process multi-band
    images, use the :py:meth:`~PIL.Image.Image.split` method or
    :py:func:`~PIL.Image.merge` function.

    :param expression: A function that receives a dictionary.
    :param options: Values to add to the function's dictionary. Deprecated.
                    You can instead use one or more keyword arguments.
    :param **kw: Values to add to the function's dictionary.
    :return: The expression result. This is usually an image object, but can
             also be an integer, a floating point value, or a pixel tuple,
             depending on the expression.
    zImageMath.lambda_eval options   z'ImageMath.lambda_eval keyword arguments)
r
   opscopyupdateitemsr   r   r   r   r)   )
expressionoptionskwargskvr3   s          r   lambda_evalr      s    * +5	
 88:DKKKKO

1a%qkDG  T
Cvv 
s   B B*)B*c                  	 |rt        ddd       t        j                         t        |j	                               t        |j	                               z   D ]'  }d|v st        t        |      sd| d}t        |       j                  |       j                  |       j                         D ].  \  }}t        |t        j                        s!t        |      |<   0 t        | dd      d	fd		 	       t        j                  | d
dt        ii      }	 |j                   S # t"        $ r |cY S w xY w)a  
    Evaluates an image expression. This uses Python's ``eval()`` function to process
    the expression string, and carries the security risks of doing so. It is not
    recommended to process expressions without considering this.
    :py:meth:`~lambda_eval` is a more secure alternative.

    :py:mod:`~PIL.ImageMath` only supports single-layer images. To process multi-band
    images, use the :py:meth:`~PIL.Image.Image.split` method or
    :py:func:`~PIL.Image.merge` function.

    :param expression: A string containing a Python-style expression.
    :param options: Values to add to the evaluation context. Deprecated.
                    You can instead use one or more keyword arguments.
    :param **kw: Values to add to the evaluation context.
    :return: The evaluated expression. This is usually an image object, but can
             also be an integer, a floating point value, or a pixel tuple,
             depending on the expression.
    zImageMath.unsafe_eval optionsr   z'ImageMath.unsafe_eval keyword arguments__r&   ' not allowedz<string>evalc                    | j                   D ]!  }t        |      t              u s |       # | j                  D ]  }|vs|dk7  sd| d}t        |       y )Nr<   r&   r   )	co_conststypeco_namesr   )codeconstnamer"   r   compiled_codescans       r   r   zunsafe_eval.<locals>.scanD  s_    ^^EE{d=11U $ MMD4DEM$}- o% "r   
__builtinsr<   )r   r   r   None)r
   r   r   listkeyshasattrbuiltinsr   r   r   r   r   r   compiler   r<   r   r)   )
r   r   r   r   r"   r   r3   r   r   r   s
          @@@r   unsafe_evalr     s   0 +5	
 88:D',,.!DO319!,aS&CS/! 4
 	KKKKO

1a%qkDG  J
F;M& 	
--
\E3<$@$
GCvv 
s   $D0 0D>=D>c                6    t        ddd       t        | |fi |S )a1  
    Evaluates an image expression.

    Deprecated. Use lambda_eval() or unsafe_eval() instead.

    :param expression: A string containing a Python-style expression.
    :param _dict: Values to add to the evaluation context.  You
                  can either use a dictionary, or one or more keyword
                  arguments.
    :return: The evaluated expression. This is usually an image object, but can
             also be an integer, a floating point value, or a pixel tuple,
             depending on the expression.

    ..  deprecated:: 10.3.0
    zImageMath.evalr   z.ImageMath.lambda_eval or ImageMath.unsafe_eval)r
   r   )r   _dictr   s      r   r   r   V  s)    * 
8
 z5/B//r   )r   r   r   r   )r   r   rJ   r   r   r   )r   r   r   r   r   r   )r   zCallable[[dict[str, Any]], Any]r   dict[str, Any]r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )
__future__r   r   typesr   typingr   r    r   r	   
_deprecater
   r   r   r   r   r   r   r   r   r   r   r   r   rA   r   r   <module>r      s   " #     ! !e- e-R**
33**+
 "  !'/'' ' 		'X !=== = 		=D 000 0 		0r   