o �J�h0�@s�ddlmZddlZddlmZddlmZmZddlm Z m Z ddl m Z Gdd �d �Z d,d d �Zd,dd�Zd-dd�Zd-dd�Zd-dd�Zd-dd�Zd.dd�Zeeeeeeed�Zifd/d%d&�Zifd0d'd(�Zifd1d*d+�ZdS)2�)� annotationsN)�CodeType)�Any�Callable�)�Image� _imagingmath)� deprecatec@sjeZdZdZdTdd�ZdUd d �Z dVdWdd�ZdXdd�ZdYdd�ZdYdd�Z dYdd�Z dZdd�Z dZd d!�Z dZd"d#�Z dZd$d%�ZdZd&d'�ZdZd(d)�ZdZd*d+�ZdZd,d-�ZdZd.d/�ZdZd0d1�ZdZd2d3�ZdZd4d5�ZdYd6d7�ZdZd8d9�ZdZd:d;�ZdZd<d=�ZdZd>d?�ZdZd@dA�ZdZdBdC�ZdZdDdE�ZdZdFdG�ZdZdHdI�Z dZdJdK�Z!dZdLdM�Z"dZdNdO�Z#dZdPdQ�Z$dZdRdS�Z%d S)[�_Operandz4Wraps an image operand, providing standard operators�im� Image.ImagecCs ||_dS�N)r )�selfr �r�KC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\PIL\ImageMath.py�__init__s z_Operand.__init__�im1�_Operand | float�returncCs�t|t�r%|jjdvr|j�d�S|jjdvr|jSd|jj��}t|��t|ttf�r;|jjdvr;t� d|jj |�St� d|jj |�S)N)�1�L�I)r�Fzunsupported mode: )rrrr) � isinstancer r �mode�convert� ValueError�int�floatr�new�size)rr�msgrrrZ__fixup!s    z_Operand.__fixupN�op�str�im2�_Operand | float | Noner� str | Nonec Cs�|�|�}|durHt�|p|j|jd�}z tt|�d|j���}Wnty8}z d|�d�}t|�|�d}~wwt� ||� �|� ��t|�S|�|�} |j| jkrg|jdkr]|� d�}| jdkrg| � d�} |j| jkr�t |jd| jd�t |jd| jd�f} |j| kr�|� d| �}| j| kr�| � d| �} t�|p�|j|jd�}z tt|�d|j���}Wnty�}z d|�d�}t|�|�d}~wwt�||� �|� �| � ��t|�S)N�_zbad operand type for '�'rrr)rr)�_Operand__fixuprrrr �getattrr�AttributeError� TypeError�unop�getimr�min�crop�binopr ) rr"rr$rZim_1�out�er!Zim_2r rrr�apply3sH   �� �      �    ��z_Operand.apply�boolcCs|j��duSr )r �getbbox�rrrr�__bool__asz_Operand.__bool__cC� |�d|�S)N�abs�r4r7rrr�__abs__e� z_Operand.__abs__cCs|Sr rr7rrr�__pos__hsz_Operand.__pos__cCr9)N�negr;r7rrr�__neg__kr=z_Operand.__neg__�othercC�|�d||�S�N�addr;�rrArrr�__add__o�z_Operand.__add__cC�|�d||�SrCr;rErrr�__radd__rrGz_Operand.__radd__cCrB�N�subr;rErrr�__sub__urGz_Operand.__sub__cCrHrJr;rErrr�__rsub__xrGz_Operand.__rsub__cCrB�N�mulr;rErrr�__mul__{rGz_Operand.__mul__cCrHrNr;rErrr�__rmul__~rGz_Operand.__rmul__cCrB�N�divr;rErrr� __truediv__�rGz_Operand.__truediv__cCrHrRr;rErrr� __rtruediv__�rGz_Operand.__rtruediv__cCrB�N�modr;rErrr�__mod__�rGz_Operand.__mod__cCrHrVr;rErrr�__rmod__�rGz_Operand.__rmod__cCrB�N�powr;rErrr�__pow__�rGz_Operand.__pow__cCrHrZr;rErrr�__rpow__�rGz_Operand.__rpow__cCr9)N�invertr;r7rrr� __invert__�r=z_Operand.__invert__cCrB�N�andr;rErrr�__and__�rGz_Operand.__and__cCrHr`r;rErrr�__rand__�rGz_Operand.__rand__cCrB�N�orr;rErrr�__or__�rGz_Operand.__or__cCrHrdr;rErrr�__ror__�rGz_Operand.__ror__cCrB�N�xorr;rErrr�__xor__�rGz_Operand.__xor__cCrHrhr;rErrr�__rxor__�rGz_Operand.__rxor__cCrB)N�lshiftr;rErrr� __lshift__�rGz_Operand.__lshift__cCrB)N�rshiftr;rErrr� __rshift__�rGz_Operand.__rshift__cCrB)N�eqr;rErrr�__eq__�rGz_Operand.__eq__cCrB)N�ner;rErrr�__ne__�rGz_Operand.__ne__cCrB)N�ltr;rErrr�__lt__�rGz_Operand.__lt__cCrB)N�ler;rErrr�__le__�rGz_Operand.__le__cCrB)N�gtr;rErrr�__gt__�rGz_Operand.__gt__cCrB)N�ger;rErrr�__ge__�rGz_Operand.__ge__)r r )rrrr )NN) r"r#rrr$r%rr&rr )rr5)rr )rArrr )&�__name__� __module__� __qualname__�__doc__rr)r4r8r<r>r@rFrIrLrMrPrQrTrUrXrYr\r]r_rbrcrfrgrjrkrmrorqrsrurwryr{rrrrr sL   � .                             r rrcC�t|j�d��S)Nr�r r rr7rrr� imagemath_int��r�cCr�)Nrr�r7rrr�imagemath_float�r�r�rAr%cC�|jd||dd�S)Nrpr�rr;rErrr�imagemath_equal��r�cCr�)Nrrrr�r;rErrr�imagemath_notequal�r�r�cCrB)Nr/r;rErrr� imagemath_min�rGr�cCrB)N�maxr;rErrr� imagemath_max�rGr�rr#cCst|j�|��Sr r�)rrrrr�imagemath_convert�r�r�)rr�equalZnotequalr/r�r� expression�Callable[[dict[str, Any]], Any]�options�dict[str, Any]�kwrcKs~|rtddd�t��}|�|�|�|�|��D]\}}t|tj�r*t|�||<q||�}z|jWSt y>|YSw)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. zImageMath.lambda_eval options� z'ImageMath.lambda_eval keyword arguments) r �ops�copy�update�itemsrrr r r+)r�r�r��args�k�vr2rrr� lambda_eval�s&�    � �r�c s�|rtddd�t���t|���t|���D]}d|vs#tt|�r-d|�d�}t|��q��|���|��� �D]\}}t |t j �rLt |��|<q<t |dd��d���fd d� ����t�|ddtii��}z|jWStyz|YSw)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. zImageMath.unsafe_eval optionsr�z'ImageMath.unsafe_eval keyword arguments�__r(� ' not allowedz<string>�eval�coderr�NonecsX|jD]}t|�t��ur�|�q|jD]}|�vr)|dkr)d|�d�}t|��qdS)Nr:r(r�)� co_consts�type�co_namesr)r��const�namer!�r�Z compiled_code�scanrrr�Ds �  ��zunsafe_eval.<locals>.scanZ __builtinsr:N)r�rrr�)r r�r��list�keys�hasattr�builtinsrr�r�rrr �compiler�r:r r+)r�r�r�r�r!r�r2rr�r� unsafe_evals6� �    �   �r��_dictcKstddd�t||fi|��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 zImageMath.evalr�z.ImageMath.lambda_eval or ImageMath.unsafe_eval)r r�)r�r�r�rrrr�Vs �r�)rr rr )rr rAr%rr )rr rr#rr )r�r�r�r�r�rrr)r�r#r�r�r�rrr)r�r#r�r�r�rrr)� __future__rr��typesr�typingrr�rr� _deprecater r r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>s:    *      � �, �B�
Memory