Package loci.formats.tiff
Class TiffSaver
java.lang.Object
loci.formats.tiff.TiffSaver
- All Implemented Interfaces:
Closeable,AutoCloseable
Parses TIFF data from an input source.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ByteArrayHandleOutput bytes.protected StringOutput filename.protected RandomAccessOutputStreamOutput stream to use when saving TIFF data. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new TIFF saver from the given filename.TiffSaver(RandomAccessOutputStream out, String filename) Constructs a new TIFF saver from the given output source.TiffSaver(RandomAccessOutputStream out, ByteArrayHandle bytes) Constructs a new TIFF saver from the given output source. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the output stream if not null.Gets the stream from which TIFF data is being saved.booleanReturns whether or not we are writing BigTIFF data.booleanReturns whether or not we are writing little-endian data.voidmakeValidIFD(IFD ifd, int pixelType, int nChannels) Makes a valid IFD.voidoverwriteComment(RandomAccessInputStream in, Object value) Convenience method for overwriting a file's first ImageDescription.voidoverwriteIFDOffset(RandomAccessInputStream raf, long offset, long nextPointer) voidoverwriteIFDValue(RandomAccessInputStream raf, int ifd, int tag, Object value) Surgically overwrites an existing IFD value with the given one.voidoverwriteIFDValue(RandomAccessInputStream raf, long ifdOffset, int tag, Object value) Surgically overwrites an existing IFD value with the given one.voidoverwriteIFDValue(RandomAccessInputStream raf, long ifdOffset, int tag, Object value, boolean skipHeaderCheck) Surgically overwrites an existing IFD value with the given one.voidvoidsetBigTiff(boolean bigTiff) Sets whether or not BigTIFF data should be written.voidSets the codec options.voidsetLittleEndian(boolean littleEndian) Sets whether or not little-endian data should be written.voidsetWritingSequentially(boolean sequential) Sets whether or not we know that the planes will be written sequentially.voidWrites the TIFF file header.voidWrite the given IFD to the open stream.voidWrite the given IFD to the open stream.voidwriteIFDValue(RandomAccessOutputStream extraOut, long offset, int tag, Object value) Writes the given IFD value to the given output object.voidwriteImage(byte[][] buf, IFDList ifds, int pixelType) voidwriteImage(byte[] buf, IFD ifd, int no, int pixelType, boolean last) voidwriteImage(byte[] buf, IFD ifd, int no, int pixelType, int x, int y, int w, int h, boolean last) Writes to any rectangle from the passed block.voidwriteImage(byte[] buf, IFD ifd, int no, int pixelType, int x, int y, int w, int h, boolean last, Integer nChannels, boolean copyDirectly) voidwriteImageIFD(IFD ifd, int no, byte[][] strips, int nChannels, boolean last, int x, int y) Performs the actual work of dealing with IFD data and writing it to the TIFF for a given image or sub-image.
-
Field Details
-
out
Output stream to use when saving TIFF data. -
filename
Output filename. -
bytes
Output bytes.
-
-
Constructor Details
-
TiffSaver
Constructs a new TIFF saver from the given filename.- Parameters:
filename- Filename of the output stream that we may use to create extra input or output streams as required.- Throws:
IOException
-
TiffSaver
Constructs a new TIFF saver from the given output source.- Parameters:
out- Output stream to save TIFF data to.filename- Filename of the output stream that we may use to create extra input or output streams as required.
-
TiffSaver
Constructs a new TIFF saver from the given output source.- Parameters:
out- Output stream to save TIFF data to.bytes- In memory byte array handle that we may use to create extra input or output streams as required.
-
-
Method Details
-
close
Closes the output stream if not null.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- Thrown if an error occurred while closing.
-
setWritingSequentially
public void setWritingSequentially(boolean sequential) Sets whether or not we know that the planes will be written sequentially. If we are writing planes sequentially and set this flag, then performance is slightly improved. -
getStream
Gets the stream from which TIFF data is being saved. -
setLittleEndian
public void setLittleEndian(boolean littleEndian) Sets whether or not little-endian data should be written. -
setBigTiff
public void setBigTiff(boolean bigTiff) Sets whether or not BigTIFF data should be written. -
isLittleEndian
public boolean isLittleEndian()Returns whether or not we are writing little-endian data. -
isBigTiff
public boolean isBigTiff()Returns whether or not we are writing BigTIFF data. -
setCodecOptions
Sets the codec options.- Parameters:
options- The value to set.
-
writeHeader
Writes the TIFF file header.- Throws:
IOException
-
writeImage
public void writeImage(byte[][] buf, IFDList ifds, int pixelType) throws loci.formats.FormatException, IOException -
writeImage
public void writeImage(byte[] buf, IFD ifd, int no, int pixelType, boolean last) throws loci.formats.FormatException, IOException -
writeImage
public void writeImage(byte[] buf, IFD ifd, int no, int pixelType, int x, int y, int w, int h, boolean last) throws loci.formats.FormatException, IOException Writes to any rectangle from the passed block.- Parameters:
buf- The block that is to be written.ifd- The Image File Directories. Mustn't benull.no- the plane index within the current series.pixelType- The type of pixels.x- The X-coordinate of the top-left corner.y- The Y-coordinate of the top-left corner.w- The width of the rectangle.h- The height of the rectangle.last- Passtrueif it is the last image,falseotherwise.- Throws:
loci.formats.FormatExceptionIOException
-
writeImage
public void writeImage(byte[] buf, IFD ifd, int no, int pixelType, int x, int y, int w, int h, boolean last, Integer nChannels, boolean copyDirectly) throws loci.formats.FormatException, IOException -
writeImageIFD
public void writeImageIFD(IFD ifd, int no, byte[][] strips, int nChannels, boolean last, int x, int y) throws loci.formats.FormatException, IOException Performs the actual work of dealing with IFD data and writing it to the TIFF for a given image or sub-image.- Parameters:
ifd- The Image File Directories. Mustn't benull.no- the plane index within the series.strips- The strips to write to the file.last- Passtrueif it is the last image,falseotherwise.x- The initial X offset of the strips/tiles to write.y- The initial Y offset of the strips/tiles to write.- Throws:
loci.formats.FormatExceptionIOException
-
writeIFD
Write the given IFD to the open stream. The provided offset will be used as the offset to the next IFD, and can be a placeholder value.- Parameters:
ifd- the complete IFD to be writtennextOffset- the offset of the next IFD to be written- Throws:
loci.formats.FormatExceptionIOException
-
writeIFD
public void writeIFD(IFD ifd, long nextOffset, boolean calculateOffset) throws loci.formats.FormatException, IOException Write the given IFD to the open stream. The provided offset will be used as the offset to the next IFD, unless offset calculation is requested. If offset calculation is requested, the next IFD's offset will be set so that it immediately follows the current IFD. Don't enable offset calculation when writing the last IFD, unless the offset will later be overwritten with 0.- Parameters:
ifd- the complete IFD to be writtennextOffset- the offset of the next IFD to be written (if known)calculateOffset- true if nextOffset should be ignored, and the next IFD should be assumed to immediately follow this one- Throws:
loci.formats.FormatExceptionIOException
-
writeIFDValue
public void writeIFDValue(RandomAccessOutputStream extraOut, long offset, int tag, Object value) throws loci.formats.FormatException, IOException Writes the given IFD value to the given output object.- Parameters:
extraOut- buffer to which "extra" IFD information should be writtenoffset- global offset to use for IFD offset valuestag- IFD tag to writevalue- IFD value to write- Throws:
loci.formats.FormatExceptionIOException
-
overwriteLastIFDOffset
public void overwriteLastIFDOffset(RandomAccessInputStream raf) throws loci.formats.FormatException, IOException -
overwriteIFDOffset
public void overwriteIFDOffset(RandomAccessInputStream raf, long offset, long nextPointer) throws loci.formats.FormatException, IOException -
overwriteIFDValue
public void overwriteIFDValue(RandomAccessInputStream raf, int ifd, int tag, Object value) throws loci.formats.FormatException, IOException Surgically overwrites an existing IFD value with the given one. This method requires that the IFD directory entry already exist. It intelligently updates the count field of the entry to match the new length. If the new length is longer than the old length, it appends the new data to the end of the file and updates the offset field; if not, or if the old data is already at the end of the file, it overwrites the old data in place.- Parameters:
raf- the input stream representing the file to be editedifd- the index into the list of IFDs, seeTiffParser.getIFDOffsets()tag- the tag codevalue- the new value for the tag- Throws:
loci.formats.FormatExceptionIOException
-
overwriteIFDValue
public void overwriteIFDValue(RandomAccessInputStream raf, long ifdOffset, int tag, Object value) throws loci.formats.FormatException, IOException Surgically overwrites an existing IFD value with the given one. This method requires that the IFD directory entry already exist. It intelligently updates the count field of the entry to match the new length. If the new length is longer than the old length, it appends the new data to the end of the file and updates the offset field; if not, or if the old data is already at the end of the file, it overwrites the old data in place.- Parameters:
raf- the input stream representing the file to be editedifdOffset- the offset to the IFDtag- the tag codevalue- the new value for the tag- Throws:
loci.formats.FormatExceptionIOException
-
overwriteIFDValue
public void overwriteIFDValue(RandomAccessInputStream raf, long ifdOffset, int tag, Object value, boolean skipHeaderCheck) throws loci.formats.FormatException, IOException Surgically overwrites an existing IFD value with the given one. This method requires that the IFD directory entry already exist. It intelligently updates the count field of the entry to match the new length. If the new length is longer than the old length, it appends the new data to the end of the file and updates the offset field; if not, or if the old data is already at the end of the file, it overwrites the old data in place.- Parameters:
raf- the input stream representing the file to be editedifdOffset- the offset to the IFDtag- the tag codevalue- the new value for the tagskipHeaderCheck- true if the TIFF header does not need to be checked- Throws:
loci.formats.FormatExceptionIOException
-
overwriteComment
public void overwriteComment(RandomAccessInputStream in, Object value) throws loci.formats.FormatException, IOException Convenience method for overwriting a file's first ImageDescription. -
makeValidIFD
Makes a valid IFD.- Parameters:
ifd- The IFD to handle.pixelType- The pixel type.nChannels- The number of channels.
-