mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +03:00
Added type hints to frombuffer
This commit is contained in:
parent
6377321625
commit
06c331af5d
|
@ -1011,7 +1011,9 @@ class TestFileJpeg:
|
||||||
# Even though this decoder never says that it is finished
|
# Even though this decoder never says that it is finished
|
||||||
# the image should still end when there is no new data
|
# the image should still end when there is no new data
|
||||||
class InfiniteMockPyDecoder(ImageFile.PyDecoder):
|
class InfiniteMockPyDecoder(ImageFile.PyDecoder):
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(
|
||||||
|
self, buffer: bytes | Image.SupportsArrayInterface
|
||||||
|
) -> tuple[int, int]:
|
||||||
return 0, 0
|
return 0, 0
|
||||||
|
|
||||||
Image.register_decoder("INFINITE", InfiniteMockPyDecoder)
|
Image.register_decoder("INFINITE", InfiniteMockPyDecoder)
|
||||||
|
|
|
@ -210,7 +210,7 @@ class MockPyDecoder(ImageFile.PyDecoder):
|
||||||
|
|
||||||
super().__init__(mode, *args)
|
super().__init__(mode, *args)
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
# eof
|
# eof
|
||||||
return -1, 0
|
return -1, 0
|
||||||
|
|
||||||
|
|
|
@ -257,7 +257,7 @@ class DdsImageFile(ImageFile.ImageFile):
|
||||||
class DXT1Decoder(ImageFile.PyDecoder):
|
class DXT1Decoder(ImageFile.PyDecoder):
|
||||||
_pulls_fd = True
|
_pulls_fd = True
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
assert self.fd is not None
|
assert self.fd is not None
|
||||||
try:
|
try:
|
||||||
self.set_as_raw(_dxt1(self.fd, self.state.xsize, self.state.ysize))
|
self.set_as_raw(_dxt1(self.fd, self.state.xsize, self.state.ysize))
|
||||||
|
@ -270,7 +270,7 @@ class DXT1Decoder(ImageFile.PyDecoder):
|
||||||
class DXT5Decoder(ImageFile.PyDecoder):
|
class DXT5Decoder(ImageFile.PyDecoder):
|
||||||
_pulls_fd = True
|
_pulls_fd = True
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
assert self.fd is not None
|
assert self.fd is not None
|
||||||
try:
|
try:
|
||||||
self.set_as_raw(_dxt5(self.fd, self.state.xsize, self.state.ysize))
|
self.set_as_raw(_dxt5(self.fd, self.state.xsize, self.state.ysize))
|
||||||
|
|
|
@ -279,7 +279,7 @@ class BlpImageFile(ImageFile.ImageFile):
|
||||||
class _BLPBaseDecoder(ImageFile.PyDecoder):
|
class _BLPBaseDecoder(ImageFile.PyDecoder):
|
||||||
_pulls_fd = True
|
_pulls_fd = True
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
try:
|
try:
|
||||||
self._read_blp_header()
|
self._read_blp_header()
|
||||||
self._load()
|
self._load()
|
||||||
|
|
|
@ -321,7 +321,7 @@ class BmpImageFile(ImageFile.ImageFile):
|
||||||
class BmpRleDecoder(ImageFile.PyDecoder):
|
class BmpRleDecoder(ImageFile.PyDecoder):
|
||||||
_pulls_fd = True
|
_pulls_fd = True
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
assert self.fd is not None
|
assert self.fd is not None
|
||||||
rle4 = self.args[1]
|
rle4 = self.args[1]
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
|
|
|
@ -481,7 +481,7 @@ class DdsImageFile(ImageFile.ImageFile):
|
||||||
class DdsRgbDecoder(ImageFile.PyDecoder):
|
class DdsRgbDecoder(ImageFile.PyDecoder):
|
||||||
_pulls_fd = True
|
_pulls_fd = True
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
assert self.fd is not None
|
assert self.fd is not None
|
||||||
bitcount, masks = self.args
|
bitcount, masks = self.args
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ class FitsImageFile(ImageFile.ImageFile):
|
||||||
class FitsGzipDecoder(ImageFile.PyDecoder):
|
class FitsGzipDecoder(ImageFile.PyDecoder):
|
||||||
_pulls_fd = True
|
_pulls_fd = True
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
assert self.fd is not None
|
assert self.fd is not None
|
||||||
value = gzip.decompress(self.fd.read())
|
value = gzip.decompress(self.fd.read())
|
||||||
|
|
||||||
|
|
|
@ -856,7 +856,10 @@ class Image:
|
||||||
)
|
)
|
||||||
|
|
||||||
def frombytes(
|
def frombytes(
|
||||||
self, data: bytes | bytearray, decoder_name: str = "raw", *args: Any
|
self,
|
||||||
|
data: bytes | bytearray | SupportsArrayInterface,
|
||||||
|
decoder_name: str = "raw",
|
||||||
|
*args: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Loads this image with pixel data from a bytes object.
|
Loads this image with pixel data from a bytes object.
|
||||||
|
@ -3145,7 +3148,7 @@ def new(
|
||||||
def frombytes(
|
def frombytes(
|
||||||
mode: str,
|
mode: str,
|
||||||
size: tuple[int, int],
|
size: tuple[int, int],
|
||||||
data: bytes | bytearray,
|
data: bytes | bytearray | SupportsArrayInterface,
|
||||||
decoder_name: str = "raw",
|
decoder_name: str = "raw",
|
||||||
*args: Any,
|
*args: Any,
|
||||||
) -> Image:
|
) -> Image:
|
||||||
|
@ -3189,7 +3192,11 @@ def frombytes(
|
||||||
|
|
||||||
|
|
||||||
def frombuffer(
|
def frombuffer(
|
||||||
mode: str, size: tuple[int, int], data, decoder_name: str = "raw", *args: Any
|
mode: str,
|
||||||
|
size: tuple[int, int],
|
||||||
|
data: bytes | SupportsArrayInterface,
|
||||||
|
decoder_name: str = "raw",
|
||||||
|
*args: Any,
|
||||||
) -> Image:
|
) -> Image:
|
||||||
"""
|
"""
|
||||||
Creates an image memory referencing pixel data in a byte buffer.
|
Creates an image memory referencing pixel data in a byte buffer.
|
||||||
|
|
|
@ -733,7 +733,7 @@ class PyDecoder(PyCodec):
|
||||||
def pulls_fd(self) -> bool:
|
def pulls_fd(self) -> bool:
|
||||||
return self._pulls_fd
|
return self._pulls_fd
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
"""
|
"""
|
||||||
Override to perform the decoding process.
|
Override to perform the decoding process.
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ class MspDecoder(ImageFile.PyDecoder):
|
||||||
|
|
||||||
_pulls_fd = True
|
_pulls_fd = True
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
assert self.fd is not None
|
assert self.fd is not None
|
||||||
|
|
||||||
img = io.BytesIO()
|
img = io.BytesIO()
|
||||||
|
|
|
@ -284,7 +284,7 @@ class PpmPlainDecoder(ImageFile.PyDecoder):
|
||||||
break
|
break
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
self._comment_spans = False
|
self._comment_spans = False
|
||||||
if self.mode == "1":
|
if self.mode == "1":
|
||||||
data = self._decode_bitonal()
|
data = self._decode_bitonal()
|
||||||
|
@ -300,7 +300,7 @@ class PpmPlainDecoder(ImageFile.PyDecoder):
|
||||||
class PpmDecoder(ImageFile.PyDecoder):
|
class PpmDecoder(ImageFile.PyDecoder):
|
||||||
_pulls_fd = True
|
_pulls_fd = True
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
assert self.fd is not None
|
assert self.fd is not None
|
||||||
|
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
|
|
|
@ -47,7 +47,7 @@ class QoiDecoder(ImageFile.PyDecoder):
|
||||||
hash_value = (r * 3 + g * 5 + b * 7 + a * 11) % 64
|
hash_value = (r * 3 + g * 5 + b * 7 + a * 11) % 64
|
||||||
self._previously_seen_pixels[hash_value] = value
|
self._previously_seen_pixels[hash_value] = value
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
assert self.fd is not None
|
assert self.fd is not None
|
||||||
|
|
||||||
self._previously_seen_pixels = {}
|
self._previously_seen_pixels = {}
|
||||||
|
|
|
@ -214,7 +214,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||||
class SGI16Decoder(ImageFile.PyDecoder):
|
class SGI16Decoder(ImageFile.PyDecoder):
|
||||||
_pulls_fd = True
|
_pulls_fd = True
|
||||||
|
|
||||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
||||||
assert self.fd is not None
|
assert self.fd is not None
|
||||||
assert self.im is not None
|
assert self.im is not None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user