def __init__(self, fptr, length, header_only=True):
<EOL>process_marker_segment = {<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_marker,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_siz_segment,<EOL><NUM_LIT>: self._parse_cod_segment,<EOL><NUM_LIT>: self._parse_coc_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_tlm_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_plt_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_qcd_segment,<EOL><NUM_LIT>: self._parse_qcc_segment,<EOL><NUM_LIT>: self._parse_rgn_segment,<EOL><NUM_LIT>: self._parse_pod_segment,<EOL><NUM_LIT>: self._parse_ppm_segment,<EOL><NUM_LIT>: self._parse_ppt_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_crg_segment,<EOL><NUM_LIT>: self._parse_cme_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_reserved_segment,<EOL><NUM_LIT>: self._parse_unrecognized_segment,<EOL><NUM_LIT>: self._parse_sot_segment,<EOL><NUM_LIT>: self._parse_unrecognized_segment,<EOL><NUM_LIT>: self._parse_unrecognized_segment,<EOL><NUM_LIT>: self._parse_sod_segment,<EOL><NUM_LIT>: self._parse_eoc_segment<EOL>}<EOL>self.offset = fptr.tell()<EOL>self.length = length<EOL>self.segment = []<EOL>read_buffer = fptr.read(<NUM_LIT:2>)<EOL>segment = SOCsegment(offset=fptr.tell() - <NUM_LIT:2>, length=<NUM_LIT:0>)<EOL>self.segment.append(segment)<EOL>self._tile_offset = []<EOL>self._tile_length = []<EOL>while True:<EOL><INDENT>read_buffer = fptr.read(<NUM_LIT:2>)<EOL>try:<EOL><INDENT>self._marker_id, = struct.unpack('<STR_LIT>', read_buffer)<EOL><DEDENT>except struct.error:<EOL><INDENT>offset = fptr.tell() - <NUM_LIT:2><EOL>msg = ('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>msg = msg.format(offset=offset)<EOL>raise IOError(msg)<EOL><DEDENT>self._offset = fptr.tell() - <NUM_LIT:2><EOL>if self._marker_id == <NUM_LIT> and header_only:<EOL><INDENT>break<EOL><DEDENT>try:<EOL><INDENT>segment = process_marker_segment[self._marker_id](fptr)<EOL><DEDENT>except KeyError:<EOL><INDENT>msg = ('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>msg = msg.format(offset=self._offset,<EOL>marker_id=self._marker_id)<EOL>warnings.warn(msg, UserWarning)<EOL>break<EOL><DEDENT>self.segment.append(segment)<EOL>if self._marker_id == <NUM_LIT>:<EOL><INDENT>break<EOL><DEDENT>if self._marker_id == <NUM_LIT>:<EOL><INDENT>if self._parse_tpart_flag and not header_only:<EOL><INDENT>self._parse_tile_part_bit_stream(fptr, segment,<EOL>self._tile_length[-<NUM_LIT:1>])<EOL><DEDENT>new_offset = self._tile_offset[-<NUM_LIT:1>] + self._tile_length[-<NUM_LIT:1>]<EOL>fptr.seek(new_offset)<EOL><DEDENT><DEDENT>
Parameters
----------
fptr : file
    Open file object.
length : int
    Length of the codestream in bytes.
header_only : bool, optional
    If True, only marker segments in the main header are parsed.
    Supplying False may impose a large performance penalty.