mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-05 06:00:58 +03:00
Added reading of J2K comments
This commit is contained in:
parent
0e3f51dec6
commit
dd410e4b32
|
@ -424,8 +424,9 @@ def test_pclr() -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_comment() -> None:
|
def test_comment() -> None:
|
||||||
with Image.open("Tests/images/comment.jp2") as im:
|
for path in ("Tests/images/9bit.j2k", "Tests/images/comment.jp2"):
|
||||||
assert im.info["comment"] == b"Created by OpenJPEG version 2.5.0"
|
with Image.open(path) as im:
|
||||||
|
assert im.info["comment"] == b"Created by OpenJPEG version 2.5.0"
|
||||||
|
|
||||||
# Test an image that is truncated partway through a codestream
|
# Test an image that is truncated partway through a codestream
|
||||||
with open("Tests/images/comment.jp2", "rb") as fp:
|
with open("Tests/images/comment.jp2", "rb") as fp:
|
||||||
|
|
|
@ -252,6 +252,7 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
||||||
if sig == b"\xff\x4f\xff\x51":
|
if sig == b"\xff\x4f\xff\x51":
|
||||||
self.codec = "j2k"
|
self.codec = "j2k"
|
||||||
self._size, self._mode = _parse_codestream(self.fp)
|
self._size, self._mode = _parse_codestream(self.fp)
|
||||||
|
self._parse_comment()
|
||||||
else:
|
else:
|
||||||
sig = sig + self.fp.read(8)
|
sig = sig + self.fp.read(8)
|
||||||
|
|
||||||
|
@ -262,6 +263,9 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
||||||
if dpi is not None:
|
if dpi is not None:
|
||||||
self.info["dpi"] = dpi
|
self.info["dpi"] = dpi
|
||||||
if self.fp.read(12).endswith(b"jp2c\xff\x4f\xff\x51"):
|
if self.fp.read(12).endswith(b"jp2c\xff\x4f\xff\x51"):
|
||||||
|
hdr = self.fp.read(2)
|
||||||
|
length = _binary.i16be(hdr)
|
||||||
|
self.fp.seek(length - 2, os.SEEK_CUR)
|
||||||
self._parse_comment()
|
self._parse_comment()
|
||||||
else:
|
else:
|
||||||
msg = "not a JPEG 2000 file"
|
msg = "not a JPEG 2000 file"
|
||||||
|
@ -296,10 +300,6 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
||||||
]
|
]
|
||||||
|
|
||||||
def _parse_comment(self) -> None:
|
def _parse_comment(self) -> None:
|
||||||
hdr = self.fp.read(2)
|
|
||||||
length = _binary.i16be(hdr)
|
|
||||||
self.fp.seek(length - 2, os.SEEK_CUR)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
marker = self.fp.read(2)
|
marker = self.fp.read(2)
|
||||||
if not marker:
|
if not marker:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user