No need for InconsistentStartOfTileError anymore, closes #81.

Also fixed corruption of devel left over from issue number 79.
This commit is contained in:
jevans 2013-07-21 20:32:18 -04:00
commit efca5e3d34
2 changed files with 11 additions and 31 deletions

View file

@ -5,7 +5,6 @@ codestreams.
"""
# pylint: disable=C0302,R0902,R0903,R0913
from itertools import takewhile
import math
import struct
import sys
@ -43,16 +42,6 @@ for _marker in range(0xff90, 0xff94):
_VALID_MARKERS.append(_marker)
class InconsistentStartOfTileError(IOError):
"""To be raised if bad SOT segment encountered.
SOT segment offsets are recorded as encountered. The offsets should all be
different.
"""
def __init__(self, msg):
IOError.__init__(self, msg)
class Codestream(object):
"""Container for codestream information.
@ -115,6 +104,11 @@ class Codestream(object):
read_buffer = fptr.read(2)
marker_id, = struct.unpack('>H', read_buffer)
if marker_id == 0xff90 and header_only:
# Start-of-tile (SOT) means that we are out of the main header
# and there is no need to go further.
break
try:
segment = self._process_marker_segment(fptr, marker_id)
except Exception as error:
@ -139,12 +133,6 @@ class Codestream(object):
fptr.seek(self._tile_offset[-1] + self._tile_length[-1])
if header_only:
# start-of-tile (SOT) means we are out of the main header.
# No need to go any further.
gen = takewhile(lambda s: s.marker_id != 'SOT', self.segment)
self.segment = list(gen)
def _process_marker_segment(self, fptr, marker_id):
"""Process and return a segment from the codestream.
@ -210,19 +198,12 @@ class Codestream(object):
# we encounter start-of-data marker segments.
segment = _parse_sot_segment(fptr)
if segment.offset not in self._tile_offset:
self._tile_offset.append(segment.offset)
if segment.psot == 0:
tile_part_length = self.offset + self.length - segment.offset - 2
else:
tile_part_length = segment.psot
self._tile_length.append(tile_part_length)
self._tile_offset.append(segment.offset)
if segment.psot == 0:
tile_part_length = self.offset + self.length - segment.offset - 2
else:
msg = "Inconsistent start-of-tile (SOT) marker segment "
msg += "encountered in tile with index {0}. "
msg += "Codestream parsing terminated."
msg = msg.format(segment.isot)
raise InconsistentStartOfTileError(msg)
tile_part_length = segment.psot
self._tile_length.append(tile_part_length)
elif marker_id == 0xff93:
# start of data. Need to seek past the current tile part.

View file

@ -6954,8 +6954,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(c.segment[3]._exponent, [4] + [5, 5, 6] * 5)
def test_NR_merged_dump(self):
jfile = os.path.join(data_root,
'input/nonregression/merged.jp2')
jfile = os.path.join(data_root, 'input/nonregression/merged.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]