Erroring out appropriately when _read_openjpeg gets differing sampling
If the subsampling factors are different, we should error out when using read with libopenjpeg. Closed #72
This commit is contained in:
parent
a57de5d872
commit
a8219236aa
4 changed files with 17 additions and 9 deletions
|
|
@ -613,9 +613,19 @@ class Jp2k(Jp2kBox):
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
------
|
------
|
||||||
IOError
|
RuntimeError
|
||||||
If the image has differing subsample factors.
|
If the image has differing subsample factors.
|
||||||
"""
|
"""
|
||||||
|
# Check for differing subsample factors.
|
||||||
|
codestream = self.get_codestream(header_only=True)
|
||||||
|
dxs = np.array(codestream.segment[1].XRsiz)
|
||||||
|
dys = np.array(codestream.segment[1].YRsiz)
|
||||||
|
if np.any(dxs - dxs[0]) or np.any(dys - dys[0]):
|
||||||
|
msg = "Components must all have the same subsampling factors "
|
||||||
|
msg += "to use this method with OpenJPEG 1.5.1. Please consider "
|
||||||
|
msg += "using OPENJP2 instead."
|
||||||
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
|
|
||||||
with ExitStack() as stack:
|
with ExitStack() as stack:
|
||||||
# Set decoding parameters.
|
# Set decoding parameters.
|
||||||
|
|
@ -653,7 +663,6 @@ class Jp2k(Jp2kBox):
|
||||||
stack.callback(opj._cio_close, cio)
|
stack.callback(opj._cio_close, cio)
|
||||||
|
|
||||||
ncomps = image.contents.numcomps
|
ncomps = image.contents.numcomps
|
||||||
|
|
||||||
component = image.contents.comps[0]
|
component = image.contents.comps[0]
|
||||||
if component.sgnd:
|
if component.sgnd:
|
||||||
if component.prec <= 8:
|
if component.prec <= 8:
|
||||||
|
|
@ -726,7 +735,7 @@ class Jp2k(Jp2kBox):
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
------
|
------
|
||||||
IOError
|
RuntimeError
|
||||||
If the image has differing subsample factors.
|
If the image has differing subsample factors.
|
||||||
"""
|
"""
|
||||||
# Check for differing subsample factors.
|
# Check for differing subsample factors.
|
||||||
|
|
@ -735,7 +744,7 @@ class Jp2k(Jp2kBox):
|
||||||
dys = np.array(codestream.segment[1].YRsiz)
|
dys = np.array(codestream.segment[1].YRsiz)
|
||||||
if np.any(dxs - dxs[0]) or np.any(dys - dys[0]):
|
if np.any(dxs - dxs[0]) or np.any(dys - dys[0]):
|
||||||
msg = "Components must all have the same subsampling factors."
|
msg = "Components must all have the same subsampling factors."
|
||||||
raise IOError(msg)
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
img_array = self._read_common(reduce=reduce,
|
img_array = self._read_common(reduce=reduce,
|
||||||
layer=layer,
|
layer=layer,
|
||||||
|
|
|
||||||
|
|
@ -319,7 +319,7 @@ class TestJp2k(unittest.TestCase):
|
||||||
# Issue 86.
|
# Issue 86.
|
||||||
filename = os.path.join(data_root, 'input/conformance/p0_05.j2k')
|
filename = os.path.join(data_root, 'input/conformance/p0_05.j2k')
|
||||||
j = Jp2k(filename)
|
j = Jp2k(filename)
|
||||||
with self.assertRaises(IOError):
|
with self.assertRaises(RuntimeError):
|
||||||
j.read()
|
j.read()
|
||||||
|
|
||||||
@unittest.skipIf(data_root is None,
|
@unittest.skipIf(data_root is None,
|
||||||
|
|
|
||||||
|
|
@ -794,12 +794,11 @@ class TestSuite(unittest.TestCase):
|
||||||
data = Jp2k(jfile).read()
|
data = Jp2k(jfile).read()
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
|
|
||||||
@unittest.skip("Should have worked, must be investigated.")
|
|
||||||
def test_NR_DEC_file_409752_jp2_40_decode(self):
|
def test_NR_DEC_file_409752_jp2_40_decode(self):
|
||||||
jfile = os.path.join(data_root, 'input/nonregression/file409752.jp2')
|
jfile = os.path.join(data_root, 'input/nonregression/file409752.jp2')
|
||||||
j = Jp2k(jfile)
|
j = Jp2k(jfile)
|
||||||
data = j.read()
|
with self.assertRaises(RuntimeError) as ce:
|
||||||
self.assertTrue(True)
|
data = j.read()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -1068,7 +1068,7 @@ class TestSuite(unittest.TestCase):
|
||||||
def test_NR_DEC_file_409752_jp2_40_decode(self):
|
def test_NR_DEC_file_409752_jp2_40_decode(self):
|
||||||
jfile = os.path.join(data_root,
|
jfile = os.path.join(data_root,
|
||||||
'input/nonregression/file409752.jp2')
|
'input/nonregression/file409752.jp2')
|
||||||
with self.assertRaises(IOError):
|
with self.assertRaises(RuntimeError):
|
||||||
data = Jp2k(jfile).read()
|
data = Jp2k(jfile).read()
|
||||||
|
|
||||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue