o
    eU                     @  s   d dl mZ d dlZddlmZmZ G 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i Zee  D ]\ZZedd dkrReeedd < q>i fddZdS )    )annotationsN   )Image_imagingmathc                   @  s"  e Zd ZdZdd Zdd ZdGd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/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dS )H_Operandz4Wraps an image operand, providing standard operatorsc                 C  s
   || _ d S N)im)selfr    r
   @/var/www/html/venv/lib/python3.10/site-packages/PIL/ImageMath.py__init__   s   
z_Operand.__init__c                 C  s   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	d| jj
|S t	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msgr
   r
   r   __fixup   s   
z_Operand.__fixupNc           	   
   C  s  |  |}|d u rKt|p|j|jd }|  ztt|d |j }W n ty; } zd| d}t	||d }~ww t
||jj|jj t|S |  |}|j|jkrj|jdkr`|d}|jdkrj|d}|j|jkrt|jd |jd t|jd |jd f}|j|kr|d| }|j|kr|d| }t|p|j|jd }|  |  ztt|d |j }W n ty } zd| d}t	||d }~ww t||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   r
   r
   r   apply0   sJ   






,


z_Operand.applyc                 C  s   | j  d uS r   )r   getbboxr	   r
   r
   r   __bool__X   s   z_Operand.__bool__c                 C     |  d| S )Nabsr,   r.   r
   r
   r   __abs__\      z_Operand.__abs__c                 C  s   | S r   r
   r.   r
   r
   r   __pos___   s   z_Operand.__pos__c                 C  r0   )Nnegr2   r.   r
   r
   r   __neg__b   r4   z_Operand.__neg__c                 C     |  d| |S Naddr2   r	   otherr
   r
   r   __add__f      z_Operand.__add__c                 C     |  d|| S r9   r2   r;   r
   r
   r   __radd__i   r>   z_Operand.__radd__c                 C  r8   Nsubr2   r;   r
   r
   r   __sub__l   r>   z_Operand.__sub__c                 C  r?   rA   r2   r;   r
   r
   r   __rsub__o   r>   z_Operand.__rsub__c                 C  r8   Nmulr2   r;   r
   r
   r   __mul__r   r>   z_Operand.__mul__c                 C  r?   rE   r2   r;   r
   r
   r   __rmul__u   r>   z_Operand.__rmul__c                 C  r8   Ndivr2   r;   r
   r
   r   __truediv__x   r>   z_Operand.__truediv__c                 C  r?   rI   r2   r;   r
   r
   r   __rtruediv__{   r>   z_Operand.__rtruediv__c                 C  r8   Nmodr2   r;   r
   r
   r   __mod__~   r>   z_Operand.__mod__c                 C  r?   rM   r2   r;   r
   r
   r   __rmod__   r>   z_Operand.__rmod__c                 C  r8   Npowr2   r;   r
   r
   r   __pow__   r>   z_Operand.__pow__c                 C  r?   rQ   r2   r;   r
   r
   r   __rpow__   r>   z_Operand.__rpow__c                 C  r0   )Ninvertr2   r.   r
   r
   r   
__invert__   r4   z_Operand.__invert__c                 C  r8   Nandr2   r;   r
   r
   r   __and__   r>   z_Operand.__and__c                 C  r?   rW   r2   r;   r
   r
   r   __rand__   r>   z_Operand.__rand__c                 C  r8   Norr2   r;   r
   r
   r   __or__   r>   z_Operand.__or__c                 C  r?   r[   r2   r;   r
   r
   r   __ror__   r>   z_Operand.__ror__c                 C  r8   Nxorr2   r;   r
   r
   r   __xor__   r>   z_Operand.__xor__c                 C  r?   r_   r2   r;   r
   r
   r   __rxor__   r>   z_Operand.__rxor__c                 C  r8   )Nlshiftr2   r;   r
   r
   r   
__lshift__   r>   z_Operand.__lshift__c                 C  r8   )Nrshiftr2   r;   r
   r
   r   
__rshift__   r>   z_Operand.__rshift__c                 C  r8   )Neqr2   r;   r
   r
   r   __eq__   r>   z_Operand.__eq__c                 C  r8   )Nner2   r;   r
   r
   r   __ne__   r>   z_Operand.__ne__c                 C  r8   )Nltr2   r;   r
   r
   r   __lt__   r>   z_Operand.__lt__c                 C  r8   )Nler2   r;   r
   r
   r   __le__   r>   z_Operand.__le__c                 C  r8   )Ngtr2   r;   r
   r
   r   __gt__   r>   z_Operand.__gt__c                 C  r8   )Nger2   r;   r
   r
   r   __ge__   r>   z_Operand.__ge__)NN)&__name__
__module____qualname____doc__r   r   r,   r/   r3   r5   r7   r=   r@   rC   rD   rG   rH   rK   rL   rO   rP   rS   rT   rV   rY   rZ   r]   r^   ra   rb   rd   rf   rh   rj   rl   rn   rp   rr   r
   r
   r
   r   r      sH    
(r   c                 C     t | jdS )Nr   r   r   r   r.   r
   r
   r   imagemath_int      ry   c                 C  rw   )Nr   rx   r.   r
   r
   r   imagemath_float   rz   r{   c                 C     | j d| |ddS )Nrg   r   r   r2   r;   r
   r
   r   imagemath_equal      r~   c                 C  r|   )Nri   r   r}   r2   r;   r
   r
   r   imagemath_notequal   r   r   c                 C  r8   )Nr%   r2   r;   r
   r
   r   imagemath_min   r>   r   c                 C  r8   )Nmaxr2   r;   r
   r
   r   imagemath_max   r>   r   c                 C  s   t | j|S r   rx   )r	   r   r
   r
   r   imagemath_convert   rz   r   
   
imagemath_c                   s   t   t| t|  D ]}d|v stt|r%d| d}t|q |  |   D ]\}}t|drCt	| |< q4t
| dd fdd t| d	d
tii }z|jW S  typ   | Y S 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                   sX   | j D ]}t|tu r| q| jD ]}| vr)|dkr)d| d}t|qd S )Nr1   r   r   )	co_conststypeco_namesr   )codeconstnamer   argscompiled_codescanr
   r   r      s   

zeval.<locals>.scan
__builtinsr1   )opscopylistkeyshasattrbuiltinsr   updateitemsr   compiler   r1   r   r!   )
expression_dictkwkr   vr*   r
   r   r   r      s*   



r   )
__future__r   r    r   r   r   ry   r{   r~   r   r   r   r   r   r   globalsr   r   r   r   r
   r
   r
   r   <module>   s$    $