K i(ddlmZddlZddlmZmZdZerddlmZddl m Z ddl m Z Gd d Z dd Zdd Zdd ZddZddZddZddZeeeeeeedZddZddZy)) annotationsN)Image _imagingmathF)Callable)CodeType)Anyc8eZdZdZd%dZd&dZ d' d(dZd)dZd*dZd*dZ d*d Z d+d Z d+d Z d+d Z d+d Zd+dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZd*dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZd+dZ d+d Z!d+d!Z"d+d"Z#d+d#Z$d+d$Z%y),_Operandz4Wraps an image operand, providing standard operatorsc||_yN)im)selfrs S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/PIL/ImageMath.py__init__z_Operand.__init__!s c t|tr{|jjdvr|jj dS|jjdvr |jSd|jj}t |t|t tfrC|jjdvr+tjd|jj|Stjd|jj|S)N)1LI)rFzunsupported mode: )rrrr) isinstancer rmodeconvert ValueErrorintfloatrnewsize)rim1msgs r__fixupz_Operand.__fixup$s c8 $vv{{j(vv~~c** *vv *366;;-8 o%#U|,1PyydggllC88yydggllC88rNc0|j|}|tj|xs |j|jd} t t |d|j}t j||j|jt|S|j|} |j| jk7r@|jdk7r|jd}| jdk7r| jd} |j| jk7rt|jd| jdt|jd| jdf} |j| k7r|jd| z}| j| k7r| jd| z} tj|xs |j|jd} t t |d|j}t j||j|j| jt|S#t$r}d|d}t||d}~wwxYw#t$r}d|d}t||d}~wwxYw)N_zbad operand type for ''rrr)rr)_Operand__fixuprrrrgetattrrAttributeError TypeErrorunopgetimrmincropbinopr ) ropr im2rim_1outer!im_2rs rapplyz_Operand.apply6s)||C  ;))D-DIItyy$?C ,\bT499++>?   b#))+tzz| <6}1<<$DyyDII%99#<<,D99#<<,DyyDII% ! diil3 ! diil399$99Vd]3D99$99Vd]3D))D-DIItyy$?C ,\bT499++>?   r399; djjl K}=" ,.rd!4n!+ ,4" ,.rd!4n!+ ,s0I&I5 I2I--I25 J>JJc:|jjduSr )rgetbboxrs r__bool__z_Operand.__bool__dsww ,,rc&|jd|S)Nabsr5r8s r__abs__z_Operand.__abs__hzz%&&rc|Sr r8s r__pos__z_Operand.__pos__ks rc&|jd|S)Nnegr<r8s r__neg__z_Operand.__neg__nr>rc(|jd||SNaddr<rothers r__add__z_Operand.__add__rzz%u--rc(|jd||SrFr<rHs r__radd__z_Operand.__radd__uzz%--rc(|jd||SNsubr<rHs r__sub__z_Operand.__sub__xrKrc(|jd||SrPr<rHs r__rsub__z_Operand.__rsub__{rNrc(|jd||SNmulr<rHs r__mul__z_Operand.__mul__~rKrc(|jd||SrVr<rHs r__rmul__z_Operand.__rmul__rNrc(|jd||SNdivr<rHs r __truediv__z_Operand.__truediv__rKrc(|jd||Sr\r<rHs r __rtruediv__z_Operand.__rtruediv__rNrc(|jd||SNmodr<rHs r__mod__z_Operand.__mod__rKrc(|jd||Srbr<rHs r__rmod__z_Operand.__rmod__rNrc(|jd||SNpowr<rHs r__pow__z_Operand.__pow__rKrc(|jd||Srhr<rHs r__rpow__z_Operand.__rpow__rNrc&|jd|S)Ninvertr<r8s r __invert__z_Operand.__invert__szz(D))rc(|jd||SNandr<rHs r__and__z_Operand.__and__rKrc(|jd||Srqr<rHs r__rand__z_Operand.__rand__rNrc(|jd||SNorr<rHs r__or__z_Operand.__or__zz$e,,rc(|jd||Srwr<rHs r__ror__z_Operand.__ror__szz$t,,rc(|jd||SNxorr<rHs r__xor__z_Operand.__xor__rKrc(|jd||Sr~r<rHs r__rxor__z_Operand.__rxor__rNrc(|jd||S)Nlshiftr<rHs r __lshift__z_Operand.__lshift__zz(D%00rc(|jd||S)Nrshiftr<rHs r __rshift__z_Operand.__rshift__rrc(|jd||S)Neqr<rHs r__eq__z_Operand.__eq__rzrc(|jd||S)Nner<rHs r__ne__z_Operand.__ne__rzrc(|jd||S)Nltr<rHs r__lt__z_Operand.__lt__rzrc(|jd||S)Nler<rHs r__le__z_Operand.__le__rzrc(|jd||S)Ngtr<rHs r__gt__z_Operand.__gt__rzrc(|jd||S)Nger<rHs r__ge__z_Operand.__ge__rzr)r Image.Image)r _Operand | floatreturnr)NN) r/strr rr0_Operand | float | Nonerz str | Nonerr )rbool)rr )rIrrr )&__name__ __module__ __qualname____doc__rr&r5r9r=rArDrJrMrRrTrXrZr^r`rdrfrjrlrorsruryr|rrrrrrrrrrr@rrr r s>9,(, + ++% +  +  +\-''............*..--..11------rr cJt|jjdS)Nrr rrr8s r imagemath_intr DGGOOC( ))rcJt|jjdS)Nrrr8s rimagemath_floatrrrc,|jd||dS)Nrrrr<rHs rimagemath_equalr ::dD%c: 22rc,|jd||dS)Nrrrr<rHs rimagemath_notequalrrrc(|jd||S)Nr,r<rHs r imagemath_minr ::eT5 ))rc(|jd||S)Nmaxr<rHs r imagemath_maxrrrcJt|jj|Sr r)rrs rimagemath_convertrs DGGOOD) **r)rrequalnotequalr,rrc tj}|j||jD].\}}t |t j s!t |||<0||} |jS#t$r|cYSwxYw)a1 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 **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. ) opscopyupdateitemsrrr rr() expressionkwargskvr2s r lambda_evalrs|88:DKKO "1 a %qkDG" T Cvv  s0 A<< B  B c tj|D]'}d|vstt|sd|d}t |j |j D].\}}t|tjs!t||<0t|ddd fd tj|ddtii} |jS#t$r|cYSwxYw) 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 **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. __r% ' not allowedzevalc|jD]!}t|tus|#|jD]}|vs|dk7sd|d}t|y)Nr;r%r) co_conststypeco_namesr)codeconstnamer!r compiled_codescans rrzunsafe_eval..scan+si^^ EE{d=11U  MM &D4DEM$}- o% &r __builtinsr;)rrrNone)rrhasattrbuiltinsrrrrrr compilerr;rr() rrrr!rr2rrrs @@@r unsafe_evalr s&88:D " 19!,aS &CS/ !"  KKO "1 a %qkDG"J F;M&  -- \E3<$@$ GCvv  s C C-,C-)rr rr )rr rIrrr )rr rrrr )rzCallable[[dict[str, Any]], Any]rr rr )rrrr rr ) __future__rrrr TYPE_CHECKINGcollections.abcrtypesrtypingr r rrrrrrrrrrr@rrrsy"#! (e-e-R** 33**+   "   8/r