B ë˜Þ]s¬ã@s8ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z m Z mZddlmZmZddlmZmZmZmZy ddlZWn ek r¸ddlZeZYnXyddlmZmZWn$ek ròddlmZmZYnXe süt‚e e ¡Z!Gdd„de"ƒZ#Gd d „d e$ƒZ%Gd d „d e&ƒZ'e(d ƒZ)y:ddl m*Z+e e,e+ddƒkrvede,e+ddƒe fƒ‚Wn¢ek rZ-z‚e'ƒZ+e.e-ƒ /d¡r°e 0de"¡nXe.e-ƒ /d¡rÒe 0e.e-ƒe"¡n6de.e-ƒkrîe 0de"¡nde.e-ƒkre 0de"¡‚WddZ-[-XYnXe1edƒZ2y ddl3Z3Wnek rLdZ3YnXyddl4m5Z5dZ6WnFek r¨yddl7m5Z5dZ6Wnek r¢dZ6YnXYnXdd„Z8dZ9dZ:dZ;dZd!Z?d"Z@dZAdZBdZCdZDd ZEdZFZ9d ZGdZHZId!ZJdZKZLdZMZNdZFZ9dZOdZPdZQdZRdZSdZTdZUdZVdZWdZXdZYdZZe1e+d#ƒrpe+j[Z[e+j\Z\e+j]Z]e+j^Z^e+j_Z_gZ`iZaiZbiZciZdiZeiZfiZgd$d%d&d'd(d)d*d+d,d-d.d/d0œ Zhejid1krÀd2Zjnd3Zjd4d5d6ejd7dfejd8dfd5d9d:d:d:d9d9d9d;dd=d?d@d?dAdBdAdCœZkdDdE„ZlemehƒZndFZodGdH„ZpdIdJ„ZqdKdL„ZrdMdN„ZsdatdOdP„ZudQdR„Zvd¾dTdU„Zwd¿dVdW„ZxdXdY„ZyGdZd[„d[e&ƒZzd\d]„Z{Gd^d_„d_e&ƒZ|Gd`da„dae&ƒZ}Gdbdc„dce&ƒZ~ddde„Zdfdg„Z€dÀdhdi„ZdÁdkdl„Z‚dmdn„ZƒdÂdodp„Z„dÃdqdr„Z…dsdt„Z†dudv„Z‡dwdxdydzd{d|d}d~dd€dd‚dƒd„d…d†d‡dˆd‰œZˆdŠeˆd‹ejd7f<dŒeˆd‹ejd8f<ddŽ„Z‰dÄdd‘„ZŠd’d“„Z‹d”d•„ZŒd–d—„Zd˜d™„ZŽdšd›„ZdÅdœd„ZdždŸ„Z‘d d¡„Z’d¢d£„Z“d¤d¥„Z”d¦d§„Z•d¨d©„Z–dªd«„Z—d¬d­„Z˜d®d¯„Z™dÆd°d±„Zšd²d³„Z›d´dµ„Zœd¶d·„Zd¸d¹„ZždÇdºd»„ZŸeŸƒe  e+j¡¡Gd¼d½„d½eƒZ¢dS)ÈéNé)ÚPILLOW_VERSIONÚ ImageModeÚTiffTagsÚ __version__Ú_plugins)Úi8Úi32le)Údeferred_errorÚisPathÚ isStringTypeÚpy3)ÚCallableÚMutableMappingc@s eZdZdS)ÚDecompressionBombWarningN)Ú__name__Ú __module__Ú __qualname__©rrú+/tmp/pip-build-ktz6qwqq/Pillow/PIL/Image.pyrBsrc@s eZdZdS)ÚDecompressionBombErrorN)rrrrrrrrFsrc@seZdZdd„ZdS)Ú_imaging_not_installedcCs tdƒ‚dS)Nz&The _imaging C module is not installed)Ú ImportError)ÚselfÚidrrrÚ __getattr__Lsz"_imaging_not_installed.__getattr__N)rrrrrrrrrJsriUUU)Ú_imagingrzjThe _imaging extension was built for another version of Pillow or PIL: Core version: %s Pillow version: %szModule use of pythonz?The _imaging extension was built for another version of Python.zThe _imaging extensionz!Symbol not found: _PyUnicodeUCS2_zxThe _imaging extension was built for Python with UCS2 support; recompile Pillow or build Python --without-wide-unicode. z!Symbol not found: _PyUnicodeUCS4_zuThe _imaging extension was built for Python with UCS4 support; recompile Pillow or build Python --with-wide-unicode. Úpypy_version_info)ÚPathTFcCs t|dƒS)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 Úim)Úhasattr)ÚtrrrÚ isImageType™s r"éééééÚDEFAULT_STRATEGY)ÚLr))Ú1)r)r))r))r)ÚI)r+)r)ÚF)r,)ÚPr))r-)ÚRGBr))ÚRÚGÚB)r.r))r/r0r1ÚX)r.r))r/r0r1ÚA)r.r))ÚCÚMÚYÚK)r.r))r6ZCbZCr)r.r))r)r3r1)r.r))ÚHÚSÚV) r*r)r+r,r-r.ÚRGBXÚRGBAÚCMYKÚYCbCrÚLABÚHSVÚlittleú<ú>)z|b1N)z|u1N)z|u1r#Úi4Zf4)z|u1r$)z|u1r%)zu2N)zi2N)zu4N)zi4N)r*r)ÚLAr+r,r-r.r;r<r=r>r?r@zI;16zI;16BzI;16LzI;16SzI;16BSzI;16LSzI;32zI;32BzI;32LzI;32SzI;32BSzI;32LScCsLt|j\}}|dkr.|jd|jdf|fS|jd|jd|f|fSdS)Nrr)Ú _MODE_CONVÚmodeÚsize)rÚtypÚextrarrrÚ_conv_type_shape(srK)r)r-r;r<r=zI;16zI;16LzI;16BcCs t |¡jS)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ÚgetmodeZbasemode)rGrrrÚ getmodebase7s rMcCs t |¡jS)a  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. )rrLZbasetype)rGrrrÚ getmodetypeDs rNcCs t |¡jS)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. )rrLÚbands)rGrrrÚgetmodebandnamesPs rPcCstt |¡jƒS)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. )ÚlenrrLrO)rGrrrÚ getmodebands_srRcCsútdkr dSyddlm}|s"t‚Wntk r8YnXyddlm}|sPt‚Wntk rfYnXyddlm}|s~t‚Wntk r”YnXyddlm}|s¬t‚Wntk rÂYnXyddlm}|sÚt‚Wntk rðYnXdadS)z-Explicitly load standard file format drivers.rN)ÚBmpImagePlugin)ÚGifImagePlugin)ÚJpegImagePlugin)ÚPpmImagePlugin)ÚPngImagePlugin) Ú _initializedÚrSÚAssertionErrorrrTrUrVrW)rSrTrUrVrWrrrÚpreinitps8          r[c Cs†tdkr dSxdtD]\}y&t d|¡td|tƒtƒgƒWqtk rl}zt d||¡Wdd}~XYqXqWtszt r‚dadSdS)zw Explicitly initializes the Python Imaging Library. This function loads all available file format drivers. r#rz Importing %szPIL.%szImage: failed to import %s: %sNr) rXrÚloggerÚdebugÚ __import__ÚglobalsÚlocalsrÚOPENÚSAVE)ZpluginÚerrrÚinitžs  $rdrcCs”|dkrd}nt|tƒs|f}yt|}||f||žŽStk rLYnXy tt|dƒ}||f||žŽStk rŽtd|ƒ‚YnXdS)NrÚ_decoderzdecoder %s not available)Ú isinstanceÚtupleÚDECODERSÚKeyErrorÚgetattrÚcoreÚAttributeErrorÚIOError)rGÚ decoder_nameÚargsrJÚdecoderrrrÚ _getdecoder¸s rqcCs”|dkrd}nt|tƒs|f}yt|}||f||žŽStk rLYnXy tt|dƒ}||f||žŽStk rŽtd|ƒ‚YnXdS)NrÚ_encoderzencoder %s not available)rfrgÚENCODERSrirjrkrlrm)rGÚ encoder_namerorJÚencoderrrrÚ _getencoderÍs rvcCst|tƒr|St|ƒS)N)rfÚ_E)ÚvaluerrrÚcoerce_eæsryc@s$eZdZdd„Zdd„Zdd„ZdS)rwcCs ||_dS)N)Údata)rrzrrrÚ__init__ësz _E.__init__cCst|jdt|ƒjfƒS)NÚ__add__)rwrzry)rÚotherrrrr|îsz _E.__add__cCst|jdt|ƒjfƒS)NÚ__mul__)rwrzry)rr}rrrr~ñsz _E.__mul__N)rrrr{r|r~rrrrrwêsrwcCsîdg}|t|ƒƒj}yV|\}}}||krD|dkrDt|tjƒrD|dfS||krh|dkrht|tjƒrhd|fSWntk r~YnXyL|\\}}}}}||krÊ|dkrÊt|tjƒrÊ|dkrÊt|tjƒrÊ||fSWntk ràYnXtdƒ‚dS)NÚstubr~gr|gð?zillegal expression)rwrzrfÚnumbersÚNumberÚ TypeErrorÚ ValueError)ÚexprrrzÚaÚbÚcÚdrcrrrÚ_getscaleoffsetõs*     r‰c@sÆeZdZdZdZdZdZdd„Zedd„ƒZ edd „ƒZ ed d „ƒZ d d „Z dd„Z dd„Zdd„Zejjdkrxdd„Zdd„Zdd„Zdšdd„Zdd„Zdd „Zd!d"„Zd#d$„Zed%d&„ƒZd'd(„Zd)d*„Zd›d,d-„Zd.d/„Zdœd1d2„Z dd3d4„Z!d5d6„Z"d7d8„Z#d9d:„Z$ddde%d;fddodp„Z?d©dsdt„Z@dªdvdw„ZAdxdy„ZBd«dzd{„ZCeDdfd|d}„ZEeDd>dddfd~d„ZFd¬d€d„ZGd‚dƒ„ZHd­d„d…„ZId†d‡„ZJdˆd‰„ZKdŠd‹„ZLeMfdŒd„ZNdeDd?dfdŽd„ZOeDd?fdd‘„ZPd’d“„ZQd”d•„ZRd–d—„ZSd˜d™„ZTdS)®ÚImageaD 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` NTcCs:d|_d|_d|_d|_i|_t|_d|_d|_d|_ dS)NrY)rrr) rrGÚ_sizeÚpaletteÚinfoÚNORMALÚcategoryÚreadonlyÚpyaccessÚ_exif)rrrrr{#szImage.__init__cCs |jdS)Nr)rH)rrrrÚwidth0sz Image.widthcCs |jdS)Nr)rH)rrrrÚheight4sz Image.heightcCs|jS)N)r‹)rrrrrH8sz Image.sizecCs`tƒ}||_|j|_|j|_|jdkrP|jr:|j ¡|_nddlm}| ¡|_|j  ¡|_ |S)N)r-ÚPAr)Ú ImagePalette) rŠrrGrHr‹rŒÚcopyrYr–r)rrÚnewr–rrrÚ_new<s    z Image._newcCs|S)Nr)rrrrÚ __enter__LszImage.__enter__cGsBt|dƒr8t|ddƒr8t|dƒr(| ¡|jr8|j ¡d|_dS)NÚfpÚ _exclusive_fpFÚ _close__fp)r rjrr›Úclose)rrorrrÚ__exit__Os   zImage.__exit__c Cszy&t|dƒr| ¡|j ¡d|_Wn.tk rT}zt d|¡Wdd}~XYnXt|ddƒrhd|_t t dƒƒ|_ dS)a’ Closes the file pointer, if possible. This operation will destroy the image core and release its memory. The image data will be unusable afterward. This function is only required to close images that have not had their file read and closed by the :py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for more information. rNzError closing: %sÚmapzOperation on closed image) r rr›ržÚ Exceptionr\r]rjr r rƒr)rÚmsgrrrržWs     z Image.closer$cCs | ¡dS)N)rŸ)rrrrÚ__del__usz Image.__del__cCs$| ¡|j ¡|_d|_d|_dS)Nr)Úloadrr—r‘r)rrrrÚ_copyxs z Image._copycCs|jr| ¡n| ¡dS)N)rr¥r¤)rrrrÚ_ensure_mutable~s zImage._ensure_mutablecKs‚ddl}d}|rd|}|s6| |¡\}}t |¡n|}| |¡sL||}| ¡|r`|dkrn|j |¡n|j||f|Ž|S)NrrYÚ.ZPPM) ÚtempfileÚmkstempÚosržÚendswithr¤rZsave_ppmÚsave)rÚfileÚformatÚoptionsr¨ÚsuffixÚfÚfilenamerrrÚ_dump„s   z Image._dumpcCsh|j|jkof|j|jkof|j|jkof|j|jkof|j|jkof|j|jkof| ¡| ¡kof| ¡| ¡kS)N)Ú __class__rGrHrrrÚ getpaletteÚtobytes)rr}rrrÚ__eq__œs      z Image.__eq__cCs||k}| S)Nr)rr}ÚeqrrrÚ__ne__¨sz Image.__ne__cCs.d|jj|jj|j|jd|jdt|ƒfS)Nz(<%s.%s image mode=%s size=%dx%d at 0x%X>rr)r´rrrGrHr)rrrrÚ__repr__¬szImage.__repr__cCst ¡}| |d¡| ¡S)z[ iPython display hook support :returns: png version of the image as bytes ZPNG)ÚioÚBytesIOr¬Úgetvalue)rr†rrrÚ _repr_png_¶s zImage._repr_png_cCsTi}t|ƒ\}}||d<||d<d|d<|jdkrD| dd¡|d<n | ¡|d<|S) NÚshapeÚtypestrr$Úversionr*Úrawr)rz)rKrGr¶)rr˜r¿rÀrrrÚ__array_interface__¿s   zImage.__array_interface__cCs|j|j|j| ¡| ¡gS)N)rrGrHrµr¶)rrrrÚ __getstate__ÏszImage.__getstate__cCsbt |¡g|_|\}}}}}||_||_||_t ||¡|_|dkrT|rT|  |¡|  |¡dS)N)r)rEr-r•) rŠr{ZtilerrGr‹rkr˜rÚ putpaletteÚ frombytes)rÚstaterrGrHrŒrzrrrÚ __setstate__Òs   zImage.__setstate__rÂc Gs¶t|ƒdkr"t|dtƒr"|d}|dkr8|dkr8|j}| ¡t|j||ƒ}| |j¡td|j ddƒ}g}x$|  |¡\}}}|  |¡|rtPqtW|dkr¬t d|ƒ‚d  |¡S) 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. :param args: Extra arguments to the encoder. :rtype: A bytes object. rrrÂrir%zencoder error %d in tobytesó)rQrfrgrGr¤rvÚsetimagerÚmaxrHÚencodeÚappendÚ RuntimeErrorÚjoin) rrtrorcÚbufsizerzÚlÚsrˆrrrr¶Þs"   z Image.tobytescOs tdƒ‚dS)Nz;tostring() has been removed. Please call tobytes() instead.)ÚNotImplementedError)rroÚkwrrrÚtostring szImage.tostringÚimagecCsj| ¡|jdkrtdƒ‚| d¡}d d||jdf d¡d||jd f d¡d | d¡|d g¡S) a- 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 bitmapZxbmrÉz#define %s_width %d rÚasciiz#define %s_height %d rzstatic char %s_bits[] = { s};)r¤rGrƒr¶rÏrHrÌ)rÚnamerzrrrÚtobitmaps    zImage.tobitmapcGsˆt|ƒdkr"t|dtƒr"|d}|dkr8|dkr8|j}t|j||ƒ}| |j¡| |¡}|ddkrptdƒ‚|ddkr„tdƒ‚dS)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. rrrÂrznot enough image datazcannot decode image dataN) rQrfrgrGrqrÊrÚdecoderƒ)rrzrnrorˆrÒrrrrÆ's     zImage.frombytescOs tdƒ‚dS)Nz?fromstring() has been removed. Please call frombytes() instead.)rÓ)rrorÔrrrÚ fromstringAszImage.fromstringcCsÜ|jrˆ|jrˆ|jjrˆ|jj|j ¡Žd|j_d|j_d|j_d|jkrˆt|jdt ƒrn|j  |jdd¡n|j  |jd¡d|j_|jrØt rÊt rÊ|jr¢|jSddlm}| ||j¡|_|jrÊ|jS|j |j¡SdS)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: :ref:`PixelAccess` or :py:class:`PIL.PyAccess` rr.NÚ transparencyr<r)ÚPyAccess)rrŒZdirtyrÅÚgetdatarGÚrawmoderrfÚintÚputpalettealphaÚputpalettealphasÚcffiÚUSE_CFFI_ACCESSr‘rYrÝr˜rZ pixel_access)rrÝrrrr¤Fs&  z Image.loadcCsdS)as 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)rrrrÚverifyms z Image.verifyéc s>| ¡|s*|jdkr*|jr&|jj}nd}|r<||jkrDˆsD| ¡S|j d¡dk }ˆrô|dkrhtdƒ‚|j |ˆ¡}|  |¡}|rð|jj dkrð|jd‰dd „‰|d kr¶ˆˆˆƒ‰n0t |ƒdkræt ‡‡‡fd d „t d t ˆƒƒDƒƒ‰ˆ|jd<|S|dkr|jdkr| |¡Sd} d} |rž|jdkr^|dkr^|  |j ||jd¡¡} | jd=| S|jdkr<|dkr<|jd} t| tƒršt d¡d} n tƒ  t |jd¡¡} |jdkr|  |j¡t| t ƒry| j | ¡} Wntk rtdƒ‚YnX|  d| ¡|dkr&|  |¡} n |  d¡} |  d¡} nb|jdkrž|dkrž|jd} d} t| tƒrz|j | ¡n$t| tƒr–|j | d ¡ntdƒ‚|dkrF|t krF|j |¡}|  |¡}ddl!m"}| #d|j $d¡¡|_| rø|jd=| dk rBy|j | ¡|jd<Wn(tk r@|jd=t d¡YnX|S|dkrTt%}y|j ||¡}WnXtk r¾y"|j t&|jƒ¡}| ||¡}Wnt'k r¸tdƒ‚YnXYnX|  |¡} | rØ| jd=| dk r:| jdkr0y| j | ¡| jd<Wn(tk r,| jd=t d¡YnXn | | jd<| S)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. The current version supports all possible conversions between "L", "RGB" and "CMYK." The **matrix** argument only supports "L" and "RGB". When translating a color image to greyscale (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 greyscale ("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 128 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. :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 NONE or 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 WEB or ADAPTIVE. :param colors: Number of colors to use for the ADAPTIVE palette. Defaults to 256. :rtype: :py:class:`~PIL.Image.Image` :returns: An :py:class:`~PIL.Image.Image` object. r-r.rÜN)r)r.zillegal conversionr$cSsP|d|d|d|d|d|d|dd}tdtdt|ƒƒƒS)Nrrr#r$gà?éÿ)rËÚminrà)ÚmÚvrrrÚconvert_transparency·s<z+Image.convert..convert_transparencyr)cs*g|]"}ˆˆ|d|dd…ˆƒ‘qS)r%r)Ú.0Úi)rëÚmatrixrÜrrú Àsz!Image.convert..rr<F)r*r)r+r.)r)r.r-zVPalette images with Transparency expressed in bytes should be converted to RGBA imagesT)rrz2Couldn't allocate a palette color for transparency)rrz.Transparency for P mode should be bytes or intr)r–z0Couldn't allocate palette entry for transparency)(r¤rGrŒr—rÚgetrƒrZconvert_matrixr™rOrQrgÚrangeÚquantizeZconvert_transparentrfÚbytesÚwarningsÚwarnrŠrkr˜rÅÚgetcolorr¡ÚputpixelÚconvertÚgetpixelrâràráÚADAPTIVErYr–rÂrµÚFLOYDSTEINBERGrMri)rrGrîÚditherrŒÚcolorsZhas_transparencyrr˜ZtrnsZ delete_trnsZnew_imr!Ztrns_imr–r)rërîrÜrrøxsÄ*                              z Image.convertrrc CsÚ| ¡|dkr"d}|jdkr"d}|jdkr<|dkrfilter argument should be ImageFilter.Filter instance or class)rYr r¤rfrr r‚ZMultibandFilterrrOr™r rñrÍÚgetbandÚmergerG)rr r Z multibandÚimsr‡rrrr »s    "z Image.filtercCst |j¡jS)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 )rrLrGrO)rrrrÚgetbands×szImage.getbandscCs| ¡|j ¡S)aQ Calculates the bounding box of the non-zero regions in the image. :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. )r¤rÚgetbbox)rrrrrás z Image.getbboxcCsl| ¡|jdkr`|j ¡}g}x*tdƒD]}||r*| |||f¡q*Wt|ƒ|kr\dS|S|j |¡S)a Returns a list of colors used in this image. :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)r¤rGrÚ histogramrñrÍrQÚ getcolors)rZ maxcolorsÚhÚoutrírrrrðs    zImage.getcolorscCs"| ¡|dk r|j |¡S|jS)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. N)r¤rr)rÚbandrrrrÞs z Image.getdatacCsV| ¡|jjdkrLg}x*t|jjƒD]}| |j |¡ ¡¡q&Wt|ƒS|j ¡S)a& Gets the 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)r¤rrOrñrÍrÚ getextremarg)rÚextremarírrrrs  zImage.getextremacCs,|jdkrtƒ|_|j |j d¡¡|jS)NZexif)r’ÚExifr¤rrð)rrrrÚgetexif/s z Image.getexifcCs| ¡|jjS)zr Returns a capsule that points to the internal image memory. :returns: A capsule object. )r¤rÚptr)rrrrÚgetim5sz Image.getimcCsL| ¡y*trt|j ¡ƒSdd„|j ¡DƒSWntk rFdSXdS)z  Returns the image palette as a list. :returns: A list of color values [r, g, b, ...], or None if the image has no palette. cSsg|] }t|ƒ‘qSr)r)rìr‡rrrrïLsz$Image.getpalette..N)r¤r Úlistrrµrƒ)rrrrrµ?szImage.getpalettecCs&| ¡|jr|j |¡S|j |¡S)a  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. )r¤r‘rùr)rÚxyrrrrùPs  zImage.getpixelcCs2| ¡|j ¡\}}dd„|Dƒdd„|DƒfS)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. cSsg|] }t|ƒ‘qSr)r)rìr‡rrrrïisz'Image.getprojection..)r¤rÚ getprojection)rÚxÚyrrrr _szImage.getprojectioncCsT| ¡|r$| ¡|j d|j¡S|jdkrJ|dkr>| ¡}|j |¡S|j ¡S)ae 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. 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 greyscale ("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 greyscale image ("L"). :param mask: An optional mask. :param extrema: An optional tuple of manually-specified extrema. :returns: A list containing pixel counts. )rr)r+r,N)r¤rrrGr)rÚmaskrrrrrks  zImage.histogramcCsT| ¡|r$| ¡|j d|j¡S|jdkrJ|dkr>| ¡}|j |¡S|j ¡S)ah Calculates and returns the entropy for the image. A bilevel image (mode "1") is treated as a greyscale ("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 greyscale image ("L"). :param mask: An optional mask. :param extrema: An optional tuple of manually-specified extrema. :returns: A float value representing the image entropy )rr)r+r,N)r¤rÚentropyrGr)rr#rrrrr$‰s  z Image.entropycCs tdƒ‚dS)NzCoffset() has been removed. Please call ImageChops.offset() instead.)rÓ)rZxoffsetZyoffsetrrrÚoffset£sz Image.offsetcCst|ƒr|dkr|}d}|dkr$d}t|ƒdkr|t|ƒr@|j}nt|ƒrP|j}ntdƒ‚||d|d|d|df7}t|ƒr ddlm}| ||j¡}nBt|ƒrâ|  ¡|j|jkrÜ|jdksÐ|jd krÜ|  |j¡}|j }|  ¡|r |  ¡|j   |||j ¡n|j   ||¡dS) 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" or "RGBA" images (in the latter case, 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 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. N)rrr#z,cannot determine region size; use 4-item boxrr)Ú ImageColorr.)r<ÚRGBa)r"rQrHrƒr rYr&rörGr¤rørr¦Úpaste)rrrr#rHr&rrrr(¨s4( $   z Image.paste©rrcCst|ttfƒstdƒ‚t|ttfƒs,tdƒ‚t|ƒdkr@tdƒ‚t|ƒdksTtdƒ‚t|ƒdkrhtdƒ‚t|ƒdkr|td ƒ‚t|ƒdkr’||j}|d |jkr¦|}n | |¡}||d|j|d |j f}|d |jkrä|}n | |¡}t ||ƒ}|  ||¡d S) 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. zSource must be a tuplezDestination must be a tuple)r#r%zSource must be a 2 or 4-tupler#zDestination must be a 2-tuplerzSource must be non-negativez Destination must be non-negative)rrrN) rfrrgrƒrQrèrHrr“r”Úalpha_compositer()rrÚdestÚsourceZoverlayrZ backgroundÚresultrrrr*øs.          zImage.alpha_compositecs’| ¡tˆtƒrˆ |¡Stˆƒrl|jdkrNtˆƒ\}}| |j  ||¡¡S‡fdd„t dƒDƒ|jj ‰|jdkr~t dƒ‚| |j ˆ|¡¡S)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. :param mode: Output mode (default is same as input). In the current version, 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+zI;16r,csg|] }ˆ|ƒ‘qSrr)rìrí)ÚlutrrrïGszImage.point..rær,z+point operation not supported for this mode) r¤rfÚImagePointHandlerÚpointÚcallablerGr‰r™rZpoint_transformrñrOrƒ)rr.rGÚscaler%r)r.rr0(s     z Image.pointc Cs@| ¡|jdkr ylt|jƒd}y|j |¡Wn8ttfk rj|j |¡}|jdkr`t‚||_YnXd|_|jj|_Wn t tfk ržtdƒ‚YnX|jdkr°d}nd}t |ƒrì|jdkrÎtdƒ‚|  ¡|jd krê| d ¡}n@y|j  ||¡Wn(ttfk r&t d |j|ƒ}YnXdS|j |j|¡dS) az 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 or other color value. )rEr•r<r3Nzillegal image mode)rEr•rr$)r*r)r*r))r¦rGrMrZsetmoderlrƒrør‘rir"r¤Zfillbandr˜rHZputband)rÚalpharGrrrrrÚputalphaOs<         zImage.putalphaçð?çcCs| ¡|j |||¡dS)a Copies pixel data to this image. This method copies data from a sequence object into the image, starting at the upper left corner (0, 0), and continuing 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 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)r¦rÚputdata)rrzr2r%rrrr7…s z Image.putdatar.cCsªddlm}|jdkrtdƒ‚| ¡t||jƒrD| |j|j¡}n8t|t ƒspt r\t |ƒ}nd  dd„|Dƒ¡}| ||¡}d|jkrŠd nd |_||_d |j_| ¡d S) aî Attaches a palette to this image. The image must be a "P", "PA", "L" or "LA" image, and the palette sequence must contain 768 integer values, where each group of three values represent the red, green, and blue values for the corresponding pixel index. Instead of an integer sequence, you can use an 8-bit string. :param data: A palette sequence (either a list or a string). :param rawmode: The raw mode of the palette. r)r–)r)rEr-r•zillegal image moderYcss|]}t|ƒVqdS)N)Úchr)rìr!rrrú ®sz#Image.putpalette..r3r•r-r.N) rYr–rGrƒr¤rfrÂrßrŒrór rÏ)rrzrßr–rŒrrrrÅ–s      zImage.putpalettecCsh|jr| ¡| ¡|jr*|j ||¡S|jdkrZt|ttfƒrZt |ƒdkrZ|j   |¡}|j  ||¡S)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 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. r-)r$r%) rr¥r¤r‘r÷rGrfrrgrQrŒrör)rrrxrrrr÷µs   zImage.putpixelc Cs*ddlm}|jdkrtdƒ‚|dkr^|jdkrF|j d¡dd…}qbtd d „tdƒDƒƒ}n|}d }d gd }x8t|ƒD],\}}|||d|dd…7}|||<qzWt|ƒ} |  ¡} d| _|jd| ddd| _ | jj | j   ¡Ž|   d¡} |dt|ƒd} |   | ¡|jd|t|ƒd| _ | S)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)r–)r)r-zillegal image modeNr-r.icss|]}|dVqdS)r$Nr)rìrírrrr9ïsz&Image.remap_palette..rÉrrær$)rŒrHr)ó)rYr–rGrƒrrµÚ bytearrayrñÚ enumerater—rŒrÅrÞrørQ) rZdest_mapZsource_paletter–Zreal_source_paletteZ palette_bytesZ new_positionsríÚ oldPositionZmapping_paletteZm_imZnew_palette_bytesrrrÚ remap_paletteÛs2       zImage.remap_palettecCs(|ttttttfkrzd |¡}dd„tdftdftdftdftdftd ffDƒ}t|d d  |d d …¡d|d ƒ‚t |ƒ}|d kr–d|j }nt |ƒ}|j |kr¾|d|j kr¾|  ¡S|j dkrÌt}|j dkr |  |j d d …d¡}| |||¡}|  |j ¡S| ¡| |j |||¡¡S)aƒ Returns a resized copy of this image. :param size: The requested size in pixels, as a 2-tuple: (width, height). :param resample: An optional resampling filter. This can be one of :py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BOX`, :py:attr:`PIL.Image.BILINEAR`, :py:attr:`PIL.Image.HAMMING`, :py:attr:`PIL.Image.BICUBIC` or :py:attr:`PIL.Image.LANCZOS`. If omitted, or if the image has mode "1" or "P", it is set :py:attr:`PIL.Image.NEAREST`. See: :ref:`concept-filters`. :param box: An optional 4-tuple of floats giving the region of the source image which should be scaled. The values should be within (0, 0, width, height) rectangle. If omitted or None, the entire source is used. :returns: An :py:class:`~PIL.Image.Image` object. zUnknown resampling filter ({}).cSs g|]}d |d|d¡‘qS)z{} ({})rr)r®)rìr rrrrï>sz Image.resize..z Image.NEARESTz Image.LANCZOSzImage.BILINEARz Image.BICUBICz Image.BOXz Image.HAMMINGz Use z, Néÿÿÿÿz or )rr)r*r-)rEr<r…)ÚNEARESTÚBILINEARÚBICUBICÚLANCZOSÚBOXÚHAMMINGr®rƒrÏrgrHr—rGrøÚresizer¤r™r)rrHÚresamplerÚmessageÚfiltersrrrrrF&s2 (    z Image.resizecCs2|d}|s^|s^|dkr | ¡S|dkr2| t¡S|dkrH|rH| t¡S|dkr^|r^| t¡S|j\}}|dkrvd} n|} |dkr”|d|df} n|} t |¡ }tt  |¡d ƒtt  |¡d ƒd tt  |¡ d ƒtt  |¡d ƒd g} d d „} | | d | d| d  | d | ƒ\| d<| d<| d| d7<| d| d 7<|rg} g}xJd|df||fd|ffD].\}}| ||| ƒ\}}|   |¡|  |¡qrWt t  t| ƒ¡t t| ƒ¡ƒ}t t  t|ƒ¡t t|ƒ¡ƒ}| || d|| d| ƒ\| d<| d<||}}|j||ft| ||dS)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:attr:`PIL.Image.NEAREST` (use nearest neighbour), :py:attr:`PIL.Image.BILINEAR` (linear interpolation in a 2x2 environment), or :py:attr:`PIL.Image.BICUBIC` (cubic spline interpolation in a 4x4 environment). If omitted, or if the image has mode "1" or "P", it is set :py:attr:`PIL.Image.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é´éZiN)rrg@égc Ss8|\}}}}}}||||||||||fS)Nr) r!r"rîr…r†r‡rˆrcr±rrrÚ transformºszImage.rotate..transformrr#r&)Ú fillcolor)r—Ú transposeÚ ROTATE_180Ú ROTATE_90Ú ROTATE_270rHÚmathÚradiansrÚcosÚsinrÍràÚceilrËÚfloorrèrMÚAFFINE)rZanglerGr ÚcenterÚ translaterNÚwrZ post_transZ rotn_centerrîrMZxxÚyyr!r"ÚnwZnhrrrÚrotatebsR"       2"   , z Image.rotatec KsRd}d}t|ƒr|}d}ntr4t|tƒr4t|ƒ}d}|sRt|dƒrRt|jƒrR|j}| ¡| dd¡}||_ d|_ t ƒt j  |¡d ¡}|sÎ|tkržtƒy t|}Wn"tk rÌtd |¡ƒ‚YnX| ¡tkràtƒ|ròt| ¡}n t| ¡}|r,| d d¡r t |d ¡}n t |d ¡}z||||ƒWd |rL| ¡Xd S) 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), pathlib.Path 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. :returns: None :exception ValueError: If the output format could not be determined from the file name. Use the format option to solve this. :exception IOError: If the file could not be written. The file may have been created, and may contain partial data. rYFTrØÚsave_allrrzunknown file extension: {}rÍzr+bzw+bN)r Ú HAS_PATHLIBrfrÚstrr rØr¦ÚpopZ encoderinfoZ encoderconfigr[rªÚpathÚsplitextÚlowerÚ EXTENSIONrdrirƒr®ÚupperrbÚSAVE_ALLrðÚbuiltinsÚopenrž) rr›r®Úparamsr²Zopen_fpr`ÚextZ save_handlerrrrr¬×sH     z Image.savecCs|dkr t‚dS)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`. :param frame: Frame number, starting at 0. :exception EOFError: If the call attempts to seek beyond the end of the sequence. rN)ÚEOFError)rÚframerrrÚseek*sz Image.seekcCst|||ddS)a… Displays this image. This method is mainly intended for debugging purposes. 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 **display**, **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. :param command: command used to show the image )ÚtitleÚcommandN)Ú_show)rrqrrrrrÚshow<sz Image.showcCs:| ¡|jjdkr | ¡g}nt|j|j ¡ƒ}t|ƒS)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)r¤rrOr—r r™Úsplitrg)rrrrrruRs   z Image.splitcCsX| ¡t|ƒrFy| ¡ |¡}Wn"tk rDtd |¡ƒ‚YnX| |j |¡¡S)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 zThe image has no channel "{}") r¤r rÚindexrƒr®r™rr)rZchannelrrrÚ getchannelgs zImage.getchannelcCsdS)z‹ Returns the current frame number. See :py:meth:`~PIL.Image.Image.seek`. :returns: Frame number, starting with 0. rr)rrrrÚtell|sz Image.tellcCsÎ|j\}}||dkr.z Image.NEARESTzImage.BILINEARz Image.BICUBICz Use z, r?z or )r*r-)rYÚEXTENTÚfloatÚ PERSPECTIVEr~rƒr@rArBrDrErCr®rÏr¤rGrZ transform2)rrrÖrþrzrGrzr\rrrrrÚxsZysr^ÚswÚseÚneZAsZAtrHrIrrrZ __transformer s^      "( ( zImage.__transformercCs| ¡| |j |¡¡S)a¶ Transpose image (flip or rotate in 90 degree steps) :param method: One of :py:attr:`PIL.Image.FLIP_LEFT_RIGHT`, :py:attr:`PIL.Image.FLIP_TOP_BOTTOM`, :py:attr:`PIL.Image.ROTATE_90`, :py:attr:`PIL.Image.ROTATE_180`, :py:attr:`PIL.Image.ROTATE_270`, :py:attr:`PIL.Image.TRANSPOSE` or :py:attr:`PIL.Image.TRANSVERSE`. :returns: Returns a flipped or rotated copy of this image. )r¤r™rrO)rrþrrrrOP s zImage.transposecCs| ¡| |j |¡¡S)zj Randomly spread pixels in an image. :param distance: Distance to spread pixels. )r¤r™rÚ effect_spread)rZdistancerrrr‡^ szImage.effect_spreadcCs$ddlm}|jstdƒ‚| |¡S)z#Returns a QImage copy of this imager)ÚImageQtzQt bindings are not installed)rYrˆÚqt_is_installedrÚtoqimage)rrˆrrrrŠg s zImage.toqimagecCs$ddlm}|jstdƒ‚| |¡S)z$Returns a QPixmap copy of this imager)rˆzQt bindings are not installed)rYrˆr‰rÚ toqpixmap)rrˆrrrr‹o s zImage.toqpixmap)NN)rÂ)rÖ)rÂ)ræNrNr)N)N)ræ)N)NN)NN)N)NN)r)r))N)r5r6)r.)N)N)NN)UrrrÚ__doc__r®Úformat_descriptionZ!_close_exclusive_fp_after_loadingr{Úpropertyr“r”rHr™ršrŸržÚsysÚ version_infoÚmajorr£r¥r¦r³r·r¹rºr¾rÃrÄrÈr¶rÕrÙrÆrÛr¤råÚWEBrøròr—Ú__copy__rrÿr r r rrrrÞrrrrµrùr rr$r%r(r*r0r4r7rÅr÷r>r@rFr_r¬rprtrurwrxrBryrMr}rOr‡rŠr‹rrrrrŠs¢          +  ' = 9           P 0 '6  & K? n S  3PI rŠc@s eZdZdS)r/N)rrrrrrrr/| sr/c@s eZdZdS)r{N)rrrrrrrr{ sr{cCstƒ t d¡¡S)z+Create greyscale wedge (for debugging only)r))rŠr™rkZwedgerrrrÚ_wedge sr”cCsNt|ttfƒstdƒ‚t|ƒdkr*tdƒ‚|ddksB|ddkrJtdƒ‚dS)zª Common check to enforce type and sanity check on size tuples :param size: Should be a 2 tuple of (width, height) :returns: True, or raises a ValueError zSize must be a tupler#z Size must be a tuple of length 2rrzWidth and height must be >= 0T)rfrrgrƒrQ)rHrrrÚ _check_size“ s r•cCs¢t|ƒ|dkr$tƒ t ||¡¡St|ƒrDddlm}| ||¡}tƒ}|dkrŽt |t t fƒrŽt |ƒdkrŽddlm }|  ¡|_|j |¡}| t |||¡¡S)a™ 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 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. Nr)r&r-)r$r%)r–)r•rŠr™rkr˜r rYr&rörfrrgrQr–rŒrz)rGrHÚcolorr&rr–rrrr˜¥ s  "   r˜rÂcGsZt|ƒt|ƒdkr*t|dtƒr*|d}|dkr>|dkr>|}t||ƒ}| |||¡|S)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 Decoder `. 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. rrrÂr)r•rQrfrgr˜rÆ)rGrHrzrnrorrrrrÆÌ s rÆcOs tdƒ‚dS)Nz?fromstring() has been removed. Please call frombytes() instead.)rÓ)rorÔrrrrÛò srÛc Gsžt|ƒt|ƒdkr*t|dtƒr*|d}|dkrŽ|dkrTtjdtdd|ddf}|dtkrŽt|d ƒ}|  t   |||d d|¡¡}d|_ |St |||||ƒS) aä 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 **BytesIO** object, and use :py:func:`~PIL.Image.open` to load it. In the current version, 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 rrrÂrzthe frombuffer defaults will change in Pillow 7.0.0; for portability, change the call to read: frombuffer(mode, size, data, 'raw', mode, 0, 1)r#)Ú stacklevelr?)rrN)r•rQrfrgrôrõÚRuntimeWarningÚ _MAPMODESr˜r™rkZ map_bufferrrÆ)rGrHrzrnrorrrrÚ frombufferø s #   ršc Csö|j}|d}t|ƒ}| dd¡}|dkrry(d|dd…|df}t|\}}Wqvtk rntdƒ‚YqvXn|}|dkr„d}n|d kr’d }nd }||kr®td ||fƒ‚|d |df} |dk rât|dƒrÚ| ¡}n|  ¡}t || |d|dd ƒS)a¨ Creates an image memory from an object exporting the array interface (using the buffer protocol). If **obj** is not contiguous, then the tobytes method is called and :py:func:`~PIL.Image.frombuffer` is used. If you have an image in NumPy:: from PIL import Image import numpy as np im = Image.open('hopper.jpg') a = np.asarray(im) Then this can be used to convert it to a Pillow image:: im = Image.fromarray(a) :param obj: Object with array interface :param mode: Mode to use (will be determined from type if None) See: :ref:`concept-modes`. :returns: An image object. .. versionadded:: 1.1.6 r¿ÚstridesN)rrr#rÀzCannot handle this data type)r*r)r+r-r,r.r$r%zToo many dimensions: %d > %d.rrr¶rÂ) rÃrQrðÚ_fromarray_typemaprir‚rƒr r¶rÕrš) ÚobjrGZarrr¿Úndimr›ZtypekeyrßZndmaxrHrrrÚ fromarray4 s0   rŸcCs$ddlm}|jstdƒ‚| |¡S)z-Creates an image instance from a QImage imager)rˆzQt bindings are not installed)rYrˆr‰rÚ fromqimage)rrˆrrrr m s r cCs$ddlm}|jstdƒ‚| |¡S)z.Creates an image instance from a QPixmap imager)rˆzQt bindings are not installed)rYrˆr‰rÚ fromqpixmap)rrˆrrrr¡v s r¡)r*z1;8)r)r))r+zI;8)r+zI;16)r+zI;16B)r+zI;16S)r+zI;16BS)r+zI;32)r+zI;32B)r+zI;32S)r+zI;32BS)r,zF;32F)r,zF;32BF)r,zF;64F)r,zF;64BF)rErE)r.r.)r<r<)))rrz|b1))rrz|u1))rrz|i1))rrzu2))rrzi2))rrzu4))rrzi4))rrzf4))rrzf8))rrr#z|u1))rrr$z|u1))rrr%z|u1)r+r+)rr)r,r,cCs\tdkr dS|d|d}|dtkr._open_coreNzcannot identify image file %r)rƒrarfrrbÚresolver rjrkrprlr»ÚUnsupportedOperationr¼Úreadr[rdrœržrôrõrm)r›rGr²r­r²rrHr)r°r±rrk¯ s@       rkcCs&| ¡| ¡| t |j|j¡¡S)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. )r¤r™rkr*r)Úim1Úim2rrrr* s r*cCs(| ¡| ¡| t |j|j|¡¡S)aŒ 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. )r¤r™rkÚblendr)r¶r·r3rrrr¸ sr¸cCs| ¡}| |d|¡|S)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)r—r()Zimage1Zimage2r#rÖrrrÚ composite/ s r¹cGs| |d¡S)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)r0)rÖrorrrÚeval@ s rºcCsžt|ƒt|ƒksd|kr tdƒ‚xB|dd…D]2}|jt|ƒkrHtdƒ‚|j|djkr.tdƒ‚q.Wx|D] }| ¡qjW|d tj |fdd „|DƒžŽ¡S) 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. Ú*zwrong number of bandsrNz mode mismatchrz size mismatchcSsg|] }|j‘qSr)r)rìr†rrrrïe szmerge..) rRrQrƒrGrNrHr¤r™rkr)rGrOrrrrrP s    rcCs"| ¡}t |¡||ft|<dS)a1 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)rhr¦rÍra)rr®r¯rrrÚ register_openl s  r¼cCs|t| ¡<dS)zÈ Registers an image MIME type. This function should not be used in application code. :param id: An image format identifier. :param mimetype: The image MIME type for this format. N)ÚMIMErh)rÚmimetyperrrÚ register_mime{ sr¿cCs|t| ¡<dS)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)rbrh)rÚdriverrrrÚ register_save† srÁcCs|t| ¡<dS)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)rirh)rrÀrrrÚregister_save_all‘ s rÂcCs| ¡t| ¡<dS)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)rhrgrf)rÚ extensionrrrÚregister_extension srÄcCsx|D]}t||ƒqWdS)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Ä)rÚ extensionsrÃrrrÚregister_extensions¨ s rÆcCsts tƒtS)za Returns a dictionary containing all file extensions belonging to registered plugins )rgrdrrrrÚregistered_extensions´ srÇcCs |t|<dS)a Registers an image decoder. This function should not be used in application code. :param name: The name of the decoder :param decoder: A callable(mode, args) that returns an ImageFile.PyDecoder object .. versionadded:: 4.1.0 N)rh)rØrprrrÚregister_decoder¾ s rÈcCs |t|<dS)a Registers an image encoder. This function should not be used in application code. :param name: The name of the encoder :param encoder: A callable(mode, args) that returns an ImageFile.PyEncoder object .. versionadded:: 4.1.0 N)rs)rØrurrrÚregister_encoderÌ s rÉcKst|f|ŽdS)N)Ú_showxv)rÖr¯rrrrsÞ srscKs ddlm}|j||f|ŽdS)Nr)Ú ImageShow)rYrËrt)rÖrqr¯rËrrrrÊã s rÊcCstƒ t |||¡¡S)a 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, y2). :param quality: Quality. )rŠr™rkÚeffect_mandelbrot)rHZextentZqualityrrrrÌí s rÌcCstƒ t ||¡¡S)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™rkÚ effect_noise)rHÚsigmarrrrÍú srÍcCstƒ t |¡¡S)zl Generate 256x256 linear gradient from black to white, top to bottom. :param mode: Input mode. )rŠr™rkÚlinear_gradient)rGrrrrÏ srÏcCstƒ t |¡¡S)zm Generate 256x256 radial gradient from black to white, centre to edge. :param mode: Input mode. )rŠr™rkÚradial_gradient)rGrrrrÐ srÐc Cs|dkrtj}xîdtjfdtjfdtjfgD]Î\}}||kr>q,|| ¡}d}x0dD](\}}| |¡rT|}|dt|ƒ …}qTWyt |ƒ|}Wn&t k r¶t   d  |¡¡w,YnXy ||ƒWq,t k rø}zt   d  ||¡¡Wdd}~XYq,Xq,WdS)NZPILLOW_ALIGNMENTZPILLOW_BLOCK_SIZEZPILLOW_BLOCKS_MAXr))Úki)réiz {} is not intz{}: {})rªÚenvironrkZ set_alignmentZset_block_sizeZset_blocks_maxrfr«rQràrƒrôrõr®)ÚenvÚvar_nameÚsetterÚvarZunitsZpostfixÚmulrcrrrÚ_apply_env_variables s.   rØc@sŽeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd"d d„Z dd„Z dd„Z dd„Z dd„Z dd„Zesrdd„Zdd„Zdd„Zdd „Zd!S)#rrBcCsi|_i|_d|_d|_dS)N)Ú_dataÚ_ifdsÚ_infoÚ _loaded_exif)rrrrr{B sz Exif.__init__cCs<y"t|ƒdkr t|tƒs |dSWntk r6YnX|S)Nrr)rQrfÚdictr¡)rrxrrrÚ_fixupH s  z Exif._fixupcs‡fdd„| ¡DƒS)Ncsi|]\}}ˆ |¡|“qSr)rÞ)rìrÑrê)rrrú S sz$Exif._fixup_dict..)Úitems)rZsrc_dictr)rrÚ _fixup_dictP szExif._fixup_dictc Cs`y|j ||¡Wnttfk r,Yn0Xddlm}| |j¡}| |j¡|  |¡SdS)Nr)ÚTiffImagePlugin) r›rprir‚rYrâÚImageFileDirectory_v1Úheadr¤rá)rÚtagrârrrrÚ _get_ifd_dictU s   zExif._get_ifd_dictcCsÂ||jkrdS||_|j ¡|j ¡d|_|s6dSt |dd…¡|_|j d¡|_ ddl m }|  |j ¡|_|jj |_|j |jj¡|j |j¡| d¡}|r¾|j |¡||jd<dS)Nr'rr)râii‡)rÜrÙÚclearrÚrÛr»r¼r›rµrärYrârãÚ_endianÚendianrpÚnextr¤ræÚupdate)rrzrâÚifdrrrr¤c s&       z Exif.loadrcCs\ddlm}|jdkrd}nd}|j|d}x| ¡D]\}}|||<q6Wd|| |¡S)Nr)rârBsII*sMM*)ZifhsExif)rYrâréÚImageFileDirectory_v2ràr¶)rr%rârärìrårxrrrr¶ƒ s    z Exif.tobytesc Cs||jkr||kr|dkr2| |¡|j|<nÖ|dkrddlm}|ddd…dkr¬|d}t|dd…ƒ}||d…}i}x tdt d |dd …¡dƒD]è}t d ||dd |ddd …¡\}} } } y|j| \} } Wnt k rw¨YnX| | }|d krBt d | ¡\}||d||d…} n | d|…} t | ƒ|krvt   d|t | ƒ|f¡q¨| s~q¨| |ƒ| dƒ||<q¨Wt | |¡ƒ|jd<n\| d¡dkr|d}i}x2tdt d|dd …¡dƒD]}t d||dd |ddd …¡\}} } } |dkrêt d| ¡\}|j |¡d|j d ¡i}|j d ¡t|j d¡ƒ|d<|j d ¡|j d ¡|d<|j d¡|j d ¡}|jtjd} | |ƒ|dƒ|d<|j d ¡|j d ¡|d<dt | |¡ƒi}qêW||jd<|j |i¡S)N)i%ˆi i|’r)rírsFUJIFILMé rzHz>HHL4siz>LZModelIDZ TimeStampZInternalSerialNumberZParallaxZCategory)rÚrærârír rñrªÚunpackZ_load_dispatchrirQrôrõrÝrárðr›rprµrÚFLOAT)rråríZ exif_dataZ ifd_offsetZifd_dataZ makernoteríZifd_tagrIÚcountrzZ unit_sizeÚhandlerrHr%Z camerainfoZparallaxrrrÚget_ifd sv   &,  (,        z Exif.get_ifdcCs0|jdk r&x|j ¡D] }||qWt|jƒS)N)rÛÚkeysrbrÙ)rrårrrÚ__str__ã s  z Exif.__str__cCs(t|jƒ}|jdk r | |j¡t|ƒS)N)ÚsetrÙrÛrërQ)rrôrrrÚ__len__ë s   z Exif.__len__cCs^|jdk rT||jkrT||jkrT| |j|¡|j|<|dkrL| |¡|j|<|j|=|j|S)Ni%ˆ)rÛrÙrÞró)rrårrrÚ __getitem__ñ s zExif.__getitem__cCs||jkp|jdk o||jkS)N)rÙrÛ)rrårrrÚ __contains__ù szExif.__contains__cCs||kS)Nr)rrårrrÚhas_keyþ sz Exif.has_keycCs*|jdk r||jkr|j|=||j|<dS)N)rÛrÙ)rrårxrrrÚ __setitem__ szExif.__setitem__cCs(|jdk r||jkr|j|=|j|=dS)N)rÛrÙ)rrårrrÚ __delitem__ szExif.__delitem__cCs(t|jƒ}|jdk r | |j¡t|ƒS)N)rörÙrÛrëÚiter)rrôrrrÚ__iter__ s   z Exif.__iter__N)r)rrrrér{rÞrárær¤r¶rórõr÷rørùr rúrûrürþrrrrr? s" Tr)r)r)r)rÂ)rÂ)N)r£)N)N)N)£Úatexitr»ÚloggingrSr€rªrªrrôrYrrrrrÚ_binaryrr Z_utilr r r r rjrÚ __builtin__Úcollections.abcrrÚ collectionsrZÚ getLoggerrr\r˜rr¡rÚobjectrràr¢rrkrjrêrbÚ startswithrõr rärãZpathlibrraZpathlib2r"ÚNONEZFLIP_LEFT_RIGHTZFLIP_TOP_BOTTOMrQrPrRZ TRANSPOSEZ TRANSVERSErYr€r‚r~r|r@rDrAZLINEARrErBZCUBICrCZ ANTIALIASZORDEREDZ RASTERIZErûr’rúZ MEDIANCUTZ MAXCOVERAGEZ FASTOCTREEZ LIBIMAGEQUANTrŽZSEQUENCEZ CONTAINERr(ZFILTEREDZ HUFFMAN_ONLYZRLEZFIXEDr¦rar½rbrirgrhrsZ _MODEINFOÚ byteorderZ_ENDIANrFrKÚsortedZMODESr™rMrNrPrRrXr[rdrqrvryrwr‰rŠr/r{r”r•r˜rÆrÛršrŸr r¡rœrrkr*r¸r¹rºrr¼r¿rÁrÂrÄrÆrÇrÈrÉrsrÊrÌrÍrÏrÐrØÚregisterÚ clear_cacherrrrrÚsÚ                .   w  ' & < 9   Z