Changeset 1386


Ignore:
Timestamp:
08/30/06 13:10:20 (14 years ago)
Author:
melissa
Message:
  • added API methods for retrieving thumbnails:
    • BufferedImage openThumbImage(String, int)
    • byte[] openThumbBytes(String, int)
    • int getThumbSizeX(String)
    • int getThumbSizeY(String)
  • fixed a bug in DataTools
  • tweaked Zeiss ZVI readers (adapted from Michel Boudinot's changes)
Location:
trunk/loci
Files:
7 edited

Legend:

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

    r1264 r1386  
    320320    if (bytes.length - off < len) len = bytes.length - off; 
    321321    long total = 0; 
    322     for (int i=0; i<len; i++) { 
    323       total |= (bytes[i] < 0 ? 256L + bytes[i] : 
    324         (long) bytes[i]) << ((little ? i : len - i - 1) * 8); 
     322    for (int i=0, ndx=off; i<len; i++, ndx++) { 
     323      total |= (bytes[ndx] < 0 ? 256L + bytes[ndx] : 
     324        (long) bytes[ndx]) << ((little ? i : len - i - 1) * 8); 
    325325    } 
    326326    return total; 
  • trunk/loci/formats/FormatReader.java

    r1385 r1386  
    4545  protected static final int DEBUG_LEVEL = 1; 
    4646 
     47  /** Default thumbnail width and height. */ 
     48  protected static final int THUMBNAIL_DIMENSION = 128; 
     49 
    4750  // -- Fields -- 
    4851 
     
    100103  public abstract int getSizeT(String id) throws FormatException, IOException; 
    101104 
     105  /** Get the size of the X dimension for the thumbnail. */ 
     106  public int getThumbSizeX(String id) throws FormatException, IOException { 
     107    return THUMBNAIL_DIMENSION; 
     108  } 
     109 
     110  /** Get the size of the Y dimension for the thumbnail. */ 
     111  public int getThumbSizeY(String id) throws FormatException, IOException { 
     112    return THUMBNAIL_DIMENSION; 
     113  } 
     114 
    102115  /** Return true if the data is in little-endian format. */ 
    103116  public abstract boolean isLittleEndian(String id) 
     
    120133  public abstract byte[] openBytes(String id, int no) 
    121134    throws FormatException, IOException; 
     135 
     136  /** Obtains a thumbnail for the specified image from the given file. */ 
     137  public BufferedImage openThumbImage(String id, int no) 
     138    throws FormatException, IOException 
     139  { 
     140    return ImageTools.scale(openImage(id, no),  
     141      getThumbSizeX(id), getThumbSizeY(id));       
     142  } 
     143 
     144  /** 
     145   * Obtains a thumbnail for the specified image from the given file, 
     146   * as a byte array.  We assume that the thumbnail has the same number of 
     147   * channels as the original image.  If there is more than one channel, then 
     148   * the resulting byte array will be of the format "RRR...BBB...GGG...". 
     149   */ 
     150  public byte[] openThumbBytes(String id, int no) 
     151    throws FormatException, IOException 
     152  { 
     153    BufferedImage img = openThumbImage(id, no); 
     154    byte[][] bytes = ImageTools.getBytes(img); 
     155    if (bytes.length == 1) return bytes[0]; 
     156    byte[] rtn = new byte[bytes.length * bytes[0].length]; 
     157    for (int i=0; i<bytes.length; i++) { 
     158      System.arraycopy(bytes[i], 0, rtn, bytes[0].length * i, bytes[i].length); 
     159    } 
     160    return rtn; 
     161  } 
    122162 
    123163  /** Closes the currently open file. */ 
  • trunk/loci/formats/IFormatReader.java

    r1385 r1386  
    2929import java.util.Hashtable; 
    3030 
    31  
    32  
    33  
    3431/** Abstract superclass of all biological file format readers. */ 
    3532public interface IFormatReader extends IFormatHandler { 
     
    6057  int getSizeT(String id) throws FormatException, IOException; 
    6158 
     59  /** Get the size of the X dimension for the thumbnail. */ 
     60  int getThumbSizeX(String id) throws FormatException, IOException; 
     61 
     62  /** Get the size of the Y dimension for the thumbnail. */ 
     63  int getThumbSizeY(String id) throws FormatException, IOException; 
     64   
    6265  /** Return true if the data is in little-endian format. */ 
    6366  boolean isLittleEndian(String id) 
     
    8285 
    8386  /** Obtains a thumbnail for the specified image from the given file. */ 
    84   //BufferedImage openThumbImage(String id, int no) 
    85   //  throws FormatException, IOException; 
     87  BufferedImage openThumbImage(String id, int no) 
     88    throws FormatException, IOException; 
    8689 
    8790  /** 
     
    8992   * as a byte array. 
    9093   */ 
    91   //byte[] openThumbBytes(String id, int no) 
    92   //  throws FormatException, IOException; 
     94  byte[] openThumbBytes(String id, int no) 
     95    throws FormatException, IOException; 
    9396 
    9497  /** Closes the currently open file. */ 
  • trunk/loci/formats/ImageReader.java

    r1385 r1386  
    231231  } 
    232232 
     233  /** Get the size of the X dimension for the thumbnail. */ 
     234  public int getThumbSizeX(String id) throws FormatException, IOException { 
     235    if (!id.equals(currentId)) initFile(id); 
     236    return readers[index].getThumbSizeX(id); 
     237  } 
     238 
     239  /** Get the size of the Y dimension for the thumbnail. */ 
     240  public int getThumbSizeY(String id) throws FormatException, IOException { 
     241    if (!id.equals(currentId)) initFile(id); 
     242    return readers[index].getThumbSizeY(id); 
     243  } 
     244 
    233245  /** Return true if the data is in little-endian format. */ 
    234246  public boolean isLittleEndian(String id) throws FormatException, IOException 
     
    291303    if (!id.equals(currentId)) initFile(id); 
    292304    return readers[index].openImage(id, no); 
     305  } 
     306 
     307  /** Obtains a thumbnail for the specified image from the given file. */ 
     308  public BufferedImage openThumbImage(String id, int no) 
     309    throws FormatException, IOException 
     310  { 
     311    if (!id.equals(currentId)) initFile(id); 
     312    return readers[index].openThumbImage(id, no); 
     313  } 
     314 
     315  /** 
     316   * Obtains a thumbnail for the specified image from the given file, 
     317   * as a byte array.  We assume that the thumbnail has the same number of 
     318   * channels as the original image.  If there is more than one channel, then 
     319   * the resulting byte array will be of the format "RRR...BBB...GGG...". 
     320   */ 
     321  public byte[] openThumbBytes(String id, int no) 
     322    throws FormatException, IOException 
     323  { 
     324    if (!id.equals(currentId)) initFile(id); 
     325    return readers[index].openThumbBytes(id, no); 
    293326  } 
    294327 
  • trunk/loci/formats/in/LegacyZVIReader.java

    r1264 r1386  
    3636 * @author Curtis Rueden ctrueden at wisc.edu 
    3737 * @author Melissa Linkert linkert at cs.wisc.edu 
     38 * @author Michel Boudinot Michel dot boudinot at iaf.cnrs-gif.fr 
    3839 */ 
    3940public class LegacyZVIReader extends FormatReader { 
  • trunk/loci/formats/in/ZeissZVIReader.java

    r1264 r1386  
    3636 * @author Melissa Linkert linkert at cs.wisc.edu 
    3737 * @author Curtis Rueden ctrueden at wisc.edu 
     38 * @author Michel Boudinot Michel dot boudinot at iaf.cnrs-gif.fr 
    3839 */ 
    3940public class ZeissZVIReader extends FormatReader { 
     
    310311  { 
    311312    if (needLegacy) return legacy.openImage(id, no); 
    312     byte[] data = openBytes(id, no); 
    313     int bpp = bitsPerSample / 8; 
    314     if (bpp == 0) bpp = bytesPerPixel; 
    315     if (bpp > 4) bpp /= 3; 
    316     return ImageTools.makeImage(data, width, height, 
    317       (!isRGB(id) || separated) ? 1 : 3, true, bpp, false); 
     313    try { 
     314      byte[] data = openBytes(id, no); 
     315      int bpp = bitsPerSample / 8; 
     316      if (bpp == 0) bpp = bytesPerPixel; 
     317      if (bpp > 4) bpp /= 3; 
     318      return ImageTools.makeImage(data, width, height, 
     319        (!isRGB(id) || separated) ? 1 : 3, true, bpp, false); 
     320    } 
     321    catch (Exception e) { 
     322      needLegacy = true; 
     323    } 
     324    return openImage(id, no); 
    318325  } 
    319326 
     
    737744        try { 
    738745          switch (type) { 
     746            case 0: // VT_EMPTY: nothing 
     747            case 1: // VT_NUL: nothing 
     748              data = null; 
     749              pt += 2; 
     750              break; 
    739751            case 2: // VT_I2: 16 bit integer 
    740752              data = new Integer(DataTools.bytesToInt(tag, pt, 2, true)); 
     
    766778              pt += length; 
    767779              break; 
     780            case 9: // VT_DISPATCH: 16 bytes 
     781              data = new String(tag, pt, 16); 
     782              pt += 16; 
     783              break; 
    768784            case 11: // VT_BOOL: 16 bit integer (true if !0) 
    769               int temp = DataTools.bytesToInt(tag, pt, 4, true); 
     785              int temp = DataTools.bytesToInt(tag, pt, 2, true); 
    770786              data = new Boolean(temp != 0); 
    771               pt += 4; 
     787              pt += 2; 
    772788              break; 
    773789            case 16: // VT_I1: 8 bit integer 
     
    859875            case 267: metadata.put("ImageRelativeTime3", data); break; 
    860876            case 268: metadata.put("ImageRelativeTime4", data); break; 
     877            case 333: metadata.put("RelFocusPosition1", data); break; 
     878            case 334: metadata.put("RelFocusPosition2", data); break; 
     879            case 513: metadata.put("tagID_513", data); break; 
    861880            case 515: metadata.put("ImageWidth", data); break; 
    862881            case 516: metadata.put("ImageHeight", data); break; 
     882            case 517: metadata.put("tagID_517", data); break; 
    863883            //case 518: metadata.put("PixelType", data); break; 
    864884            case 519: metadata.put("NumberOfRawImages", data); break; 
     
    867887            case 530: metadata.put("Document Subtype", data); break; 
    868888            case 531: metadata.put("Acquisition Bit Depth", data); break; 
     889            case 532: metadata.put("Image Memory Usage (RAM)", data); break; 
    869890            case 534: metadata.put("Z-Stack single representative", data); 
    870891                      break; 
     
    883904            case 1003: metadata.put("Source", data); break; 
    884905            case 1004: metadata.put("Message", data); break; 
     906            case 1025: metadata.put("Acquisition Date", data); break; 
    885907            case 1026: metadata.put("8-bit acquisition", data); break; 
    886908            case 1027: metadata.put("Camera Bit Depth", data); break; 
     
    953975            case 2069: metadata.put("Fluorescence Lamp Intensity", data); break; 
    954976            case 2070: metadata.put("LightManagerEnabled", data); break; 
     977            case 2071: metadata.put("tag_ID_2071", data); break; 
    955978            case 2072: metadata.put("Focus Position", data); break; 
    956979            case 2073: metadata.put("Stage Position X", data);break; 
     
    11671190              metadata.put("Fluorescence Attenuator Position", data); 
    11681191              break; 
     1192            case 2261: metadata.put("Objective ID", data); break; 
     1193            case 2262: metadata.put("Reflector ID", data); break; 
    11691194            case 2307: metadata.put("Camera Framestart Left", data); break; 
    11701195            case 2308: metadata.put("Camera Framestart Top", data); break; 
     
    12241249            case 2603: metadata.put("CameraLiveExposureTimeValue", data); break; 
    12251250            case 2604: metadata.put("CameraLiveScalingFactor", data); break; 
     1251            case 2819: metadata.put("Image Index Z", data); break; 
     1252            case 2820: metadata.put("Image Channel Index", data); break; 
     1253            case 2821: metadata.put("Image Index T", data); break; 
    12261254            case 2822: metadata.put("ImageTile Index", data); break; 
    12271255            case 2823: metadata.put("Image acquisition Index", data); break; 
     1256            case 2827: metadata.put("Image IndexS", data); break; 
    12281257            case 2841: metadata.put("Original Stage Position X", data); break; 
    12291258            case 2842: metadata.put("Original Stage Position Y", data); break; 
     
    12541283              metadata.put("Autofocus Current Calibration Item", data); 
    12551284              break; 
     1285            case 20478: metadata.put("tag_ID_20478", data); break; 
    12561286            case 65537: metadata.put("CameraFrameFullWidth", data); break; 
    12571287            case 65538: metadata.put("CameraFrameFullHeight", data); break; 
     
    13621392            case 65639: metadata.put("DeepView EDoF", data); break; 
    13631393            case 65643: metadata.put("DeepView Slider Name", data); break; 
     1394            case 65655: metadata.put("DeepView Slider Name", data); break; 
     1395            case 16777488: metadata.put("Excitation Wavelength", data); break; 
     1396            case 16777489: metadata.put("Emission Wavelength", data); break; 
    13641397          } 
    13651398        } 
     
    14721505    // Stage Label 
    14731506    try { 
    1474       int xPos = Integer.parseInt((String) metadata.get("Stage Position X")); 
    1475       int yPos = Integer.parseInt((String) metadata.get("Stage Position Y")); 
     1507      int xPos = Integer.parseInt(metadata.get("Stage Position X").toString()); 
     1508      int yPos = Integer.parseInt(metadata.get("Stage Position Y").toString()); 
    14761509      store.setStageLabel(null, new Float(xPos), new Float(yPos), null, null); 
    14771510    } 
    14781511    catch (NumberFormatException n) { } 
     1512    catch (NullPointerException npe) { } 
    14791513  } 
    14801514 
  • trunk/loci/plugins/browser/ImagePreview.java

    r1271 r1386  
    6262      ImageReader ir = new ImageReader(); 
    6363      FormatReader fr = (FormatReader) ir.getReader(file.getAbsolutePath()); 
    64       BufferedImage image = fr.openImage(file.getAbsolutePath(),0); 
     64      BufferedImage image = fr.openThumbImage(file.getAbsolutePath(),0); 
    6565 
    66       thumbnail = 
    67         new ImageIcon(image.getScaledInstance(90, -1, Image.SCALE_DEFAULT)); 
     66      thumbnail = new ImageIcon(image); 
    6867    } 
    6968    catch (Exception e) { e.printStackTrace(); } 
Note: See TracChangeset for help on using the changeset viewer.