CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
ImageMath.cpython-310.pyc127 linesDownload Raw Back to __pycache__
1o

2��Yi�)�@s�ddlmZddlZddlmZmZdZer(ddlmZddl	m3Z4ddlmZGd	d5�d6�Z
d(d
d�Zd(dd�Zd)dd�Zd)dd�Zd)dd�Zd)dd�Zd*dd�Zeeeeeeed�Zd+d$d%�Zd,d&d'�ZdS)-�)�annotationsN�)�Image�_imagingmathF)�Callable)�CodeType)�Anyc@sjeZdZdZdTdd�ZdUd	d7�Z		dVdWdd�ZdXdd�ZdYdd�ZdYdd�Z	dYdd�Z8dZdd�ZdZd 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%dS)[�_Operandz4Wraps an image operand, providing standard operators�im�Image.ImagecCs9||_dS�N)r10)�selfr11�r�wE:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\PIL/ImageMath.py�__init__!s12z_Operand.__init__�im1�_Operand | float�returncCs�t|t�r%|jjdvr|j�d�S|jjdvr|jSd|jj��}t|��t|ttf�r;|jjdvr;t�	d|jj13|�St�	d|jj14|�S)N)�1�L�I)r�Fzunsupported mode: )rrrr)�15isinstancer	r16�mode�convert�17ValueError�int�floatr�new�size)r
r�msgrrrZ__fixup$s18z_Operand.__fixupN�op�str�im2�_Operand | float | Noner�19str | Nonec20Cs�|�|�}|durHt�|p|j|jd�}z
tt|�d|j���}Wnty8}zd|�d�}t|�|�d}~wwt�	||�21�|�22��t|�S|�|�}	|j|	jkrg|jdkr]|�d�}|	jdkrg|	�d�}	|j|	jkr�t|jd|	jd�t|jd|	jd�f}23|j|24kr�|�
d|25�}|	j|26kr�|	�
d|27�}	t�|p�|j|jd�}z
tt|�d|j���}Wnty�}zd|�d�}t|�|�d}~wwt�||�28�|�29�|	�30��t|�S)N�_zbad operand type for '�'rrr)rr)�_Operand__fixuprrrr�getattrr�AttributeError�	TypeError�unopZgetimr�min�crop�binopr	)r
r!rr#rZim_1�out�er Zim_2rrrr�apply6sH3132��33�34353637�383940��z_Operand.apply�boolcCs|j��duSr)r41Zgetbbox�r
rrr�__bool__dsz_Operand.__bool__cC�|�d|�S)N�abs�r2r4rrr�__abs__h�z_Operand.__abs__cCs|Srrr4rrr�__pos__ksz_Operand.__pos__cCr6)N�negr8r4rrr�__neg__nr:z_Operand.__neg__�othercC�|�d||�S�N�addr8�r
r>rrr�__add__r�z_Operand.__add__cC�|�d||�Sr@r8rBrrr�__radd__urDz_Operand.__radd__cCr?�N�subr8rBrrr�__sub__xrDz_Operand.__sub__cCrErGr8rBrrr�__rsub__{rDz_Operand.__rsub__cCr?�N�mulr8rBrrr�__mul__~rDz_Operand.__mul__cCrErKr8rBrrr�__rmul__�rDz_Operand.__rmul__cCr?�N�divr8rBrrr�__truediv__�rDz_Operand.__truediv__cCrErOr8rBrrr�__rtruediv__�rDz_Operand.__rtruediv__cCr?�N�modr8rBrrr�__mod__�rDz_Operand.__mod__cCrErSr8rBrrr�__rmod__�rDz_Operand.__rmod__cCr?�N�powr8rBrrr�__pow__�rDz_Operand.__pow__cCrErWr8rBrrr�__rpow__�rDz_Operand.__rpow__cCr6)N�invertr8r4rrr�42__invert__�r:z_Operand.__invert__cCr?�N�andr8rBrrr�__and__�rDz_Operand.__and__cCrEr]r8rBrrr�__rand__�rDz_Operand.__rand__cCr?�N�orr8rBrrr�__or__�rDz_Operand.__or__cCrErar8rBrrr�__ror__�rDz_Operand.__ror__cCr?�N�xorr8rBrrr�__xor__�rDz_Operand.__xor__cCrErer8rBrrr�__rxor__�rDz_Operand.__rxor__cCr?)N�lshiftr8rBrrr�43__lshift__�rDz_Operand.__lshift__cCr?)N�rshiftr8rBrrr�44__rshift__�rDz_Operand.__rshift__cCr?)N�eqr8rBrrr�__eq__�rDz_Operand.__eq__cCr?)N�ner8rBrrr�__ne__�rDz_Operand.__ne__cCr?)N�ltr8rBrrr�__lt__�rDz_Operand.__lt__cCr?)N�ler8rBrrr�__le__�rDz_Operand.__le__cCr?)N�gtr8rBrrr�__gt__�rDz_Operand.__gt__cCr?)N�ger8rBrrr�__ge__�rDz_Operand.__ge__)r45r)rrrr)NN)46r!r"rrr#r$rr%rr	)rr3)rr	)r>rrr	)&�__name__�47__module__�__qualname__�__doc__rr(r2r5r9r;r=rCrFrIrJrMrNrQrRrUrVrYrZr\r_r`rcrdrgrhrjrlrnrprrrtrvrxrrrrr	sL4849�50.5152535455565758596061626364656667686970717273747576777879r	r
rcC�t|j�d��S)Nr�r	r80rr4rrr�
imagemath_int��rcCr})Nrr~r4rrr�imagemath_float�r�r�r>r$cC�|jd||dd�S)Nrmr�rr8rBrrr�imagemath_equal��r�cCr�)Nrorr�r8rBrrr�imagemath_notequal�r�r�cCr?)Nr-r8rBrrr�
imagemath_min�rDr�cCr?)N�maxr8rBrrr�
imagemath_max�rDr�rr"cCst|j�|��Srr~)r
rrrr�imagemath_convert�r�r�)rr�equalZnotequalr-r�r�81expression�Callable[[dict[str, Any]], Any]�kwrcKsdt��}|�|�|��D]\}}t|tj�rt|�||<q
||�}z|jWSty1|YSw)a182    Returns the result of an image function.83 84    :py:mod:`~PIL.ImageMath` only supports single-layer images. To process multi-band85    images, use the :py:meth:`~PIL.Image.Image.split` method or86    :py:func:`~PIL.Image.merge` function.87 88    :param expression: A function that receives a dictionary.89    :param **kw: Values to add to the function's dictionary.90    :return: The expression result. This is usually an image object, but can91             also be an integer, a floating point value, or a pixel tuple,92             depending on the expression.93    )	�ops�copy�update�itemsrrr	r94r*)r�r��args�k�vr0rrr�lambda_eval�s95��r�cs�t���|D]}d|vstt|�rd|�d�}t|��q��|����D]\}}t|tj�r5t	|��|<q%t96|dd��d���fd97d�����t�|dd
tii��}z|j
WStyc|YSw)a-98    Evaluates an image expression. This uses Python's ``eval()`` function to process99    the expression string, and carries the security risks of doing so. It is not100    recommended to process expressions without considering this.101    :py:meth:`~lambda_eval` is a more secure alternative.102 103    :py:mod:`~PIL.ImageMath` only supports single-layer images. To process multi-band104    images, use the :py:meth:`~PIL.Image.Image.split` method or105    :py:func:`~PIL.Image.merge` function.106 107    :param expression: A string containing a Python-style expression.108    :param **kw: Values to add to the evaluation context.109    :return: The evaluated expression. This is usually an image object, but can110             also be an integer, a floating point value, or a pixel tuple,111             depending on the expression.112    �__r'�
' not allowedz<string>�eval�coderr�NonecsX|jD]}t|�t��ur�|�q|jD]}|�vr)|dkr)d|�d�}t|��qdS)Nr7r'r�)�	co_consts�type�co_namesr)r��const�namer �r�Z
compiled_code�scanrrr�+s113�114��zunsafe_eval.<locals>.scanZ115__builtinsr7N)r�rrr�)r�r��hasattr�builtinsrr�r�rrr	�compiler�r7r116r*)r�r�r�r r�r0rr�r�unsafe_evals(�117�118�r�)r
r	rr	)r
r	r>r$rr	)r
r	rr"rr	)r�r�r�rrr)r�r"r�rrr)�119__future__rr��rr�
TYPE_CHECKING�collections.abcr�typesr�typingrr	rr�r�r�r�r�r�r�r�r�rrrr�<module>s6120*121122123124125126�127
Aluode/PerceptionLabPortable · CoolFace