Package loci.formats
Class FormatWriter
java.lang.Object
loci.formats.FormatHandler
loci.formats.FormatWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,ICompressedTileWriter,IFormatHandler,IFormatWriter,IMetadataConfigurable,IPyramidHandler
- Direct Known Subclasses:
APNGWriter,AVIWriter,CellH5Writer,DicomWriter,EPSWriter,ICSWriter,ImageIOWriter,JavaWriter,JPEG2000Writer,OMEXMLWriter,QTWriter,TiffWriter,V3DrawWriter
Abstract superclass of all biological file format writers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ColorModelDefault color model.protected StringCurrent compression type.protected String[]Available compression types.protected intFrame rate to use when writing in frames per second, if applicable.protected boolean[][]Whether each plane in each series of the current file has been prepped for writing.protected booleanWhether the channels in an RGB image are interleaved.protected MetadataRetrieveCurrent metadata retrieval object.protected CodecOptionsThe options if required.protected loci.common.RandomAccessOutputStreamCurrent file.protected intCurrent pyramid resolution.protected List<List<Resolution>> protected booleanWhether or not we are writing planes sequentially.protected intCurrent series.protected intThe number of valid bits per pixel.Fields inherited from class loci.formats.FormatHandler
COMPRESSION_SUFFIXES, currentId, format, LOGGER, metadataOptions, suffixes -
Constructor Summary
ConstructorsConstructorDescriptionFormatWriter(String format, String suffix) Constructs a format writer with the given name and default suffix.FormatWriter(String format, String[] suffixes) Constructs a format writer with the given name and default suffixes. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReports whether the writer can save multiple images to a single file.voidSwitch the output file for the current dataset.protected voidcheckParams(int no, byte[] buf, int x, int y, int w, int h) Ensure that the arguments that are being passed to saveBytes(...) are valid.voidclose()protected loci.common.RandomAccessOutputStreamCreate an output stream for the current file path.Gets the color model.Gets the current compression type.String[]Gets the available compression types.intGets the frames per second to use when writing.Retrieves the current metadata retrieval object for this writer.int[]Gets the supported pixel types.int[]getPixelTypes(String codec) Gets the supported pixel types for the given codec.protected intRetrieve the total number of planes in the current series.protected intgetPlaneCount(int series) Retrieve the total number of planes in given series.intGet the current resolution level.intReturn the number of resolutions for the current series.Get a list of resolution objects for the current series.protected intRetrieve the number of samples per pixel for the current series.protected intgetSamplesPerPixel(int series) Retrieve the number of samples per pixel for given series.intReturns the current series.protected intgetSizeX()protected intgetSizeY()intRetrieves the current tile width Defaults to 0 if not supportedintRetrieves the current tile height Defaults to 0 if not supportedprotected booleanprotected booleanisFullPlane(int x, int y, int w, int h) Returns true if the given rectangle coordinates correspond to a full image in the given series.booleanGets whether or not the channels in an image are interleaved.booleanisSupportedType(int type) Checks if the given pixel type is supported.voidsaveBytes(int no, byte[] buf) Saves the given image to the current series in the current file.voidsaveBytes(int no, byte[] buf, loci.common.Region tile) Saves the given image tile to the current series in the current file.voidSaves the given image plane to the current series in the current file.voidSaves the given image plane to the current series in the current file.voidSaves the given image plane to the current series in the current file.protected voidseekToPlaneOffset(long baseOffset, int x, int y) Seek to the given (x, y) coordinate of the image that starts at the given offset.voidsetCodecOptions(CodecOptions options) Sets the codec options.voidsetColorModel(ColorModel model) Sets the color model.voidsetCompression(String compress) Sets the current compression type.voidsetFramesPerSecond(int rate) Sets the frames per second to use when writing.voidInitializes a writer from the input file name.voidsetInterleaved(boolean interleaved) Sets whether or not the channels in an image are interleaved.voidsetMetadataRetrieve(MetadataRetrieve retrieve) Sets the metadata retrieval object from which to retrieve standardized metadata.voidsetResolution(int resolution) Set the resolution level.voidsetResolutions(List<Resolution> resolutions) Specify a list of resolution objects for the current series.voidsetSeries(int series) Sets the current series.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 usedvoidsetValidBitsPerPixel(int bits) Sets the number of valid bits per pixel.voidsetWriteSequentially(boolean sequential) Sets whether or not we know that planes will be written sequentially.Methods 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.ICompressedTileWriter
getCodec, saveCompressedBytesMethods inherited from interface loci.formats.IFormatHandler
getFormat, getNativeDataType, getSuffixes, isThisTypeMethods inherited from interface loci.formats.IFormatWriter
saveBytesMethods inherited from interface loci.formats.IMetadataConfigurable
getMetadataOptions, getSupportedMetadataLevels, setMetadataOptions
-
Field Details
-
fps
protected int fpsFrame rate to use when writing in frames per second, if applicable. -
cm
Default color model. -
compressionTypes
Available compression types. -
compression
Current compression type. -
options
The options if required. -
initialized
protected boolean[][] initializedWhether each plane in each series of the current file has been prepped for writing. -
interleaved
protected boolean interleavedWhether the channels in an RGB image are interleaved. -
validBits
protected int validBitsThe number of valid bits per pixel. -
series
protected int seriesCurrent series. -
sequential
protected boolean sequentialWhether or not we are writing planes sequentially. -
metadataRetrieve
Current metadata retrieval object. Should never be accessed directly as the semantics ofgetMetadataRetrieve()prevent "null" access. -
out
protected loci.common.RandomAccessOutputStream outCurrent file. -
resolution
protected int resolutionCurrent pyramid resolution. -
resolutionData
-
-
Constructor Details
-
FormatWriter
Constructs a format writer with the given name and default suffix. -
FormatWriter
Constructs a format writer with the given name and default suffixes.
-
-
Method Details
-
changeOutputFile
Description copied from interface:IFormatWriterSwitch the output file for the current dataset.- Specified by:
changeOutputFilein interfaceIFormatWriter- Throws:
FormatExceptionIOException
-
saveBytes
Description copied from interface:IFormatWriterSaves the given image to the current series in the current file.- Specified by:
saveBytesin interfaceIFormatWriter- Parameters:
no- the plane index within the series.buf- the byte array that represents the image.- Throws:
FormatException- if one of the parameters is invalid.IOException- if there was a problem writing to the file.
-
saveBytes
public void saveBytes(int no, byte[] buf, loci.common.Region tile) throws FormatException, IOException Description copied from interface:IFormatWriterSaves the given image tile to the current series in the current file.- Specified by:
saveBytesin interfaceIFormatWriter- Parameters:
no- the plane index within the series.buf- the byte array that represents the image tile.tile- the Region representing the image tile to be read.- Throws:
FormatException- if one of the parameters is invalid.IOException- if there was a problem writing to the file.
-
savePlane
Description copied from interface:IFormatWriterSaves the given image plane to the current series in the current file.- Specified by:
savePlanein interfaceIFormatWriter- Parameters:
no- the plane index within the series.plane- the image plane.- Throws:
FormatException- if one of the parameters is invalid.IOException- if there was a problem writing to the file.
-
savePlane
public void savePlane(int no, Object plane, int x, int y, int w, int h) throws FormatException, IOException Description copied from interface:IFormatWriterSaves the given image plane to the current series in the current file.- Specified by:
savePlanein interfaceIFormatWriter- Parameters:
no- the plane index within the series.plane- the image plane.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.
-
savePlane
public void savePlane(int no, Object plane, loci.common.Region tile) throws FormatException, IOException Description copied from interface:IFormatWriterSaves the given image plane to the current series in the current file.- Specified by:
savePlanein interfaceIFormatWriter- Parameters:
no- the plane index within the series.plane- the image plane.tile- the Region representing the image tile to be read.- Throws:
FormatException- if one of the parameters is invalid.IOException- if there was a problem writing to the file.
-
setSeries
Description copied from interface:IFormatWriterSets the current series.- Specified by:
setSeriesin interfaceIFormatWriter- Parameters:
series- the series index, starting from 0.- Throws:
FormatException- if the specified series is invalid.
-
getSeries
public int getSeries()Description copied from interface:IFormatWriterReturns the current series.- Specified by:
getSeriesin interfaceIFormatWriter
-
setInterleaved
public void setInterleaved(boolean interleaved) Description copied from interface:IFormatWriterSets whether or not the channels in an image are interleaved.- Specified by:
setInterleavedin interfaceIFormatWriter
-
isInterleaved
public boolean isInterleaved()Description copied from interface:IFormatWriterGets whether or not the channels in an image are interleaved.- Specified by:
isInterleavedin interfaceIFormatWriter
-
setValidBitsPerPixel
public void setValidBitsPerPixel(int bits) Description copied from interface:IFormatWriterSets the number of valid bits per pixel.- Specified by:
setValidBitsPerPixelin interfaceIFormatWriter
-
canDoStacks
public boolean canDoStacks()Description copied from interface:IFormatWriterReports whether the writer can save multiple images to a single file.- Specified by:
canDoStacksin interfaceIFormatWriter
-
setMetadataRetrieve
Description copied from interface:IFormatWriterSets the metadata retrieval object from which to retrieve standardized metadata.- Specified by:
setMetadataRetrievein interfaceIFormatWriter
-
getMetadataRetrieve
Description copied from interface:IFormatWriterRetrieves the current metadata retrieval object for this writer. You can be assured that this method will never return anullmetadata retrieval object.- Specified by:
getMetadataRetrievein interfaceIFormatWriter- Returns:
- A metadata retrieval object.
-
setColorModel
Description copied from interface:IFormatWriterSets the color model.- Specified by:
setColorModelin interfaceIFormatWriter
-
getColorModel
Description copied from interface:IFormatWriterGets the color model.- Specified by:
getColorModelin interfaceIFormatWriter
-
setFramesPerSecond
public void setFramesPerSecond(int rate) Description copied from interface:IFormatWriterSets the frames per second to use when writing.- Specified by:
setFramesPerSecondin interfaceIFormatWriter
-
getFramesPerSecond
public int getFramesPerSecond()Description copied from interface:IFormatWriterGets the frames per second to use when writing.- Specified by:
getFramesPerSecondin interfaceIFormatWriter
-
getCompressionTypes
Description copied from interface:IFormatWriterGets the available compression types.- Specified by:
getCompressionTypesin interfaceIFormatWriter
-
setCompression
Description copied from interface:IFormatWriterSets the current compression type.- Specified by:
setCompressionin interfaceIFormatWriter- Throws:
FormatException
-
setCodecOptions
Description copied from interface:IFormatWriterSets the codec options.- Specified by:
setCodecOptionsin interfaceIFormatWriter- Parameters:
options- The options to set.
-
getCodecOptions
- Specified by:
getCodecOptionsin interfaceICompressedTileWriter- Returns:
- the codec options that can be used to compress tiles
-
getCompression
Description copied from interface:IFormatWriterGets the current compression type.- Specified by:
getCompressionin interfaceIFormatWriter
-
getPixelTypes
public int[] getPixelTypes()Description copied from interface:IFormatWriterGets the supported pixel types.- Specified by:
getPixelTypesin interfaceIFormatWriter
-
getPixelTypes
Description copied from interface:IFormatWriterGets the supported pixel types for the given codec.- Specified by:
getPixelTypesin interfaceIFormatWriter
-
isSupportedType
public boolean isSupportedType(int type) Description copied from interface:IFormatWriterChecks if the given pixel type is supported.- Specified by:
isSupportedTypein interfaceIFormatWriter
-
setWriteSequentially
public void setWriteSequentially(boolean sequential) Description copied from interface:IFormatWriterSets whether or not we know that planes will be written sequentially. If planes are written sequentially and this flag is set, then performance will be slightly improved.- Specified by:
setWriteSequentiallyin interfaceIFormatWriter
-
getTileSizeX
Description copied from interface:IFormatWriterRetrieves the current tile width Defaults to 0 if not supported- Specified by:
getTileSizeXin interfaceIFormatWriter- 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- 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- 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- 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
-
setResolutions
Description copied from interface:IFormatWriterSpecify a list of resolution objects for the current series. If resolutions are specified using this method, then any resolution data supplied via the MetadataRetrieve will be ignored.- Specified by:
setResolutionsin interfaceIFormatWriter
-
getResolutions
Description copied from interface:IFormatWriterGet a list of resolution objects for the current series.- Specified by:
getResolutionsin interfaceIFormatWriter
-
getResolutionCount
public int getResolutionCount()Description copied from interface:IPyramidHandlerReturn the number of resolutions for the current series. Resolutions are stored in descending order, so the largest resolution is first and the smallest resolution is last.- Specified by:
getResolutionCountin interfaceIPyramidHandler
-
getResolution
public int getResolution()Description copied from interface:IPyramidHandlerGet the current resolution level.- Specified by:
getResolutionin interfaceIPyramidHandler- See Also:
-
setResolution
public void setResolution(int resolution) Description copied from interface:IPyramidHandlerSet the resolution level.- Specified by:
setResolutionin interfaceIPyramidHandler- See Also:
-
setId
Initializes a writer from the input file name. Initializes aRandomAccessOutputStreamfor the output file and initializes the metadata for all the series usingsetSeries(int).- Specified by:
setIdin interfaceIFormatHandler- Parameters:
id- aStringspecifying the path to the file- Throws:
FormatExceptionIOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
checkParams
Ensure that the arguments that are being passed to saveBytes(...) are valid.- Throws:
FormatException- if any of the arguments is invalid.
-
seekToPlaneOffset
Seek to the given (x, y) coordinate of the image that starts at the given offset.- Throws:
IOException
-
isFullPlane
Returns true if the given rectangle coordinates correspond to a full image in the given series.- Throws:
FormatException
-
getSamplesPerPixel
protected int getSamplesPerPixel()Retrieve the number of samples per pixel for the current series. -
getSamplesPerPixel
protected int getSamplesPerPixel(int series) Retrieve the number of samples per pixel for given series. -
getPlaneCount
protected int getPlaneCount()Retrieve the total number of planes in the current series. -
getPlaneCount
protected int getPlaneCount(int series) Retrieve the total number of planes in given series. -
createOutputStream
Create an output stream for the current file path. If the file path's parent directory does not exist, it will be created.- Returns:
- an open RandomAccessOuputStream for the current file
- Throws:
IOException- if the directory or output stream creation fails
-
getSizeX
- Throws:
FormatException
-
getSizeY
- Throws:
FormatException
-
hasResolutions
protected boolean hasResolutions()
-