Changeset 2707


Ignore:
Timestamp:
04/30/07 14:01:08 (13 years ago)
Author:
curtis
Message:

To handle files with differing numbers of images, check ZCT coordinate bounds
rather than catching FormatExceptions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/FileStitcher.java

    r2706 r2707  
    334334  public BufferedImage openImage(int no) throws FormatException, IOException { 
    335335    FormatTools.assertId(currentId, true, 2); 
    336     try {  
    337       int[] q = computeIndices(no); 
    338       int fno = q[0], ino = q[1]; 
    339       if (ino < readers[fno].getImageCount()) { 
    340         return readers[fno].openImage(ino); 
    341       } 
    342     } 
    343     catch (FormatException e) { 
    344       if (FormatHandler.debug) e.printStackTrace();  
     336    int[] q = computeIndices(no); 
     337    int fno = q[0], ino = q[1]; 
     338    if (ino < readers[fno].getImageCount()) { 
     339      return readers[fno].openImage(ino); 
    345340    } 
    346341 
     
    359354  public byte[] openBytes(int no) throws FormatException, IOException { 
    360355    FormatTools.assertId(currentId, true, 2); 
    361     try {  
    362       int[] q = computeIndices(no); 
    363       int fno = q[0], ino = q[1]; 
    364       if (ino < readers[fno].getImageCount()) { 
    365         return readers[fno].openBytes(ino); 
    366       } 
    367     } 
    368     catch (FormatException e) { 
    369       if (FormatHandler.debug) e.printStackTrace(); 
     356    int[] q = computeIndices(no); 
     357    int fno = q[0], ino = q[1]; 
     358    if (ino < readers[fno].getImageCount()) { 
     359      return readers[fno].openBytes(ino); 
    370360    } 
    371361 
     
    386376  { 
    387377    FormatTools.assertId(currentId, true, 2); 
    388     try {  
    389       int[] q = computeIndices(no); 
    390       int fno = q[0], ino = q[1]; 
     378    int[] q = computeIndices(no); 
     379    int fno = q[0], ino = q[1]; 
     380    if (ino < readers[fno].getImageCount()) { 
    391381      return readers[fno].openBytes(ino, buf); 
    392382    } 
    393     catch (FormatException e) { 
    394       if (FormatHandler.debug) e.printStackTrace(); 
    395     } 
     383 
     384    // return a blank image to cover for the fact that 
     385    // this file does not contain enough image planes 
     386    Arrays.fill(buf, (byte) 0); 
    396387    return buf; 
    397388  } 
     
    402393  { 
    403394    FormatTools.assertId(currentId, true, 2); 
    404     try {  
    405       int[] q = computeIndices(no); 
    406       int fno = q[0], ino = q[1]; 
    407       if (ino < readers[fno].getImageCount()) { 
    408         return readers[fno].openThumbImage(ino); 
    409       } 
    410     } 
    411     catch (FormatException e) { 
    412       if (FormatHandler.debug) e.printStackTrace(); 
     395    int[] q = computeIndices(no); 
     396    int fno = q[0], ino = q[1]; 
     397    if (ino < readers[fno].getImageCount()) { 
     398      return readers[fno].openThumbImage(ino); 
    413399    } 
    414400 
     
    426412  public byte[] openThumbBytes(int no) throws FormatException, IOException { 
    427413    FormatTools.assertId(currentId, true, 2); 
    428     try {  
    429       int[] q = computeIndices(no); 
    430       int fno = q[0], ino = q[1]; 
    431       if (ino < readers[fno].getImageCount()) { 
    432         return readers[fno].openThumbBytes(ino); 
    433       } 
    434     } 
    435     catch (FormatException e) { 
    436       if (FormatHandler.debug) e.printStackTrace(); 
    437     } 
     414    int[] q = computeIndices(no); 
     415    int fno = q[0], ino = q[1]; 
     416    if (ino < readers[fno].getImageCount()) { 
     417      return readers[fno].openThumbBytes(ino); 
     418    } 
     419 
    438420    // return a blank image to cover for the fact that 
    439421    // this file does not contain enough image planes 
     
    930912    readers[fno].setSeries(reader.getSeries()); 
    931913 
    932     int ino = FormatTools.getIndex(readers[fno], posZ[0], posC[0], posT[0]); 
     914    int ino; 
     915    if (posZ[0] < readers[fno].getSizeZ() && 
     916      posC[0] < readers[fno].getSizeC() && posT[0] < readers[fno].getSizeT()) 
     917    { 
     918      ino = FormatTools.getIndex(readers[fno], posZ[0], posC[0], posT[0]); 
     919    } 
     920    else ino = Integer.MAX_VALUE; // coordinates out of range 
    933921 
    934922    return new int[] {fno, ino}; 
Note: See TracChangeset for help on using the changeset viewer.