mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 02:36:17 +03:00
Merge pull request #7725 from radarhere/type_hints_tga
This commit is contained in:
commit
dd753f4ab5
|
@ -18,6 +18,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
from . import Image, ImageFile, ImagePalette
|
from . import Image, ImageFile, ImagePalette
|
||||||
from ._binary import i16le as i16
|
from ._binary import i16le as i16
|
||||||
|
@ -49,8 +50,10 @@ class TgaImageFile(ImageFile.ImageFile):
|
||||||
format = "TGA"
|
format = "TGA"
|
||||||
format_description = "Targa"
|
format_description = "Targa"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
# process header
|
# process header
|
||||||
|
assert self.fp is not None
|
||||||
|
|
||||||
s = self.fp.read(18)
|
s = self.fp.read(18)
|
||||||
|
|
||||||
id_len = s[0]
|
id_len = s[0]
|
||||||
|
@ -151,8 +154,9 @@ class TgaImageFile(ImageFile.ImageFile):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass # cannot decode
|
pass # cannot decode
|
||||||
|
|
||||||
def load_end(self):
|
def load_end(self) -> None:
|
||||||
if self._flip_horizontally:
|
if self._flip_horizontally:
|
||||||
|
assert self.im is not None
|
||||||
self.im = self.im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
|
self.im = self.im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
|
||||||
|
|
||||||
|
|
||||||
|
@ -171,7 +175,7 @@ SAVE = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _save(im, fp, filename):
|
def _save(im: Image.Image, fp: BytesIO, filename: str) -> None:
|
||||||
try:
|
try:
|
||||||
rawmode, bits, colormaptype, imagetype = SAVE[im.mode]
|
rawmode, bits, colormaptype, imagetype = SAVE[im.mode]
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
|
@ -194,6 +198,7 @@ def _save(im, fp, filename):
|
||||||
warnings.warn("id_section has been trimmed to 255 characters")
|
warnings.warn("id_section has been trimmed to 255 characters")
|
||||||
|
|
||||||
if colormaptype:
|
if colormaptype:
|
||||||
|
assert im.im is not None
|
||||||
palette = im.im.getpalette("RGB", "BGR")
|
palette = im.im.getpalette("RGB", "BGR")
|
||||||
colormaplength, colormapentry = len(palette) // 3, 24
|
colormaplength, colormapentry = len(palette) // 3, 24
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user