main_header of Codestream object is now a property. #212
This improves loading time of glymur.data.jpxfile() by 33%.
This commit is contained in:
parent
96db5e1a6a
commit
b719313554
1 changed files with 19 additions and 3 deletions
|
|
@ -997,10 +997,23 @@ class ContiguousCodestreamBox(Jp2kBox):
|
||||||
"""
|
"""
|
||||||
def __init__(self, main_header=None, length=0, offset=-1):
|
def __init__(self, main_header=None, length=0, offset=-1):
|
||||||
Jp2kBox.__init__(self, box_id='jp2c', longname='Contiguous Codestream')
|
Jp2kBox.__init__(self, box_id='jp2c', longname='Contiguous Codestream')
|
||||||
self.main_header = main_header
|
self._main_header = main_header
|
||||||
self.length = length
|
self.length = length
|
||||||
self.offset = offset
|
self.offset = offset
|
||||||
|
|
||||||
|
# The filename can be set if lazy loading is desired.
|
||||||
|
self._filename = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def main_header(self):
|
||||||
|
if self._main_header is None:
|
||||||
|
if self._filename is not None:
|
||||||
|
with open(self._filename, 'rb') as fptr:
|
||||||
|
fptr.seek(self._offset + 8)
|
||||||
|
main_header = Codestream(fptr, self._length, header_only=True)
|
||||||
|
self._main_header = main_header
|
||||||
|
return self._main_header
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
msg = "glymur.jp2box.ContiguousCodeStreamBox(main_header={0})"
|
msg = "glymur.jp2box.ContiguousCodeStreamBox(main_header={0})"
|
||||||
return msg.format(repr(self.main_header))
|
return msg.format(repr(self.main_header))
|
||||||
|
|
@ -1035,8 +1048,11 @@ class ContiguousCodestreamBox(Jp2kBox):
|
||||||
-------
|
-------
|
||||||
ContiguousCodestreamBox instance
|
ContiguousCodestreamBox instance
|
||||||
"""
|
"""
|
||||||
main_header = Codestream(fptr, length, header_only=True)
|
box = cls(None, length=length, offset=offset)
|
||||||
return cls(main_header, length=length, offset=offset)
|
box._filename = fptr.name
|
||||||
|
box._length = length
|
||||||
|
box._offset = offset
|
||||||
|
return box
|
||||||
|
|
||||||
|
|
||||||
class DataReferenceBox(Jp2kBox):
|
class DataReferenceBox(Jp2kBox):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue