
    hrA             
      
   % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKrS SKrS SKrS SKJrJrJrJr  S SKJr  S SKJr  S SKJrJrJrJrJr  SSKJrJrJ r J!r!J"r"J#r#  SS	K$J%r%J&r&J'r'  SS
K(J)r)  SSK*J+r+J,r,  S\-S'    S SK.J/r/  \Rb                  " \25      r3 " S S\45      r5 " S S\65      r7Sr8S\-S'   \9" S5      r:S\-S'    SSKJ;r<  \"\=" \<SS5      :w  a  S\=" \<SS5       S\" 3r>\0" \>5      e SS! jrD " S" S#\5      rE " S$ S%\5      rF " S& S'\5      rG\GR                  S(\GR                  S)\GR                  S)\GR                  S*\GR                  S+0rM " S, S-\5      rN " S. S/\5      rO " S0 S1\5      rP\R                  \2   rR\E\F\G\N\O\P4 H*  r\ H!  rS\T" \R\SR                  \SR                  5        M#     M,     \W" \<S25      (       a<  \<R                  rX\<R                  rY\<R                  rZ\<R                  r[\<R                  r\Sr]\](       a*  S SK^r^S S3K_J`r`  S S4KaJbrb  SS5KJcrcJdrdJereJfrfJgrg  SS6KhJiriJjrjJkrkJlrl  / rmS7\-S8'   0 rnS9\-S:'   0 roS;\-S<'   0 rpS=\-S>'   0 rqS=\-S?'   0 rrS;\-S@'   0 rsSA\-SB'   0 rtSC\-SD'   \R                  SE:X  a  SFOSGrvSSI jrw/ SJQrxSKrySSL jrzSSM jr{SSN jr|SSO jr}S q~SSP jrSSQ jr S         SSR jjr S         SSS jjr " ST SU5      r    SSV jr " SW SX\5      r " SY SH5      r " SZ S[\GR                  5      r " S\ S]\GR                  5      rSS^ jr S       SS_ jjr@ S           SS` jjr S           SSa jjr " Sb Sc\5      r " Sd Se\5      rSSSf jjr        SSg jrSSh jrSSi jr0 SjSk_SlSm_SnSo_SpSq_SrSs_StSu_SvSw_SxSy_SzS{_S|S}_S~S_SS_SS_SS_SS_SS_SS_SSS\v S34SS\v S34S0ErSS jr  S       SS jjrSS jrSS jrSS jrSS jrSS jr S       SS jjrSS jr      SS jr      SS jrSS jrSS jrSS jrSS jrSS jrSS jr        SS jrSS jrSS jrSS jrSSS jjr\" 5         \GRT                  " \<GRV                  5        \](       a  \\9\4   rO\r " S S\5      rg! \0 a    Sr/ GN9f = f! \0 a  r?\+R                  " \0" S5      5      r<\A" \?5      R                  S5      (       a  \R                  " S\45        e \A" \?5      R                  S 5      (       a  \R                  " \A" \?5      \45        e Sr?C?ff = f)    )annotationsN)CallableIteratorMutableMappingSequence)IntEnum)
ModuleType)IOAnyLiteralProtocolcast   )ExifTags	ImageModeTiffTagsUnidentifiedImageError__version___plugins)i32leo32beo32le)	deprecate)DeferredErroris_pathzModuleType | NoneElementTree)r   c                      \ rS rSrSrg)DecompressionBombWarningF    N__name__
__module____qualname____firstlineno____static_attributes__r        ;/var/www/html/env/lib/python3.13/site-packages/PIL/Image.pyr   r   F       r'   r   c                      \ rS rSrSrg)DecompressionBombErrorJ   r    Nr!   r    r'   r(   r+   r+   J   r)   r'   r+   FboolWARN_POSSIBLE_FORMATSiUUU
int | NoneMAX_IMAGE_PIXELS)_imagingPILLOW_VERSIONzUThe _imaging extension was built for another version of Pillow or PIL:
Core version: z
Pillow version: z'The _imaging C module is not installed.zModule use of pythonz?The _imaging extension was built for another version of Python.zThe _imaging extensionc                4    [        SSS5        [        U S5      $ )z
Checks if an object is an image object.

.. warning::

   This function is for internal use only.

:param t: object to check if it's an image
:returns: True if the object is an image
zImage.isImageType(im)   zisinstance(im, Image.Image)im)r   hasattr)ts    r(   isImageTyper8   v   s     %r+HI1dr'   c                  0    \ rS rSrSrSrSrSrSrSr	Sr
S	rg
)	Transpose   r   r                  r    N)r"   r#   r$   r%   FLIP_LEFT_RIGHTFLIP_TOP_BOTTOM	ROTATE_90
ROTATE_180
ROTATE_270	TRANSPOSE
TRANSVERSEr&   r    r'   r(   r:   r:      s%    OOIJJIJr'   r:   c                  (    \ rS rSrSrSrSrSrSrSr	g)		Transform   r   r   r<   r=   r>   r    N)
r"   r#   r$   r%   AFFINEEXTENTPERSPECTIVEQUADMESHr&   r    r'   r(   rI   rI      s    FFKDDr'   rI   c                  ,    \ rS rSrSrSrSrSrSrSr	Sr
g	)

Resampling   r   r>   r<   r?   r=   r   r    N)r"   r#   r$   r%   NEARESTBOXBILINEARHAMMINGBICUBICLANCZOSr&   r    r'   r(   rQ   rQ      s     G
CHGGGr'   rQ         ?      ?       @g      @c                  $    \ rS rSrSrSrSrSrSrg)Dither   r   r   r<   r=   r    N)	r"   r#   r$   r%   NONEORDERED	RASTERIZEFLOYDSTEINBERGr&   r    r'   r(   r]   r]      s    DGINr'   r]   c                      \ rS rSrSrSrSrg)Palette   r   r   r    N)r"   r#   r$   r%   WEBADAPTIVEr&   r    r'   r(   rd   rd      s    
CHr'   rd   c                  $    \ rS rSrSrSrSrSrSrg)Quantize   r   r   r<   r=   r    N)	r"   r#   r$   r%   	MEDIANCUTMAXCOVERAGE
FASTOCTREELIBIMAGEQUANTr&   r    r'   r(   ri   ri      s    IKJMr'   ri   DEFAULT_STRATEGY)Element)PrettyPrinter)	ImageFileImageFilterImagePaletteImageQtTiffImagePlugin)CapsuleType
NumpyArrayStrOrBytesPath	TypeGuard	list[str]IDzodict[str, tuple[Callable[[IO[bytes], str | bytes], ImageFile.ImageFile], Callable[[bytes], bool | str] | None]]OPENdict[str, str]MIMEz:dict[str, Callable[[Image, IO[bytes], str | bytes], None]]SAVESAVE_ALL	EXTENSIONz$dict[str, type[ImageFile.PyDecoder]]DECODERSz$dict[str, type[ImageFile.PyEncoder]]ENCODERSlittle<>Imagec                    [         R                  " U R                  5      nU R                  U R                  4n[        UR                  5      nUS:w  a  X#4-  nX!R                  4$ Nr   )r   getmodemodeheightwidthlenbandstypestr)r5   mshapeextras       r(   _conv_type_shaper      sS    "''"A ii2ELEz))r'   )1CMYKFHSVII;16I;16BI;16LzI;16NLLALaLABPPARGBRGBARGBaRGBXYCbCr)r   r   r   r   r   r   r   r   c                B    [         R                  " U 5      R                  $ )a	  
Gets the "base" mode for given mode.  This function returns "L" for
images that contain grayscale data, and "RGB" for images that
contain color data.

:param mode: Input mode.
:returns: "L" or "RGB".
:exception KeyError: If the input mode was not a standard mode.
)r   r   basemoder   s    r(   getmodebaser     s     T"+++r'   c                B    [         R                  " U 5      R                  $ )z
Gets the storage type mode.  Given a mode, this function returns a
single-layer mode suitable for storing individual bands.

:param mode: Input mode.
:returns: "L", "I", or "F".
:exception KeyError: If the input mode was not a standard mode.
)r   r   basetyper   s    r(   getmodetyper   &  s     T"+++r'   c                B    [         R                  " U 5      R                  $ )a  
Gets a list of individual band names.  Given a mode, this function returns
a tuple containing the names of individual bands (use
:py:method:`~PIL.Image.getmodetype` to get the mode used to store each
individual band.

:param mode: Input mode.
:returns: A tuple containing band names.  The length of the tuple
    gives the number of bands in an image of the given mode.
:exception KeyError: If the input mode was not a standard mode.
)r   r   r   r   s    r(   getmodebandnamesr   2  s     T"(((r'   c                T    [        [        R                  " U 5      R                  5      $ )z
Gets the number of individual bands for this mode.

:param mode: Input mode.
:returns: The number of bands in this mode.
:exception KeyError: If the input mode was not a standard mode.
)r   r   r   r   r   s    r(   getmodebandsr   A  s      y  &,,--r'   c                 l   [         S:  a  g SSKJn   U (       d   e  SSKJn  U(       d   e  SSKJn  U(       d   e  SSKJn  U(       d   e  SSKJn  U(       d   e Sq g! [         a     NSf = f! [         a     NRf = f! [         a     NQf = f! [         a     NPf = f! [         a     Sq gf = f)zp
Explicitly loads BMP, GIF, JPEG, PPM and PPM file format drivers.

It is called when opening or saving images.
r   N)BmpImagePlugin)GifImagePlugin)JpegImagePlugin)PpmImagePlugin)PngImagePlugin)_initialized r   ImportErrorr   r   r   r   )r   r   r   r   r   s        r(   preinitr   R  s     q$~$~%$~$~ L7          LsW   A$ A4 B  B B$ $
A10A14
B B
BB
B! B!$
B32B3c                 f   [         S:  a  g[        R                  S5      S   n [         H=  n [        R                  SU5        [        U  SU 3[        5       [        5       / 5        M?     [        (       d  [        (       a  Sq gg! [         a!  n[        R                  SX5         SnAM  SnAff = f)	z
Explicitly initializes the Python Imaging Library. This function
loads all available file format drivers.

It is called when opening or saving images if :py:meth:`~preinit()` is
insufficient, and by :py:meth:`~PIL.features.pilinfo`.
r<   F.r   zImporting %szImage: failed to import %s: %sNT)r   r"   
rpartitionr   loggerdebug
__import__globalslocalsr   r}   r   )parent_nameplugines      r(   initr     s     q%%c*1-K	FLL0+ax0')VXrJ  ttt  	FLL96EE	Fs   9B
B0B++B0c                   Uc  SnO[        U[        5      (       d  U4n [        U   nU" U /X#-   Q76 $ ! [         a     Of = f [	        [
        U S35      nO$! [         a  nSU S3n[        U5      UeS nAff = fU" U /X#-   Q76 $ )Nr    _decoderzdecoder  not available)
isinstancetupler   KeyErrorgetattrcoreAttributeErrorOSError)r   decoder_nameargsr   decoderr   msgs          r(   _getdecoderr          |e$$w,<( t+dl++  
"$<. 9: "n5cl!" 4'$,'''   	4 
A AA 
A:#A55A:c                   Uc  SnO[        U[        5      (       d  U4n [        U   nU" U /X#-   Q76 $ ! [         a     Of = f [	        [
        U S35      nO$! [         a  nSU S3n[        U5      UeS nAff = fU" U /X#-   Q76 $ )Nr    _encoderzencoder r   )r   r   r   r   r   r   r   r   )r   encoder_namer   r   encoderr   r   s          r(   _getencoderr     r   r   c                  f    \ rS rSrSrSS jrSS jrSS jr\rSS jr	SS jr
SS jr\rSS	 jrS
rg)ImagePointTransformi  z
Used with :py:meth:`~PIL.Image.Image.point` for single band images with more than
8 bits, this represents an affine transformation, where the value is multiplied by
``scale`` and ``offset`` is added.
c                    Xl         X l        g N)scaleoffset)selfr   r   s      r(   __init__ImagePointTransform.__init__  s    
r'   c                F    [        U R                  * U R                  * 5      $ r   )r   r   r   r   s    r(   __neg__ImagePointTransform.__neg__  s    "DJJ;==r'   c                    [        U[        5      (       a:  [        U R                  UR                  -   U R                  UR                  -   5      $ [        U R                  U R                  U-   5      $ r   )r   r   r   r   r   others     r(   __add__ImagePointTransform.__add__  sX    e011&

U[[($++*D  #4::t{{U/BCCr'   c                    X* -   $ r   r    r   s     r(   __sub__ImagePointTransform.__sub__  s    f}r'   c                    X* -   $ r   r    r   s     r(   __rsub__ImagePointTransform.__rsub__  s    u}r'   c                    [        U[        5      (       a  [        $ [        U R                  U-  U R                  U-  5      $ r   r   r   NotImplementedr   r   r   s     r(   __mul__ImagePointTransform.__mul__  5    e011!!"4::#5t{{U7JKKr'   c                    [        U[        5      (       a  [        $ [        U R                  U-  U R                  U-  5      $ r   r   r   s     r(   __truediv__ImagePointTransform.__truediv__  r   r'   )r   r   N)r   floatr   r  returnNone)r  r   )r   zImagePointTransform | floatr  r   )r"   r#   r$   r%   __doc__r   r   r   __radd__r   r   r   __rmul__r   r&   r    r'   r(   r   r     s;    >D HL
 HLr'   r   c                    U " [        SS5      5      n[        U[         5      (       a  UR                  UR                  4$ SU4$ Nr   r   )r   r   r   r   )expras     r(   _getscaleoffsetr    s?     	 A&'A",Q0C"D"DAGGQXXP1a&Pr'   c                  "    \ rS rSr  SS jrSrg)SupportsGetDatai	  c                    g r   r    r   s    r(   getdataSupportsGetData.getdata
  s    *-r'   r    N)r  ztuple[Transform, Sequence[int]])r"   r#   r$   r%   r  r&   r    r'   r(   r  r  	  s    .	(.r'   r  c                     \ rS rSr% SrSrS\S'   SrS\S'   SrSaS jr	\
SbS	 j5       r\R                  ScS
 j5       r\
SdS j5       r\
SdS j5       r\
SeS j5       r\
SfS j5       r\
SdS j5       r\R                  SgS j5       rShS jrS rS rSaS jrSaS jrSaS jr Si       SjS jjrSkS jrSfS jrSlS jrSmS jrSnS jrSnS jr\
SoS j5       rSpS jr  Sq   SrS  jjr!SsS! jr"StS" jr#SuSvS# jjr$SwSxS$ jjr% Su       SyS% jjr&SzS& jr'SaS' jr(SSS\)RT                  S(4           S{S) jjr+S(SS*S\,RZ                  4           S|S+ jjr.S}S, jr/\/r0SqS~S- jjr1      SS. jr2      SS/ jr3SqSS0 jjr4SS1 jr5SS2 jr6SS3.SS4 jjr7 S   SS5 jjr8SqSS6 jjr9SS7 jr:SS8 jr;SS9 jr<SaS: jr=SS; jr>SS< jr?SSS= jjr@\
SS> j5       rASaS? jrB    SS@ jrCSSA jrD Si     SSB jjrE Si     SSC jjrF  Si       SSD jjrG S       SSE jjrH Sq     SSF jjrISSG jrJ  S       SSH jjrK S     SSI jjrL      SSJ jrM Sq     SSK jjrN        SSL jrO   S         SSM jjrP Sq     SSN jjrQ\RR                  SOSSS4             SSP jjrT Sq       SSQ jjrUSSR jrVSqSSS jjrWSST jrXSSU jrYSdSV jrZ\RR                  SW4       SSX jjr\S\RR                  SYS4             SSZ jjr]\RR                  S4             SS[ jjr^SS\ jr_SS] jr`SS^ jraSS_ jrbS`rcg)r   i  a$  
This class represents an image object.  To create
:py:class:`~PIL.Image.Image` objects, use the appropriate factory
functions.  There's hardly ever any reason to call the Image constructor
directly.

* :py:func:`~PIL.Image.open`
* :py:func:`~PIL.Image.new`
* :py:func:`~PIL.Image.frombytes`
N
str | Noneformatformat_descriptionTc                f    S U l         SU l        SU l        S U l        0 U l        SU l        S U l        g )Nr   r   r   r   )_im_mode_sizepaletteinforeadonly_exifr   s    r(   r   Image.__init__  s3    <@

9=68	"&
r'   c                    [        U R                  [        5      (       a  U R                  R                  eU R                  c   eU R                  $ r   )r   r  r   exr   s    r(   r5   Image.im)  s:    dhh..((++xx###xxr'   c                    Xl         g r   )r  r   r5   s     r(   r5   r!  0  s    r'   c                     U R                   S   $ Nr   sizer   s    r(   r   Image.width4      yy|r'   c                     U R                   S   $ r   r&  r   s    r(   r   Image.height8  r)  r'   c                    U R                   $ r   )r  r   s    r(   r'  
Image.size<      zzr'   c                    U R                   $ r   )r  r   s    r(   r   
Image.mode@  r.  r'   c                z    U R                   =(       a    U R                   R                  =(       d    U R                  $ r   )r  r  	_readonlyr   s    r(   r  Image.readonlyD  s$    .TXX..A4>>Ar'   c                    Xl         g r   )r2  )r   r  s     r(   r  r3  H  s    !r'   c                b   [        5       nXl        UR                  Ul        UR                  Ul        UR                  S;   aM  U R                  (       a   U R                  R                  5       Ul        OSSKJ	n  UR                  " 5       Ul        U R                  R                  5       Ul
        U$ )Nr   r   r   rt   )r   r5   r   r  r'  r  r  copyr   rt   r  )r   r5   newrt   s       r(   _new
Image._newL  su    gGG	GG	77k!||"ll//1**77999>>#
r'   c                    U $ r   r    r   s    r(   	__enter__Image.__enter__\  s    r'   c                    SSK Jn  [        XR                  5      (       a*  [        U SS5      (       a  U R	                  5         S U l        g g )Nr   rr   _exclusive_fpF)r   rr   r   r   	_close_fpfp)r   r   rr   s      r(   __exit__Image.__exit___  s;    d//00t_e44 DG 1r'   c                    [        U SS5      (       aJ  [        R                  S:X  a/  [        [        S5      (       a  U R                  R                  5         SU l        [        [        S5      5      U l        g)a>  
This operation will destroy the image core and release its memory.
The image data will be unusable afterward.

This function is required to close images that have multiple frames or
have not had their file read and closed by the
:py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for
more information.
mapNwin32pypy_version_infozOperation on closed image)	r   sysplatformr6   rG  closer   
ValueErrorr  r   s    r(   rL  Image.closeg  sU     4%%||w&738K+L+L )-DH
 !,G!HIr'   c                p    U R                  5         U R                  R                  5       U l        SU l        g r%  )loadr5   r8  r  r   s    r(   _copyImage._copy{  s#    		'',,.r'   c                h    U R                   (       a  U R                  5         g U R                  5         g r   )r  rQ  rP  r   s    r(   _ensure_mutableImage._ensure_mutable  s    ==JJLIIKr'   c                `   SnU(       a  SU 3nU(       d/  [         R                  " U5      u  pV[        R                  " U5        OUnUR	                  U5      (       d  Xd-   nU R                  5         U(       a  US:X  a  U R                  R                  U5        U$ U R                  " Xb40 UD6  U$ )Nr   r   PPM)	tempfilemkstemposrL  endswithrP  r5   save_ppmsave)r   filer  optionssuffixffilenames          r(   _dumpImage._dump  s     \F"**62KAHHQKH$$V,,#,		5GGX&  IIh2'2r'   c                   U R                   UR                   La  g[        U[        5      (       d   eU R                  UR                  :H  =(       a    U R                  UR                  :H  =(       ai    U R
                  UR
                  :H  =(       aI    U R                  5       UR                  5       :H  =(       a!    U R                  5       UR                  5       :H  $ NF)	__class__r   r   r   r'  r  
getpalettetobytesr   s     r(   __eq__Image.__eq__  s    >>0%''''II# 2		UZZ'2		UZZ'2 !U%5%5%772 %--/1	
r'   c                    SU R                   R                   SU R                   R                   SU R                   SU R                  S    SU R                  S    S[        U 5      S	 S
3$ )Nr   r    image mode= size=r   xr   z at 0xXr   )rg  r#   r"   r   r'  idr   s    r(   __repr__Image.__repr__  sm    ))*!DNN,C,C+D E))F499Q<.$))A, HtHQ<q"	
r'   c                    UR                  SU R                  R                   SU R                  R                   SU R                   SU R
                  S    SU R
                  S    S35        g	)
z"IPython plain text display supportr   r   rm  rn  r   ro  r   r   N)textrg  r#   r"   r   r'  )r   pcycles      r(   _repr_pretty_Image._repr_pretty_  sf    
 	
))*!DNN,C,C+D E))F499Q<.$))A,qJ	
r'   c                    [         R                  " 5       n U R                  " X140 UD6  UR	                  5       $ ! [         a     gf = f)zHelper function for iPython display hook.

:param image_format: Image format.
:returns: image as bytes, saved into the given format.
N)ioBytesIOr]  	Exceptiongetvalue)r   image_formatkwargsbs       r(   _repr_imageImage._repr_image  sG     JJL	IIa00 zz|  		s   : 
AAc                "    U R                  SSS9$ )zZiPython display hook support for PNG format.

:returns: PNG version of the image as bytes
PNGr   )compress_levelr  r   s    r(   
_repr_png_Image._repr_png_  s    
 a88r'   c                $    U R                  S5      $ )z\iPython display hook support for JPEG format.

:returns: JPEG version of the image as bytes
JPEGr  r   s    r(   _repr_jpeg_Image._repr_jpeg_  s    
 ''r'   c                    SS0nU R                   S:X  a  U R                  SS5      US'   OU R                  5       US'   [        U 5      u  US'   US'   U$ )	Nversionr=   r   rawr   datar   r   )r   ri  r   )r   r9  s     r(   __array_interface__Image.__array_interface__  s\     @I!n99 ,,uc2CK,,.CK'7'=$Gc)n
r'   c                V    U R                  5         U R                  R                  5       $ r   )rP  r5   __arrow_c_schema__r   s    r(   r  Image.__arrow_c_schema__  s    		ww))++r'   c                    U R                  5         U R                  R                  5       U R                  R                  5       4$ r   )rP  r5   r  __arrow_c_array__r   requested_schemas     r(   r  Image.__arrow_c_array__  s2     			**,dgg.G.G.IJJr'   c                    U R                  5       nU R                  U R                  U R                  U R	                  5       U/$ r   )ri  r  r   r'  rh  )r   im_datas     r(   __getstate__Image.__getstate__  s1    ,,.		499dii1BGLLr'   c                    [         R                  U 5        US S u  p#pEnX l        X0l        X@l        [
        R                  " X45      U l        US;   a  U(       a  U R                  U5        U R                  U5        g )Nr?   r   r   r   r   )
r   r   r  r  r  r   r9  r5   
putpalette	frombytes)r   stater  r   r'  r  r  s          r(   __setstate__Image.__setstate__  sb    t*/)'D4	

((4&))gOOG$tr'   c                >   Un[        U5      S:X  a  [        US   [        5      (       a  US   nUS:X  a  US:X  a  U R                  nU R	                  5         U R
                  S:X  d  U R                  S:X  a  g[        U R                  X5      nUR                  U R                  5        [        SU R                  S   S-  5      n/ n UR                  U5      u  pxn	UR                  U	5        U(       a  OM/  US:  a  SU S	3n
[        U
5      eSR                  U5      $ )
a  
Return image as a bytes object.

.. warning::

    This method returns the raw image data from the internal
    storage.  For compressed image data (e.g. PNG, JPEG) use
    :meth:`~.save`, with a BytesIO parameter for in-memory
    data.

:param encoder_name: What encoder to use.  The default is to
                     use the standard "raw" encoder.

                     A list of C encoders can be seen under
                     codecs section of the function array in
                     :file:`_imaging.c`. Python encoders are
                     registered within the relevant plugins.
:param args: Extra arguments to the encoder.
:returns: A :py:class:`bytes` object.
r   r   r  r    r'   i   r>   zencoder error z in tobytes)r   r   r   r   rP  r   r   r   setimager5   maxr'  encodeappendRuntimeErrorjoin)r   r   r   encoder_argsr   bufsizeoutputbytes_consumederrcoder  r   s              r(   ri  Image.tobytes  s   , !|!ja%&H&H'?L5 \R%799L		::?dkkQ. 		<>	

477eTYYq\A-.,-HHW,=)NTMM$	 
 Q;"7);7Cs##xxr'   c                \   U R                  5         U R                  S:w  a  Sn[        U5      eU R                  S5      nSR	                  SU SU R
                  S    S3R                  S	5      SU S
U R
                  S    S3R                  S	5      SU S3R                  S	5      US/5      $ )z
Returns the image converted to an X11 bitmap.

.. note:: This method only works for mode "1" images.

:param name: The name prefix to use for the bitmap variables.
:returns: A string containing an X11 bitmap.
:raises ValueError: If the mode is not "1"
r   znot a bitmapxbmr'   z#define z_width r   
asciiz_height r   zstatic char z_bits[] = {
s   };)rP  r   rM  ri  r  r'  r  )r   namer   r  s       r(   tobitmapImage.tobitmap1  s     			99 CS/!||E"xx4&		!~R8??H4&1b9@@ItfN3::7C
 	
r'   c                   U R                   S:X  d  U R                  S:X  a  gUn[        U5      S:X  a  [        US   [        5      (       a  US   nUS:X  a  US:X  a  U R
                  n[        U R
                  X$5      nUR                  U R                  5        UR                  U5      nUS   S:  a  Sn[        U5      eUS   S:w  a  Sn[        U5      eg)z
Loads this image with pixel data from a bytes object.

This method is similar to the :py:func:`~PIL.Image.frombytes` function,
but loads data into this image instead of creating a new image object.
r   Nr   r  r    znot enough image datazcannot decode image data)r   r   r   r   r   r   r   r  r5   decoderM  )r   r  r   r   decoder_argsdsr   s           r(   r  Image.frombytesK  s     ::?dkkQ. |!ja%&H&H'?L 5 \R%799L 		<>	

477HHTNQ419)CS/!Q419,CS/! r'   c                   U R                   Gb  U R                  (       Gay  U R                  R                  (       Ga]  U R                  R                  5       u  pU R                  R                  U R                  R                  X5        SU R                  l        SU R                  l        SU R                  ;   a  US;   a  [        U R                  S   [        5      (       a*  U R                  R                  U R                  S   S5        O(U R                  R                  U R                  S   5        SU R                  l        OSU R                  R                  U R                  R                  U R                  R                  5      U R                  l        U R                   b%  U R                  R                  U R                  5      $ g)a  
Allocates storage for the image and loads the pixel data.  In
normal cases, you don't need to call this method, since the
Image class automatically loads an opened image when it is
accessed for the first time.

If the file associated with the image was opened by Pillow, then this
method will close it. The exception to this is if the image has
multiple frames, in which case the file will be left open for seek
operations. See :ref:`file-handling` for more information.

:returns: An image access object.
:rtype: :py:class:`.PixelAccess`
Nr   transparencyr   r   r   )r  r  dirtyr  r5   r  r   rawmoder  r   intputpalettealphaputpalettealphasrh  pixel_accessr  )r   r   arrs      r(   rP  
Image.loadp  s8    88DLLLT\\5G5G5G,,.IDGGt||00$<!"DLL#'DLL *t|/Cdii7==GG++DIIn,EqIGG,,TYY~-FG$*!'+ww'9'9LL%%t||'8'8($ 8877''66r'   c                    g)a;  
Verifies the contents of a file. For data read from a file, this
method attempts to determine if the file is broken, without
actually decoding the image data.  If this method finds any
problems, it raises suitable exceptions.  If you need to load
the image after using this method, you must reopen the image
file.
Nr    r   s    r(   verifyImage.verify  s     	r'      c                   ^^^ US;   a  [        US5        U R                  5         SU R                  ;   nU(       dI  U R                  S:X  a9  U R                  (       a  U R                  R                  nOSnUS:X  a	  U(       a  SnU(       a  XR                  :X  a  T(       d  U R                  5       $ T(       a  US;  a  Sn[        U5      eU R                  R                  UT5      nU R                  U5      n	U(       a  U R                  R                  S	:X  aq  U	R                  S   m      S$S
 jmUS:X  a
  T" TT5      mO8[        U5      S	:X  a)  [        UUU4S j[        [        T5      5       5       5      mTU	R                  S'   U	$ US:X  a!  U R                  S:X  a  U R                  U5      $ Sn
SnU(       GaY  U R                  S;   a  US;   d  U R                  S:X  aL  US;   aF  U R                  U R                  R                  XR                  S   5      5      n	U	R                  S	 U	$ U R                  S;   Ga?  US;   Ga8  U R                  S   n[!        U["        5      (       a  [$        R&                  " S5        SnGO[)        U R                  S5      nU R                  S:X  a  U R                  c   eUR+                  U R                  U R                  R                  5        [!        U[        5      (       a-  SnUR                  c   e UR                  R-                  X5      nUc  Sn
OUR1                  SU5        US;   a  UR3                  U5      nOUR3                  S5      nUR5                  S5      n
OU R                  S:X  a  US;   a  U R                  S   nSn[!        U["        5      (       a  U R                  R7                  U5        O?[!        U[8        5      (       a  U R                  R;                  US5        OSn[        U5      eUS:X  a  U[<        R>                  :X  a  U R                  R                  U5      nU R                  U5      n	SSK J!n  URB                  " SU	R                  RE                  S5      5      U	l        U(       a  U	R                  S	 U
bC   U	R                  R-                  [G        [        [8        S4   U
5      U	5      U	R                  S'   U	$ U	$ S U R                  U4;   a  U nUS :X  a.  UR                  S!;  a  UR3                  S5      nUR                  nOUnUS!;   au  SS"K J%n  URM                  S#5      nURM                  S 5      nUR                  S :X  a  UU/OUU/nURO                  US   US   UR                  U5      nURQ                  U5      $ Uc  [R        RT                  n U R                  R3                  X5      nU R                  U5      n	US:X  aA  U[<        R>                  :w  a-  SSK J!n  URB                  " SURE                  S5      5      U	l        U(       a  U	R                  S	 U
br  U	R                  S:X  aT  U	R                  (       aC   U	R                  R-                  [G        [        [8        S4   U
5      U	5      U	R                  S'   U	$ XR                  S'   U	$ ! [         a(  n[/        U5      S:X  a  Sn SnAGN[        U5      UeSnAff = f! [H         a'    U	R                  S	 [$        R&                  " S5         U	$ f = f! [         aw     [W        U R                  5      nUU R                  :X  a  e U R                  R3                  U5      nUR3                  X5      n GN! [X         a  nSn[        U5      UeSnAff = ff = f! [         a=  nU	R                  S	 [/        U5      S:w  a  [$        R&                  " S5         SnAU	$ SnAff = f)%a  
Returns a converted copy of this image. For the "P" mode, this
method translates pixels through the palette.  If mode is
omitted, a mode is chosen so that all information in the image
and the palette can be represented without a palette.

This supports all possible conversions between "L", "RGB" and "CMYK". The
``matrix`` argument only supports "L" and "RGB".

When translating a color image to grayscale (mode "L"),
the library uses the ITU-R 601-2 luma transform::

    L = R * 299/1000 + G * 587/1000 + B * 114/1000

The default method of converting a grayscale ("L") or "RGB"
image into a bilevel (mode "1") image uses Floyd-Steinberg
dither to approximate the original image luminosity levels. If
dither is ``None``, all values larger than 127 are set to 255 (white),
all other values to 0 (black). To use other thresholds, use the
:py:meth:`~PIL.Image.Image.point` method.

When converting from "RGBA" to "P" without a ``matrix`` argument,
this passes the operation to :py:meth:`~PIL.Image.Image.quantize`,
and ``dither`` and ``palette`` are ignored.

When converting from "PA", if an "RGBA" palette is present, the alpha
channel from the image will be used instead of the values from the palette.

:param mode: The requested mode. See: :ref:`concept-modes`.
:param matrix: An optional conversion matrix.  If given, this
   should be 4- or 12-tuple containing floating point values.
:param dither: Dithering method, used when converting from
   mode "RGB" to "P" or from "RGB" or "L" to "1".
   Available methods are :data:`Dither.NONE` or :data:`Dither.FLOYDSTEINBERG`
   (default). Note that this is not used when ``matrix`` is supplied.
:param palette: Palette to use when converting from mode "RGB"
   to "P".  Available palettes are :data:`Palette.WEB` or
   :data:`Palette.ADAPTIVE`.
:param colors: Number of colors to use for the :data:`Palette.ADAPTIVE`
   palette. Defaults to 256.
:rtype: :py:class:`~PIL.Image.Image`
:returns: An :py:class:`~PIL.Image.Image` object.
zBGR;15zBGR;16zBGR;24r4   r  r   r   r   )r   r   zillegal conversionr=   c           	         U S   US   -  U S   US   -  -   U S   US   -  -   U S   S-  -   n[        S[        S[        U5      5      5      $ )Nr   r   r<   r=   rY      )r  minr  )r   vvalues      r(   convert_transparency+Image.convert.<locals>.convert_transparency  s\     aD1Q4K!A$1+5!qtCadSjPEq#c3u:"677r'   r   c              3  N   >#    U  H  nT" TUS -  US -  S -    T5      v   M     g7f)r>   Nr    ).0ir  matrixr  s     r(   	<genexpr> Image.convert.<locals>.<genexpr>  s5      )!9A -VAEAEAI-FUU!9s   "%NF)r   r   r   r   r   r   )r   r   r   r   )r   r   r   zVPalette images with Transparency expressed in bytes should be converted to RGBA imagesTr   r   z2Couldn't allocate a palette color for transparencyz$cannot allocate more than 256 colorsr  r   r   r   r   z.Transparency for P mode should be bytes or intr   r7  .z0Couldn't allocate palette entry for transparencyr   )r   r   r   )ImageCmssRGB)r   ztuple[float, ...]r  ztuple[int, int, int]r  r  )-r   rP  r  r   r  r8  rM  r5   convert_matrixr:  r   r   r   rangequantizeconvert_transparentr   byteswarningswarnr9  r  getcolorstrputpixelconvertgetpixelr  r  r  rd   rg   r   rt   rh  r   r}  r  createProfilebuildTransformapplyr]   rb   r   r   )r   r   r  ditherr  colorshas_transparencyr   r5   new_imtrnsdelete_trnsr7   trns_imerrr   rt   
other_moder  srgblabprofiles	transformmodebaser  r  s     `                     @@r(   r  Image.convert  s   h 11dB		)TYY6		S(||||((u}!1		)&99;<'* o%''f5BYYr]FDGGMMQ$6%{{>:8(8-A88 3;#7#MLY!^#( )!&s<'8!9) $L /;N+M3;499.==((		449O		U"t/K'K GG//ii6OP KK///D<M4MIIn-a''MM3 #'K "$))V4GyyC'#||777**4<<9J9JK%a//"VC#*??#>>#>A$+OO$<$<Q$E y#((3</&-ood&;G '.ooe&<G&//7c!d.B&BIIn-"a''GG,,Q/3''GG++Aq1JC$S/)3;7g&6&66!!&)BYYr]F&)66vyy++E2FN  KK/	V28..2I2IU38_d33FKK/ M6MTYY%%Bu}77"99F+BWW
!
44&--f5,,U3*,''U*:C;s$33QK!bggt	 !r** >**F	-.B 23;7g&6&66&)66ubmmE>RSFNN+{{c!fnn28..2I2IU38_d3V3FKK/  /3N+m $. A#&q6-S#S )-A*4S/q$@Ad ! V N3MM"TUMV@  
	-	-&tyy1tyy(WW__X.ZZ- -* o1,-
	-4 " N31v!GG !N
 su   [	 .A [> \2 7A ^6 	
[;[6*[66[;>-\/.\/2
^3=A^
^/^**^//^36
_= 2_88_=r   c                   U R                  5         Uc0  [        R                  nU R                  S:X  a  [        R                  nU R                  S:X  a1  U[        R                  [        R
                  4;  a  Sn[        U5      eU(       a  UR                  5         UR                  S:w  a  Sn[        U5      eU R                  S;  a  Sn[        U5      eU R                  R                  SXTR                  5      nU R                  U5      nUR                  c   eUR                  R                  5       Ul
        U$ US:  a  S	n[        U5      eU R                  U R                  R                  XU5      5      nS
SKJn	  UR                  R                  5       n
UR                  R!                  X5      SU[#        U
5      -   nU	R                  " X5      Ul
        U$ )a  
Convert the image to 'P' mode with the specified number
of colors.

:param colors: The desired number of colors, <= 256
:param method: :data:`Quantize.MEDIANCUT` (median cut),
               :data:`Quantize.MAXCOVERAGE` (maximum coverage),
               :data:`Quantize.FASTOCTREE` (fast octree),
               :data:`Quantize.LIBIMAGEQUANT` (libimagequant; check support
               using :py:func:`PIL.features.check_feature` with
               ``feature="libimagequant"``).

               By default, :data:`Quantize.MEDIANCUT` will be used.

               The exception to this is RGBA images. :data:`Quantize.MEDIANCUT`
               and :data:`Quantize.MAXCOVERAGE` do not support RGBA images, so
               :data:`Quantize.FASTOCTREE` is used by default instead.
:param kmeans: Integer greater than or equal to zero.
:param palette: Quantize to the palette of given
                :py:class:`PIL.Image.Image`.
:param dither: Dithering method, used when converting from
   mode "RGB" to "P" or from "RGB" or "L" to "1".
   Available methods are :data:`Dither.NONE` or :data:`Dither.FLOYDSTEINBERG`
   (default).
:returns: A new image
Nr   zoFast Octree (method == 2) and libimagequant (method == 3) are the only valid methods for quantizing RGBA imagesr   zbad mode for palette image>   r   r   z7only RGB or L mode images can be quantized to a paletter   zkmeans must not be negativer   r7  )rP  ri   rk   r   rm   rn   rM  r5   r  r:  r  r8  r  r   rt   getpalettemoderh  r   )r   r  methodkmeansr  r  r   r5   r  rt   r   palette_datas               r(   r  Image.quantize  s   F 			>''FyyF"!,,996""2
 $
H  S/!LLN||s"2 o%yy,O o%fjj9BYYr]F??...$__113FNMA:/CS/!YYtww''?@"uu##%uu''34Hfs4y6HI!..tB
	r'   c                t    U R                  5         U R                  U R                  R                  5       5      $ )z
Copies this image. Use this method if you wish to paste things
into an image, but still retain the original.

:rtype: :py:class:`~PIL.Image.Image`
:returns: An :py:class:`~PIL.Image.Image` object.
)rP  r:  r5   r8  r   s    r(   r8  
Image.copy  s&     			yy((r'   c                   Uc  U R                  5       $ US   US   :  a  Sn[        U5      eUS   US   :  a  Sn[        U5      eU R                  5         U R                  U R	                  U R
                  U5      5      $ )ax  
Returns a rectangular region from this image. The box is a
4-tuple defining the left, upper, right, and lower pixel
coordinate. See :ref:`coordinate-system`.

Note: Prior to Pillow 3.4.0, this was a lazy operation.

:param box: The crop rectangle, as a (left, upper, right, lower)-tuple.
:rtype: :py:class:`~PIL.Image.Image`
:returns: An :py:class:`~PIL.Image.Image` object.
r<   r   z&Coordinate 'right' is less than 'left'r=   r   z'Coordinate 'lower' is less than 'upper')r8  rM  rP  r:  _cropr5   )r   boxr   s      r(   crop
Image.crop  sx     ;99;q6CF?:CS/!Vc!f_;CS/!		yyDGGS122r'   c                    [        [        [        [        U5      5      u  p4pV[        XS-
  5      [        Xd-
  5      4n[	        U5        UR                  X4XV45      $ )a%  
Returns a rectangular region from the core image object im.

This is equivalent to calling im.crop((x0, y0, x1, y1)), but
includes additional sanity checks.

:param im: a core image object
:param box: The crop rectangle, as a (left, upper, right, lower)-tuple.
:returns: A core image object.
)rG  r  roundabs_decompression_bomb_checkr  )r   r5   r  x0y0x1y1absolute_valuess           r(   r  Image._crop  sL     S#eS/2rw<RW6!/2ww'((r'   c                    g)a  
Configures the image file loader so it returns a version of the
image that as closely as possible matches the given mode and
size. For example, you can use this method to convert a color
JPEG to grayscale while loading it.

If any changes are made, returns a tuple with the chosen ``mode`` and
``box`` with coordinates of the original image within the altered one.

Note that this method modifies the :py:class:`~PIL.Image.Image` object
in place. If the image has already been loaded, this method has no
effect.

Note: This method is not implemented for most images. It is
currently implemented only for JPEG and MPO images.

:param mode: The requested mode.
:param size: The requested size in pixels, as a 2-tuple:
   (width, height).
Nr    )r   r   r'  s      r(   draftImage.draft,  s    . 	r'   c                    Uc  UnU R                  5         U R                  U R                  R                  X5      5      $ r   )rP  r:  r5   expand)r   xmarginymargins      r(   _expandImage._expandE  s1    ?G		yy9::r'   c           
     X   SSK Jn  U R                  5         [        U5      (       a  U" 5       n[	        US5      (       d  Sn[        U5      e[        XR                  5      nU R                  R                  S:X  d  U(       a*  U R                  UR                  U R                  5      5      $ [        U R                  R                  5       Vs/ s H;  oPR                  UR                  U R                  R                  U5      5      5      PM=     nn[        U R                  U5      $ s  snf )z
Filters this image using the given filter.  For a list of
available filters, see the :py:mod:`~PIL.ImageFilter` module.

:param filter: Filter kernel.
:returns: An :py:class:`~PIL.Image.Image` object.r   )rs   filterz>filter argument should be ImageFilter.Filter instance or class)r   rs   rP  callabler6   	TypeErrorr   MultibandFilterr5   r   r:  r#  r  getbandmerger   )r   r#  rs   r   	multibandcimss          r(   r#  Image.filterK  s     	"		FXFvx((RCC. v'B'BC	77==A99V]]477344 CHBV
BVQIIfmmDGGOOA$678BV 	 
 TYY$$
s   AD'c                V    [         R                  " U R                  5      R                  $ )z
Returns a tuple containing the name of each band in this image.
For example, ``getbands`` on an RGB image returns ("R", "G", "B").

:returns: A tuple containing band names.
:rtype: tuple
)r   r   r   r   r   s    r(   getbandsImage.getbandsf  s       +111r'   )
alpha_onlyc               X    U R                  5         U R                  R                  U5      $ )a  
Calculates the bounding box of the non-zero regions in the
image.

:param alpha_only: Optional flag, defaulting to ``True``.
   If ``True`` and the image has an alpha channel, trim transparent pixels.
   Otherwise, trim pixels when all channels are zero.
   Keyword-only argument.
:returns: The bounding box is returned as a 4-tuple defining the
   left, upper, right, and lower pixel coordinate. See
   :ref:`coordinate-system`. If the image is completely empty, this
   method returns None.

)rP  r5   getbbox)r   r0  s     r(   r2  Image.getbboxp  s       			wwz**r'   c                .   U R                  5         U R                  S;   aV  U R                  R                  5       n[	        S5       Vs/ s H  o2U   (       d  M  X#   U4PM     nn[        U5      U:  a  gU$ U R                  R                  U5      $ s  snf )a  
Returns a list of colors used in this image.

The colors will be in the image's mode. For example, an RGB image will
return a tuple of (red, green, blue) color values, and a P image will
return the index of the color in the palette.

:param maxcolors: Maximum number of colors.  If this number is
   exceeded, this method returns None.  The default limit is
   256 colors.
:returns: An unsorted list of (count, pixel) values.
)r   r   r   r  N)rP  r   r5   	histogramr  r   	getcolors)r   	maxcolorshr  outs        r(   r6  Image.getcolors  s~      			99'!!#A?DSz+Rz!qTIQT1IzC+R3x)#Jww  ++	 ,Ss   B
Bc                v    U R                  5         Ub  U R                  R                  U5      $ U R                  $ )a}  
Returns the contents of this image as a sequence object
containing pixel values.  The sequence object is flattened, so
that values for line one follow directly after the values of
line zero, and so on.

Note that the sequence object returned by this method is an
internal PIL data type, which only supports certain sequence
operations.  To convert it to an ordinary sequence (e.g. for
printing), use ``list(im.getdata())``.

:param band: What band to return.  The default is to return
   all bands.  To return a single band, pass in the index
   value (e.g. 0 to get the "R" band from an "RGB" image).
:returns: A sequence-like object.
)rP  r5   r'  )r   bands     r(   r  Image.getdata  s/    $ 			77??4((wwr'   c                   ^  T R                  5         T R                  R                  S:  a2  [        U 4S j[	        T R                  R                  5       5       5      $ T R                  R                  5       $ )z
Gets the minimum and maximum pixel values for each band in
the image.

:returns: For a single-band image, a 2-tuple containing the
   minimum and maximum pixel value.  For a multi-band image,
   a tuple containing one 2-tuple for each band.
r   c              3  v   >#    U  H.  nTR                   R                  U5      R                  5       v   M0     g 7fr   )r5   r'  
getextrema)r  r  r   s     r(   r  #Image.getextrema.<locals>.<genexpr>  s,     WBVQ+6688BVs   69)rP  r5   r   r   r  r@  r   s   `r(   r@  Image.getextrema  sO     			77==1W%BVWWWww!!##r'   c                  ^^ SS jmSUU4S jjm[         c  [        R                  " S5        0 $ SU R                  ;  a  0 $ [         R                  " U R                  S   R                  S5      5      nT" UR                  5      T" U5      0$ )zy
Returns a dictionary containing the XMP tags.
Requires defusedxml to be installed.

:returns: XMP tags in a dictionary.
c                2    [         R                  " SSU 5      $ )Nz^{[^}]+}r   )resub)tags    r(   get_nameImage.getxmp.<locals>.get_name  s    66*b#..r'   c                  > U R                   R                  5        VVs0 s H  u  pT" U5      U_M     nnn[        U 5      nU(       aa  U HY  nT" UR                  5      nT	" U5      nXc;   a3  [	        X6   [        5      (       d  X6   /X6'   X6   R                  U5        MU  XsU'   M[     U$ U(       a"  U R                  (       a  U R                  US'   U$ U R                  $ s  snnf )Nru  )attribitemslistrG  r   r  ru  )
elementkr  r  childrenchildr  child_valuerH  	get_values
           r(   rS  Image.getxmp.<locals>.get_value  s    @G@T@T@V$W@VXa[!^@VE$WG}H%E#EII.D"+E"2K})%+t<<+0;-EK**;7&1d & L <<$+LLE&M L ||#! %Xs   Cz5XMP data cannot be read without defusedxml dependencyxmp    )rG  r  r  r  )rN  rp   r  zstr | dict[str, Any] | None)r   r  r  r  
fromstringrstriprG  )r   rootrH  rS  s     @@r(   getxmpImage.getxmp  sy    	/	 	( MMQRI		!I%%dii&6&=&=g&FG"IdO44r'   c                   U R                   c  [        5       U l         O'U R                   R                  (       a  U R                   $ SU R                   l        U R                  R	                  S5      nUc  SU R                  ;   aD  [
        R                  SR                  U R                  S   R                  S5      SS 5      5      nO[        U S5      (       a  U R                  R                  U R                   l        U R                  R                  U R                   l        U R                   R                  U R                   U R                  R"                  5        Ub  U R                   R%                  U5        [&        R(                  R*                  U R                   ;  a  U R                  R	                  S	5      nU(       d3  U R                  R	                  S
5      =n(       a  UR-                  S5      nU(       aQ  [.        R0                  " SU5      nU(       a3  [3        US   5      U R                   [&        R(                  R*                  '   U R                   $ )zR
Gets EXIF data from the image.

:returns: an :py:class:`~PIL.Image.Exif` object.
NTexifzRaw profile type exifr   r  r=   tag_v2zXML:com.adobe.xmprU  zutf-8ztiff:Orientation(="|>)([0-9])r<   )r  Exif_loadedr  getr  fromhexr  splitr6   r^  _bigtiffbigtiff_endianendianload_from_fprC  _offsetrP  r   BaseOrientationr  rE  searchr  )r   	exif_infoxmp_tagsmatchs       r(   getexifImage.getexif  s    ::DJZZ::!

IIMM&)	&$))3!MMGGDII&=>DDTJ12NO	 x((%)[[%9%9

"$(KK$7$7

!

''1D1DE JJOOI& ==$$DJJ6yy}}%89HTYY]]5-A!A!A#??73		"BHM<?aMDJJx}}889zzr'   c                    U R                   b  U R                   R                  (       d  g SU R                   l        U R                  5         g rf  )r  r`  rp  r   s    r(   _reload_exifImage._reload_exif  s0    ::TZZ%7%7"

r'   c                \    SSK Jn  [        SS5        UR                  R                  U 5      $ )Nr   r@  zImage.Image.get_child_images   )r   rr   r   get_child_images)r   rr   s     r(   rw  Image.get_child_images  s'    0"5""33D99r'   c                N    U R                  5         U R                  R                  $ )zZ
Returns a capsule that points to the internal image memory.

:returns: A capsule object.
)rP  r5   ptrr   s    r(   getimImage.getim  s     			ww{{r'   c                    U R                  5          U R                  R                  5       nUc  Un[	        U R                  R                  X!5      5      $ ! [         a     gf = f)a  
Returns the image palette as a list.

:param rawmode: The mode in which to return the palette. ``None`` will
   return the palette in its current mode.

   .. versionadded:: 9.1.0

:returns: A list of color values [r, g, b, ...], or None if the
   image has no palette.
N)rP  r5   r  rM  rM  rh  )r   r  r   s      r(   rh  Image.getpalette$  s^     				77))+D ?GDGG&&t566	  		s   A 
A"!A"c                    U R                   S;   d  SU R                  ;   a  gU R                   S:X  a4  U R                  c   eU R                  R                   R                  S5      $ g)a  
Determine if an image has transparency data, whether in the form of an
alpha channel, a palette with an alpha channel, or a "transparency" key
in the info dictionary.

Note the image might still appear solid, if all of the values shown
within are opaque.

:returns: A boolean.
)r   r   r   r   r   r  Tr   AF)r   r  r  r[  r   s    r(   has_transparency_dataImage.has_transparency_data:  sZ     II;;*99<<+++<<$$--c22r'   c                   U R                   S:w  d  SU R                  ;  a  gSSKJn  U R	                  S5      nUc   eU R                  S   n[        U[        5      (       a  [        U5       H  u  pEXRUS-  S-   '   M     O
S	X#S-  S-   '   UR                  " S[        U5      5      U l        SU R                  l	        U R                  S	 g)
z
If a P mode image has a "transparency" key in the info dictionary,
remove the key and instead apply the transparency to the palette.
Otherwise, the image is unchanged.
r   r  Nr   r7  r   r>   r=   r   )
r   r  r   rt   rh  r   r  	enumerater  r  )r   rt   r  r  r  alphas         r(   apply_transparencyImage.apply_transparencyP  s     99~TYY>"//&)"""yy0lE**%l3%*A	" 4 -.G1$q()#00wHIIn%r'   c                j    U R                  5         U R                  R                  [        U5      5      $ )z
Returns the pixel value at a given position.

:param xy: The coordinate, given as (x, y). See
   :ref:`coordinate-system`.
:returns: The pixel value.  If the image is a multi-layer image,
   this method returns a tuple.
)rP  r5   r  r   )r   xys     r(   r  Image.getpixelh  s&     			wwb	**r'   c                    U R                  5         U R                  R                  5       u  p[        U5      [        U5      4$ )z
Get projection to x and y axes

:returns: Two sequences, indicating where there are non-zero
    pixels along the X-axis and the Y-axis, respectively.
)rP  r5   getprojectionrM  )r   ro  ys      r(   r  Image.getprojectionw  s4     			ww$$&AwQr'   c                T   U R                  5         U(       a6  UR                  5         U R                  R                  SUR                  5      $ U R                  S;   a2  U R                  R                  Ub  U5      $ U R	                  5       5      $ U R                  R                  5       $ )aN  
Returns a histogram for the image. The histogram is returned as a
list of pixel counts, one for each pixel value in the source
image. Counts are grouped into 256 bins for each band, even if
the image has more than 8 bits per band. If the image has more
than one band, the histograms for all bands are concatenated (for
example, the histogram for an "RGB" image contains 768 values).

A bilevel image (mode "1") is treated as a grayscale ("L") image
by this method.

If a mask is provided, the method returns a histogram for those
parts of the image where the mask image is non-zero. The mask
image must have the same size as the image, and be either a
bi-level image (mode "1") or a grayscale image ("L").

:param mask: An optional mask.
:param extrema: An optional tuple of manually-specified extrema.
:returns: A list containing pixel counts.
r  r   r   )rP  r5   r5  r   r@  r   maskextremas      r(   r5  Image.histogram  s    . 			IIK77$$VTWW5599
"77$$". 48OO4E  ww  ""r'   c                T   U R                  5         U(       a6  UR                  5         U R                  R                  SUR                  5      $ U R                  S;   a2  U R                  R                  Ub  U5      $ U R	                  5       5      $ U R                  R                  5       $ )a  
Calculates and returns the entropy for the image.

A bilevel image (mode "1") is treated as a grayscale ("L")
image by this method.

If a mask is provided, the method employs the histogram for
those parts of the image where the mask image is non-zero.
The mask image must have the same size as the image, and be
either a bi-level image (mode "1") or a grayscale image ("L").

:param mask: An optional mask.
:param extrema: An optional tuple of manually-specified extrema.
:returns: A float value representing the image entropy
r  r  )rP  r5   entropyr   r@  r  s      r(   r  Image.entropy  s    $ 			IIK77??64773399
"77??". 48OO4E  ww  r'   c                   [        U[        5      (       a  Ub  Sn[        U5      eUnSnUc  Sn[        U5      S:X  ai  [        U[        5      (       a  UR                  nO/[        U[        5      (       a  UR                  nOSn[        U5      eX"S   US   -   US   US   -   4-  n[        U[
        5      (       a"  SSKJn  UR                  XR                  5      nO[        U[        5      (       ar  UR                  5         U R                  UR                  :w  a;  U R                  S	:w  d  UR                  S
;  a  UR                  U R                  5      nUR                  nOUnU R                  5         U(       a7  UR                  5         U R                  R                  XrUR                  5        gU R                  R                  Xr5        g)a  
Pastes another image into this image. The box argument is either
a 2-tuple giving the upper left corner, a 4-tuple defining the
left, upper, right, and lower pixel coordinate, or None (same as
(0, 0)). See :ref:`coordinate-system`. If a 4-tuple is given, the size
of the pasted image must match the size of the region.

If the modes don't match, the pasted image is converted to the mode of
this image (see the :py:meth:`~PIL.Image.Image.convert` method for
details).

Instead of an image, the source can be a integer or tuple
containing pixel values.  The method then fills the region
with the given color.  When creating RGB images, you can
also use color strings as supported by the ImageColor module.

If a mask is given, this method updates only the regions
indicated by the mask. You can use either "1", "L", "LA", "RGBA"
or "RGBa" images (if present, the alpha band is used as mask).
Where the mask is 255, the given image is copied as is.  Where
the mask is 0, the current value is preserved.  Intermediate
values will mix the two images together, including their alpha
channels if they have them.

See :py:meth:`~PIL.Image.Image.alpha_composite` if you want to
combine images with respect to their alpha channels.

:param im: Source image or pixel value (integer, float or tuple).
:param box: An optional 4-tuple giving the region to paste into.
   If a 2-tuple is used instead, it's treated as the upper left
   corner.  If omitted or None, the source is pasted into the
   upper left corner.

   If an image is given as the second argument and there is no
   third, the box defaults to (0, 0), and the second argument
   is interpreted as a mask image.
:param mask: An optional mask image.
Nz=If using second argument as mask, third argument must be Noner  r<   z,cannot determine region size; use 4-item boxr   r   
ImageColorr   )r   r   r   )r   r   rM  r   r'  r  r   r  r  r   rP  r  r5   rT  paste)r   r5   r  r  r   r'  r  sources           r(   r  Image.paste  sm   Z c5!!U o%DC;Cs8q="e$$wwD%((yy E o%FT!W$c!ftAw&677C b#$((YY7FE""GGIyyBGG#99%8N)NDII.BUUFFIIKGGMM&tww/GGMM&&r'   c                   [        U[        [        45      (       d  Sn[        U5      e[        U[        [        45      (       d  Sn[        U5      e[	        U5      S:X  a  [        U5      nO5[	        U5      S:X  a  [        U5      UR
                  -   nOSn[        U5      e[	        U5      S:X  d  Sn[        U5      e[        U5      S:  a  Sn[        U5      eUS	UR
                  -   :X  a  UnOUR                  U5      n[        U5      US   UR                  -   US
   UR                  -   4-   nUS	U R
                  -   :X  a  U nOU R                  U5      n[        X5      n	U R                  X5        g)a  'In-place' analog of Image.alpha_composite. Composites an image
onto this image.

:param im: image to composite over this one
:param dest: Optional 2 tuple (left, top) specifying the upper
  left corner in this (destination) image.
:param source: Optional 2 (left, top) tuple for the upper left
  corner in the overlay source image, or 4 tuple (left, top, right,
  bottom) for the bounds of the source rectangle

Performance Note: Not currently implemented in-place in the core layer.
zSource must be a list or tuplez#Destination must be a list or tupler>   r<   z*Source must be a sequence of length 2 or 4z*Destination must be a sequence of length 2r   zSource must be non-negativer  r   N)r   rM  r   rM  r   r'  r  r  r   r   alpha_compositer  )
r   r5   destr  r   overlay_crop_boxoverlayr  
backgroundresults
             r(   r  Image.alpha_composite  sM     &4-002CS/!$u..7CS/!v;!$V}[A$V}rww6>CS/!4yA~>CS/!v;?/CS/! v//Ggg./G DkT!Ww}}4d1g6NOO &499$$J3J 5

6r'   c                v   U R                  5         [        U[        5      (       a  UR                  U 5      $ [	        U5      (       a  U R
                  S;   a7  [        U5      u  p4U R                  U R                  R                  X45      5      $ [        S5       Vs/ s H
  oQ" U5      PM     snU R                  R                  -  nOUnU R
                  S:X  a  Sn[        U5      eUS:w  a  U Vs/ s H  n[        U5      PM     nnU R                  U R                  R                  Xb5      5      $ s  snf s  snf )a?  
Maps this image through a lookup table or function.

:param lut: A lookup table, containing 256 (or 65536 if
   self.mode=="I" and mode == "L") values per band in the
   image.  A function can be used instead, it should take a
   single argument. The function is called once for each
   possible pixel value, and the resulting table is applied to
   all bands of the image.

   It may also be an :py:class:`~PIL.Image.ImagePointHandler`
   object::

       class Example(Image.ImagePointHandler):
         def point(self, im: Image) -> Image:
           # Return result
:param mode: Output mode (default is same as input). This can only be used if
   the source image has mode "L" or "P", and the output has mode "1" or the
   source image mode is "I" and the output mode is "L".
:returns: An :py:class:`~PIL.Image.Image` object.
)r   r   r   r  r   z+point operation not supported for this mode)rP  r   ImagePointHandlerpointr$  r   r  r:  r5   point_transformr  r   rM  r  )r   lutr   r   r   r  flatLutr   s           r(   r  Image.pointS  s    B 			c,--99T?"C==yy.. !0 4yy!8!8!GHH',Sz2z!s1vz2TWW]]BGG99?CS/!3;)01AuQxG1yyw566 3 2s   D10D6c                   U R                  5         U R                  S;  aP   [        U R                  5      S-   n U R                  R	                  U5        U R                  R                  U l        U R                  S;   a  SnOSn[        U[        5      (       aO  UR                  S	;  a  Sn[        U5      eUR                  5         UR                  S
:X  a  UR                  S5      nO U R                  R                  Xa5        gU R                  R!                  UR                  U5        g! [
        [        4 aJ  nU R                  R                  U5      nUR                  S;  a  Sn[        U5      UeX@l         SnAGN-SnAff = f! [         a  nSn[        U5      UeSnAff = f! [
        [        4 a    [        SU R                  U5      n Nf = f)a*  
Adds or replaces the alpha layer in this image.  If the image
does not have an alpha layer, it's converted to "LA" or "RGBA".
The new layer must be either "L" or "1".

:param alpha: The new alpha layer.  This can either be an "L" or "1"
   image having the same size as this image, or an integer.
r  r  z alpha channel could not be addedNillegal image moder  r   r=   )r   r   r   r   )rT  r   r   r5   setmoder   rM  r  r  r   r   r   rP  fillbandr9  r'  putband)r   r  r   r   r5   r   r<  s          r(   putalphaImage.putalpha  s    	9900-"499-3!GGOOD) "WW\\

 99$DDeU##zz+* o%JJLzzS c*  -
 $'G '
3 !.Bww&::@(o14 GG!  -* o1,-* #J/ 3CE23sR   F D. F +F+ .F>?F=F FF 
F(F##F(+'GGc                \    U R                  5         U R                  R                  XU5        g)a,  
Copies pixel data from a flattened sequence object into the image. The
values should start at the upper left corner (0, 0), continue to the
end of the line, followed directly by the first value of the second
line, and so on. Data will be read until either the image or the
sequence ends. The scale and offset values are used to adjust the
sequence values: **pixel = value*scale + offset**.

:param data: A flattened sequence object.
:param scale: An optional scale value.  The default is 1.0.
:param offset: An optional offset value.  The default is 0.0.
N)rT  r5   putdata)r   r  r   r   s       r(   r  Image.putdata  s"    & 	V,r'   c                    SSK Jn  U R                  S;  a  Sn[        U5      e[	        XR                  5      (       aW  UR
                  b(  UR                  " UR
                  UR                  5      nOTUR                  " UR                  S9nSUl        O2[	        U[        5      (       d  [        U5      nUR                  " X!5      nSU R                  ;   a  SOS	U l
        XPl        SU;   a  S
OSU R                  l        U R                  5         g)a  
Attaches a palette to this image.  The image must be a "P", "PA", "L"
or "LA" image.

The palette sequence must contain at most 256 colors, made up of one
integer value for each channel in the raw mode.
For example, if the raw mode is "RGB", then it can contain at most 768
values, made up of red, green and blue values for the corresponding pixel
index in the 256 colors.
If the raw mode is "RGBA", then it can contain at most 1024 values,
containing red, green, blue and alpha values.

Alternatively, an 8-bit string may be used instead of an integer sequence.

:param data: A palette sequence (either a list or a string).
:param rawmode: The raw mode of the palette. Either "RGB", "RGBA", or a mode
   that can be transformed to "RGB" or "RGBA" (e.g. "R", "BGR;15", "RGBA;L").
r   r7  r  r  Nr  r  r   r   r   r   )r   rt   r   rM  r   r  r  r  r  r  r  rP  )r   r  r  rt   r   r  s         r(   r  Image.putpalette  s    . 	#9922&CS/!d5566||'&**4<<F&33DLLI !dE**T{"&&w5G DII-T3
&)WnF%		r'   c                   U R                   (       a  U R                  5         U R                  5         U R                  S;   a  [	        U[
        [        45      (       a  [        U5      S;   au  U R                  S:X  a  [        U5      S:X  a  US   OSnUSS nU R                  c   eU R                  R                  [        U5      U 5      nU R                  S:X  a  UW4OUnU R                  R                  X5      $ )a]  
Modifies the pixel at the given position. The color is given as
a single numerical value for single-band images, and a tuple for
multi-band images. In addition to this, RGB and RGBA tuples are
accepted for P and PA images.

Note that this method is relatively slow.  For more extensive changes,
use :py:meth:`~PIL.Image.Image.paste` or the :py:mod:`~PIL.ImageDraw`
module instead.

See:

* :py:meth:`~PIL.Image.Image.paste`
* :py:meth:`~PIL.Image.Image.putdata`
* :py:mod:`~PIL.ImageDraw`

:param xy: The pixel coordinate, given as (x, y). See
   :ref:`coordinate-system`.
:param value: The pixel value.
r6  )r=   r>   r   r>   r=   r  N)r  rQ  rP  r   r   rM  r   r   r  r  r5   r  )r   r  r  r  palette_indexs        r(   r  Image.putpixel  s    0 ==JJL		 II$54-00E
f$ yyD $'J!Oabq	<<+++ LL11%,EM.2ii4.?]E*]Eww**r'   c                   SSK Jn  U R                  S;  a  Sn[        U5      eSnSnUcz  U R                  S:X  aN  U R	                  5         U R
                  R                  5       nUS:X  a  S	nU R
                  R                  Xf5      nO/[        S
 [        S5       5       5      nO[        U5      S:  a  S	nSnSnS/S-  n[        U5       H  u  pXrX-  X-  U-    -  nXU
'   M     [        U5      nU R                  5       nSUl        UR                  " XkU-  S9Ul        UR
                  R                  XfS-   UR                  R!                  5       5        UR#                  S5      nUR                  Xv5        UR                  " XgS9Ul        SU R$                  ;   a.   UR'                  U R$                  S   5      UR$                  S'   U$ U$ ! [         a!    SUR$                  ;   a  UR$                  S	  U$ f = f)a-  
Rewrites the image to reorder the palette.

:param dest_map: A list of indexes into the original palette.
   e.g. ``[1,0]`` would swap a two item palette, and ``list(range(256))``
   is the identity transform.
:param source_palette: Bytes or None.
:returns:  An :py:class:`~PIL.Image.Image` object.

r   r7  )r   r   r  r=   r   r   r   r>   c              3  *   #    U  H	  oS -  v   M     g7f)r=   Nr    r  r  s     r(   r  &Image.remap_palette.<locals>.<genexpr>O  s     *F:a6:s   i   r'   r   r  r  z;Lr   r  )r   rt   r   rM  rP  r5   r  rh  	bytearrayr  r   r  r8  r  r  r  ri  r  r  index)r   dest_mapsource_palettert   r   r   palette_modepalette_bytesnew_positionsr  oldPositionmapping_palettem_ims                r(   remap_paletteImage.remap_palette2  s    	#99J&&CS/!!yyC		#ww5576)E!%!3!3L!O!**F5:*F!F 3&E!Lc	 (1NA#k&9E&A M *++&	 20 $M2yy{
#00E"9
 	<)<dll>R>R>TU||C 4#00UTYY&2,4NN499^;T,U		.)
 t	  2!TYY.		.1	2s   +G 'G98G9c           
        [         U   S-
  nUS   US   -
  US   -  nUS   US   -
  US   -  nXE-  nXF-  n[        S[        US   U-
  5      5      [        S[        US   U-
  5      5      [        U R                  S   [
        R                  " US   U-   5      5      [        U R                  S   [
        R                  " US   U-   5      5      4$ )zpExpands the box so it includes adjacent pixels
that may be used by resampling with the given resampling filter.
rY   r<   r   r=   r   )_filters_supportr  r  r  r'  mathceil)	r   r'  resampler  filter_supportscale_xscale_y	support_x	support_ys	            r(   _get_safe_boxImage._get_safe_box  s     *(3c9q6CF?d1g-q6CF?d1g-",	",	 3s1v	)*+3s1v	)*+		!diiA(:;<		!diiA(:;<	
 	
r'   c                8   UcD  U R                   R                  S5      nU(       a  [        R                  O[        R                  nGOU[        R                  [        R
                  [        R                  [        R                  [        R                  [        R                  4;  a  SU S3n[        R                  S4[        R                  S4[        R
                  S4[        R                  S4[        R                  S	4[        R                  S
44 Vs/ s H  nUS    SUS    S3PM     nnUSSR                  USS 5       SUS    3-  n[        U5      eUb  US:  a  Sn[        U5      eUc  SU R                  -   n[        U5      nU R                  U:X  a#  USU R                  -   :X  a  U R                  5       $ U R                   S;   a  [        R                  nU R                   S;   ab  U[        R                  :w  aN  U R                  SSS.U R                      5      n	U	R                  XU5      n	U	R                  U R                   5      $ U R!                  5         UGb  U[        R                  :w  a  [#        US   US   -
  US   -  U-  5      =(       d    Sn
[#        US   US   -
  US   -  U-  5      =(       d    SnU
S:  d  US:  a  U R%                  U['        [        U5      U5      nX4n[)        U R*                  5      (       a  U R+                  XS9O[,        R+                  XUS9n US   US   -
  U
-  US   US   -
  U-  US   US   -
  U
-  US   US   -
  U-  4nU R/                  U R0                  R                  XU5      5      $ s  snf )aX  
Returns a resized copy of this image.

:param size: The requested size in pixels, as a tuple or array:
   (width, height).
:param resample: An optional resampling filter.  This can be
   one of :py:data:`Resampling.NEAREST`, :py:data:`Resampling.BOX`,
   :py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`,
   :py:data:`Resampling.BICUBIC` or :py:data:`Resampling.LANCZOS`.
   If the image has mode "1" or "P", it is always set to
   :py:data:`Resampling.NEAREST`. If the image mode is "BGR;15",
   "BGR;16" or "BGR;24", then the default filter is
   :py:data:`Resampling.NEAREST`. Otherwise, the default filter is
   :py:data:`Resampling.BICUBIC`. See: :ref:`concept-filters`.
:param box: An optional 4-tuple of floats providing
   the source image region to be scaled.
   The values must be within (0, 0, width, height) rectangle.
   If omitted or None, the entire source is used.
:param reducing_gap: Apply optimization by resizing the image
   in two steps. First, reducing the image by integer times
   using :py:meth:`~PIL.Image.Image.reduce`.
   Second, resizing using regular resampling. The last step
   changes size no less than by ``reducing_gap`` times.
   ``reducing_gap`` may be None (no first step is performed)
   or should be greater than 1.0. The bigger ``reducing_gap``,
   the closer the result to the fair resampling.
   The smaller ``reducing_gap``, the faster resizing.
   With ``reducing_gap`` greater or equal to 3.0, the result is
   indistinguishable from fair resampling in most cases.
   The default value is None (no optimization).
:returns: An :py:class:`~PIL.Image.Image` object.
NzBGR;Unknown resampling filter ().Image.Resampling.NEARESTImage.Resampling.LANCZOSImage.Resampling.BILINEARImage.Resampling.BICUBICImage.Resampling.BOXImage.Resampling.HAMMINGr    (r   ) Use ,  or rZ   z#reducing_gap must be 1.0 or greaterr  r   r   r  r   r   r<   r=   )r  )r   
startswithrQ   rS   rW   rU   rX   rT   rV   r  rM  r'  r   r8  r  resizerP  r  r  r   r$  reducer   r:  r5   )r   r'  r  r  reducing_gapbgrr   r#  filtersr5   factor_xfactor_y
reduce_boxfactors                 r(   r  Image.resize  sx   P ))&&v.C-0z))j6H6HHNN
 
 0z<C
  '')CD'')CD((*EF'')CD^^%;<'')CD
F !9+Rq	{!,  
 U499WSb\234}EECS/!#s(:7CS/!;499$CT{99(:!:99;99
"!))H99&8z7I7I+IT6:499EFB43/B::dii((		#J4F4F(FCFSVOtAw6EFK!HCFSVOtAw6EFK!H!|x!|!//d:x6PRUV
"-  ,, KKK7d
C  Vjm+x7Vjm+x7Vjm+x7Vjm+x7	 yy<==k
s   Nc                   [        U[        [        45      (       d  X4nUc  SU R                  -   nUS:X  a#  USU R                  -   :X  a  U R	                  5       $ U R
                  S;   aM  U R                  SSS.U R
                     5      nUR                  X5      nUR                  U R
                  5      $ U R                  5         U R                  U R                  R                  X5      5      $ )a  
Returns a copy of the image reduced ``factor`` times.
If the size of the image is not dividable by ``factor``,
the resulting size will be rounded up.

:param factor: A greater than 0 integer or tuple of two integers
   for width and height separately.
:param box: An optional 4-tuple of ints providing
   the source image region to be reduced.
   The values must be within ``(0, 0, width, height)`` rectangle.
   If omitted or ``None``, the entire source is used.
r  r  r  r   r   )r   rM  r   r'  r8  r   r  r  rP  r:  r5   )r   r  r  r5   s       r(   r  Image.reduce	  s    " &4-00%F;499$CVv		'9 999;99&T6:499EFB6'B::dii((		yy455r'   Fc           	        US-  nU(       d  U(       d  US:X  a  U R                  5       $ US:X  a  U R                  [        R                  5      $ US;   aZ  U(       d  U R                  U R
                  :X  a9  U R                  US:X  a  [        R                  5      $ [        R                  5      $ U R                  u  pxUc  Sn	OUn	Uc
  US-  US-  4n[        R                  " U5      * n[        [        R                  " U5      S5      [        [        R                  " U5      S5      S	[        [        R                  " U5      * S5      [        [        R                  " U5      S5      S	/n
SS
 jnU" US   * U	S   -
  US   * U	S   -
  U
5      u  U
S'   U
S'   U
S==   US   -  ss'   U
S==   US   -  ss'   U(       a  / n/ nSUS4Xx4SU44 H3  u  pU" XU
5      u  nnUR                  U5        UR                  U5        M5     [        R                  " [!        U5      5      [        R"                  " [%        U5      5      -
  n[        R                  " [!        U5      5      [        R"                  " [%        U5      5      -
  nU" UU-
  * S-  UU-
  * S-  U
5      u  U
S'   U
S'   UUpU R'                  Xx4[(        R*                  XUS9$ )a  
Returns a rotated copy of this image.  This method returns a
copy of this image, rotated the given number of degrees counter
clockwise around its centre.

:param angle: In degrees counter clockwise.
:param resample: An optional resampling filter.  This can be
   one of :py:data:`Resampling.NEAREST` (use nearest neighbour),
   :py:data:`Resampling.BILINEAR` (linear interpolation in a 2x2
   environment), or :py:data:`Resampling.BICUBIC` (cubic spline
   interpolation in a 4x4 environment). If omitted, or if the image has
   mode "1" or "P", it is set to :py:data:`Resampling.NEAREST`.
   See :ref:`concept-filters`.
:param expand: Optional expansion flag.  If true, expands the output
   image to make it large enough to hold the entire rotated image.
   If false or omitted, make the output image the same size as the
   input image.  Note that the expand flag assumes rotation around
   the center and no translation.
:param center: Optional center of rotation (a 2-tuple).  Origin is
   the upper left corner.  Default is the center of the image.
:param translate: An optional post-rotate translation (a 2-tuple).
:param fillcolor: An optional color for area outside the rotated image.
:returns: An :py:class:`~PIL.Image.Image` object.
g     v@r      )Z   i  r  r  r<              c                >    Uu  p4pVpxX0-  XA-  -   U-   X`-  Xq-  -   U-   4$ r   r    )	ro  r  r  r
  r  r*  r  r   ra  s	            r(   r  Image.rotate.<locals>.transform	  s3    !'Q1515=1$aeaema&777r'   r   r?   r[   )	fillcolor)ro  r  r  r  r  zlist[float]r  tuple[float, float])r8  	transposer:   rD   r   r   rC   rE   r'  r  radiansr  cossinr  r  r  floorr  r  rI   rK   )r   angler  r  center	translater  wr8  
post_transr  r  xxyyro  r  transformed_xtransformed_ynwnhs                       r(   rotateImage.rotate1	  s   D  )zyy{"|~~i&:&:;;	!vt{{1J~~+0B;I'' <E<P<P , yyJ"J>!eQU^Fe$$$((5/2&$((5/2&488E?"B'$((5/2&
	8  )AYJA&
Z](BF 
q	6!9 	q	VAY	q	VAY	BB!Q!!Q8/8v/F,}		-(		-( 9 3r7#djjR&99B3r7#djjR&99B
 $-rAvY_Qi#ov#V F1Ivayrq~~FI$$f)  
 	
r'   c                   SnSn[        U5      (       a  [        R                  " U5      nSnO/U[        R                  :X  a   [        R                  R
                  nU(       dK  [        US5      (       a:  [        UR                  5      (       a   [        R                  " UR                  5      n[        5         [        R                  R                  U5      S   R                  5       n[        U[        5      (       a  UR                  5       OUnU(       d  U[         ;  a
  [#        5          [         U   nSSKJn
  [        X
R*                  5      (       a[  [        R                  R-                  U5      [        R                  R-                  U R.                  5      :X  a  U R1                  5         OU R3                  5         UR5                  S	S5      n0 [7        U S
0 5      EUEU l        SU l        UR=                  5       [>        ;  a
  [#        5         U(       d1  UcF  URA                  S5      (       a0  UR=                  5       [B        ;   a  [B        UR=                  5          nO[>        UR=                  5          nSnU(       ak  [        R                  RE                  U5      (       + nURA                  SS5      (       a  [F        RH                  " US5      nO/[F        RH                  " US5      nO[K        [L        [           U5      n U" XU5          U ?U(       a  URQ                  5         gg! [         a     GNf = f! [$         a  nSU 3n	['        U	5      UeSnAff = f! [N         aH    U(       a  URQ                  5         U(       a(   [        RR                  " U5        e ! [T         a     e f = fe f = f! [         a     Nf = f!  U ?f ! [         a     f f = f= f)a  
Saves this image under the given filename.  If no format is
specified, the format to use is determined from the filename
extension, if possible.

Keyword options can be used to provide additional instructions
to the writer. If a writer doesn't recognise an option, it is
silently ignored. The available options are described in the
:doc:`image format documentation
<../handbook/image-file-formats>` for each writer.

You can use a file object instead of a filename. In this case,
you must always specify the format. The file object must
implement the ``seek``, ``tell``, and ``write``
methods, and be opened in binary mode.

:param fp: A filename (string), os.PathLike object or file object.
:param format: Optional format override.  If omitted, the
   format to use is determined from the filename extension.
   If a file object was used instead of a filename, this
   parameter should always be used.
:param params: Extra parameters to the image writer. These can also be
   set on the image itself through ``encoderinfo``. This is useful when
   saving multiple images::

     # Saving XMP data to a single image
     from PIL import Image
     red = Image.new("RGB", (1, 1), "#f00")
     red.save("out.mpo", xmp=b"test")

     # Saving XMP data to the second frame of an image
     from PIL import Image
     black = Image.new("RGB", (1, 1))
     red = Image.new("RGB", (1, 1), "#f00")
     red.encoderinfo = {"xmp": b"test"}
     black.save("out.mpo", save_all=True, append_images=[red])
:returns: None
:exception ValueError: If the output format could not be determined
   from the file name.  Use the format option to solve this.
:exception OSError: If the file could not be written.  The file
   may have been created, and may contain partial data.
r   FTr  r   zunknown file extension: Nr@  save_allencoderinfor    append_imagesr  zr+bzw+b)+r   rZ  fspathrJ  stdoutbufferr   r6   r  r   pathsplitextlowerr   r  r  r   r   r   rM  r   rr   abspathrb  rT  rP  popr   r  encoderconfigupperr   ra  r   existsbuiltinsopenr   r
   r}  rL  removePermissionError)r   rC  r  paramsrb  open_fpfilename_extextr   r   rr   r  save_handlercreateds                 r(   r]  
Image.save	  s   \ !#2;;yy}HG3::ZZ&& GB//GBGG4D4Dyy)H	ww''1!4::<'1,'F'Fl!!#L)#-"3
 	  d//00RWW__6
WW__T]]+6,   "IIK::j$/IgdM2>I&I.0<<>%F

?++(*#FLLN3L/L''..22Gzz(E** ]]8U3]]8U3bi$B	8,$ HHJ S "    -06 o1,-V  	
IIh'  ' 	 " $! s   L* ,	L; 	M N3 *
L87L8;
MMM(N0NN0
N+(N0*N++N00O 3
O ?O OOO
OOOOc                *    US:w  a  Sn[        U5      eg)a  
Seeks to the given frame in this sequence file. If you seek
beyond the end of the sequence, the method raises an
``EOFError`` exception. When a sequence file is opened, the
library automatically seeks to frame 0.

See :py:meth:`~PIL.Image.Image.tell`.

If defined, :attr:`~PIL.Image.Image.n_frames` refers to the
number of available frames.

:param frame: Frame number, starting at 0.
:exception EOFError: If the call attempts to seek beyond the end
    of the sequence.
r   zno more images in fileN)EOFError)r   framer   s      r(   seek
Image.seek'
  s    $ A:*C3- r'   c                    [        XS9  g)a  
Displays this image. This method is mainly intended for debugging purposes.

This method calls :py:func:`PIL.ImageShow.show` internally. You can use
:py:func:`PIL.ImageShow.register` to override its default behaviour.

The image is first saved to a temporary file. By default, it will be in
PNG format.

On Unix, the image is then opened using the **xdg-open**, **display**,
**gm**, **eog** or **xv** utility, depending on which one can be found.

On macOS, the image is opened with the native Preview application.

On Windows, the image is opened with the standard PNG display utility.

:param title: Optional title to use for the image window, where possible.
)titleN)_show)r   r1  s     r(   show
Image.show=
  s    ( 	d r'   c                    U R                  5         U R                  R                  S:X  a  U R                  5       4$ [	        [        U R                  U R                  R                  5       5      5      $ )a  
Split this image into individual bands. This method returns a
tuple of individual image bands from an image. For example,
splitting an "RGB" image creates three new images each
containing a copy of one of the original bands (red, green,
blue).

If you need only one band, :py:meth:`~PIL.Image.Image.getchannel`
method can be more convenient and faster.

:returns: A tuple containing bands.
r   )rP  r5   r   r8  r   rG  r:  rc  r   s    r(   rc  Image.splitS
  sK     			77==AIIK>!SDGGMMO455r'   c                (   U R                  5         [        U[        5      (       a    U R                  5       R	                  U5      nU R                  U R                  R                  U5      5      $ ! [
         a  nSU S3n[        U5      UeSnAff = f)a  
Returns an image containing a single channel of the source image.

:param channel: What channel to return. Could be index
  (0 for "R" channel of "RGB") or channel name
  ("A" for alpha channel of "RGBA").
:returns: An image in "L" mode.

.. versionadded:: 4.3.0
zThe image has no channel ""N)	rP  r   r  r.  r  rM  r:  r5   r'  )r   channelr   r   s       r(   
getchannelImage.getchannelf
  s     			gs##---///8
 yy122	  -27)1= o1,-s   A0 0
B:BBc                    g)z
Returns the current frame number. See :py:meth:`~PIL.Image.Image.seek`.

If defined, :attr:`~PIL.Image.Image.n_frames` refers to the
number of available frames.

:returns: Frame number, starting with 0.
r   r    r   s    r(   tell
Image.tell|
  s     r'   r[   c                  ^ ^
 [        [        [        R                  U5      5      m
SU
U 4S jjnU" 5       nUc  gUnSnUb:  T R	                  S[        US   U-  5      [        US   U-  5      45      nUb  US   nT R                  U:w  aC  T R                  XbXsS9n	U	R                  T l        UT l	        T R                  R                  T l        ST l        g)aV  
Make this image into a thumbnail.  This method modifies the
image to contain a thumbnail version of itself, no larger than
the given size.  This method calculates an appropriate thumbnail
size to preserve the aspect of the image, calls the
:py:meth:`~PIL.Image.Image.draft` method to configure the file reader
(where applicable), and finally resizes the image.

Note that this function modifies the :py:class:`~PIL.Image.Image`
object in place.  If you need to use the full resolution image as well,
apply this method to a :py:meth:`~PIL.Image.Image.copy` of the original
image.

:param size: The requested size in pixels, as a 2-tuple:
   (width, height).
:param resample: Optional resampling filter.  This can be one
   of :py:data:`Resampling.NEAREST`, :py:data:`Resampling.BOX`,
   :py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`,
   :py:data:`Resampling.BICUBIC` or :py:data:`Resampling.LANCZOS`.
   If omitted, it defaults to :py:data:`Resampling.BICUBIC`.
   (was :py:data:`Resampling.NEAREST` prior to version 2.5.0).
   See: :ref:`concept-filters`.
:param reducing_gap: Apply optimization by resizing the image
   in two steps. First, reducing the image by integer times
   using :py:meth:`~PIL.Image.Image.reduce` or
   :py:meth:`~PIL.Image.Image.draft` for JPEG images.
   Second, resizing using regular resampling. The last step
   changes size no less than by ``reducing_gap`` times.
   ``reducing_gap`` may be None (no first step is performed)
   or should be greater than 1.0. The bigger ``reducing_gap``,
   the closer the result to the fair resampling.
   The smaller ``reducing_gap``, the faster resizing.
   With ``reducing_gap`` greater or equal to 3.0, the result is
   indistinguishable from fair resampling in most cases.
   The default value is 2.0 (very close to fair resampling
   while still being faster in many cases).
:returns: None
c                    >^^^ SS jn Tu  mmTTR                   :  a  TTR                  :  a  g TR                   TR                  -  mTT-  T:  a  U " TT-  UU4S jS9mTT4$ U " TT-  UU4S jS9mTT4$ )Nc                |    [        [        [        R                  " U 5      [        R                  " U 5      US9S5      $ )Nkeyr   )r  r  r  r  r  )numberrC  s     r(   round_aspectDImage.thumbnail.<locals>.preserve_aspect_ratio.<locals>.round_aspect
  s+    3tzz&1499V3D#NPQRRr'   c                &   > [        TU T-  -
  5      $ r   r  )naspectr  s    r(   <lambda>@Image.thumbnail.<locals>.preserve_aspect_ratio.<locals>.<lambda>
  s    3vA~;Nr'   rB  c                6   > U S:X  a  S$ [        TTU -  -
  5      $ r%  rH  )rI  rJ  ro  s    r(   rK  rL  
  s!    16a.Rs6APQE>?R.Rr'   )rD  r  rC  Callable[[int], float]r  r  )r   r   )rE  rJ  ro  r  provided_sizer   s    @@@r(   preserve_aspect_ratio.Image.thumbnail.<locals>.preserve_aspect_ratio
  s    S !DAqDJJ1#3ZZ$++-F1u V1NO
 a4K !J$R a4Kr'   Nr   r   )r  r  )r  tuple[int, int] | None)r   rG  r  r  r  r  r'  r  r5   r  r   r  r  )r   r'  r  r  rP  preserved_size
final_sizer  resr5   rO  s   `         @r(   	thumbnailImage.thumbnail
  s    Z c$**d34	 	" /0!#
#**s47\12CQ,8N4OPC !f99
"ZsVBeeDG#DJDJr'   r   c           
     :   U R                   S;   a_  U[        R                  :w  aK  U R                  SSS.U R                      5      R	                  XX4XV5      R                  U R                   5      $ [        U[        5      (       a  UR	                  XXES9$ [        US5      (       a  UR                  5       u  p#Uc  Sn[        U5      e[        U R                   X5      nU R                   S:X  a0  U R                  (       a  U R                  R                  5       Ul        U R                  R                  5       Ul        U[        R                  :X  a1  U H)  u  pUR!                  X[        R"                  XUSL 5        M+     U$ UR!                  S	U-   XX4USL 5        U$ )
a"  
Transforms this image.  This method creates a new image with the
given size, and the same mode as the original, and copies data
to the new image using the given transform.

:param size: The output size in pixels, as a 2-tuple:
   (width, height).
:param method: The transformation method.  This is one of
  :py:data:`Transform.EXTENT` (cut out a rectangular subregion),
  :py:data:`Transform.AFFINE` (affine transform),
  :py:data:`Transform.PERSPECTIVE` (perspective transform),
  :py:data:`Transform.QUAD` (map a quadrilateral to a rectangle), or
  :py:data:`Transform.MESH` (map a number of source quadrilaterals
  in one operation).

  It may also be an :py:class:`~PIL.Image.ImageTransformHandler`
  object::

    class Example(Image.ImageTransformHandler):
        def transform(self, size, data, resample, fill=1):
            # Return result

  Implementations of :py:class:`~PIL.Image.ImageTransformHandler`
  for some of the :py:class:`Transform` methods are provided
  in :py:mod:`~PIL.ImageTransform`.

  It may also be an object with a ``method.getdata`` method
  that returns a tuple supplying new ``method`` and ``data`` values::

    class Example:
        def getdata(self):
            method = Image.Transform.EXTENT
            data = (0, 0, 100, 100)
            return method, data
:param data: Extra data to the transformation method.
:param resample: Optional resampling filter.  It can be one of
   :py:data:`Resampling.NEAREST` (use nearest neighbour),
   :py:data:`Resampling.BILINEAR` (linear interpolation in a 2x2
   environment), or :py:data:`Resampling.BICUBIC` (cubic spline
   interpolation in a 4x4 environment). If omitted, or if the image
   has mode "1" or "P", it is set to :py:data:`Resampling.NEAREST`.
   See: :ref:`concept-filters`.
:param fill: If ``method`` is an
  :py:class:`~PIL.Image.ImageTransformHandler` object, this is one of
  the arguments passed to it. Otherwise, it is unused.
:param fillcolor: Optional fill color for the area outside the
   transform in the output image.
:returns: An :py:class:`~PIL.Image.Image` object.
r  r   r   )r  fillr  Nzmissing method datar   r  )r   rQ   rS   r  r  r   ImageTransformHandlerr6   r  rM  r9  r  r8  r  rI   rO   _Image__transformerrN   )r   r'  r  r  r  rY  r  r   r5   r  quads              r(   r  Image.transform
  s^   v 99&8z7I7I+ID&9$))DE4I# f344##D#MM69%%!>>+LF<'CS/!D,99**,BJ)).."Y^^#!	  y~~tyD?P " 		 tTY$=N 	r'   c           
        US   US   -
  nUS   US   -
  nU[         R                  :X  a  US S nOU[         R                  :X  a+  Uu  ppX-
  U-  nX-
  U-  n[         R                  nUSU	SX4nOU[         R                  :X  a  US S nOU[         R                  :X  a  US S nUSS nUSS nUSS nUu  pSU-  nSU-  nU	US   U	-
  U-  US   U	-
  U-  US   US   -
  US   -
  U	-   U-  U-  U
US   U
-
  U-  US   U
-
  U-  US   US   -
  US   -
  U
-   U-  U-  4nOS	n[        U5      eU[        R                  [        R                  [        R                  4;  a  U[        R                  [        R                  [        R                  4;   a?  [        R                  S
[        R                  S[        R                  S0nUU   SU S3-   nOSU S3n[        R                  S4[        R                  S4[        R                  S44 Vs/ s H  nUS    SUS    S3PM     nnUSSR                  US S 5       SUS    3-  n[        U5      eUR                  5         U R                  5         UR                  S;   a  [        R                  nU R                   R#                  XR                   X4XV5        g s  snf )Nr<   r   r=   r   r@      r>   rZ   zunknown transformation methodr  r  r  r  z) cannot be used.r  r  r  r  r  r  r  r  r  r  r  )rI   rK   rL   rM   rN   rM  rQ   rS   rU   rW   rT   rV   rX   r  rP  r   r5   r  )r   r  imager  r  r  rY  r  r8  r  r  r  r  xsysr  swseneAsAtr   unusabler#  r  s                            r(   __transformerImage.__transformer=  s#    FSVOFSVOY%%%8Dy'''!NBB'QB'QB%%F2q")Dy,,,8Dy~~% bqBaBaBaBFBqBqBAr!Ar!AAA&+r1B6Ar!Ar!AAA&+r1B6	D 2CS/!
 

 JNNJ,>,>
@R@RSSNN$:&&(B&&(B,
 x(Rz9J+KK3H:R@
  '')CD((*EF'')CDF !9+Rq	{!,   U499WSb\234}EECS/!

		::#!))H#xxxF%s   J;c                v    U R                  5         U R                  U R                  R                  U5      5      $ )a~  
Transpose image (flip or rotate in 90 degree steps)

:param method: One of :py:data:`Transpose.FLIP_LEFT_RIGHT`,
  :py:data:`Transpose.FLIP_TOP_BOTTOM`, :py:data:`Transpose.ROTATE_90`,
  :py:data:`Transpose.ROTATE_180`, :py:data:`Transpose.ROTATE_270`,
  :py:data:`Transpose.TRANSPOSE` or :py:data:`Transpose.TRANSVERSE`.
:returns: Returns a flipped or rotated copy of this image.
)rP  r:  r5   r  )r   r  s     r(   r  Image.transpose  s+     			yy**6233r'   c                v    U R                  5         U R                  U R                  R                  U5      5      $ )zR
Randomly spread pixels in an image.

:param distance: Distance to spread pixels.
)rP  r:  r5   effect_spread)r   distances     r(   rn  Image.effect_spread  s+     			yy..x899r'   c                n    SSK Jn  UR                  (       d  Sn[        U5      eUR                  " U 5      $ )z#Returns a QImage copy of this imager   ru   Qt bindings are not installed)r   ru   qt_is_installedr   toqimager   ru   r   s      r(   ru  Image.toqimage  s/    &&1Cc""%%r'   c                n    SSK Jn  UR                  (       d  Sn[        U5      eUR                  " U 5      $ )z$Returns a QPixmap copy of this imager   rr  rs  )r   ru   rt  r   	toqpixmaprv  s      r(   ry  Image.toqpixmap  s/    &&1Cc""  &&r'   )r  r  r  r2  r  r  r  rC  r5   r  rG  r  r  r  r  )r  core.ImagingCore)r5   r|  r  r  r  r  )r  tuple[int, int]r  r  )r  r  r  r  )r5   r|  r  r   )NN)r^  r  r  r  r_  r   r  r  )r   objectr  r-   )rv  rq   rw  r-   r  r  )r  r  r  r   r  bytes | None)r  r  )r  z.dict[str, str | bytes | int | tuple[int, ...]])r  r  r   )r  zobject | Noner  ztuple[object, object])r  	list[Any])r  r  r  r  r  )r   r  r   r   r  r  )r`  )r  r  r  r  )r  *bytes | bytearray | SupportsArrayInterfacer   r  r   r   r  r  )r  zcore.PixelAccess | None)r   r  r  ztuple[float, ...] | Noner  zDither | Noner  rd   r  r  r  r   )r  r  r  r/   r  r  r  Image | Noner  r]   r  r   )r  r   )r  (tuple[float, float, float, float] | Noner  r   )r5   r|  r  !tuple[float, float, float, float]r  r|  )r   r  r'  rR  r  z0tuple[str, tuple[int, int, float, float]] | None)r  r  r  r/   r  r   )r#  z-ImageFilter.Filter | type[ImageFilter.Filter]r  r   )r  tuple[str, ...])r0  r-   r   tuple[int, int, int, int] | None)r  )r7  r  r  zBlist[tuple[int, tuple[int, ...]]] | list[tuple[int, float]] | None)r<  r/   r  r|  )r  z1tuple[float, float] | tuple[tuple[int, int], ...]r  zdict[str, Any])r  r_  )r  zlist[ImageFile.ImageFile])r  rw   )r   )r  r  r  zlist[int] | Noner  r-   )r  tuple[int, int] | list[int]r  zfloat | tuple[int, ...] | None)r  ztuple[list[int], list[int]])r  r  r  tuple[float, float] | Noner  	list[int])r  r  r  r  r  r  )r5   z'Image | str | float | tuple[float, ...]r  z:Image | tuple[int, int, int, int] | tuple[int, int] | Noner  r  r  r  )r  r  )r5   r   r  Sequence[int]r  r  r  r  )r  zSequence[float] | NumpyArray | Callable[[int], float] | Callable[[ImagePointTransform], ImagePointTransform | float] | ImagePointHandlerr   r  r  r   )r  zImage | intr  r  )rZ   r  )r  zISequence[float] | Sequence[Sequence[int]] | core.ImagingCore | NumpyArrayr   r  r   r  r  r  )r  z1ImagePalette.ImagePalette | bytes | Sequence[int]r  r  r  r  )r  r~  r  z#float | tuple[int, ...] | list[int]r  r  )r  r  r  zbytes | bytearray | Noner  r   )r'  r~  r  rQ   r  r  r  tuple[int, int, int, int])NNN)
r'  z(tuple[int, int] | list[int] | NumpyArrayr  r/   r  r  r  float | Noner  r   )r  zint | tuple[int, int]r  r  r  r   )r  r  r  rQ   r  z
int | boolr  r  r  rR  r  &float | tuple[float, ...] | str | Noner  r   )rC  StrOrBytesPath | IO[bytes]r  r  r$  r   r  r  )r-  r  r  r  )r1  r  r  r  )r  ztuple[Image, ...])r9  z	int | strr  r   )r'  r  r  rQ   r  r  r  r  )r'  r~  r  z3Transform | ImageTransformHandler | SupportsGetDatar  zSequence[Any] | Noner  r  rY  r  r  r  r  r   )r  r  r`  r   r  rI   r  zSequence[float]r  r  rY  r-   r  r  )r  r:   r  r   )ro  r  r  r   )r  zImageQt.ImageQt)r  ImageQt.QPixmap)dr"   r#   r$   r%   r  r  __annotations__r  !_close_exclusive_fp_after_loadingr   propertyr5   setterr   r   r'  r   r  r:  r=  rD  rL  rQ  rT  rc  rj  rr  rx  r  r  r  r  r  r  r  r  ri  r  r  rP  r  rd   rf   r  r]   rb   r  r8  __copy__r  r  r  r   r#  r.  r2  r6  r  r@  rZ  rp  rs  rw  r{  rh  r  r  r  r  r5  r  r  r  r  r  r  r  r  r  r  r  r  rQ   rS   r  r]  r.  r3  rc  r:  r=  rW   rV  r  r[  r  rn  ru  ry  r&   r    r'   r(   r   r     sI   	 FJ%)
)(,%'   YY          B B __" " J(
 =A/9MP	0



9( 
 
,
 15K -K	KM	3 j
: "#"8#" #" 	#"
 
#"J"H	  +/ $";;{{ ){ 	{
 { { 
{~ ! $..QQ Q 	Q
 Q Q 
Qf	) H34)"))J)	),&<	92;%62 -1 +(  #,,	K,2.$%5N#J:7,  *&0+-+	'+
  PT# #2L#	#D PT! !2L!	!> KO!	Y'3Y' HY' 	Y'
 
Y'x PV6 6 ,6 ?L6 	6 B  :7 :7 :7 
:7x5(t 	-W- - 	-
 
-4 )?) ) 
	)V(+!(+*M(+	(+V OSX!X3KX	Xt

 
 /	

 
#
2  $8<%)j>6j> j> 6	j>
 #j> 
j>^ 15!6%!6 .!6 
	!6L  *11"-1,0<@r
r
 r
 	r

 +r
 *r
 :r
 
r
j DH@,@6@@SV@	@D ,!,6&3,	  *11%(	T!T T #	T
 
Tx &*"**<@\\ D\ #	\
 \ \ :\ 
\H #**TG&TG TG 	TG
 TG TG TG 
TGl4:&'r'   c                  @    \ rS rSrSr\R                  SS j5       rSrg)r  i  zV
Used as a mixin by point transforms
(for use with :py:meth:`~PIL.Image.Image.point`)
c                    g r   r    r#  s     r(   r  ImagePointHandler.point  s    r'   r    N)r5   r   r  r   )	r"   r#   r$   r%   r  abcabstractmethodr  r&   r    r'   r(   r  r    s!    
 	 r'   r  c                  P    \ rS rSrSr\R                          SS j5       rSrg)rZ  i  z]
Used as a mixin by geometry transforms
(for use with :py:meth:`~PIL.Image.Image.transform`)
c                    g r   r    )r   r'  r`  r_  s       r(   r  ImageTransformHandler.transform  s     	r'   r    N)r'  r~  r`  r   r_  r   r  r   )	r"   r#   r$   r%   r  r  r  r  r&   r    r'   r(   rZ  rZ    sG    
 	  	
 
 r'   rZ  c                    [        U [        [        45      (       d  Sn[        U5      e[	        U 5      S:w  a  Sn[        U5      eU S   S:  d	  U S   S:  a  Sn[        U5      eg)z
Common check to enforce type and sanity check on size tuples

:param size: Should be a 2 tuple of (width, height)
:returns: None, or raises a ValueError
zSize must be a list or tupler<   z#Size must be a sequence of length 2r   r   zWidth and height must be >= 0N)r   rM  r   rM  r   )r'  r   s     r(   _check_sizer    sg     dT5M**,o
4yA~3oAw{d1gk-o "r'   c                   U S;   a  [        U S5        [        U5        Uc-  [        5       R                  [        R
                  " X5      5      $ [        U[        5      (       a  SSKJ	n  UR                  X 5      n[        5       nU S:X  a  [        U[        [        45      (       a  [        S U 5       5      (       aw  [        [        [        S4   [        U5      5      n[!        U5      S:X  d  [!        U5      S	:X  a7  SS
KJn  UR"                  " 5       Ul        UR$                  R                  U5      nUR                  [        R&                  " XU5      5      $ )ap  
Creates a new image with the given mode and size.

:param mode: The mode to use for the new image. See:
   :ref:`concept-modes`.
:param size: A 2-tuple, containing (width, height) in pixels.
:param color: What color to use for the image.  Default is black.
   If given, this should be a single integer or floating point value
   for single-band modes, and a tuple for multi-band modes (one value
   per band).  When creating RGB or HSV images, you can also use color
   strings as supported by the ImageColor module.  If the color is
   None, the image is not initialised.
:returns: An :py:class:`~PIL.Image.Image` object.
r  r4   r   r  r   c              3  B   #    U  H  n[        U[        5      v   M     g 7fr   )r   r  r  s     r(   r  new.<locals>.<genexpr>  s     2Eq
1c""Es   .r=   r>   r7  )r   r  r   r:  r   r9  r   r  r   r  r  rM  r   allr   r  r   rt   r  rY  )r   r'  colorr  r5   
color_intsrt   s          r(   r9  r9    s    ( --$}w||DHHT011% 	!##E0	ButUm,,2E222&*5c?E%L&I
z?a3z?a#7&%224BJJJ''
3E77499T/00r'   c                   [        U5        [        X5      nUR                  S:w  a^  UR                  S:w  aN  Un[	        U5      S:X  a  [        US   [        5      (       a  US   nUS:X  a  US:X  a  U nUR                  X#U5        U$ )a?  
Creates a copy of an image memory from pixel data in a buffer.

In its simplest form, this function takes three arguments
(mode, size, and unpacked pixel data).

You can also use any pixel decoder supported by PIL. For more
information on available decoders, see the section
:ref:`Writing Your Own File Codec <file-codecs>`.

Note that this function decodes pixel data only, not entire images.
If you have an entire image in a string, wrap it in a
:py:class:`~io.BytesIO` object, and use :py:func:`~PIL.Image.open` to load
it.

:param mode: The image mode. See: :ref:`concept-modes`.
:param size: The image size.
:param data: A byte buffer containing raw data for the given mode.
:param decoder_name: What decoder to use.
:param args: Additional parameters for the given decoder.
:returns: An :py:class:`~PIL.Image.Image` object.
r   r   r  r    )r  r9  r   r   r   r   r   r  )r   r'  r  r   r   r5   r  s          r(   r  r  '  s|    < 	TB	xx1}a |!ja%&H&H'?L5 \R%7L
T6Ir'   c           	        [        U5        [        U5      S:X  a  [        US   [        5      (       a  US   nUS:X  a  US:X  a  U SS4nUS   [        ;   az  [        U S5      nUR                  [        R                  " X!USU5      5      nU S:X  a7  SSK	J
n  UR                  " SUR                  R                  S5      5      Ul        SUl        U$ [        XX#U5      $ )	aq  
Creates an image memory referencing pixel data in a byte buffer.

This function is similar to :py:func:`~PIL.Image.frombytes`, but uses data
in the byte buffer, where possible.  This means that changes to the
original buffer object are reflected in this image).  Not all modes can
share memory; supported modes include "L", "RGBX", "RGBA", and "CMYK".

Note that this function decodes pixel data only, not entire images.
If you have an entire image file in a string, wrap it in a
:py:class:`~io.BytesIO` object, and use :py:func:`~PIL.Image.open` to load it.

The default parameters used for the "raw" decoder differs from that used for
:py:func:`~PIL.Image.frombytes`. This is a bug, and will probably be fixed in a
future release. The current release issues a warning if you do this; to disable
the warning, you should provide the full set of parameters. See below for details.

:param mode: The image mode. See: :ref:`concept-modes`.
:param size: The image size.
:param data: A bytes or other buffer object containing raw
    data for the given mode.
:param decoder_name: What decoder to use.
:param args: Additional parameters for the given decoder.  For the
    default encoder ("raw"), it's recommended that you provide the
    full set of parameters::

        frombuffer(mode, size, data, "raw", mode, 0, 1)

:returns: An :py:class:`~PIL.Image.Image` object.

.. versionadded:: 1.1.4
r   r   r  r    r  r   r7  r   )r  r   r   r   	_MAPMODESr9  r:  r   
map_bufferr   rt   r5   rh  r  r  r  )r   r'  r  r   r   r5   rt   s          r(   
frombufferr  U  s    P  4yA~*T!We44Awu2:A:D7iT6"B\1dKLBs{*)66ubee>N>Nu>UV
BKITT::r'   c                  ,    \ rS rSrSr\SS j5       rSrg)SupportsArrayInterfacei  z;
An object that has an ``__array_interface__`` dictionary.
c                    [        5       er   NotImplementedErrorr   s    r(   r  *SupportsArrayInterface.__array_interface__  s    !##r'   r    Nr  )r"   r#   r$   r%   r  r  r  r&   r    r'   r(   r  r    s     $ $r'   r  c                  .    \ rS rSrSr S   SS jjrSrg)SupportsArrowArrayInterfacei  za
An object that has an ``__arrow_c_array__`` method corresponding to the arrow c
data interface.
Nc                    [        5       er   r  r  s     r(   r  -SupportsArrowArrayInterface.__arrow_c_array__  s     "##r'   r    r   )r  z'PyCapsule'r  ztuple['PyCapsule', 'PyCapsule'])r"   r#   r$   r%   r  r  r&   r    r'   r(   r  r    s&     /3$ +$	($ $r'   r  c           	     x   U R                   nUS   n[        U5      nUR                  SS5      nUc   SUSS -   US   4n [
        U   u  pOUn	US
;   a  SnOUS:X  a  SnOSnXL:  a  SU SU S3n[        U5      eUS:X  a  SOUS   US   4nUbQ  [        U S5      (       a  U R                  5       n O/[        U S5      (       a  U R                  5       n OSn[        U5      e[        XU SU	SS5      $ ! [         a  nSn[	        U5      UeSnAff = f! [         a  nUu  pSU
 S	U 3n[	        U5      UeSnAff = f)a  
Creates an image memory from an object exporting the array interface
(using the buffer protocol)::

  from PIL import Image
  import numpy as np
  a = np.zeros((5, 5))
  im = Image.fromarray(a)

If ``obj`` is not contiguous, then the ``tobytes`` method is called
and :py:func:`~PIL.Image.frombuffer` is used.

In the case of NumPy, be aware that Pillow modes do not always correspond
to NumPy dtypes. Pillow modes only offer 1-bit pixels, 8-bit pixels,
32-bit signed integer pixels, and 32-bit floating point pixels.

Pillow images can also be converted to arrays::

  from PIL import Image
  import numpy as np
  im = Image.open("hopper.jpg")
  a = np.asarray(im)

When converting Pillow images to arrays however, only pixel values are
transferred. This means that P and PA mode images will lose their palette.

:param obj: Object with array interface
:param mode: Optional mode to use when reading ``obj``. Will be determined from
  type if ``None``.

  This will not be used to convert the data after reading, but will be used to
  change how the data is read::

    from PIL import Image
    import numpy as np
    a = np.full((1, 1), 300)
    im = Image.fromarray(a, mode="L")
    im.getpixel((0, 0))  # 44
    im = Image.fromarray(a, mode="RGB")
    im.getpixel((0, 0))  # (44, 1, 0)

  See: :ref:`concept-modes` for general information about modes.
:returns: An image object.

.. versionadded:: 1.1.6
r   stridesNr  r<   r   zCannot handle this data typezCannot handle this data type: r  )r   r   r   r   r   r   r=   r>   zToo many dimensions: z > r   r   r   ri  tostringz1'strides' requires either tobytes() or tostring()r  )r  r   ra  r   r%  _fromarray_typemaprM  r6   ri  r  r  )objr   r  r   ndimr  typekeyr   r   r  typekey_shaper   ndmaxr'  s                 r(   	fromarrayr    s   ^ 
!
!CLEu:Dggi&G|	(uQRy(#i.8G	(.w7MD' ((	|%dV3ugQ7o	1uQxq1D3	""++-CS*%%,,.CECS/!d#ugq!<<?  	(0CC.a'	(
  	(%,"M2=/G9MCC.a'	(s/   C2 D 2
D<D

D
D9D44D9c                    [        U S5      (       d  Sn[        U5      eU R                  5       u  pE[        R                  " XXE5      nU(       a  [        5       R                  U5      $ Sn[        U5      e)as  Creates an image with zero-copy shared memory from an object exporting
the arrow_c_array interface protocol::

  from PIL import Image
  import pyarrow as pa
  arr = pa.array([0]*(5*5*4), type=pa.uint8())
  im = Image.fromarrow(arr, 'RGBA', (5, 5))

If the data representation of the ``obj`` is not compatible with
Pillow internal storage, a ValueError is raised.

Pillow images can also be converted to Arrow objects::

  from PIL import Image
  import pyarrow as pa
  im = Image.open('hopper.jpg')
  arr = pa.array(im)

As with array support, when converting Pillow images to arrays,
only pixel values are transferred. This means that P and PA mode
images will lose their palette.

:param obj: Object with an arrow_c_array interface
:param mode: Image mode.
:param size: Image size. This must match the storage of the arrow object.
:returns: An Image object

Note that according to the Arrow spec, both the producer and the
consumer should consider the exported array to be immutable, as
unsynchronized updates will potentially cause inconsistent data.

See: :ref:`arrow-support` for more detailed information

.. versionadded:: 11.2.1

r  z!arrow_c_array interface not foundz,new_arrow returned None without an exception)r6   rM  r  r   	new_arrowr   r:  )r  r   r'  r   schema_capsulearray_capsuler  s          r(   	fromarrowr    sf    N 3+,,1o&)&;&;&=#^
..^
CC
w||C  
8C
S/r'   c                n    SSK Jn  UR                  (       d  Sn[        U5      eUR                  " U 5      $ )z-Creates an image instance from a QImage imager   rr  rs  )r   ru   rt  r   
fromqimager5   ru   r   s      r(   r  r  5  s/    ""-#b!!r'   c                n    SSK Jn  UR                  (       d  Sn[        U5      eUR                  " U 5      $ )z.Creates an image instance from a QPixmap imager   rr  rs  )r   ru   rt  r   fromqpixmapr  s      r(   r  r  ?  s/    ""-#r""r'   )r  z|b1)r   z1;8)r  |u1)r   r   )r  z|i1)r   zI;8)r  z<u2)r   r   )r  z>u2)r   r   )r  z<i2)r   zI;16S)r  z>i2)r   zI;16BS)r  z<u4)r   zI;32)r  z>u4)r   zI;32B)r  z<i4)r   zI;32S)r  z>i4)r   zI;32BS)r  z<f4)r   zF;32F)r  z>f4)r   zF;32BF)r  z<f8)r   zF;64F)r  z>f8)r   zF;64BF))r   r   r<   r  )r   r   ))r   r   r=   r  )r   r   ))r   r   r>   r  )r   r   r  i4)r   r   f4)r   r   c                   [         c  g [        SU S   5      [        SU S   5      -  nUS[         -  :  a  SU SS[         -   S3n[        U5      eU[         :  a'  [        R                  " SU S[          S3[
        5        g g )Nr   r   r<   zImage size (z pixels) exceeds limit of z0 pixels, could be decompression bomb DOS attack.)r0   r  r+   r  r  r   )r'  pixelsr   s      r(   r  r  d  s    DG_s1d1g.F$$$6("<QAQ=Q<R S> > 	 %S))  6("<=M<N O6 6$	
 !r'   c           	     B  ^	^
^ US:w  a  S[        U5       3n[        U5      e[        U [        R                  5      (       a  Sn[        U5      eUc  [
        nO([        U[        [        45      (       d  Sn[        U5      eSm
Sn[        U 5      (       a  [        R                  " U 5      nU(       a  [        R                  " US5      n Sm
O[        [        [            U 5      n  U R#                  S	5        U R+                  S
5      n[-        5         / m          SU
U4S jjnU" XXR5      nUcJ  U[
        L aA  [
        R/                  5       m	[1        5       (       a  U" U UU[        U	4S jU 5       5      5      nU(       a	  T
Ul        U$ T
(       a  U R5                  5         T H  n[6        R8                  " U5        M     SU(       a  UOU -  n[;        U5      e! [$        [        R&                  4 a*    [        R(                  " U R+                  5       5      n Sm
 GN(f = f)a9  
Opens and identifies the given image file.

This is a lazy operation; this function identifies the file, but
the file remains open and the actual image data is not read from
the file until you try to process the data (or call the
:py:meth:`~PIL.Image.Image.load` method).  See
:py:func:`~PIL.Image.new`. See :ref:`file-handling`.

:param fp: A filename (string), os.PathLike object or a file object.
   The file object must implement ``file.read``,
   ``file.seek``, and ``file.tell`` methods,
   and be opened in binary mode. The file object will also seek to zero
   before reading.
:param mode: The mode.  If given, this argument must be "r".
:param formats: A list or tuple of formats to attempt to load the file in.
   This can be used to restrict the set of formats checked.
   Pass ``None`` to try all supported formats. You can print the set of
   available formats by running ``python3 -m PIL`` or using
   the :py:func:`PIL.features.pilinfo` function.
:returns: An :py:class:`~PIL.Image.Image` object.
:exception FileNotFoundError: If the file cannot be found.
:exception PIL.UnidentifiedImageError: If the image cannot be opened and
   identified.
:exception ValueError: If the ``mode`` is not "r", or if a ``StringIO``
   instance is used for ``fp``.
:exception TypeError: If ``formats`` is not ``None``, a list or a tuple.
rz	bad mode zKStringIO cannot be used to open an image. Binary data must be used instead.zformats must be a list or tupleFr   rbTr      c                r  > U H  nUR                  5       nU[        ;  a
  [        5          [        U   u  pVU(       + =(       d    U" U5      n[        U[        5      (       a  TR                  U5        Mq  U(       a2  U R                  S5        U" X5      n[        UR                  5        Us  $ M     g ! [        [        [        [        R                  4 a>  n	[        (       a'  TR                  US-   [	        U	5      -   5         S n	A	GM   S n	A	GM  S n	A	f[         a    T
(       a  U R!                  5         e f = f)Nr   z opening failed. )r  r}   r   r   r  r  r.  r  r'  SyntaxError
IndexErrorr%  structerrorr.   BaseExceptionrL  )rC  rb  prefixformatsr  factoryacceptr  r5   r   exclusive_fpwarning_messagess             r(   
_open_coreopen.<locals>._open_core  s     A	A}"&q'#5vf~fc**$++F3GGAJ .B-bgg6I	  *   YE N(($++A0C,Cc!f,LMM )  HHJs   AB356B33$D6+D&D6c              3  6   >#    U  H  oT;  d  M
  Uv   M     g 7fr   r    )r  r  checked_formatss     r(   r  open.<locals>.<genexpr>  s     T7O6Sff7s   		zcannot identify image file %r)
rC  	IO[bytes]rb  zstr | bytesr  r  r  zlist[str] | tuple[str, ...]r  zImageFile.ImageFile | None)reprrM  r   r{  StringIOr|   rM  r   r%  r   rZ  r  r   r!  r   r
   r  r.  r   UnsupportedOperationr|  readr   r8  r   rA  rL  r  r  r   )rC  r   r  r   rb  r  r  r5   messager  r  r  s            @@@r(   r!  r!  y  s   D s{$t*&o	B	$	$0 	 o$///nLHr{{99R=]]8T*"U)R 


 WWR[FI"$  -	
 
$ : 
B&	2B	zgm'')66T7TT	B 
'	

#g $
)Xr
JC
 
%%y B334 ZZ	"s   $G A HHc                    U R                  5         UR                  5         U R                  [        R                  " U R                  UR                  5      5      $ )z
Alpha composite im2 over im1.

:param im1: The first image. Must have mode RGBA.
:param im2: The second image.  Must have mode RGBA, and the same size as
   the first image.
:returns: An :py:class:`~PIL.Image.Image` object.
)rP  r:  r   r  r5   )im1im2s     r(   r  r    s:     HHJHHJ88D((899r'   c                    U R                  5         UR                  5         U R                  [        R                  " U R                  UR                  U5      5      $ )aW  
Creates a new image by interpolating between two input images, using
a constant alpha::

    out = image1 * (1.0 - alpha) + image2 * alpha

:param im1: The first image.
:param im2: The second image.  Must have the same mode and size as
   the first image.
:param alpha: The interpolation alpha factor.  If alpha is 0.0, a
   copy of the first image is returned. If alpha is 1.0, a copy of
   the second image is returned. There are no restrictions on the
   alpha value. If necessary, the result is clipped to fit into
   the allowed output range.
:returns: An :py:class:`~PIL.Image.Image` object.
)rP  r:  r   blendr5   )r  r  r  s      r(   r  r  
  s:    $ HHJHHJ88DJJsvvsvvu566r'   c                L    UR                  5       nUR                  U SU5        U$ )aF  
Create composite image by blending images using a transparency mask.

:param image1: The first image.
:param image2: The second image.  Must have the same mode and
   size as the first image.
:param mask: A mask image.  This image can have mode
   "1", "L", or "RGBA", and must have the same size as the
   other two images.
N)r8  r  )image1image2r  r`  s       r(   	compositer  !  s$     KKME	KKd#Lr'   c                *    U R                  US   5      $ )a  
Applies the function (which should take one argument) to each pixel
in the given image. If the image has more than one band, the same
function is applied to each band. Note that the function is
evaluated once for each possible pixel value, so you cannot use
random components or other generators.

:param image: The input image.
:param function: A function object, taking one integer argument.
:returns: An :py:class:`~PIL.Image.Image` object.
r   )r  )r`  r   s     r(   evalr  2  s     ;;tAwr'   c           	        [        U 5      [        U5      :w  d  SU ;   a  Sn[        U5      eUSS  HS  nUR                  [	        U 5      :w  a  Sn[        U5      eUR
                  US   R
                  :w  d  MH  Sn[        U5      e   U H  nUR                  5         M     US   R                  [        R                  " U /U Vs/ s H  oDR                  PM     snQ76 5      $ s  snf )aM  
Merge a set of single band images into a new multiband image.

:param mode: The mode to use for the output image. See:
    :ref:`concept-modes`.
:param bands: A sequence containing one single-band image for
    each band in the output image.  All bands must have the
    same size.
:returns: An :py:class:`~PIL.Image.Image` object.
*zwrong number of bandsr   Nzmode mismatchr   zsize mismatch)r   r   rM  r   r   r'  rP  r:  r   r(  r5   )r   r   r   r<  r  s        r(   r(  r(  B  s     DSZ'3$;%oab	99D))!CS/!99a%!CS/!  		 8==DA%+@%QDD%+@ABB+@s   C$c                v    U R                  5       n U [        ;  a  [        R                  U 5        X4[        U '   g)a  
Register an image file plugin.  This function should not be used
in application code.

:param id: An image format identifier.
:param factory: An image file factory method.
:param accept: An optional function that can be used to quickly
   reject images having another format.
N)r  r|   r  r}   )rq  r  r  s      r(   register_openr  a  s,    " 
B	|
		"DHr'   c                2    U[         U R                  5       '   g)a  
Registers an image MIME type by populating ``Image.MIME``. This function
should not be used in application code.

``Image.MIME`` provides a mapping from image format identifiers to mime
formats, but :py:meth:`~PIL.ImageFile.ImageFile.get_format_mimetype` can
provide a different result for specific images.

:param id: An image format identifier.
:param mimetype: The image MIME type for this format.
N)r   r  )rq  mimetypes     r(   register_mimer  x  s      Dr'   c                2    U[         U R                  5       '   g)z
Registers an image save function.  This function should not be
used in application code.

:param id: An image format identifier.
:param driver: A function to save images in this format.
N)r   r  rq  drivers     r(   register_saver    s     Dr'   c                2    U[         U R                  5       '   g)z
Registers an image function to save all the frames
of a multiframe format.  This function should not be
used in application code.

:param id: An image format identifier.
:param driver: A function to save images in this format.
N)r   r  r   s     r(   register_save_allr    s     "HRXXZr'   c                N    U R                  5       [        UR                  5       '   g)z
Registers an image extension.  This function should not be
used in application code.

:param id: An image format identifier.
:param extension: An extension used for this format.
N)r  r   r  )rq  	extensions     r(   register_extensionr    s     $&88:Iioo r'   c                ,    U H  n[        X5        M     g)z
Registers image extensions.  This function should not be
used in application code.

:param id: An image format identifier.
:param extensions: A list of extensions used for this format.
N)r  )rq  
extensionsr  s      r(   register_extensionsr
    s      	2)  r'   c                 "    [        5         [        $ )zU
Returns a dictionary containing all file extensions belonging
to registered plugins
)r   r   r    r'   r(   registered_extensionsr    s    
 	Fr'   c                    U[         U '   g)z
Registers an image decoder.  This function should not be
used in application code.

:param name: The name of the decoder
:param decoder: An ImageFile.PyDecoder object

.. versionadded:: 4.1.0
N)r   )r  r   s     r(   register_decoderr         HTNr'   c                    U[         U '   g)z
Registers an image encoder.  This function should not be
used in application code.

:param name: The name of the encoder
:param encoder: An ImageFile.PyEncoder object

.. versionadded:: 4.1.0
N)r   )r  r   s     r(   register_encoderr    r  r'   c                6    SSK Jn  UR                  " U 40 UD6  g )Nr   )	ImageShow)r   r  r3  )r`  r_  r  s      r(   r2  r2    s    NN5$G$r'   c                ^    [        5       R                  [        R                  " XU5      5      $ )z
Generate a Mandelbrot set covering the given extent.

:param size: The requested size in pixels, as a 2-tuple:
   (width, height).
:param extent: The extent to cover, as a 4-tuple:
   (x0, y0, x1, y1).
:param quality: Quality.
)r   r:  r   effect_mandelbrot)r'  extentqualitys      r(   r  r    s"     7<<..tWEFFr'   c                \    [        5       R                  [        R                  " X5      5      $ )z
Generate Gaussian noise centered around 128.

:param size: The requested size in pixels, as a 2-tuple:
   (width, height).
:param sigma: Standard deviation of noise.
)r   r:  r   effect_noise)r'  sigmas     r(   r  r    s      7<<))$677r'   c                \    [        5       R                  [        R                  " U 5      5      $ )z`
Generate 256x256 linear gradient from black to white, top to bottom.

:param mode: Input mode.
)r   r:  r   linear_gradientr   s    r(   r  r          7<<,,T233r'   c                \    [        5       R                  [        R                  " U 5      5      $ )za
Generate 256x256 radial gradient from black to white, centre to edge.

:param mode: Input mode.
)r   r:  r   radial_gradientr   s    r(   r  r    r  r'   c                2   U b  U O[         R                  nS[        R                  4S[        R                  4S[        R
                  44 Hl  u  p#X!;  a  M  X   R                  5       nSnS H.  u  pgUR                  U5      (       d  M  UnUS [        U5      *  nM0      [        U5      U-  n U" U5        Mn     g ! [         a    [        R                  " U S35         M  f = f! [         a&  n	[        R                  " U SU	 35         S n	A	M  S n	A	ff = f)NPILLOW_ALIGNMENTPILLOW_BLOCK_SIZEPILLOW_BLOCKS_MAXr   ))rO  i   )r   i   z is not intz: )rZ  environr   set_alignmentset_block_sizeset_blocks_maxr  r[  r   r  rM  r  r  )
envenv_dictvar_namer  varunitspostfixmulvar_intr   s
             r(   _apply_env_variablesr0    s   os2::H 
T//0	d112	d112
 # &&(=LG||G$$/S\M* >
	#h&G
	.7O/$  	MMXJk23	  	.MMXJb,--	.s*    B</C&<#C#"C#&
D0DDc                      \ rS rSr% SrSrS\S'   SrSrSS jr	SS jr
SS	 jr S     SS
 jjrSS jrS S jrSS!S jjrS"S jrS#S$S jjrS%S jrSS jrS&S jrS'S jrS(S jrS)S jrS*S jrS+S jrS,S jrSrg)-r_  iC  a  
This class provides read and write access to EXIF image data::

  from PIL import Image
  im = Image.open("exif.png")
  exif = im.getexif()  # Returns an instance of this class

Information can be read and written, iterated over or deleted::

  print(exif[274])  # 1
  exif[274] = 2
  for k, v in exif.items():
    print("Tag", k, "Value", v)  # Tag 274 Value 2
  del exif[274]

To access information beyond IFD0, :py:meth:`~PIL.Image.Exif.get_ifd`
returns a dictionary::

  from PIL import ExifTags
  im = Image.open("exif_gps.jpg")
  exif = im.getexif()
  gps_ifd = exif.get_ifd(ExifTags.IFD.GPSInfo)
  print(gps_ifd)

Other IFDs include ``ExifTags.IFD.Exif``, ``ExifTags.IFD.MakerNote``,
``ExifTags.IFD.Interop`` and ``ExifTags.IFD.IFD1``.

:py:mod:`~PIL.ExifTags` also has enum classes to provide names for data::

  print(exif[ExifTags.Base.Software])  # PIL
  print(gps_ifd[ExifTags.GPS.GPSDateStamp])  # 1999:99:99 99:99:99
Nr  rg  Fc                J    0 U l         0 U l        0 U l        S U l        S U l        g r   )_data_hidden_data_ifds_info_loaded_exifr   s    r(   r   Exif.__init__i  s'    %'
,.02
CG
*.r'   c                |     [        U5      S:X  a  [        U[        5      (       a  US   $ U$ ! [         a     U$ f = fr  )r   r   r   r}  )r   r  s     r(   _fixupExif._fixupp  sG    	5zQ:eU#;#;Qx   		s   (- 
;;c                v    UR                  5        VVs0 s H  u  p#X R                  U5      _M     snn$ s  snnf r   )rL  r:  )r   src_dictrO  r  s       r(   _fixup_dictExif._fixup_dictx  s2     /7nn.>?.>da;;q>!.>???s   5c                    U R                   R                  U5        SSKJn  UR                  " U R
                  US9nUR                  U R                   5        U R                  [        U5      5      $ ! [        [        4 a     g f = f)Nr   rv   )group)rC  r.  r   rv   ImageFileDirectory_v2headrP  r>  dictr   r%  )r   r   rB  rv   r  s        r(   _get_ifd_dictExif._get_ifd_dict}  sr    	0 GGLL  *"88%PDIIdgg##DJ// )$ 		s   A3 3BBc                   U R                   (       a  SOSnU R                  S:X  a  SU-   S-   [        S5      -   nOSU-   [        S5      -   nU R                   (       a-  X R                  S:X  a  [        S5      O
[        S5      -  nUS-  nU$ )	N   +   *r   s   IIrV  r_  s   MM s       )re  rg  r   r   )r   r  rD  s      r(   	_get_headExif._get_head  sy    !\\'w;;#7?W,uQx7Dw&q1D<<s 2E!Ha@D''Dr'   c                   XR                   :X  a  g Xl         U R                  R                  5         U R                  R                  5         U R                  R                  5         U(       a:  UR                  S5      (       a$  USS  nU(       a  UR                  S5      (       a  M$  U(       d  S U l        g [        R                  " U5      U l	        U R                  R                  S5      U l        SSKJn  UR                  " U R                  5      U l        U R                  R                  U l        U R                  R#                  U R                  R$                  5        U R                  R'                  U R                  5        g )N   Exif  r@   r_  r   rA  )r7  r3  clearr4  r5  r  r6  r{  r|  rC  r  rD  r   rv   rC  rf  rg  r.  nextrP  )r   r  rv   s      r(   rP  	Exif.load  s     $$$ 

!

t778D t77DJZZ-GGLLO	%$::499E
jj((TZZ__%

 r'   c                   S U l         U R                  R                  5         U R                  R                  5         U R                  R                  5         SSKJn  Xl        Ub  U R                  5       U l	        O U R                  R                  S5      U l	        UR                  " U R                  5      U l        U R                  c  U R                  R                  U l        Uc  U R                  R                  nU R                  R!                  5         U R                  R#                  U5        U R                  R%                  U R                  5        g )Nr   rA  r_  )r7  r3  rO  r4  r5  r   rv   rC  rK  rD  r  rC  r6  rg  rf  rP  r=  r.  rP  )r   rC  r   rv   s       r(   rh  Exif.load_from_fp  s     

!

 	&(DIQDI$::499E
;;**,,DK>ZZ__FV

 r'   c                   [        U 5      n[        R                  R                  U ;   a]  U R	                  U [        R                  R                     [        R                  R                  5      nU(       a  UR                  U5        [        R                  R                  U ;   a`  U R	                  U [        R                  R                     [        R                  R                  5      U[        R                  R                  '   U$ r   )rE  r   IFDr_  rF  updateGPSInfo)r   merged_dictifds      r(   _get_merged_dictExif._get_merged_dict  s    4j <<$$$T(,,*;*;%<hll>O>OPC""3' <<4'040B0BX\\))*HLL,@,@1K,,- r'   c                R   SSK Jn  U R                  5       nUR                  " US9nU R                  R                  5        H  u  pVXP;  d  M  XdU'   M     U R                  5        GH(  u  pWU[        R                  R                  [        R                  R                  4;   a  [        U[        5      (       d  U R                  U5      nU[        R                  R                  :X  a  [        R                  R                  U;   a  [        U[        R                  R                     [        5      (       dT  UR                  5       nU R                  [        R                  R                  5      U[        R                  R                  '   XtU'   GM+     SU-   UR                  U5      -   $ )Nr   rA  )ifhrN  )r   rv   rK  rC  r5  rL  r   rU  r_  rW  r   rE  get_ifdInteropr8  ri  )r   r   rv   rD  rY  rG  ifd_dictr  s           r(   ri  Exif.tobytes  s2   %~~33=!ZZ--/MC#C 0 **,JC!!$$  !--S)8<<,,, ,,5&uX\\-A-A'BDII!JJLE26,,x||?S?S2TE(,,../H ' %F(;;;r'   c           	     4   XR                   ;  GaD  U[        R                  R                  :X  a_  U R                  bP  U R                  R
                  S:w  a6  U R                  U R                  R
                  5      nUb  X R                   U'   GOU[        R                  R                  [        R                  R                  4;   aQ  U R                  R                  XR                  U5      5      nUb"  U R                  X15      nUb  X R                   U'   GO>U[        R                  R                  [        R                  R                  4;   Ga  [        R                  R                  U R                   ;  a)  U R                  [        R                  R                  5        U R                   [        R                  R                     U   nU[        R                  R                  :X  GaI  SSKJn  UR!                  S5      (       Ga/  [#        US5      nXFS  n0 n[%        [&        R(                  " SUS S 5      S   5       H  n	[&        R(                  " SXyS	-  S-   U	S-   S	-  S-    5      u  pp UR*                  U   u  nnX-  nUS
:  a'  [&        R(                  " SU5      u  nXsS	-
  UU-   S	-
   nOUS U n[/        U5      U:w  a*  [0        R2                  " SU S[/        U5       SU
 35        M  U(       d  M  U" U" 5       US5      X'   M     [5        U R7                  U5      5      U R                   U'   GOU R                  S5      S:X  Ga  0 n[%        [&        R(                  " SUS S 5      S   5       GH  n	[&        R(                  " SXIS	-  S-   U	S-   S	-  S-    5      u  ppU
S:X  d  M7  [&        R(                  " SU5      u  nU R8                  R;                  U5        SU R8                  R=                  S
5      0nU R8                  R=                  S
5        [#        U R8                  R=                  S	5      5      US'   U R8                  R=                  S
5        U R8                  R=                  S
5      US'   U R8                  R=                  S	5        U R8                  R=                  S
5      nUR*                  [>        R@                     S   nU" U" 5       US5      S   US'   U R8                  R=                  S
5        U R8                  R=                  S5      US'   SU0nGM     XR                   U'   O"U R                  XA5      nUb  X R                   U'   U R                   RC                  U0 5      nU[        R                  R                  :X  aq  U R                  (       a`  URE                  5        VVs0 s HC  u  nnU[        R                  R                  [        R                  R                  4;  d  M@  UU_ME     nnnU$ ! [,         a     GM  f = fs  snnf )Nr   r   )rC  s   FUJIFILMr_  z<Hr<   z<HHL4sr4   r>   z<Lz9Possibly corrupt EXIF MakerNote data.  Expecting to read z bytes but only got z. Skipping tag Fi  Nintendoz>Hz>HHL4si  z>LModelID	TimeStampInternalSerialNumberParallaxCategory)#r5  r   rU  IFD1r6  rP  rF  r_  rW  r4  ra  r_  	MakerNoter^  rv   rC  r  r   r  r  unpack_load_dispatchr   r   r  r  rE  r>  rC  r.  r  r   FLOAT
setdefaultrL  )r   rG  rY  r   tag_datarC  
ifd_offsetifd_data	makernoter  ifd_tagtypcountr  	unit_sizehandlerr'  
camerainfoparallaxrO  r  s                        r(   r^  Exif.get_ifd  s   jj hll'''::)djjoo.B,,TZZ__=C*-

3**HLL,@,@AA**..sHHSMB%,,V9C*-

3--x||/E/EFF<<$$DJJ6LL!2!23::hll&7&78=(,,000F**;77%*8Q%7
#+K#8$&	!&v}}T8BQ<'H'K!LA8> ((r6A:Q"q@P*Q95G%) %:$H$H$M!"$-$+ $)#4D#ax,2MM$,E	'/ftmb>P'Q'+ET{"4yD0 (%99=>R'*4yk	%K!"
 !)#' (18 5 7u2I.; "M@ +/t/?/?	/J*K

3&)Z7$&	!&v}}T8BQ<'H'K!LA8> ((r6A:Q"q@P*Q95G%  '&0,2MM$,E	 $V 4 %.tww||AF"
 !%Q:?R@P:Q
; 7 $QEIWW\\RS_
+A B $R 0+/77<<?*?*N*N$,NN+""#+% :A$9$;Xu:""#:%
: 6 !%Q9=a
: 6-3Z,@	A "MB +4

3 ,,X;C*-

3jj##C,(,,###(9(9 "iik)FQX\\118<<3I3IJJ 1)  
 
Q $, ) ()Fs   .X3?X6X
XXc                    [         R                  R                  [         R                  R                  4 H  nX;   d  M
  X   U R                  U'   X	 M     g r   )r   rU  r_  rW  r4  r   rG  s     r(   hide_offsetsExif.hide_offsetsa  sA    LL%%x||';';<C{)-!!#&I =r'   c                t    U R                   b  U R                    H  nX     M	     [        U R                  5      $ r   )r6  r  r3  r|  s     r(   __str__Exif.__str__g  s/    ::!zz	 " 4::r'   c                    [        U R                  5      nU R                  b  UR                  U R                  5        [	        U5      $ r   )setr3  r6  rV  r   r   keyss     r(   __len__Exif.__len__o  s3    4::::!KK

#4yr'   c                    U R                   bV  XR                  ;  aG  XR                   ;   a8  U R                  U R                   U   5      U R                  U'   U R                   U	 U R                  U   $ r   )r6  r3  r:  r|  s     r(   __getitem__Exif.__getitem__u  sU    ::!c&;zz@Q"kk$**S/:DJJsO

3zz#r'   c                r    XR                   ;   =(       d#    U R                  S L=(       a    XR                  ;   $ r   )r3  r6  r|  s     r(   __contains__Exif.__contains__{  s)    jj RTZZt%;%Qzz@QRr'   c                r    U R                   b  XR                   ;   a  U R                   U	 X R                  U'   g r   r6  r3  )r   rG  r  s      r(   __setitem__Exif.__setitem__~  s+    ::!cZZ&7

3

3r'   c                r    U R                   b  XR                   ;   a  U R                   U	 g U R                  U	 g r   r  r|  s     r(   __delitem__Exif.__delitem__  s+    ::!cZZ&7

3

3r'   c                    [        U R                  5      nU R                  b  UR                  U R                  5        [	        U5      $ r   )r  r3  r6  rV  iterr  s     r(   __iter__Exif.__iter__  s3    4::::!KK

#Dzr'   )r3  r4  r5  r6  r7  rg  rC  rD  r{  )r  r   r  r   )r=  dict[int, Any]r  r  r   )r   r  rB  r/   r  zdict[int, Any] | None)r  r  )r  r  r  r  )rC  r  r   r/   r  r  )r  r  )r_  )r   r  r  r  )rG  r  r  r  r  r}  )rG  r  r  r   )rG  r  r  r-   )rG  r  r  r   r  r  )rG  r  r  r  )r  zIterator[int])r"   r#   r$   r%   r  rg  r  re  r`  r   r:  r>  rF  rK  rP  rh  rZ  ri  r^  r}  r  r  r  r  r  r  r  r&   r    r'   r(   r_  r_  C  s    B FJGG/@ 0400",0	0 	!:!."<0jXS 
 r'   r_  )r7   r   r  zTypeGuard[Image])r5   r   r  ztuple[tuple[int, ...], str])r   r  r  r  )r   r  r  r  )r   r  r  r  r{  r  )r    )
r   r  r   r  r   r   r   tuple[Any, ...]r  z)core.ImagingDecoder | ImageFile.PyDecoder)
r   r  r   r  r   r   r   r  r  z)core.ImagingEncoder | ImageFile.PyEncoder)r	  z<Callable[[ImagePointTransform], ImagePointTransform | float]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   )r   r  r'  r~  r  zbytes | SupportsArrayInterfacer   r  r   r   r  r   r   )r  r  r   r  r  r   )r  r  r   r  r'  r~  r  r   )r5   zImageQt.QImager  ImageFile.ImageFile)r5   r  r  r  )r'  r~  r  r  )r  N)rC  r  r   zLiteral['r']r  z"list[str] | tuple[str, ...] | Noner  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   rN  r  r   )r   r  r   zSequence[Image]r  r   )rq  r  r  zSCallable[[IO[bytes], str | bytes], ImageFile.ImageFile] | type[ImageFile.ImageFile]r  z$Callable[[bytes], bool | str] | Noner  r  )rq  r  r  r  r  r  )rq  r  r  z/Callable[[Image, IO[bytes], str | bytes], None]r  r  )rq  r  r  r  r  r  )rq  r  r	  r{   r  r  )r  r~   )r  r  r   ztype[ImageFile.PyDecoder]r  r  )r  r  r   ztype[ImageFile.PyEncoder]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(  zdict[str, str] | Noner  r  )
__future__r   r  atexitr   r{  loggingr  rZ  rE  r  rJ  rX  r  collections.abcr   r   r   r   enumr   typesr	   typingr
   r   r   r   r   r   r   r   r   r   r   r   _binaryr   r   r   
_deprecater   _utilr   r   r  
defusedxmlr   r   	getLoggerr"   r   RuntimeWarningr   r}  r+   r.   r  r0   r1   r   r   r   r  r9  r  r  r  r8   r:   rI   rQ   rT   rU   rV   rW   rX   r  r]   rd   ri   modulesmoduleitemsetattrr  r  r6   ro   FILTEREDHUFFMAN_ONLYRLEFIXEDTYPE_CHECKINGmmapxml.etree.ElementTreerp   IPython.lib.prettyrq   rr   rs   rt   ru   rv   _typingrw   rx   ry   rz   r|   r}   r   r   r   r   r   r   	byteorder_ENDIANr   MODESr  r   r   r   r   r   r   r   r   r   r   r  r  r   ABCr  rZ  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  r2  r  r  r  r  r0  registerclear_cache	_ExifBaser_  r    r'   r(   <module>r     s  6 # 
   	   	 	  
   H H   3 3
  ) ( ! ) & 
		8	$	~ 		Y 	 $ t #  ##?@ * @
 #gd$4d;;$T+;TBC D*m- 	
 # <4(    NNC W g 
w  
X		:vwID		4::.  J
 4#$$,,}}H$$L
((CJJE -0PPKKI      n CE@ EGI
D I	> 13
. 313
. 3
 (*#	2 I	
,	,). *Z@ GI(
( ((+(4C(.(4 GI(
( ((+(4C(.(:'L 'LTQ
FQQ.h .k&' k&'dM CGG (, 5611
11
%11 211 	11p 	+
+
+ 5+ 	+
 + +d 	;;
;;
;; );; 	;;
 ;; ;;|$X $	$( 	$U=p1	$1,/17F1
1h"# \ Z	
 \ ] ^ ^ _ ] ^ ^ _ ^ _  ^!" _#$ %& '( (y^jy^j/ 6
. 26{&"{&
{& 0{& 	{&D:7."  CJ 48	$ 1 
. 

D
	
""D"	".	*

"%G
G#DGORG
G844.>      ! sCx(IIJ9 JGx  KH  
[)RSTD
1v/00 	M	
 
	 
Q		3	4	4c!fn- 

s+   S  ,S  SSUA>UU