
    h4h(                        d dl mZ d dlZddlmZmZ dZerd dlmZ d dl	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ddZddZy)    )annotationsN   )Image_imagingmathF)Callable)CodeType)Anyc                  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     E/var/www/flask-api/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.apply6   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__d   s    ww ,,r   c                &    | j                  d|       S )Nabsr5   r8   s    r   __abs__z_Operand.__abs__h       zz%&&r   c                    | S r    r8   s    r   __pos__z_Operand.__pos__k   s    r   c                &    | j                  d|       S )Nnegr<   r8   s    r   __neg__z_Operand.__neg__n   r>   r   c                (    | j                  d| |      S Naddr<   r   others     r   __add__z_Operand.__add__r       zz%u--r   c                (    | j                  d||       S rF   r<   rH   s     r   __radd__z_Operand.__radd__u       zz%--r   c                (    | j                  d| |      S Nsubr<   rH   s     r   __sub__z_Operand.__sub__x   rK   r   c                (    | j                  d||       S rP   r<   rH   s     r   __rsub__z_Operand.__rsub__{   rN   r   c                (    | j                  d| |      S Nmulr<   rH   s     r   __mul__z_Operand.__mul__~   rK   r   c                (    | j                  d||       S rV   r<   rH   s     r   __rmul__z_Operand.__rmul__   rN   r   c                (    | j                  d| |      S Ndivr<   rH   s     r   __truediv__z_Operand.__truediv__   rK   r   c                (    | j                  d||       S r\   r<   rH   s     r   __rtruediv__z_Operand.__rtruediv__   rN   r   c                (    | j                  d| |      S Nmodr<   rH   s     r   __mod__z_Operand.__mod__   rK   r   c                (    | j                  d||       S rb   r<   rH   s     r   __rmod__z_Operand.__rmod__   rN   r   c                (    | j                  d| |      S Npowr<   rH   s     r   __pow__z_Operand.__pow__   rK   r   c                (    | j                  d||       S rh   r<   rH   s     r   __rpow__z_Operand.__rpow__   rN   r   c                &    | j                  d|       S )Ninvertr<   r8   s    r   
__invert__z_Operand.__invert__   s    zz(D))r   c                (    | j                  d| |      S Nandr<   rH   s     r   __and__z_Operand.__and__   rK   r   c                (    | j                  d||       S rq   r<   rH   s     r   __rand__z_Operand.__rand__   rN   r   c                (    | j                  d| |      S Norr<   rH   s     r   __or__z_Operand.__or__       zz$e,,r   c                (    | j                  d||       S rw   r<   rH   s     r   __ror__z_Operand.__ror__   s    zz$t,,r   c                (    | j                  d| |      S Nxorr<   rH   s     r   __xor__z_Operand.__xor__   rK   r   c                (    | j                  d||       S r~   r<   rH   s     r   __rxor__z_Operand.__rxor__   rN   r   c                (    | j                  d| |      S )Nlshiftr<   rH   s     r   
__lshift__z_Operand.__lshift__       zz(D%00r   c                (    | j                  d| |      S )Nrshiftr<   rH   s     r   
__rshift__z_Operand.__rshift__   r   r   c                (    | j                  d| |      S )Neqr<   rH   s     r   __eq__z_Operand.__eq__   rz   r   c                (    | j                  d| |      S )Nner<   rH   s     r   __ne__z_Operand.__ne__   rz   r   c                (    | j                  d| |      S )Nltr<   rH   s     r   __lt__z_Operand.__lt__   rz   r   c                (    | j                  d| |      S )Nler<   rH   s     r   __le__z_Operand.__le__   rz   r   c                (    | j                  d| |      S )Ngtr<   rH   s     r   __gt__z_Operand.__gt__   rz   r   c                (    | j                  d| |      S )Nger<   rH   s     r   __ge__z_Operand.__ge__   rz   r   )r   Image.Image)r    _Operand | floatreturnr   )NN)
r/   strr    r   r0   _Operand | float | Noner   z
str | Noner   r   )r   bool)r   r   )rI   r   r   r   )&__name__
__module____qualname____doc__r   r&   r5   r9   r=   rA   rD   rJ   rM   rR   rT   rX   rZ   r^   r`   rd   rf   rj   rl   ro   rs   ru   ry   r|   r   r   r   r   r   r   r   r   r   r   r@   r   r   r   r      s    >9, (,++ + %	+
 + 
+\-''............*..--..11------r   r   c                J    t        | j                  j                  d            S )Nr   r   r   r   r8   s    r   imagemath_intr          DGGOOC())r   c                J    t        | j                  j                  d            S )Nr   r   r8   s    r   imagemath_floatr      r   r   c                ,    | j                  d| |d      S )Nr   r   r   r<   rH   s     r   imagemath_equalr          ::dD%c:22r   c                ,    | j                  d| |d      S )Nr   r   r   r<   rH   s     r   imagemath_notequalr      r   r   c                (    | j                  d| |      S )Nr,   r<   rH   s     r   imagemath_minr          ::eT5))r   c                (    | j                  d| |      S )Nmaxr<   rH   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                   t         j                         }|j                  |       |j                         D ].  \  }}t	        |t
        j
                        s!t        |      ||<   0  | |      }	 |j                  S # t        $ r |cY S w xY w)a1  
    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 **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.
    )	opscopyupdateitemsr   r   r   r   r(   )
expressionkwargskvr2   s         r   lambda_evalr      s|     88:DKKO

 "1a%qkDG" T
Cvv 
s   0A< <B
	B
c                   t         j                         |D ]'  }d|v st        t        |      sd| d}t	        |       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 **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.
    __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>.scan+  si    ^^ 	EE{d=11U	 MM 	&D4DEM$}- o%	&r   
__builtinsr;   )r   r   r   None)r   r   hasattrbuiltinsr   r   r   r   r   r   compiler   r;   r   r(   )	r   r   r   r!   r   r2   r   r   r   s	         @@@r   unsafe_evalr     s    & 88:D "19!,aS&CS/!"
 	KKO

 "1a%qkDG" J
F;M& 	
--
\E3<$@$
GCvv 
s   C C-,C-)r   r   r   r   )r   r   rI   r   r   r   )r   r   r   r   r   r   )r   zCallable[[dict[str, Any]], Any]r   r	   r   r	   )r   r   r   r	   r   r	   )
__future__r   r    r   r   TYPE_CHECKINGcollections.abcr   typesr   typingr	   r   r   r   r   r   r   r   r   r   r   r   r@   r   r   <module>r      sy   " #  !(e- e-R**
33**+
 " 8/r   