o
    ]oiU                     @  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
   U/var/www/html/kuke-dev/django-kuke/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   Z__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   Zim2r   outer   r   r
   r
   r   apply0   sJ   






,


z_Operand.applyc                 C  s   | j  d uS r   )r   Z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  r-   )Nnegr/   r+   r
   r
   r   __neg__b   r1   z_Operand.__neg__c                 C     |  d| |S Naddr/   r	   otherr
   r
   r   __add__f      z_Operand.__add__c                 C     |  d|| S r6   r/   r8   r
   r
   r   __radd__i   r;   z_Operand.__radd__c                 C  r5   Nsubr/   r8   r
   r
   r   __sub__l   r;   z_Operand.__sub__c                 C  r<   r>   r/   r8   r
   r
   r   __rsub__o   r;   z_Operand.__rsub__c                 C  r5   Nmulr/   r8   r
   r
   r   __mul__r   r;   z_Operand.__mul__c                 C  r<   rB   r/   r8   r
   r
   r   __rmul__u   r;   z_Operand.__rmul__c                 C  r5   Ndivr/   r8   r
   r
   r   __truediv__x   r;   z_Operand.__truediv__c                 C  r<   rF   r/   r8   r
   r
   r   __rtruediv__{   r;   z_Operand.__rtruediv__c                 C  r5   Nmodr/   r8   r
   r
   r   __mod__~   r;   z_Operand.__mod__c                 C  r<   rJ   r/   r8   r
   r
   r   __rmod__   r;   z_Operand.__rmod__c                 C  r5   Npowr/   r8   r
   r
   r   __pow__   r;   z_Operand.__pow__c                 C  r<   rN   r/   r8   r
   r
   r   __rpow__   r;   z_Operand.__rpow__c                 C  r-   )Ninvertr/   r+   r
   r
   r   
__invert__   r1   z_Operand.__invert__c                 C  r5   Nandr/   r8   r
   r
   r   __and__   r;   z_Operand.__and__c                 C  r<   rT   r/   r8   r
   r
   r   __rand__   r;   z_Operand.__rand__c                 C  r5   Norr/   r8   r
   r
   r   __or__   r;   z_Operand.__or__c                 C  r<   rX   r/   r8   r
   r
   r   __ror__   r;   z_Operand.__ror__c                 C  r5   Nxorr/   r8   r
   r
   r   __xor__   r;   z_Operand.__xor__c                 C  r<   r\   r/   r8   r
   r
   r   __rxor__   r;   z_Operand.__rxor__c                 C  r5   )Nlshiftr/   r8   r
   r
   r   
__lshift__   r;   z_Operand.__lshift__c                 C  r5   )Nrshiftr/   r8   r
   r
   r   
__rshift__   r;   z_Operand.__rshift__c                 C  r5   )Neqr/   r8   r
   r
   r   __eq__   r;   z_Operand.__eq__c                 C  r5   )Nner/   r8   r
   r
   r   __ne__   r;   z_Operand.__ne__c                 C  r5   )Nltr/   r8   r
   r
   r   __lt__   r;   z_Operand.__lt__c                 C  r5   )Nler/   r8   r
   r
   r   __le__   r;   z_Operand.__le__c                 C  r5   )Ngtr/   r8   r
   r
   r   __gt__   r;   z_Operand.__gt__c                 C  r5   )Nger/   r8   r
   r
   r   __ge__   r;   z_Operand.__ge__)NN)&__name__
__module____qualname____doc__r   r   r*   r,   r0   r2   r4   r:   r=   r@   rA   rD   rE   rH   rI   rL   rM   rP   rQ   rS   rV   rW   rZ   r[   r^   r_   ra   rc   re   rg   ri   rk   rm   ro   r
   r
   r
   r   r      sH    
(r   c                 C     t | jdS )Nr   r   r   r   r+   r
   r
   r   imagemath_int      rv   c                 C  rt   )Nr   ru   r+   r
   r
   r   imagemath_float   rw   rx   c                 C     | j d| |ddS )Nrd   r   r   r/   r8   r
   r
   r   imagemath_equal      r{   c                 C  ry   )Nrf   r   rz   r/   r8   r
   r
   r   imagemath_notequal   r|   r}   c                 C  r5   )Nr$   r/   r8   r
   r
   r   imagemath_min   r;   r~   c                 C  r5   )Nmaxr/   r8   r
   r
   r   imagemath_max   r;   r   c                 C  s   t | j|S r   ru   )r	   r   r
   r
   r   imagemath_convert   rw   r   
   Z
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 )Nr.   r   r   )	co_conststypeco_namesr   )codeconstnamer   argsZcompiled_codescanr
   r   r      s   

zeval.<locals>.scanZ
__builtinsr.   )opscopylistkeyshasattrbuiltinsr   updateitemsr   compiler   r.   r   r    )
expression_dictkwkr   vr(   r
   r   r   r      s*   



r   )
__future__r   r    r   r   r   rv   rx   r{   r}   r~   r   r   r   r   globalsr   r   r   r   r
   r
   r
   r   <module>   s$    $