a
    ֶa^                     @   s   d dl Z ddlmZmZ d Zdd 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r|eeedd < q|i fddZdS )    N   )Image_imagingmathc                 C   s   t | ttfS N)
isinstanceintfloat)v r
   ]/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/PIL/ImageMath.py_isconstant   s    r   c                   @   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 r   )im)selfr   r
   r
   r   __init__    s    z_Operand.__init__c                 C   s   t |trH|jjdv r"|jdS |jjdv r4|jS td|jj n8t|rn| jjdv rntd| jj	|S td| jj	|S d S )N)1LI)r   Fzunsupported mode: )r   r   r   r   )
r   r   r   modeconvert
ValueErrorr   r   newsize)r   im1r
   r
   r   Z__fixup#   s    
z_Operand.__fixupNc              
   C   s  |  |}|d u rt|p|j|jd }|  ztt|d |j }W n6 ty~ } zt	d| d|W Y d }~n
d }~0 0 t
||jj|jj nn|  |}|j|jkr|jdkr|d}|jdkr|d}|j|jkrtd|j|jkrrt|jd |jd t|jd |jd f}|j|kr@|d| }|j|krZ|d| }t|ph|j|d }nt|p|j|jd }|  |  ztt|d |j }W n8 ty } zt	d| d|W Y d }~n
d }~0 0 t||jj|jj|jj t|S )	N_zbad operand type for ''r   zmode mismatchr   r   )r   r   )_Operand__fixupr   r   r   r   loadgetattrr   AttributeError	TypeErrorunopr   idr   r   minZcropbinopr   )r   opr   Zim2r   outer   r
   r
   r   apply4   sB    
(




,(z_Operand.applyc                 C   s   | j  d uS r   )r   Zgetbboxr   r
   r
   r   __bool__^   s    z_Operand.__bool__c                 C   s   |  d| S )Nabsr)   r*   r
   r
   r   __abs__b   s    z_Operand.__abs__c                 C   s   | S r   r
   r*   r
   r
   r   __pos__e   s    z_Operand.__pos__c                 C   s   |  d| S )Nnegr-   r*   r
   r
   r   __neg__h   s    z_Operand.__neg__c                 C   s   |  d| |S Naddr-   r   otherr
   r
   r   __add__l   s    z_Operand.__add__c                 C   s   |  d|| S r2   r-   r4   r
   r
   r   __radd__o   s    z_Operand.__radd__c                 C   s   |  d| |S Nsubr-   r4   r
   r
   r   __sub__r   s    z_Operand.__sub__c                 C   s   |  d|| S r8   r-   r4   r
   r
   r   __rsub__u   s    z_Operand.__rsub__c                 C   s   |  d| |S Nmulr-   r4   r
   r
   r   __mul__x   s    z_Operand.__mul__c                 C   s   |  d|| S r<   r-   r4   r
   r
   r   __rmul__{   s    z_Operand.__rmul__c                 C   s   |  d| |S Ndivr-   r4   r
   r
   r   __truediv__~   s    z_Operand.__truediv__c                 C   s   |  d|| S r@   r-   r4   r
   r
   r   __rtruediv__   s    z_Operand.__rtruediv__c                 C   s   |  d| |S Nmodr-   r4   r
   r
   r   __mod__   s    z_Operand.__mod__c                 C   s   |  d|| S rD   r-   r4   r
   r
   r   __rmod__   s    z_Operand.__rmod__c                 C   s   |  d| |S Npowr-   r4   r
   r
   r   __pow__   s    z_Operand.__pow__c                 C   s   |  d|| S rH   r-   r4   r
   r
   r   __rpow__   s    z_Operand.__rpow__c                 C   s   |  d| S )Ninvertr-   r*   r
   r
   r   
__invert__   s    z_Operand.__invert__c                 C   s   |  d| |S Nandr-   r4   r
   r
   r   __and__   s    z_Operand.__and__c                 C   s   |  d|| S rN   r-   r4   r
   r
   r   __rand__   s    z_Operand.__rand__c                 C   s   |  d| |S Norr-   r4   r
   r
   r   __or__   s    z_Operand.__or__c                 C   s   |  d|| S rR   r-   r4   r
   r
   r   __ror__   s    z_Operand.__ror__c                 C   s   |  d| |S Nxorr-   r4   r
   r
   r   __xor__   s    z_Operand.__xor__c                 C   s   |  d|| S rV   r-   r4   r
   r
   r   __rxor__   s    z_Operand.__rxor__c                 C   s   |  d| |S )Nlshiftr-   r4   r
   r
   r   
__lshift__   s    z_Operand.__lshift__c                 C   s   |  d| |S )Nrshiftr-   r4   r
   r
   r   
__rshift__   s    z_Operand.__rshift__c                 C   s   |  d| |S )Neqr-   r4   r
   r
   r   __eq__   s    z_Operand.__eq__c                 C   s   |  d| |S )Nner-   r4   r
   r
   r   __ne__   s    z_Operand.__ne__c                 C   s   |  d| |S )Nltr-   r4   r
   r
   r   __lt__   s    z_Operand.__lt__c                 C   s   |  d| |S )Nler-   r4   r
   r
   r   __le__   s    z_Operand.__le__c                 C   s   |  d| |S )Ngtr-   r4   r
   r
   r   __gt__   s    z_Operand.__gt__c                 C   s   |  d| |S )Nger-   r4   r
   r
   r   __ge__   s    z_Operand.__ge__)NN)&__name__
__module____qualname____doc__r   r   r)   r+   r.   r/   r1   r6   r7   r:   r;   r>   r?   rB   rC   rF   rG   rJ   rK   rM   rP   rQ   rT   rU   rX   rY   r[   r]   r_   ra   rc   re   rg   ri   r
   r
   r
   r   r      sF   
*r   c                 C   s   t | jdS )Nr   r   r   r   r*   r
   r
   r   imagemath_int   s    ro   c                 C   s   t | jdS )Nr   rn   r*   r
   r
   r   imagemath_float   s    rp   c                 C   s   | j d| |ddS )Nr^   r   r   r-   r4   r
   r
   r   imagemath_equal   s    rr   c                 C   s   | j d| |ddS )Nr`   r   rq   r-   r4   r
   r
   r   imagemath_notequal   s    rs   c                 C   s   |  d| |S )Nr$   r-   r4   r
   r
   r   imagemath_min   s    rt   c                 C   s   |  d| |S )Nmaxr-   r4   r
   r
   r   imagemath_max   s    rv   c                 C   s   t | j|S r   rn   )r   r   r
   r
   r   imagemath_convert   s    rw   
   Z
imagemath_c           	      K   s   t  }|| || t| D ]\}}t|dr(t|||< q(t| dd}|jD ]$}||vrZ|dkrZt	d| dqZt
| ddtii|}z|jW S  ty   | Y S 0 dS )	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   z<string>evalr,   r   z' not allowedZ
__builtinsN)opscopyupdatelistitemshasattrr   compileco_namesr   builtinsry   r,   r   r    )	Z
expression_dictkwargskr	   codenamer'   r
   r
   r   ry      s    



ry   )r    r   r   VERBOSEr   r   ro   rp   rr   rs   rt   rv   rw   rz   r}   globalsr~   r   r	   ry   r
   r
   r
   r   <module>   s"    %