Changeset 3456


Ignore:
Timestamp:
12/10/07 13:08:45 (12 years ago)
Author:
melissa
Message:

Added convenience method to TiffTools for retrieving the image description from an IFD.

Location:
trunk
Files:
10 edited

Legend:

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

    r3442 r3456  
    861861  } 
    862862 
    863   /** Convenience method for obtaining a file's first ImageDescription. */ 
    864   public static String getComment(String id) 
    865     throws FormatException, IOException 
    866   { 
    867     // read first IFD 
    868     RandomAccessStream in = new RandomAccessStream(id); 
    869     Hashtable ifd = TiffTools.getFirstIFD(in); 
    870     in.close(); 
     863 
     864  /** Convenience method for obtaining the ImageDescription from an IFD. */ 
     865  public static String getComment(Hashtable ifd) { 
    871866    if (ifd == null) return null; 
    872867 
     
    887882    } 
    888883    return comment; 
     884  } 
     885 
     886  /** Convenience method for obtaining a file's first ImageDescription. */ 
     887  public static String getComment(String id) 
     888    throws FormatException, IOException 
     889  { 
     890    // read first IFD 
     891    RandomAccessStream in = new RandomAccessStream(id); 
     892    Hashtable ifd = TiffTools.getFirstIFD(in); 
     893    in.close(); 
     894    return getComment(ifd); 
    889895  } 
    890896 
  • trunk/loci/formats/in/BaseTiffReader.java

    r3428 r3456  
    509509 
    510510    // TIFF comment 
    511     String comment = null; 
    512     Object o = TiffTools.getIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION); 
    513     if (o instanceof String) comment = (String) o; 
    514     else if (o instanceof String[]) { 
    515       String[] s = (String[]) o; 
    516       if (s.length > 0) comment = s[0]; 
    517     } 
    518     else if (o != null) comment = o.toString(); 
     511    String comment = TiffTools.getComment(ifd); 
    519512    if (comment != null) { 
    520513      // sanitize comment 
  • trunk/loci/formats/in/FlexReader.java

    r3354 r3456  
    146146 
    147147    // parse factors from XML 
    148     String xml = (String) TiffTools.getIFDValue(ifds[0], 
    149       FLEX, true, String.class); 
     148    String xml = TiffTools.getComment(ifds[0]); 
    150149 
    151150    // HACK - workaround for Windows and Mac OS X bug where 
  • trunk/loci/formats/in/ImprovisionTiffReader.java

    r3425 r3456  
    130130 
    131131    for (int i=0; i<ifds.length; i++) { 
    132       comment = (String) TiffTools.getIFDValue(ifds[i], 
    133         TiffTools.IMAGE_DESCRIPTION); 
     132      comment = TiffTools.getComment(ifds[i]); 
    134133      comment = comment.replaceAll("\r\n", "\n"); 
    135134      comment = comment.replaceAll("\r", "\n"); 
  • trunk/loci/formats/in/LeicaReader.java

    r3392 r3456  
    262262      ifds = TiffTools.getIFDs(in); 
    263263      if (ifds == null) throw new FormatException("No IFDs found"); 
    264       String descr = (String) TiffTools.getIFDValue(ifds[0], 
    265         TiffTools.IMAGE_DESCRIPTION); 
     264      String descr = TiffTools.getComment(ifds[0]); 
    266265 
    267266      int ndx = descr.indexOf("Series Name"); 
  • trunk/loci/formats/in/OMETiffReader.java

    r3454 r3456  
    8080 
    8181    OMETiffHandler handler = new OMETiffHandler(); 
    82     String comment = 
    83       (String) TiffTools.getIFDValue(ifds[0], TiffTools.IMAGE_DESCRIPTION); 
     82    String comment = TiffTools.getComment(ifds[0]); 
    8483 
    8584    currentSeries = -1; 
     
    110109    String s = null; 
    111110    if (ifds.length > 1) { 
    112       s = (String) TiffTools.getIFDValue(ifds[1], TiffTools.IMAGE_DESCRIPTION); 
     111      s = TiffTools.getComment(ifds[1]); 
    113112    } 
    114113    isWiscScan = s != null && s.indexOf("ome.xsd") != -1; 
     
    200199 
    201200      usedIFDs[i] = TiffTools.getIFDs(new RandomAccessStream(usedFiles[i])); 
    202       String c = (String) 
    203         TiffTools.getIFDValue(usedIFDs[i][0], TiffTools.IMAGE_DESCRIPTION); 
     201      String c = TiffTools.getComment(usedIFDs[i][0]); 
    204202      try { 
    205203        SAXParser parser = SAX_FACTORY.newSAXParser(); 
     
    243241  /* @see BaseTiffReader#initMetadataStore() */ 
    244242  protected void initMetadataStore() { 
    245     Object c = TiffTools.getIFDValue(ifds[0], TiffTools.IMAGE_DESCRIPTION); 
    246     String comment = null; 
    247     if (c instanceof String) comment = (String) c; 
    248     else if (c instanceof String[]) comment = ((String[]) c)[0]; 
     243    String comment = TiffTools.getComment(ifds[0]); 
    249244    metadata.remove("Comment"); 
    250245    MetadataStore store = getMetadataStore(); 
  • trunk/loci/formats/in/SEQReader.java

    r3197 r3456  
    9898 
    9999    // parse the description to get channels, slices and times where applicable 
    100     String descr = (String) TiffTools.getIFDValue(ifds[0], 
    101       TiffTools.IMAGE_DESCRIPTION); 
     100    String descr = TiffTools.getComment(ifds[0]); 
    102101    metadata.remove("Comment"); 
    103102    if (descr != null) { 
  • trunk/loci/formats/in/TCSReader.java

    r3443 r3456  
    387387      // cut up comment 
    388388 
    389       String comment = 
    390         (String) TiffTools.getIFDValue(ifds[0], TiffTools.IMAGE_DESCRIPTION); 
     389      String comment = TiffTools.getComment(ifds[0]); 
    391390      if (comment != null && comment.startsWith("[")) { 
    392391        StringTokenizer st = new StringTokenizer(comment, "\n"); 
  • trunk/utils/EditTiff.java

    r3166 r3456  
    2626      if (ifd == null) System.out.println("Warning: first IFD is null!"); 
    2727      // extract TIFF comment from IFD 
    28       String ome = (String) 
    29         TiffTools.getIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION); 
     28      String ome = TiffTools.getComment(ifd); 
    3029      System.out.println("[done]"); 
    3130      // display comment, and prompt for changes 
  • trunk/utils/SewTiffs.java

    r2765 r3456  
    5757 
    5858        // preserve TIFF comment 
    59         Object descObj = 
    60           TiffTools.getIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION); 
    61         String desc = null; 
    62         if (descObj instanceof String) desc = (String) descObj; 
    63         else if (descObj instanceof String[]) desc = ((String[]) descObj)[0]; 
     59        String desc = TiffTools.getComment(ifd); 
    6460 
    6561        if (desc != null) { 
Note: See TracChangeset for help on using the changeset viewer.