o
    üÞh�.  ã                   @  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                   @  sj  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dZdHdI„Z dZdJdK„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   úM/var/www/html/premium_crap/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 rHt |p|j|jd ¡}ztt|› d|j› �ƒ}W n ty8 } zd|› d�}t|ƒ|‚d }~ww t 	|| 
¡ | 
¡ ¡ t|ƒS |   |¡}	|j|	jkrg|jdkr]| d¡}|	jdkrg|	 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 || 
¡ | 
¡ |	 
¡ ¡ t|ƒS )NÚ_zbad operand type for 'ú'r   r   r   )r   r   )Ú_Operand__fixupr   r   r   r    Úgetattrr   ÚAttributeErrorÚ	TypeErrorÚunopÚgetimr   ÚminÚcropÚbinopr
   )r   r#   r   r%   r   Úim_1ÚoutÚer!   Úim_2r    r   r   r   Úapply3   sH   

€þ
è



þ


€þz_Operand.applyÚboolc                 C  s   | j  ¡ d uS r   )r   Úgetbbox©r   r   r   r   Ú__bool__a   s   z_Operand.__bool__c                 C  ó   |   d| ¡S )NÚabs©r7   r:   r   r   r   Ú__abs__e   ó   z_Operand.__abs__c                 C  s   | S r   r   r:   r   r   r   Ú__pos__h   s   z_Operand.__pos__c                 C  r<   )NÚnegr>   r:   r   r   r   Ú__neg__k   r@   z_Operand.__neg__Úotherc                 C  ó   |   d| |¡S ©NÚaddr>   ©r   rD   r   r   r   Ú__add__o   ó   z_Operand.__add__c                 C  ó   |   d|| ¡S rF   r>   rH   r   r   r   Ú__radd__r   rJ   z_Operand.__radd__c                 C  rE   ©NÚsubr>   rH   r   r   r   Ú__sub__u   rJ   z_Operand.__sub__c                 C  rK   rM   r>   rH   r   r   r   Ú__rsub__x   rJ   z_Operand.__rsub__c                 C  rE   ©NÚmulr>   rH   r   r   r   Ú__mul__{   rJ   z_Operand.__mul__c                 C  rK   rQ   r>   rH   r   r   r   Ú__rmul__~   rJ   z_Operand.__rmul__c                 C  rE   ©NÚdivr>   rH   r   r   r   Ú__truediv__�   rJ   z_Operand.__truediv__c                 C  rK   rU   r>   rH   r   r   r   Ú__rtruediv__„   rJ   z_Operand.__rtruediv__c                 C  rE   ©NÚmodr>   rH   r   r   r   Ú__mod__‡   rJ   z_Operand.__mod__c                 C  rK   rY   r>   rH   r   r   r   Ú__rmod__Š   rJ   z_Operand.__rmod__c                 C  rE   ©NÚpowr>   rH   r   r   r   Ú__pow__�   rJ   z_Operand.__pow__c                 C  rK   r]   r>   rH   r   r   r   Ú__rpow__�   rJ   z_Operand.__rpow__c                 C  r<   )NÚinvertr>   r:   r   r   r   Ú
__invert__”   r@   z_Operand.__invert__c                 C  rE   ©NÚandr>   rH   r   r   r   Ú__and__—   rJ   z_Operand.__and__c                 C  rK   rc   r>   rH   r   r   r   Ú__rand__š   rJ   z_Operand.__rand__c                 C  rE   ©NÚorr>   rH   r   r   r   Ú__or__�   rJ   z_Operand.__or__c                 C  rK   rg   r>   rH   r   r   r   Ú__ror__    rJ   z_Operand.__ror__c                 C  rE   ©NÚxorr>   rH   r   r   r   Ú__xor__£   rJ   z_Operand.__xor__c                 C  rK   rk   r>   rH   r   r   r   Ú__rxor__¦   rJ   z_Operand.__rxor__c                 C  rE   )NÚlshiftr>   rH   r   r   r   Ú
__lshift__©   rJ   z_Operand.__lshift__c                 C  rE   )NÚrshiftr>   rH   r   r   r   Ú
__rshift__¬   rJ   z_Operand.__rshift__c                 C  rE   )NÚeqr>   rH   r   r   r   Ú__eq__°   rJ   z_Operand.__eq__c                 C  rE   )NÚner>   rH   r   r   r   Ú__ne__³   rJ   z_Operand.__ne__c                 C  rE   )NÚltr>   rH   r   r   r   Ú__lt__¶   rJ   z_Operand.__lt__c                 C  rE   )NÚler>   rH   r   r   r   Ú__le__¹   rJ   z_Operand.__le__c                 C  rE   )NÚgtr>   rH   r   r   r   Ú__gt__¼   rJ   z_Operand.__gt__c                 C  rE   )NÚger>   rH   r   r   r   Ú__ge__¿   rJ   z_Operand.__ge__)r   r   )r   r   r   r   )NN)
r#   r$   r   r   r%   r&   r   r'   r   r
   )r   r8   )r   r
   )rD   r   r   r
   )&Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r*   r7   r;   r?   rA   rC   rI   rL   rO   rP   rS   rT   rW   rX   r[   r\   r_   r`   rb   re   rf   ri   rj   rm   rn   rp   rr   rt   rv   rx   rz   r|   r~   r   r   r   r   r
      sL    

û
.




























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‡   rD   r&   c                 C  ó   | j d| |dd�S )Nrs   r   ©r   r>   rH   r   r   r   Úimagemath_equalÍ   ó   rŠ   c                 C  rˆ   )Nru   r   r‰   r>   rH   r   r   r   Úimagemath_notequalÑ   r‹   rŒ   c                 C  rE   )Nr0   r>   rH   r   r   r   Úimagemath_minÕ   rJ   r�   c                 C  rE   )NÚmaxr>   rH   r   r   r   Úimagemath_maxÙ   rJ   r�   r   r$   c                 C  s   t | j |¡ƒS r   r„   )r   r   r   r   r   Úimagemath_convertÝ   r†   r�   )r   r   ÚequalÚnotequalr0   rŽ   r   Ú
expressionúCallable[[dict[str, Any]], Any]Úoptionsúdict[str, Any]Úkwr   c                 K  s~   |rt dddƒ t ¡ }| |¡ | |¡ | ¡ D ]\}}t|tjƒr*t|ƒ||< q| |ƒ}z|jW S  t	y>   | 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. Deprecated.
                    You can instead use one or more keyword arguments.
    :param **kw: Values to add to the function's dictionary.
    :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.
    zImageMath.lambda_eval optionsé   z'ImageMath.lambda_eval keyword arguments)
r	   ÚopsÚcopyÚupdateÚitemsr   r   r
   r   r,   )r“   r•   r—   ÚargsÚkÚvr4   r   r   r   Úlambda_evalì   s&   ý

€ÿr    c                   sê   |rt dddƒ t ¡ ‰ g |¢|¢D ]}d|v stt|ƒr'd|› d�}t|ƒ‚qˆ  |¡ ˆ  |¡ ˆ  ¡ D ]\}}t|t	j	ƒrFt
|ƒˆ |< q6t| ddƒ‰d‡ ‡‡fdd„‰ˆˆƒ t | ddtiiˆ ¡}z|jW S  tyt   | 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. Deprecated.
                    You can instead use one or more keyword arguments.
    :param **kw: Values to add to the evaluation context.
    :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.
    zImageMath.unsafe_eval optionsr˜   z'ImageMath.unsafe_eval keyword argumentsÚ__r)   ú' not allowedz<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­   D  s   
€
€ýzunsafe_eval.<locals>.scanÚ
__builtinsr=   N)r¤   r   r   r¥   )r	   r™   rš   ÚhasattrÚbuiltinsr   r›   rœ   r   r   r
   Úcompiler£   r=   r   r,   )r“   r•   r—   rž   r!   rŸ   r4   r   r«   r   Úunsafe_eval  s6   ýþ

€
ÿ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.evalr˜   z.ImageMath.lambda_eval or ImageMath.unsafe_eval)r	   r²   )r“   r³   r—   r   r   r   r£   V  s   ýr£   )r   r
   r   r
   )r   r
   rD   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:    
*





ùþ,þBþ