mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-11 17:10:58 +03:00
Merge branch 'main' into context_manager
This commit is contained in:
commit
dae31540f4
|
@ -429,7 +429,8 @@ 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"):
|
||||||
|
with Image.open(path) as im:
|
||||||
assert im.info["comment"] == b"Created by OpenJPEG version 2.5.0"
|
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
|
||||||
|
|
|
@ -52,6 +52,12 @@ zlib library, and what version of zlib-ng is being used::
|
||||||
Other Changes
|
Other Changes
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
Reading JPEG 2000 comments
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
When opening a JPEG 2000 image, the comment may now be read into
|
||||||
|
:py:attr:`~PIL.Image.Image.info` for J2K images, not just JP2 images.
|
||||||
|
|
||||||
zlib-ng in wheels
|
zlib-ng in wheels
|
||||||
^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|
|
@ -253,6 +253,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)
|
||||||
|
|
||||||
|
@ -263,6 +264,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"
|
||||||
|
@ -298,10 +302,6 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
def _parse_comment(self) -> None:
|
def _parse_comment(self) -> None:
|
||||||
assert self.fp is not None
|
assert self.fp is not 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:
|
||||||
|
|
|
@ -640,7 +640,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state) {
|
||||||
opj_dparameters_t params;
|
opj_dparameters_t params;
|
||||||
OPJ_COLOR_SPACE color_space;
|
OPJ_COLOR_SPACE color_space;
|
||||||
j2k_unpacker_t unpack = NULL;
|
j2k_unpacker_t unpack = NULL;
|
||||||
size_t buffer_size = 0, tile_bytes = 0;
|
size_t tile_bytes = 0;
|
||||||
unsigned n, tile_height, tile_width;
|
unsigned n, tile_height, tile_width;
|
||||||
int subsampling;
|
int subsampling;
|
||||||
int total_component_width = 0;
|
int total_component_width = 0;
|
||||||
|
@ -870,7 +870,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state) {
|
||||||
tile_info.data_size = tile_bytes;
|
tile_info.data_size = tile_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer_size < tile_info.data_size) {
|
if (tile_info.data_size > 0) {
|
||||||
/* malloc check ok, overflow and tile size sanity check above */
|
/* malloc check ok, overflow and tile size sanity check above */
|
||||||
UINT8 *new = realloc(state->buffer, tile_info.data_size);
|
UINT8 *new = realloc(state->buffer, tile_info.data_size);
|
||||||
if (!new) {
|
if (!new) {
|
||||||
|
@ -883,7 +883,6 @@ j2k_decode_entry(Imaging im, ImagingCodecState state) {
|
||||||
to valgrind errors. */
|
to valgrind errors. */
|
||||||
memset(new, 0, tile_info.data_size);
|
memset(new, 0, tile_info.data_size);
|
||||||
state->buffer = new;
|
state->buffer = new;
|
||||||
buffer_size = tile_info.data_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opj_decode_tile_data(
|
if (!opj_decode_tile_data(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user