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 int
bitsAllocated
private int
bitsStored
private java.util.BitSet
bufferBitSet
DOCUMENT ME!private byte[]
bufferByte
DOCUMENT ME!private double[]
bufferDouble
DOCUMENT ME!private float[]
bufferFloat
DOCUMENT ME!private int[]
bufferInt
DOCUMENT ME!private long[]
bufferLong
DOCUMENT ME!private short[]
bufferShort
DOCUMENT ME!private int
bufferSize
DOCUMENT ME!private int
compressionType
DOCUMENT ME!private java.util.zip.DeflaterOutputStream
deflaterStream
DOCUMENT ME!private FileInfoBase
fileInfo
DOCUMENT ME!private int
highBit
private java.util.zip.InflaterInputStream
inflaterStream
DOCUMENT ME!private int
minimumBitsMinus1
Used in reading and writing booleanprivate int
numChannels
private int
planarConfig
DOCUMENT ME!static int
RGB
DOCUMENT ME!private boolean
RGBAOrder
static int
RRRGGGBBB
DOCUMENT ME!private int
shiftToDivide
Used in reading and writing booleanprivate boolean
threeByteInteger
private int
type
DOCUMENT 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 void
close()
Closes the file.void
finalize()
Prepares this class for cleanup.java.util.BitSet
getBitSetBuffer()
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).void
readImage(int type, long start, int length)
This method reads a raw chunk from a file.void
setBitsAllocated(int bitsAllocated)
void
setBitsStored(int bitsStored)
void
setHighBit(int highBit)
void
setImageFile(java.io.RandomAccessFile file, FileInfoBase fInfo)
Sets the classes file handle to the past in the method.void
setMinimumBitsMinus1(int minimumBitsMinus1)
Used in reading and writing booleanvoid
setNumChannels(int numChannels)
Sets the number of channels used in RGB files.void
setPlanarConfig(int _planarConfig)
Sets the planar configuration for RGB images.void
setRGBAOrder(boolean RGBAOrder)
DOCUMENT ME!void
setShiftToDivide(int shiftToDivide)
Used in reading and writing booleanvoid
setThreeByteInteger(boolean threeByteInteger)
void
writeBufferByte(byte[] buffer, int start, int end)
This method writes a raw byte buffer to a file.void
writeBufferDouble(double[] buffer, int start, int end, boolean endianess)
This method writes a double buffer to a file.void
writeBufferFloat(float[] buffer, int start, int end, boolean endianess)
This method writes a float buffer to a file.void
writeBufferInt(int[] buffer, int start, int end, boolean endianess)
This method writes a int buffer to a file.void
writeBufferLong(long[] buffer, int start, int end, boolean endianess)
This method writes a int buffer to a file.void
writeBufferRGB(int[] buffer, int start, int end)
This method writes a RGB buffer to a file.void
writeBufferRGB_USHORT(int[] buffer, int start, int end, boolean endianess)
This method writes a RGB_USHORT buffer to a file.void
writeBufferShort(short[] buffer, int start, int end, boolean endianess)
This method writes a raw short buffer to a file.void
writeBufferUByte(short[] buffer, int start, int end)
This method writes a raw unsigned byte buffer to a file.void
writeBufferUInt(long[] buffer, int start, int end, boolean endianess)
This method writes an unisgned int buffer to a file.void
writeBufferUShort(int[] buffer, int start, int end, boolean endianess)
This method writes a raw unsigned short buffer to a file.void
writeImage(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.IOException
Closes 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.IOException
This 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.IOException
This 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.IOException
This 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.IOException
This 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.IOException
This 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.IOException
This 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.IOException
This 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.IOException
This 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.IOException
This 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.IOException
This 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.IOException
This 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.IOException
This 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!
-
-