Class ND2Reader

All Implemented Interfaces:
Closeable, AutoCloseable, ICompressedTileReader, IFormatHandler, IFormatReader, IMetadataConfigurable, IPyramidHandler

public class ND2Reader extends SubResolutionFormatReader
ND2Reader is the file format reader for Nikon ND2 files. The JAI ImageIO library is required to use this reader; it is available from http://jai-imageio.dev.java.net. Note that JAI ImageIO is bundled with a version of the JJ2000 library, so it is important that either: (1) the JJ2000 jar file is *not* in the classpath; or (2) the JAI jar file precedes JJ2000 in the classpath. Thanks to Tom Caswell for additions to the ND2 metadata parsing logic.
  • Field Details

    • ND2_MAGIC_BYTES_1

      public static final long ND2_MAGIC_BYTES_1
      See Also:
    • ND2_MAGIC_BYTES_2

      public static final long ND2_MAGIC_BYTES_2
      See Also:
    • BUFFER_SIZE

      private static final int BUFFER_SIZE
      See Also:
    • USE_CHUNKMAP_LEGACY_KEY

      @Deprecated public static final String USE_CHUNKMAP_LEGACY_KEY
      Deprecated.
      Legacy chunkmap option key will be removed in Bio-Formats 8.0.0.
      See Also:
    • USE_CHUNKMAP_KEY

      public static final String USE_CHUNKMAP_KEY
      See Also:
    • USE_CHUNKMAP_DEFAULT

      public static final boolean USE_CHUNKMAP_DEFAULT
      See Also:
    • offsets

      private long[][] offsets
      Array of image offsets.
    • isJPEG

      private boolean isJPEG
      Whether or not the pixel data is compressed using JPEG 2000.
    • codec

      private Codec codec
      Codec to use when decompressing pixel data.
    • isLossless

      private boolean isLossless
      Whether or not the pixel data is losslessly compressed.
    • tsT

      private ArrayList<Double> tsT
    • positionCount

      private int positionCount
    • fieldIndex

      private int fieldIndex
    • xOffset

      private long xOffset
    • yOffset

      private long yOffset
    • zOffset

      private long zOffset
    • pfsOffset

      private long pfsOffset
    • pfsStateOffset

      private long pfsStateOffset
    • posX

      private ArrayList<ome.units.quantity.Length> posX
    • posY

      private ArrayList<ome.units.quantity.Length> posY
    • posZ

      private ArrayList<ome.units.quantity.Length> posZ
    • exposureTime

      private ArrayList<Double> exposureTime
    • channelColors

      private Map<String,Integer> channelColors
    • split

      private boolean split
    • lastChannel

      private int lastChannel
    • colors

      private int[] colors
    • useZ

      private Boolean useZ
    • nXFields

      private int nXFields
    • backupHandler

      private ND2Handler backupHandler
    • trueSizeX

      private double trueSizeX
    • trueSizeY

      private double trueSizeY
    • trueSizeZ

      private Double trueSizeZ
    • textChannelNames

      private ArrayList<String> textChannelNames
    • textEmissionWavelengths

      private ArrayList<Double> textEmissionWavelengths
    • textData

      private boolean textData
    • refractiveIndex

      private Double refractiveIndex
    • imageMetadataLVProcessed

      Boolean imageMetadataLVProcessed
    • imageMetadataLVOrder

      String imageMetadataLVOrder
    • lensNA

      private transient Double lensNA
    • objectiveMag

      private transient Double objectiveMag
    • objectiveModel

      private transient String objectiveModel
  • Constructor Details

    • ND2Reader

      public ND2Reader()
      Constructs a new ND2 reader.
  • Method Details

    • useChunkMap

      public boolean useChunkMap()
    • isThisType

      public boolean isThisType(loci.common.RandomAccessInputStream stream) throws IOException
      Description copied from interface: IFormatReader
      Checks if the given stream is a valid stream for this file format. The number of bytes read is format-dependent.
      Specified by:
      isThisType in interface IFormatReader
      Overrides:
      isThisType in class FormatReader
      Parameters:
      stream - A RandomAccessInputStream representing the file to check. The first byte in the stream is assumed to be the first byte in the file.
      Returns:
      true if the file represented by the stream can be read by this reader; false otherwise.
      Throws:
      IOException
    • get8BitLookupTable

      public byte[][] get8BitLookupTable()
      Description copied from interface: IFormatReader
      Gets the 8-bit color lookup table associated with the most recently opened image. If no image planes have been opened, or if IFormatReader.isIndexed() returns false, then this may return null. Also, if IFormatReader.getPixelType() returns anything other than FormatTools.INT8 or FormatTools.UINT8, this method will return null.
      Specified by:
      get8BitLookupTable in interface IFormatReader
      Overrides:
      get8BitLookupTable in class FormatReader
    • get16BitLookupTable

      public short[][] get16BitLookupTable()
      Description copied from interface: IFormatReader
      Gets the 16-bit color lookup table associated with the most recently opened image. If no image planes have been opened, or if IFormatReader.isIndexed() returns false, then this may return null. Also, if IFormatReader.getPixelType() returns anything other than FormatTools.INT16 or FormatTools.UINT16, this method will return null.
      Specified by:
      get16BitLookupTable in interface IFormatReader
      Overrides:
      get16BitLookupTable in class FormatReader
    • openBytes

      public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException
      Description copied from interface: IFormatReader
      Obtains a sub-image of the specified image plane into a pre-allocated byte array.
      Specified by:
      openBytes in interface IFormatReader
      Specified by:
      openBytes in class FormatReader
      Parameters:
      no - the plane index within the current series.
      buf - a pre-allocated buffer.
      x - X coordinate of the upper-left corner of the sub-image
      y - Y coordinate of the upper-left corner of the sub-image
      w - width of the sub-image
      h - height of the sub-image
      Returns:
      the pre-allocated buffer buf for convenience.
      Throws:
      FormatException - if there was a problem parsing the metadata of the file.
      IOException - if there was a problem reading the file.
      See Also:
    • close

      public void close(boolean fileOnly) throws IOException
      Description copied from interface: IFormatReader
      Closes the currently open file. If the flag is set, this is all that happens; if unset, it is equivalent to calling Closeable.close().
      Specified by:
      close in interface IFormatReader
      Overrides:
      close in class SubResolutionFormatReader
      Throws:
      IOException
    • getAvailableOptions

      protected ArrayList<String> getAvailableOptions()
      Description copied from class: FormatReader
      Returns the list of available metadata options.
      Overrides:
      getAvailableOptions in class FormatReader
    • initFile

      protected void initFile(String id) throws FormatException, IOException
      Description copied from class: SubResolutionFormatReader
      Initializes the given file (parsing header information, etc.). Most subclasses should override this method to perform initialization operations such as parsing metadata.
      Overrides:
      initFile in class SubResolutionFormatReader
      Throws:
      FormatException - if a parsing error occurs processing the file.
      IOException - if an I/O error occurs processing the file
    • iterateIn

      private ArrayList<String> iterateIn(loci.common.RandomAccessInputStream in, Long stop)
      Function for iterating through ND2 metaAttributes
      Parameters:
      in - stream of bytes from file
      stop - position where to stop
      Returns:
      text info values, if found
    • iterateIn

      private ArrayList<String> iterateIn(loci.common.RandomAccessInputStream in, Long stop, boolean minimal)
      Function for iterating through ND2 metaAttributes
      Parameters:
      in - stream of bytes from file
      stop - position where to stop
      minimal - true if values should be read with no additional metadata parsing
      Returns:
      text info values, if found
    • populateMetadataStore

      private void populateMetadataStore(ND2Handler handler) throws FormatException
      Throws:
      FormatException
    • createCodec

      private Codec createCodec(boolean isJPEG)
    • copyPixels

      private void copyPixels(int x, int y, int w, int h, int bpp, int scanlinePad, byte[] pix, byte[] buf, boolean split) throws IOException
      Throws:
      IOException
    • sanitizeControl

      public static String sanitizeControl(String s)
      Remove control and invalid characters from the given string.
    • getScanlinePad

      private int getScanlinePad()
    • parseText

      private void parseText(String textString, int offsetCount, boolean useDimensions)
    • setDimensions

      private void setDimensions(int numT, int numZ, int numSeries)
    • getOffsets

      public long[][] getOffsets()
      Returns:
      offsets to pixel data
    • setOffsets

      public void setOffsets(String file, long[][] newOffsets) throws IOException
      Change the underlying file path and pixel data offsets, keeping all other metadata the same.
      Throws:
      IOException