Package loci.formats.out
Class DicomWriter
java.lang.Object
loci.formats.FormatHandler
loci.formats.FormatWriter
loci.formats.out.DicomWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,ICompressedTileWriter,IFormatHandler,IFormatWriter,IMetadataConfigurable,IPyramidHandler,IExtraMetadataWriter
DicomWriter is the file format writer for DICOM files.
This is designed for whole slide images, and may not produce
schema-compliant files for other modalities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class(package private) classHelper class for creating UIDs. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate intprivate booleanprivate long[]private Integerprivate longprivate IFD[][]private Stringprivate Stringprivate long[]private long[]private int[]private DicomWriter.PlaneOffset[][]private static final Stringprivate ArrayList<ITagProvider> static final StringOption for turning off TIFF metadata.private TiffSaverprivate long[]private int[]private long[]private int[]private long[]private long[]static final Stringstatic final StringOption for setting the organization root for UIDs.private DicomWriter.UIDCreatorprivate BooleanFields inherited from class loci.formats.FormatWriter
cm, compression, compressionTypes, fps, initialized, interleaved, metadataRetrieve, options, out, resolution, resolutionData, sequential, series, validBitsFields inherited from class loci.formats.FormatHandler
COMPRESSION_SUFFIXES, currentId, format, LOGGER, metadataOptions, suffixes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReports whether the writer can save multiple images to a single file.private voidcheckPixelCount(boolean warn) private voidCheck if pre-compressed tiles are supported with the current options.voidclose()private ome.units.quantity.LengthfixUnits(ome.units.quantity.Length size) Check if the unit for the given Length is "pixel" or "referenceframe".static StringformatFixedWidth(double v, int width) Format the given double as a string with no more thanwidthcharacters.getCodec()private Stringprivate StringgetFilename(int pyramid, int res) private StringgetImageType(String pyramidName, int res, boolean hasPyramid, int resolutionCount) private intgetIndex(int pyramid, int res) private TiffRationalgetPhysicalSize(ome.units.quantity.Length size) int[]getPixelTypes(String codec) Gets the supported pixel types for the given codec.private static StringgetScientificNotationPattern(int intDigits, int signBytes, int width) private intgetStoredLength(DicomTag tag) private TiffCompressionintRetrieves the current tile width Defaults to 0 if not supportedintRetrieves the current tile height Defaults to 0 if not supportedprivate Stringprivate int[]getZCTCoords(int no) private booleanprivate DicomTagprivate DicomTagmakeItem()private DicomTagprivate short[]makeShortArray(int v) private voidopenFile(int pyramid, int res) private StringPad the given string so that the length is a multiple of 2.private Stringprivate Stringprivate voidprivate StringPad the given string so that the length is a multiple of 2.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.voidsaveCompressedBytes(int no, byte[] buf, int x, int y, int w, int h) Save a compressed tile to the current output file.voidsetBigTiff(boolean bigTiff) Sets whether or not BigTIFF files should be written.voidsetExtraMetadata(String tagSource) Provide additional metadata that should be written as part of this dataset.voidInitializes a writer from the input file name.voidsetResolution(int r) Set the resolution level.voidsetSeries(int s) 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 usedprotected org.perf4j.slf4j.Slf4JStopWatchbooleanChecks the writer's associated MetadataOptions to see if dual personality writing has been explicitly enabled or disabled.private voidWrite the preamble, prefix, and file meta elements.private voidwriteIFDs(int resIndex) private voidprivate voidMethods inherited from class loci.formats.FormatWriter
changeOutputFile, checkParams, createOutputStream, getCodecOptions, getColorModel, getCompression, getCompressionTypes, getFramesPerSecond, getMetadataRetrieve, getPixelTypes, getPlaneCount, getPlaneCount, getResolution, getResolutionCount, getResolutions, getSamplesPerPixel, getSamplesPerPixel, getSeries, getSizeX, getSizeY, hasResolutions, isFullPlane, isInterleaved, isSupportedType, saveBytes, saveBytes, savePlane, savePlane, savePlane, seekToPlaneOffset, setCodecOptions, setColorModel, setCompression, setFramesPerSecond, setInterleaved, setMetadataRetrieve, setResolutions, setValidBitsPerPixel, setWriteSequentiallyMethods 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.IFormatHandler
getFormat, getNativeDataType, getSuffixes, isThisTypeMethods inherited from interface loci.formats.IMetadataConfigurable
getMetadataOptions, getSupportedMetadataLevels, setMetadataOptions
-
Field Details
-
UID_ROOT_KEY
Option for setting the organization root for UIDs.- See Also:
-
UID_DEFAULT_ROOT
- See Also:
-
TIFF_KEY
Option for turning off TIFF metadata.- See Also:
-
SOP_CLASS_UID_VALUE
- See Also:
-
pixelDataLengthPointer
private long[] pixelDataLengthPointer -
pixelDataSize
private int[] pixelDataSize -
transferSyntaxPointer
private long[] transferSyntaxPointer -
compressionMethodPointer
private long[] compressionMethodPointer -
nextIFDPointer
private long[] nextIFDPointer -
ifds
-
fileMetaLengthPointer
private long fileMetaLengthPointer -
baseTileWidth
private int baseTileWidth -
baseTileHeight
private int baseTileHeight -
tileWidth
private int[] tileWidth -
tileHeight
private int[] tileHeight -
tileWidthPointer
private long[] tileWidthPointer -
tileHeightPointer
private long[] tileHeightPointer -
tileCountPointer
private long[] tileCountPointer -
planeOffsets
-
currentPlane
-
uids
-
instanceUIDValue
-
implementationUID
-
tagProviders
-
bigTiff
private boolean bigTiff -
tiffSaver
-
validPixelCount
-
-
Constructor Details
-
DicomWriter
public DicomWriter()
-
-
Method Details
-
setExtraMetadata
Description copied from interface:IExtraMetadataWriterProvide additional metadata that should be written as part of this dataset. Primarily intended for DicomWriter. Calling this method is optional. Multiple calls are allowed, e.g. if tags come from multiple external sources. If multiple calls to this method are made then the order matters, with earlier calls implying higher priority when resolving duplicate or conflicting tags. All calls to this method must occur before setId is called.- Specified by:
setExtraMetadatain interfaceIExtraMetadataWriter
-
setBigTiff
public void setBigTiff(boolean bigTiff) Sets whether or not BigTIFF files should be written. This flag is not reset when close() is called. -
writeDualPersonality
public boolean writeDualPersonality()Checks the writer's associated MetadataOptions to see if dual personality writing has been explicitly enabled or disabled. If the option is not set, the default is to return true, enabling dual personality writing. -
setSeries
Description copied from interface:IFormatWriterSets the current series.- Specified by:
setSeriesin interfaceIFormatWriter- Overrides:
setSeriesin classFormatWriter- Parameters:
s- the series index, starting from 0.- Throws:
FormatException- if the specified series is invalid.
-
setResolution
public void setResolution(int r) Description copied from interface:IPyramidHandlerSet the resolution level.- Specified by:
setResolutionin interfaceIPyramidHandler- Overrides:
setResolutionin classFormatWriter- See Also:
-
getCodec
- Specified by:
getCodecin interfaceICompressedTileWriter- Returns:
- the codec that can be used to compress tiles
-
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
-
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.- See Also:
-
canDoStacks
public boolean canDoStacks()Description copied from interface:IFormatWriterReports whether the writer can save multiple images to a single file.- Specified by:
canDoStacksin interfaceIFormatWriter- Overrides:
canDoStacksin classFormatWriter
-
getPixelTypes
Description copied from interface:IFormatWriterGets the supported pixel types for the given codec.- Specified by:
getPixelTypesin interfaceIFormatWriter- Overrides:
getPixelTypesin classFormatWriter
-
setId
Description copied from class:FormatWriterInitializes a writer from the input file name. Initializes aRandomAccessOutputStreamfor the output file and initializes the metadata for all the series usingFormatWriter.setSeries(int).- Specified by:
setIdin interfaceIFormatHandler- Overrides:
setIdin classFormatWriter- Parameters:
id- aStringspecifying the path to the file- Throws:
FormatExceptionIOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFormatWriter- Throws:
IOException
-
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- Overrides:
setTileSizeXin classFormatWriter- 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
-
getTileSizeX
public int getTileSizeX()Description copied from interface:IFormatWriterRetrieves the current tile width Defaults to 0 if not supported- Specified by:
getTileSizeXin interfaceIFormatWriter- Overrides:
getTileSizeXin classFormatWriter- Returns:
- The current tile width being used
-
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- Overrides:
setTileSizeYin classFormatWriter- 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
-
getTileSizeY
public int getTileSizeY()Description copied from interface:IFormatWriterRetrieves the current tile height Defaults to 0 if not supported- Specified by:
getTileSizeYin interfaceIFormatWriter- Overrides:
getTileSizeYin classFormatWriter- Returns:
- The current tile height being used
-
getUIDRoot
-
getStoredLength
-
writeTag
- Throws:
IOException
-
writeTag
- Throws:
IOException
-
padString
Pad the given string so that the length is a multiple of 2. If the input is null, an empty string is returned. Otherwise, a space is appended if necessary. This should not be used for UID values.- Parameters:
value- original string- Returns:
- padded string whose length is a multiple of 2
-
padUID
Pad the given string so that the length is a multiple of 2. If the input is null, an empty string is returned. Otherwise, a null character is appended if necessary. This should not be used for non-UID values.- Parameters:
value- original string- Returns:
- padded string whose length is a multiple of 2
-
padString
-
padString
-
getTransferSyntax
- Returns:
- transfer syntax UID corresponding to the current compression type
-
getCompressionMethod
- Returns:
- compression method corresponding to the current compression type
-
openFile
- Throws:
IOException
-
writeHeader
Write the preamble, prefix, and file meta elements. See http://dicom.nema.org/medical/dicom/current/output/html/part10.html#sect_7.1- Throws:
IOException
-
getFilename
-
getIndex
private int getIndex(int pyramid, int res) -
getZCTCoords
private int[] getZCTCoords(int no) -
isReallySequential
private boolean isReallySequential() -
getImageType
-
writeIFDs
- Throws:
IOException
-
getTIFFCompression
-
makeItem
- Returns:
- item tag with an undefined length
-
makeItemDelimitation
- Returns:
- item delimitation tag with 0 length
-
lookupTag
-
padTagValues
-
makeShortArray
private short[] makeShortArray(int v) -
fixUnits
private ome.units.quantity.Length fixUnits(ome.units.quantity.Length size) Check if the unit for the given Length is "pixel" or "referenceframe". These two units cannot be assigned to proper physical units (e.g. mm), so need to be handled specially. -
getPhysicalSize
-
checkPrecompressedSupport
private void checkPrecompressedSupport()Check if pre-compressed tiles are supported with the current options. TODO: maybe this should be a higher-level API method?- Throws:
UnsupportedOperationException- if pre-compressed tiles are not supported
-
checkPixelCount
- Throws:
FormatException
-
getScientificNotationPattern
-
formatFixedWidth
Format the given double as a string with no more thanwidthcharacters. -
stopWatch
protected org.perf4j.slf4j.Slf4JStopWatch stopWatch()
-