Changeset 2994 for trunk


Ignore:
Timestamp:
07/17/07 12:25:19 (13 years ago)
Author:
melissa
Message:

Added support for 16-bit and < 8-bit data.

File:
1 edited

Legend:

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

    r2976 r2994  
    2929import java.util.Vector; 
    3030import loci.formats.*; 
     31import loci.formats.codec.BitBuffer; 
    3132import loci.formats.codec.MSRLECodec; 
    3233 
     
    9798  public byte[] openBytes(int no) throws FormatException, IOException { 
    9899    FormatTools.assertId(currentId, true, 1); 
    99     byte[] buf = 
    100       new byte[core.sizeY[0] * bmpScanLineSize * (bmpBitsPerPixel / 8)]; 
     100    int bytes = FormatTools.getBytesPerPixel(core.pixelType[0]); 
     101    double p = ((double) bmpScanLineSize) / bmpBitsPerPixel; 
     102    int effectiveWidth = (int) (bmpScanLineSize / p); 
     103    if (effectiveWidth == 0 || effectiveWidth < core.sizeX[0]) { 
     104      effectiveWidth = core.sizeX[0]; 
     105    } 
     106 
     107    byte[] buf =  
     108      new byte[core.sizeY[0] * effectiveWidth * bytes * core.sizeC[0]]; 
    101109    return openBytes(no, buf); 
    102110  } 
     
    111119    } 
    112120 
    113     if (buf.length < core.sizeY[0]*bmpScanLineSize*(bmpBitsPerPixel / 8)) { 
     121    int bytes = FormatTools.getBytesPerPixel(core.pixelType[0]); 
     122    double p = ((double) bmpScanLineSize) / bmpBitsPerPixel; 
     123    int effectiveWidth = (int) (bmpScanLineSize / p); 
     124    if (effectiveWidth == 0 || effectiveWidth < core.sizeX[0]) { 
     125      effectiveWidth = core.sizeX[0]; 
     126    } 
     127 
     128    if (buf.length < core.sizeY[0]*effectiveWidth*bytes*core.sizeC[0]) { 
    114129      throw new FormatException("Buffer too small."); 
    115130    } 
     
    141156    } 
    142157 
     158    if (bmpBitsPerPixel < 8) { 
     159      int rawSize = bytes * core.sizeY[0] * effectiveWidth * core.sizeC[0]; 
     160      rawSize /= (8 / bmpBitsPerPixel); 
     161 
     162      byte[] b = new byte[rawSize]; 
     163      
     164      int len = rawSize / core.sizeY[0]; 
     165      for (int y=0; y<core.sizeY[0]; y++) { 
     166        in.read(b, (core.sizeY[0] - y - 1) * len, len);  
     167      } 
     168       
     169      BitBuffer bb = new BitBuffer(b); 
     170 
     171      for (int i=0; i<buf.length; i++) { 
     172        buf[i] = (byte) bb.getBits(bmpBitsPerPixel); 
     173      }  
     174 
     175      return buf; 
     176    } 
     177 
    143178    int pad = bmpScanLineSize - core.sizeX[0]*(bmpBitsPerPixel / 8); 
    144179    int scanline = core.sizeX[0] * (bmpBitsPerPixel / 8); 
     
    146181    for (int i=core.sizeY[0] - 1; i>=0; i--) { 
    147182      in.read(buf, i*scanline, scanline); 
    148       if (bmpBitsPerPixel != 8) { 
     183      if (bmpBitsPerPixel == 24) {  
    149184        for (int j=0; j<core.sizeX[0]; j++) { 
    150185          byte r = buf[i*scanline + j*3 + 2]; 
     
    155190      in.skipBytes(pad * (bmpBitsPerPixel / 8)); 
    156191    } 
     192     
     193    if (bmpBitsPerPixel == 16) { 
     194      // channels are separated, need to swap them 
     195      byte[] r = new byte[core.sizeX[0] * core.sizeY[0] * 2]; 
     196      System.arraycopy(buf, 2 * (buf.length / 3), r, 0, r.length); 
     197      System.arraycopy(buf, 0, buf, 2 * (buf.length / 3), r.length); 
     198      System.arraycopy(r, 0, buf, 0, r.length); 
     199    } 
     200     
    157201    return buf; 
    158202  } 
     
    162206    FormatTools.assertId(currentId, true, 1); 
    163207    return ImageTools.makeImage(openBytes(no), 
    164       core.sizeX[0], core.sizeY[0], core.sizeC[0], true); 
     208      core.sizeX[0], core.sizeY[0], core.sizeC[0], !core.interleaved[0],  
     209      FormatTools.getBytesPerPixel(core.pixelType[0]), core.littleEndian[0]); 
    165210  } 
    166211 
     
    200245      in.seek(pos); 
    201246      listString = new String(list); 
     247      if (listString.equals(" JUN")) { 
     248        in.skipBytes(1); 
     249        pos++;  
     250      } 
    202251 
    203252      if (listString.equals("JUNK")) { 
     
    336385                } 
    337386 
    338                 if (!(bmpBitsPerPixel == 8 || bmpBitsPerPixel == 24 || 
     387                if (!(bmpBitsPerPixel == 4 || bmpBitsPerPixel == 8 ||  
     388                  bmpBitsPerPixel == 24 || bmpBitsPerPixel == 16 ||  
    339389                  bmpBitsPerPixel == 32)) 
    340390                { 
     
    461511    core.currentOrder[0] = core.sizeC[0] == 3 ? "XYCTZ" : "XYTCZ"; 
    462512    core.littleEndian[0] = true; 
    463  
    464     if (bmpBitsPerPixel == 8) core.pixelType[0] = FormatTools.UINT8; 
     513    core.interleaved[0] = bmpBitsPerPixel == 16; 
     514 
     515    if (bmpBitsPerPixel <= 8) core.pixelType[0] = FormatTools.UINT8; 
    465516    else if (bmpBitsPerPixel == 16) core.pixelType[0] = FormatTools.UINT16; 
    466517    else if (bmpBitsPerPixel == 32) core.pixelType[0] = FormatTools.UINT32; 
Note: See TracChangeset for help on using the changeset viewer.