loci.formats.out

## Class TiffWriter

- java.lang.Object
- - loci.formats.FormatHandler
  - - loci.formats.FormatWriter
    - - loci.formats.out.TiffWriter

- All Implemented Interfaces:
    java.io.Closeable, java.lang.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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private static java.lang.String[]` | `BIG_TIFF_SUFFIXES`
    `protected boolean` | `canDetectBigTiff` Whether or not BigTIFF can be used automatically.
    `protected boolean` | `checkParams` Whether or not to check the parameters passed to saveBytes.
    `static java.lang.String` | `COMPRESSION_J2K`
    `static java.lang.String` | `COMPRESSION_J2K_LOSSY`
    `static java.lang.String` | `COMPRESSION_JPEG`
    `static java.lang.String` | `COMPRESSION_LZW`
    `static java.lang.String` | `COMPRESSION_UNCOMPRESSED`
    `static java.lang.String` | `COMPRESSION_ZLIB`
    `protected loci.common.RandomAccessInputStream` | `in` Input stream to use when overwriting data.
    `protected boolean` | `isBigTiff` Whether or not the output file is a BigTIFF file.
    `protected TiffSaver` | `tiffSaver` The TiffSaver that will do most of the writing.
    `private static int` | `TILE_GRANULARITY` TIFF tiles must be of a height and width divisible by 16.
    `protected int` | `tileSizeX` The tile width which will be used for writing.
    `protected int` | `tileSizeY` The tile height which will be used for writing.

    - ### Fields inherited from class loci.formats.FormatWriter

      `cm, compression, compressionTypes, fps, initialized, interleaved, metadataRetrieve, options, out, resolution, resolutionData, sequential, series, validBits`

    - ### Fields inherited from class loci.formats.FormatHandler

      `COMPRESSION_SUFFIXES, currentId, format, LOGGER, metadataOptions, suffixes`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TiffWriter()`
    `TiffWriter(java.lang.String format, java.lang.String[] exts)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canDoStacks()` Reports whether the writer can save multiple images to a single file.
    `void` | `close()`
    `protected loci.common.RandomAccessInputStream` | `createInputStream()`
    `protected TiffSaver` | `createTiffSaver()`
    `private void` | `formatCompression(IFD ifd)` Sets the compression code for the specified IFD.
    `Codec` | `getCodec()`
    `int[]` | `getPixelTypes(java.lang.String codec)` Gets the supported pixel types for the given codec.
    `int` | `getPlaneCount()` Retrieve the total number of planes in the current series.
    `private TiffCompression` | `getTIFFCompression()` Get the TIFF compression enum value that corresponds to the current compression type.
    `private byte[]` | `getTile(byte[] buf, loci.common.Region tileParams, loci.common.Region srcParams)`
    `int` | `getTileSizeX()` Retrieves the current tile width Defaults to 0 if not supported
    `int` | `getTileSizeY()` Retrieves the current tile height Defaults to 0 if not supported
    `protected IFD` | `makeIFD()`
    `protected int` | `prepareToWriteImage(int no, byte[] buf, IFD ifd, int x, int y, int w, int h)` Performs the preparation for work prior to the usage of the TIFF saver.
    `void` | `saveBytes(int no, byte[] buf, IFD ifd)` Saves the given image to the specified (possibly already open) file.
    `void` | `saveBytes(int no, byte[] buf, IFD ifd, int x, int y, int w, int h)` Saves the given image to the specified series in the current file.
    `void` | `saveBytes(int no, byte[] buf, int x, int y, int w, int h)` Saves the given image tile to the current series in the current file.
    `void` | `saveCompressedBytes(int no, byte[] buf, int x, int y, int w, int h)` Save a compressed tile to the current output file.
    `void` | `setBigTiff(boolean bigTiff)` Sets whether or not BigTIFF files should be written.
    `void` | `setCanDetectBigTiff(boolean detect)` Sets whether or not BigTIFF can be used automatically based upon the input data size (true by default).
    `void` | `setId(java.lang.String id)` Initializes a writer from the input file name.
    `int` | `setTileSizeX(int tileSize)` Will attempt to set the tile width to the desired value and return the actual value which will be used
    `int` | `setTileSizeY(int tileSize)` Will attempt to set the tile height to the desired value and return the actual value which will be used
    `protected void` | `setupTiffSaver()`

    - ### Methods inherited from class loci.formats.FormatWriter

      `changeOutputFile, checkParams, createOutputStream, getCodecOptions, getColorModel, getCompression, getCompressionTypes, getFramesPerSecond, getMetadataRetrieve, getPixelTypes, getPlaneCount, getResolution, getResolutionCount, getResolutions, getSamplesPerPixel, getSamplesPerPixel, getSeries, getSizeX, getSizeY, hasResolutions, isFullPlane, isInterleaved, isSupportedType, saveBytes, saveBytes, savePlane, savePlane, savePlane, seekToPlaneOffset, setCodecOptions, setColorModel, setCompression, setFramesPerSecond, setInterleaved, setMetadataRetrieve, setResolution, setResolutions, setSeries, setValidBitsPerPixel, setWriteSequentially`

    - ### Methods inherited from class loci.formats.FormatHandler

      `checkSuffix, checkSuffix, getFormat, getMetadataOptions, getNativeDataType, getSuffixes, getSupportedMetadataLevels, isThisType, setMetadataOptions`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface loci.formats.IFormatHandler

      `getFormat, getNativeDataType, getSuffixes, isThisType`

    - ### Methods inherited from interface loci.formats.IMetadataConfigurable

      `getMetadataOptions, getSupportedMetadataLevels, setMetadataOptions`

- - ### Field Detail

    - #### COMPRESSION_UNCOMPRESSED

          public static final java.lang.String COMPRESSION_UNCOMPRESSED

    - #### COMPRESSION_LZW

          public static final java.lang.String COMPRESSION_LZW

    - #### COMPRESSION_J2K

          public static final java.lang.String COMPRESSION_J2K

    - #### COMPRESSION_J2K_LOSSY

          public static final java.lang.String COMPRESSION_J2K_LOSSY

    - #### COMPRESSION_JPEG

          public static final java.lang.String COMPRESSION_JPEG

    - #### COMPRESSION_ZLIB

          public static final java.lang.String COMPRESSION_ZLIB

    - #### BIG_TIFF_SUFFIXES

          private static final java.lang.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:
        Constant Field Values

    - #### 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 Detail

    - #### TiffWriter

          public TiffWriter()

    - #### TiffWriter

          public TiffWriter(java.lang.String format,
                            java.lang.String[] exts)

  - ### Method Detail

    - #### 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,
                                          java.io.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`
        `java.io.IOException`

    - #### makeIFD

          protected IFD makeIFD()
                         throws FormatException,
                                java.io.IOException

      Throws:
        `FormatException`
        `java.io.IOException`

    - #### setId

          public void setId(java.lang.String id)
                     throws FormatException,
                            java.io.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`
        `java.io.IOException`

    - #### saveBytes

          public void saveBytes(int no,
                                byte[] buf,
                                IFD ifd)
                         throws java.io.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:
        `java.io.IOException`
        `FormatException`

    - #### saveBytes

          public void saveBytes(int no,
                                byte[] buf,
                                IFD ifd,
                                int x,
                                int y,
                                int w,
                                int h)
                         throws java.io.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:
        `java.io.IOException`
        `FormatException`

    - #### prepareToWriteImage

          protected int prepareToWriteImage(int no,
                                            byte[] buf,
                                            IFD ifd,
                                            int x,
                                            int y,
                                            int w,
                                            int h)
                                     throws java.io.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:
        `java.io.IOException`
        `FormatException`

    - #### close

          public void close()
                     throws java.io.IOException

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Overrides:
        `close` in class `FormatWriter`
      Throws:
        `java.io.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,
                                java.io.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.
        `java.io.IOException` - if there was a problem writing to the file.
      See Also:
        `IFormatWriter.saveBytes(int, byte[], int, int, int, int)`

    - #### 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(java.lang.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 java.io.IOException

      Throws:
        `java.io.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 java.io.IOException

      Throws:
        `java.io.IOException`

    - #### createTiffSaver

          protected TiffSaver createTiffSaver()

Copyright © 2026 Open Microscopy Environment