public class TiffSaver
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Field and Description |
---|---|
private boolean |
bigTiff
Whether or not to write BigTIFF data.
|
protected loci.common.ByteArrayHandle |
bytes
Output bytes.
|
protected java.lang.String |
filename
Output filename.
|
private loci.common.ByteArrayHandle |
ifdBuffer |
private static org.slf4j.Logger |
LOGGER |
private CodecOptions |
options
The codec options if set.
|
protected loci.common.RandomAccessOutputStream |
out
Output stream to use when saving TIFF data.
|
private long[] |
sequentialTileByteCounts |
private java.lang.Long |
sequentialTileFilePointer |
private long[] |
sequentialTileOffsets
Store tile offsets and original file pointer when writing sequentially.
|
private boolean |
sequentialWrite |
Constructor and Description |
---|
TiffSaver(loci.common.RandomAccessOutputStream out,
loci.common.ByteArrayHandle bytes)
Constructs a new TIFF saver from the given output source.
|
TiffSaver(loci.common.RandomAccessOutputStream out,
java.lang.String filename)
Constructs a new TIFF saver from the given output source.
|
TiffSaver(java.lang.String filename)
Constructs a new TIFF saver from the given filename.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the output stream if not null.
|
loci.common.RandomAccessOutputStream |
getStream()
Gets the stream from which TIFF data is being saved.
|
boolean |
isBigTiff()
Returns whether or not we are writing BigTIFF data.
|
boolean |
isLittleEndian()
Returns whether or not we are writing little-endian data.
|
private void |
makeValidIFD(IFD ifd,
int pixelType,
int nChannels)
Makes a valid IFD.
|
void |
overwriteComment(loci.common.RandomAccessInputStream in,
java.lang.Object value)
Convenience method for overwriting a file's first ImageDescription.
|
void |
overwriteIFDOffset(loci.common.RandomAccessInputStream raf,
long offset,
long nextPointer) |
void |
overwriteIFDValue(loci.common.RandomAccessInputStream raf,
int ifd,
int tag,
java.lang.Object value)
Surgically overwrites an existing IFD value with the given one.
|
void |
overwriteIFDValue(loci.common.RandomAccessInputStream raf,
long ifdOffset,
int tag,
java.lang.Object value)
Surgically overwrites an existing IFD value with the given one.
|
void |
overwriteIFDValue(loci.common.RandomAccessInputStream raf,
long ifdOffset,
int tag,
java.lang.Object value,
boolean skipHeaderCheck)
Surgically overwrites an existing IFD value with the given one.
|
void |
overwriteLastIFDOffset(loci.common.RandomAccessInputStream raf) |
void |
setBigTiff(boolean bigTiff)
Sets whether or not BigTIFF data should be written.
|
void |
setCodecOptions(CodecOptions options)
Sets the codec options.
|
void |
setLittleEndian(boolean littleEndian)
Sets whether or not little-endian data should be written.
|
void |
setWritingSequentially(boolean sequential)
Sets whether or not we know that the planes will be written sequentially.
|
void |
writeHeader()
Writes the TIFF file header.
|
void |
writeIFD(IFD ifd,
long nextOffset)
Write the given IFD to the open stream.
|
void |
writeIFD(IFD ifd,
long nextOffset,
boolean calculateOffset)
Write the given IFD to the open stream.
|
private void |
writeIFDStrips(IFD ifd,
int no,
byte[][] strips,
int nChannels,
boolean last,
int x,
int y,
long defaultByteCount) |
void |
writeIFDValue(loci.common.RandomAccessOutputStream extraOut,
long offset,
int tag,
java.lang.Object value)
Writes the given IFD value to the given output object.
|
void |
writeImage(byte[][] buf,
IFDList ifds,
int pixelType) |
void |
writeImage(byte[] buf,
IFD ifd,
int no,
int pixelType,
boolean last) |
void |
writeImage(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.
|
void |
writeImage(byte[] buf,
IFD ifd,
int no,
int pixelType,
int x,
int y,
int w,
int h,
boolean last,
java.lang.Integer nChannels,
boolean copyDirectly) |
private void |
writeImageIFD(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.
|
private void |
writeIntValue(loci.common.RandomAccessOutputStream out,
long offset)
Write the given value to the given RandomAccessOutputStream.
|
private static final org.slf4j.Logger LOGGER
protected loci.common.RandomAccessOutputStream out
protected java.lang.String filename
protected loci.common.ByteArrayHandle bytes
private boolean bigTiff
private boolean sequentialWrite
private long[] sequentialTileOffsets
private long[] sequentialTileByteCounts
private java.lang.Long sequentialTileFilePointer
private CodecOptions options
private loci.common.ByteArrayHandle ifdBuffer
public TiffSaver(java.lang.String filename) throws java.io.IOException
filename
- Filename of the output stream that we may use to create
extra input or output streams as required.java.io.IOException
public TiffSaver(loci.common.RandomAccessOutputStream out, java.lang.String filename)
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.public TiffSaver(loci.common.RandomAccessOutputStream out, loci.common.ByteArrayHandle bytes)
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.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- Thrown if an error occurred while closing.public void setWritingSequentially(boolean sequential)
public loci.common.RandomAccessOutputStream getStream()
public void setLittleEndian(boolean littleEndian)
public void setBigTiff(boolean bigTiff)
public boolean isLittleEndian()
public boolean isBigTiff()
public void setCodecOptions(CodecOptions options)
options
- The value to set.public void writeHeader() throws java.io.IOException
java.io.IOException
public void writeImage(byte[][] buf, IFDList ifds, int pixelType) throws FormatException, java.io.IOException
FormatException
java.io.IOException
public void writeImage(byte[] buf, IFD ifd, int no, int pixelType, boolean last) throws FormatException, java.io.IOException
FormatException
java.io.IOException
public void writeImage(byte[] buf, IFD ifd, int no, int pixelType, int x, int y, int w, int h, boolean last) throws FormatException, java.io.IOException
buf
- The block that is to be written.ifd
- The Image File Directories. Mustn't be null
.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
- Pass true
if it is the last image,
false
otherwise.FormatException
java.io.IOException
public void writeImage(byte[] buf, IFD ifd, int no, int pixelType, int x, int y, int w, int h, boolean last, java.lang.Integer nChannels, boolean copyDirectly) throws FormatException, java.io.IOException
FormatException
java.io.IOException
private void writeImageIFD(IFD ifd, int no, byte[][] strips, int nChannels, boolean last, int x, int y) throws FormatException, java.io.IOException
ifd
- The Image File Directories. Mustn't be null
.no
- the plane index within the series.strips
- The strips to write to the file.last
- Pass true
if it is the last image,
false
otherwise.x
- The initial X offset of the strips/tiles to write.y
- The initial Y offset of the strips/tiles to write.FormatException
java.io.IOException
public void writeIFD(IFD ifd, long nextOffset) throws FormatException, java.io.IOException
ifd
- the complete IFD to be writtennextOffset
- the offset of the next IFD to be writtenFormatException
java.io.IOException
public void writeIFD(IFD ifd, long nextOffset, boolean calculateOffset) throws FormatException, java.io.IOException
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 oneFormatException
java.io.IOException
public void writeIFDValue(loci.common.RandomAccessOutputStream extraOut, long offset, int tag, java.lang.Object value) throws FormatException, java.io.IOException
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 writeFormatException
java.io.IOException
public void overwriteLastIFDOffset(loci.common.RandomAccessInputStream raf) throws FormatException, java.io.IOException
FormatException
java.io.IOException
public void overwriteIFDOffset(loci.common.RandomAccessInputStream raf, long offset, long nextPointer) throws FormatException, java.io.IOException
FormatException
java.io.IOException
public void overwriteIFDValue(loci.common.RandomAccessInputStream raf, int ifd, int tag, java.lang.Object value) throws FormatException, java.io.IOException
raf
- the input stream representing the file to be editedifd
- the index into the list of IFDs TiffParser.getIFDOffsets()
tag
- the tag codevalue
- the new value for the tagFormatException
java.io.IOException
public void overwriteIFDValue(loci.common.RandomAccessInputStream raf, long ifdOffset, int tag, java.lang.Object value) throws FormatException, java.io.IOException
raf
- the input stream representing the file to be editedifdOffset
- the offset to the IFDtag
- the tag codevalue
- the new value for the tagFormatException
java.io.IOException
public void overwriteIFDValue(loci.common.RandomAccessInputStream raf, long ifdOffset, int tag, java.lang.Object value, boolean skipHeaderCheck) throws FormatException, java.io.IOException
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 checkedFormatException
java.io.IOException
public void overwriteComment(loci.common.RandomAccessInputStream in, java.lang.Object value) throws FormatException, java.io.IOException
FormatException
java.io.IOException
private void writeIntValue(loci.common.RandomAccessOutputStream out, long offset) throws java.io.IOException
java.io.IOException
private void makeValidIFD(IFD ifd, int pixelType, int nChannels)
ifd
- The IFD to handle.pixelType
- The pixel type.nChannels
- The number of channels.private void writeIFDStrips(IFD ifd, int no, byte[][] strips, int nChannels, boolean last, int x, int y, long defaultByteCount) throws FormatException, java.io.IOException
FormatException
java.io.IOException
Copyright © 2023 Open Microscopy Environment