Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
ImageOps.cpython-313.pyc349 linesDownload Raw Back to __pycache__
1�

2v�j�f��x�SSKJr SSKrSSKrSSKrSSKJr SSKJrJ	r	J3r4Jr SSKJ
r
JrJr S$SjrS%SjrS&S	jrS'S(SjjrS)S*Sjjr\R*R,4S+S
jjr\R*R,4S+Sjjr\R*R,SS4S,SjjrS-S.Sjjr\R*R,4S/Sjjr"SS\	5r\R*R:4S0SjjrS1S2SjjrS3S4Sjjr \R*R,SS4S5Sjjr!S6Sjr"S6Sjr#S6Sjr$S6Sjr%S7Sjr&S8S9Sjjr'\S:S j5r(\S5S!.S;S"jj5r(S6S!.S<S#jjr(g)=�)�annotationsN)�Sequence)�Literal�Protocol�cast�overload�)�ExifTags�Image�ImagePalettec��[U[5(a-[U5S:Xa	U=upup4O[U5S:XaUupp4OU=n=n=p4WWWW4$)N��)�7isinstance�tuple�len)�border�left�top�right�bottoms     �RD:\code\apps\devtools\python\user_packages\Python313\site-packages\PIL/ImageOps.py�_borderr!sc���&�%� � ��v�;�!��(.�.�I�D�
��v�
��[�A�
�'-�$�D�u��&,�,��,�s�,�U���e�V�#�#�c�^�[U[5(aSSKJn UR	X5nU$)Nr	)�8ImageColor)r�str�r�getcolor)�color�moders   r�_colorr",s'���%���� ��#�#�E�0���Lrc���URS:Xa
Sn[U5eURS;a7URS:Xa[U5S:XaX-U-nURU5$SUR3n[	U5e)N�Pzmode P support coming soon)�L�RGBr&�znot supported for mode )r!�NotImplementedErrorr�point�OSError)�image�lut�msgs   r�_lutr.4st���z�z�S��*��!�#�&�&�	���|�	#��:�:���3�s�8�s�?��)�c�/�C��{�{�3���'��9�10�|�4���c�l�rFc�T�U(a!URS5RU5nOURU5n/n[S[U5S5GH�nXWUS-nUb'[	U[115(aSX�'O
UHn	SX�'M	 U(a�[	U[5(dX4nSn12[S5H13n	X�U	-n14M [X�S-S-5n[S5H-nX�U:�aX�U-15nSX�'OX�==U-ss'SnUS::dM- O [X�S-S-5n[SSS5H-n
X�U
:�aX�U
-16nSX�'OX�==U-ss'SnUS::dM- O [S5HnX�(dM O [SSS5Hn
X�(dM O W
W::a&UR[[S555 GMwSX�-17-nU*U-n[S5H5n	[X�-U-5n	U	S:aSn	OU	S:�aSn	URU	5 M7 GM� [X5$)	a�18Maximize (normalize) image contrast. This function calculates a19histogram of the input image (or mask region), removes ``cutoff`` percent of the20lightest and darkest pixels from the histogram, and remaps the image21so that the darkest pixel becomes black (0), and the lightest22becomes white (255).23 24:param image: The image to process.25:param cutoff: The percent to cut off from the histogram on the low and26               high ends. Either a tuple of (low, high), or a single27               number for both.28:param ignore: The background pixel value (use None for no background).29:param mask: Histogram used in contrast operation is computed using pixels30             within the mask. If no mask is given the entire image is used31             for histogram computation.32:param preserve_tone: Preserve image tone in Photoshop-like style autocontrast.33 34                      .. versionadded:: 8.2.035 36:return: An image.37r%rr'�dr	�������g�o@)�convert�	histogram�rangerr�intr�extend�list�appendr.)r+�cutoff�ignore�mask�
preserve_toner4r,�layer�h�ix�n�cut�lo�hi�scale�offsets                r�autocontrastrGFs1��8��M�M�#�&�0�0��6�	��O�O�D�)�	�38�C��q�#�i�.�#�.���e�c�k�*�����&�#�&�&���	� �B��A�E�!���f�e�,�,� �)���A��C�j���"��I��!��a��)�m�s�*�+�C��C�j���2��;��"��+�C��A�E��E�S�L�E��C��!�8��!��a��)�m�s�*�+�C��C��R�(���2��;��"��+�C��A�E��E�S�L�E��C��!�8��)���*�B��u�u�����R��$�B��u�u��%���8��J�J�t�E�#�J�'�(��R�W�%�E��S�5�[�F��C�j�����f�,�-����6��B��#�X��B��39�40�2��
!�i/�v���rc���URS:XdeUcSUs=::aUs=::aS::de eO SUs=::aUs=::aUs=::aS::de e[[[[	US55n[[[[	US55nUb![[[[	US55OSn	/n41/n/n[U5H?n
U42R
US5 UR
US5 UR
US5 MA U	c�[XT-435nUH�n
U44R
USX�SUS-45-[U5--5 UR
USX�SUS-46-[U5--5 UR
USX�SUS-47-[U5--5 M� GO@[Xd-485n[XV-495nUH�n
U50R
USX�SUS-51-[U5--5 UR
USX�SUS-52-[U5--5 UR
USX�SUS-53-[U5--5 M� UH�n
U54R
U	SX�SU	S-55-[U5--5 UR
U	SX�SU	S-56-[U5--5 UR
U	SX�SU	S-57-[U5--5 M� [SU-585H?n
U59R
US5 UR
US5 UR
US5 MA URS5n[X60U-U-5$)	aK61Colorize grayscale image.62This function calculates a color wedge which maps all black pixels in63the source image to the first color and all white pixels to the64second color. If ``mid`` is specified, it uses three-color mapping.65The ``black`` and ``white`` arguments should be RGB tuples or color names;66optionally you can use three-color mapping by also specifying ``mid``.67Mapping positions for any of the colors can be specified68(e.g. ``blackpoint``), where these parameters are the integer69value corresponding to where the corresponding color should be mapped.70These parameters must have logical order, such that71``blackpoint <= midpoint <= whitepoint`` (if ``mid`` is specified).72 73:param image: The image to colorize.74:param black: The color to use for black input pixels.75:param white: The color to use for white input pixels.76:param mid: The color to use for midtone input pixels.77:param blackpoint: an int value [0, 255] for the black mapping.78:param whitepoint: an int value [0, 255] for the white mapping.79:param midpoint: an int value [0, 255] for the midtone mapping.80:return: An image.81r%Nrr1r&r	rr')82r!rrr6r"r5r9rr3r.)r+�black�white�mid�83blackpoint�84whitepoint�midpoint�	rgb_black�	rgb_white�rgb_mid�red�green�blue�i�	range_map�85range_map1�86range_map2s                 r�colorizerY�ss��B�:�:�����87�{��J�3�*�3��3�3�3�3�3��J�?�(�?�j�?�C�?�?�?�?�?��X�c�]�F�5�%�$8�9�I��X�c�]�F�5�%�$8�9�I�9<��d�8�C�=�&��e�"4�5�d�G�
�C��E�
�D��:�
���88�89�9�Q�<� �
���Y�q�\�"����I�a�L�!�����*�1�2�	��A��J�J��!��q�a�L�9�Q�<�$?�@�C�	�N�R�R�
�
�L�L��!��q�a�L�9�Q�<�$?�@�C�	�N�R�R�
�
�K�K��!��q�a�L�9�Q�<�$?�@�C�	�N�R�R�
���8�0�1�90��:�0�1�91��A��J�J��!��q�A�J��1��$=�>�#�j�/�Q�Q�
�
�L�L��!��q�A�J��1��$=�>�#�j�/�Q�Q�
�
�K�K��!��q�A�J��1��$=�>�#�j�/�Q�Q�
���A��J�J�w�q�z�A�1����92�)B�$C�s�:��$V�V�W��L�L���93�Q�A�,����";�<��J��O�O�
�
�K�K���94�Q�A�,����*C�%D��J��%W�W�X���3��#�
$���95�96�9�Q�<� �
���Y�q�\�"����I�a�L�!�%�
�M�M�%� �E���U�{�T�)�*�*rc�X�URUR-nUSUS-nX4:wasX4:�a8[URUR-US-5nXQS:waUSU4nO6[URUR-US-5nXaS:waXaS4nURXS9$)a�97Returns a resized version of the image, set to the maximum width and height98within the requested size, while maintaining the original aspect ratio.99 100:param image: The image to resize.101:param size: The requested output size in pixels, given as a102             (width, height) tuple.103:param method: Resampling method to use. Default is104               :py:attr:`~PIL.Image.Resampling.BICUBIC`.105               See :ref:`concept-filters`.106:return: An image.107rr	��resample��width�height�round�resize�r+�size�method�im_ratio�108dest_ratio�109new_height�	new_widths       r�containri
��� �{�{�U�\�\�)�H��a��4��7�"�J���� ��u�|�|�e�k�k�9�D��G�C�D�J��!�W�$��Q���,����e�k�k�E�L�L�8�4��7�B�C�I���G�#�!��7�+���<�<��<�.�.rc�X�URUR-nUSUS-nX4:wasX4:a8[URUR-US-5nXQS:waUSU4nO6[URUR-US-5nXaS:waXaS4nURXS9$)a�110Returns a resized version of the image, so that the requested size is111covered, while maintaining the original aspect ratio.112 113:param image: The image to resize.114:param size: The requested output size in pixels, given as a115             (width, height) tuple.116:param method: Resampling method to use. Default is117               :py:attr:`~PIL.Image.Resampling.BICUBIC`.118               See :ref:`concept-filters`.119:return: An image.120rr	r[r]rbs       r�coverrl,rjr)��?rmc121�>�[XU5nURU:XaUnU$[R"URX5nUR122(a$UR
5nUbURU5 URUS:waJ[USUR-123[S[USS55-5nURXXS45 U$[USUR-124[S[USS55-5n	URUSU	45 U$)a0125Returns a resized and padded version of the image, expanded to fill the126requested aspect ratio and size.127 128:param image: The image to resize and crop.129:param size: The requested output size in pixels, given as a130             (width, height) tuple.131:param method: Resampling method to use. Default is132               :py:attr:`~PIL.Image.Resampling.BICUBIC`.133               See :ref:`concept-filters`.134:param color: The background color of the padded image.135:param centering: Control the position of the original image within the136                  padded version.137 138                      (0.5, 0.5) will keep the image centered139                      (0, 0) will keep the image aligned to the top left140                      (1, 1) will keep the image aligned to the bottom141                      right142:return: An image.143rr	)rircr�newr!�palette�144getpalette�145putpaletter^r`�max�min�paster_)146r+rcrdr �	centering�resized�outrp�x�ys147          r�padr{Ks��8�e�6�*�G��|�|�t�����J��i�i��148�149�D�0���?�?��(�(�*�G��"����w�'��=�=�D��G�#��t�A�w����.�#�a��Y�q�\�1�9M�2N�N�O�A��I�I�g�1�v�&��J��t�A�w����/�3�q�#�i��l�A�:N�3O�O�P�A��I�I�g��1�v�&��Jrc��[U5up#pEURX#URSU-150URSU-15145$)a152Remove border from image.  The same amount of pixels are removed153from all four sides.  This function works on all image modes.154 155.. seealso:: :py:meth:`~PIL.Image.Image.crop`156 157:param image: The image to crop.158:param border: The number of pixels to remove.159:return: An image.160rr	)r�croprc)r+rrrrrs      rr}r}ysB�� '�v���D�u��:�:�t�%�*�*�Q�-�%�"7����A���9O�P�Q�Qrc���US:XaUR5$US::a
Sn[U5e[XR-5[XR-54nURXB5$)a�161Returns a rescaled image by a specific factor given in parameter.162A factor greater than 1 expands the image, between 0 and 1 contracts the163image.164 165:param image: The image to rescale.166:param factor: The expansion factor, as a float.167:param resample: Resampling method to use. Default is168                 :py:attr:`~PIL.Image.Resampling.BICUBIC`.169                 See :ref:`concept-filters`.170:returns: An :py:class:`~PIL.Image.Image` object.171r	rz!the factor must be greater than 0)�copy�172ValueErrorr`r^r_ra)r+�factorr\r-rcs     rrErE�s^����{��z�z�|��	�1��1����o���f�{�{�*�+�U�6�L�L�3H�-I�J���|�|�D�+�+rc�*�\rSrSrSrSSjrSrg)�SupportsGetMeshi�a-173An object that supports the ``getmesh`` method, taking an image as an174argument, and returning a list of tuples. Each tuple contains two tuples,175the source box as a tuple of 4 integers, and a tuple of 8 integers for the176final quadrilateral, in order of top left, bottom left, bottom right, top177right.178c��g�N�)�selfr+s  r�getmesh�SupportsGetMesh.getmesh�s��rr�N)r+�Image.Image�returnzUlist[tuple[tuple[int, int, int, int], tuple[int, int, int, int, int, int, int, int]]])�__name__�179__module__�__qualname__�__firstlineno__�__doc__r��__static_attributes__r�rrr�r��s���� ��180�rr�c��URUR[RRURU5U5$)a,181Deform the image.182 183:param image: The image to deform.184:param deformer: A deformer object.  Any object that implements a185                ``getmesh`` method can be used.186:param resample: An optional resampling filter. Same values possible as187   in the PIL.Image.transform function.188:return: An image.189)�	transformrcr�	Transform�MESHr�)r+�deformerr\s   r�deformr��s7���?�?�
�190�191�E�O�O�(�(�(�*:�*:�5�*A�8��rc��URS:XaURS5nURU5n/n[S[	U5S5H�nX$US-Vs/sH
oU(dMUPM nn[	U5S::a%UR[
[S555 MV[R"[RU5US-192S-nU(d%UR[
[S555 M�US-n[S5Hn	URX�-5 X�X�--nM! M� [X5$s snf)	ad193Equalize the image histogram. This function applies a non-linear194mapping to the input image, in order to create a uniform195distribution of grayscale values in the output image.196 197:param image: The image to equalize.198:param mask: An optional mask.  If given, only the pixels selected by199             the mask are included in the analysis.200:return: An image.201r$r&rr'r	r2r1r)
r!r3r4r5rr7r8�	functools�reduce�operator�addr9r.)202r+r<r?r,�b�_f�histo�steprArUs203          r�equalizer��s��
�z�z�S���
�
�e�$��
�����A�204�C�
�1�c�!�f�c�
"���A��G�n�3�n����n��3��u�:��?��J�J�t�E�#�J�'�(��$�$�X�\�\�5�9�E�"�I�E�#�M�D���205�206�4��c�207�+�,��A�I���s��A��J�J�q�y�)��a�e�H��A�$�#������4s�208D=�%D=c�t�[U5up4pVX0RS-U-nX@RS-U-n[X R5n	UR(a�URRn209[210R211"X�R
U21255n[U	[5(a/[U	5S:Xd[U	5S:XaURU	5n	OSn[R"URXx4U	5nU(aURURW2135 URXU45 U$)z�214Add border to the image215 216:param image: The image to expand.217:param border: Border width, in pixels.218:param fill: Pixel fill value (a color value).  Default is 0 (black).219:return: An image.220rr	�rN)rrcr"r!rprrqrrrrrrorrru)
r+r�fillrrrrr^r_r r!rprxs
             r�expandr��s��� '�v���D�u��:�:�a�=� �5�(�E�
�:�:�a�=�
 �6�
)�F��4���$�E��}�}��}�}�!�!���+�+�D�2B�2B�4�2H�I���e�U�#�#��U��q��C��J�!�O��$�$�U�+�E����221�)�)�E�J�J����2227�C�����w����-��I�I�e�C�[�!��Jr�c��UupVSUs=::aS::dO SnSUs=::aS::dO SnSUs=::aS:dO SnX0RS-X0RS-4nURSUSS--223URSUSS--2244nUSUS-n	USUS-n225X�:XaUSnUSnOX�:�a
X�S-nUSnO
USnUSU226-nUSUSU-227U--n
USUSU-228U--nX�X�-X�-4nURXUS9$)a�229Returns a resized and cropped version of the image, cropped to the230requested aspect ratio and size.231 232This function was contributed by Kevin Cazabon.233 234:param image: The image to resize and crop.235:param size: The requested output size in pixels, given as a236             (width, height) tuple.237:param method: Resampling method to use. Default is238               :py:attr:`~PIL.Image.Resampling.BICUBIC`.239               See :ref:`concept-filters`.240:param bleed: Remove a border around the outside of the image from all241              four edges. The value is a decimal percentage (use 0.01 for242              one percent). The default value is 0 (no border).243              Cannot be greater than or equal to 0.5.244:param centering: Control the cropping position.  Use (0.5, 0.5) for245                  center cropping (e.g. if cropping the width, take 50% off246                  of the left side, and therefore 50% off the right side).247                  (0.0, 0.0) will crop from the top left corner (i.e. if248                  cropping the width, take all of the crop off of the right249                  side, and if cropping the height, take all of it off the250                  bottom).  (1.0, 0.0) will crop from the bottom left251                  corner, etc. (i.e. if cropping the width, take all of the252                  crop off the left side, and if cropping the height take253                  none from the top, and therefore all off the bottom).254:return: An image.255r�g�?rmrr	r)�box)rcra)r+rcrd�bleedrv�centering_x�centering_y�bleed_pixels�	live_size�live_size_ratio�output_ratio�256crop_width�crop_height�	crop_left�crop_topr}s                r�fitr�sw��P )��K��+�$��$����+�$��$����%��#�����J�J�q�M�)�5�:�:�a�=�+@�A�L�	�257�258�1�
��Q��!�+�+�
�259�260�1�
��Q��!�+�+��I� ��l�Y�q�\�1�O���7�T�!�W�$�L��&��q�\�261���l��	�	(�!�a�L�0�262���l���q�\�263���l�\�1���Q��9�Q�<�*�#<��"K�K�I��A��)�A�,��"<��!K�K�H���!7��9O�P�D��<�<��$�<�/�/rc�T�UR[RR5$)za264Flip the image vertically (top to bottom).265 266:param image: The image to flip.267:return: An image.268)�	transposer�	Transpose�FLIP_TOP_BOTTOM�r+s r�flipr�^����?�?�5�?�?�:�:�;�;rc�$�URS5$)zY269Convert the image to grayscale.270 271:param image: The image to convert.272:return: An image.273r%)r3r�s r�	grayscaler�hs���=�=���rc��[[SSS55nURS:XaURU5$[	X5$)zS274Invert (negate) the image.275 276:param image: The image to invert.277:return: An image.278r1r2�1)r8r5r!r)r.)r+r,s  r�invertr�rs;���u�S�"�b�!�279"�C�$�z�z�S�0�5�;�;�s��F�d�5�6F�Frc�T�UR[RR5$)za280Flip image horizontally (left to right).281 282:param image: The image to mirror.283:return: An image.284)r�rr��FLIP_LEFT_RIGHTr�s r�mirrorr�}r�rc�t�SSU-285-S-286)n[S5Vs/sHo3U-PM	 nn[X5$s snf)z�287Reduce the number of bits for each color channel.288 289:param image: The image to posterize.290:param bits: The number of bits to keep for each channel (1-8).291:return: An image.292r�r	r')r5r.)r+�bitsr<rUr,s     r�	posterizer��sC���1�t�8�_�q�
 �!�D�"�3�Z�293(�Z��t�8�Z�C�294(������)s�5c��/n[S5H/nX1:aURU5 MURSU-2955 M1 [X5$)z�296Invert all pixel values above a threshold.297 298:param image: The image to solarize.299:param threshold: All pixels above this grayscale level are inverted.300:return: An image.301r'r1)r5r9r.)r+�	thresholdr,rUs    r�solarizer��sD��
�C�
�3�Z���=��J�J�q�M��J�J�s�Q�w��	�302���rc��gr�r��r+�in_places  r�exif_transposer��s��LOr)r�c��gr�r�r�s  rr�r��s��rc�303^304�UR5 UR5nUR[RR305S5n[RR[RR[RR[RR[RR[RR[RRS.RU5nUGb�U(a<URR!U5UlURR"UlOUR!U5nU(aUOWnUR5n[RR306U;GaCU[RR307	SUR&;aUR)5UR&S'O;SUR&;a+UR)5R+5UR&S'SH�nX�R&;dMSH�m308UR&Un	[-U	[.5(a[0R2"T309SU	5n	OQ[-U	[45(a[5U3104S	jU	55n	O&[0R2"T311R75S312U	5n	X�R&U'M� M� U(dW$gU(dUR95$g)a�313If an image has an EXIF Orientation tag, other than 1, transpose the image314accordingly, and remove the orientation data.315 316:param image: The image to transpose.317:param in_place: Boolean. Keyword-only argument.318    If ``True``, the original image is modified in-place, and ``None`` is returned.319    If ``False`` (default), a new :py:class:`~PIL.Image.Image` object is returned320    with the transposition applied. If there is no transposition, a copy of the321    image will be returned.322r	)rr�r���r�N�exifzRaw profile type exif)zXML:com.adobe.xmp�xmp)ztiff:Orientation="([0-9])"z,<tiff:Orientation>([0-9])</tiff:Orientation>rc3�p># �UH+n[R"TR5SU5v� M- g7f)rN)�re�sub�encode)�.0�v�patterns  �r�	<genexpr>�!exif_transpose.<locals>.<genexpr>�s+����*�JO�Q����w�~�~�'7��a� @� @�%�s�36r)�load�getexif�getr323�Base�Orientationrr�r��324ROTATE_180r��	TRANSPOSE�325ROTATE_270�326TRANSVERSE�	ROTATE_90�imr�rc�_size�info�tobytes�hexrrr�r�rr�r)r+r��327image_exif�orientationrd�transposed_image�328exif_imager��key�valuer�s          @rr�r��s,���329�J�J�L�����J��.�.����!:�!:�A�>�K��?�?�*�*��?�?�%�%��?�?�*�*��?�?�$�$��?�?�%�%��?�?�%�%��?�?�$�$��330�c�+�������x�x�)�)�&�1�E�H��(�(�-�-�E�K�$���v�6��&�U�,<�331��!�!�#���=�=�$�$��,��X�]�]�.�.�/�����(�*.�,�,�.�332����'�(�J�O�O�;�;?�<�<�>�;M�;M�;O�333��� 7�8�3���/�/�)�$��!+���� 4��%�e�S�1�1�$&�F�F�7�B��$>�E�'��u�5�5�$)�*�JO�*�%�E�%'�F�F�7�>�>�+;�S�%�$H�E�/4����,�$�4� �#�#�����z�z�|��r)r�int | tuple[int, ...]r�ztuple[int, int, int, int])r �str | int | tuple[int, ...]r!rr�r�)r+r�r,z	list[int]r�r�)rNNF)r+r�r:zfloat | tuple[float, float]r;zint | Sequence[int] | Noner<�Image.Image | Noner=�boolr�r�)Nrr1�)r+r�rI�str | tuple[int, ...]rJr�rK�"str | int | tuple[int, ...] | NonerLr6rMr6rNr6r�r�)r+r�rc�tuple[int, int]rdr6r�r�)r+r�rcr�rdr6r r�rv�tuple[float, float]r�r�)r)r+r�rr6r�r�)r+r�r��floatr\r6r�r�)r+r�r�r�r\r6r�r�r�)r+r�r<r�r�r�)rr)r+r�rr�r�r�r�r�)r+r�rcr�rdr6r�r�rvr�r�r�)r+r�r�r�)r+r�r�r6r�r�)�)r+r�r�r6r�r�)r+r�r�z
Literal[True]r��None)r+r�r�zLiteral[False]r�r�)r+r�r�r�r�r�))�334__future__rr�r�r��collections.abcr�typingrrrrrr335rrrr"r.rGrY�336Resampling�BICUBICrirlr{r}rEr��BILINEARr�r�r�r�r�r�r�r�r�r�r�r�rr�<module>rs6��&#���	�$�4�4�+�+�$���(+,�)-�#��]��]�'�]�
'�]��	]�337�]��
]�H/3����d+��d+� �d+�!�d+�338,�	d+�339�d+��
d+��d+��d+�P>C�=M�=M�=U�=U�/��/�-�/�7:�/��/�@>C�=M�=M�=U�=U�/��/�-�/�7:�/��/�D�"�"�*�*�04�%/�+��+�340�+�
�+�.�	+�341#�+��
+�\R� 8=�7G�7G�7O�7O�,��,� %�,�14�,��,�2
�h�
�&�$�$�-�-���������	�(�B%&�()����!��&���	�D�"�"�*�*��%/�X0��X0�342�X0�
�X0��	X0�343#�X0��
X0�v<��G�<�344��"345�O�346�O�347�6;����%3����348��349<A�;�;r
codekingpro/portable-devtools · Team Ai