o
    Ñ­jÖ,  ã                   @  sâ   d dl mZ d dlZd dlmZ d dlmZmZ ddlm	Z	m
Z
 ddlmZ G dd	„ d	ƒZd,dd„Zd,dd„Zd-dd„Zd-dd„Zd-dd„Zd-dd„Zd.dd„ZeeeeeeedœZi fd/d%d&„Zi fd0d'd(„Zi fd1d*d+„ZdS )2é    )ÚannotationsN)ÚCodeType)ÚAnyÚCallableé   )ÚImageÚ_imagingmath)Ú	deprecatec                   @  sf  e Zd ZdZdTdd„ZdUd	d
„Z		dVdWdd„ZdXdd„ZdYdd„ZdYdd„Z	dYdd„Z
dZdd„ZdZd d!„ZdZd"d#„ZdZd$d%„ZdZd&d'„ZdZd(d)„ZdZd*d+„ZdZd,d-„ZdZd.d/„ZdZd0d1„ZdZd2d3„ZdZd4d5„ZdYd6d7„ZdZd8d9„ZdZd:d;„ZdZd<d=„ZdZd>d?„ZdZd@dA„ZdZdBdC„ZdZdDdE„ZdZdFdG„ZdHdI„ Z dJdK„ Z!dZdLdM„Z"dZdNdO„Z#dZdPdQ„Z$dZdRdS„Z%dS )[Ú_Operandz4Wraps an image operand, providing standard operatorsÚimúImage.Imagec                 C  s
   || _ d S ©N)r   )Úselfr   © r   úJ/var/www/html/CropPilot/venv/lib/python3.10/site-packages/PIL/ImageMath.pyÚ__init__   s   
z_Operand.__init__Úim1ú_Operand | floatÚreturnc                 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   r   Úmsgr   r   r   Ú__fixup!   s   
z_Operand.__fixupNÚopÚstrÚim2ú_Operand | float | Noner   ú
str | Nonec              
   C  sÒ  |   |¡}|d u rLt |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rk|jdkra| d¡}|	jdkrk|	 d¡}	|j|	jkrŸt|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   r#   r   r%   r   Úim_1ÚoutÚer!   Úim_2r    r   r   r   Úapply3   sN   

€þ
æ



þ


€þz_Operand.applyÚboolc                 C  s   | j  ¡ d uS r   )r   Úgetbbox©r   r   r   r   Ú__bool__d   s   z_Operand.__bool__c                 C  ó   |   d| ¡S )NÚabs©r8   r;   r   r   r   Ú__abs__h   ó   z_Operand.__abs__c                 C  s   | S r   r   r;   r   r   r   Ú__pos__k   s   z_Operand.__pos__c                 C  r=   )NÚnegr?   r;   r   r   r   Ú__neg__n   rA   z_Operand.__neg__Úotherc                 C  ó   |   d| |¡S ©NÚaddr?   ©r   rE   r   r   r   Ú__add__r   ó   z_Operand.__add__c                 C  ó   |   d|| ¡S rG   r?   rI   r   r   r   Ú__radd__u   rK   z_Operand.__radd__c                 C  rF   ©NÚsubr?   rI   r   r   r   Ú__sub__x   rK   z_Operand.__sub__c                 C  rL   rN   r?   rI   r   r   r   Ú__rsub__{   rK   z_Operand.__rsub__c                 C  rF   ©NÚmulr?   rI   r   r   r   Ú__mul__~   rK   z_Operand.__mul__c                 C  rL   rR   r?   rI   r   r   r   Ú__rmul__�   rK   z_Operand.__rmul__c                 C  rF   ©NÚdivr?   rI   r   r   r   Ú__truediv__„   rK   z_Operand.__truediv__c                 C  rL   rV   r?   rI   r   r   r   Ú__rtruediv__‡   rK   z_Operand.__rtruediv__c                 C  rF   ©NÚmodr?   rI   r   r   r   Ú__mod__Š   rK   z_Operand.__mod__c                 C  rL   rZ   r?   rI   r   r   r   Ú__rmod__�   rK   z_Operand.__rmod__c                 C  rF   ©NÚpowr?   rI   r   r   r   Ú__pow__�   rK   z_Operand.__pow__c                 C  rL   r^   r?   rI   r   r   r   Ú__rpow__“   rK   z_Operand.__rpow__c                 C  r=   )NÚinvertr?   r;   r   r   r   Ú
__invert__—   rA   z_Operand.__invert__c                 C  rF   ©NÚandr?   rI   r   r   r   Ú__and__š   rK   z_Operand.__and__c                 C  rL   rd   r?   rI   r   r   r   Ú__rand__�   rK   z_Operand.__rand__c                 C  rF   ©NÚorr?   rI   r   r   r   Ú__or__    rK   z_Operand.__or__c                 C  rL   rh   r?   rI   r   r   r   Ú__ror__£   rK   z_Operand.__ror__c                 C  rF   ©NÚxorr?   rI   r   r   r   Ú__xor__¦   rK   z_Operand.__xor__c                 C  rL   rl   r?   rI   r   r   r   Ú__rxor__©   rK   z_Operand.__rxor__c                 C  rF   )NÚlshiftr?   rI   r   r   r   Ú
__lshift__¬   rK   z_Operand.__lshift__c                 C  rF   )NÚrshiftr?   rI   r   r   r   Ú
__rshift__¯   rK   z_Operand.__rshift__c                 C  rF   )NÚeqr?   rI   r   r   r   Ú__eq__³   rK   z_Operand.__eq__c                 C  rF   )NÚner?   rI   r   r   r   Ú__ne__¶   rK   z_Operand.__ne__c                 C  rF   )NÚltr?   rI   r   r   r   Ú__lt__¹   rK   z_Operand.__lt__c                 C  rF   )NÚler?   rI   r   r   r   Ú__le__¼   rK   z_Operand.__le__c                 C  rF   )NÚgtr?   rI   r   r   r   Ú__gt__¿   rK   z_Operand.__gt__c                 C  rF   )NÚger?   rI   r   r   r   Ú__ge__Â   rK   z_Operand.__ge__)r   r   )r   r   r   r   )NN)
r#   r$   r   r   r%   r&   r   r'   r   r
   )r   r9   )r   r
   )rE   r   r   r
   )&Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r*   r8   r<   r@   rB   rD   rJ   rM   rP   rQ   rT   rU   rX   rY   r\   r]   r`   ra   rc   rf   rg   rj   rk   rn   ro   rq   rs   ru   rw   ry   r{   r}   r   r   r   r   r   r
      sL    

û
1


























r
   r   r   c                 C  ó   t | j d¡ƒS )Nr   ©r
   r   r   r;   r   r   r   Úimagemath_intÇ   ó   r†   c                 C  r„   )Nr   r…   r;   r   r   r   Úimagemath_floatË   r‡   rˆ   rE   r&   c                 C  ó   | j d| |dd�S )Nrt   r   ©r   r?   rI   r   r   r   Úimagemath_equalÐ   ó   r‹   c                 C  r‰   )Nrv   r   rŠ   r?   rI   r   r   r   Úimagemath_notequalÔ   rŒ   r�   c                 C  rF   )Nr1   r?   rI   r   r   r   Úimagemath_minØ   rK   rŽ   c                 C  rF   )NÚmaxr?   rI   r   r   r   Úimagemath_maxÜ   rK   r�   r   r$   c                 C  s   t | j |¡ƒS r   r…   )r   r   r   r   r   Úimagemath_convertà   r‡   r‘   )r   r   ÚequalÚnotequalr1   r�   r   Ú
expressionúCallable[[dict[str, Any]], Any]Úoptionsúdict[str, Any]Úkwr   c                 K  sl   t  ¡ }| |¡ | |¡ | ¡ D ]\}}t|dƒr!t|ƒ||< q| |ƒ}z|jW S  ty5   | Y S w )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. You
                    can either use a dictionary, or one or more keyword
                    arguments.
    :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.
    r   )ÚopsÚcopyÚupdateÚitemsÚhasattrr
   r   r-   )r”   r–   r˜   ÚargsÚkÚvr5   r   r   r   Úlambda_evalï   s   


€ÿr¡   c                   sä   t  ¡ ‰ t| ¡ ƒt| ¡ ƒ D ]}d|v stt|ƒr%d|› d�}t|ƒ‚qˆ  |¡ ˆ  |¡ ˆ  ¡ D ]\}}t|dƒrCt	|ƒˆ |< q4t
| ddƒ‰d‡ ‡‡fdd„‰ˆˆƒ t | ddtiiˆ ¡}z|jW S  tyq   | Y S w )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.  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>ÚevalÚcoder   r   ÚNonec                   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   )r¥   ÚconstÚnamer!   ©rž   Úcompiled_codeÚscanr   r   r®   9  s   
€
€ýzunsafe_eval.<locals>.scanÚ
__builtinsr>   N)r¥   r   r   r¦   )r™   rš   ÚlistÚkeysr�   Úbuiltinsr   r›   rœ   r
   Úcompiler¤   r>   r   r-   )r”   r–   r˜   rŸ   r!   r    r5   r   r¬   r   Úunsafe_eval  s*   þ


€
ÿr´   Ú_dictc                 K  s   t dddƒ t| |fi |¤ŽS )a1  
    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.evalé   z.ImageMath.lambda_eval or ImageMath.unsafe_eval)r	   r´   )r”   rµ   r˜   r   r   r   r¤   K  s   ýr¤   )r   r
   r   r
   )r   r
   rE   r&   r   r
   )r   r
   r   r$   r   r
   )r”   r•   r–   r—   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¤   r   r   r   r   Ú<module>   s:    
-





ùþ%þ;þ