/ lib / PIL / Image.pyc
Image.pyc
   1  o

   2  Y��c�
   3  @s|ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
   4  Z
   5  ddlmZm
Z
ddlmZddlmZzddlmZWneySdZYnwddlmZmZmZmZmZmZddlmZmZmZddl m!Z!dd	l"m#Z#m$Z$d
   6  d�Z%e�&e'�Z(Gdd
�d
e)�Z*Gdd�de+�Z,e-d�Z.z ddlm/Z0ee1e0dd�kr�de1e0dd��de��Z2ee2��Wn0ey�Z3z$e#ed��Z0e4e3��5d�r�e
   7  �6de)��e4e3��5d�r�e
   8  �6e4e3�e)��dZ3[3wwe7ed�Z8zddl9Z9Wne�ydZ9Ynwdd�Z:Gdd�de�Z;Gdd�de�Z<Gd d!�d!e�Z=e=j>d"e=j?d#e=j@d#e=jAd$e=jBd%iZCGd&d'�d'e�ZDGd(d)�d)e�ZEGd*d+�d+e�ZFejGe'ZHe;e<e=eDeEeFfD]ZeD]ZIeJeHeIjKeIjL��qX�qTe7e0d,��r{e0jMZMe0jNZNe0jOZOe0jPZPe0jQZQgZRiZSiZTiZUiZViZWiZXiZYejZd-k�r�d.nd/Z[d0d1�Z\gd2�Z]d3Z^d4d5�Z_d6d7�Z`d8d9�Zad:d;�Zbdacd<d=�Zdd>d?�Zed�dAdB�Zfd�dCdD�ZgdEdF�ZhGdGdH�dH�ZidIdJ�ZjGdKdL�dL�ZkGdMdN�dN�ZlGdOdP�dP�ZmdQdR�ZndSdT�Zod�dUdV�Zpd�dXdY�Zqd�dZd[�Zrd�d\d]�Zsd^d_�Ztd`da�Zuidbdc�ddde�dfdg�dhdi�djdk�dldm�dndo�dpdq�drds�dtdu�dvdw�dxdy�dzd{�d|d}�d~d�d�d��d�d��d�d�d�e[d�fd�d�e[d�fd�i�Zvd�d��Zwd�d�d��Zxd�d��Zyd�d��Zzd�d��Z{d�d��Z|d�d��Z}d�d�d��Z~d�d��Zd�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d�d��Z�e��e��e0j��Gd�d��d�e
�Z�dS)��N)�Callable�MutableMapping)�IntEnum)�Path�)�ExifTags�	ImageMode�TiffTags�UnidentifiedImageError�__version__�_plugins)�i32le�o32be�o32le)�	deprecate)�
DeferredError�is_pathcCs�dddd�}||vrtddddd	�||Sd
   9  ddd
�}||vr5t|d||�d||���t||Sdt�d|�d�}t|��)Nrr�)�NORMAL�SEQUENCE�	CONTAINER�Image categories�
  10  �is_animatedT��plural�BILINEAR�BICUBIC�LANCZOS)ZLINEARZCUBICZ	ANTIALIASz or Resampling.zmodule 'z' has no attribute '�')r�
  11  Resampling�__name__�AttributeError)�name�
  12  categoriesZold_resampling�msg�r&��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PIL\Image.py�__getattr__?s��r(c@�eZdZdS)�DecompressionBombWarningN�r!�
  13  __module__�__qualname__r&r&r&r'r*U�r*c@r))�DecompressionBombErrorNr+r&r&r&r'r/Yr.r/iUUU)�_imaging�PILLOW_VERSIONzUThe _imaging extension was built for another version of Pillow or PIL:
  14  Core version: z
  15  Pillow version: z'The _imaging C module is not installed.zModule use of pythonz?The _imaging extension was built for another version of Python.zThe _imaging extension�pypy_version_infocCs
  16  t|d�S)z�
  17      Checks if an object is an image object.
  18  
  19      .. warning::
  20  
  21         This function is for internal use only.
  22  
  23      :param t: object to check if it's an image
  24      :returns: True if the object is an image
  25      �im)�hasattr)�tr&r&r'�isImageType�s
  26  r6c@s(eZdZdZdZdZdZdZdZdZ	dS)	�	Transposerrr����N)
  27  r!r,r-�FLIP_LEFT_RIGHT�FLIP_TOP_BOTTOM�	ROTATE_90�
  28  ROTATE_180�
  29  ROTATE_270�	TRANSPOSE�
  30  TRANSVERSEr&r&r&r'r7�sr7c@s eZdZdZdZdZdZdZdS)�	Transformrrrr8r9N)r!r,r-�AFFINE�EXTENT�PERSPECTIVE�QUAD�MESHr&r&r&r'rC�srCc@s$eZdZdZdZdZdZdZdZdS)r rr9rr:r8rN)	r!r,r-�NEAREST�BOXr�HAMMINGrrr&r&r&r'r �sr ��?��?�@g@c@�eZdZdZdZdZdZdS)�Ditherrrrr8N)r!r,r-�NONEZORDEREDZ	RASTERIZE�FLOYDSTEINBERGr&r&r&r'rP��
  31  rPc@seZdZdZdZdS)�PaletterrN)r!r,r-�WEB�ADAPTIVEr&r&r&r'rT�srTc@rO)�Quantizerrrr8N)r!r,r-�	MEDIANCUTZMAXCOVERAGE�
  32  FASTOCTREE�
LIBIMAGEQUANTr&r&r&r'rW�rSrW�DEFAULT_STRATEGY�little�<�>cCs>t�|j�}|j|jf}t|j�}|dkr||f7}||jfS�Nr)r�getmode�mode�height�width�len�bands�typestr)r3�m�shape�extrar&r&r'�_conv_type_shape�s
  33  
  34  
  35  rj)�1�CMYK�F�HSV�I�L�LAB�P�RGB�RGBA�RGBX�YCbCr)rprrrurtrl�I;16zI;16L�I;16BcC�t�|�jS)a%
  36      Gets the "base" mode for given mode.  This function returns "L" for
  37      images that contain grayscale data, and "RGB" for images that
  38      contain color data.
  39  
  40      :param mode: Input mode.
  41      :returns: "L" or "RGB".
  42      :exception KeyError: If the input mode was not a standard mode.
  43      )rr`�basemode�rar&r&r'�getmodebases
  44  r|cCry)a
  45      Gets the storage type mode.  Given a mode, this function returns a
  46      single-layer mode suitable for storing individual bands.
  47  
  48      :param mode: Input mode.
  49      :returns: "L", "I", or "F".
  50      :exception KeyError: If the input mode was not a standard mode.
  51      )rr`�basetyper{r&r&r'�getmodetypes	r~cCry)a�
  52      Gets a list of individual band names.  Given a mode, this function returns
  53      a tuple containing the names of individual bands (use
  54      :py:method:`~PIL.Image.getmodetype` to get the mode used to store each
  55      individual band.
  56  
  57      :param mode: Input mode.
  58      :returns: A tuple containing band names.  The length of the tuple
  59          gives the number of bands in an image of the given mode.
  60      :exception KeyError: If the input mode was not a standard mode.
  61      )rr`rer{r&r&r'�getmodebandnames!srcCstt�|�j�S)z�
  62      Gets the number of individual bands for this mode.
  63  
  64      :param mode: Input mode.
  65      :returns: The number of bands in this mode.
  66      :exception KeyError: If the input mode was not a standard mode.
  67      )rdrr`rer{r&r&r'�getmodebands0�r�cCs�tdkrdSzddlm}|sJ�Wn	tyYnwzddlm}|s'J�Wn	ty1Ynwzddlm}|s=J�Wn	tyGYnwzddlm}|sSJ�Wn	ty]Ynwzddlm}|siJ�WdadStyyYdadSw)z-Explicitly load standard file format drivers.rN)�BmpImagePlugin)�GifImagePlugin)�JpegImagePlugin)�PpmImagePlugin)�PngImagePlugin)�_initialized�r��ImportErrorr�r�r�r�)r�r�r�r�r�r&r&r'�preinitAsD����
  68  	��r�cCs�tdkrdStD]/}zt�d|�td|��t�t�g�Wqty7}z
t�d||�WYd}~qd}~wwts<t	r@dadSdS)zw
  69      Explicitly initializes the Python Imaging Library. This function
  70      loads all available file format drivers.
  71      rrzImporting %szPIL.zImage: failed to import %s: %sNr)
  72  r�r�logger�debug�
  73  __import__�globals�localsr��OPEN�SAVE)�plugin�er&r&r'�initos���r�r&c
  74  C�|durd}nt|t�s|f}zt|}Wn	tyYnw||g||�R�Sz	tt|d�}WntyI}zd|�d�}t|�|�d}~ww||g||�R�S)Nr&�_decoderzdecoder � not available)�
  75  isinstance�tuple�DECODERS�KeyError�getattr�corer"�OSError)ra�decoder_name�argsri�decoderr�r%r&r&r'�_getdecoder��$
  76  �
  77  ��r�c
  78  Cr�)Nr&�_encoderzencoder r�)r�r��ENCODERSr�r�r�r"r�)ra�encoder_namer�ri�encoderr�r%r&r&r'�_getencoder�r�r�cCs"tdd�t|t�r|Std|�S)N�coerce_err)rr��_E)�valuer&r&r'r��s
  79  r�c@sLeZdZdd�Zdd�Zdd�ZeZdd�Zd	d
  80  �Zdd�Z	e	Z
  81  d
d�ZdS)r�cCs||_||_dS�N)�scale�data)�selfr�r�r&r&r'�__init__�s
  82  z_E.__init__cCst|j|j�Sr�)r�r�r��r�r&r&r'�__neg__�sz
  83  _E.__neg__cCs6t|t�rt|j|j|j|j�St|j|j|�Sr�)r�r�r�r��r��otherr&r&r'�__add__�s
  84  z
  85  _E.__add__cCs
  86  ||Sr�r&r�r&r&r'�__sub__��
  87  z
  88  _E.__sub__cCs
  89  ||Sr�r&r�r&r&r'�__rsub__�r�z_E.__rsub__cCs$t|t�rtSt|j||j|�Sr��r�r��NotImplementedr�r�r�r&r&r'�__mul__��
  90  z
  91  _E.__mul__cCs$t|t�rtSt|j||j|�Sr�r�r�r&r&r'�__truediv__�r�z_E.__truediv__N)r!r,r-r�r�r��__radd__r�r�r��__rmul__r�r&r&r&r'r��sr�cCs,|tdd��}t|t�r|j|jfSd|fS�Nrr)r�r�r�r�)�expr�ar&r&r'�_getscaleoffset�sr�c@s�eZdZdZdZdZdZdd�Zdd�Ze	dd	��Z
  92  e	d
  93  d��Ze	dd
��Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd�dd�Zdd�Zdd�Zd d!�Zd"d#�Ze	d$d%��Zd&d'�Zd(d)�Zd�d+d,�Zd�d.d/�Zd�d0d1�Zd2d3�Zd4d5�Zddde j!d6fd7d8�Z"d6dd9de#j$fd:d;�Z%d<d=�Z&e&Z'd�d>d?�Z(d@dA�Z)dBdC�Z*d�dDdE�Z+dFdG�Z,dHdI�Z-dJdK�Z.d�dLdM�Z/d�dNdO�Z0dPdQ�Z1dRdS�Z2dTdU�Z3dVdW�Z4dXdY�Z5dZd[�Z6d�d]d^�Z7d_d`�Z8dadb�Z9dcdd�Z:d�dedf�Z;d�dgdh�Z<d�didj�Z=d�dldm�Z>d�dndo�Z?dpdq�Z@d�dtdu�ZAd�dvdw�ZBdxdy�ZCd�dzd{�ZDd|d}�ZEd�d~d�ZFd�d�d��ZGeHjId9dddfd�d��ZJd�d�d��ZKd�d��ZLd�d�d��ZMd�d��ZNd�d��ZOd�d��ZPeHjQd�fd�d��ZRdeHjId�dfd�d��ZSeHjId�fd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXdS)��ImageaD
  94      This class represents an image object.  To create
  95      :py:class:`~PIL.Image.Image` objects, use the appropriate factory
  96      functions.  There's hardly ever any reason to call the Image constructor
  97      directly.
  98  
  99      * :py:func:`~PIL.Image.open`
 100      * :py:func:`~PIL.Image.new`
 101      * :py:func:`~PIL.Image.frombytes`
 102      NTcCs:d|_d|_d|_d|_i|_d|_d|_d|_d|_dS)Nr��rrr)	r3ra�_size�palette�info�	_category�readonly�pyaccess�_exifr�r&r&r'r�s
 103  zImage.__init__cCs&|dkrtddddd�|jSt|��)N�categoryrrrTr)rr�r")r�r#r&r&r'r(
szImage.__getattr__cC�
 104  |jdS�Nr��sizer�r&r&r'rc�
 105  zImage.widthcCr�r_r�r�r&r&r'rbr�zImage.heightcCs|jSr�)r�r�r&r&r'r�sz
 106  Image.sizecCs`t�}||_|j|_|j|_|jdvr(|jr|j��|_nddlm}|��|_|j	��|_	|S)N�rr�PAr��ImagePalette)
 107  r�r3rar�r�r��copyr�r�r�)r�r3�newr�r&r&r'�_news
 108  
 109  z
 110  Image._newcCs|Sr�r&r�r&r&r'�	__enter__/szImage.__enter__cGs`t|d�r+t|dd�r+t|dd�r#|j|jkr|j��ttd��|_|jr+|j��d|_dS)N�fp�
_exclusive_fpF�_fp�Operation on closed image)r4r�r�r��closer�
 111  ValueError)r�r�r&r&r'�__exit__2s
 112  
 113  
 114  zImage.__exit__c
 115  Cs�z%t|dd�r|j|jkr|j��ttd��|_|jr!|j��d|_Wnty=}zt�d|�WYd}~nd}~wwt|dd�rGd|_	ttd��|_
 116  dS)a�
 117          Closes the file pointer, if possible.
 118  
 119          This operation will destroy the image core and release its memory.
 120          The image data will be unusable afterward.
 121  
 122          This function is required to close images that have multiple frames or
 123          have not had their file read and closed by the
 124          :py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for
 125          more information.
 126          r�Fr�NzError closing: %s�map)r�r�r�r�rr��	Exceptionr�r�r�r3)r�r%r&r&r'r�<s
 127  
 128  
 129  ��zImage.closecCs$|��|j��|_d|_d|_dSr�)�loadr3r�r�r�r�r&r&r'�_copy[s
 130  zImage._copycCs|jr	|��dS|��dSr�)r�r�r�r�r&r&r'�_ensure_mutableaszImage._ensure_mutablecKs�d}|rd|}|st�|�\}}t�|�n|}|�|�s"||}|��|r,|dkr4|j�|�|S|j||fi|��|S)Nr��.�PPM)	�tempfile�mkstemp�osr��endswithr�r3Zsave_ppm�save)r��file�format�options�suffix�f�filenamer&r&r'�_dumpgs
 131  �zImage._dumpcCs\|j|juo-|j|jko-|j|jko-|j|jko-|j|jko-|��|��ko-|��|��kSr�)�	__class__rar�r�r��
 132  getpalette�tobytesr�r&r&r'�__eq__}s
 133  �
 134  �
 135  �
 136  ���zImage.__eq__cCs.d|jj|jj|j|jd|jdt|�fS)Nz(<%s.%s image mode=%s size=%dx%d at 0x%X>rr)r�r,r!rar��idr�r&r&r'�__repr__�s�zImage.__repr__c	Cs2|�d|jj|jj|j|jd|jdf�dS)z"IPython plain text display supportz <%s.%s image mode=%s size=%dx%d>rrN)�textr�r,r!rar�)r��p�cycler&r&r'�
_repr_pretty_�s���zImage._repr_pretty_c
 137  CsFt��}z|�|d�W|��Sty"}zd}t|�|�d}~ww)zZiPython display hook support
 138  
 139          :returns: png version of the image as bytes
 140          �PNGz!Could not save to PNG for displayN)�io�BytesIOr�r�r��getvalue)r��br�r%r&r&r'�
 141  _repr_png_�s�
 142  ��zImage._repr_png_cCs�i}t|�\}}||d<||d<d|d<z|jdkr%|�dd�|d<W|S|��|d<W|Stye}z,t|ttf�s`zd	dl}d	d
 143  lm	}Wn	t
 144  yQY�w||j�|d�kr`t�
|��d}~ww)Nrhrfr8�versionrk�rawrpr�r)�parsez1.23)rjrar�r�r��MemoryError�RecursionError�numpy�packaging.versionrr�r�warnings�warn)r�r�rhrfr�r
 145  �
parse_versionr&r&r'�__array_interface__�s2
 146  ���
 147  ��zImage.__array_interface__cCs|j|j|j|��|��gSr�)r�rar�r�r�r�r&r&r'�__getstate__�szImage.__getstate__cCs\t�|�|\}}}}}||_||_||_t�||�|_|dvr'|r'|�|�|�	|�dS)N�rp�LArrr�)
 148  r�r�r�rar�r�r�r3�
 149  putpalette�	frombytes)r��stater�rar�r�r�r&r&r'�__setstate__�s
 150  
 151  zImage.__setstate__rc
 152  Gs�t|�dkrt|dt�r|d}|dkr|dkr|j}|��|jdks*|jdkr,dSt|j||�}|�|j	�t
 153  d|jdd�}g}	|�|�\}}}|�
|�|rVnqF|dkred	|�d
 154  �}	t|	��d�|�S)a!
 155          Return image as a bytes object.
 156  
 157          .. warning::
 158  
 159              This method returns the raw image data from the internal
 160              storage.  For compressed image data (e.g. PNG, JPEG) use
 161              :meth:`~.save`, with a BytesIO parameter for in-memory
 162              data.
 163  
 164          :param encoder_name: What encoder to use.  The default is to
 165                               use the standard "raw" encoder.
 166  
 167                               A list of C encoders can be seen under
 168                               codecs section of the function array in
 169                               :file:`_imaging.c`. Python encoders are
 170                               registered within the relevant plugins.
 171          :param args: Extra arguments to the encoder.
 172          :returns: A :py:class:`bytes` object.
 173          rrrr&�ir9Tzencoder error z in tobytes)rdr�r�rar�rcrbr��setimager3�maxr��encode�append�RuntimeError�join)
 174  r�r�r�r��bufsizer��l�s�dr%r&r&r'r��s*
 175  �
 176  z
Image.tobytes�imagecCs~|��|jdkrd}t|��|�d�}d�d|�d|jd�d��d	�d|�d
 177  |jd�d��d	�d|�d
��d	�|dg�S)a-
 178          Returns the image converted to an X11 bitmap.
 179  
 180          .. note:: This method only works for mode "1" images.
 181  
 182          :param name: The name prefix to use for the bitmap variables.
 183          :returns: A string containing an X11 bitmap.
 184          :raises ValueError: If the mode is not "1"
 185          rkznot a bitmap�xbmrz#define z_width r�
 186  �asciiz_height rzstatic char z_bits[] = {
 187  s};)r�rar�r�rr�r)r�r#r%r�r&r&r'�tobitmap
s
 188  
 189  ��zImage.tobitmapcGs�t|�dkrt|dt�r|d}|dkr|dkr|j}t|j||�}|�|j�|�|�}|ddkr:d}t|��|ddkrFd}t|��dS)z�
 190          Loads this image with pixel data from a bytes object.
 191  
 192          This method is similar to the :py:func:`~PIL.Image.frombytes` function,
 193          but loads data into this image instead of creating a new image object.
 194          rrrr&znot enough image datazcannot decode image dataN)	rdr�r�rar�rr3�decoder�)r�r�r�r�r!r r%r&r&r'r's	
 195  �zImage.frombytescCs|jdurb|jrb|jjrb|j��\}}|j�||�d|j_d|j_d|jvrL|dvrLt|jdt�r>|j�	|jdd�n	|j�
 196  |jd�d|j_n|�d�rSdnd}||j_|j�
||�|j_|jdur�tr�tr�|jrq|jSddlm}|�||j�|_|jr�|jS|j�|j�SdS)	a�
 197          Allocates storage for the image and loads the pixel data.  In
 198          normal cases, you don't need to call this method, since the
 199          Image class automatically loads an opened image when it is
 200          accessed for the first time.
 201  
 202          If the file associated with the image was opened by Pillow, then this
 203          method will close it. The exception to this is if the image has
 204          multiple frames, in which case the file will be left open for seek
 205          operations. See :ref:`file-handling` for more information.
 206  
 207          :returns: An image access object.
 208          :rtype: :ref:`PixelAccess` or :py:class:`PIL.PyAccess`
 209          Nr�transparency�rr�rtrsr)�PyAccess)r3r��dirty�getdatar�rawmoder�r��int�putpalettealpha�putpalettealphasra�
 210  startswithr��cffi�USE_CFFI_ACCESSr�r�r*r�r�Zpixel_access)r�ra�arr�palette_moder*r&r&r'r�Cs.
 211  
 212  �z
 213  Image.loadcC�dS)as
 214          Verifies the contents of a file. For data read from a file, this
 215          method attempts to determine if the file is broken, without
 216          actually decoding the image data.  If this method finds any
 217          problems, it raises suitable exceptions.  If you need to load
 218          the image after using this method, you must reopen the image
 219          file.
 220          Nr&r�r&r&r'�verifyn�	zImage.verify�c
s�|��|j�d�du}|s%|jdkr%|jr|jj}nd}|dkr%|r%d}|r.||jkr2�s2|��S�r�|dvr>d}t|��|j�|��}|�	|�}	|r�|jj
 221  dkr�|	jd�d	d
 222  ��|dkre�����nt|�dkr}t���fdd
�t
dt���D����|	jd<|	S|dkr�|jdkr�|�|�Sd}
 223  d}|�r}|jdvr�|dvs�|jdkr�|dkr�|�	|j�||jd��}|jd=|S|jdv�rJ|dv�rJ|jd}
t|
t�r�t�d�d}n�t��	t�|jd��}|jdk�r&|�|j�t|
t��r&d}z	|j�|
|�}
Wn"t�y%}zt|�dk�rd}
nt|�|�WYd}~nd}~ww|
du�r.d}
 224  nO|�d|
�|dv�r?|�|�}n|�d�}|�d�}
 225  n3|jdk�r}|dv�r}|jd}
d}t|
t��ri|j�|
�nt|
t��rw|j�|
d�nd}t|��|dk�r�|t j!k�r�|j�|�}|�	|�}	ddl"m#}|�#d|	j�$d��|	_|�r�|	jd=|
 226  du�r�z
|	j�|
 227  |	�|	jd<W|	St%�y�|	jd=t�d�Y|	Sw|	Sd|j|fv�r|jdk�r�|n|j}|dv�rdd l"m&}|�'d!�}|�'d�}|jdk�r||gn||g}|�(|d|d|j|�}|�)|�S|du�r$t*j+}z	|j�||�}Wn9t�yfzt,|j�}||jk�rB�|j�|�}|�||�}Wnt-�yc}zd}t|�|�d}~wwYnw|�	|�}|dk�r�|t j!k�r�ddl"m#}|�#dt.t
d"��d�|_|�r�|jd=|
 228  du�r�|jdk�r�z
|j�|
 229  |�|jd<W|St�y�}z|jd=t|�dk�r�t�d�WYd}~|SWYd}~|Sd}~ww|
 230  |jd<|S)#a�
 231          Returns a converted copy of this image. For the "P" mode, this
 232          method translates pixels through the palette.  If mode is
 233          omitted, a mode is chosen so that all information in the image
 234          and the palette can be represented without a palette.
 235  
 236          The current version supports all possible conversions between
 237          "L", "RGB" and "CMYK". The ``matrix`` argument only supports "L"
 238          and "RGB".
 239  
 240          When translating a color image to greyscale (mode "L"),
 241          the library uses the ITU-R 601-2 luma transform::
 242  
 243              L = R * 299/1000 + G * 587/1000 + B * 114/1000
 244  
 245          The default method of converting a greyscale ("L") or "RGB"
 246          image into a bilevel (mode "1") image uses Floyd-Steinberg
 247          dither to approximate the original image luminosity levels. If
 248          dither is ``None``, all values larger than 127 are set to 255 (white),
 249          all other values to 0 (black). To use other thresholds, use the
 250          :py:meth:`~PIL.Image.Image.point` method.
 251  
 252          When converting from "RGBA" to "P" without a ``matrix`` argument,
 253          this passes the operation to :py:meth:`~PIL.Image.Image.quantize`,
 254          and ``dither`` and ``palette`` are ignored.
 255  
 256          When converting from "PA", if an "RGBA" palette is present, the alpha
 257          channel from the image will be used instead of the values from the palette.
 258  
 259          :param mode: The requested mode. See: :ref:`concept-modes`.
 260          :param matrix: An optional conversion matrix.  If given, this
 261             should be 4- or 12-tuple containing floating point values.
 262          :param dither: Dithering method, used when converting from
 263             mode "RGB" to "P" or from "RGB" or "L" to "1".
 264             Available methods are :data:`Dither.NONE` or :data:`Dither.FLOYDSTEINBERG`
 265             (default). Note that this is not used when ``matrix`` is supplied.
 266          :param palette: Palette to use when converting from mode "RGB"
 267             to "P".  Available palettes are :data:`Palette.WEB` or
 268             :data:`Palette.ADAPTIVE`.
 269          :param colors: Number of colors to use for the :data:`Palette.ADAPTIVE`
 270             palette. Defaults to 256.
 271          :rtype: :py:class:`~PIL.Image.Image`
 272          :returns: An :py:class:`~PIL.Image.Image` object.
 273          r(Nrrrsrt)rprszillegal conversionr8cSsP|d|d|d|d|d|d|dd}tdtdt|���S)Nrrrr8rL��)r�minr.)rg�vr&r&r'�convert_transparency�s<z+Image.convert.<locals>.convert_transparencyrpc3s.�|]}��|d|dd���VqdS)r9Nr&��.0�i�r=�matrixr(r&r'�	<genexpr>�s
 274  ��
 275  �z Image.convert.<locals>.<genexpr>rF)rkrpro�rrt)rprsrrzVPalette images with Transparency expressed in bytes should be converted to RGBA imagesT�rrz2Couldn't allocate a palette color for transparencyz$cannot allocate more than 256 colorsr��rr�rtz.Transparency for P mode should be bytes or intrr�z0Couldn't allocate palette entry for transparencyrq)rsrtru)�ImageCms�sRGBr9)/r�r��getrar�r�r�r3Zconvert_matrixr�rerdr��range�quantizeZconvert_transparentr��bytesrr
r�r�r�r�getcolor�str�putpixel�convert�getpixelr0r.r/rTrVr�r�r�r�rG�
createProfile�buildTransform�applyrPrRr|r��list)r�rarB�ditherr��colorsZhas_transparencyr%r3r�ZtrnsZdelete_trns�new_imr5Ztrns_im�errr�r�Z
 276  other_moderG�srgb�lab�profiles�	transformZmodebaser&rAr'rPys$0
 277  
 278  
 279  �
 280  
 281  �
 282  
 283  �
 284  ���
 285  
 286  
 287  
 288  
 289  
 290  ��
 291  
 292  
 293  �
 294  
 295  
 296  
 297  ����
 298  
 299  ��
 300  ���
 301  	z
Image.convertrcCs|��|durtj}|jdkrtj}|jdkr&|tjtjfvr&d}t|��|r]|��|jdkr7d}t|��|jdkrG|jdkrGd}t|��|j�d||j�}|�	|�}|j
 302  ��|_
 303  |S|�	|j�|||��}d	d
 304  l
m}	|j��}
 305  |j�|
 306  |
 307  �d|t|
 308  ��}|	�|
 309  |�|_
 310  |S)a
 311          Convert the image to 'P' mode with the specified number
 312          of colors.
 313  
 314          :param colors: The desired number of colors, <= 256
 315          :param method: :data:`Quantize.MEDIANCUT` (median cut),
 316                         :data:`Quantize.MAXCOVERAGE` (maximum coverage),
 317                         :data:`Quantize.FASTOCTREE` (fast octree),
 318                         :data:`Quantize.LIBIMAGEQUANT` (libimagequant; check support
 319                         using :py:func:`PIL.features.check_feature` with
 320                         ``feature="libimagequant"``).
 321  
 322                         By default, :data:`Quantize.MEDIANCUT` will be used.
 323  
 324                         The exception to this is RGBA images. :data:`Quantize.MEDIANCUT`
 325                         and :data:`Quantize.MAXCOVERAGE` do not support RGBA images, so
 326                         :data:`Quantize.FASTOCTREE` is used by default instead.
 327          :param kmeans: Integer
 328          :param palette: Quantize to the palette of given
 329                          :py:class:`PIL.Image.Image`.
 330          :param dither: Dithering method, used when converting from
 331             mode "RGB" to "P" or from "RGB" or "L" to "1".
 332             Available methods are :data:`Dither.NONE` or :data:`Dither.FLOYDSTEINBERG`
 333             (default).
 334          :returns: A new image
 335  
 336          NrtzoFast Octree (method == 2) and libimagequant (method == 3) are the only valid methods for quantizing RGBA imagesrrzbad mode for palette imagersrpz7only RGB or L mode images can be quantized to a paletterr�)r�rWrXrarYrZr�r3rPr�r�r�rKr�r��getpalettemoder�rd)r�rW�methodZkmeansr�rVr%r3rXr�rar&r&r'rK^s<$
 337  ��
 338  
 339  
 340  zImage.quantizecCs|��|�|j���S)z�
 341          Copies this image. Use this method if you wish to paste things
 342          into an image, but still retain the original.
 343  
 344          :rtype: :py:class:`~PIL.Image.Image`
 345          :returns: An :py:class:`~PIL.Image.Image` object.
 346          )r�r�r3r�r�r&r&r'r��sz
 347  Image.copycCsd|dur|��S|d|dkrd}t|��|d|dkr$d}t|��|��|�|�|j|��S)a�
 348          Returns a rectangular region from this image. The box is a
 349          4-tuple defining the left, upper, right, and lower pixel
 350          coordinate. See :ref:`coordinate-system`.
 351  
 352          Note: Prior to Pillow 3.4.0, this was a lazy operation.
 353  
 354          :param box: The crop rectangle, as a (left, upper, right, lower)-tuple.
 355          :rtype: :py:class:`~PIL.Image.Image`
 356          :returns: An :py:class:`~PIL.Image.Image` object.
 357          Nrrz&Coordinate 'right' is less than 'left'r8rz'Coordinate 'lower' is less than 'upper')r�r�r�r��_cropr3)r��boxr%r&r&r'�crop�s
z
 358  Image.cropcCsJtttt|��\}}}}t||�t||�f}t|�|�||||f�S)a]
 359          Returns a rectangular region from the core image object im.
 360  
 361          This is equivalent to calling im.crop((x0, y0, x1, y1)), but
 362          includes additional sanity checks.
 363  
 364          :param im: a core image object
 365          :param box: The crop rectangle, as a (left, upper, right, lower)-tuple.
 366          :returns: A core image object.
 367          )r�r.�round�abs�_decompression_bomb_checkrb)r�r3ra�x0�y0�x1�y1Zabsolute_valuesr&r&r'r`�szImage._cropcCr6)aY
 368          Configures the image file loader so it returns a version of the
 369          image that as closely as possible matches the given mode and
 370          size. For example, you can use this method to convert a color
 371          JPEG to greyscale while loading it.
 372  
 373          If any changes are made, returns a tuple with the chosen ``mode`` and
 374          ``box`` with coordinates of the original image within the altered one.
 375  
 376          Note that this method modifies the :py:class:`~PIL.Image.Image` object
 377          in place. If the image has already been loaded, this method has no
 378          effect.
 379  
 380          Note: This method is not implemented for most images. It is
 381          currently implemented only for JPEG and MPO images.
 382  
 383          :param mode: The requested mode.
 384          :param size: The requested size in pixels, as a 2-tuple:
 385             (width, height).
 386          Nr&)r�rar�r&r&r'�draft�szImage.draftcCs*|dur|}|��|�|j�||d��Sr�)r�r�r3�expand)r�ZxmarginZymarginr&r&r'�_expand�sz
Image._expandc
 387  Cs�ddlm}|��t|t�r|�}t|d�sd}t|��t||j�}|jj	dks+|r4|�
 388  |�|j��Sg}t|jj	�D]}|�
|�
 389  |�|j�|����q<t|j|�S)z�
 390          Filters this image using the given filter.  For a list of
 391          available filters, see the :py:mod:`~PIL.ImageFilter` module.
 392  
 393          :param filter: Filter kernel.
 394          :returns: An :py:class:`~PIL.Image.Image` object.r)�ImageFilter�filterz>filter argument should be ImageFilter.Filter instance or class)r�rmr�r�rr4�	TypeError�MultibandFilterr3rer�rnrJr�getband�mergera)r�rnrmr%Z	multiband�ims�cr&r&r'rns
 395  
 396   zImage.filtercCst�|j�jS)z�
 397          Returns a tuple containing the name of each band in this image.
 398          For example, ``getbands`` on an RGB image returns ("R", "G", "B").
 399  
 400          :returns: A tuple containing band names.
 401          :rtype: tuple
 402          )rr`rarer�r&r&r'�getbands szImage.getbandscCs|��|j��S)aQ
 403          Calculates the bounding box of the non-zero regions in the
 404          image.
 405  
 406          :returns: The bounding box is returned as a 4-tuple defining the
 407             left, upper, right, and lower pixel coordinate. See
 408             :ref:`coordinate-system`. If the image is completely empty, this
 409             method returns None.
 410  
 411          )r�r3�getbboxr�r&r&r'rv*s
 412  z
Image.getbboxcCsh|��|jdvr.|j��}g}td�D]}||r#|�|||f�qt|�|kr,dS|S|j�|�S)a�
 413          Returns a list of colors used in this image.
 414  
 415          The colors will be in the image's mode. For example, an RGB image will
 416          return a tuple of (red, green, blue) color values, and a P image will
 417          return the index of the color in the palette.
 418  
 419          :param maxcolors: Maximum number of colors.  If this number is
 420             exceeded, this method returns None.  The default limit is
 421             256 colors.
 422          :returns: An unsorted list of (count, pixel) values.
 423          )rkrprrr9N)r�rar3�	histogramrJrrd�	getcolors)r�Z	maxcolors�h�outr@r&r&r'rx9s
 424  
 425  �zImage.getcolorscCs"|��|dur|j�|�S|jS)a�
 426          Returns the contents of this image as a sequence object
 427          containing pixel values.  The sequence object is flattened, so
 428          that values for line one follow directly after the values of
 429          line zero, and so on.
 430  
 431          Note that the sequence object returned by this method is an
 432          internal PIL data type, which only supports certain sequence
 433          operations.  To convert it to an ordinary sequence (e.g. for
 434          printing), use ``list(im.getdata())``.
 435  
 436          :param band: What band to return.  The default is to return
 437             all bands.  To return a single band, pass in the index
 438             value (e.g. 0 to get the "R" band from an "RGB" image).
 439          :returns: A sequence-like object.
 440          N)r�r3rq)r��bandr&r&r'r,Ssz
Image.getdatacCsR|��|jjdkr$g}t|jj�D]
}|�|j�|����qt|�S|j��S)a"
 441          Gets the minimum and maximum pixel values for each band in
 442          the image.
 443  
 444          :returns: For a single-band image, a 2-tuple containing the
 445             minimum and maximum pixel value.  For a multi-band image,
 446             a tuple containing one 2-tuple for each band.
 447          r)r�r3rerJrrq�
 448  getextremar�)r��extremar@r&r&r'r|js
 449  
 450  zImage.getextremacsHdd����fdd��tdurt�d�iSt�|�}�|j��|�iS)NcSs|�d�dS)N�}r)�split)�tagr&r&r'�get_name}szImage._getxmp.<locals>.get_namecs��fdd�|j��D�}t|�}|r@|D])}�|j�}�|�}||vr9t||t�s1||g||<||�|�q|||<q|S|rL|jrJ|j|d<|S|jS)Ncsi|]	\}}�|�|�qSr&r&�r?�kr<)r�r&r'�
 451  <dictcomp>�sz4Image._getxmp.<locals>.get_value.<locals>.<dictcomp>r�)�attrib�itemsrUr�r�rr�)�elementr��children�childr#Zchild_value�r��	get_valuer&r'r��s"
 452  
 453  �
 454  �z Image._getxmp.<locals>.get_valuez5XMP data cannot be read without defusedxml dependency)�ElementTreerr
�
 455  fromstringr�)r��xmp_tags�rootr&r�r'�_getxmp|s
 456  
 457  z
Image._getxmpcCs|jdurt�|_d|j_n|jjr|jSd|j_|j�d�}|durVd|jvr;t�d�|jd�d�dd���}nt	|d�rV|j
 458  j|j_|j
 459  j
|j_|j�|j|j
 460  j�|dur`|j�|�d	|jvr~|j�d
 461  �}|r~t�d|�}|r~t|d�|jd	<|jS)
NFT�exifzRaw profile type exifr�r$r8�tag_v2izXML:com.adobe.xmpztiff:Orientation(="|>)([0-9])r)r��Exif�_loadedr�rIrL�fromhexrrr4r��_bigtiff�bigtiff�_endian�endian�load_from_fpr��_offsetr��re�searchr.)r�Z	exif_infor��matchr&r&r'�getexif�s2
 462  
 463  
 464  �
 465  
 466  z
Image.getexifcCs*|jdus	|jjsdSd|j_|��dS)NF)r�r�r�r�r&r&r'�_reload_exif�szImage._reload_exifc	Cs~g}|��}g}tjj|vr-|tjj}|r-t|t�s|f}|D]}|�|�|�|f�q |�tj	j
 467  �}|rD|�d�rD|�||jj
f�d}|D]j\}}	|j��}
 468  |durW|
 469  }|j}|�d�}|dur�z||j7}Wn	tysYnw|j�|�|j�|�d��}
t�|
�}t|��}|dur�|	g|_|�d�|��|�|�Wd�n1s�wYqH|dur�|j�|�|S)Niir)r�r�Base�SubIFDsr�r�r�
_get_ifd_dict�get_ifd�IFD�IFD1rI�_info�nextr��tell�_exif_offsetr"�seek�readrr�open�
 470  _frame_pos�_seekr�)r�Zchild_imagesr�ZifdsZsubifd_offsetsZ
subifd_offsetZifd1�offset�ifd�
 471  ifd_offset�current_offsetr�Zthumbnail_offsetr�r3r&r&r'�get_child_images�sP
 472  
 473  
 474  �
 475  
 476  
 477  ��zImage.get_child_imagescCs|��|jjS)zr
 478          Returns a capsule that points to the internal image memory.
 479  
 480          :returns: A capsule object.
 481          )r�r3�ptrr�r&r&r'�getim�szImage.getimrscCsJ|��z|j��}Wn
 482  tyYdSw|dur|}t|j�||��S)aG
 483          Returns the image palette as a list.
 484  
 485          :param rawmode: The mode in which to return the palette. ``None`` will
 486             return the palette in its current mode.
 487  
 488             .. versionadded:: 9.1.0
 489  
 490          :returns: A list of color values [r, g, b, ...], or None if the
 491             image has no palette.
 492          N)r�r3r^r�rUr�)r�r-rar&r&r'r��s
�zImage.getpalettecCs�|jdks
 493  d|jvrdSddlm}|�d�}|jd}t|t�r3t|�D]\}}|||dd<q%nd	||dd<|�dt|��|_d|j_	|jd=dS)
 494  z�
 495          If a P mode image has a "transparency" key in the info dictionary,
 496          remove the key and instead apply the transparency to the palette.
 497          Otherwise, the image is unchanged.
 498          rrr(Nrr�rtr9r8r)
 499  rar�r�r�r�r�rL�	enumerater�r+)r�r�r�r(r@�alphar&r&r'�apply_transparencys
 500  
 501  
 502  �zImage.apply_transparencycCs&|��|jr
|j�|�S|j�|�S)a

 503          Returns the pixel value at a given position.
 504  
 505          :param xy: The coordinate, given as (x, y). See
 506             :ref:`coordinate-system`.
 507          :returns: The pixel value.  If the image is a multi-layer image,
 508             this method returns a tuple.
 509          )r�r�rQr3)r��xyr&r&r'rQ"s
 510  zImage.getpixelcCs&|��|j��\}}t|�t|�fS)z�
 511          Get projection to x and y axes
 512  
 513          :returns: Two sequences, indicating where there are non-zero
 514              pixels along the X-axis and the Y-axis, respectively.
 515          )r�r3�
getprojectionrU)r��x�yr&r&r'r�1szImage.getprojectioncC�T|��|r|��|j�d|j�S|jdvr%|dur|��}|j�|�S|j��S)a�
 516          Returns a histogram for the image. The histogram is returned as a
 517          list of pixel counts, one for each pixel value in the source
 518          image. Counts are grouped into 256 bins for each band, even if
 519          the image has more than 8 bits per band. If the image has more
 520          than one band, the histograms for all bands are concatenated (for
 521          example, the histogram for an "RGB" image contains 768 values).
 522  
 523          A bilevel image (mode "1") is treated as a greyscale ("L") image
 524          by this method.
 525  
 526          If a mask is provided, the method returns a histogram for those
 527          parts of the image where the mask image is non-zero. The mask
 528          image must have the same size as the image, and be either a
 529          bi-level image (mode "1") or a greyscale image ("L").
 530  
 531          :param mask: An optional mask.
 532          :param extrema: An optional tuple of manually-specified extrema.
 533          :returns: A list containing pixel counts.
 534          r��rormN)r�r3rwrar|�r��maskr}r&r&r'rw=s
 535  
 536  zImage.histogramcCr�)ah
 537          Calculates and returns the entropy for the image.
 538  
 539          A bilevel image (mode "1") is treated as a greyscale ("L")
 540          image by this method.
 541  
 542          If a mask is provided, the method employs the histogram for
 543          those parts of the image where the mask image is non-zero.
 544          The mask image must have the same size as the image, and be
 545          either a bi-level image (mode "1") or a greyscale image ("L").
 546  
 547          :param mask: An optional mask.
 548          :param extrema: An optional tuple of manually-specified extrema.
 549          :returns: A float value representing the image entropy
 550          r�r�N)r�r3�entropyrar|r�r&r&r'r�\s
 551  
 552  z
Image.entropycCs$t|�r|dur|}d}|durd}t|�dkr@t|�r |j}nt|�r(|j}nd}t|��||d|d|d|df7}t|t�rSddlm}|�||j	�}n!t|�rt|�
 553  �|j	|j	krq|j	dksk|j	d	vrq|�|j	�}|j}|�
�|r�|�
 554  �|j�|||j�dS|j�||�dS)
 555  a�
 556          Pastes another image into this image. The box argument is either
 557          a 2-tuple giving the upper left corner, a 4-tuple defining the
 558          left, upper, right, and lower pixel coordinate, or None (same as
 559          (0, 0)). See :ref:`coordinate-system`. If a 4-tuple is given, the size
 560          of the pasted image must match the size of the region.
 561  
 562          If the modes don't match, the pasted image is converted to the mode of
 563          this image (see the :py:meth:`~PIL.Image.Image.convert` method for
 564          details).
 565  
 566          Instead of an image, the source can be a integer or tuple
 567          containing pixel values.  The method then fills the region
 568          with the given color.  When creating RGB images, you can
 569          also use color strings as supported by the ImageColor module.
 570  
 571          If a mask is given, this method updates only the regions
 572          indicated by the mask. You can use either "1", "L", "LA", "RGBA"
 573          or "RGBa" images (if present, the alpha band is used as mask).
 574          Where the mask is 255, the given image is copied as is.  Where
 575          the mask is 0, the current value is preserved.  Intermediate
 576          values will mix the two images together, including their alpha
 577          channels if they have them.
 578  
 579          See :py:meth:`~PIL.Image.Image.alpha_composite` if you want to
 580          combine images with respect to their alpha channels.
 581  
 582          :param im: Source image or pixel value (integer or tuple).
 583          :param box: An optional 4-tuple giving the region to paste into.
 584             If a 2-tuple is used instead, it's treated as the upper left
 585             corner.  If omitted or None, the source is pasted into the
 586             upper left corner.
 587  
 588             If an image is given as the second argument and there is no
 589             third, the box defaults to (0, 0), and the second argument
 590             is interpreted as a mask image.
 591          :param mask: An optional mask image.
 592          Nr�rz,cannot determine region size; use 4-item boxrr��
 593  ImageColorrs)rrt�RGBa)r6rdr�r�r�rNr�r�rMrar�rPr3r��paste)r�r3rar�r�r%r�r&r&r'r�vs6($
 594  zImage.paster�c	Cst|ttf�s
d}t|��t|ttf�sd}t|��t|�dvr&d}t|��t|�dks2d}t|��t|�dkr>d}t|��t|�dkrI||j}|d	|jkrS|}n|�|�}||d|j|d
 595  |j	f}|d	|jkrr|}n|�|�}t
 596  ||�}|�||�dS)a-'In-place' analog of Image.alpha_composite. Composites an image
 597          onto this image.
 598  
 599          :param im: image to composite over this one
 600          :param dest: Optional 2 tuple (left, top) specifying the upper
 601            left corner in this (destination) image.
 602          :param source: Optional 2 (left, top) tuple for the upper left
 603            corner in the overlay source image, or 4 tuple (left, top, right,
 604            bottom) for the bounds of the source rectangle
 605  
 606          Performance Note: Not currently implemented in-place in the core layer.
 607          zSource must be a tuplezDestination must be a tuple)rr9zSource must be a 2 or 4-tuplerzDestination must be a 2-tuplerzSource must be non-negativer�rN)r�rUr�r�rdr;r�rbrcrb�alpha_compositer�)	r�r3�dest�sourcer%�overlayra�
 608  background�resultr&r&r'r��s4
 609  
 610   
 611  
 612  zImage.alpha_compositecs�|��t�t�r��|�St��r6|jdvr't��\}}|�|j�	||��S�fdd�t
 613  d�D�|jj�|jdkrAd}t|��|dkrLdd��D��|�|j��|��S)a�
 614          Maps this image through a lookup table or function.
 615  
 616          :param lut: A lookup table, containing 256 (or 65536 if
 617             self.mode=="I" and mode == "L") values per band in the
 618             image.  A function can be used instead, it should take a
 619             single argument. The function is called once for each
 620             possible pixel value, and the resulting table is applied to
 621             all bands of the image.
 622  
 623             It may also be an :py:class:`~PIL.Image.ImagePointHandler`
 624             object::
 625  
 626                 class Example(Image.ImagePointHandler):
 627                   def point(self, data):
 628                     # Return result
 629          :param mode: Output mode (default is same as input).  In the
 630             current version, this can only be used if the source image
 631             has mode "L" or "P", and the output has mode "1" or the
 632             source image mode is "I" and the output mode is "L".
 633          :returns: An :py:class:`~PIL.Image.Image` object.
 634          )rorwrmcsg|]}�|��qSr&r&r>��lutr&r'�
 635  <listcomp> �zImage.point.<locals>.<listcomp>r9rmz+point operation not supported for this modecSsg|]}t|��qSr&)rcr>r&r&r'r�(r�)
r�r��ImagePointHandler�point�callablerar�r�r3Zpoint_transformrJrer�)r�r�rar�r�r%r&r�r'r��s
 636  
 637  
 638  
 639  zImage.pointc
 640  CsV|��|jdvr\z?t|j�d}z|j�|�Wn%ttfy>}z|j�|�}|jdvr1t|�||_WYd}~nd}~wwd|_|jj|_Wnt	y[}zd}t|�|�d}~ww|jdvrdd}nd}t
 641  |�r�|jdvrud}t|��|��|jd	kr�|�d
 642  �}nz
 643  |j�||�WdSttfy�t
d
 644  |j|�}Ynw|j�|j|�dS)az
 645          Adds or replaces the alpha layer in this image.  If the image
 646          does not have an alpha layer, it's converted to "LA" or "RGBA".
 647          The new layer must be either "L" or "1".
 648  
 649          :param alpha: The new alpha layer.  This can either be an "L" or "1"
 650             image having the same size as this image, or an integer or
 651             other color value.
 652          rF�AN�illegal image moder)rr8)rkrprkrp)r�rar|r3�setmoder"r�rPr�r�r6r��fillbandr�r��putband)r�r�rar�r3r%r{r&r&r'�putalpha+sL
 653  
 654  ��
 655  ��
 656  
 657  
 658  
 659  ���zImage.putalpharM�cCs|��|j�|||�dS)a|
 660          Copies pixel data from a flattened sequence object into the image. The
 661          values should start at the upper left corner (0, 0), continue to the
 662          end of the line, followed directly by the first value of the second
 663          line, and so on. Data will be read until either the image or the
 664          sequence ends. The scale and offset values are used to adjust the
 665          sequence values: **pixel = value*scale + offset**.
 666  
 667          :param data: A flattened sequence object.
 668          :param scale: An optional scale value.  The default is 1.0.
 669          :param offset: An optional offset value.  The default is 0.0.
 670          N)r�r3�putdata)r�r�r�r�r&r&r'r�csz
Image.putdatacCs�ddlm}|jdvrd}t|��t||j�r |�|j|j�}nt|t�s)t|�}|�||�}d|jvr6dnd|_||_d|j_|�	�d	S)
 671  a}
 672          Attaches a palette to this image.  The image must be a "P", "PA", "L"
 673          or "LA" image.
 674  
 675          The palette sequence must contain at most 256 colors, made up of one
 676          integer value for each channel in the raw mode.
 677          For example, if the raw mode is "RGB", then it can contain at most 768
 678          values, made up of red, green and blue values for the corresponding pixel
 679          index in the 256 colors.
 680          If the raw mode is "RGBA", then it can contain at most 1024 values,
 681          containing red, green, blue and alpha values.
 682  
 683          Alternatively, an 8-bit string may be used instead of an integer sequence.
 684  
 685          :param data: A palette sequence (either a list or a string).
 686          :param rawmode: The raw mode of the palette. Either "RGB", "RGBA", or a mode
 687             that can be transformed to "RGB" or "RGBA" (e.g. "R", "BGR;15", "RGBA;L").
 688          rr�rr�r�r�rrrsN)
 689  r�r�rar�r�rr-r�rLr�)r�r�r-r�r%r�r&r&r'rus
 690  
 691  zImage.putpalettecCs�|jr|��|��|jr|j�||�S|jdvrNt|ttf�rNt	|�dvrN|jdkr>t	|�dkr6|dnd}|dd�}|j
 692  �||�}|jdkrN||f}|j�||�S)a�
 693          Modifies the pixel at the given position. The color is given as
 694          a single numerical value for single-band images, and a tuple for
 695          multi-band images. In addition to this, RGB and RGBA tuples are
 696          accepted for P and PA images.
 697  
 698          Note that this method is relatively slow.  For more extensive changes,
 699          use :py:meth:`~PIL.Image.Image.paste` or the :py:mod:`~PIL.ImageDraw`
 700          module instead.
 701  
 702          See:
 703  
 704          * :py:meth:`~PIL.Image.Image.paste`
 705          * :py:meth:`~PIL.Image.Image.putdata`
 706          * :py:mod:`~PIL.ImageDraw`
 707  
 708          :param xy: The pixel coordinate, given as (x, y). See
 709             :ref:`coordinate-system`.
 710          :param value: The pixel value.
 711          r��r8r9r�r9r8r:N)
r�r�r�r�rOrar�rUr�rdr�rMr3)r�r�r�r�r&r&r'rO�s 
 712  �
 713  
 714  zImage.putpixelc
Cs�ddlm}|jdvrd}t|��d}d}|dur@|jdkr5|��|j��}|d	kr-d
 715  }|j�||�}ntdd�t	d
�D��}d}dgd}t
 716  |�D]\}	}
 717  |||
 718  ||
 719  ||�7}|	||
 720  <qKt|�}|��}d|_|j|||d�|_|j�
|d|j���|�d�}|�
||�|j||d�|_d|jvr�z|�|jd�|jd<W|Sty�d|jvr�|jd=Y|SY|Sw|S)ae
 721          Rewrites the image to reorder the palette.
 722  
 723          :param dest_map: A list of indexes into the original palette.
 724             e.g. ``[1,0]`` would swap a two item palette, and ``list(range(256))``
 725             is the identity transform.
 726          :param source_palette: Bytes or None.
 727          :returns:  An :py:class:`~PIL.Image.Image` object.
 728  
 729          rr�)rprrr�r8rsNrrrtr9css�|]}|dVqdS)r8Nr&r>r&r&r'rC�s�z&Image.remap_palette.<locals>.<genexpr>irrr9)r�z;Lrpr()r�r�rar�r�r3r^r��	bytearrayrJr�r�r�rr�rPr��index)
r�Zdest_map�source_paletter�r%rer5�
palette_bytes�
new_positionsr@ZoldPositionZmapping_paletteZm_imr&r&r'�
remap_palette�sV
 730  
 731  
 732  
 733  �
 734  �
 735  
 736  �
 737  
 738  ��zImage.remap_palettec		Cs�t|d}|d|d|d}|d|d|d}||}||}tdt|d|��tdt|d|��t|jdt�|d|��t|jdt�|d|��fS)z�Expands the box so it includes adjacent pixels
 739          that may be used by resampling with the given resampling filter.
 740          rLrrr8r)�_filters_supportrr.r;r��math�ceil)	r�r��resampleraZfilter_supportZscale_xZscale_yZ	support_xZ	support_yr&r&r'�
_get_safe_boxs�zImage._get_safe_boxc
Cs�|durd|jv}|rtjntj}nL|tjtjtjtjtjtjfvr^d|�d�}dd�tjdftjdftjd	ftjd
 741  ftjdftjdffD�}|d
d�|dd��d|d7}t	|��|durl|dkrld}t	|��t
 742  |�}|��|dur~d|j}nt
 743  |�}|j|kr�|d|jkr�|�
�S|jdvr�tj}|jdvr�|tjkr�|�ddd�|j�}|�|||�}|�|j�S|��|du�r?|tjk�r?t|d|d|d|�p�d}	t|d|d|d|�p�d}
 744  |	dks�|
 745  dk�r?|�|||�}|	|
 746  f}t|j��r|j||d�}ntj|||d�}|d|d|	|d|d|
 747  |d|d|	|d|d|
 748  f}|�|j�|||��S)aJ
 749          Returns a resized copy of this image.
 750  
 751          :param size: The requested size in pixels, as a 2-tuple:
 752             (width, height).
 753          :param resample: An optional resampling filter.  This can be
 754             one of :py:data:`Resampling.NEAREST`, :py:data:`Resampling.BOX`,
 755             :py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`,
 756             :py:data:`Resampling.BICUBIC` or :py:data:`Resampling.LANCZOS`.
 757             If the image has mode "1" or "P", it is always set to
 758             :py:data:`Resampling.NEAREST`. If the image mode specifies a number
 759             of bits, such as "I;16", then the default filter is
 760             :py:data:`Resampling.NEAREST`. Otherwise, the default filter is
 761             :py:data:`Resampling.BICUBIC`. See: :ref:`concept-filters`.
 762          :param box: An optional 4-tuple of floats providing
 763             the source image region to be scaled.
 764             The values must be within (0, 0, width, height) rectangle.
 765             If omitted or None, the entire source is used.
 766          :param reducing_gap: Apply optimization by resizing the image
 767             in two steps. First, reducing the image by integer times
 768             using :py:meth:`~PIL.Image.Image.reduce`.
 769             Second, resizing using regular resampling. The last step
 770             changes size no less than by ``reducing_gap`` times.
 771             ``reducing_gap`` may be None (no first step is performed)
 772             or should be greater than 1.0. The bigger ``reducing_gap``,
 773             the closer the result to the fair resampling.
 774             The smaller ``reducing_gap``, the faster resizing.
 775             With ``reducing_gap`` greater or equal to 3.0, the result is
 776             indistinguishable from fair resampling in most cases.
 777             The default value is None (no optimization).
 778          :returns: An :py:class:`~PIL.Image.Image` object.
 779          N�;�Unknown resampling filter (�).cS�$g|]}|d�d|d�d��qS�r� (r�)r&�r?rnr&r&r'r�X���z Image.resize.<locals>.<listcomp>�Image.Resampling.NEAREST�Image.Resampling.LANCZOS�Image.Resampling.BILINEAR�Image.Resampling.BICUBIC�Image.Resampling.BOX�Image.Resampling.HAMMING� Use �, ������ or rMz#reducing_gap must be 1.0 or greaterr��rkrrrD�Lar�rrrr8)ra)rar rIrrrrJrKrr�r�r�r�r�rP�resizer.r�r��reducer�r�r3)
r�r�r�ra�reducing_gapZtype_specialr%�filtersr3Zfactor_xZfactor_yZ
 780  reduce_box�factorr&r&r'r�)sn"
 781  ���&
 782  $$�zImage.resizecCs�t|ttf�s||f}|durd|j}nt|�}|dkr(|d|jkr(|��S|jdvrD|�ddd�|j�}|�||�}|�|j�S|��|�	|j
 783  �||��S)a!
 784          Returns a copy of the image reduced ``factor`` times.
 785          If the size of the image is not dividable by ``factor``,
 786          the resulting size will be rounded up.
 787  
 788          :param factor: A greater than 0 integer or tuple of two integers
 789             for width and height separately.
 790          :param box: An optional 4-tuple of ints providing
 791             the source image region to be reduced.
 792             The values must be within ``(0, 0, width, height)`` rectangle.
 793             If omitted or ``None``, the entire source is used.
 794          Nr�rErDr�r�)r�rUr�r�r�rarPr�r�r�r3)r�rrar3r&r&r'r��s

 795  zImage.reducecCs0|d}|s4|s4|dkr|��S|dkr|�tj�S|dvr4|s&|j|jkr4|�|dkr0tj�Stj�S|j\}}|dur@d}	n|}	|durO|d|df}
 796  n|}
 797  t	�
 798  |�}tt	�|�d	�tt	�
|�d	�d
 799  tt	�
|�d	�tt	�|�d	�d
 800  g}dd�}||
 801  d|	d|
 802  d
|	d
|�\|d<|d<|d|
 803  d7<|d|
 804  d
7<|�rg}
g}d|df||fd|ffD]\}}||||�\}}|
�|�|�|�q�t	�t|
��t	�t|
��}t	�t|��t	�t|��}|||d||d|�\|d<|d<||}}|j||ftj|||d�S)a�
 805          Returns a rotated copy of this image.  This method returns a
 806          copy of this image, rotated the given number of degrees counter
 807          clockwise around its centre.
 808  
 809          :param angle: In degrees counter clockwise.
 810          :param resample: An optional resampling filter.  This can be
 811             one of :py:data:`Resampling.NEAREST` (use nearest neighbour),
 812             :py:data:`Resampling.BILINEAR` (linear interpolation in a 2x2
 813             environment), or :py:data:`Resampling.BICUBIC` (cubic spline
 814             interpolation in a 4x4 environment). If omitted, or if the image has
 815             mode "1" or "P", it is set to :py:data:`Resampling.NEAREST`.
 816             See :ref:`concept-filters`.
 817          :param expand: Optional expansion flag.  If true, expands the output
 818             image to make it large enough to hold the entire rotated image.
 819             If false or omitted, make the output image the same size as the
 820             input image.  Note that the expand flag assumes rotation around
 821             the center and no translation.
 822          :param center: Optional center of rotation (a 2-tuple).  Origin is
 823             the upper left corner.  Default is the center of the image.
 824          :param translate: An optional post-rotate translation (a 2-tuple).
 825          :param fillcolor: An optional color for area outside the rotated image.
 826          :returns: An :py:class:`~PIL.Image.Image` object.
 827          g�v@r�)�ZirNr�rN�r�c	Ss8|\}}}}}}||||||||||fSr�r&)	r�r�rBr�rrtr!r�r�r&r&r'r]	s(zImage.rotate.<locals>.transformrrr:)�	fillcolor)r��	transposer7r?rcrbr>r@r�r��radiansrc�cos�sinrr�r�floorr;r]rCrD)r��angler�rk�center�	translater�wryZ
 828  post_transZrotn_centerrBr]�xx�yyr�r��nwZnhr&r&r'�rotate�s^"��
 829  �	"� 
 830  ,
 831  �zImage.rotatecKs�d}d}t|t�rt|�}d}nt|�r|}d}n|tjkr.ztjj}Wn	ty-Ynw|s=t|d�r=t|j	�r=|j	}|�
 832  �|�dd�}||_d|_
t�tj�|�d��}|s�|tvrct�zt|}Wnty}z
 833  d|��}	t|	�|�d	}~ww|��tvr�t�|r�t|��}
 834  nt|��}
 835  d}|r�tj�|�}|�d
 836  d�r�t�|d�}nt�|d�}z|
 837  |||�Wn!ty�|r�|��|r�zt� |�W�t!y�Y�w�w|r�|��d	Sd	S)
a�
 838          Saves this image under the given filename.  If no format is
 839          specified, the format to use is determined from the filename
 840          extension, if possible.
 841  
 842          Keyword options can be used to provide additional instructions
 843          to the writer. If a writer doesn't recognise an option, it is
 844          silently ignored. The available options are described in the
 845          :doc:`image format documentation
 846          <../handbook/image-file-formats>` for each writer.
 847  
 848          You can use a file object instead of a filename. In this case,
 849          you must always specify the format. The file object must
 850          implement the ``seek``, ``tell``, and ``write``
 851          methods, and be opened in binary mode.
 852  
 853          :param fp: A filename (string), pathlib.Path object or file object.
 854          :param format: Optional format override.  If omitted, the
 855             format to use is determined from the filename extension.
 856             If a file object was used instead of a filename, this
 857             parameter should always be used.
 858          :param params: Extra parameters to the image writer.
 859          :returns: None
 860          :exception ValueError: If the output format could not be determined
 861             from the file name.  Use the format option to solve this.
 862          :exception OSError: If the file could not be written.  The file
 863             may have been created, and may contain partial data.
 864          r�FTr#�save_allr&rzunknown file extension: Nrzr+bzw+b)"r�rrNr�sys�stdout�bufferr"r4r#r��pop�encoderinfo�
encoderconfigr�r��path�splitext�lower�	EXTENSIONr�r�r��upperr��SAVE_ALL�existsrI�builtinsr�r�r��remove�PermissionError)r�r�r��paramsr�Zopen_fpr�extr�r%Zsave_handler�createdr&r&r'r�*	sz
 865  
 866  �
 867  
 868  �����	�z
 869  Image.savecCs|dkrt�dS)a0
 870          Seeks to the given frame in this sequence file. If you seek
 871          beyond the end of the sequence, the method raises an
 872          ``EOFError`` exception. When a sequence file is opened, the
 873          library automatically seeks to frame 0.
 874  
 875          See :py:meth:`~PIL.Image.Image.tell`.
 876  
 877          If defined, :attr:`~PIL.Image.Image.n_frames` refers to the
 878          number of available frames.
 879  
 880          :param frame: Frame number, starting at 0.
 881          :exception EOFError: If the call attempts to seek beyond the end
 882              of the sequence.
 883          rN)�EOFError)r��framer&r&r'r��	s�z
 884  Image.seekcCst||d�dS)a�
 885          Displays this image. This method is mainly intended for debugging purposes.
 886  
 887          This method calls :py:func:`PIL.ImageShow.show` internally. You can use
 888          :py:func:`PIL.ImageShow.register` to override its default behaviour.
 889  
 890          The image is first saved to a temporary file. By default, it will be in
 891          PNG format.
 892  
 893          On Unix, the image is then opened using the **display**, **eog** or
 894          **xv** utility, depending on which one can be found.
 895  
 896          On macOS, the image is opened with the native Preview application.
 897  
 898          On Windows, the image is opened with the standard PNG display utility.
 899  
 900          :param title: Optional title to use for the image window, where possible.
 901          )�titleN)�_show)r�r)r&r&r'�show�	sz
 902  Image.showcCs@|��|jjdkr|��g}t|�St|j|j���}t|�S)a�
 903          Split this image into individual bands. This method returns a
 904          tuple of individual image bands from an image. For example,
 905          splitting an "RGB" image creates three new images each
 906          containing a copy of one of the original bands (red, green,
 907          blue).
 908  
 909          If you need only one band, :py:meth:`~PIL.Image.Image.getchannel`
 910          method can be more convenient and faster.
 911  
 912          :returns: A tuple containing bands.
 913          r)r�r3rer�r�r�rr�)r�rsr&r&r'r�	s
 914  �zImage.splitc
 915  Csf|��t|t�r*z	|���|�}Wnty)}zd|�d�}t|�|�d}~ww|�|j�|��S)a@
 916          Returns an image containing a single channel of the source image.
 917  
 918          :param channel: What channel to return. Could be index
 919            (0 for "R" channel of "RGB") or channel name
 920            ("A" for alpha channel of "RGBA").
 921          :returns: An image in "L" mode.
 922  
 923          .. versionadded:: 4.3.0
 924          zThe image has no channel "�"N)	r�r�rNrur�r�r�r3rq)r��channelr�r%r&r&r'�
 925  getchannel�	s
 926  
 927  ��zImage.getchannelcCr6)z�
 928          Returns the current frame number. See :py:meth:`~PIL.Image.Image.seek`.
 929  
 930          If defined, :attr:`~PIL.Image.Image.n_frames` refers to the
 931          number of available frames.
 932  
 933          :returns: Frame number, starting with 0.
 934          rr&r�r&r&r'r��	r8z
 935  Image.tellrNcs�tttj|�����fdd�}d}|dur6|�}|durdS��d|d||d|f�}|dur6|d}|durG���|�}|durGdS�j|kra�j||||d�}|j�_|�_	�jj
 936  �_
 937  d�_d�_dS)an
 938          Make this image into a thumbnail.  This method modifies the
 939          image to contain a thumbnail version of itself, no larger than
 940          the given size.  This method calculates an appropriate thumbnail
 941          size to preserve the aspect of the image, calls the
 942          :py:meth:`~PIL.Image.Image.draft` method to configure the file reader
 943          (where applicable), and finally resizes the image.
 944  
 945          Note that this function modifies the :py:class:`~PIL.Image.Image`
 946          object in place.  If you need to use the full resolution image as well,
 947          apply this method to a :py:meth:`~PIL.Image.Image.copy` of the original
 948          image.
 949  
 950          :param size: The requested size in pixels, as a 2-tuple:
 951             (width, height).
 952          :param resample: Optional resampling filter.  This can be one
 953             of :py:data:`Resampling.NEAREST`, :py:data:`Resampling.BOX`,
 954             :py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`,
 955             :py:data:`Resampling.BICUBIC` or :py:data:`Resampling.LANCZOS`.
 956             If omitted, it defaults to :py:data:`Resampling.BICUBIC`.
 957             (was :py:data:`Resampling.NEAREST` prior to version 2.5.0).
 958             See: :ref:`concept-filters`.
 959          :param reducing_gap: Apply optimization by resizing the image
 960             in two steps. First, reducing the image by integer times
 961             using :py:meth:`~PIL.Image.Image.reduce` or
 962             :py:meth:`~PIL.Image.Image.draft` for JPEG images.
 963             Second, resizing using regular resampling. The last step
 964             changes size no less than by ``reducing_gap`` times.
 965             ``reducing_gap`` may be None (no first step is performed)
 966             or should be greater than 1.0. The bigger ``reducing_gap``,
 967             the closer the result to the fair resampling.
 968             The smaller ``reducing_gap``, the faster resizing.
 969             With ``reducing_gap`` greater or equal to 3.0, the result is
 970             indistinguishable from fair resampling in most cases.
 971             The default value is 2.0 (very close to fair resampling
 972             while still being faster in many cases).
 973          :returns: None
 974          cs�dd�}�\����jkr��jkrdS�j�j����kr1|����fdd�d����fS|����fdd�d����fS)NcSs ttt�|�t�|�|d�d�S)N��keyr)rr;r�r
 975  r�)�numberr0r&r&r'�round_aspect
 976  s zDImage.thumbnail.<locals>.preserve_aspect_ratio.<locals>.round_aspectcst�|��Sr��rd��n)�aspectr�r&r'�<lambda>!
 977  sz@Image.thumbnail.<locals>.preserve_aspect_ratio.<locals>.<lambda>r/cs|dkrdSt��|�Sr�r3r4)r6r�r&r'r7$
 978  �)rcrb)r2�Z
provided_sizer�)r6r�r�r'�preserve_aspect_ratio
 979  s��z.Image.thumbnail.<locals>.preserve_aspect_ratioNrr)rar�)
r�r�r�r
 980  rjr�r�r�r3r�rar�r�)r�r�r�r�r:ra�resr3r&r9r'�	thumbnail�	s,( 
 981  
 982  
 983  zImage.thumbnailrc
 984  Cs|jdvr!|tjkr!|�ddd�|j��||||||��|j�St|t�r/|j||||d�St|d�r:|��\}}|durDd}t	|��t
 985  |j||�}|jdkrY|jrY|j��|_|j
��|_
|tjkrz|D]\}	}
 986  |�|	|tj|
 987  ||du�qf|S|�d	||||||du�|S)
 988  a�
 989          Transforms this image.  This method creates a new image with the
 990          given size, and the same mode as the original, and copies data
 991          to the new image using the given transform.
 992  
 993          :param size: The output size in pixels, as a 2-tuple:
 994             (width, height).
 995          :param method: The transformation method.  This is one of
 996            :py:data:`Transform.EXTENT` (cut out a rectangular subregion),
 997            :py:data:`Transform.AFFINE` (affine transform),
 998            :py:data:`Transform.PERSPECTIVE` (perspective transform),
 999            :py:data:`Transform.QUAD` (map a quadrilateral to a rectangle), or
1000            :py:data:`Transform.MESH` (map a number of source quadrilaterals
1001            in one operation).
1002  
1003            It may also be an :py:class:`~PIL.Image.ImageTransformHandler`
1004            object::
1005  
1006              class Example(Image.ImageTransformHandler):
1007                  def transform(self, size, data, resample, fill=1):
1008                      # Return result
1009  
1010            It may also be an object with a ``method.getdata`` method
1011            that returns a tuple supplying new ``method`` and ``data`` values::
1012  
1013              class Example:
1014                  def getdata(self):
1015                      method = Image.Transform.EXTENT
1016                      data = (0, 0, 100, 100)
1017                      return method, data
1018          :param data: Extra data to the transformation method.
1019          :param resample: Optional resampling filter.  It can be one of
1020             :py:data:`Resampling.NEAREST` (use nearest neighbour),
1021             :py:data:`Resampling.BILINEAR` (linear interpolation in a 2x2
1022             environment), or :py:data:`Resampling.BICUBIC` (cubic spline
1023             interpolation in a 4x4 environment). If omitted, or if the image
1024             has mode "1" or "P", it is set to :py:data:`Resampling.NEAREST`.
1025             See: :ref:`concept-filters`.
1026          :param fill: If ``method`` is an
1027            :py:class:`~PIL.Image.ImageTransformHandler` object, this is one of
1028            the arguments passed to it. Otherwise, it is unused.
1029          :param fillcolor: Optional fill color for the area outside the
1030             transform in the output image.
1031          :returns: An :py:class:`~PIL.Image.Image` object.
1032          rDr�r�)r��fillr,Nzmissing method datarrr�)rar rIrPr]r��ImageTransformHandlerr4r,r�r�r�r�r�rCrH�_Image__transformerrG)r�r�r_r�r�r=rr%r3ra�quadr&r&r'r]E
1033  s47�
1034  
1035  
1036  ���zImage.transformc
1037  Csj|d|d}|d|d}|tjkr|dd�}n�|tjkr?|\}	}
1038  }}||	|}
||
1039  |}tj}|
d|	d||
1040  f}n~|tjkrK|dd�}nr|tjkr�|dd�}|dd�}|dd�}|dd�}|\}	}
1041  d|}d|}|	|d|	||d|	||d|d|d|	|||
1042  |d|
1043  ||d|
1044  ||d|d|d|
1045  ||f}nd	}t|��|tjtjtj	fv�r|tj
1046  tjtjfvr�tj
1047  d
1048  tjdtjdi|d
|�d�}nd|�d�}dd�tjdftjdftj	dffD�}|dd�
|dd��d|d7}t|��|��|��|jdv�r'tj}|j�||j||||�dS)Nrrr8rr;�r9rMzunknown transformation methodr�r�r�r�z) cannot be used.r�r�cSr�r�r&r�r&r&r'r��
1049  r�z'Image.__transformer.<locals>.<listcomp>r�r�r�r�r�r�r�r�)rCrDrErFrGr�r rIrrrJrKrrr�rar3Z
1050  transform2)r�rar"r_r�r�r=rryrfrgrhri�xs�ysr�sw�se�ne�AsZAtr%rr&r&r'Z
__transformer�
1051  sv
1052  
1053  
1054  
1055  ""����
1056  ���&zImage.__transformercC�|��|�|j�|��S)a�
1057          Transpose image (flip or rotate in 90 degree steps)
1058  
1059          :param method: One of :py:data:`Transpose.FLIP_LEFT_RIGHT`,
1060            :py:data:`Transpose.FLIP_TOP_BOTTOM`, :py:data:`Transpose.ROTATE_90`,
1061            :py:data:`Transpose.ROTATE_180`, :py:data:`Transpose.ROTATE_270`,
1062            :py:data:`Transpose.TRANSPOSE` or :py:data:`Transpose.TRANSVERSE`.
1063          :returns: Returns a flipped or rotated copy of this image.
1064          )r�r�r3r)r�r_r&r&r'r�
1065  szImage.transposecCrH)zj
1066          Randomly spread pixels in an image.
1067  
1068          :param distance: Distance to spread pixels.
1069          )r�r�r3�
effect_spread)r��distancer&r&r'rI�
1070  szImage.effect_spreadcC�(ddlm}|jsd}t|��|�|�S)z#Returns a QImage copy of this imager��ImageQt�Qt bindings are not installed)r�rM�qt_is_installedr��toqimage�r�rMr%r&r&r'rP�
1071  
1072  zImage.toqimagecCrK)z$Returns a QPixmap copy of this imagerrLrN)r�rMrOr��	toqpixmaprQr&r&r'rSrRzImage.toqpixmap)NN�r)r"r�)r9)rs)r�r�)rMr�)NNN)Yr!r,r-�__doc__r��format_description�!_close_exclusive_fp_after_loadingr�r(�propertyrcrbr�r�r�r�r�r�r�r�r�r�r�rrrrr�r&rr�r7rTrUrPrPrRrKr��__copy__rbr`rjrlrnrurvrxr,r|r�r�r�r�r�r�r�rQr�rwr�r�r�r�r�r�rrOr�r�r�r�r rIrr�r�r+rr.r�rr<r]r?rrIrPrSr&r&r&r'r��s�

1073  
1074  
1075  
1076  
1077  
1078  
1079  
1080  
1081  4
1082  +
1083  �h
1084  �O
1085  
1086  
1087  
1088  
1089  +
1090  
1091  
1092  
1093  
1094  
1095  Q
1096  31
1097  8
1098  #
1099  +U
1100  
1101  i$
11021103  wb
1104  \
1105  �[
1106  �O		r�c@�eZdZdZdS)r�zb
1107      Used as a mixin by point transforms
1108      (for use with :py:meth:`~PIL.Image.Image.point`)
1109      N�r!r,r-rUr&r&r&r'r��r�c@rZ)r>zi
1110      Used as a mixin by geometry transforms
1111      (for use with :py:meth:`~PIL.Image.Image.transform`)
1112      Nr[r&r&r&r'r>%r\r>cCst��t�d��S)z+Create greyscale wedge (for debugging only)rp)r�r�r��wedger&r&r&r'�_wedge5sr^cCsZt|ttf�s
d}t|��t|�dkrd}t|��|ddks%|ddkr+d}t|��dS)z�
1113      Common check to enforce type and sanity check on size tuples
1114  
1115      :param size: Should be a 2 tuple of (width, height)
1116      :returns: True, or raises a ValueError
1117      zSize must be a tuplerz Size must be a tuple of length 2rrzWidth and height must be >= 0T)r�rUr�r�rd)r�r%r&r&r'�_check_size;sr_cCs�t|�|durt��t�||��St|t�r#ddlm}|�	||�}t�}|dkrHt|t
1118  tf�rHt|�dvrHddlm
}|�
�|_|j�	|�}|�t�|||��S)a�
1119      Creates a new image with the given mode and size.
1120  
1121      :param mode: The mode to use for the new image. See:
1122         :ref:`concept-modes`.
1123      :param size: A 2-tuple, containing (width, height) in pixels.
1124      :param color: What color to use for the image.  Default is black.
1125         If given, this should be a single integer or floating point value
1126         for single-band modes, and a tuple for multi-band modes (one value
1127         per band).  When creating RGB images, you can also use color
1128         strings as supported by the ImageColor module.  If the color is
1129         None, the image is not initialised.
1130      :returns: An :py:class:`~PIL.Image.Image` object.
1131      Nrr�rrr�r�)r_r�r�r�r�r�rNr�r�rMrUr�rdr�r�r=)rar��colorr�r3r�r&r&r'r�Ps
1132  "
1133  r�rcGsZt|�t|�dkrt|dt�r|d}|dkr|dkr|}t||�}|�|||�|S)a�
1134      Creates a copy of an image memory from pixel data in a buffer.
1135  
1136      In its simplest form, this function takes three arguments
1137      (mode, size, and unpacked pixel data).
1138  
1139      You can also use any pixel decoder supported by PIL. For more
1140      information on available decoders, see the section
1141      :ref:`Writing Your Own File Codec <file-codecs>`.
1142  
1143      Note that this function decodes pixel data only, not entire images.
1144      If you have an entire image in a string, wrap it in a
1145      :py:class:`~io.BytesIO` object, and use :py:func:`~PIL.Image.open` to load
1146      it.
1147  
1148      :param mode: The image mode. See: :ref:`concept-modes`.
1149      :param size: The image size.
1150      :param data: A byte buffer containing raw data for the given mode.
1151      :param decoder_name: What decoder to use.
1152      :param args: Additional parameters for the given decoder.
1153      :returns: An :py:class:`~PIL.Image.Image` object.
1154      rrrr&)r_rdr�r�r�r)rar�r�r�r�r3r&r&r'rws
1155  rc	Gs�t|�t|�dkrt|dt�r|d}|dkrS|dkr"|ddf}|dtvrSt|d�}|�t�|||d|��}|dkrNddl	m
1156  }|�
1157  d|j�d��|_
d|_|St|||||�S)	a�
1158      Creates an image memory referencing pixel data in a byte buffer.
1159  
1160      This function is similar to :py:func:`~PIL.Image.frombytes`, but uses data
1161      in the byte buffer, where possible.  This means that changes to the
1162      original buffer object are reflected in this image).  Not all modes can
1163      share memory; supported modes include "L", "RGBX", "RGBA", and "CMYK".
1164  
1165      Note that this function decodes pixel data only, not entire images.
1166      If you have an entire image file in a string, wrap it in a
1167      :py:class:`~io.BytesIO` object, and use :py:func:`~PIL.Image.open` to load it.
1168  
1169      In the current version, the default parameters used for the "raw" decoder
1170      differs from that used for :py:func:`~PIL.Image.frombytes`.  This is a
1171      bug, and will probably be fixed in a future release.  The current release
1172      issues a warning if you do this; to disable the warning, you should provide
1173      the full set of parameters.  See below for details.
1174  
1175      :param mode: The image mode. See: :ref:`concept-modes`.
1176      :param size: The image size.
1177      :param data: A bytes or other buffer object containing raw
1178          data for the given mode.
1179      :param decoder_name: What decoder to use.
1180      :param args: Additional parameters for the given decoder.  For the
1181          default encoder ("raw"), it's recommended that you provide the
1182          full set of parameters::
1183  
1184              frombuffer(mode, size, data, "raw", mode, 0, 1)
1185  
1186      :returns: An :py:class:`~PIL.Image.Image` object.
1187  
1188      .. versionadded:: 1.1.4
1189      rrrr&rErrr�rs)r_rdr�r��	_MAPMODESr�r�r��
1190  map_bufferr�r�r3r�r�r�r)rar�r�r�r�r3r�r&r&r'�
1191  frombuffer�s#
1192  
1193  rcc
1194  CsD|j}|d}t|�}|�dd�}|durUzd|dd�|df}Wnty6}zd}t|�|�d}~wwzt|\}}	WntyT}z	d|}t|�|�d}~ww|}	|d	vr^d}
1195  n	|d
1196  kred}
1197  nd}
1198  ||
1199  krxd
|�d|
1200  �d�}t|��|dkr~dn|d|df}|dur�t|d�r�|��}n|�	�}t
1201  |||d|	dd�S)an
1202      Creates an image memory from an object exporting the array interface
1203      (using the buffer protocol).
1204  
1205      If ``obj`` is not contiguous, then the ``tobytes`` method is called
1206      and :py:func:`~PIL.Image.frombuffer` is used.
1207  
1208      If you have an image in NumPy::
1209  
1210        from PIL import Image
1211        import numpy as np
1212        im = Image.open("hopper.jpg")
1213        a = np.asarray(im)
1214  
1215      Then this can be used to convert it to a Pillow image::
1216  
1217        im = Image.fromarray(a)
1218  
1219      :param obj: Object with array interface
1220      :param mode: Optional mode to use when reading ``obj``. Will be determined from
1221        type if ``None``.
1222  
1223        This will not be used to convert the data after reading, but will be used to
1224        change how the data is read::
1225  
1226          from PIL import Image
1227          import numpy as np
1228          a = np.full((1, 1), 300)
1229          im = Image.fromarray(a, mode="L")
1230          im.getpixel((0, 0))  # 44
1231          im = Image.fromarray(a, mode="RGB")
1232          im.getpixel((0, 0))  # (44, 1, 0)
1233  
1234        See: :ref:`concept-modes` for general information about modes.
1235      :returns: An image object.
1236  
1237      .. versionadded:: 1.1.6
1238      rh�stridesNrErrfzCannot handle this data typez$Cannot handle this data type: %s, %s)rkrprorrrmrsr8r9zToo many dimensions: z > r�rrr�r)rrdrIr�ro�_fromarray_typemapr�r4r��tostringrc)�objrar4rh�ndimrd�typekeyr�r%r-Zndmaxr�r&r&r'�	fromarray�sD'
1239  ��
1240  ��
1241  
1242  rjcCrK)z-Creates an image instance from a QImage imagerrLrN)r�rMrOr��
1243  fromqimage�r3rMr%r&r&r'rk"rRrkcCrK)z.Creates an image instance from a QPixmap imagerrLrN)r�rMrOr��fromqpixmaprlr&r&r'rm,rRrm)rEz|b1)rkz1;8)rE�|u1)rprp)rEz|i1)rozI;8)rEz<u2)rorw)rEz>u2)rorx)rEz<i2)rozI;16S)rEz>i2)rozI;16BS)rEz<u4)rozI;32)rEz>u4)rozI;32B)rEz<i4)rozI;32S)rEz>i4)rozI;32BS)rEz<f4)rmzF;32F)rEz>f4)rmzF;32BF)rEz<f8)rmzF;64F)rEz>f8)rmzF;64BF))rrrrn)rr))rrr8rn)rsrs))rrr9rn)rtrtrE�i4)roro�f4)rmrmcCsptdurdS|d|d}|dtkr#d|�ddt�d�}t|��|tkr6t�d|�dt�d�t�dSdS)NrrrzImage size (z pixels) exceeds limit of z0 pixels, could be decompression bomb DOS attack.)�MAX_IMAGE_PIXELSr/rr
r*)r��pixelsr%r&r&r'reQs���re�rc		sj|dkrdt|���}t|��t|tj�rd}t|��|dur"t}n
t|ttf�s/d}t|��d�d}t|t	�r?t
1244  |���}nt|�rE|}|rOt
�|d�}d	�z|�d
1245  �Wnttjfykt�|���}d	�Ynw|�d�}t�g���fdd
�}|||||�}|dur�t�r�|||||�}|r��|_|S�r�|���D]}t�|�q�d|r�|n|}t|��)a`
1246      Opens and identifies the given image file.
1247  
1248      This is a lazy operation; this function identifies the file, but
1249      the file remains open and the actual image data is not read from
1250      the file until you try to process the data (or call the
1251      :py:meth:`~PIL.Image.Image.load` method).  See
1252      :py:func:`~PIL.Image.new`. See :ref:`file-handling`.
1253  
1254      :param fp: A filename (string), pathlib.Path object or a file object.
1255         The file object must implement ``file.read``,
1256         ``file.seek``, and ``file.tell`` methods,
1257         and be opened in binary mode.
1258      :param mode: The mode.  If given, this argument must be "r".
1259      :param formats: A list or tuple of formats to attempt to load the file in.
1260         This can be used to restrict the set of formats checked.
1261         Pass ``None`` to try all supported formats. You can print the set of
1262         available formats by running ``python3 -m PIL`` or using
1263         the :py:func:`PIL.features.pilinfo` function.
1264      :returns: An :py:class:`~PIL.Image.Image` object.
1265      :exception FileNotFoundError: If the file cannot be found.
1266      :exception PIL.UnidentifiedImageError: If the image cannot be opened and
1267         identified.
1268      :exception ValueError: If the ``mode`` is not "r", or if a ``StringIO``
1269         instance is used for ``fp``.
1270      :exception TypeError: If ``formats`` is not ``None``, a list or a tuple.
1271      rsz	bad mode zKStringIO cannot be used to open an image. Binary data must be used instead.Nzformats must be a list or tupleFr��rbTr�c	s�|D][}|��}|tvrt�z3t|\}}|p||�}t|�ttfvr+��|�n|rA|�d�|||�}t|j	�|WSWqt
1272  ttt
jfyPYqty]�r\|���wdSr�)rr�r��typerNrLrr�rer��SyntaxError�
1273  IndexErrorro�struct�error�
BaseExceptionr�)	r�r��prefix�formatsr@�factory�acceptr�r3�Zaccept_warnings�exclusive_fpr&r'�
1274  _open_core�s.
1275  
1276  
1277  
1278  ��zopen.<locals>._open_corezcannot identify image file %r)�reprr�r�r�StringIO�IDrUr�rorrN�resolverr!r�r�r"�UnsupportedOperationrr�r�r�r�r�rr
r
1279  )	r�rar}r%r�r|r�r3�messager&r�r'r�fsX�
1280  �
1281  r�cCs&|��|��|�t�|j|j��S)z�
1282      Alpha composite im2 over im1.
1283  
1284      :param im1: The first image. Must have mode RGBA.
1285      :param im2: The second image.  Must have mode RGBA, and the same size as
1286         the first image.
1287      :returns: An :py:class:`~PIL.Image.Image` object.
1288      )r�r�r�r�r3)�im1�im2r&r&r'r��s
1289  r�cCs(|��|��|�t�|j|j|��S)a�
1290      Creates a new image by interpolating between two input images, using
1291      a constant alpha::
1292  
1293          out = image1 * (1.0 - alpha) + image2 * alpha
1294  
1295      :param im1: The first image.
1296      :param im2: The second image.  Must have the same mode and size as
1297         the first image.
1298      :param alpha: The interpolation alpha factor.  If alpha is 0.0, a
1299         copy of the first image is returned. If alpha is 1.0, a copy of
1300         the second image is returned. There are no restrictions on the
1301         alpha value. If necessary, the result is clipped to fit into
1302         the allowed output range.
1303      :returns: An :py:class:`~PIL.Image.Image` object.
1304      )r�r�r��blendr3)r�r�r�r&r&r'r��sr�cCs|��}|�|d|�|S)af
1305      Create composite image by blending images using a transparency mask.
1306  
1307      :param image1: The first image.
1308      :param image2: The second image.  Must have the same mode and
1309         size as the first image.
1310      :param mask: A mask image.  This image can have mode
1311         "1", "L", or "RGBA", and must have the same size as the
1312         other two images.
1313      N)r�r�)�image1�image2r�r"r&r&r'�	composite
sr�cGs|�|d�S)a�
1314      Applies the function (which should take one argument) to each pixel
1315      in the given image. If the image has more than one band, the same
1316      function is applied to each band. Note that the function is
1317      evaluated once for each possible pixel value, so you cannot use
1318      random components or other generators.
1319  
1320      :param image: The input image.
1321      :param function: A function object, taking one integer argument.
1322      :returns: An :py:class:`~PIL.Image.Image` object.
1323      r)r�)r"r�r&r&r'�eval
s
r�cCs�t|�t|�ksd|vrd}t|��|dd�D]}|jt|�kr'd}t|��|j|djkr5d}t|��q|D]}|��q8|d�tj	|gdd	�|D��R��S)
1324  am
1325      Merge a set of single band images into a new multiband image.
1326  
1327      :param mode: The mode to use for the output image. See:
1328          :ref:`concept-modes`.
1329      :param bands: A sequence containing one single-band image for
1330          each band in the output image.  All bands must have the
1331          same size.
1332      :returns: An :py:class:`~PIL.Image.Image` object.
1333      �*zwrong number of bandsrNz
mode mismatchrz
size mismatchcSsg|]}|j�qSr&)r3)r?rr&r&r'r�9
szmerge.<locals>.<listcomp>)
1334  r�rdr�rar~r�r�r�r�rr)rarer%r{r&r&r'rr!
s�
1335  &rrcCs"|��}t�|�||ft|<dS)a1
1336      Register an image file plugin.  This function should not be used
1337      in application code.
1338  
1339      :param id: An image format identifier.
1340      :param factory: An image file factory method.
1341      :param accept: An optional function that can be used to quickly
1342         reject images having another format.
1343      N)rr�rr�)r�r~rr&r&r'�
register_open@
s
1344  
1345  r�cC�|t|��<dS)z�
1346      Registers an image MIME type.  This function should not be used
1347      in application code.
1348  
1349      :param id: An image format identifier.
1350      :param mimetype: The image MIME type for this format.
1351      N)�MIMEr)r��mimetyper&r&r'�
register_mimeO
r�r�cCr�)z�
1352      Registers an image save function.  This function should not be
1353      used in application code.
1354  
1355      :param id: An image format identifier.
1356      :param driver: A function to save images in this format.
1357      N)r�r�r��driverr&r&r'�
register_saveZ
r�r�cCr�)z�
1358      Registers an image function to save all the frames
1359      of a multiframe format.  This function should not be
1360      used in application code.
1361  
1362      :param id: An image format identifier.
1363      :param driver: A function to save images in this format.
1364      N)rrr�r&r&r'�register_save_alle
s	r�cCs|��t|��<dS)z�
1365      Registers an image extension.  This function should not be
1366      used in application code.
1367  
1368      :param id: An image format identifier.
1369      :param extension: An extension used for this format.
1370      N)rrr)r��	extensionr&r&r'�register_extensionq
�r�cCs|D]}t||�qdS)z�
1371      Registers image extensions.  This function should not be
1372      used in application code.
1373  
1374      :param id: An image format identifier.
1375      :param extensions: A list of extensions used for this format.
1376      N)r�)r��
1377  extensionsr�r&r&r'�register_extensions|
s�r�cCs
1378  t�tS)za
1379      Returns a dictionary containing all file extensions belonging
1380      to registered plugins
1381      )r�rr&r&r&r'�registered_extensions�
sr�cC�|t|<dS)a
1382      Registers an image decoder.  This function should not be
1383      used in application code.
1384  
1385      :param name: The name of the decoder
1386      :param decoder: A callable(mode, args) that returns an
1387                      ImageFile.PyDecoder object
1388  
1389      .. versionadded:: 4.1.0
1390      N)r�)r#r�r&r&r'�register_decoder�
�r�cCr�)a
1391      Registers an image encoder.  This function should not be
1392      used in application code.
1393  
1394      :param name: The name of the encoder
1395      :param encoder: A callable(mode, args) that returns an
1396                      ImageFile.PyEncoder object
1397  
1398      .. versionadded:: 4.1.0
1399      N)r�)r#r�r&r&r'�register_encoder�
r�r�cKs"ddlm}|j|fi|��dS)Nr)�	ImageShow)r�r�r+)r"r�r�r&r&r'r*�
sr*cCst��t�|||��S)a
1400      Generate a Mandelbrot set covering the given extent.
1401  
1402      :param size: The requested size in pixels, as a 2-tuple:
1403         (width, height).
1404      :param extent: The extent to cover, as a 4-tuple:
1405         (x0, y0, x1, y1).
1406      :param quality: Quality.
1407      )r�r�r��effect_mandelbrot)r��extent�qualityr&r&r'r��
s
1408  r�cCst��t�||��S)z�
1409      Generate Gaussian noise centered around 128.
1410  
1411      :param size: The requested size in pixels, as a 2-tuple:
1412         (width, height).
1413      :param sigma: Standard deviation of noise.
1414      )r�r�r��effect_noise)r��sigmar&r&r'r��
r�r�cC�t��t�|��S)zl
1415      Generate 256x256 linear gradient from black to white, top to bottom.
1416  
1417      :param mode: Input mode.
1418      )r�r�r��linear_gradientr{r&r&r'r��
�r�cCr�)zm
1419      Generate 256x256 radial gradient from black to white, centre to edge.
1420  
1421      :param mode: Input mode.
1422      )r�r�r��radial_gradientr{r&r&r'r��
r�r�cCs�|durtj}dtjfdtjfdtjffD]d\}}||vrq||��}d}dD]\}}|�|�r<|}|dt|��}q(zt	|�|}Wnt
1423  yVt�|�d��Yqwz||�Wqt
1424  yy}zt�|�d|���WYd}~qd}~wwdS)NZPILLOW_ALIGNMENTZPILLOW_BLOCK_SIZEZPILLOW_BLOCKS_MAXr))r�i)rgiz is not intz: )
r��environr�Z
set_alignmentZset_block_sizeZset_blocks_maxrr�rdr.r�rr
)�env�var_name�setter�var�units�postfix�mulr�r&r&r'�_apply_env_variables�
s8�
1425  �� ���r�c@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
1426  �Zdd�Z	d
d�Z
1427  d(dd�Zdd�Zd)dd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�ZdS)*r�NFcCs"i|_i|_i|_d|_d|_dSr�)�_data�_hidden_data�_ifdsr��_loaded_exifr�r&r&r'r�s
1428  
1429  z
Exif.__init__cCsBzt|�dkrt|t�r|dWSW|SW|Sty Y|Swr�)rdr�r�r�)r�r�r&r&r'�_fixups
1430  ����zExif._fixupcs�fdd�|��D�S)Ncsi|]
1431  \}}|��|��qSr&)r�r�r�r&r'r�#r8z$Exif._fixup_dict.<locals>.<dictcomp>)r�)r�Zsrc_dictr&r�r'�_fixup_dict szExif._fixup_dictc	CsXz|j�|�WnttfyYdSwddlm}|�|j�}|�|j�|�	|�S)Nr��TiffImagePlugin)
1432  r�r�r�ror�r��ImageFileDirectory_v2�headr�r�)r�r�r�r�r&r&r'r�%s�
1433  zExif._get_ifd_dictcCsn|jrdnd}|jdkrd|dtd�}nd|td�}|jr5||jdkr,td�ntd�7}|d7}|S)	N�+�*r]sII�rAsMMs)r�r�rr)r�rr�r&r&r'�	_get_head3s
1434  zExif._get_headcCs�||jkrdS||_|j��|j��|j��|r&|�d�r&|dd�}|s-d|_dSt�|�|_	|j	�
1435  d�|_ddlm
}|�|j�|_|jj|_|j	�|jj�|j�|j	�dS)N�Exifr;rArr�)r�r��clearr�r�r1r�rrr�r�r�r�r�r�r�r�r�r�r�)r�r�r�r&r&r'r�>s$
1436  
1437  
1438  
1439  
1440  z	Exif.loadcCs�d|_|j��|j��|j��ddlm}||_|dur%|��|_	n|j�
1441  d�|_	|�|j	�|_|j
dur=|jj|_
|durE|jj}|j�|�|j�|j�dS)Nrr�rA)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�)r�r�r�r�r&r&r'r�[s 
1442  
1443  
1444  
1445  
1446  zExif.load_from_fpcCs^t|�}tjj|vr|�|tjj�}|r|�|�tjj|vr-|�|tjj�|tjj<|Sr�)�dictrr�r�r��update�GPSInfo)r�Zmerged_dictr�r&r&r'�_get_merged_dictqs
1447  
1448  �zExif._get_merged_dictrAcCs�ddlm}|��}|j|d�}|��D]@\}}|tjjtjjfvrPt	|t
1449  �sP|�|�}|tjjkrPtjj|vrPt	|tjjt
1450  �sP|�
�}|�tjj�|tjj<|||<qd||�|�S)Nrr�)�ifhr�)r�r�r�r�r�rr�r�r�r�r�r��Interopr�r�)r�r�r�r�r�r�r�r&r&r'r��s&��
1451  �
1452  zExif.tobytesc	Cs�||jv�r�|tjjkr#|jdur!|jjdkr!|�|jj�|j|<�n�|tjjtjjfvrE|j	�
1453  ||�
1454  |��}|durC|�|�|j|<�n�|tjjtjjfv�r�tjj|jvr^|�
tjj�|jtjj|}|tjjk�r�ddlm}|dd�dk�rt|d�}||d�}i}tdt�d|dd��d�D]s}t�d||d	d|dd	d��\}	}
1455  }}z	|j|
1456  \}
}Wn	ty�Yq�w||
}|d
1457  kr�t�d|�\}||d	||d	�}n|d|�}t|�|kr�t�d|�d
t|��d|	���q�|�sq�||�|d�||	<q�t|�|��|j|<n�|�
1458  d�dk�r�i}tdt�d|dd��d�D]�}t�d||d	d|dd	d��\}	}
1459  }}|	dk�r�t�d|�\}|j�|�d|j�d
1460  �i}|j�d
1461  �t|j�d	��|d<|j�d
1462  �|j�d
1463  �|d<|j�d	�|j�d
1464  �}|jtjd}||�|d�|d<|j�d
1465  �|j�d�|d<dt|�|��i}�q1||j|<n|�|�|j|<|j�
1466  |i�}|tjjk�r�|j	�r�dd�|� �D�}|S)Nrr)r�rAsFUJIFILMz<Hrz<HHL4s�r9z<Lz9Possibly corrupt EXIF MakerNote data.  Expecting to read z bytes but only got z. Skipping tag FiZNintendoz>Hz>HHL4siz>LZModelID�	TimeStampZInternalSerialNumberZParallax�CategorycSs*i|]\}}|tjjtjjfvr||�qSr&)rr�r��	Makernoter�r&r&r'r��s
1467  �z Exif.get_ifd.<locals>.<dictcomp>)!r�rr�r�r�r�r�r�r�r�rIr�r�r�r�r�r
rJry�unpack�_load_dispatchr�rdrr
r�r�r�r�r�r	�FLOATr�)r�r�r�Ztag_datar�r�Zifd_dataZ	makernoter@�ifd_tag�typ�countr��	unit_size�handlerr�Z
1468  camerainfoZparallaxr�r&r&r'r��s���
1469  " �������
1470  �" �
1471  ����
1472  ��zExif.get_ifdcCs6tjjtjjfD]}||vr|||j|<||=qdSr�)rr�r�r�r��r�r�r&r&r'�hide_offsets�s��zExif.hide_offsetscCs,|jdur|j��D]}||q
1473  t|j�Sr�)r��keysrNr�r�r&r&r'�__str__s
1474  
1475  
1476  zExif.__str__cC�(t|j�}|jdur|�|j�t|�Sr�)�setr�r�r�rd�r�r�r&r&r'�__len__	�
1477  
1478  zExif.__len__cCsF|jdur||jvr||jvr|�|j|�|j|<|j|=|j|Sr�)r�r�r�r�r&r&r'�__getitem__s
1479  zExif.__getitem__cCs||jvp|jduo||jvSr�)r�r�r�r&r&r'�__contains__szExif.__contains__cCs*|jdur||jvr|j|=||j|<dSr��r�r�)r�r�r�r&r&r'�__setitem__szExif.__setitem__cCs,|jdur||jvr|j|=dS|j|=dSr�r�r�r&r&r'�__delitem__szExif.__delitem__cCr�r�)r�r�r�r��iterr�r&r&r'�__iter__#r�z
Exif.__iter__r�)rA)r!r,r-r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r&r&r&r'r�
s*
1480  
1481  dr�)r&)rrTr�)rsN)��atexitr!r�loggingr�r�r�ryrr�r�collections.abcrr�enumr�pathlibr�defusedxml.ElementTreer�r�r�rrr	r
1482  rr�_binaryr
rr�
1483  _deprecater�_utilrrr(�	getLoggerr!r��RuntimeWarningr*r�r/r.rqr0r�r�r%r<rNr1r
r4r3r2r6r7rCr rJrrKrrr�rPrTrW�modules�module�item�setattrr#r�r[�FILTERED�HUFFMAN_ONLY�RLE�FIXEDr�r�r�r�rrr�r��	byteorder�_ENDIANrj�MODESrar|r~rr�r�r�r�r�r�r�r�r�r�r�r>r^r_r�rrcrjrkrmrerer�r�r�r�r�rrr�r�r�r�r�r�r�r�r�r*r�r�r�r�r��register�clear_cacher�r&r&r&r'�<module>s�� 
1484  
1485  ��������
1486  �	
1487  �
1488  
1489  �	
.
1490  
1491  "	>	
1492  
1493  '
1494  &
1495  9L
1496  
1497  ������	�
1498  ���
��������
1499  t
1500  	
1501  
	
1502