Changeset 4000


Ignore:
Timestamp:
05/05/08 12:41:33 (12 years ago)
Author:
curtis
Message:

Speed up SDT reading.

File:
1 edited

Legend:

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

    r3867 r4000  
    132132    FormatTools.checkBufferSize(this, buf.length, w, h); 
    133133 
    134     if (intensity) { 
    135       in.seek(off + 2 * core.sizeX[series] * core.sizeY[series] * 
    136         timeBins * no); 
    137       byte[] b = 
    138         new byte[timeBins * 2 * core.sizeX[series] * core.sizeY[series]]; 
    139       in.read(b); 
    140       int offset = y * core.sizeX[series] * timeBins * 2; 
    141       for (int row=0; row<h; row++) { 
    142         offset += x * timeBins * 2; 
    143         for (int col=0; col<w; col++) { 
    144           // read all lifetime bins at this pixel for this channel 
    145  
    146           // combine lifetime bins into intensity value 
     134    int sizeX = core.sizeX[series]; 
     135    int sizeY = core.sizeY[series]; 
     136    int bpp = FormatTools.getBytesPerPixel(core.pixelType[series]); 
     137    boolean little = core.littleEndian[series]; 
     138 
     139    boolean direct = !intensity && x == 0 && y == 0 && w == sizeX && h == sizeY; 
     140    byte[] b = direct ? buf : new byte[sizeY * sizeX * timeBins * bpp]; 
     141    in.seek(off + no * b.length); 
     142    in.readFully(b); 
     143    if (direct) return buf; // no cropping required 
     144 
     145    int scan = intensity ? bpp : timeBins * bpp; 
     146 
     147    for (int row=0; row<h; row++) { 
     148      int yi = (y + row) * sizeX * timeBins * bpp; 
     149      int ri = row * w * scan; 
     150      for (int col=0; col<w; col++) { 
     151        int xi = yi + (x + col) * timeBins * bpp; 
     152        int ci = ri + col * scan; 
     153        if (intensity) { 
     154          // combine all lifetime bins into single intensity value 
    147155          short sum = 0; 
    148156          for (int t=0; t<timeBins; t++) { 
    149             sum += DataTools.bytesToShort(b, offset, true); 
    150             offset += 2; 
     157            sum += DataTools.bytesToShort(b, xi + t * bpp, little); 
    151158          } 
    152           int ndx = 2 * (w * row + col); 
    153           DataTools.unpackShort(sum, buf, ndx, core.littleEndian[0]); 
     159          DataTools.unpackShort(sum, buf, ci, little); 
    154160        } 
    155         offset += timeBins * 2 * (core.sizeX[series] - w - x); 
    156       } 
    157     } 
    158     else { 
    159       in.seek(off + 2 * core.sizeX[series]*core.sizeY[series] * timeBins * no); 
    160       in.skipBytes(y * core.sizeX[series] * timeBins * 2); 
    161       for (int row=0; row<h; row++) { 
    162         in.skipBytes(x * timeBins * 2); 
    163         for (int col=0; col<w; col++) { 
    164           for (int t=0; t<timeBins; t++) { 
    165             int ndx = 2 * (timeBins * w * row + timeBins * col + t); 
    166             in.readFully(buf, ndx, 2); 
    167           } 
     161        else { 
     162          // each lifetime bin is a separate interleaved "channel" 
     163          System.arraycopy(b, xi, buf, ci, scan); 
    168164        } 
    169         in.skipBytes(timeBins * 2 * (core.sizeX[series] - w - x)); 
    170165      } 
    171166    } 
Note: See TracChangeset for help on using the changeset viewer.