Changeset 5668


Ignore:
Timestamp:
11/04/09 12:42:23 (10 years ago)
Author:
curtis
Message:

Add IFD.getIFDTextValue convenience method; clean up a few IFD calls.

Location:
trunk/components/bio-formats/src/loci/formats
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/in/BaseTiffReader.java

    r5624 r5668  
    446446 
    447447    // populate Experimenter 
    448     String artist = null; 
    449     Object o = firstIFD.getIFDValue(IFD.ARTIST); 
    450     if (o instanceof String) artist = (String) o; 
    451     else if (o instanceof String[]) { 
    452       String[] s = (String[]) o; 
    453       for (int i=0; i<s.length; i++) { 
    454         artist += s[i]; 
    455         if (i < s.length - 1) artist += "\n"; 
    456       } 
    457     } 
     448    String artist = firstIFD.getIFDTextValue(IFD.ARTIST); 
    458449    if (artist != null) { 
    459450      String firstName = null, lastName = null; 
     
    464455        lastName = artist.substring(ndx + 1); 
    465456      } 
    466       String email = (String) firstIFD.getIFDValue(IFD.HOST_COMPUTER); 
     457      String email = firstIFD.getIFDTextValue(IFD.HOST_COMPUTER); 
    467458      store.setExperimenterFirstName(firstName, 0); 
    468459      store.setExperimenterLastName(lastName, 0); 
     
    532523    } 
    533524    // populate Instrument 
    534     //String make = ifd.getIFDStringValue(IFD.MAKE, false); 
    535     //String model = ifd.getIFDStringValue(IFD.MODEL, false); 
     525    //String make = ifd.getIFDTextValue(IFD.MAKE); 
     526    //String model = ifd.getIFDTextValue(IFD.MODEL); 
    536527    //store.setInstrumentModel(model, 0); 
    537528    //store.setInstrumentManufacturer(make, 0); 
     
    543534   */ 
    544535  protected String getImageCreationDate() { 
    545     Object o = ifds.get(0).getIFDValue(IFD.DATE_TIME); 
    546     if (o instanceof String) return (String) o; 
    547     if (o instanceof String[]) return ((String[]) o)[0]; 
    548     return null; 
     536    return ifds.get(0).getIFDTextValue(IFD.DATE_TIME); 
    549537  } 
    550538 
  • trunk/components/bio-formats/src/loci/formats/in/LeicaReader.java

    r5624 r5668  
    395395        byte[] data = new byte[size]; 
    396396        in.read(data); 
    397         ifd.put(new Integer(tag), data); 
     397        ifd.putIFDValue(tag, data); 
    398398        in.seek(pos); 
    399399        tag = in.readInt(); 
  • trunk/components/bio-formats/src/loci/formats/in/MetamorphReader.java

    r5664 r5668  
    807807        } 
    808808 
    809         temp.put(new Integer(IFD.STRIP_OFFSETS), newOffsets); 
     809        temp.putIFDValue(IFD.STRIP_OFFSETS, newOffsets); 
    810810 
    811811        long[] newByteCounts = new long[stripsPerImage]; 
     
    817817          Arrays.fill(newByteCounts, stripByteCounts[0]); 
    818818        } 
    819         temp.put(new Integer(IFD.STRIP_BYTE_COUNTS), newByteCounts); 
     819        temp.putIFDValue(IFD.STRIP_BYTE_COUNTS, newByteCounts); 
    820820 
    821821        tempIFDs.add(temp); 
  • trunk/components/bio-formats/src/loci/formats/in/MinimalTiffReader.java

    r5636 r5668  
    243243      IFD ifd = ifds.get(i); 
    244244      boolean thumbnail = ifd.getIFDIntValue(IFD.NEW_SUBFILE_TYPE) == 1 && 
    245         (ifds.size() > 1 || ifd.get(new Integer(IFD.IMAGE_WIDTH)) == null); 
     245        (ifds.size() > 1 || ifd.getIFDValue(IFD.IMAGE_WIDTH) == null); 
    246246      if (thumbnail) thumbs.add(ifd); 
    247247      else v.add(ifd); 
  • trunk/components/bio-formats/src/loci/formats/in/NikonReader.java

    r5614 r5668  
    444444    original = ifds.get(0); 
    445445    if (cfaPattern != null) { 
    446       original.put(new Integer(IFD.COLOR_MAP), (int[]) cfaPattern); 
     446      original.putIFDValue(IFD.COLOR_MAP, (int[]) cfaPattern); 
    447447    } 
    448448    ifds.set(0, original); 
  • trunk/components/bio-formats/src/loci/formats/in/NikonTiffReader.java

    r5624 r5668  
    7878    IFD ifd = tp.getFirstIFD(); 
    7979    if (ifd == null) return false; 
    80     Object software = ifd.get(new Integer(IFD.SOFTWARE)); 
     80    String software = ifd.getIFDTextValue(IFD.SOFTWARE); 
    8181    return software != null && software.toString().indexOf("EZ-C1") != -1; 
    8282  } 
  • trunk/components/bio-formats/src/loci/formats/in/TCSReader.java

    r5614 r5668  
    146146    IFD ifd = tp.getFirstIFD(); 
    147147    if (ifd == null) return false; 
    148     String document = (String) ifd.get(new Integer(IFD.DOCUMENT_NAME)); 
     148    String document = ifd.getIFDTextValue(IFD.DOCUMENT_NAME); 
    149149    if (document == null) document = ""; 
    150     Object s = ifd.get(new Integer(IFD.SOFTWARE)); 
    151     String software = null; 
    152     if (s instanceof String) software = (String) s; 
    153     else if (s instanceof String[]) { 
    154       String[] ss = (String[]) s; 
    155       if (ss.length > 0) software = ss[0]; 
    156     } 
     150    String software = ifd.getIFDTextValue(IFD.SOFTWARE); 
    157151    if (software == null) software = ""; 
    158152    software = software.trim(); 
  • trunk/components/bio-formats/src/loci/formats/in/TiffReader.java

    r5416 r5668  
    182182 
    183183  private boolean checkCommentMetamorph(String comment) { 
    184     Object software = ifds.get(0).getIFDValue(IFD.SOFTWARE); 
    185     String check = software instanceof String ? (String) software : 
    186       software instanceof String[] ? ((String[]) software)[0] : null; 
     184    String software = ifds.get(0).getIFDTextValue(IFD.SOFTWARE); 
    187185    return comment != null && software != null && 
    188       check.indexOf("MetaMorph") != -1; 
     186      software.indexOf("MetaMorph") != -1; 
    189187  } 
    190188 
     
    269267          offsets[j] = offsets[j - 1] + stripByteCounts[j - 1]; 
    270268        } 
    271         ifd.put(new Integer(IFD.STRIP_OFFSETS), offsets); 
     269        ifd.putIFDValue(IFD.STRIP_OFFSETS, offsets); 
    272270      } 
    273271 
  • trunk/components/bio-formats/src/loci/formats/in/ZeissLSMReader.java

    r5664 r5668  
    378378        // than LZW compression is used 
    379379        if (ifd.getCompression() != TiffCompression.LZW) { 
    380           ifd.put(new Integer(IFD.PREDICTOR), new Integer(1)); 
     380          ifd.putIFDValue(IFD.PREDICTOR, 1); 
    381381        } 
    382382      } 
  • trunk/components/bio-formats/src/loci/formats/tiff/IFD.java

    r5334 r5668  
    322322  } 
    323323 
     324  /** Gets the given directory entry value as a string (regardless of type). */ 
     325  public String getIFDTextValue(int tag) { 
     326    String value = null; 
     327    Object o = getIFDValue(tag); 
     328    if (o instanceof String[]) { 
     329      StringBuilder sb = new StringBuilder(); 
     330      String[] s = (String[]) o; 
     331      for (int i=0; i<s.length; i++) { 
     332        sb.append(s[i]); 
     333        if (i < s.length - 1) sb.append("\n"); 
     334      } 
     335      value = sb.toString(); 
     336    } 
     337    else if (o != null) value = o.toString(); 
     338 
     339    // sanitize line feeds 
     340    if (value != null) { 
     341      value = value.replaceAll("\r\n", "\n"); // CR-LF to LF 
     342      value = value.replaceAll("\r", "\n"); // CR to LF 
     343    } 
     344 
     345    return value; 
     346  } 
     347 
    324348  /** 
    325349   * Gets the given directory entry values in long format 
     
    425449  /** Convenience method for obtaining the ImageDescription from this IFD. */ 
    426450  public String getComment() { 
    427     // extract comment 
    428     Object o = getIFDValue(IMAGE_DESCRIPTION); 
    429     String comment = null; 
    430     if (o instanceof String) comment = (String) o; 
    431     else if (o instanceof String[]) { 
    432       String[] s = (String[]) o; 
    433       if (s.length > 0) comment = s[0]; 
    434     } 
    435     else if (o != null) comment = o.toString(); 
    436  
    437     if (comment != null) { 
    438       // sanitize line feeds 
    439       comment = comment.replaceAll("\r\n", "\n"); // CR-LF to LF 
    440       comment = comment.replaceAll("\r", "\n"); // CR to LF 
    441     } 
    442     return comment; 
     451    return getIFDTextValue(IMAGE_DESCRIPTION); 
    443452  } 
    444453 
Note: See TracChangeset for help on using the changeset viewer.