Changeset 3220


Ignore:
Timestamp:
10/02/07 13:03:30 (12 years ago)
Author:
melissa
Message:

Added support for MS Video 1 codec.

Location:
trunk/loci/formats
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/in/AVIReader.java

    r3197 r3220  
    2929import loci.formats.*; 
    3030import loci.formats.codec.BitBuffer; 
    31 import loci.formats.codec.MSRLECodec; 
     31import loci.formats.codec.*; 
    3232 
    3333/** 
    34  * AVIReader is the file format reader for uncompressed AVI files. 
     34 * AVIReader is the file format reader for AVI files. 
    3535 * 
    3636 * Much of this code was adapted from Wayne Rasband's AVI Movie Reader 
     
    4343public class AVIReader extends FormatReader { 
    4444 
     45  // -- Constants -- 
     46 
     47  /** Supported compression types. */ 
     48  private static final int MSRLE = 1; 
     49  private static final int MS_VIDEO = 1296126531; 
     50 
    4551  // -- Fields -- 
    4652 
     
    6268  private short bmpBitsPerPixel; 
    6369  private byte[][] lut = null; 
    64   private boolean isRLE = false; 
    6570 
    6671  private byte[] lastImage; 
     
    102107    in.seek(fileOff); 
    103108 
    104     if (isRLE) { 
    105       byte[] b = new byte[(int) ((Long) lengths.get(no)).longValue()]; 
    106       in.read(b); 
    107  
    108       Object[] options = new Object[2]; 
    109       options[1] = lastImage; 
    110       options[0] = new int[] {core.sizeX[0], core.sizeY[0]}; 
    111  
    112       MSRLECodec codec = new MSRLECodec(); 
    113       buf = codec.decompress(b, options); 
    114       lastImage = buf; 
    115       if (no == core.imageCount[0] - 1) lastImage = null; 
    116       return buf; 
    117     } 
     109    if (bmpCompression != 0) return uncompress(no, buf); 
    118110 
    119111    if (bmpBitsPerPixel < 8) { 
     
    321313                } 
    322314 
    323                 if (bmpCompression == 1) { 
    324                   // MS RLE compression scheme 
    325                   isRLE = true; 
    326                 } 
    327                 else if (bmpCompression != 0) { 
     315                if (bmpCompression != MSRLE && bmpCompression != 0 && 
     316                  bmpCompression != MS_VIDEO) 
     317                { 
    328318                  throw new FormatException("Unsupported compression type " + 
    329319                    bmpCompression); 
     
    448438    core.imageCount[0] = offsets.size(); 
    449439 
    450     core.rgb[0] = bmpBitsPerPixel > 8 || isRLE; 
     440    core.rgb[0] = bmpBitsPerPixel > 8 || (bmpCompression != 0); 
    451441    core.sizeZ[0] = 1; 
    452442    core.sizeC[0] = core.rgb[0] ? 3 : 1; 
     
    455445    core.littleEndian[0] = true; 
    456446    core.interleaved[0] = bmpBitsPerPixel != 16; 
    457     core.indexed[0] = isRLE; 
     447    core.indexed[0] = bmpBitsPerPixel == 8 && bmpCompression != 0; 
    458448    core.falseColor[0] = false; 
    459449    core.metadataComplete[0] = true; 
     
    468458    } 
    469459 
     460    if (bmpCompression != 0) core.pixelType[0] = FormatTools.UINT8; 
     461 
    470462    MetadataStore store = getMetadataStore(); 
    471463 
     
    481473  } 
    482474 
     475  // -- Helper methods -- 
     476 
     477  private byte[] uncompress(int no, byte[] buf) 
     478    throws FormatException, IOException 
     479  { 
     480    byte[] b = new byte[(int) ((Long) lengths.get(no)).longValue()]; 
     481    in.read(b); 
     482    if (bmpCompression == MSRLE) { 
     483      Object[] options = new Object[2]; 
     484      options[1] = lastImage; 
     485      options[0] = new int[] {core.sizeX[0], core.sizeY[0]}; 
     486      MSRLECodec codec = new MSRLECodec(); 
     487      buf = codec.decompress(b, options); 
     488      lastImage = buf; 
     489      if (no == core.imageCount[0] - 1) lastImage = null; 
     490      return buf; 
     491    } 
     492    else if (bmpCompression == MS_VIDEO) { 
     493      Object[] options = new Object[4]; 
     494      options[0] = new Integer(bmpBitsPerPixel); 
     495      options[1] = new Integer(core.sizeX[0]); 
     496      options[2] = new Integer(core.sizeY[0]); 
     497      options[3] = lastImage; 
     498 
     499      MSVideoCodec codec = new MSVideoCodec(); 
     500      buf = codec.decompress(b, options); 
     501      lastImage = buf; 
     502      if (no == core.imageCount[0] - 1) lastImage = null; 
     503      return buf; 
     504    } 
     505    throw new FormatException("Unsupported compression : " + bmpCompression); 
     506  } 
     507 
    483508} 
Note: See TracChangeset for help on using the changeset viewer.