Package loci.formats
Class ImageWriter
java.lang.Object
loci.formats.ImageWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,ICompressedTileWriter,IFormatHandler,IFormatWriter,IMetadataConfigurable,IPyramidHandler
ImageWriter is the master file format writer for all supported formats.
It uses one instance of each writer subclass (specified in writers.txt,
or other class list source) to identify file formats and write data.
- Author:
- Curtis Rueden ctrueden at wisc.edu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intCurrent form index.protected StringName of current file.private static ClassList<IFormatWriter> Default list of writer classes, for use with noargs constructor.private static final org.slf4j.Loggerprivate String[]Valid suffixes for all file format writers.protected IFormatWriter[]List of supported file format writers. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new ImageWriter with the default list of writer classes from writers.txt.ImageWriter(ClassList<IFormatWriter> classList) Constructs a new ImageWriter from the given list of writer classes. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReports whether the writer can save multiple images to a single file.voidSwitch the output file for the current dataset.voidclose()getCodec()Gets the color model.Gets the current compression type.String[]Gets the available compression types.static ClassList<IFormatWriter> Gets the name of this file format.Gets a string describing the file format for the given file.intGets the frames per second to use when writing.Retrieves the current metadata retrieval object for this writer.Class<?> Returns the native data type of image planes for this reader, as returned byIFormatReader.openPlane(int, int, int, int, int)orIFormatWriter.savePlane(int, java.lang.Object).int[]Gets the supported pixel types.int[]getPixelTypes(String codec) Gets the supported pixel types for the given codec.intGet the current resolution level.intReturn the number of resolutions for the current series.Get a list of resolution objects for the current series.intReturns the current series.String[]Gets the default file suffixes for this file format.intRetrieves the current tile width Defaults to 0 if not supportedintRetrieves the current tile height Defaults to 0 if not supportedGets the writer used to save the current file.getWriter(Class<? extends IFormatWriter> c) Gets the file format writer instance matching the given class.Gets the writer used to save the given file.Gets all constituent file format writers.booleanGets whether or not the channels in an image are interleaved.booleanisSupportedType(int type) Checks if the given pixel type is supported.booleanisThisType(String name) Checks if the given string is a valid filename for this file format.voidsaveBytes(int no, byte[] buf) Saves the given image to the current series in the current file.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.voidsaveBytes(int no, byte[] buf, loci.common.Region tile) Saves the given image tile to the current 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.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.voidsetCodecOptions(CodecOptions options) Sets the codec options.voidSets the color model.voidsetCompression(String compress) Sets the current compression type.voidsetFramesPerSecond(int rate) Sets the frames per second to use when writing.voidSets the current file name.voidsetInterleaved(boolean interleaved) Sets whether or not the channels in an image are interleaved.voidsetMetadataOptions(MetadataOptions options) voidSets 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.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
defaultClasses
Default list of writer classes, for use with noargs constructor. -
writers
List of supported file format writers. -
suffixes
Valid suffixes for all file format writers. Populated the first time getSuffixes() is called. -
currentId
Name of current file. -
current
protected int currentCurrent form index.
-
-
Constructor Details
-
ImageWriter
public ImageWriter()Constructs a new ImageWriter with the default list of writer classes from writers.txt. -
ImageWriter
Constructs a new ImageWriter from the given list of writer classes.
-
-
Method Details
-
getDefaultWriterClasses
-
getFormat
Gets a string describing the file format for the given file.- Throws:
FormatExceptionIOException
-
getWriter
Gets the writer used to save the given file.- Throws:
FormatException
-
getWriter
Gets the writer used to save the current file. -
getWriter
Gets the file format writer instance matching the given class. -
getWriters
Gets all constituent file format writers. -
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
-
getSupportedMetadataLevels
- Specified by:
getSupportedMetadataLevelsin interfaceIMetadataConfigurable
-
getMetadataOptions
- Specified by:
getMetadataOptionsin interfaceIMetadataConfigurable
-
setMetadataOptions
- Specified by:
setMetadataOptionsin interfaceIMetadataConfigurable- See Also:
-
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, 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.- Specified by:
saveBytesin interfaceIFormatWriter- 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.
-
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
-
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
-
setCompression
Description copied from interface:IFormatWriterSets the current compression type.- Specified by:
setCompressionin interfaceIFormatWriter- Throws:
FormatException
-
getCompression
Description copied from interface:IFormatWriterGets the current compression type.- Specified by:
getCompressionin 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
-
setCodecOptions
Description copied from interface:IFormatWriterSets the codec options.- Specified by:
setCodecOptionsin interfaceIFormatWriter- Parameters:
options- The options to set.
-
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.- Specified by:
saveCompressedBytesin interfaceICompressedTileWriter- 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
-
getCodec
- Specified by:
getCodecin interfaceICompressedTileWriter- Returns:
- the codec that can be used to compress tiles
-
getCodecOptions
- Specified by:
getCodecOptionsin interfaceICompressedTileWriter- Returns:
- the codec options that can be used to compress tiles
-
isThisType
Description copied from interface:IFormatHandlerChecks if the given string is a valid filename for this file format.- Specified by:
isThisTypein interfaceIFormatHandler
-
getFormat
Description copied from interface:IFormatHandlerGets the name of this file format.- Specified by:
getFormatin interfaceIFormatHandler
-
getSuffixes
Description copied from interface:IFormatHandlerGets the default file suffixes for this file format.- Specified by:
getSuffixesin interfaceIFormatHandler
-
getNativeDataType
Description copied from interface:IFormatHandlerReturns the native data type of image planes for this reader, as returned byIFormatReader.openPlane(int, int, int, int, int)orIFormatWriter.savePlane(int, java.lang.Object). For most readers this type will be a byte array; however, some readers call external APIs that work with other types such asBufferedImage.- Specified by:
getNativeDataTypein interfaceIFormatHandler
-
setId
Description copied from interface:IFormatHandlerSets the current file name.- Specified by:
setIdin interfaceIFormatHandler- Throws:
FormatExceptionIOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
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:
-