)Ej)ddlmZddlZddlmZmZdZerddlmZddl m Z ddl m Z Gd d Z dd ZddZd dZd dZd dZd dZd!dZeeeeeeedZd"dZd#dZdS)$) annotationsN)Image _imagingmathF)Callable)CodeType)Anyc(eZdZdZd2dZd3dZ d4d5dZd6dZd7dZd7dZ d7dZ d8dZ d8dZ d8dZ d8dZd8dZd8dZd8dZd8dZd8dZd8d Zd8d!Zd8d"Zd7d#Zd8d$Zd8d%Zd8d&Zd8d'Zd8d(Zd8d)Zd8d*Zd8d+Zd8d,Z d8d-Z!d8d.Z"d8d/Z#d8d0Z$d8d1Z%d S)9_Operandz4Wraps an image operand, providing standard operatorsim Image.Imagec||_dSN)r )selfr s ?C:\PYTHON\MyICR_Suite\python\Lib\site-packages\PIL/ImageMath.py__init__z_Operand.__init__!s im1_Operand | floatreturnct|tr[|jjdvr|jdS|jjdvr|jSd|jj}t |t|t tfr.|jjdvr tj d|jj |Stj d|jj |S)N)1LI)rFzunsupported mode: )rrrr) isinstancer r modeconvert ValueErrorintfloatrnewsize)rrmsgs r__fixupz_Operand.__fixup$s c8 $ $ 9v{j((v~~c*** **v 836;88 oo%#U|,, 91P1PydglC888ydglC888rNopstrim2_Operand | float | Noner str | Nonec||}|tj|p|j|jd} t t |d|j}n(#t$r}d|d}t||d}~wwxYwt j || | n||} |j| jkr@|jdkr| d}| jdkr| d} |j| jkrt|jd| jdt|jd| jdf} |j| kr| d| z}| j| kr| d| z} tj|p|j|jd} t t |d|j}n(#t$r}d|d}t||d}~wwxYwt j|| | | t|S)N_zbad operand type for ''rrr)rr)_Operand__fixuprr"rr#getattrrAttributeError TypeErrorunopgetimrmincropbinopr ) rr&rr(rim_1outer$im_2r#s rapplyz_Operand.apply6sm||C   ;)D-DIty$??C ,\b+>+>49+>+>??! , , ,4r444nn!+ ,  b#))++tzz|| < < < <<<$$DyDI%%9##<<,,D9##<<,,DyDI%% ! dil33 ! dil339$$99Vd]33D9$$99Vd]33D)D-DIty$??C ,\b+>+>49+>+>??! , , ,4r444nn!+ ,  r399;; djjll K K K}}s/A B%A;;B)H H.H))H.boolc8|jduSr)r getbboxrs r__bool__z_Operand.__bool__dsw  ,,rc.|d|S)Nabsr;r?s r__abs__z_Operand.__abs__hzz%&&&rc|Srr?s r__pos__z_Operand.__pos__ks rc.|d|S)NnegrCr?s r__neg__z_Operand.__neg__nrErotherc0|d||SNaddrCrrLs r__add__z_Operand.__add__rzz%u---rc0|d||SrNrCrPs r__radd__z_Operand.__radd__uzz%---rc0|d||SNsubrCrPs r__sub__z_Operand.__sub__xrRrc0|d||SrWrCrPs r__rsub__z_Operand.__rsub__{rUrc0|d||SNmulrCrPs r__mul__z_Operand.__mul__~rRrc0|d||Sr]rCrPs r__rmul__z_Operand.__rmul__rUrc0|d||SNdivrCrPs r __truediv__z_Operand.__truediv__rRrc0|d||SrcrCrPs r __rtruediv__z_Operand.__rtruediv__rUrc0|d||SNmodrCrPs r__mod__z_Operand.__mod__rRrc0|d||SrirCrPs r__rmod__z_Operand.__rmod__rUrc0|d||SNpowrCrPs r__pow__z_Operand.__pow__rRrc0|d||SrorCrPs r__rpow__z_Operand.__rpow__rUrc.|d|S)NinvertrCr?s r __invert__z_Operand.__invert__szz(D)))rc0|d||SNandrCrPs r__and__z_Operand.__and__rRrc0|d||SrxrCrPs r__rand__z_Operand.__rand__rUrc0|d||SNorrCrPs r__or__z_Operand.__or__zz$e,,,rc0|d||Sr~rCrPs r__ror__z_Operand.__ror__szz$t,,,rc0|d||SNxorrCrPs r__xor__z_Operand.__xor__rRrc0|d||SrrCrPs r__rxor__z_Operand.__rxor__rUrc0|d||S)NlshiftrCrPs r __lshift__z_Operand.__lshift__zz(D%000rc0|d||S)NrshiftrCrPs r __rshift__z_Operand.__rshift__rrc0|d||S)NeqrCrPs r__eq__z_Operand.__eq__rrc0|d||S)NnerCrPs r__ne__z_Operand.__ne__rrc0|d||S)NltrCrPs r__lt__z_Operand.__lt__rrc0|d||S)NlerCrPs r__le__z_Operand.__le__rrc0|d||S)NgtrCrPs r__gt__z_Operand.__gt__rrc0|d||S)NgerCrPs r__ge__z_Operand.__ge__rr)r r )rrrr )NN) r&r'rrr(r)rr*rr )rr<)rr )rLrrr )&__name__ __module__ __qualname____doc__rr.r;r@rDrHrKrQrTrYr[r_rarergrkrmrqrsrvrzr|rrrrrrrrrrrrrGrrr r s>>9999,(, +++++\----''''''''................................................****........--------........11111111--------------------------rr rrcPt|jdS)Nrr r rr?s r imagemath_intr DGOOC(( ) ))rcPt|jdS)Nrrr?s rimagemath_floatrrrrLr)c4|d||dS)NrrrrCrPs rimagemath_equalr ::dD%c: 2 22rc4|d||dS)NrrrrCrPs rimagemath_notequalrrrc0|d||S)Nr4rCrPs r imagemath_minr ::eT5 ) ))rc0|d||S)NmaxrCrPs r imagemath_maxrrrrr'cPt|j|Srr)rrs rimagemath_convertrs DGOOD)) * **r)r r!equalnotequalr4rr expressionCallable[[dict[str, Any]], Any]kwr c 4t}|||D]1\}}t |t jrt |||<2||} |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 r r0)rrargskvr8s r lambda_evalrs88::DKKOOO ""1 a % % "qkkDG *T  Cv  sB BBc t|D]0}d|vstt|rd|d}t |1|D]1\}}t|tjrt||<2t|ddd fd tj |d } |j S#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 allowedzevalcoderrNonec|jD]+}t|tur |,|jD]!}|vr|dkrd|d}t|"dS)NrBr-r) co_conststypeco_namesr)rconstnamer$r compiled_codescans rrzunsafe_eval..scan+s^  EE{{d=1111U M & &D4DEMM-$--- oo% & &rN)rrrr)rrhasattrbuiltinsrrrrrr compilerr r0) rrrr$rr8rrrs @@@r unsafe_evalr s9&88::D "" 199!,,9&a&&&CS// !  KKOOO ""1 a % % "qkkDGJ F;;M&&&&&&&& D - D$ / /Cv  s&C-- C<;C<)rr rr )rr rLr)rr )rr rr'rr )rrrr rr )rr'rr rr ) __future__rrrr TYPE_CHECKINGcollections.abcrtypesrtypingr r rrrrrrrrrrrGrrrs"#"""""!!!!!!!! ((((((e-e-e-e-e-e-e-e-R******** 33333333********++++   "   8//////r