Checking for the codestream markers to always occupy two bytes.
This commit is contained in:
parent
1ccd793bae
commit
83f17b2181
3 changed files with 70 additions and 3 deletions
|
|
@ -137,8 +137,17 @@ platforms.
|
||||||
Testing
|
Testing
|
||||||
'''''''
|
'''''''
|
||||||
|
|
||||||
If you wish to run the tests (strongly recommended :-), you can either run them
|
There are two environment variables you may wish to set before running the
|
||||||
from within python as follows ... ::
|
tests.
|
||||||
|
|
||||||
|
* **OPJ_DATA_ROOT** - points to directory for OpenJPEG test data
|
||||||
|
* **FORMAT_CORPUS_ROOT** - points to directory for format-corpus repository (see https://github.com/openplanets/format-corpus)
|
||||||
|
|
||||||
|
Setting these two environment variables is not required, as any tests using
|
||||||
|
either of them will be skipped.
|
||||||
|
|
||||||
|
In order to run the tests, you can either run them from within
|
||||||
|
python as follows ... ::
|
||||||
|
|
||||||
>>> import glymur
|
>>> import glymur
|
||||||
>>> glymur.runtests()
|
>>> glymur.runtests()
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,14 @@ class Codestream(object):
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
read_buffer = fptr.read(2)
|
read_buffer = fptr.read(2)
|
||||||
marker_id, = struct.unpack('>H', read_buffer)
|
try:
|
||||||
|
marker_id, = struct.unpack('>H', read_buffer)
|
||||||
|
except struct.error:
|
||||||
|
# Treat this as a warning.
|
||||||
|
msg = "Marker had length {0} instead of expected length of 2 "
|
||||||
|
msg += "bytes. Codestream parsing terminated."
|
||||||
|
warnings.warn(msg.format(len(read_buffer)))
|
||||||
|
break
|
||||||
|
|
||||||
if marker_id == 0xff90 and header_only:
|
if marker_id == 0xff90 and header_only:
|
||||||
# Start-of-tile (SOT) means that we are out of the main header
|
# Start-of-tile (SOT) means that we are out of the main header
|
||||||
|
|
|
||||||
51
glymur/test/test_format_corpus.py
Normal file
51
glymur/test/test_format_corpus.py
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
"""
|
||||||
|
These tests deal with JPX/JP2/J2K images in the format-corpus repository.
|
||||||
|
"""
|
||||||
|
#pylint: disable-all
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.hexversion < 0x02070000:
|
||||||
|
import unittest2 as unittest
|
||||||
|
else:
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
from glymur import Jp2k
|
||||||
|
import glymur
|
||||||
|
|
||||||
|
try:
|
||||||
|
data_root = os.environ['FORMAT_CORPUS_ROOT']
|
||||||
|
except KeyError:
|
||||||
|
data_root = None
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||||
|
"Requires features introduced in 3.2 (assertWarns)")
|
||||||
|
@unittest.skipIf(data_root is None,
|
||||||
|
"FORMAT_CORPUS_ROOT environment variable not set")
|
||||||
|
class TestSuite(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_balloon_trunc1(self):
|
||||||
|
# Has one byte shaved off of EOC marker.
|
||||||
|
jfile = os.path.join(data_root,
|
||||||
|
'jp2k-test/byteCorruption/balloon_trunc1.jp2')
|
||||||
|
j2k = Jp2k(jfile)
|
||||||
|
with self.assertWarns(UserWarning):
|
||||||
|
c = j2k.get_codestream(header_only=False)
|
||||||
|
|
||||||
|
# The last segment is truncated, so there should not be an EOC marker.
|
||||||
|
self.assertNotEqual(c.segment[-1].marker_id, 'EOC')
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue