File format name: Nikon ND2

Maintainer: Nikon

Software that produces these files: NIS Elements

Other software that reads this format: NIS Elements

Specifications: none :-(

Structure:
** All ND2 files are little-endian.

Old ND2:

"Old" ND2 refers to files that were generated before May or June of 2007. Basically, the file consists of a series of JPEG-2000 codestreams, with a block of XML stuck on the end.

'file' on an old ND2 file looks like this:

user@machine:/data/$ file old_nd2.nd2
old_nd2.nd2: JPEG 2000 image data
The first 8 bytes of the file should be: 0x00 00 00 0c 6a 50 20 20

The only really noteworthy aspect of this format is that the XML block at the end of the file is malformed, so we have to parse it manually (meaning someone at some point may find missing or mislabeled metadata).

New ND2:

"New" ND2 refers to files that were generated after May or June of 2007. The new format is much preferred to the old format, in that the pixels are stored raw or zlib-compressed (and thus JAI is not required).

'file' on a new ND2 file looks like this:

user@machine:/data/$ file new_nd2.nd2
new_nd2.nd2: PARIX object not stripped
The file is divided into chunks of the following format:
4 byte header - 0xda ce be 0a
4 bytes - signed integer (length part 1)
4 bytes - signed integer (length part 2)
4 bytes - signed integer (ignored)
length pt 1 + length pt 2 bytes of data

The data portion of each chunk begins with a string identifer terminated by "!"; for pixel data, this is "ImageDataSeq|%n!", where %n is the plane number (indexed from 0). Otherwise, if the identifier begins with "Image%s!", you can expect a block of XML metadata. Unlike old ND2, this is valid XML, which we parse using SAX.

Other notes: