|
|
@ -5,30 +5,12 @@ from datetime import datetime |
|
|
|
from nd2reader.model.metadata import Metadata |
|
|
|
from nd2reader.parser.base import BaseParser |
|
|
|
from nd2reader.driver.v3 import V3Driver |
|
|
|
from nd2reader.common.v3 import read_chunk |
|
|
|
import re |
|
|
|
import six |
|
|
|
import struct |
|
|
|
|
|
|
|
|
|
|
|
def read_chunk(fh, chunk_location): |
|
|
|
""" |
|
|
|
Gets the data for a given chunk pointer |
|
|
|
|
|
|
|
:rtype: bytes |
|
|
|
|
|
|
|
""" |
|
|
|
fh.seek(chunk_location) |
|
|
|
# The chunk metadata is always 16 bytes long |
|
|
|
chunk_metadata = fh.read(16) |
|
|
|
header, relative_offset, data_length = struct.unpack("IIQ", chunk_metadata) |
|
|
|
if header != 0xabeceda: |
|
|
|
raise ValueError("The ND2 file seems to be corrupted.") |
|
|
|
# We start at the location of the chunk metadata, skip over the metadata, and then proceed to the |
|
|
|
# start of the actual data field, which is at some arbitrary place after the metadata. |
|
|
|
fh.seek(chunk_location + 16 + relative_offset) |
|
|
|
return fh.read(data_length) |
|
|
|
|
|
|
|
|
|
|
|
class V3Parser(BaseParser): |
|
|
|
""" Parses ND2 files and creates a Metadata and ImageReader object. """ |
|
|
|
CHUNK_HEADER = 0xabeceda |
|
|
|