mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-26 07:04:45 +03:00
Type annotations: Add stubs for _imaging; aliases into aliases.py.
This commit is contained in:
parent
cd26623083
commit
0b005596b1
100
PIL/_imaging.pyi
Normal file
100
PIL/_imaging.pyi
Normal file
|
@ -0,0 +1,100 @@
|
|||
if False:
|
||||
from PIL.aliases import *
|
||||
|
||||
from typing import Any # temporarily, hopefully ;)
|
||||
from typing import Optional, List
|
||||
|
||||
PILLOW_VERSION = ...
|
||||
DEFAULT_STRATEGY = ...
|
||||
FILTERED = ...
|
||||
HUFFMAN_ONLY = ...
|
||||
RLE = ...
|
||||
FIXED = ...
|
||||
|
||||
# List of functions is incomplete
|
||||
|
||||
def alpha_composite(core1: ImagingCore, core2: ImagingCore) -> ImagingCore: ...
|
||||
def blend(core1: ImagingCore, core2: ImagingCore, alpha: float) -> ImagingCore: ...
|
||||
def fill(mode: Mode, size: Size, color: Any) -> Any: ...
|
||||
def new(mode: Mode, size: Size) -> ImagingCore: ...
|
||||
|
||||
def map_buffer(data, size, decoder_name, isNone, isint, args): ...
|
||||
|
||||
def crc32(): ... ###
|
||||
|
||||
def effect_mandelbrot(size, extent, quality): ...
|
||||
def effect_noise(size, sigma): ...
|
||||
def linear_gradient(mode): ...
|
||||
def radial_gradient(mode): ...
|
||||
def wedge(something): ...
|
||||
|
||||
class ImagingCore:
|
||||
mode = ... # type: str
|
||||
size = ... # type: Size ## close enough?
|
||||
bands = ... # type: int
|
||||
id = ... ### use? size_t? int?
|
||||
ptr = ... ###
|
||||
|
||||
def getpixel(self, xy: XY) -> Optional[Any]: ...
|
||||
def putpixel(self, xy: XY, value: Any) -> None: ...
|
||||
def pixel_access(self, readonly: bool) -> Any: ...
|
||||
|
||||
def convert(self, mode, dither, paletteimage): ...
|
||||
def convert2(self): ... ###
|
||||
def convert_matrix(self, a): ...
|
||||
def convert_transparent(self, a, b): ...
|
||||
def copy(self) -> ImagingCore: ...
|
||||
def crop(self, bbox: LURD) -> ImagingCore: ...
|
||||
def expand(self, xmargin: int, ymargin: int, mode: Mode) -> Any: ...
|
||||
def filter(self, xy, divisor, offset, kernel): ...
|
||||
def histogram(self, tuple2: Optional[Any], coremask: Optional[Any]) -> List[int]: ...
|
||||
|
||||
def modefilter(self, i: int) -> Any: ...
|
||||
|
||||
# def offset(self): ... ### Function removed?
|
||||
|
||||
def paste(self, core: ImagingCore, box: LURD, coremask: ImagingCore) -> None: ...
|
||||
def point(self, lut, mode): ...
|
||||
def point_transform(self, scale, offset): ...
|
||||
def putdata(self, data, scale, offset): ...
|
||||
|
||||
def quantize(self, colors, method, kmeans): ...
|
||||
|
||||
def rankfilter(self): ... ###
|
||||
|
||||
def resize(self, size, resample): ...
|
||||
def transpose(self, method): ...
|
||||
def transform2(self, box, core, method, data, resample, fill): ...
|
||||
|
||||
def isblock(self): ... ###
|
||||
|
||||
def getbbox(self) -> Optional[LURD]: ...
|
||||
def getcolors(self, maxcolors): ...
|
||||
def getextrema(self): ... ###
|
||||
def getprojection(self): ... # returns tuple x, y
|
||||
|
||||
def getband(self, band): ...
|
||||
# each band has: getextrema() which may return a 2tuple?
|
||||
def putband(self, alphacore, band): ...
|
||||
def split(self): ...
|
||||
def fillband(self, band, alpha): ...
|
||||
|
||||
def setmode(self, mode): ...
|
||||
|
||||
def getpalette(self, mode): ...
|
||||
def getpalettemode(self): ... ###
|
||||
def putpalette(self, a): ...
|
||||
def putpalettealpha(self, a, b): ...
|
||||
def putpalettealphas(self, a): ...
|
||||
|
||||
### chop_* here
|
||||
|
||||
### gaussian_blur and unsharp_mask here
|
||||
|
||||
### box_blur here
|
||||
|
||||
def effect_spread(self, distance): ...
|
||||
|
||||
def new_block(self): ... ###
|
||||
|
||||
def save_ppm(self, file): ... ###
|
11
PIL/aliases.py
Normal file
11
PIL/aliases.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from typing import Tuple
|
||||
|
||||
# Type aliases; names subject to change
|
||||
LURD = Tuple[int, int, int, int] # left, up(per), right, down = x0, y0, x1, y1
|
||||
XY = Tuple[int, int]
|
||||
Coord = XY
|
||||
Size = XY # NOTE: All XY aliases will be interchangeable
|
||||
Matrix4 = Tuple[float, float, float, float]
|
||||
Matrix12 = Tuple[float, float, float, float, float, float, float, float, float, float, float, float]
|
||||
Mode = str
|
||||
|
|
@ -27,14 +27,7 @@
|
|||
if False:
|
||||
from typing import Any, Text, Optional, Tuple, List, Sequence, Union, Callable, Dict
|
||||
|
||||
# Type aliases; names subject to change
|
||||
LURD = Tuple[int, int, int, int] # left, up(per), right, down = x0, y0, x1, y1
|
||||
XY = Tuple[int, int]
|
||||
Coord = XY
|
||||
Size = XY # NOTE: All XY aliases will be interchangeable
|
||||
Matrix4 = Tuple[float, float, float, float]
|
||||
Matrix12 = Tuple[float, float, float, float, float, float, float, float, float, float, float, float]
|
||||
Mode = str
|
||||
from PIL.aliases import *
|
||||
|
||||
# Just required for typing, or gradual module inclusion while adding annotation?
|
||||
from io import BytesIO
|
||||
|
@ -43,6 +36,7 @@ if False:
|
|||
from . import ImageFilter
|
||||
from ImageFile import PyDecoder
|
||||
from ImageFile import PyEncoder
|
||||
from _imaging import ImagingCore
|
||||
|
||||
from . import VERSION, PILLOW_VERSION, _plugins
|
||||
|
||||
|
@ -552,7 +546,7 @@ class Image(object):
|
|||
# type: () -> None
|
||||
# FIXME: take "new" parameters / other image?
|
||||
# FIXME: turn mode and size into delegating properties?
|
||||
self.im = None # type: Optional[Any]
|
||||
self.im = None # type: Optional[ImagingCore]
|
||||
self.mode = ""
|
||||
self.size = (0, 0)
|
||||
self.palette = None # type: Optional[ImagePalette.ImagePalette]
|
||||
|
@ -1135,7 +1129,7 @@ class Image(object):
|
|||
return self._new(self._crop(self.im, box))
|
||||
|
||||
def _crop(self, im, box):
|
||||
# type: (Image, LURD) -> Image
|
||||
# type: (ImagingCore, LURD) -> Image
|
||||
"""
|
||||
Returns a rectangular region from the core image object im.
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user