%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/PIL/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/PIL/__pycache__/ImageOps.cpython-312.pyc

�

��e�W����ddlmZddlZddlZddlZddlmZmZmZd�Z	d�Z
d�Zdd	�Zdd
�Z
ejjfd�Zejjfd�Zejjdd
fd�Zd d�Zejjfd�Zejj*fd�Zd!d�Zd"d�Zejjdd
fd�Zd�Zd�Zd�Zd�Zd�Zd#d�Zdd�d�Z y)$�)�annotationsN�)�ExifTags�Image�ImagePalettec��t|t�r/t|�dk(r|x\}}\}}nt|�dk(r|\}}}}n|x}x}x}}fS)N��)�
isinstance�tuple�len)�border�left�top�right�bottoms     �./usr/lib/python3/dist-packages/PIL/ImageOps.py�_borderrsg���&�%� ��v�;�!��(.�.�I�D�#�
��v�
��[�A�
�'-�$�D�#�u�f�&,�,��,�s�,�U�V���e�V�#�#�c�V�t|t�rddlm}|j	||�}|S)Nr)�
ImageColor)r�str�r�getcolor)�color�moders   r�_colorr*s&���%��� ��#�#�E�4�0���Lrc��|jdk(r
d}t|��|jdvr6|jdk(rt|�dk(r||z|z}|j|�Sd|j��}t	|��)N�Pzmode P support coming soon)�L�RGBr!�znot supported for mode )r�NotImplementedErrorr
�point�OSError)�image�lut�msgs   r�_lutr)2sv���z�z�S��*��!�#�&�&�	���|�	#��:�:���3�s�8�s�?���)�c�/�C��{�{�3���'��
�
�|�4���c�l�rFc���|r!|jd�j|�}n|j|�}g}tdt|�d�D�]|}|||dz}|�	d||<|r�t|t�s||f}d}
td�D]
}	|
||	z}
�|
|dzdz}td�D].}|||kDr|||z
}d||<n||xx|zcc<d}|dks�.n|
|dzdz}tddd�D].}
|||
kDr|||
z
}d||
<n||
xx|zcc<d}|dks�.ntd�D]	}||s�	ntddd�D]	}
||
s�	n
kr%|jttd�����.d|
|z
z}||z}td�D]3}	t|	|z|z�}	|	dkrd}	n|	dkDrd}	|j|	��5��t||�S#t$r|D]}	d||	<�	Y���wxYw)	a�
    Maximize (normalize) image contrast. This function calculates a
    histogram of the input image (or mask region), removes ``cutoff`` percent of the
    lightest and darkest pixels from the histogram, and remaps the image
    so that the darkest pixel becomes black (0), and the lightest
    becomes white (255).

    :param image: The image to process.
    :param cutoff: The percent to cut off from the histogram on the low and
                   high ends. Either a tuple of (low, high), or a single
                   number for both.
    :param ignore: The background pixel value (use None for no background).
    :param mask: Histogram used in contrast operation is computed using pixels
                 within the mask. If no mask is given the entire image is used
                 for histogram computation.
    :param preserve_tone: Preserve image tone in Photoshop-like style autocontrast.

                          .. versionadded:: 8.2.0

    :return: An image.
    r rr"�dr����g�o@)�convert�	histogram�ranger
�	TypeErrorrr�extend�list�int�appendr))r&�cutoff�ignore�mask�
preserve_toner/r'�layer�h�ix�n�cut�lo�hi�scale�offsets                r�autocontrastrCDs|��,��M�M�#�&�0�0��6�	��O�O�D�)�	�
�C��q�#�i�.�#�.�;���e�e�c�k�*����
���&�	�
��f�e�,� �&�)���A��C�j�
����"��I��
��f�Q�i�-�3�&�C��C�j�
����2��;���"��+�C��A�b�E��b�E�S�L�E��C��!�8��
��f�Q�i�-�3�&�C��C��R�(�
����2��;���"��+�C��A�b�E��b�E�S�L�E��C��!�8��
���*�	�B���u��	���R��$�	�B���u��	���8��J�J�t�E�#�J�'�(��R�"�W�%�E��S�5�[�F��C�j�
����e��f�,�-����6��B��#�X��B��
�
�2��

�k;�x��s����m�
� ��B��A�b�E��
�s�G�G2�1G2c�>�|jdk(sJ�|�d|cxkr|cxkrdks!J�J�d|cxkr|cxkr|cxkrdksJ�J�t|d�}t|d�}|�t|d�}g}g}g}	td|�D]>}
|j|d�|j|d�|	j|d��@|��td||z
�}|D]�}
|j|d|
|d|dz
zt	|�zz�|j|d|
|d|dz
zt	|�zz�|	j|d|
|d|dz
zt	|�zz����nFtd||z
�}td||z
�}
|D]�}
|j|d|
|d|dz
zt	|�zz�|j|d|
|d|dz
zt	|�zz�|	j|d|
|d|dz
zt	|�zz���|
D]�}
|j|d|
|d|dz
zt	|
�zz�|j|d|
|d|dz
zt	|
�zz�|	j|d|
|d|dz
zt	|
�zz���tdd|z
�D]>}
|j|d�|j|d�|	j|d��@|jd�}t
|||z|	z�S)a�
    Colorize grayscale image.
    This function calculates a color wedge which maps all black pixels in
    the source image to the first color and all white pixels to the
    second color. If ``mid`` is specified, it uses three-color mapping.
    The ``black`` and ``white`` arguments should be RGB tuples or color names;
    optionally you can use three-color mapping by also specifying ``mid``.
    Mapping positions for any of the colors can be specified
    (e.g. ``blackpoint``), where these parameters are the integer
    value corresponding to where the corresponding color should be mapped.
    These parameters must have logical order, such that
    ``blackpoint <= midpoint <= whitepoint`` (if ``mid`` is specified).

    :param image: The image to colorize.
    :param black: The color to use for black input pixels.
    :param white: The color to use for white input pixels.
    :param mid: The color to use for midtone input pixels.
    :param blackpoint: an int value [0, 255] for the black mapping.
    :param whitepoint: an int value [0, 255] for the white mapping.
    :param midpoint: an int value [0, 255] for the midtone mapping.
    :return: An image.
    r rr,r!rr	r")rrr0r5r
r.r))r&�black�white�mid�
blackpoint�
whitepoint�midpoint�red�green�blue�i�	range_map�
range_map1�
range_map2s              r�colorizerR�st��2�:�:�����
�{��J�3�*�3��3�3�3�3�3��J�?�(�?�j�?�C�?�?�?�?�?�
�5�%� �E��5�%� �E�
���S�%� ��
�C��E�
�D��1�j�
!����
�
�5��8��
���U�1�X�����E�!�H����{��!�Z�*�4�5�	��	P�A��J�J�u�Q�x�!�u�Q�x�%��(�':�";�s�9�~�"M�M�N��L�L��q��A��q��E�!�H�)<�$=��Y��$O�O�P��K�K��a��1��a��5��8�(;�#<��I��#N�N�O�	P��1�h��3�4�
��1�j�8�3�4�
��	O�A��J�J�u�Q�x�!�s�1�v��a��'8�"9�S��_�"L�L�M��L�L��q��A��Q��%��(�):�$;�s�:��$N�N�O��K�K��a��1��A���q��(9�#:�c�*�o�#M�M�N�	O��	M�A��J�J�s�1�v��U�1�X��A��%6� 7�3�z�?� J�J�K��L�L��Q��!�u�Q�x�#�a�&�'8�"9�S��_�"L�L�M��K�K��A���e�A�h��Q��&7�!8�C�
�O�!K�K�L�	M��1�c�J�&�
'����
�
�5��8��
���U�1�X�����E�!�H���
�M�M�%� �E���s�U�{�T�)�*�*rc�b�|j|jz}|d|dz}||k7rt||kDr8t|j|jz|dz�}||dk7r?|d|f}n7t|j|jz|dz�}||dk7r||df}|j||��S)a�
    Returns a resized version of the image, set to the maximum width and height
    within the requested size, while maintaining the original aspect ratio.

    :param image: The image to resize.
    :param size: The requested output size in pixels, given as a
                 (width, height) tuple.
    :param method: Resampling method to use. Default is
                   :py:attr:`~PIL.Image.Resampling.BICUBIC`.
                   See :ref:`concept-filters`.
    :return: An image.
    rr��resample��width�height�round�resize�r&�size�method�im_ratio�
dest_ratio�
new_height�	new_widths       r�containrb�����{�{�U�\�\�)�H��a��4��7�"�J��:���j� ��u�|�|�e�k�k�9�D��G�C�D�J��T�!�W�$��Q���,���e�k�k�E�L�L�8�4��7�B�C�I��D��G�#�!�4��7�+���<�<��v�<�.�.rc�b�|j|jz}|d|dz}||k7rt||kr8t|j|jz|dz�}||dk7r?|d|f}n7t|j|jz|dz�}||dk7r||df}|j||��S)a�
    Returns a resized version of the image, so that the requested size is
    covered, while maintaining the original aspect ratio.

    :param image: The image to resize.
    :param size: The requested output size in pixels, given as a
                 (width, height) tuple.
    :param method: Resampling method to use. Default is
                   :py:attr:`~PIL.Image.Resampling.BICUBIC`.
                   See :ref:`concept-filters`.
    :return: An image.
    rrrTrVr[s       r�coverrercr)��?rfc
�*�t|||�}|j|k(r|}|Stj|j||�}|j
r|j
|j��|j|dk7rKt|d|jz
tdt|dd��z�}|j||df�|St|d|jz
tdt|dd��z�}|j|d|f�|S)at
    Returns a resized and padded version of the image, expanded to fill the
    requested aspect ratio and size.

    :param image: The image to resize and crop.
    :param size: The requested output size in pixels, given as a
                 (width, height) tuple.
    :param method: Resampling method to use. Default is
                   :py:attr:`~PIL.Image.Resampling.BICUBIC`.
                   See :ref:`concept-filters`.
    :param color: The background color of the padded image.
    :param centering: Control the position of the original image within the
                      padded version.

                          (0.5, 0.5) will keep the image centered
                          (0, 0) will keep the image aligned to the top left
                          (1, 1) will keep the image aligned to the bottom
                          right
    :return: An image.
    rr)rbr\r�newr�palette�
putpalette�
getpaletterWrY�max�min�pasterX)	r&r\r]r�	centering�resized�out�x�ys	         r�padrt+s���,�e�T�6�*�G��|�|�t�����J��i�i��
�
�D�%�0���?�?��N�N�7�-�-�/�0��=�=�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��t|�\}}}}|j|||jd|z
|jd|z
f�S)a/
    Remove border from image.  The same amount of pixels are removed
    from all four sides.  This function works on all image modes.

    .. seealso:: :py:meth:`~PIL.Image.Image.crop`

    :param image: The image to crop.
    :param border: The number of pixels to remove.
    :return: An image.
    rr)r�cropr\)r&rrrrrs      rrvrvQsH�� '�v���D�#�u�f��:�:�t�S�%�*�*�Q�-�%�"7����A���9O�P�Q�Qrc���|dk(r|j�S|dkr
d}t|��t||jz�t||jz�f}|j||�S)a�
    Returns a rescaled image by a specific factor given in parameter.
    A factor greater than 1 expands the image, between 0 and 1 contracts the
    image.

    :param image: The image to rescale.
    :param factor: The expansion factor, as a float.
    :param resample: Resampling method to use. Default is
                     :py:attr:`~PIL.Image.Resampling.BICUBIC`.
                     See :ref:`concept-filters`.
    :returns: An :py:class:`~PIL.Image.Image` object.
    rrz!the factor must be greater than 0)�copy�
ValueErrorrYrWrXrZ)r&�factorrUr(r\s     rrArA`sd����{��z�z�|��	�1��1����o���f�u�{�{�*�+�U�6�E�L�L�3H�-I�J���|�|�D�(�+�+rc��|j|jtjj|j|�|�S)aL
    Deform the image.

    :param image: The image to deform.
    :param deformer: A deformer object.  Any object that implements a
                    ``getmesh`` method can be used.
    :param resample: An optional resampling filter. Same values possible as
       in the PIL.Image.transform function.
    :return: An image.
    )�	transformr\r�	Transform�MESH�getmesh)r&�deformerrUs   r�deformr�ws7���?�?�
�
�
�E�O�O�(�(�(�*:�*:�5�*A�8��rc�b�|jdk(r|jd�}|j|�}g}tdt	|�d�D]�}|||dzD�cgc]}|s�|��	}}t	|�dkr$|jt
td����Mtjtj|�|dz
dz}|s$|jt
td�����|dz}td�D]!}	|j||z�|||	|zz}�#��t||�Scc}w)	a�
    Equalize the image histogram. This function applies a non-linear
    mapping to the input image, in order to create a uniform
    distribution of grayscale values in the output image.

    :param image: The image to equalize.
    :param mask: An optional mask.  If given, only the pixels selected by
                 the mask are included in the analysis.
    :return: An image.
    rr!rr"rr-r,r	)
rr.r/r0r
r2r3�	functools�reduce�operator�addr5r))
r&r8r;r'�b�_f�histo�stepr=rNs
          r�equalizer��s��
�z�z�S���
�
�e�$��
�����A�
�C�
�1�c�!�f�c�
"�%����A��G�n�3����3��3��u�:��?��J�J�t�E�#�J�'�(��$�$�X�\�\�5�9�E�"�I�E�#�M�D���
�
�4��c�
�+�,��A�I���s��%�A��J�J�q�D�y�)��A�a�!�e�H��A�%�%���s����4s�D,�D,c��t|�\}}}}||jdz|z}||jdz|z}t||j�}	|jrFtj
|j
���}
t|	t�r|
j|	�}	nd}
tj|j||f|	�}|
r|j|
j�|j|||f�|S)z�
    Add border to the image

    :param image: The image to expand.
    :param border: Border width, in pixels.
    :param fill: Pixel fill value (a color value).  Default is 0 (black).
    :return: An image.
    rr)riN)rr\rrrirrkrrrrrhrjrn)r&r�fillrrrrrWrXrrirqs            r�expandr��s��� '�v���D�#�u�f��5�:�:�a�=� �5�(�E�
�5�:�:�a�=�
 �6�
)�F��4����$�E��}�}��+�+�E�4D�4D�4F�G���e�U�#��$�$�U�+�E���
�)�)�E�J�J�����
7�C�����w���'��I�I�e�d�C�[�!��Jr�c�N�t|�}d|dcxkrdksnd|d<d|dcxkrdksnd|d<d|cxkrdksnd}||jdz||jdzf}|jd|ddzz
|jd|ddzz
f}|d|dz}|d|dz}||k(r|d}	|d}
n ||k\r||dz}	|d}
n
|d}	|d|z}
|d|d|	z
|dzz}|d|d|
z
|dzz}||||	z||
zf}
|j|||
��S)a
    Returns a resized and cropped version of the image, cropped to the
    requested aspect ratio and size.

    This function was contributed by Kevin Cazabon.

    :param image: The image to resize and crop.
    :param size: The requested output size in pixels, given as a
                 (width, height) tuple.
    :param method: Resampling method to use. Default is
                   :py:attr:`~PIL.Image.Resampling.BICUBIC`.
                   See :ref:`concept-filters`.
    :param bleed: Remove a border around the outside of the image from all
                  four edges. The value is a decimal percentage (use 0.01 for
                  one percent). The default value is 0 (no border).
                  Cannot be greater than or equal to 0.5.
    :param centering: Control the cropping position.  Use (0.5, 0.5) for
                      center cropping (e.g. if cropping the width, take 50% off
                      of the left side, and therefore 50% off the right side).
                      (0.0, 0.0) will crop from the top left corner (i.e. if
                      cropping the width, take all of the crop off of the right
                      side, and if cropping the height, take all of it off the
                      bottom).  (1.0, 0.0) will crop from the bottom left
                      corner, etc. (i.e. if cropping the width, take all of the
                      crop off the left side, and if cropping the height take
                      none from the top, and therefore all off the bottom).
    :return: An image.
    r�rg�?rfrr	)�box)r3r\rZ)r&r\r]�bleedro�bleed_pixels�	live_size�live_size_ratio�output_ratio�
crop_width�crop_height�	crop_left�crop_toprvs              r�fitr��s���F�Y��I��)�A�,�%�#�%��	�!���)�A�,�%�#�%��	�!���%��#�����E�J�J�q�M�)�5�5�:�:�a�=�+@�A�L�	�
�
�1�
��Q��!�+�+�
�
�
�1�
��Q��!�+�+��I� ��l�Y�q�\�1�O���7�T�!�W�$�L��,�&��q�\�
���l��	�L�	(�!�I�a�L�0�
���l���q�\�
���l�\�1���Q��9�Q�<�*�#<�	�!��"L�L�I��A��)�A�,��"<�	�!��!L�L�H��x��Z�!7��K�9O�P�D��<�<��f�$�<�/�/rc�T�|jtjj�S)zq
    Flip the image vertically (top to bottom).

    :param image: The image to flip.
    :return: An image.
    )�	transposer�	Transpose�FLIP_TOP_BOTTOM�r&s r�flipr�����?�?�5�?�?�:�:�;�;rc�$�|jd�S)zi
    Convert the image to grayscale.

    :param image: The image to convert.
    :return: An image.
    r )r.r�s r�	grayscaler� s���=�=���rc��ttddd��}|jdk(r|j|�St	||�S)zc
    Invert (negate) the image.

    :param image: The image to invert.
    :return: An image.
    r,r-�1)r3r0rr$r))r&r's  r�invertr�*s=���u�S�"�b�!�
"�C�$�z�z�S�0�5�;�;�s��F�d�5�#�6F�Frc�T�|jtjj�S)zq
    Flip image horizontally (left to right).

    :param image: The image to mirror.
    :return: An image.
    )r�rr��FLIP_LEFT_RIGHTr�s r�mirrorr�5r�rc�r�dd|z
zdz
}td�D�cgc]}||z��	}}t||�Scc}w)z�
    Reduce the number of bits for each color channel.

    :param image: The image to posterize.
    :param bits: The number of bits to keep for each channel (1-8).
    :return: An image.
    r	�rr")r0r))r&�bitsr8rNr's     r�	posterizer�?sF���1�t�8�_�q�
 �!�D�"�3�Z�
(��1�t�8�
(�C�
(���s����)s�4c��g}td�D]-}||kr|j|��|jd|z
��/t||�S)z�
    Invert all pixel values above a threshold.

    :param image: The image to solarize.
    :param threshold: All pixels above this grayscale level are inverted.
    :return: An image.
    r"r,)r0r5r))r&�	thresholdr'rNs    r�solarizer�LsM��
�C�
�3�Z� ���y�=��J�J�q�M��J�J�s�Q�w��	 �
��s��r)�in_placec��|j�|j�}|jtjj
�}tjjtjjtjjtjjtjjtjjtjjd�j|�}|��:|j|�}|r)|j |_d|_|j$|_|r|n|}|j�}tjj
|vr�|tjj
=d|j&vr|j)�|j&d<n�d|j&vr,|j)�j+�|j&d<nFd|j&vr8dD]3}t-j.|d|j&d�|j&d<�5|s|Sy|s|j1�Sy)a
    If an image has an EXIF Orientation tag, other than 1, transpose the image
    accordingly, and remove the orientation data.

    :param image: The image to transpose.
    :param in_place: Boolean. Keyword-only argument.
        If ``True``, the original image is modified in-place, and ``None`` is returned.
        If ``False`` (default), a new :py:class:`~PIL.Image.Image` object is returned
        with the transposition applied. If there is no transposition, a copy of the
        image will be returned.
    )r	�r
���r�N�exifzRaw profile type exifzXML:com.adobe.xmp)ztiff:Orientation="([0-9])"z,<tiff:Orientation>([0-9])</tiff:Orientation>r)�load�getexif�getr�Base�Orientationrr�r��
ROTATE_180r��	TRANSPOSE�
ROTATE_270�
TRANSVERSE�	ROTATE_90r��im�pyaccess�_size�info�tobytes�hex�re�subrx)	r&r��
image_exif�orientationr]�transposed_image�
exif_imager��patterns	         r�exif_transposer�]s���
�J�J�L�����J��.�.����!:�!:�;�K��?�?�*�*��?�?�%�%��?�?�*�*��?�?�$�$��?�?�%�%��?�?�%�%��?�?�$�$��
�c�+����� �?�?�6�2���'�*�*�E�H�!�E�N�*�0�0�E�K�&�U�,<�
��!�!�#���=�=�$�$��,��X�]�]�.�.�/�����(�*.�,�,�.�
����'�(�J�O�O�;�;?�<�<�>�;M�;M�;O�
��� 7�8�$�
���7� ��G�<>�6�6���Z�_�_�5H�%I�<�J�O�O�$7�8�	��#�#��
��z�z�|��r)rNNF)Nrr,�)r)N)rr)�)!�
__future__rr�r�r�rrrrrrr)rCrR�
Resampling�BICUBICrbrertrvrA�BILINEARr�r�r�r�r�r�r�r�r�r�r��rr�<module>r�s���&#���	�+�+�$���$X�vO+�d!&� 0� 0� 8� 8�/�:$�.�.�6�6�/�:"�,�,�4�4�D�J�#�LR�#(�"2�"2�":�":�,�.&+�%5�%5�%>�%>�
� �>�4"�,�,�4�4�C�:�S0�l<��G�<�
��"',�2r

Zerion Mini Shell 1.0