Package gov.nih.mipav.model.file
Class FileRawChunk
- java.lang.Object
-
- gov.nih.mipav.model.file.FileBase
-
- gov.nih.mipav.model.file.FileRawChunk
-
public class FileRawChunk extends FileBase
The class reads and writes raw files of all data types: boolean, byte, short, int, long, float, and double. For the read process an offset can be passed as a parameter to identify the location in the file where the data starts. A number of file formats while not "raw" have data at a specific location after a fixed length but unknown header and therefore can be treated as raw.- Version:
- 0.1 Sept 2, 1997
- Author:
- Matthew J. McAuliffe, Ph.D.
- See Also:
FileRaw
-
-
Field Summary
Fields Modifier and Type Field Description private intbitsAllocatedprivate intbitsStoredprivate java.util.BitSetbufferBitSetDOCUMENT ME!private byte[]bufferByteDOCUMENT ME!private double[]bufferDoubleDOCUMENT ME!private float[]bufferFloatDOCUMENT ME!private int[]bufferIntDOCUMENT ME!private long[]bufferLongDOCUMENT ME!private short[]bufferShortDOCUMENT ME!private intbufferSizeDOCUMENT ME!private intcompressionTypeDOCUMENT ME!private java.util.zip.DeflaterOutputStreamdeflaterStreamDOCUMENT ME!private FileInfoBasefileInfoDOCUMENT ME!private inthighBitprivate java.util.zip.InflaterInputStreaminflaterStreamDOCUMENT ME!private intminimumBitsMinus1Used in reading and writing booleanprivate intnumChannelsprivate intplanarConfigDOCUMENT ME!static intRGBDOCUMENT ME!private booleanRGBAOrderstatic intRRRGGGBBBDOCUMENT ME!private intshiftToDivideUsed in reading and writing booleanprivate booleanthreeByteIntegerprivate inttypeDOCUMENT ME!-
Fields inherited from class gov.nih.mipav.model.file.FileBase
BIG_ENDIAN, bitsPerPixel, fileNames, LITTLE_ENDIAN, pBarVisible, raFile, READ, READ_WRITE
-
-
Constructor Summary
Constructors Constructor Description FileRawChunk(java.io.RandomAccessFile file, FileInfoBase fInfo)Raw reader/writer constructor.FileRawChunk(java.lang.String fileName, FileInfoBase fInfo, int rwFlag, int compress)Compressed raw reader/writer constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the file.voidfinalize()Prepares this class for cleanup.java.util.BitSetgetBitSetBuffer()Gets the Bitset buffer (binary image).byte[]getByteBuffer()Gets the byte buffer (image).double[]getDoubleBuffer()Gets the double buffer (image).float[]getFloatBuffer()Gets the float buffer (image).int[]getIntBuffer()gGets the integer buffer (image).long[]getLongBuffer()Gets the long buffer (image).short[]getShortBuffer()Gets the short buffer (image).voidreadImage(int type, long start, int length)This method reads a raw chunk from a file.voidsetBitsAllocated(int bitsAllocated)voidsetBitsStored(int bitsStored)voidsetHighBit(int highBit)voidsetImageFile(java.io.RandomAccessFile file, FileInfoBase fInfo)Sets the classes file handle to the past in the method.voidsetMinimumBitsMinus1(int minimumBitsMinus1)Used in reading and writing booleanvoidsetNumChannels(int numChannels)Sets the number of channels used in RGB files.voidsetPlanarConfig(int _planarConfig)Sets the planar configuration for RGB images.voidsetRGBAOrder(boolean RGBAOrder)DOCUMENT ME!voidsetShiftToDivide(int shiftToDivide)Used in reading and writing booleanvoidsetThreeByteInteger(boolean threeByteInteger)voidwriteBufferByte(byte[] buffer, int start, int end)This method writes a raw byte buffer to a file.voidwriteBufferDouble(double[] buffer, int start, int end, boolean endianess)This method writes a double buffer to a file.voidwriteBufferFloat(float[] buffer, int start, int end, boolean endianess)This method writes a float buffer to a file.voidwriteBufferInt(int[] buffer, int start, int end, boolean endianess)This method writes a int buffer to a file.voidwriteBufferLong(long[] buffer, int start, int end, boolean endianess)This method writes a int buffer to a file.voidwriteBufferRGB(int[] buffer, int start, int end)This method writes a RGB buffer to a file.voidwriteBufferRGB_USHORT(int[] buffer, int start, int end, boolean endianess)This method writes a RGB_USHORT buffer to a file.voidwriteBufferShort(short[] buffer, int start, int end, boolean endianess)This method writes a raw short buffer to a file.voidwriteBufferUByte(short[] buffer, int start, int end)This method writes a raw unsigned byte buffer to a file.voidwriteBufferUInt(long[] buffer, int start, int end, boolean endianess)This method writes an unisgned int buffer to a file.voidwriteBufferUShort(int[] buffer, int start, int end, boolean endianess)This method writes a raw unsigned short buffer to a file.voidwriteImage(ModelImage image, int start, int end)This method writes a raw image file (1D-5D).-
Methods inherited from class gov.nih.mipav.model.file.FileBase
addProgressChangeListener, bytesToDouble, bytesToFloat, bytesToInt, bytesToShort, doubleToBytes, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, floatToBytes, getBufferDouble, getBufferFloat, getBufferInt, getBufferLong, getBufferShort, getBufferUShort, getDataType, getDouble, getFloat, getInt, getLong, getProgressChangeListeners, getRaFile, getSignedShort, getString, getUInt, getUnsignedByte, getUnsignedShort, intToBytes, isBigEndian, isProgressBarVisible, linkProgress, longToBytes, readDouble, readFloat, readInt, readLong, readShort, readString, readUnsignedShort, removeProgressChangeListener, setBigEndian, setBufferFloat, setBufferInt, setBufferLong, setBufferShort, setBufferString, setDataType, setEndianess, shortToBytes, writeBytes, writeDouble, writeFloat, writeInt, writeLong, writeShort
-
-
-
-
Field Detail
-
RGB
public static final int RGB
DOCUMENT ME!- See Also:
- Constant Field Values
-
RRRGGGBBB
public static final int RRRGGGBBB
DOCUMENT ME!- See Also:
- Constant Field Values
-
bufferBitSet
private java.util.BitSet bufferBitSet
DOCUMENT ME!
-
bufferByte
private byte[] bufferByte
DOCUMENT ME!
-
bufferDouble
private double[] bufferDouble
DOCUMENT ME!
-
bufferFloat
private float[] bufferFloat
DOCUMENT ME!
-
bufferInt
private int[] bufferInt
DOCUMENT ME!
-
bufferLong
private long[] bufferLong
DOCUMENT ME!
-
bufferShort
private short[] bufferShort
DOCUMENT ME!
-
bufferSize
private int bufferSize
DOCUMENT ME!
-
compressionType
private int compressionType
DOCUMENT ME!
-
deflaterStream
private java.util.zip.DeflaterOutputStream deflaterStream
DOCUMENT ME!
-
fileInfo
private FileInfoBase fileInfo
DOCUMENT ME!
-
inflaterStream
private java.util.zip.InflaterInputStream inflaterStream
DOCUMENT ME!
-
numChannels
private int numChannels
-
planarConfig
private int planarConfig
DOCUMENT ME!
-
RGBAOrder
private boolean RGBAOrder
-
type
private int type
DOCUMENT ME!
-
minimumBitsMinus1
private int minimumBitsMinus1
Used in reading and writing boolean
-
shiftToDivide
private int shiftToDivide
Used in reading and writing boolean
-
threeByteInteger
private boolean threeByteInteger
-
bitsAllocated
private int bitsAllocated
-
bitsStored
private int bitsStored
-
highBit
private int highBit
-
-
Constructor Detail
-
FileRawChunk
public FileRawChunk(java.io.RandomAccessFile file, FileInfoBase fInfo)Raw reader/writer constructor.- Parameters:
file- random access file pointerfInfo- information that describes the image
-
FileRawChunk
public FileRawChunk(java.lang.String fileName, FileInfoBase fInfo, int rwFlag, int compress)Compressed raw reader/writer constructor.- Parameters:
fileName- the name of the file to read/writefInfo- information that describes the imagerwFlag- whether we are reading or writing the file (READ or WRITE)compress- the compression method to use (should not be none)
-
-
Method Detail
-
close
public final void close() throws java.io.IOExceptionCloses the file.- Throws:
java.io.IOException- DOCUMENT ME!
-
finalize
public void finalize()
Prepares this class for cleanup.
-
setMinimumBitsMinus1
public void setMinimumBitsMinus1(int minimumBitsMinus1)
Used in reading and writing boolean- Parameters:
minimumBitsMinus1-
-
setThreeByteInteger
public void setThreeByteInteger(boolean threeByteInteger)
-
setBitsAllocated
public void setBitsAllocated(int bitsAllocated)
-
setBitsStored
public void setBitsStored(int bitsStored)
-
setHighBit
public void setHighBit(int highBit)
-
setShiftToDivide
public void setShiftToDivide(int shiftToDivide)
Used in reading and writing boolean- Parameters:
shiftToDivide-
-
getBitSetBuffer
public java.util.BitSet getBitSetBuffer()
Gets the Bitset buffer (binary image).- Returns:
- the buffer
-
getByteBuffer
public byte[] getByteBuffer()
Gets the byte buffer (image).- Returns:
- the buffer
-
getDoubleBuffer
public double[] getDoubleBuffer()
Gets the double buffer (image).- Returns:
- the buffer
-
getFloatBuffer
public float[] getFloatBuffer()
Gets the float buffer (image).- Returns:
- the buffer
-
getIntBuffer
public int[] getIntBuffer()
gGets the integer buffer (image).- Returns:
- the buffer
-
getLongBuffer
public long[] getLongBuffer()
Gets the long buffer (image).- Returns:
- the buffer
-
getShortBuffer
public short[] getShortBuffer()
Gets the short buffer (image).- Returns:
- the buffer
-
readImage
public void readImage(int type, long start, int length) throws java.io.IOExceptionThis method reads a raw chunk from a file.- Parameters:
type- type of data that is to be readstart- points to where the data of the image is located.length- number of pixels to be read- Throws:
java.io.IOException- if there is an error reading the file
-
setImageFile
public void setImageFile(java.io.RandomAccessFile file, FileInfoBase fInfo)Sets the classes file handle to the past in the method.- Parameters:
file- random access file pointerfInfo- information that describes the image
-
setNumChannels
public void setNumChannels(int numChannels)
Sets the number of channels used in RGB files.- Parameters:
numChannels- DOCUMENT ME!
-
setPlanarConfig
public void setPlanarConfig(int _planarConfig)
Sets the planar configuration for RGB images.- Parameters:
_planarConfig- 0 indicates pixels are RGB, RGB chunky 1 indicates pixels are RRR, GGG, BBB planar
-
setRGBAOrder
public void setRGBAOrder(boolean RGBAOrder)
DOCUMENT ME!- Parameters:
RGBAOrder- DOCUMENT ME!
-
writeBufferByte
public void writeBufferByte(byte[] buffer, int start, int end) throws java.io.IOExceptionThis method writes a raw byte buffer to a file.- Parameters:
buffer- the image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]- Throws:
java.io.IOException- DOCUMENT ME!
-
writeBufferDouble
public void writeBufferDouble(double[] buffer, int start, int end, boolean endianess) throws java.io.IOExceptionThis method writes a double buffer to a file.- Parameters:
buffer- the image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]endianess- the endianess of the data- Throws:
java.io.IOException- DOCUMENT ME!
-
writeBufferFloat
public void writeBufferFloat(float[] buffer, int start, int end, boolean endianess) throws java.io.IOExceptionThis method writes a float buffer to a file.- Parameters:
buffer- the image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]endianess- the endianess of the data- Throws:
java.io.IOException- DOCUMENT ME!
-
writeBufferInt
public void writeBufferInt(int[] buffer, int start, int end, boolean endianess) throws java.io.IOExceptionThis method writes a int buffer to a file.- Parameters:
buffer- the image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]endianess- the endianess of the data- Throws:
java.io.IOException- DOCUMENT ME!
-
writeBufferLong
public void writeBufferLong(long[] buffer, int start, int end, boolean endianess) throws java.io.IOExceptionThis method writes a int buffer to a file.- Parameters:
buffer- the image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]endianess- the endianess of the data- Throws:
java.io.IOException- DOCUMENT ME!
-
writeBufferRGB
public void writeBufferRGB(int[] buffer, int start, int end) throws java.io.IOExceptionThis method writes a RGB buffer to a file.- Parameters:
buffer- the image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]- Throws:
java.io.IOException- DOCUMENT ME!
-
writeBufferRGB_USHORT
public void writeBufferRGB_USHORT(int[] buffer, int start, int end, boolean endianess) throws java.io.IOExceptionThis method writes a RGB_USHORT buffer to a file.- Parameters:
buffer- the image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]endianess- the endianess of the data- Throws:
java.io.IOException- DOCUMENT ME!
-
writeBufferShort
public void writeBufferShort(short[] buffer, int start, int end, boolean endianess) throws java.io.IOExceptionThis method writes a raw short buffer to a file.- Parameters:
buffer- the image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]endianess- the endianess of the data- Throws:
java.io.IOException- DOCUMENT ME!
-
writeBufferUByte
public void writeBufferUByte(short[] buffer, int start, int end) throws java.io.IOExceptionThis method writes a raw unsigned byte buffer to a file.- Parameters:
buffer- image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]- Throws:
java.io.IOException- DOCUMENT ME!
-
writeBufferUInt
public void writeBufferUInt(long[] buffer, int start, int end, boolean endianess) throws java.io.IOExceptionThis method writes an unisgned int buffer to a file.- Parameters:
buffer- the image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]endianess- the endianess of the data- Throws:
java.io.IOException- DOCUMENT ME!
-
writeBufferUShort
public void writeBufferUShort(int[] buffer, int start, int end, boolean endianess) throws java.io.IOExceptionThis method writes a raw unsigned short buffer to a file.- Parameters:
buffer- the image data bufferstart- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]endianess- the endianess of the data- Throws:
java.io.IOException- DOCUMENT ME!
-
writeImage
public void writeImage(ModelImage image, int start, int end) throws java.io.IOException
This method writes a raw image file (1D-5D).- Parameters:
image- image model from which the data will be read.start- start of data in the read image file in units of extents[0]*extents[1]end- end of data in the read image file in units of extents[0]*extents[1]- Throws:
java.io.IOException- DOCUMENT ME!
-
-