Package gov.nih.mipav.model.file
Class FileAvi
- java.lang.Object
-
- gov.nih.mipav.model.file.FileBase
-
- gov.nih.mipav.model.file.FileAvi
-
public class FileAvi extends FileBase
AVI file writer and reader.- Version:
- 1.1 March 5, 2011
- Author:
- William Gandler, Matthew J. McAuliffe, Ph.D. The Microsoft Video 1 decoding was mostly derived from Mike A good source of sample avi files is http://samples.mplayerhq.hu.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
AVIF_HASINDEX
private boolean
AVIF_ISINTERLEAVED
DOCUMENT ME!private boolean
AVIF_MUSTUSEINDEX
globals needed for read - set in readHeader, used in readImage.private short
bitCount
DOCUMENT ME!private int
blankFramesSent
DOCUMENT ME!private byte[]
bufferWrite
DOCUMENT ME!private float
captureTime
private int
compression
0 for RGB 24 bit per pixel uncompressed 1 for RLE 8 bit per pixel compressed 1296126531 for Microsoft video 1 compression.private float
compressionQuality
DOCUMENT ME!private int
dataFramesSent
DOCUMENT ME!private byte[]
dataSignature
globals needed for write.private int[]
dcLength
DOCUMENT ME!private boolean
endianess
true for big-endian and false for little-endian.private java.io.File
file
DOCUMENT ME!private java.lang.String
fileDir
DOCUMENT ME!private FileInfoAvi
fileInfo
DOCUMENT ME!private java.lang.String
fileName
DOCUMENT ME!private java.io.File
fileW
private int
framesToCapture
private int
framesToSkip
private int
height
DOCUMENT ME!private long
idx1Position
DOCUMENT ME!private ModelImage
imageA
DOCUMENT ME!private ModelImage
imageB
DOCUMENT ME!private float[]
imageBufferA
DOCUMENT ME!private float[]
imageBufferB
DOCUMENT ME!private float
imageMinA
DOCUMENT ME!private long
indexPointer
DOCUMENT ME!private int
indexSize
Size of the index block in bytes.private boolean
isScript
for saving within scripts.private int
LIST2Size
DOCUMENT ME!private int
LIST2subchunkSize
DOCUMENT ME!private ModelLUT
LUTa
DOCUMENT ME!private byte[]
lutBuffer
DOCUMENT ME!private int[]
lutBufferRemapped
DOCUMENT ME!private int
microSecPerFrame
DOCUMENT ME!private long
moviPosition
DOCUMENT ME!private long
moviSubchunkPosition
DOCUMENT ME!private int
newCompressionType
2 for .mov, 3 for mjpeg, 4 for mp4v2.private java.lang.String
outputFileName
private ProgressBarInterface
progressBar
DOCUMENT ME!private java.io.RandomAccessFile
raFileW
private int
rate
private boolean
readQT
DOCUMENT ME!private float
remapConstA
DOCUMENT ME!private long[]
savedbLength
DOCUMENT ME!private long
saveFileSize
DOCUMENT ME!private long
saveLIST2Size
DOCUMENT ME!private long
savemovi
DOCUMENT ME!private int
scale
private float
skipTime
private int
streams
DOCUMENT ME!private int
tDim
DOCUMENT ME!private int
totalBlankFrames
DOCUMENT ME!private int
totalDataFrames
These are used for writing the AVI frame by frame from the surface renderer.private ViewUserInterface
UI
DOCUMENT ME!private boolean
useNewCompression
DOCUMENT ME!private int
width
DOCUMENT ME!private boolean
writeQT
DOCUMENT ME!private int
xDim
DOCUMENT ME!private int
xPad
DOCUMENT ME!private int
yDim
DOCUMENT ME!private int
zDim
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 FileAvi(java.lang.String fileName, java.lang.String fileDir)
Avi reader/writer constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
DOCUMENT ME!private byte[]
createLUT()
Creates a LUT to write.void
finalize()
Prepares this class for cleanup.java.lang.String
getFileDir()
Returns fileDir.FileInfoAvi
getFileInfo()
java.lang.String
getFileName()
Returns fileName.boolean
getHasIndex()
int
getMicroSecPerFrame()
ModelLUT
getModelLUT()
Returns LUT if defined.boolean
getMustUseIndex()
int
getRate()
int
getScale()
int
readHeader()
Reads the image header.ModelImage
readImage(boolean one)
Reads the AVI file header and data.boolean
readWriteImage()
void
setAVIWrite(ModelImage _imageA, int microSecPerFrame, int _totalDataFrames, int _totalBlankFrames)
This method sets up for an AVI image write.void
setCaptureTime(float captureTime)
void
setCompressionQuality(float quality)
DOCUMENT ME!void
setIsScript(boolean isScript)
DOCUMENT ME!void
setMicroSecPerFrame(int microSec)
DOCUMENT ME!void
setOutputFileName(java.lang.String outputFileName)
void
setProgressBar(ProgressBarInterface pBar)
DOCUMENT ME!void
setReadQT(boolean readQT)
DOCUMENT ME!void
setSkipTime(float skipTime)
void
setWriteQT(boolean writeQuickTime)
DOCUMENT ME!private void
writeAVITriplet(int timeSlice, int slice, ModelLUT LUTb, int red, int green, int blue, float opacityPrime, float alphaBlend, java.util.BitSet paintBitmap)
Writes the AVI BGR triplet.private void
writeAVITripletC(int timeSlice, int slice, ModelRGB RGBTA, ModelRGB RGBTB, int red, int green, int blue, float opacityPrime, float alphaBlend, java.util.BitSet paintBitmap)
Write BGR AVI triplet for color image.private void
writeAVITripletCFrames()
Write BGR AVI triplet for color image.void
writeBlankFrame()
DOCUMENT ME!void
writeDataFrame(ModelImage _imageA)
DOCUMENT ME!private void
writeidx1CHUNK()
DOCUMENT ME!boolean
writeImage(ModelImage _imageA, ModelImage _imageB, ModelLUT _LUTa, ModelLUT LUTb, ModelRGB RGBTA, ModelRGB RGBTB, int red, int green, int blue, float OPACITY, float alphaBlend, java.util.BitSet paintBitmap, int compression)
This method writes an AVI image file.void
writeIntW(int data, boolean bigEndian)
Writes an int as four bytes to a file.private void
writeRLE8(int timeSlice, int slice, byte[] pixStore, byte[] lastStore, byte[] encodeStore)
Writes the RLE8 encoded LUT index.void
writeShortW(short data, boolean bigEndian)
Writes a short as two bytes to a file.-
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
-
AVIF_ISINTERLEAVED
private boolean AVIF_ISINTERLEAVED
DOCUMENT ME!
-
AVIF_MUSTUSEINDEX
private boolean AVIF_MUSTUSEINDEX
globals needed for read - set in readHeader, used in readImage.
-
AVIF_HASINDEX
private boolean AVIF_HASINDEX
-
bitCount
private short bitCount
DOCUMENT ME!
-
blankFramesSent
private int blankFramesSent
DOCUMENT ME!
-
bufferWrite
private byte[] bufferWrite
DOCUMENT ME!
-
compression
private int compression
0 for RGB 24 bit per pixel uncompressed 1 for RLE 8 bit per pixel compressed 1296126531 for Microsoft video 1 compression.
-
compressionQuality
private float compressionQuality
DOCUMENT ME!
-
dataFramesSent
private int dataFramesSent
DOCUMENT ME!
-
dataSignature
private byte[] dataSignature
globals needed for write.
-
dcLength
private int[] dcLength
DOCUMENT ME!
-
endianess
private boolean endianess
true for big-endian and false for little-endian.
-
file
private java.io.File file
DOCUMENT ME!
-
fileDir
private java.lang.String fileDir
DOCUMENT ME!
-
fileInfo
private FileInfoAvi fileInfo
DOCUMENT ME!
-
fileName
private java.lang.String fileName
DOCUMENT ME!
-
height
private int height
DOCUMENT ME!
-
idx1Position
private long idx1Position
DOCUMENT ME!
-
imageA
private ModelImage imageA
DOCUMENT ME!
-
imageB
private ModelImage imageB
DOCUMENT ME!
-
imageBufferA
private float[] imageBufferA
DOCUMENT ME!
-
imageBufferB
private float[] imageBufferB
DOCUMENT ME!
-
imageMinA
private float imageMinA
DOCUMENT ME!
-
indexPointer
private long indexPointer
DOCUMENT ME!
-
indexSize
private int indexSize
Size of the index block in bytes.
-
isScript
private boolean isScript
for saving within scripts.
-
LIST2Size
private int LIST2Size
DOCUMENT ME!
-
LIST2subchunkSize
private int LIST2subchunkSize
DOCUMENT ME!
-
LUTa
private ModelLUT LUTa
DOCUMENT ME!
-
lutBuffer
private byte[] lutBuffer
DOCUMENT ME!
-
lutBufferRemapped
private int[] lutBufferRemapped
DOCUMENT ME!
-
microSecPerFrame
private int microSecPerFrame
DOCUMENT ME!
-
scale
private int scale
-
rate
private int rate
-
moviPosition
private long moviPosition
DOCUMENT ME!
-
moviSubchunkPosition
private long moviSubchunkPosition
DOCUMENT ME!
-
newCompressionType
private int newCompressionType
2 for .mov, 3 for mjpeg, 4 for mp4v2.
-
progressBar
private ProgressBarInterface progressBar
DOCUMENT ME!
-
readQT
private boolean readQT
DOCUMENT ME!
-
remapConstA
private float remapConstA
DOCUMENT ME!
-
savedbLength
private long[] savedbLength
DOCUMENT ME!
-
saveFileSize
private long saveFileSize
DOCUMENT ME!
-
saveLIST2Size
private long saveLIST2Size
DOCUMENT ME!
-
savemovi
private long savemovi
DOCUMENT ME!
-
streams
private int streams
DOCUMENT ME!
-
totalBlankFrames
private int totalBlankFrames
DOCUMENT ME!
-
totalDataFrames
private int totalDataFrames
These are used for writing the AVI frame by frame from the surface renderer.
-
UI
private ViewUserInterface UI
DOCUMENT ME!
-
useNewCompression
private boolean useNewCompression
DOCUMENT ME!
-
width
private int width
DOCUMENT ME!
-
writeQT
private boolean writeQT
DOCUMENT ME!
-
xDim
private int xDim
DOCUMENT ME!
-
yDim
private int yDim
DOCUMENT ME!
-
zDim
private int zDim
DOCUMENT ME!
-
tDim
private int tDim
DOCUMENT ME!
-
xPad
private int xPad
DOCUMENT ME!
-
outputFileName
private java.lang.String outputFileName
-
captureTime
private float captureTime
-
skipTime
private float skipTime
-
fileW
private java.io.File fileW
-
raFileW
private java.io.RandomAccessFile raFileW
-
framesToCapture
private int framesToCapture
-
framesToSkip
private int framesToSkip
-
-
Method Detail
-
setCaptureTime
public void setCaptureTime(float captureTime)
-
setSkipTime
public void setSkipTime(float skipTime)
-
setOutputFileName
public void setOutputFileName(java.lang.String outputFileName)
-
getMicroSecPerFrame
public int getMicroSecPerFrame()
-
getScale
public int getScale()
-
getRate
public int getRate()
-
getHasIndex
public boolean getHasIndex()
-
getMustUseIndex
public boolean getMustUseIndex()
-
close
public void close()
DOCUMENT ME!
-
finalize
public void finalize()
Prepares this class for cleanup.
-
getFileDir
public java.lang.String getFileDir()
Returns fileDir.- Returns:
- fileDir
-
getFileName
public java.lang.String getFileName()
Returns fileName.- Returns:
- filename
-
getFileInfo
public FileInfoAvi getFileInfo()
-
getModelLUT
public ModelLUT getModelLUT()
Returns LUT if defined.- Returns:
- The LUT if defined, otherwise null.
-
readImage
public ModelImage readImage(boolean one) throws java.io.IOException
Reads the AVI file header and data.- Parameters:
one
- if true only reads one slice per file- Returns:
- An ARGB image
- Throws:
java.io.IOException
- if there is an error reading the file
-
setAVIWrite
public void setAVIWrite(ModelImage _imageA, int microSecPerFrame, int _totalDataFrames, int _totalBlankFrames) throws java.io.IOException
This method sets up for an AVI image write. This is only used for RGB images where only an imageA and no imageB will be present. The image will be written as a series of 2D images and a series of frames without data used for repeating existing frames. This method will use the first 2D image.- Parameters:
_imageA
- First 2D image for AVI.microSecPerFrame
- Frame rate._totalDataFrames
- Number of frames containing true data._totalBlankFrames
- Number of frames that are "blank" and should be filled with previous frame's data.- Throws:
java.io.IOException
- if there is an error writing the file.
-
setCompressionQuality
public void setCompressionQuality(float quality)
DOCUMENT ME!- Parameters:
quality
- DOCUMENT ME!
-
setIsScript
public void setIsScript(boolean isScript)
DOCUMENT ME!- Parameters:
isScript
- DOCUMENT ME!
-
setMicroSecPerFrame
public void setMicroSecPerFrame(int microSec)
DOCUMENT ME!- Parameters:
microSec
- DOCUMENT ME!
-
setProgressBar
public void setProgressBar(ProgressBarInterface pBar)
DOCUMENT ME!- Parameters:
pBar
- DOCUMENT ME!
-
setReadQT
public void setReadQT(boolean readQT)
DOCUMENT ME!- Parameters:
readQT
- DOCUMENT ME!
-
setWriteQT
public void setWriteQT(boolean writeQuickTime)
DOCUMENT ME!- Parameters:
writeQuickTime
- DOCUMENT ME!
-
writeBlankFrame
public void writeBlankFrame() throws java.io.IOException
DOCUMENT ME!- Throws:
java.io.IOException
- DOCUMENT ME!
-
writeDataFrame
public void writeDataFrame(ModelImage _imageA) throws java.io.IOException
DOCUMENT ME!- Parameters:
_imageA
- DOCUMENT ME!- Throws:
java.io.IOException
- DOCUMENT ME!
-
writeImage
public boolean writeImage(ModelImage _imageA, ModelImage _imageB, ModelLUT _LUTa, ModelLUT LUTb, ModelRGB RGBTA, ModelRGB RGBTB, int red, int green, int blue, float OPACITY, float alphaBlend, java.util.BitSet paintBitmap, int compression) throws java.io.IOException
This method writes an AVI image file.- Parameters:
_imageA
- DOCUMENT ME!_imageB
- DOCUMENT ME!_LUTa
- DOCUMENT ME!LUTb
- DOCUMENT ME!RGBTA
- DOCUMENT ME!RGBTB
- DOCUMENT ME!red
- DOCUMENT ME!green
- DOCUMENT ME!blue
- DOCUMENT ME!OPACITY
- DOCUMENT ME!alphaBlend
- DOCUMENT ME!paintBitmap
- DOCUMENT ME!compression
- -1 = unchosen, 0 = 24 bit uncompressed RGB, 1 = 8 bit per pixel compressed RLE- Returns:
- DOCUMENT ME!
- Throws:
java.io.IOException
- if there is an error writing the file.
-
createLUT
private byte[] createLUT()
Creates a LUT to write.- Returns:
- DOCUMENT ME!
-
readHeader
public int readHeader() throws java.io.IOException
Reads the image header.- Returns:
- DOCUMENT ME!
- Throws:
java.io.IOException
- DOCUMENT ME!
-
writeAVITriplet
private void writeAVITriplet(int timeSlice, int slice, ModelLUT LUTb, int red, int green, int blue, float opacityPrime, float alphaBlend, java.util.BitSet paintBitmap) throws java.io.IOException
Writes the AVI BGR triplet.- Parameters:
timeSlice
- t (time) slice to showslice
- z slice to showLUTb
- DOCUMENT ME!red
- DOCUMENT ME!green
- DOCUMENT ME!blue
- DOCUMENT ME!opacityPrime
- DOCUMENT ME!alphaBlend
- DOCUMENT ME!paintBitmap
- DOCUMENT ME!- Throws:
java.io.IOException
- DOCUMENT ME!
-
writeAVITripletC
private void writeAVITripletC(int timeSlice, int slice, ModelRGB RGBTA, ModelRGB RGBTB, int red, int green, int blue, float opacityPrime, float alphaBlend, java.util.BitSet paintBitmap) throws java.io.IOException
Write BGR AVI triplet for color image.- Parameters:
timeSlice
- t (time) slice to showslice
- z slice to showRGBTA
- DOCUMENT ME!RGBTB
- DOCUMENT ME!red
- DOCUMENT ME!green
- DOCUMENT ME!blue
- DOCUMENT ME!opacityPrime
- DOCUMENT ME!alphaBlend
- DOCUMENT ME!paintBitmap
- DOCUMENT ME!- Throws:
java.io.IOException
- DOCUMENT ME!
-
writeAVITripletCFrames
private void writeAVITripletCFrames() throws java.io.IOException
Write BGR AVI triplet for color image. Since this is a frame captured on screen, this method is much simpler.- Throws:
java.io.IOException
- DOCUMENT ME!
-
writeidx1CHUNK
private void writeidx1CHUNK() throws java.io.IOException
DOCUMENT ME!- Throws:
java.io.IOException
- DOCUMENT ME!
-
writeRLE8
private void writeRLE8(int timeSlice, int slice, byte[] pixStore, byte[] lastStore, byte[] encodeStore) throws java.io.IOException
Writes the RLE8 encoded LUT index.- Parameters:
timeSlice
- t (time) slice to showslice
- z slice to showpixStore
- DOCUMENT ME!lastStore
- DOCUMENT ME!encodeStore
- DOCUMENT ME!- Throws:
java.io.IOException
- DOCUMENT ME!
-
readWriteImage
public boolean readWriteImage() throws java.io.IOException
- Throws:
java.io.IOException
-
writeIntW
public final void writeIntW(int data, boolean bigEndian) throws java.io.IOException
Writes an int as four bytes to a file.- Parameters:
data
- Data to be written to file.bigEndian
-true
indicates big endian byte order,false
indicates little endian.- Throws:
java.io.IOException
- if there is an error writing the file
-
writeShortW
public final void writeShortW(short data, boolean bigEndian) throws java.io.IOException
Writes a short as two bytes to a file.- Parameters:
data
- Data to be written to file.bigEndian
-true
indicates big endian byte order,false
indicates little endian.- Throws:
java.io.IOException
- if there is an error writing the file
-
-