
    h.                       S SK Jr  S SKrS SKJr  S SKJrJr  SSKJ	r	J
r
  SSKJr   " S S	5      rSS
 jrSS jrSS jrSS jrSS jrSS jrSS jr\\\\\\\S.r0 4       SS jjr0 4       SS jjr0 4       SS jjrg)    )annotationsN)CodeType)AnyCallable   )Image_imagingmath)	deprecatec                     \ rS rSrSrS'S jrS(S jr  S)         S*S jjrS+S jrS,S jr	S,S	 jr
S,S
 jrS-S jrS-S jrS-S jrS-S jrS-S jrS-S jrS-S jrS-S jrS-S jrS-S jrS-S jrS-S jrS,S jrS-S jrS-S jrS-S jrS-S jrS-S jrS-S jrS-S jrS-S jr S-S  jr!S-S! jr"S-S" jr#S-S# jr$S-S$ jr%S-S% jr&S&r'g)._Operand   z4Wraps an image operand, providing standard operatorsc                    Xl         g Nim)selfr   s     ?/var/www/html/env/lib/python3.13/site-packages/PIL/ImageMath.py__init___Operand.__init__   s        c                D   [        U[        5      (       a  UR                  R                  S;   a  UR                  R	                  S5      $ UR                  R                  S;   a  UR                  $ SUR                  R                   3n[        U5      e[        U[        [        45      (       aF  U R                  R                  S;   a,  [        R                  " SU R                  R                  U5      $ [        R                  " SU R                  R                  U5      $ )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   __fixup_Operand.__fixup!   s    c8$$vv{{j(vv~~c**
*vv*366;;-8 o% #U|,,1PyydggllC88yydggllC88r   Nc                H   U R                  U5      nUc  [        R                  " U=(       d    UR                  UR                  S 5      n [        [        U SUR                   35      n[        R                  " XR                  5       UR                  5       5        GOU R                  U5      n	UR                  U	R                  :w  aB  UR                  S:w  a  UR                  S5      nU	R                  S:w  a  U	R                  S5      n	UR                  U	R                  :w  a  [        UR                  S   U	R                  S   5      [        UR                  S   U	R                  S   5      4n
UR                  U
:w  a  UR                  SU
-   5      nU	R                  U
:w  a  U	R                  SU
-   5      n	[        R                  " U=(       d    UR                  UR                  S 5      n [        [        U SUR                   35      n[        R                  " XR                  5       UR                  5       U	R                  5       5        [        U5      $ ! [         a  nSU S3n[        U5      UeS nAff = f! [         a  nSU S3n[        U5      UeS nAff = f)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   apply_Operand.apply3   s    ||C ;))D-DIItyy$?C,\bT499++>? b))+tzz|< <<$DyyDII%99#<<,D99#<<,DyyDII% 		!diil3		!diil3 99$99Vd]3D99$99Vd]3D))D-DIItyy$?C,\bT499++>? r99;

djjlK}= " ,.rd!4n!+,4 " ,.rd!4n!+,s0   I 0J  
I=&I88I= 
J!
JJ!c                :    U R                   R                  5       S L$ r   )r   getbboxr   s    r   __bool___Operand.__bool__a   s    ww ,,r   c                &    U R                  SU 5      $ )Nabsr:   r>   s    r   __abs___Operand.__abs__e       zz%&&r   c                    U $ r    r>   s    r   __pos___Operand.__pos__h   s    r   c                &    U R                  SU 5      $ )NnegrC   r>   s    r   __neg___Operand.__neg__k   rF   r   c                &    U R                  SX5      $ NaddrC   r   others     r   __add___Operand.__add__o       zz%--r   c                &    U R                  SX5      $ rP   rC   rR   s     r   __radd___Operand.__radd__r       zz%--r   c                &    U R                  SX5      $ NsubrC   rR   s     r   __sub___Operand.__sub__u   rV   r   c                &    U R                  SX5      $ r\   rC   rR   s     r   __rsub___Operand.__rsub__x   rZ   r   c                &    U R                  SX5      $ NmulrC   rR   s     r   __mul___Operand.__mul__{   rV   r   c                &    U R                  SX5      $ rd   rC   rR   s     r   __rmul___Operand.__rmul__~   rZ   r   c                &    U R                  SX5      $ NdivrC   rR   s     r   __truediv___Operand.__truediv__   rV   r   c                &    U R                  SX5      $ rl   rC   rR   s     r   __rtruediv___Operand.__rtruediv__   rZ   r   c                &    U R                  SX5      $ NmodrC   rR   s     r   __mod___Operand.__mod__   rV   r   c                &    U R                  SX5      $ rt   rC   rR   s     r   __rmod___Operand.__rmod__   rZ   r   c                &    U R                  SX5      $ NpowrC   rR   s     r   __pow___Operand.__pow__   rV   r   c                &    U R                  SX5      $ r|   rC   rR   s     r   __rpow___Operand.__rpow__   rZ   r   c                &    U R                  SU 5      $ )NinvertrC   r>   s    r   
__invert___Operand.__invert__   s    zz(D))r   c                &    U R                  SX5      $ NandrC   rR   s     r   __and___Operand.__and__   rV   r   c                &    U R                  SX5      $ r   rC   rR   s     r   __rand___Operand.__rand__   rZ   r   c                &    U R                  SX5      $ NorrC   rR   s     r   __or___Operand.__or__       zz$,,r   c                &    U R                  SX5      $ r   rC   rR   s     r   __ror___Operand.__ror__   s    zz$,,r   c                &    U R                  SX5      $ NxorrC   rR   s     r   __xor___Operand.__xor__   rV   r   c                &    U R                  SX5      $ r   rC   rR   s     r   __rxor___Operand.__rxor__   rZ   r   c                &    U R                  SX5      $ )NlshiftrC   rR   s     r   
__lshift___Operand.__lshift__       zz(D00r   c                &    U R                  SX5      $ )NrshiftrC   rR   s     r   
__rshift___Operand.__rshift__   r   r   c                &    U R                  SX5      $ )NeqrC   rR   s     r   __eq___Operand.__eq__   r   r   c                &    U R                  SX5      $ )NnerC   rR   s     r   __ne___Operand.__ne__   r   r   c                &    U R                  SX5      $ )NltrC   rR   s     r   __lt___Operand.__lt__   r   r   c                &    U R                  SX5      $ )NlerC   rR   s     r   __le___Operand.__le__   r   r   c                &    U R                  SX5      $ )NgtrC   rR   s     r   __gt___Operand.__gt__   r   r   c                &    U R                  SX5      $ )NgerC   rR   s     r   __ge___Operand.__ge__   r   r   r   )r   Image.Image)r$   _Operand | floatreturnr   )NN)
r4   strr$   r   r5   _Operand | float | Noner   z
str | Noner   r   )r   bool)r   r   )rS   r   r   r   )(__name__
__module____qualname____firstlineno____doc__r   r+   r:   r?   rD   rI   rM   rT   rX   r^   ra   rf   ri   rn   rq   rv   ry   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__rH   r   r   r   r      s    >9, (,++ + %	+
 + 
+\-''............*..--..11------r   r   c                J    [        U R                  R                  S5      5      $ )Nr   r   r   r   r>   s    r   imagemath_intr          DGGOOC())r   c                J    [        U R                  R                  S5      5      $ )Nr   r   r>   s    r   imagemath_floatr      r   r   c                $    U R                  SXSS9$ )Nr   r   r   rC   rR   s     r   imagemath_equalr          ::dDc:22r   c                $    U R                  SXSS9$ )Nr   r   r   rC   rR   s     r   imagemath_notequalr      r   r   c                &    U R                  SX5      $ )Nr1   rC   rR   s     r   imagemath_minr          ::eT))r   c                &    U R                  SX5      $ )NmaxrC   rR   s     r   imagemath_maxr      r   r   c                J    [        U R                  R                  U5      5      $ r   r   )r   r   s     r   imagemath_convertr      s    DGGOOD)**r   )r    r!   equalnotequalr1   r   r   c                r   U(       a  [        SSS5        [        R                  5       nUR                  U5        UR                  U5        UR	                  5        H3  u  pE[        U[        R                  5      (       d  M&  [        U5      X4'   M5     U " U5      n UR                  $ ! [         a    Us $ f = f)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vr7   s          r   lambda_evalr      s    * +5	
 88:DKKKKO

a%%qkDG  T
Cvv 
s   B' 'B65B6c                  ^^^	 U(       a  [        SSS5        [        R                  5       m[        UR	                  5       5      [        UR	                  5       5      -    H/  nSU;   d  [        [        U5      (       d  M   SU S3n[        U5      e   TR                  U5        TR                  U5        TR                  5        H4  u  p5[        U[        R                  5      (       d  M&  [        U5      TU'   M6     [        U SS5      mSUUU	4S	 jjm	T	" T5        [        R                  " U S
S[        00T5      n UR                   $ ! ["         a    Us $ f = f)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                   > U R                    H$  n[        U5      [        T5      L d  M  T" U5        M&     U R                   H"  nUT;  d  M  US:w  d  M  SU S3n[        U5      e   g )NrB   r*   r   )	co_conststypeco_namesr   )codeconstnamer%   r   compiled_codescans       r   r   unsafe_eval.<locals>.scanD  s_    ^^EE{d=11U $ MMD4DEM$}- o% "r   
__builtinsrB   )r   r   r   None)r
   r   r   listkeyshasattrbuiltinsr   r   r   r   r   r   compiler   rB   r   r-   )
r   r   r   r   r%   r   r7   r   r   r   s
          @@@r   unsafe_evalr    s   0 +5	
 88:D',,.!DO319!,,aS&CS/! 4
 	KKKKO

a%%qkDG  J
F;M& & 	
--
\E3<$@$
GCvv 
s   <E EEc                4    [        SSS5        [        X40 UD6$ )a  
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
 z/B//r   )r   r   r   r   )r   r   rS   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   rH   r   r   <module>r     s   " #     ! !e- e-R**
33**+
 "  !'/'' ' 		'X !=== = 		=D 000 0 		0r   