Package loci.formats
Class WriterWrapper
java.lang.Object
loci.formats.WriterWrapper
- All Implemented Interfaces:
Closeable,AutoCloseable,ICompressedTileWriter,IFormatHandler,IFormatWriter,IMetadataConfigurable,IPyramidHandler
- Direct Known Subclasses:
BufferedImageWriter
Abstract superclass of writer logic that wraps other writers.
All methods are simply delegated to the wrapped writer.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a writer wrapper around a new image writer.Constructs a writer wrapper around the given writer. -
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()duplicate(Class<? extends IFormatWriter> imageWriterClass) Performs a deep copy of the writer, including nested wrapped writers.private WriterWrapperduplicateRecurse(Class<? extends IFormatWriter> imageWriterClass) getCodec()Gets the color model.Gets the current compression type.String[]Gets the available compression types.Gets the name of this file format.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 wrapped writer.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.unwrap()Unwraps nested wrapped writers until the core writer (i.e., not aWriterWrapperorImageWriter) is found.unwrap(Class<? extends IFormatWriter> writerClass, String id) Unwraps nested wrapped writers until the given writer class is found.Unwraps nested wrapped writers until the core writer (i.e., not aWriterWrapperorImageWriter) is found.
-
Field Details
-
writer
FormatWriter used to write the file.
-
-
Constructor Details
-
WriterWrapper
public WriterWrapper()Constructs a writer wrapper around a new image writer. -
WriterWrapper
Constructs a writer wrapper around the given writer.
-
-
Method Details
-
getWriter
Gets the wrapped writer. -
unwrap
Unwraps nested wrapped writers until the core writer (i.e., not aWriterWrapperorImageWriter) is found.- Throws:
FormatExceptionIOException
-
unwrap
Unwraps nested wrapped writers until the core writer (i.e., not aWriterWrapperorImageWriter) is found.- Parameters:
id- Id to use as a basis when unwrapping any nestedImageWriters. If null, the current id is used.- Throws:
FormatExceptionIOException
-
unwrap
public IFormatWriter unwrap(Class<? extends IFormatWriter> writerClass, String id) throws FormatException, IOException Unwraps nested wrapped writers until the given writer class is found.- Parameters:
writerClass- Class of the desired nested writer. If null, the core writer (i.e., deepest wrapped writer) will be returned.id- Id to use as a basis when unwrapping any nestedImageWriters. If null, the current id is used.- Throws:
FormatExceptionIOException
-
duplicate
public WriterWrapper duplicate(Class<? extends IFormatWriter> imageWriterClass) throws FormatException Performs a deep copy of the writer, including nested wrapped writers. Most of the writer state is preserved as well, including:- Parameters:
imageWriterClass- If non-null, anyImageWriters in the writer stack will be replaced with instances of the given class.- Throws:
FormatException- If something goes wrong during the duplication.
-
getSupportedMetadataLevels
- Specified by:
getSupportedMetadataLevelsin interfaceIMetadataConfigurable
-
getMetadataOptions
- Specified by:
getMetadataOptionsin interfaceIMetadataConfigurable
-
setMetadataOptions
- Specified by:
setMetadataOptionsin interfaceIMetadataConfigurable
-
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
-
setCodecOptions
Description copied from interface:IFormatWriterSets the codec options.- Specified by:
setCodecOptionsin interfaceIFormatWriter- Parameters:
options- The options to set.
-
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
-
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
-
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:
-
duplicateRecurse
private WriterWrapper duplicateRecurse(Class<? extends IFormatWriter> imageWriterClass) throws FormatException - Throws:
FormatException
-