
    RfU                       d dl mZ d dlZddlmZmZ  G d d          Zd Zd Zd	 Z	d
 Z
d Zd Zd Zi Z e e                                                      D ] \  ZZedd         dk    reeedd         <   !i fdZdS )    )annotationsN   )Image_imagingmathc                      e Zd ZdZd Zd Zd%dZd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%dS )&_Operandz4Wraps an image operand, providing standard operatorsc                    || _         d S N)im)selfr   s     ?/var/www/html/env/lib/python3.11/site-packages/PIL/ImageMath.py__init__z_Operand.__init__   s        c                   t          |t                    r[|j        j        dv r|j                            d          S |j        j        dv r|j        S d|j        j         }t          |          t          |t          t          f          r.| 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$$ 	9v{j((v~~c***
**v836;88 oo% #U|,, 91P1PydglC888ydglC888r   Nc                F   |                      |          }|t          j        |p|j        |j        d           }|                                 	 t          t          |dz   |j        z             }n(# t          $ r}d| d}t          |          |d }~ww xY wt          j
        ||j        j        |j        j                   n|                      |          }|j        |j        k    r@|j        dk    r|                    d          }|j        dk    r|                    d          }|j        |j        k    rt          |j        d         |j        d                   t          |j        d         |j        d                   f}|j        |k    r|                    d|z             }|j        |k    r|                    d|z             }t          j        |p|j        |j        d           }|                                 |                                 	 t          t          |dz   |j        z             }n(# t          $ r}d| d}t          |          |d }~ww xY wt          j        ||j        j        |j        j        |j        j                   t#          |          S )N_zbad operand type for ''r   r   r   )r   r   )_Operand__fixupr   r   r   r   loadgetattrr   AttributeError	TypeErrorunopr   idr   mincropbinopr   )	r   opr   im2r   outer   r   s	            r   applyz_Operand.apply0   sj   ll3;)D,CHch==CHHJJJ,\28ch+>??! , , ,4r444nn!+, b#&)SVY7777 ,,s##Cx38##8s??++c**C8s??++c**Cx38##CHQK!55s38A;QR7T7TU8t##((6D=11C8t##((6D=11C)D,CHch==CHHJJJHHJJJ,\28ch+>??! , , ,4r444nn!+, r369cfiCCC}}s0    A0 0
B:BB H7 7
IIIc                8    | j                                         d uS r
   )r   getbboxr   s    r   __bool__z_Operand.__bool__X   s    w  ,,r   c                .    |                      d|           S )Nabsr1   r4   s    r   __abs__z_Operand.__abs__\       zz%&&&r   c                    | S r
    r4   s    r   __pos__z_Operand.__pos___   s    r   c                .    |                      d|           S )Nnegr8   r4   s    r   __neg__z_Operand.__neg__b   r:   r   c                0    |                      d| |          S Naddr8   r   others     r   __add__z_Operand.__add__f       zz%u---r   c                0    |                      d||           S rB   r8   rD   s     r   __radd__z_Operand.__radd__i       zz%---r   c                0    |                      d| |          S Nsubr8   rD   s     r   __sub__z_Operand.__sub__l   rG   r   c                0    |                      d||           S rL   r8   rD   s     r   __rsub__z_Operand.__rsub__o   rJ   r   c                0    |                      d| |          S Nmulr8   rD   s     r   __mul__z_Operand.__mul__r   rG   r   c                0    |                      d||           S rR   r8   rD   s     r   __rmul__z_Operand.__rmul__u   rJ   r   c                0    |                      d| |          S Ndivr8   rD   s     r   __truediv__z_Operand.__truediv__x   rG   r   c                0    |                      d||           S rX   r8   rD   s     r   __rtruediv__z_Operand.__rtruediv__{   rJ   r   c                0    |                      d| |          S Nmodr8   rD   s     r   __mod__z_Operand.__mod__~   rG   r   c                0    |                      d||           S r^   r8   rD   s     r   __rmod__z_Operand.__rmod__   rJ   r   c                0    |                      d| |          S Npowr8   rD   s     r   __pow__z_Operand.__pow__   rG   r   c                0    |                      d||           S rd   r8   rD   s     r   __rpow__z_Operand.__rpow__   rJ   r   c                .    |                      d|           S )Ninvertr8   r4   s    r   
__invert__z_Operand.__invert__   s    zz(D)))r   c                0    |                      d| |          S Nandr8   rD   s     r   __and__z_Operand.__and__   rG   r   c                0    |                      d||           S rm   r8   rD   s     r   __rand__z_Operand.__rand__   rJ   r   c                0    |                      d| |          S Norr8   rD   s     r   __or__z_Operand.__or__       zz$e,,,r   c                0    |                      d||           S rs   r8   rD   s     r   __ror__z_Operand.__ror__   s    zz$t,,,r   c                0    |                      d| |          S Nxorr8   rD   s     r   __xor__z_Operand.__xor__   rG   r   c                0    |                      d||           S rz   r8   rD   s     r   __rxor__z_Operand.__rxor__   rJ   r   c                0    |                      d| |          S )Nlshiftr8   rD   s     r   
__lshift__z_Operand.__lshift__       zz(D%000r   c                0    |                      d| |          S )Nrshiftr8   rD   s     r   
__rshift__z_Operand.__rshift__   r   r   c                0    |                      d| |          S )Neqr8   rD   s     r   __eq__z_Operand.__eq__   rv   r   c                0    |                      d| |          S )Nner8   rD   s     r   __ne__z_Operand.__ne__   rv   r   c                0    |                      d| |          S )Nltr8   rD   s     r   __lt__z_Operand.__lt__   rv   r   c                0    |                      d| |          S )Nler8   rD   s     r   __le__z_Operand.__le__   rv   r   c                0    |                      d| |          S )Ngtr8   rD   s     r   __gt__z_Operand.__gt__   rv   r   c                0    |                      d| |          S )Nger8   rD   s     r   __ge__z_Operand.__ge__   rv   r   )NN)&__name__
__module____qualname____doc__r   r#   r1   r5   r9   r=   r@   rF   rI   rN   rP   rT   rV   rZ   r\   r`   rb   rf   rh   rk   ro   rq   ru   rx   r|   r~   r   r   r   r   r   r   r   r   r<   r   r   r   r      s       >>  9 9 9$% % % %P- - -' ' '  ' ' '. . .. . .. . .. . .. . .. . .. . .. . .. . .. . .. . .. . .* * *. . .. . .- - -- - -. . .. . .1 1 11 1 1- - -- - -- - -- - -- - -- - - - -r   r   c                P    t          | j                            d                    S )Nr   r   r   r   r4   s    r   imagemath_intr          DGOOC(()))r   c                P    t          | j                            d                    S )Nr   r   r4   s    r   imagemath_floatr      r   r   c                4    |                      d| |d          S )Nr   r   r   r8   rD   s     r   imagemath_equalr          ::dD%c:222r   c                4    |                      d| |d          S )Nr   r   r   r8   rD   s     r   imagemath_notequalr      r   r   c                0    |                      d| |          S )Nr*   r8   rD   s     r   imagemath_minr          ::eT5)))r   c                0    |                      d| |          S )Nmaxr8   rD   s     r   imagemath_maxr      r   r   c                P    t          | j                            |                    S r
   r   )r   r   s     r   imagemath_convertr      s    DGOOD))***r   
   
imagemath_c                  	 t                                           t          |                                          t          |                                          z   D ]0}d|v st	          t
          |          rd| d}t          |          1                    |                               |                                           D ]'\  }}t	          |d          rt          |          |<   (t          | 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.

    :param expression: A string containing a Python-style expression.
    :param options: 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.
    __r"   ' not allowedr   z<string>evalc                    | j         D ]+}t          |          t                    u r |           ,| j        D ]!}|vr|dk    rd| d}t          |          "d S )Nr7   r"   r   )	co_conststypeco_namesr   )codeconstnamer   argscompiled_codescans       r   r   zeval.<locals>.scan   s    ^ 	 	EE{{d=1111UM 	& 	&D4DEMM-$--- oo%	& 	&r   
__builtinsr7   )opscopylistkeyshasattrbuiltinsr   updateitemsr   compiler   r7   r   r&   )

expression_dictkwkr   vr/   r   r   r   s
          @@@r   r   r      sp    88::D%**,,$rwwyy//1 " "199!,,9&a&&&CS//!  	KKKKOOO

 " "11d 	"qkkDGJ
F;;M& & & & & & & 	D
-
\E3<$@$
G
GCv   


s   :E EE)
__future__r   r    r   r   r   r   r   r   r   r   r   r   r   r   globalsr   r   r   r   r<   r   r   <module>r      sP  " # " " " " "  ! ! ! ! ! ! ! !_- _- _- _- _- _- _- _-F* * ** * *
3 3 33 3 3* * ** * *+ + + 	D""##  DAq"vAbccF  + + + + + +r   