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 Details

    • 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 File file
      DOCUMENT ME!
    • fileDir

      private String fileDir
      DOCUMENT ME!
    • fileInfo

      private FileInfoAvi fileInfo
      DOCUMENT ME!
    • fileName

      private 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 String outputFileName
    • captureTime

      private float captureTime
    • skipTime

      private float skipTime
    • fileW

      private File fileW
    • raFileW

      private RandomAccessFile raFileW
    • framesToCapture

      private int framesToCapture
    • framesToSkip

      private int framesToSkip
  • Constructor Details

    • FileAvi

      public FileAvi(String fileName, String fileDir) throws IOException
      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

      public void setOutputFileName(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.
      Overrides:
      finalize in class FileBase
    • getFileDir

      public String getFileDir()
      Returns fileDir.
      Returns:
      fileDir
    • getFileName

      public 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 IOException
      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

      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 IOException
      DOCUMENT ME!
      Throws:
      IOException - DOCUMENT ME!
    • writeDataFrame

      public void writeDataFrame(ModelImage _imageA) throws IOException
      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

      public int readHeader() throws IOException
      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 show
      slice - z slice to show
      LUTb - 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 show
      slice - z slice to show
      RGBTA - 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

      private void writeAVITripletCFrames() throws IOException
      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

      private void writeidx1CHUNK() throws IOException
      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 show
      slice - z slice to show
      pixStore - DOCUMENT ME!
      lastStore - DOCUMENT ME!
      encodeStore - DOCUMENT ME!
      Throws:
      IOException - DOCUMENT ME!
    • readWriteImage

      public boolean readWriteImage() throws IOException
      Throws:
      IOException
    • writeIntW

      public final void writeIntW(int data, boolean bigEndian) throws 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:
      IOException - if there is an error writing the file
    • writeShortW

      public final void writeShortW(short data, boolean bigEndian) throws 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:
      IOException - if there is an error writing the file