Changeset 7236


Ignore:
Timestamp:
11/23/10 16:27:13 (10 years ago)
Author:
melissa
Message:
  • Properly unpack 16-bit BufferedImages into a byte array. Fix courtesy of Lee Kamentsky.
  • Prevent XML metadata parsing failures from causing TiffReader.setId to fail.
Location:
trunk/components/bio-formats/src/loci/formats/in
Files:
2 edited

Legend:

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

    r6881 r7236  
    2727import java.io.IOException; 
    2828 
     29import loci.common.DataTools; 
    2930import loci.formats.FormatException; 
    3031import loci.formats.FormatReader; 
     
    6768 
    6869    BufferedImage data = (BufferedImage) openPlane(no, x, y, w, h); 
    69     byte[] t = AWTImageTools.getBytes(data, false); 
    70     System.arraycopy(t, 0, buf, 0, (int) Math.min(t.length, buf.length)); 
     70    switch (data.getColorModel().getComponentSize(0)) { 
     71      case 8: 
     72        byte[] t = AWTImageTools.getBytes(data, false); 
     73        System.arraycopy(t, 0, buf, 0, (int) Math.min(t.length, buf.length)); 
     74        break; 
     75      case 16: 
     76        short[] ts = AWTImageTools.getShorts(data)[0]; 
     77        for (int i=0; i<ts.length && i < buf.length*2; i++) { 
     78          DataTools.unpackBytes(ts[i], buf, i * 2, 2, isLittleEndian()); 
     79        } 
     80        break; 
     81    } 
    7182    return buf; 
    7283  } 
  • trunk/components/bio-formats/src/loci/formats/in/TiffReader.java

    r6881 r7236  
    136136              metadata = metadata.substring(metadata.indexOf("<")); 
    137137              metadata = "<root>" + XMLTools.sanitizeXML(metadata) + "</root>"; 
    138               Hashtable<String, String> xmlMetadata = 
    139                 XMLTools.parseXML(metadata); 
    140               for (String key : xmlMetadata.keySet()) { 
    141                 addGlobalMeta(key, xmlMetadata.get(key)); 
     138              try { 
     139                Hashtable<String, String> xmlMetadata = 
     140                  XMLTools.parseXML(metadata); 
     141                for (String key : xmlMetadata.keySet()) { 
     142                  addGlobalMeta(key, xmlMetadata.get(key)); 
     143                } 
    142144              } 
     145              catch (IOException e) { } 
    143146            } 
    144147            else { 
Note: See TracChangeset for help on using the changeset viewer.