Package loci.formats.out
Class TiffWriter
java.lang.Object
loci.formats.FormatHandler
loci.formats.FormatWriter
loci.formats.out.TiffWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,ICompressedTileWriter,IFormatHandler,IFormatWriter,IMetadataConfigurable,IPyramidHandler
- Direct Known Subclasses:
OMETiffWriter
TiffWriter is the file format writer for TIFF files.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String[]protected booleanWhether or not BigTIFF can be used automatically.protected booleanWhether or not to check the parameters passed to saveBytes.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected loci.common.RandomAccessInputStreamInput stream to use when overwriting data.protected booleanWhether or not the output file is a BigTIFF file.protected TiffSaverThe TiffSaver that will do most of the writing.private static final intTIFF tiles must be of a height and width divisible by 16.protected intThe tile width which will be used for writing.protected intThe 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, validBitsFields inherited from class loci.formats.FormatHandler
COMPRESSION_SUFFIXES, currentId, format, LOGGER, metadataOptions, suffixes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReports whether the writer can save multiple images to a single file.voidclose()protected loci.common.RandomAccessInputStreamprotected TiffSaverprivate voidformatCompression(IFD ifd) Sets the compression code for the specified IFD.getCodec()int[]getPixelTypes(String codec) Gets the supported pixel types for the given codec.intRetrieve the total number of planes in the current series.private TiffCompressionGet 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) intRetrieves the current tile width Defaults to 0 if not supportedintRetrieves the current tile height Defaults to 0 if not supportedprotected IFDmakeIFD()protected intprepareToWriteImage(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.voidsaveBytes(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.voidSaves the given image to the specified (possibly already open) file.voidSaves the given image to the specified series in the current file.voidsaveCompressedBytes(int no, byte[] buf, int x, int y, int w, int h) Save a compressed tile to the current output file.voidsetBigTiff(boolean bigTiff) Sets whether or not BigTIFF files should be written.voidsetCanDetectBigTiff(boolean detect) Sets whether or not BigTIFF can be used automatically based upon the input data size (true by default).voidInitializes a writer from the input file name.intsetTileSizeX(int tileSize) Will attempt to set the tile width to the desired value and return the actual value which will be usedintsetTileSizeY(int tileSize) Will attempt to set the tile height to the desired value and return the actual value which will be usedprotected voidMethods 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, setWriteSequentiallyMethods inherited from class loci.formats.FormatHandler
checkSuffix, checkSuffix, getFormat, getMetadataOptions, getNativeDataType, getSuffixes, getSupportedMetadataLevels, isThisType, setMetadataOptionsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface loci.formats.IFormatHandler
getFormat, getNativeDataType, getSuffixes, isThisTypeMethods inherited from interface loci.formats.IMetadataConfigurable
getMetadataOptions, getSupportedMetadataLevels, setMetadataOptions
-
Field Details
-
COMPRESSION_UNCOMPRESSED
-
COMPRESSION_LZW
-
COMPRESSION_J2K
-
COMPRESSION_J2K_LOSSY
-
COMPRESSION_JPEG
-
COMPRESSION_ZLIB
-
BIG_TIFF_SUFFIXES
-
TILE_GRANULARITY
private static final int TILE_GRANULARITYTIFF tiles must be of a height and width divisible by 16.- See Also:
-
isBigTiff
protected boolean isBigTiffWhether or not the output file is a BigTIFF file. -
canDetectBigTiff
protected boolean canDetectBigTiffWhether or not BigTIFF can be used automatically. -
tiffSaver
The TiffSaver that will do most of the writing. -
in
protected loci.common.RandomAccessInputStream inInput stream to use when overwriting data. -
checkParams
protected boolean checkParamsWhether or not to check the parameters passed to saveBytes. -
tileSizeX
protected int tileSizeXThe tile width which will be used for writing. -
tileSizeY
protected int tileSizeYThe tile height which will be used for writing.
-
-
Constructor Details
-
TiffWriter
public TiffWriter() -
TiffWriter
-
-
Method Details
-
getTIFFCompression
Get the TIFF compression enum value that corresponds to the current compression type. -
formatCompression
Sets the compression code for the specified IFD.- Parameters:
ifd- The IFD table to handle.- Throws:
FormatException
-
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:ICompressedTileWriterSave 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 indexbuf- compressed tile bytesx- pixel X coordinate of the upper-left corner of the tiley- pixel Y coordinate of the upper-left corner of the tilew- width in pixels of the compressed tileh- height in pixels of the compressed tile- Throws:
FormatExceptionIOException
-
makeIFD
- Throws:
FormatExceptionIOException
-
setId
Description copied from class:FormatWriterInitializes a writer from the input file name. Initializes aRandomAccessOutputStreamfor the output file and initializes the metadata for all the series usingFormatWriter.setSeries(int).- Specified by:
setIdin interfaceIFormatHandler- Overrides:
setIdin classFormatWriter- Parameters:
id- aStringspecifying the path to the file- Throws:
FormatExceptionIOException
-
saveBytes
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:
IOExceptionFormatException
-
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:
IOExceptionFormatException
-
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 fromsaveBytes()in an attempt to ensure thread safety.- Throws:
IOExceptionFormatException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFormatWriter- Throws:
IOException
-
getPlaneCount
public int getPlaneCount()Description copied from class:FormatWriterRetrieve the total number of planes in the current series.- Overrides:
getPlaneCountin classFormatWriter
-
saveBytes
public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException Description copied from interface:IFormatWriterSaves 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:IFormatWriterReports whether the writer can save multiple images to a single file.- Specified by:
canDoStacksin interfaceIFormatWriter- Overrides:
canDoStacksin classFormatWriter
-
getPixelTypes
Description copied from interface:IFormatWriterGets the supported pixel types for the given codec.- Specified by:
getPixelTypesin interfaceIFormatWriter- Overrides:
getPixelTypesin classFormatWriter
-
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
- Throws:
IOException
-
getTileSizeX
Description copied from interface:IFormatWriterRetrieves the current tile width Defaults to 0 if not supported- Specified by:
getTileSizeXin interfaceIFormatWriter- Overrides:
getTileSizeXin classFormatWriter- Returns:
- The current tile width being used
- Throws:
FormatException- Image metadata including Pixels Size X must be set prior to calling getTileSizeX()
-
setTileSizeX
Description copied from interface:IFormatWriterWill attempt to set the tile width to the desired value and return the actual value which will be used- Specified by:
setTileSizeXin interfaceIFormatWriter- Overrides:
setTileSizeXin classFormatWriter- 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
Description copied from interface:IFormatWriterRetrieves the current tile height Defaults to 0 if not supported- Specified by:
getTileSizeYin interfaceIFormatWriter- Overrides:
getTileSizeYin classFormatWriter- Returns:
- The current tile height being used
- Throws:
FormatException- Image metadata including Pixels Size Y must be set prior to calling getTileSizeY()
-
setTileSizeY
Description copied from interface:IFormatWriterWill attempt to set the tile height to the desired value and return the actual value which will be used- Specified by:
setTileSizeYin interfaceIFormatWriter- Overrides:
setTileSizeYin classFormatWriter- 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
- Throws:
IOException
-
createTiffSaver
-