mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
Merge pull request #7724 from radarhere/type_hints_sgi
This commit is contained in:
commit
1d7ff595ec
|
@ -710,7 +710,7 @@ class Image:
|
||||||
self.putpalette(palette)
|
self.putpalette(palette)
|
||||||
self.frombytes(data)
|
self.frombytes(data)
|
||||||
|
|
||||||
def tobytes(self, encoder_name="raw", *args):
|
def tobytes(self, encoder_name: str = "raw", *args) -> bytes:
|
||||||
"""
|
"""
|
||||||
Return image as a bytes object.
|
Return image as a bytes object.
|
||||||
|
|
||||||
|
@ -788,7 +788,7 @@ class Image:
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
def frombytes(self, data, decoder_name="raw", *args):
|
def frombytes(self, data: bytes, decoder_name: str = "raw", *args) -> None:
|
||||||
"""
|
"""
|
||||||
Loads this image with pixel data from a bytes object.
|
Loads this image with pixel data from a bytes object.
|
||||||
|
|
||||||
|
@ -1297,7 +1297,7 @@ class Image:
|
||||||
]
|
]
|
||||||
return merge(self.mode, ims)
|
return merge(self.mode, ims)
|
||||||
|
|
||||||
def getbands(self):
|
def getbands(self) -> tuple[str, ...]:
|
||||||
"""
|
"""
|
||||||
Returns a tuple containing the name of each band in this image.
|
Returns a tuple containing the name of each band in this image.
|
||||||
For example, ``getbands`` on an RGB image returns ("R", "G", "B").
|
For example, ``getbands`` on an RGB image returns ("R", "G", "B").
|
||||||
|
@ -2495,7 +2495,7 @@ class Image:
|
||||||
|
|
||||||
_show(self, title=title)
|
_show(self, title=title)
|
||||||
|
|
||||||
def split(self):
|
def split(self) -> tuple[Image, ...]:
|
||||||
"""
|
"""
|
||||||
Split this image into individual bands. This method returns a
|
Split this image into individual bands. This method returns a
|
||||||
tuple of individual image bands from an image. For example,
|
tuple of individual image bands from an image. For example,
|
||||||
|
|
|
@ -24,13 +24,14 @@ from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
from ._binary import i16be as i16
|
from ._binary import i16be as i16
|
||||||
from ._binary import o8
|
from ._binary import o8
|
||||||
|
|
||||||
|
|
||||||
def _accept(prefix):
|
def _accept(prefix: bytes) -> bool:
|
||||||
return len(prefix) >= 2 and i16(prefix) == 474
|
return len(prefix) >= 2 and i16(prefix) == 474
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,8 +53,10 @@ class SgiImageFile(ImageFile.ImageFile):
|
||||||
format = "SGI"
|
format = "SGI"
|
||||||
format_description = "SGI Image File Format"
|
format_description = "SGI Image File Format"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
# HEAD
|
# HEAD
|
||||||
|
assert self.fp is not None
|
||||||
|
|
||||||
headlen = 512
|
headlen = 512
|
||||||
s = self.fp.read(headlen)
|
s = self.fp.read(headlen)
|
||||||
|
|
||||||
|
@ -122,7 +125,7 @@ class SgiImageFile(ImageFile.ImageFile):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def _save(im, fp, filename):
|
def _save(im: Image.Image, fp: BytesIO, filename: str) -> None:
|
||||||
if im.mode not in {"RGB", "RGBA", "L"}:
|
if im.mode not in {"RGB", "RGBA", "L"}:
|
||||||
msg = "Unsupported SGI image mode"
|
msg = "Unsupported SGI image mode"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
@ -168,8 +171,8 @@ def _save(im, fp, filename):
|
||||||
# Maximum Byte value (255 = 8bits per pixel)
|
# Maximum Byte value (255 = 8bits per pixel)
|
||||||
pinmax = 255
|
pinmax = 255
|
||||||
# Image name (79 characters max, truncated below in write)
|
# Image name (79 characters max, truncated below in write)
|
||||||
img_name = os.path.splitext(os.path.basename(filename))[0]
|
filename = os.path.basename(filename)
|
||||||
img_name = img_name.encode("ascii", "ignore")
|
img_name = os.path.splitext(filename)[0].encode("ascii", "ignore")
|
||||||
# Standard representation of pixel in the file
|
# Standard representation of pixel in the file
|
||||||
colormap = 0
|
colormap = 0
|
||||||
fp.write(struct.pack(">h", magic_number))
|
fp.write(struct.pack(">h", magic_number))
|
||||||
|
@ -201,7 +204,10 @@ def _save(im, fp, filename):
|
||||||
class SGI16Decoder(ImageFile.PyDecoder):
|
class SGI16Decoder(ImageFile.PyDecoder):
|
||||||
_pulls_fd = True
|
_pulls_fd = True
|
||||||
|
|
||||||
def decode(self, buffer):
|
def decode(self, buffer: bytes) -> tuple[int, int]:
|
||||||
|
assert self.fd is not None
|
||||||
|
assert self.im is not None
|
||||||
|
|
||||||
rawmode, stride, orientation = self.args
|
rawmode, stride, orientation = self.args
|
||||||
pagesize = self.state.xsize * self.state.ysize
|
pagesize = self.state.xsize * self.state.ysize
|
||||||
zsize = len(self.mode)
|
zsize = len(self.mode)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user