Skip to content

Commit

Permalink
Merge pull request #7725 from radarhere/type_hints_tga
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jan 17, 2024
2 parents 6fd85cf + 54c96df commit dd753f4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/PIL/TgaImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import annotations

import warnings
from io import BytesIO

from . import Image, ImageFile, ImagePalette
from ._binary import i16le as i16
Expand Down Expand Up @@ -49,8 +50,10 @@ class TgaImageFile(ImageFile.ImageFile):
format = "TGA"
format_description = "Targa"

def _open(self):
def _open(self) -> None:
# process header
assert self.fp is not None

s = self.fp.read(18)

id_len = s[0]
Expand Down Expand Up @@ -151,8 +154,9 @@ def _open(self):
except KeyError:
pass # cannot decode

def load_end(self):
def load_end(self) -> None:
if self._flip_horizontally:
assert self.im is not None
self.im = self.im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)


Expand All @@ -171,7 +175,7 @@ def load_end(self):
}


def _save(im, fp, filename):
def _save(im: Image.Image, fp: BytesIO, filename: str) -> None:
try:
rawmode, bits, colormaptype, imagetype = SAVE[im.mode]
except KeyError as e:
Expand All @@ -194,6 +198,7 @@ def _save(im, fp, filename):
warnings.warn("id_section has been trimmed to 255 characters")

if colormaptype:
assert im.im is not None
palette = im.im.getpalette("RGB", "BGR")
colormaplength, colormapentry = len(palette) // 3, 24
else:
Expand Down

0 comments on commit dd753f4

Please sign in to comment.