Package gov.nih.mipav.model.file
Class FileAvi
java.lang.Object
gov.nih.mipav.model.file.FileBase
gov.nih.mipav.model.file.FileAvi
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
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanDOCUMENT ME!private booleanglobals needed for read - set in readHeader, used in readImage.private shortDOCUMENT ME!private intDOCUMENT ME!private byte[]DOCUMENT ME!private floatprivate int0 for RGB 24 bit per pixel uncompressed 1 for RLE 8 bit per pixel compressed 1296126531 for Microsoft video 1 compression.private floatDOCUMENT ME!private intDOCUMENT ME!private byte[]globals needed for write.private int[]DOCUMENT ME!private booleantrue for big-endian and false for little-endian.private FileDOCUMENT ME!private StringDOCUMENT ME!private FileInfoAviDOCUMENT ME!private StringDOCUMENT ME!private Fileprivate intprivate intprivate intDOCUMENT ME!private longDOCUMENT ME!private ModelImageDOCUMENT ME!private ModelImageDOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private floatDOCUMENT ME!private longDOCUMENT ME!private intSize of the index block in bytes.private booleanfor saving within scripts.private intDOCUMENT ME!private intDOCUMENT ME!private ModelLUTDOCUMENT ME!private byte[]DOCUMENT ME!private int[]DOCUMENT ME!private intDOCUMENT ME!private longDOCUMENT ME!private longDOCUMENT ME!private int2 for .mov, 3 for mjpeg, 4 for mp4v2.private Stringprivate ProgressBarInterfaceDOCUMENT ME!private RandomAccessFileprivate intprivate booleanDOCUMENT ME!private floatDOCUMENT ME!private long[]DOCUMENT ME!private longDOCUMENT ME!private longDOCUMENT ME!private longDOCUMENT ME!private intprivate floatprivate intDOCUMENT ME!private intDOCUMENT ME!private intDOCUMENT ME!private intThese are used for writing the AVI frame by frame from the surface renderer.private ViewUserInterfaceDOCUMENT ME!private booleanDOCUMENT ME!private intDOCUMENT ME!private booleanDOCUMENT ME!private intDOCUMENT ME!private intDOCUMENT ME!private intDOCUMENT ME!private intDOCUMENT 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()DOCUMENT ME!private byte[]Creates a LUT to write.voidfinalize()Prepares this class for cleanup.Returns fileDir.Returns fileName.booleanintReturns LUT if defined.booleanintgetRate()intgetScale()intReads the image header.readImage(boolean one) Reads the AVI file header and data.booleanvoidsetAVIWrite(ModelImage _imageA, int microSecPerFrame, int _totalDataFrames, int _totalBlankFrames) This method sets up for an AVI image write.voidsetCaptureTime(float captureTime) voidsetCompressionQuality(float quality) DOCUMENT ME!voidsetIsScript(boolean isScript) DOCUMENT ME!voidsetMicroSecPerFrame(int microSec) DOCUMENT ME!voidsetOutputFileName(String outputFileName) voidDOCUMENT ME!voidsetReadQT(boolean readQT) DOCUMENT ME!voidsetSkipTime(float skipTime) voidsetWriteQT(boolean writeQuickTime) DOCUMENT ME!private voidwriteAVITriplet(int timeSlice, int slice, ModelLUT LUTb, int red, int green, int blue, float opacityPrime, float alphaBlend, BitSet paintBitmap) Writes the AVI BGR triplet.private voidwriteAVITripletC(int timeSlice, int slice, ModelRGB RGBTA, ModelRGB RGBTB, int red, int green, int blue, float opacityPrime, float alphaBlend, BitSet paintBitmap) Write BGR AVI triplet for color image.private voidWrite BGR AVI triplet for color image.voidDOCUMENT ME!voidwriteDataFrame(ModelImage _imageA) DOCUMENT ME!private voidDOCUMENT ME!booleanwriteImage(ModelImage _imageA, ModelImage _imageB, ModelLUT _LUTa, ModelLUT LUTb, ModelRGB RGBTA, ModelRGB RGBTB, int red, int green, int blue, float OPACITY, float alphaBlend, BitSet paintBitmap, int compression) This method writes an AVI image file.final voidwriteIntW(int data, boolean bigEndian) Writes an int as four bytes to a file.private voidwriteRLE8(int timeSlice, int slice, byte[] pixStore, byte[] lastStore, byte[] encodeStore) Writes the RLE8 encoded LUT index.final voidwriteShortW(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 Details
-
AVIF_ISINTERLEAVED
private boolean AVIF_ISINTERLEAVEDDOCUMENT ME! -
AVIF_MUSTUSEINDEX
private boolean AVIF_MUSTUSEINDEXglobals needed for read - set in readHeader, used in readImage. -
AVIF_HASINDEX
private boolean AVIF_HASINDEX -
bitCount
private short bitCountDOCUMENT ME! -
blankFramesSent
private int blankFramesSentDOCUMENT ME! -
bufferWrite
private byte[] bufferWriteDOCUMENT ME! -
compression
private int compression0 for RGB 24 bit per pixel uncompressed 1 for RLE 8 bit per pixel compressed 1296126531 for Microsoft video 1 compression. -
compressionQuality
private float compressionQualityDOCUMENT ME! -
dataFramesSent
private int dataFramesSentDOCUMENT ME! -
dataSignature
private byte[] dataSignatureglobals needed for write. -
dcLength
private int[] dcLengthDOCUMENT ME! -
endianess
private boolean endianesstrue for big-endian and false for little-endian. -
file
DOCUMENT ME! -
fileDir
DOCUMENT ME! -
fileInfo
DOCUMENT ME! -
fileName
DOCUMENT ME! -
height
private int heightDOCUMENT ME! -
idx1Position
private long idx1PositionDOCUMENT ME! -
imageA
DOCUMENT ME! -
imageB
DOCUMENT ME! -
imageBufferA
private float[] imageBufferADOCUMENT ME! -
imageBufferB
private float[] imageBufferBDOCUMENT ME! -
imageMinA
private float imageMinADOCUMENT ME! -
indexPointer
private long indexPointerDOCUMENT ME! -
indexSize
private int indexSizeSize of the index block in bytes. -
isScript
private boolean isScriptfor saving within scripts. -
LIST2Size
private int LIST2SizeDOCUMENT ME! -
LIST2subchunkSize
private int LIST2subchunkSizeDOCUMENT ME! -
LUTa
DOCUMENT ME! -
lutBuffer
private byte[] lutBufferDOCUMENT ME! -
lutBufferRemapped
private int[] lutBufferRemappedDOCUMENT ME! -
microSecPerFrame
private int microSecPerFrameDOCUMENT ME! -
scale
private int scale -
rate
private int rate -
moviPosition
private long moviPositionDOCUMENT ME! -
moviSubchunkPosition
private long moviSubchunkPositionDOCUMENT ME! -
newCompressionType
private int newCompressionType2 for .mov, 3 for mjpeg, 4 for mp4v2. -
progressBar
DOCUMENT ME! -
readQT
private boolean readQTDOCUMENT ME! -
remapConstA
private float remapConstADOCUMENT ME! -
savedbLength
private long[] savedbLengthDOCUMENT ME! -
saveFileSize
private long saveFileSizeDOCUMENT ME! -
saveLIST2Size
private long saveLIST2SizeDOCUMENT ME! -
savemovi
private long savemoviDOCUMENT ME! -
streams
private int streamsDOCUMENT ME! -
totalBlankFrames
private int totalBlankFramesDOCUMENT ME! -
totalDataFrames
private int totalDataFramesThese are used for writing the AVI frame by frame from the surface renderer. -
UI
DOCUMENT ME! -
useNewCompression
private boolean useNewCompressionDOCUMENT ME! -
width
private int widthDOCUMENT ME! -
writeQT
private boolean writeQTDOCUMENT ME! -
xDim
private int xDimDOCUMENT ME! -
yDim
private int yDimDOCUMENT ME! -
zDim
private int zDimDOCUMENT ME! -
tDim
private int tDimDOCUMENT ME! -
xPad
private int xPadDOCUMENT ME! -
outputFileName
-
captureTime
private float captureTime -
skipTime
private float skipTime -
fileW
-
raFileW
-
framesToCapture
private int framesToCapture -
framesToSkip
private int framesToSkip
-
-
Constructor Details
-
FileAvi
Avi reader/writer constructor.- Parameters:
fileName- File name.fileDir- File directory.- Throws:
IOException- if there is an error making the file
-
-
Method Details
-
setCaptureTime
public void setCaptureTime(float captureTime) -
setSkipTime
public void setSkipTime(float skipTime) -
setOutputFileName
-
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
Returns fileDir.- Returns:
- fileDir
-
getFileName
Returns fileName.- Returns:
- filename
-
getFileInfo
-
getModelLUT
Returns LUT if defined.- Returns:
- The LUT if defined, otherwise null.
-
readImage
Reads the AVI file header and data.- Parameters:
one- if true only reads one slice per file- Returns:
- An ARGB image
- Throws:
IOException- if there is an error reading the file
-
setAVIWrite
public void setAVIWrite(ModelImage _imageA, int microSecPerFrame, int _totalDataFrames, int _totalBlankFrames) throws 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:
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
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
DOCUMENT ME!- Throws:
IOException- DOCUMENT ME!
-
writeDataFrame
DOCUMENT ME!- Parameters:
_imageA- DOCUMENT ME!- Throws:
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, BitSet paintBitmap, int compression) throws 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:
IOException- if there is an error writing the file.
-
createLUT
private byte[] createLUT()Creates a LUT to write.- Returns:
- DOCUMENT ME!
-
readHeader
Reads the image header.- Returns:
- DOCUMENT ME!
- Throws:
IOException- DOCUMENT ME!
-
writeAVITriplet
private void writeAVITriplet(int timeSlice, int slice, ModelLUT LUTb, int red, int green, int blue, float opacityPrime, float alphaBlend, BitSet paintBitmap) throws 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:
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, BitSet paintBitmap) throws 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:
IOException- DOCUMENT ME!
-
writeAVITripletCFrames
Write BGR AVI triplet for color image. Since this is a frame captured on screen, this method is much simpler.- Throws:
IOException- DOCUMENT ME!
-
writeidx1CHUNK
DOCUMENT ME!- Throws:
IOException- DOCUMENT ME!
-
writeRLE8
private void writeRLE8(int timeSlice, int slice, byte[] pixStore, byte[] lastStore, byte[] encodeStore) throws 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:
IOException- DOCUMENT ME!
-
readWriteImage
- Throws:
IOException
-
writeIntW
Writes an int as four bytes to a file.- Parameters:
data- Data to be written to file.bigEndian-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeShortW
Writes a short as two bytes to a file.- Parameters:
data- Data to be written to file.bigEndian-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-