mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Merge pull request #5654 from radarhere/ihdr
This commit is contained in:
commit
57c672efcc
BIN
Tests/images/balloon_eciRGBv2_aware.jp2
Normal file
BIN
Tests/images/balloon_eciRGBv2_aware.jp2
Normal file
Binary file not shown.
|
@ -159,6 +159,16 @@ def test_load_dpi():
|
|||
assert "dpi" not in im.info
|
||||
|
||||
|
||||
def test_restricted_icc_profile():
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||
try:
|
||||
# JPEG2000 image with a restricted ICC profile and a known colorspace
|
||||
with Image.open("Tests/images/balloon_eciRGBv2_aware.jp2") as im:
|
||||
assert im.mode == "RGB"
|
||||
finally:
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||
|
||||
|
||||
def test_header_errors():
|
||||
for path in (
|
||||
"Tests/images/invalid_header_length.jp2",
|
||||
|
|
|
@ -159,50 +159,23 @@ def _parse_jp2_header(fp):
|
|||
bpc = None
|
||||
nc = None
|
||||
dpi = None # 2-tuple of DPI info, or None
|
||||
unkc = 0 # Colorspace information unknown
|
||||
|
||||
while header.has_next_box():
|
||||
tbox = header.next_box_type()
|
||||
|
||||
if tbox == b"ihdr":
|
||||
height, width, nc, bpc, c, unkc, ipr = header.read_fields(">IIHBBBB")
|
||||
height, width, nc, bpc = header.read_fields(">IIHB")
|
||||
size = (width, height)
|
||||
if unkc:
|
||||
if nc == 1 and (bpc & 0x7F) > 8:
|
||||
mode = "I;16"
|
||||
elif nc == 1:
|
||||
mode = "L"
|
||||
elif nc == 2:
|
||||
mode = "LA"
|
||||
elif nc == 3:
|
||||
mode = "RGB"
|
||||
elif nc == 4:
|
||||
mode = "RGBA"
|
||||
elif tbox == b"colr":
|
||||
meth, prec, approx = header.read_fields(">BBB")
|
||||
if meth == 1 and unkc == 0:
|
||||
cs = header.read_fields(">I")[0]
|
||||
if cs == 16: # sRGB
|
||||
if nc == 1 and (bpc & 0x7F) > 8:
|
||||
mode = "I;16"
|
||||
elif nc == 1:
|
||||
mode = "L"
|
||||
elif nc == 3:
|
||||
mode = "RGB"
|
||||
elif nc == 4:
|
||||
mode = "RGBA"
|
||||
elif cs == 17: # grayscale
|
||||
if nc == 1 and (bpc & 0x7F) > 8:
|
||||
mode = "I;16"
|
||||
elif nc == 1:
|
||||
mode = "L"
|
||||
elif nc == 2:
|
||||
mode = "LA"
|
||||
elif cs == 18: # sYCC
|
||||
if nc == 3:
|
||||
mode = "RGB"
|
||||
elif nc == 4:
|
||||
mode = "RGBA"
|
||||
if nc == 1 and (bpc & 0x7F) > 8:
|
||||
mode = "I;16"
|
||||
elif nc == 1:
|
||||
mode = "L"
|
||||
elif nc == 2:
|
||||
mode = "LA"
|
||||
elif nc == 3:
|
||||
mode = "RGB"
|
||||
elif nc == 4:
|
||||
mode = "RGBA"
|
||||
elif tbox == b"res ":
|
||||
res = header.read_boxes()
|
||||
while res.has_next_box():
|
||||
|
|
Loading…
Reference in New Issue
Block a user