mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 01:16:16 +03:00
Merge pull request #7728 from radarhere/type_hints_mpeg
This commit is contained in:
commit
c23904a4bd
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
from __future__ import annotations
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
from . import Image, ImageFile
|
||||
from ._binary import i8
|
||||
|
||||
|
@ -22,15 +24,15 @@ from ._binary import i8
|
|||
|
||||
|
||||
class BitStream:
|
||||
def __init__(self, fp):
|
||||
def __init__(self, fp: BytesIO) -> None:
|
||||
self.fp = fp
|
||||
self.bits = 0
|
||||
self.bitbuffer = 0
|
||||
|
||||
def next(self):
|
||||
def next(self) -> int:
|
||||
return i8(self.fp.read(1))
|
||||
|
||||
def peek(self, bits):
|
||||
def peek(self, bits: int) -> int:
|
||||
while self.bits < bits:
|
||||
c = self.next()
|
||||
if c < 0:
|
||||
|
@ -40,13 +42,13 @@ class BitStream:
|
|||
self.bits += 8
|
||||
return self.bitbuffer >> (self.bits - bits) & (1 << bits) - 1
|
||||
|
||||
def skip(self, bits):
|
||||
def skip(self, bits: int) -> None:
|
||||
while self.bits < bits:
|
||||
self.bitbuffer = (self.bitbuffer << 8) + i8(self.fp.read(1))
|
||||
self.bits += 8
|
||||
self.bits = self.bits - bits
|
||||
|
||||
def read(self, bits):
|
||||
def read(self, bits: int) -> int:
|
||||
v = self.peek(bits)
|
||||
self.bits = self.bits - bits
|
||||
return v
|
||||
|
@ -61,9 +63,10 @@ class MpegImageFile(ImageFile.ImageFile):
|
|||
format = "MPEG"
|
||||
format_description = "MPEG"
|
||||
|
||||
def _open(self):
|
||||
s = BitStream(self.fp)
|
||||
def _open(self) -> None:
|
||||
assert self.fp is not None
|
||||
|
||||
s = BitStream(self.fp)
|
||||
if s.read(32) != 0x1B3:
|
||||
msg = "not an MPEG file"
|
||||
raise SyntaxError(msg)
|
||||
|
|
Loading…
Reference in New Issue
Block a user