Files
intellecton/venv/lib/python3.12/site-packages/PIL/__pycache__/ImageOps.cpython-312.pyc
T

355 lines
30 KiB
Plaintext
Raw Normal View History

Ë
ß¼jßcãó.ddlmZddlZddlZddlZddlmZddlmZm Z m
Z
m Z ddl m
Z
mZmZd$dZd%dZd&d „Z d' d(d Z d) d*d Zej*j,f d+d
Zej*j,f d+dZej*j,ddf d,dZd-d.dZej*j,f d/dZGdde «Zej*j:f d0dZd1d2dZ d3 d4dZ ej*j,ddf d5dZ!d6dZ"d6dZ#d6dZ$d6dZ%d7dZ&d8d9dZ'e d:d „«Z(e d
d!œ d;d"„«Z(d
d!œd<d#„Z(y)=é)Ú annotationsN)ÚSequence)ÚLiteralÚProtocolÚcastÚoverloadé)ÚExifTagsÚImageÚ ImagePalettecóœt|t«r/t|«dk(r |x\}}\}}nt|«dk(r|\}}}}n|x}x}x}}fS)é)Ú
isinstanceÚtupleÚlen)ÚborderÚleftÚtopÚrightÚbottoms úO/home/antigravity/intellecton/venv/lib/python3.12/site-packages/PIL/ImageOps.pyÚ_borderr!sgÜ&œ%Ô Ü ˆv;˜ Ø(.Ð .‰IˆD#™
˜™vÜ
[˜
Ø'-Ñ $ˆD#u™fà&,Ð,ˆÐ,ˆ,U˜ e˜ cóVt|t«rddlm}|j ||«}|S)Nr )Ú
ImageColor)rÚstrÚrÚgetcolor)ÚcolorÚmoders rÚ_colorr",s&ÜÔÝ à×# E¨4ÓØ €Lrcóö|jdk(r
d}t|«|jdvr6|jdk(rt|«dk(r||z|z}|j|«Sd|j}t |«)Pzmode P support coming soon)ÚRGBr&éznot supported for mode )r!ÚNotImplementedErrorrÚpointÚOSError)ÚimageÚlutÚmsgs rÚ_lutr.4svØ ‡zzà*ˆÜ! |Ñ #Ø :‰:˜Ò ¤3 s£8¨s¢?ؘ‘)˜c‘/ˆCØ{‰{˜3ÓÐà¯
©
 |Ð4ˆÜcrFcó|r!|jd«j|«}n|j|«}g}tdt|«d«D}|||dz}|"t |t
«rd||<n |D]} d|| <Œ |rÐt |t «s||f}d}
td«D]
} |
|| z}
Œ t |
|dzdz«} td«D].} | || kDr| || z
} d|| <n|| xx| zcc<d} | dksŒ.nt |
|dzdz«} tddd«D].}
| ||
kDr| ||
z
} d||
<n||
xx| zcc<d} | dksŒ.ntd«D] } || sŒ ntddd«D] }
||
sŒ n
 kr%|jttd«««Œ\d|
| z
z }| |z}td«D]3} t | |z|z«} | dkrd} n| dkDrd} |j| «Œ5Œ­t||«S) aÙ
Maximize (normalize) image contrast. This function calculates a
histogram of the input image (or mask region), removes ``cutoff`` percent of the
lightest and darkest pixels from the histogram, and remaps the image
so that the darkest pixel becomes black (0), and the lightest
becomes white (255).
:param image: The image to process.
:param cutoff: The percent to cut off from the histogram on the low and
high ends. Either a tuple of (low, high), or a single
number for both.
:param ignore: The background pixel value (use None for no background).
:param mask: Histogram used in contrast operation is computed using pixels
within the mask. If no mask is given the entire image is used
for histogram computation.
:param preserve_tone: Preserve image tone in Photoshop-like style autocontrast.
.. versionadded:: 8.2.0
:return: An image.
r%rr'édr éÿéÿÿÿÿgào@) ÚconvertÚ histogramÚrangerrÚintrÚextendÚlistÚappendr.)r+ÚcutoffÚignoreÚmaskÚ
preserve_toner4r,ÚlayerÚixÚcutÚloÚhiÚscaleÚoffsets rÚ autocontrastrGFswñ8Ø—MM &×Ó6‰ à—OO DÓ)ˆ à
€CÜqœ#˜i›.¨#Ó:ˆØ e˜e c™kÐ Ø Ð ä˜&¤#Ô& à òAb’Eðá ä˜f¤eÔ  &Ð)àˆ˜C“jò
ؘ˜"™‘I‘ð
ôa˜& ™)m +ˆ˜C“jò
ؘ˜2™’;Ø  ™+Abb“E˜S‘L“Eؘ!“8Ùð
ôa˜& ™)m +ˆ˜C  
ؘ˜2™’;Ø  ™+Abb“E˜S‘L“Eؘ!“8Ùð
ô˜“*ò ˆBØ‹uÙð ô˜˜R Ó ˆBØ‹uÙð ð Š8à J‰J”tœE # ˜R "™WÑ%ˆS˜5[ˆ˜C“jò
ܘ˜e™ fÑ-ؘ’6Ø‘Bؘ#’XØ
˜2•ò

ði:ôv  Ðrcó¶|jdk(sJ|d|cxkr |cxkrdks!JJd|cxkr|cxkr |cxkrdksJJtttt |d««}tttt |d««}|!tttt |d««nd} g}
g} g} t |«D]>}
|
j
|d«| j
|d«| j
|d«Œ@| €¤t ||z
«}|D]}
|
j
|d|
|d|dz
zt|«zz«| j
|d|
|d|dz
zt|«zz«| j
|d|
|d|dz
zt|«zz«Œ‘nDt ||z
«}t ||z
«}|D]}
|
j
|d|
| d|dz
zt|«zz«| j
|d|
| d|dz
zt|«zz«| j
|d|
| d|dz
zt|«zz«Œ‘|D]}
|
j
| d|
|d| dz
zt|«zz«| j
| d|
|d| dz
zt|«zz«| j
| d|
|d| dz
zt|«zz«Œ‘t d|z
«D]>}
|
j
|d«| j
|d«| j
|d«Œ@|jd«}t||
| z| z«S) a
Colorize grayscale image.
This function calculates a color wedge which maps all black pixels in
the source image to the first color and all white pixels to the
second color. If ``mid`` is specified, it uses three-color mapping.
The ``black`` and ``white`` arguments should be RGB tuples or color names;
optionally you can use three-color mapping by also specifying ``mid``.
Mapping positions for any of the colors can be specified
(e.g. ``blackpoint``), where these parameters are the integer
value corresponding to where the corresponding color should be mapped.
These parameters must have logical order, such that
``blackpoint <= midpoint <= whitepoint`` (if ``mid`` is specified).
:param image: The image to colorize.
:param black: The color to use for black input pixels.
:param white: The color to use for white input pixels.
:param mid: The color to use for midtone input pixels.
:param blackpoint: an int value [0, 255] for the black mapping.
:param whitepoint: an int value [0, 255] for the white mapping.
:param midpoint: an int value [0, 255] for the midtone mapping.
:return: An image.
r%Nrr1r&r rr')
r!rrr6r"r5r9rr3r.)r+ÚblackÚwhiteÚmidÚ
blackpointÚ
whitepointÚmidpointÚ rgb_blackÚ rgb_whiteÚrgb_midÚredÚgreenÚblueÚiÚ range_mapÚ
range_map1Ú
range_map2s rÚcolorizerY¦ðB :‰:˜Ò ÐÐ Ø
€{Ø3 *ÔÒ? (Ô?¨jÔ?¸”Xœc‘]¤F¨5°%Ó$8Ó9€IÜ”Xœc]¤F¨5°%Ó$8Ó9€IØ9<¸Œd”8œC=¤&¨¨eÓ"4Ô5Èd€Gð
€CØ €EØ
€Dô
ò"ˆØ
9˜Q Ø
Y˜q I˜a ܘ* 2ˆ àò ˆAØ J‰Jؘ! ˜q I¨a¡L°9¸Q±<Ñ$?Ñ@ÄCÈ ÃNÑ
ð
L‰Lؘ! ˜q I¨a¡L°9¸Q±<Ñ$?Ñ@ÄCÈ ÃNÑ
ð
K‰Kؘ! ˜q I¨a¡L°9¸Q±<Ñ$?Ñ@ÄCÈ ÃNÑ
ò ô˜8 1ˆ
ܘÑ1ˆ
àò ˆAØ J‰Jؘ!‘ ˜q G¨A¡J°¸Ñ$=Ñ>Ä#ÀjÃ/Ñ
ð
L‰Lؘ!‘ ˜q G¨A¡J°¸Ñ$=Ñ>Ä#ÀjÃ/Ñ
ð
K‰Kؘ!‘ ˜q G¨A¡J°¸Ñ$=Ñ>Ä#ÀjÃ/Ñ
ð ðò Yˆ J‰Jw˜q‘z A¨°1©¸À¹
Ñ)BÑ$CÄsÈ:ÃÑ$VÑ L‰Lؘ
˜Q )¨A¡,°¸±Ñ";ÑÀJÃÑ
ð
K‰K˜ 
 Q¨)°A©,¸À¹Ñ*CÑ%DÌÈJËÑ%WÑ  Yô3˜Ñ
"ˆØ
9˜Q Ø
Y˜q I˜a
M‰M˜ €EÜ s˜U{  *rcób|j|jz }|d|dz }||k7rt||kDr8t|j|jz |dz«}||dk7r?|d|f}n7t|j|jz |dz«}||dk7r||df}|j||¬«S)
Returns a resized version of the image, set to the maximum width and height
within the requested size, while maintaining the original aspect ratio.
:param image: The image to resize.
:param size: The requested output size in pixels, given as a
(width, height) tuple.
:param method: Resampling method to use. Default is
:py:attr:`~PIL.Image.Resampling.BICUBIC`.
See :ref:`concept-filters`.
:return: An image.
rr ©Úresample©ÚwidthÚheightÚroundÚresize©r+ÚsizeÚmethodÚim_ratioÚ
dest_ratioÚ
new_heightÚ new_widths rÚcontainri
ó¿ð {‰{˜UŸ\™\Ñ)€HØa˜4 ™7Ñ"€JàØ  ܘuŸ|™|¨e¯k©kÑ9¸DÀ¹GÑDˆJؘT !™WÒ˜Q™ Ð,‘ä˜eŸk™k¨E¯L©LÑ8¸4À¹7ÑCˆIؘD ™GÒ! ¡7Ð+Ø <‰<˜ vˆ .rcób|j|jz }|d|dz }||k7rt||kr8t|j|jz |dz«}||dk7r?|d|f}n7t|j|jz |dz«}||dk7r||df}|j||¬«S)
Returns a resized version of the image, so that the requested size is
covered, while maintaining the original aspect ratio.
:param image: The image to resize.
:param size: The requested output size in pixels, given as a
(width, height) tuple.
:param method: Resampling method to use. Default is
:py:attr:`~PIL.Image.Resampling.BICUBIC`.
See :ref:`concept-filters`.
:return: An image.
rr r[r]rbs rÚcoverrl,rjr)çà?rmc
ó2t|||«}|j|k(r|}|Stj|j||«}|j
r#|j
«}||j|«|j|dk7rKt|d|jz
tdt|dd««z«}|j||df«|St|d|jz
tdt|dd««z«} |j|d| f«|S)at
Returns a resized and padded version of the image, expanded to fill the
requested aspect ratio and size.
:param image: The image to resize and crop.
:param size: The requested output size in pixels, given as a
(width, height) tuple.
:param method: Resampling method to use. Default is
:py:attr:`~PIL.Image.Resampling.BICUBIC`.
See :ref:`concept-filters`.
:param color: The background color of the padded image.
:param centering: Control the position of the original image within the
padded version.
(0.5, 0.5) will keep the image centered
(0, 0) will keep the image aligned to the top left
(1, 1) will keep the image aligned to the bottom
right
:return: An image.
rr )rircr Únewr!ÚpaletteÚ
getpaletteÚ
putpaletter^r`ÚmaxÚminÚpaster_)
r+rcrdr Ú centeringÚresizedÚoutrpÚys
rÚpadr{Ksô8e˜T *€G؇||؈ð €Jôi‰i˜Ÿ
 D¨%ÓØ ?Š?Ø×*ˆGØÐ˜ =‰=˜D ™GÒ t˜A‘w §¡Ñ.´#°a¼¸YÀq¹\È1Ó9MÓ2NÑOˆ I‰Ig  1˜  €Jôt˜A‘w §¡Ñ/´3°q¼#¸iȹlÈAÓ:NÓ3OÑPˆ I‰Ig  1˜ €JrcóŒt|«\}}}}|j|||jd|z
|jd|z
f«S)a/
Remove border from image. The same amount of pixels are removed
from all four sides. This function works on all image modes.
.. seealso:: :py:meth:`~PIL.Image.Image.crop`
:param image: The image to crop.
:param border: The number of pixels to remove.
:return: An image.
rr )rÚcroprc)r+rrrrrs rr}r}ysHô ' vÑ€Dˆ#ˆu :‰:t˜S %§*¡*¨Q¡-°%Ñ"7¸¿¹ÀA¹ÈÑ9OÐ QrcóÔ|dk(r|j«S|dkr
d}t|«t||jz«t||jz«f}|j ||«S)
Returns a rescaled image by a specific factor given in parameter.
A factor greater than 1 expands the image, between 0 and 1 contracts the
image.
:param image: The image to rescale.
:param factor: The expansion factor, as a float.
:param resample: Resampling method to use. Default is
:py:attr:`~PIL.Image.Resampling.BICUBIC`.
See :ref:`concept-filters`.
:returns: An :py:class:`~PIL.Image.Image` object.
r rz!the factor must be greater than 0)ÚcopyÚ
ValueErrorr`r^r_ra)r+Úfactorr\r-rcs rrErEˆsdð‚{Øz‰z‹|ÐØ ØÜ˜‹oÐäf˜uŸ{™{Ñ+¬U°6¸E¿L¹LÑ3HÓ-IÐJˆØ|‰|˜D +rcó eZdZdZ ddZy)ÚSupportsGetMeshaE
An object that supports the ``getmesh`` method, taking an image as an
argument, and returning a list of tuples. Each tuple contains two tuples,
the source box as a tuple of 4 integers, and a tuple of 8 integers for the
final quadrilateral, in order of top left, bottom left, bottom right, top
right.
cóy©)Úselfr+s rÚgetmeshzSupportsGetMesh.getmeshªsð rN)r+ú Image.ImageÚreturnzUlist[tuple[tuple[int, int, int, int], tuple[int, int, int, int, int, int, int, int]]])Ú__name__Ú
__module__Ú __qualname__Ú__doc__rˆr†rr¡sñð Ø ð ð
ô rcóŒ|j|jtjj|j |«|«S)aL
Deform the image.
:param image: The image to deform.
:param deformer: A deformer object. Any object that implements a
``getmesh`` method can be used.
:param resample: An optional resampling filter. Same values possible as
in the PIL.Image.transform function.
:return: An image.
)Ú transformrcr Ú TransformÚMESHrˆ)r+Údeformerr\s rÚdeformr”±s7ð ?‰?Ø
”E—OO×(¨(×*:Ñ*:¸5Ó*AÀ8ó ðrcób|jdk(r|jd«}|j|«}g}tdt |«d«D}|||dzDcgc]}|sŒ|Œ }}t |«dkr$|j t
td«««ŒMtjtj|«|dz
dz}|s$|j t
td«««Œ |dz}td«D]!} |j||z«||| |zz}Œ#ŒÕt||«Scc}w) a„
Equalize the image histogram. This function applies a non-linear
mapping to the input image, in order to create a uniform
distribution of grayscale values in the output image.
:param image: The image to equalize.
:param mask: An optional mask. If given, only the pixels selected by
the mask are included in the analysis.
:return: An image.
r$r&rr'r r2r1r)
r!r3r4r5rr7r8Ú functoolsÚreduceÚoperatorÚaddr9r.)
r+r<r?r,Ú_fÚhistoÚsteprArUs
rÚequalizeržÅsð
‡zzØ
˜$ˆØ
˜Ó€AØ
€CÜ
1”c˜!“f˜
%ˆØ  A¨¡G˜nÖ²ÐÐ ˆu‹:˜Š?Ø J‰J”tœE # ×$¤X§\¡\°5Ó9¸EÀ"¹IÑEÈ#ÑMˆØ
œ4¤ 
Ó˜A‘Iܘs›ò%—J‘J˜q D™yÔ˜A˜a !™e™H™ ‘Añ   Ðùò4s ÁD,ÁD,có^t|«\}}}}||jdz|z}||jdz|z}t||j«} |jry|jj}
t j
|
|j
|
««} t| t«r0t| «dk(st| «dk(r| j| «} nd} tj|j||f| «} | r| j| j
«| j|||f«| S)
Add border to the image
:param image: The image to expand.
:param border: Border width, in pixels.
:param fill: Pixel fill value (a color value). Default is 0 (black).
:return: An image.
rr érN)rrcr"r!rpr rqrrrrr rorrru)
r+rÚfillrrrrr^r_r r!rprxs
rÚexpandr¢äsô ' vÑ€Dˆ#ˆu 5—:‘:˜a   (€EØ
5—::˜a
 
)€FÜ ŸÓ $€EØ ‡}‚}Ø}‰}×Ü×+¨D°%×2BÑ2BÀ4Ó2HÓIˆÜ eœUÔ ¨U«°qª¼CÀ»JÈ!ºOØ×$ UÓ+‰EàˆÜ
)‰)E—J‘J ¨ °Ó
7€CÙØ w—¨Ô‡IIˆed˜C €Jrçcó|\}}d|cxkrdksnd}d|cxkrdksnd}d|cxkrdksnd}||jdz||jdzf}|jd|ddzz
|jd|ddzz
f}|d|dz } |d|dz }
| |
k(r |d} |d} n | |
k\r|
|dz} |d} n
|d} |d|
z } |d|d| z
|zz}
|d|d| z
|zz}|
||
| z|| zf}|j|||¬«S)a
Returns a resized and cropped version of the image, cropped to the
requested aspect ratio and size.
This function was contributed by Kevin Cazabon.
:param image: The image to resize and crop.
:param size: The requested output size in pixels, given as a
(width, height) tuple.
:param method: Resampling method to use. Default is
:py:attr:`~PIL.Image.Resampling.BICUBIC`.
See :ref:`concept-filters`.
:param bleed: Remove a border around the outside of the image from all
four edges. The value is a decimal percentage (use 0.01 for
one percent). The default value is 0 (no border).
Cannot be greater than or equal to 0.5.
:param centering: Control the cropping position. Use (0.5, 0.5) for
center cropping (e.g. if cropping the width, take 50% off
of the left side, and therefore 50% off the right side).
(0.0, 0.0) will crop from the top left corner (i.e. if
cropping the width, take all of the crop off of the right
side, and if cropping the height, take all of it off the
bottom). (1.0, 0.0) will crop from the bottom left
corner, etc. (i.e. if cropping the width, take all of the
crop off the left side, and if cropping the height take
none from the top, and therefore all off the bottom).