Changeset 3865


Ignore:
Timestamp:
04/02/08 12:16:06 (12 years ago)
Author:
melissa
Message:

Fixed some endianness and pixel offset calculation problems.

File:
1 edited

Legend:

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

    r3854 r3865  
    2626 
    2727import java.io.*; 
     28import java.util.Arrays; 
    2829import java.util.Vector; 
    2930import loci.formats.*; 
     
    106107    status("Finding offsets to pixel data"); 
    107108 
    108     // Slidebook files appear to be comprised of three types of blocks: 
    109     // variable length pixel data blocks, 512 byte metadata blocks and 
    110     // 128 byte metadata blocks. 
     109    // Slidebook files appear to be comprised of four types of blocks: 
     110    // variable length pixel data blocks, 512 byte metadata blocks, 
     111    // 128 byte metadata blocks, and variable length metadata blocks. 
    111112    // 
    112     // Metadata blocks begin with a 2 byte identifier, e.g. 'i' or 'h'. 
     113    // Fixed-length metadata blocks begin with a 2 byte identifier, 
     114    // e.g. 'i' or 'h'. 
    113115    // Following this are two unknown bytes (usually 256), then a 2 byte 
    114116    // endianness identifier - II or MM, for little or big endian, respectively. 
    115117    // Presumably these blocks contain useful information, but for the most 
    116118    // part we aren't sure what it is or how to extract it. 
     119    // 
     120    // Variable length metadata blocks begin with 0xffff and are 
     121    // (as far as I know) always between two fixed-length metadata blocks. 
     122    // These appear to be a relatively new addition to the format - they are 
     123    // only present in files received on/after March 30, 2008. 
    117124    // 
    118125    // Each pixel data block corresponds to one series. 
     
    146153        in.skipBytes(in.readShort() - 8); 
    147154      } 
     155      else if (checkOne == -1 && checkTwo == -1) { 
     156        boolean foundBlock = false; 
     157        byte[] block = new byte[8192]; 
     158        in.read(block); 
     159        while (!foundBlock) { 
     160          for (int i=0; i<block.length-2; i++) { 
     161            if ((block[i] == 'M' && block[i + 1] == 'M') || 
     162              (block[i] == 'I' && block[i + 1] == 'I')) 
     163            { 
     164              foundBlock = true; 
     165              in.seek(in.getFilePointer() - block.length + i - 2); 
     166              metadataOffsets.add(new Long(in.getFilePointer() - 2)); 
     167              in.skipBytes(in.readShort() - 5); 
     168              break; 
     169            } 
     170          } 
     171          if (!foundBlock) { 
     172            block[0] = block[block.length - 2]; 
     173            block[1] = block[block.length - 1]; 
     174            in.read(block, 2, block.length - 2); 
     175          } 
     176        } 
     177 
     178      } 
    148179      else { 
    149180        String s = null; 
     
    252283 
    253284    if (pixelOffsets.size() > 1) { 
     285      boolean little = core.littleEndian[0]; 
    254286      core = new CoreMetadata(pixelOffsets.size()); 
     287      Arrays.fill(core.littleEndian, little); 
    255288    } 
    256289 
     
    342375      core.imageCount[i] = core.sizeZ[i] * core.sizeT[i] * core.sizeC[i]; 
    343376      core.sizeX[i] = (int) (pixels / (core.imageCount[i] * core.sizeY[i])); 
     377      if ((core.sizeX[i] % 2) == 1) core.sizeX[i]--; 
    344378      core.pixelType[i] = FormatTools.UINT16; 
    345379      core.currentOrder[i] = "XYZTC"; 
    346       core.littleEndian[i] = true; 
    347380      core.indexed[i] = false; 
    348381      core.falseColor[i] = false; 
Note: See TracChangeset for help on using the changeset viewer.