40 """Parses the next marker in a codestream.
43 buffer: A buffer containing the codestream.
44 offset: The starting offset into the buffer.
47 A tuple (next_offset, tag) where next_offset is the offset after the marker,
48 and tag is the type tag. If no marker was found, next_offset will point to
49 the end of the buffer, and tag will be None. A marker is always 2 bytes.
53 next_offset = buffer.find(MARKER_START, offset)
55 next_offset = len(buffer)
60 if next_offset == len(buffer):
62 tag = buffer[next_offset]
63 if tag == MARKER_TAG_FILL:
68 if tag == MARKER_TAG_IGNORE:
71 return next_offset, tag
77 rewrite_buffer =
bytearray(BOX_HEADER_SIZE)
81 while offset < len(buffer):
83 if marker == MARKER_TAG_COMMENT:
85 rewrite_buffer.extend(buffer[start_offset:next_offset - MARKER_SIZE])
89 if marker
is not None:
91 next_offset -= MARKER_SIZE
92 start_offset = next_offset
99 rewrite_buffer.extend(buffer[start_offset:])
101 struct.pack_into(
'>I4s', rewrite_buffer, 0, len(rewrite_buffer), BOX_TAG_JP2C)
102 return rewrite_buffer