Class TiffWriter

All Implemented Interfaces:
Closeable, AutoCloseable, ICompressedTileWriter, IFormatHandler, IFormatWriter, IMetadataConfigurable, IPyramidHandler
Direct Known Subclasses:
OMETiffWriter

public class TiffWriter extends FormatWriter
TiffWriter is the file format writer for TIFF files.
  • Field Details

    • COMPRESSION_UNCOMPRESSED

      public static final String COMPRESSION_UNCOMPRESSED
    • COMPRESSION_LZW

      public static final String COMPRESSION_LZW
    • COMPRESSION_J2K

      public static final String COMPRESSION_J2K
    • COMPRESSION_J2K_LOSSY

      public static final String COMPRESSION_J2K_LOSSY
    • COMPRESSION_JPEG

      public static final String COMPRESSION_JPEG
    • COMPRESSION_ZLIB

      public static final String COMPRESSION_ZLIB
    • BIG_TIFF_SUFFIXES

      private static final String[] BIG_TIFF_SUFFIXES
    • TILE_GRANULARITY

      private static final int TILE_GRANULARITY
      TIFF tiles must be of a height and width divisible by 16.
      See Also:
    • isBigTiff

      protected boolean isBigTiff
      Whether or not the output file is a BigTIFF file.
    • canDetectBigTiff

      protected boolean canDetectBigTiff
      Whether or not BigTIFF can be used automatically.
    • tiffSaver

      protected TiffSaver tiffSaver
      The TiffSaver that will do most of the writing.
    • in

      protected loci.common.RandomAccessInputStream in
      Input stream to use when overwriting data.
    • checkParams

      protected boolean checkParams
      Whether or not to check the parameters passed to saveBytes.
    • tileSizeX

      protected int tileSizeX
      The tile width which will be used for writing.
    • tileSizeY

      protected int tileSizeY
      The tile height which will be used for writing.
  • Constructor Details

    • TiffWriter

      public TiffWriter()
    • TiffWriter

      public TiffWriter(String format, String[] exts)
  • Method Details

    • getTIFFCompression

      private TiffCompression getTIFFCompression()
      Get the TIFF compression enum value that corresponds to the current compression type.
    • formatCompression

      private void formatCompression(IFD ifd) throws FormatException
      Sets the compression code for the specified IFD.
      Parameters:
      ifd - The IFD table to handle.
      Throws:
      FormatException
    • getCodec

      public Codec getCodec()
      Returns:
      the codec that can be used to compress tiles
    • saveCompressedBytes

      public void saveCompressedBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException
      Description copied from interface: ICompressedTileWriter
      Save a compressed tile to the current output file. The compression type of the tile should match the compression type set in the writer.
      Parameters:
      no - plane index
      buf - compressed tile bytes
      x - pixel X coordinate of the upper-left corner of the tile
      y - pixel Y coordinate of the upper-left corner of the tile
      w - width in pixels of the compressed tile
      h - height in pixels of the compressed tile
      Throws:
      FormatException
      IOException
    • makeIFD

      protected IFD makeIFD() throws FormatException, IOException
      Throws:
      FormatException
      IOException
    • setId

      public void setId(String id) throws FormatException, IOException
      Description copied from class: FormatWriter
      Initializes a writer from the input file name. Initializes a RandomAccessOutputStream for the output file and initializes the metadata for all the series using FormatWriter.setSeries(int).
      Specified by:
      setId in interface IFormatHandler
      Overrides:
      setId in class FormatWriter
      Parameters:
      id - a String specifying the path to the file
      Throws:
      FormatException
      IOException
    • saveBytes

      public void saveBytes(int no, byte[] buf, IFD ifd) throws IOException, FormatException
      Saves the given image to the specified (possibly already open) file. The IFD hashtable allows specification of TIFF parameters such as bit depth, compression and units. Use one IFD instance per plane.
      Throws:
      IOException
      FormatException
    • saveBytes

      public void saveBytes(int no, byte[] buf, IFD ifd, int x, int y, int w, int h) throws IOException, FormatException
      Saves the given image to the specified series in the current file. The IFD hashtable allows specification of TIFF parameters such as bit depth, compression and units. Use one IFD instance per plane.
      Throws:
      IOException
      FormatException
    • prepareToWriteImage

      protected int prepareToWriteImage(int no, byte[] buf, IFD ifd, int x, int y, int w, int h) throws IOException, FormatException
      Performs the preparation for work prior to the usage of the TIFF saver. This method is factored out from saveBytes() in an attempt to ensure thread safety.
      Throws:
      IOException
      FormatException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FormatWriter
      Throws:
      IOException
    • getPlaneCount

      public int getPlaneCount()
      Description copied from class: FormatWriter
      Retrieve the total number of planes in the current series.
      Overrides:
      getPlaneCount in class FormatWriter
    • saveBytes

      public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException
      Description copied from interface: IFormatWriter
      Saves the given image tile to the current series in the current file.
      Parameters:
      no - the plane index within the series.
      buf - the byte array that represents the image tile.
      x - the X coordinate of the upper-left corner of the image tile.
      y - the Y coordinate of the upper-left corner of the image tile.
      w - the width (in pixels) of the image tile.
      h - the height (in pixels) of the image tile.
      Throws:
      FormatException - if one of the parameters is invalid.
      IOException - if there was a problem writing to the file.
      See Also:
    • canDoStacks

      public boolean canDoStacks()
      Description copied from interface: IFormatWriter
      Reports whether the writer can save multiple images to a single file.
      Specified by:
      canDoStacks in interface IFormatWriter
      Overrides:
      canDoStacks in class FormatWriter
    • getPixelTypes

      public int[] getPixelTypes(String codec)
      Description copied from interface: IFormatWriter
      Gets the supported pixel types for the given codec.
      Specified by:
      getPixelTypes in interface IFormatWriter
      Overrides:
      getPixelTypes in class FormatWriter
    • setBigTiff

      public void setBigTiff(boolean bigTiff)
      Sets whether or not BigTIFF files should be written. This flag is not reset when close() is called.
    • setCanDetectBigTiff

      public void setCanDetectBigTiff(boolean detect)
      Sets whether or not BigTIFF can be used automatically based upon the input data size (true by default). This flag is not reset when close() is called.
    • setupTiffSaver

      protected void setupTiffSaver() throws IOException
      Throws:
      IOException
    • getTileSizeX

      public int getTileSizeX() throws FormatException
      Description copied from interface: IFormatWriter
      Retrieves the current tile width Defaults to 0 if not supported
      Specified by:
      getTileSizeX in interface IFormatWriter
      Overrides:
      getTileSizeX in class FormatWriter
      Returns:
      The current tile width being used
      Throws:
      FormatException - Image metadata including Pixels Size X must be set prior to calling getTileSizeX()
    • setTileSizeX

      public int setTileSizeX(int tileSize) throws FormatException
      Description copied from interface: IFormatWriter
      Will attempt to set the tile width to the desired value and return the actual value which will be used
      Specified by:
      setTileSizeX in interface IFormatWriter
      Overrides:
      setTileSizeX in class FormatWriter
      Parameters:
      tileSize - The tile width you wish to use. Setting to 0 will disable tiling
      Returns:
      The tile width which will actually be used, this may differ from the value requested. If the requested value is not supported the writer will return and use the closest appropriate value.
      Throws:
      FormatException - Tile size must be greater than or equal to 0 and less than the image width
    • getTileSizeY

      public int getTileSizeY() throws FormatException
      Description copied from interface: IFormatWriter
      Retrieves the current tile height Defaults to 0 if not supported
      Specified by:
      getTileSizeY in interface IFormatWriter
      Overrides:
      getTileSizeY in class FormatWriter
      Returns:
      The current tile height being used
      Throws:
      FormatException - Image metadata including Pixels Size Y must be set prior to calling getTileSizeY()
    • setTileSizeY

      public int setTileSizeY(int tileSize) throws FormatException
      Description copied from interface: IFormatWriter
      Will attempt to set the tile height to the desired value and return the actual value which will be used
      Specified by:
      setTileSizeY in interface IFormatWriter
      Overrides:
      setTileSizeY in class FormatWriter
      Parameters:
      tileSize - The tile height you wish to use. Setting to 0 will disable tiling
      Returns:
      The tile height which will actually be used, this may differ from the value requested. If the requested value is not supported the writer will return and use the closest appropriate value.
      Throws:
      FormatException - Tile size must be greater than or equal to 0 and less than the image height
    • getTile

      private byte[] getTile(byte[] buf, loci.common.Region tileParams, loci.common.Region srcParams)
    • createInputStream

      protected loci.common.RandomAccessInputStream createInputStream() throws IOException
      Throws:
      IOException
    • createTiffSaver

      protected TiffSaver createTiffSaver()