Changeset 5615


Ignore:
Timestamp:
10/19/09 06:00:24 (10 years ago)
Author:
melissa
Message:

Syncing 4.1 branch with r5614.

Location:
branches/4.1/components
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1/components/bio-formats/src/loci/formats/ChannelFiller.java

    r5387 r5615  
    173173  } 
    174174 
    175   /* @see IFormatReader#setId(String) */ 
     175  // -- IFormatHandler API methods -- 
     176 
     177  /* @see IFormatHandler#setId(String) */ 
    176178  public void setId(String id) throws FormatException, IOException { 
    177179    super.setId(id); 
  • branches/4.1/components/bio-formats/src/loci/formats/ChannelSeparator.java

    r5403 r5615  
    9797  // -- IFormatReader API methods -- 
    9898 
    99   /* @see IFormatReader#setId(String) */ 
    100   public void setId(String id) throws FormatException, IOException { 
    101     super.setId(id); 
    102  
    103     // clear last image cache 
    104     lastImage = null; 
    105     lastImageIndex = -1; 
    106     lastImageSeries = -1; 
    107     lastImageX = -1; 
    108     lastImageY = -1; 
    109     lastImageWidth = -1; 
    110     lastImageHeight = -1; 
    111   } 
    112  
    11399  /* @see IFormatReader#getImageCount() */ 
    114100  public int getImageCount() { 
     
    214200  } 
    215201 
     202  // -- IFormatHandler API methods -- 
     203 
     204  /* @see IFormatHandler#setId(String) */ 
     205  public void setId(String id) throws FormatException, IOException { 
     206    super.setId(id); 
     207 
     208    // clear last image cache 
     209    lastImage = null; 
     210    lastImageIndex = -1; 
     211    lastImageSeries = -1; 
     212    lastImageX = -1; 
     213    lastImageY = -1; 
     214    lastImageWidth = -1; 
     215    lastImageHeight = -1; 
     216  } 
     217 
    216218} 
  • branches/4.1/components/bio-formats/src/loci/formats/DimensionSwapper.java

    r5587 r5615  
    168168  // -- IFormatReader API methods -- 
    169169 
    170   /* @see loci.formats.IFormatReader#setId(String) */ 
     170  /* @see IFormatReader#getSizeX() */ 
     171  public int getSizeX() { 
     172    FormatTools.assertId(getCurrentFile(), true, 2); 
     173    return getCoreMetadata()[getSeries()].sizeX; 
     174  } 
     175 
     176  /* @see IFormatReader#getSizeY() */ 
     177  public int getSizeY() { 
     178    FormatTools.assertId(getCurrentFile(), true, 2); 
     179    return getCoreMetadata()[getSeries()].sizeY; 
     180  } 
     181 
     182  /* @see IFormatReader#getSizeZ() */ 
     183  public int getSizeZ() { 
     184    FormatTools.assertId(getCurrentFile(), true, 2); 
     185    return getCoreMetadata()[getSeries()].sizeZ; 
     186  } 
     187 
     188  /* @see IFormatReader#getSizeC() */ 
     189  public int getSizeC() { 
     190    FormatTools.assertId(getCurrentFile(), true, 2); 
     191    return getCoreMetadata()[getSeries()].sizeC; 
     192  } 
     193 
     194  /* @see IFormatReader#getSizeT() */ 
     195  public int getSizeT() { 
     196    FormatTools.assertId(getCurrentFile(), true, 2); 
     197    return getCoreMetadata()[getSeries()].sizeT; 
     198  } 
     199 
     200  /* @see IFormatReader#getChannelDimLengths() */ 
     201  public int[] getChannelDimLengths() { 
     202    FormatTools.assertId(getCurrentFile(), true, 2); 
     203    int[] cLengths = getCoreMetadata()[getSeries()].cLengths; 
     204    return cLengths == null ? super.getChannelDimLengths() : cLengths; 
     205  } 
     206 
     207  /* @see IFormatReader#getChannelDimTypes() */ 
     208  public String[] getChannelDimTypes() { 
     209    FormatTools.assertId(getCurrentFile(), true, 2); 
     210    String[] cTypes = getCoreMetadata()[getSeries()].cTypes; 
     211    return cTypes == null ? super.getChannelDimTypes() : cTypes; 
     212  } 
     213 
     214  /* @see IFormatReader#getDimensionOrder() */ 
     215  public String getDimensionOrder() { 
     216    FormatTools.assertId(getCurrentFile(), true, 2); 
     217    if (outputOrder[getSeries()] != null) return outputOrder[getSeries()]; 
     218    return getInputOrder(); 
     219  } 
     220 
     221  /* @see IFormatReader#openBytes(int) */ 
     222  public byte[] openBytes(int no) throws FormatException, IOException { 
     223    return super.openBytes(reorder(no)); 
     224  } 
     225 
     226  /* @see IFormatReader#openBytes(int, int, int, int, int) */ 
     227  public byte[] openBytes(int no, int x, int y, int w, int h) 
     228    throws FormatException, IOException 
     229  { 
     230    return super.openBytes(reorder(no), x, y, w, h); 
     231  } 
     232 
     233  /* @see IFormatReader#openBytes(int, byte[]) */ 
     234  public byte[] openBytes(int no, byte[] buf) 
     235    throws FormatException, IOException 
     236  { 
     237    return super.openBytes(reorder(no), buf); 
     238  } 
     239 
     240  /* @see IFormatReader#openBytes(int, byte[], int, int, int, int) */ 
     241  public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) 
     242    throws FormatException, IOException 
     243  { 
     244    return super.openBytes(reorder(no), buf, x, y, w, h); 
     245  } 
     246 
     247  /* @see IFormatReader#openThumbImage(int) */ 
     248  public byte[] openThumbBytes(int no) throws FormatException, IOException { 
     249    return super.openThumbBytes(reorder(no)); 
     250  } 
     251 
     252  /* @see IFormatReader#getZCTCoords(int) */ 
     253  public int[] getZCTCoords(int no) { 
     254    return FormatTools.getZCTCoords(this, no); 
     255  } 
     256 
     257  /* @see IFormatReader#getIndex(int, int, int) */ 
     258  public int getIndex(int z, int c, int t) { 
     259    return FormatTools.getIndex(this, z, c, t); 
     260  } 
     261 
     262  // -- IFormatHandler API methods -- 
     263 
     264  /* @see IFormatHandler#setId(String) */ 
    171265  public void setId(String id) throws FormatException, IOException { 
    172266    String oldFile = getCurrentFile(); 
     
    177271  } 
    178272 
    179   /* @see loci.formats.IFormatReader#getSizeX() */ 
    180   public int getSizeX() { 
    181     FormatTools.assertId(getCurrentFile(), true, 2); 
    182     return getCoreMetadata()[getSeries()].sizeX; 
    183   } 
    184  
    185   /* @see loci.formats.IFormatReader#getSizeY() */ 
    186   public int getSizeY() { 
    187     FormatTools.assertId(getCurrentFile(), true, 2); 
    188     return getCoreMetadata()[getSeries()].sizeY; 
    189   } 
    190  
    191   /* @see loci.formats.IFormatReader#getSizeZ() */ 
    192   public int getSizeZ() { 
    193     FormatTools.assertId(getCurrentFile(), true, 2); 
    194     return getCoreMetadata()[getSeries()].sizeZ; 
    195   } 
    196  
    197   /* @see loci.formats.IFormatReader#getSizeC() */ 
    198   public int getSizeC() { 
    199     FormatTools.assertId(getCurrentFile(), true, 2); 
    200     return getCoreMetadata()[getSeries()].sizeC; 
    201   } 
    202  
    203   /* @see loci.formats.IFormatReader#getSizeT() */ 
    204   public int getSizeT() { 
    205     FormatTools.assertId(getCurrentFile(), true, 2); 
    206     return getCoreMetadata()[getSeries()].sizeT; 
    207   } 
    208  
    209   /* @see loci.formats.IFormatReader#getChannelDimLengths() */ 
    210   public int[] getChannelDimLengths() { 
    211     FormatTools.assertId(getCurrentFile(), true, 2); 
    212     int[] cLengths = getCoreMetadata()[getSeries()].cLengths; 
    213     return cLengths == null ? super.getChannelDimLengths() : cLengths; 
    214   } 
    215  
    216   /* @see loci.formats.IFormatReader#getChannelDimTypes() */ 
    217   public String[] getChannelDimTypes() { 
    218     FormatTools.assertId(getCurrentFile(), true, 2); 
    219     String[] cTypes = getCoreMetadata()[getSeries()].cTypes; 
    220     return cTypes == null ? super.getChannelDimTypes() : cTypes; 
    221   } 
    222  
    223   /* @see loci.formats.IFormatReader#getDimensionOrder() */ 
    224   public String getDimensionOrder() { 
    225     FormatTools.assertId(getCurrentFile(), true, 2); 
    226     if (outputOrder[getSeries()] != null) return outputOrder[getSeries()]; 
    227     return getInputOrder(); 
    228   } 
    229  
    230   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    231   public byte[] openBytes(int no) throws FormatException, IOException { 
    232     return super.openBytes(reorder(no)); 
    233   } 
    234  
    235   /* @see loci.formats.IFormatReader#openBytes(int, int, int, int, int) */ 
    236   public byte[] openBytes(int no, int x, int y, int w, int h) 
    237     throws FormatException, IOException 
    238   { 
    239     return super.openBytes(reorder(no), x, y, w, h); 
    240   } 
    241  
    242   /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    243   public byte[] openBytes(int no, byte[] buf) 
    244     throws FormatException, IOException 
    245   { 
    246     return super.openBytes(reorder(no), buf); 
    247   } 
    248  
    249   /* 
    250    * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) 
    251    */ 
    252   public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) 
    253     throws FormatException, IOException 
    254   { 
    255     return super.openBytes(reorder(no), buf, x, y, w, h); 
    256   } 
    257  
    258   /* @see loci.formats.IFormatReader#openThumbImage(int) */ 
    259   public byte[] openThumbBytes(int no) throws FormatException, IOException { 
    260     return super.openThumbBytes(reorder(no)); 
    261   } 
    262  
    263   /* @see loci.formats.IFormatReader#getZCTCoords(int) */ 
    264   public int[] getZCTCoords(int no) { 
    265     return FormatTools.getZCTCoords(this, no); 
    266   } 
    267  
    268   /* @see loci.formats.IFormatReader#getIndex(int, int, int) */ 
    269   public int getIndex(int z, int c, int t) { 
    270     return FormatTools.getIndex(this, z, c, t); 
    271   } 
    272  
    273  
    274273  // -- Helper methods -- 
    275274 
  • branches/4.1/components/bio-formats/src/loci/formats/FileStitcher.java

    r5587 r5615  
    467467  } 
    468468 
    469   /* @see IFormatReader#getNativeDataType() */ 
    470   public Class getNativeDataType() { 
    471     FormatTools.assertId(currentId, true, 2); 
    472     return reader.getNativeDataType(); 
    473   } 
    474  
    475   /* @see IFormatReader#openData(int, int, int, int, int) */ 
    476   public Object openData(int no, int x, int y, int w, int h) 
     469  /* @see IFormatReader#openPlane(int, int, int, int, int) */ 
     470  public Object openPlane(int no, int x, int y, int w, int h) 
    477471    throws FormatException, IOException 
    478472  { 
     
    481475    IFormatReader r = getReader(no); 
    482476    int ino = getAdjustedIndex(no); 
    483     if (ino < r.getImageCount()) return r.openData(ino, x, y, w, h); 
     477    if (ino < r.getImageCount()) return r.openPlane(ino, x, y, w, h); 
    484478 
    485479    return null; 
     
    875869  } 
    876870 
     871  /* @see IFormatHandler#getNativeDataType() */ 
     872  public Class getNativeDataType() { 
     873    FormatTools.assertId(currentId, true, 2); 
     874    return reader.getNativeDataType(); 
     875  } 
     876 
    877877  /* @see IFormatHandler#setId(String) */ 
    878878  public void setId(String id) throws FormatException, IOException { 
  • branches/4.1/components/bio-formats/src/loci/formats/FormatHandler.java

    r5425 r5615  
    148148  /* @see IFormatHandler#getSuffixes() */ 
    149149  public String[] getSuffixes() { return suffixes; } 
     150 
     151  /* @see IFormatHandler#getNativeDataType() */ 
     152  public Class getNativeDataType() { 
     153    // NB: Handlers use byte arrays by default as the native type. 
     154    return byte[].class; 
     155  } 
    150156 
    151157  // -- StatusReporter API methods -- 
  • branches/4.1/components/bio-formats/src/loci/formats/FormatReader.java

    r5587 r5615  
    361361 
    362362  // -- IFormatReader API methods -- 
    363  
    364   /* @see IFormatReader#setId(String) */ 
    365   public void setId(String id) throws FormatException, IOException { 
    366     if (!id.equals(currentId)) initFile(id); 
    367   } 
    368363 
    369364  /** 
     
    609604    int w, int h) throws FormatException, IOException; 
    610605 
    611   /* @see IFormatReader#getNativeDataType() */ 
    612   public Class getNativeDataType() { 
    613     // NB: Readers use byte arrays by default as the native type. 
    614     return byte[].class; 
    615   } 
    616  
    617   /* @see IFormatReader#openData(int, int, int, int, int int) */ 
    618   public Object openData(int no, int x, int y, int w, int h) 
     606  /* @see IFormatReader#openPlane(int, int, int, int, int int) */ 
     607  public Object openPlane(int no, int x, int y, int w, int h) 
    619608    throws FormatException, IOException 
    620609  { 
     
    908897  } 
    909898 
     899  /* @see IFormatHandler#setId(String) */ 
     900  public void setId(String id) throws FormatException, IOException { 
     901    if (!id.equals(currentId)) initFile(id); 
     902  } 
     903 
    910904  /* @see IFormatHandler#close() */ 
    911905  public void close() throws IOException { 
  • branches/4.1/components/bio-formats/src/loci/formats/FormatWriter.java

    r5575 r5615  
    2424package loci.formats; 
    2525 
    26 import java.awt.Image; 
    27 import java.awt.image.BufferedImage; 
    2826import java.awt.image.ColorModel; 
    2927import java.io.IOException; 
    3028 
    31 import loci.formats.gui.AWTImageTools; 
    3229import loci.formats.meta.DummyMetadata; 
    3330import loci.formats.meta.MetadataRetrieve; 
     
    9087  } 
    9188 
    92   /* @see IFormatWriter#saveImage(Image, boolean) */ 
    93   public void saveImage(Image image, boolean last) 
     89  /* @see IFormatWriter#savePlane(Object, boolean) */ 
     90  public void savePlane(Object plane, boolean last) 
    9491    throws FormatException, IOException 
    9592  { 
    96     saveImage(image, 0, last, last); 
     93    savePlane(plane, 0, last, last); 
    9794  } 
    9895 
    99   /* @see IFormatWriter#saveImage(Image, int, boolean, boolean) */ 
    100   public void saveImage(Image image, int series, boolean lastInSeries, 
     96  /* @see IFormatWriter#savePlane(Object, int, boolean, boolean) */ 
     97  public void savePlane(Object plane, int series, boolean lastInSeries, 
    10198    boolean last) throws FormatException, IOException 
    10299  { 
    103     BufferedImage img = AWTImageTools.makeBuffered(image); 
    104     boolean littleEndian = false; 
    105     int bpp = FormatTools.getBytesPerPixel(AWTImageTools.getPixelType(img)); 
    106  
    107     MetadataRetrieve r = getMetadataRetrieve(); 
    108     if (r != null) { 
    109       Boolean bigEndian = r.getPixelsBigEndian(series, 0); 
    110       if (bigEndian != null) littleEndian = !bigEndian.booleanValue(); 
     100    // NB: Writers use byte arrays by default as the native type. 
     101    if (!(plane instanceof byte[])) { 
     102      throw new IllegalArgumentException("Object to save must be a byte[]"); 
    111103    } 
    112  
    113     byte[][] pixelBytes = AWTImageTools.getPixelBytes(img, littleEndian); 
    114     byte[] buf = new byte[pixelBytes.length * pixelBytes[0].length]; 
    115     if (interleaved) { 
    116       for (int i=0; i<pixelBytes[0].length; i+=bpp) { 
    117         for (int j=0; j<pixelBytes.length; j++) { 
    118           System.arraycopy(pixelBytes[j], i, buf, i*pixelBytes.length + j*bpp, 
    119             bpp); 
    120         } 
    121       } 
    122     } 
    123     else { 
    124       for (int i=0; i<pixelBytes.length; i++) { 
    125         System.arraycopy(pixelBytes[i], 0, buf, i * pixelBytes[0].length, 
    126           pixelBytes[i].length); 
    127       } 
    128     } 
    129     pixelBytes = null; 
    130  
    131     saveBytes(buf, series, lastInSeries, last); 
     104    saveBytes((byte[]) plane, series, lastInSeries, last); 
    132105  } 
    133106 
     
    135108  public void setInterleaved(boolean interleaved) { 
    136109    this.interleaved = interleaved; 
     110  } 
     111 
     112  /* @see IFormatWriter#isInterleaved() */ 
     113  public boolean isInterleaved() { 
     114    return interleaved; 
    137115  } 
    138116 
  • branches/4.1/components/bio-formats/src/loci/formats/IFormatHandler.java

    r4953 r5615  
    4444  String[] getSuffixes(); 
    4545 
     46  /** 
     47   * Returns the native data type of image planes for this reader, as returned 
     48   * by {@link IFormatReader#openPlane} or {@link IFormatWriter#saveData}. 
     49   * For most readers this type will be a byte array; however, some readers 
     50   * call external APIs that work with other types such as 
     51   * {@link java.awt.image.BufferedImage}. 
     52   */ 
     53  Class getNativeDataType(); 
     54 
    4655  /** Sets the current file name. */ 
    4756  void setId(String id) throws FormatException, IOException; 
  • branches/4.1/components/bio-formats/src/loci/formats/IFormatReader.java

    r5587 r5615  
    241241 
    242242  /** 
    243    * Returns the native data type of image planes for this reader, as returned 
    244    * by {@link #openData}. For most readers this type will be a byte array; 
    245    * however, some readers call external APIs that work with other types such 
    246    * as {@link java.awt.image.BufferedImage}. 
    247    */ 
    248   Class getNativeDataType(); 
    249  
    250   /** 
    251243   * Obtains the specified image plane (or sub-image thereof) in the reader's 
    252244   * native data structure. For most readers this is a byte array; however, 
    253245   * some readers call external APIs that work with other types such as 
    254    * {@link java.awt.image.BufferedImage}. The openData method exists to 
     246   * {@link java.awt.image.BufferedImage}. The openPlane method exists to 
    255247   * maintain generality and efficiency while avoiding pollution of the API 
    256248   * with AWT-specific logic. 
     
    259251   * @see loci.formats.gui.BufferedImageReader 
    260252   */ 
    261   Object openData(int no, int x, int y, int w, int h) 
     253  Object openPlane(int no, int x, int y, int w, int h) 
    262254    throws FormatException, IOException; 
    263255 
  • branches/4.1/components/bio-formats/src/loci/formats/IFormatWriter.java

    r5575 r5615  
    2424package loci.formats; 
    2525 
    26 import java.awt.Image; 
    2726import java.awt.image.ColorModel; 
    2827import java.io.IOException; 
     
    3837 */ 
    3938public interface IFormatWriter extends IFormatHandler { 
    40  
    41   /** 
    42    * Saves the given image to the current file. 
    43    * Note that this method will append the image to the file; it will not 
    44    * overwrite previously saved images. 
    45    * If this image is the last one in the file, the last flag must be set. 
    46    */ 
    47   void saveImage(Image image, boolean last) throws FormatException, IOException; 
    48  
    49   /** 
    50    * Saves the given image to the given series in the current file. 
    51    * Note that this method will append the image to the file; it will not 
    52    * overwrite previously saved images. 
    53    * If this image is the last one in the series, the lastInSeries flag 
    54    * must be set. 
    55    * If this image is the last one in the file, the last flag must be set. 
    56    */ 
    57   void saveImage(Image image, int series, boolean lastInSeries, boolean last) 
    58     throws FormatException, IOException; 
    5939 
    6040  /** 
     
    7858 
    7959  /** 
    80    * Sets whether or not the channels in an image are interleaved. 
     60   * Saves the given image plane to the current file. 
     61   * Note that this method will append the image plane to the file; it will not 
     62   * overwrite previously saved image planes. 
     63   * If this image plane is the last one in the file, the last flag must be set. 
    8164   */ 
     65  void savePlane(Object plane, boolean last) 
     66    throws FormatException, IOException; 
     67 
     68  /** 
     69   * Saves the given image plane to the given series in the current file. 
     70   * Note that this method will append the image plane to the file; it will not 
     71   * overwrite previously saved image planes. 
     72   * If this image plane is the last one in the series, the lastInSeries flag 
     73   * must be set. 
     74   * If this image plane is the last one in the file, the last flag must be set. 
     75   */ 
     76  void savePlane(Object plane, int series, boolean lastInSeries, boolean last) 
     77    throws FormatException, IOException; 
     78 
     79  /** Sets whether or not the channels in an image are interleaved. */ 
    8280  void setInterleaved(boolean interleaved); 
     81 
     82  /** Gets whether or not the channels in an image are interleaved. */ 
     83  boolean isInterleaved(); 
    8384 
    8485  /** Reports whether the writer can save multiple images to a single file. */ 
  • branches/4.1/components/bio-formats/src/loci/formats/ImageReader.java

    r5587 r5615  
    340340  } 
    341341 
    342   /* @see IFormatReader#getNativeDataType() */ 
    343   public Class getNativeDataType() { 
    344     return getReader().getNativeDataType(); 
    345   } 
    346  
    347   /* @see IFormatReader#openData(int, int, int, int, int) */ 
    348   public Object openData(int no, int x, int y, int w, int h) 
     342  /* @see IFormatReader#openPlane(int, int, int, int, int) */ 
     343  public Object openPlane(int no, int x, int y, int w, int h) 
    349344    throws FormatException, IOException 
    350345  { 
    351     return getReader().openData(no, x, y, w, h); 
     346    return getReader().openPlane(no, x, y, w, h); 
    352347  } 
    353348 
     
    584579  } 
    585580 
     581  /* @see IFormatHandler#getNativeDataType() */ 
     582  public Class getNativeDataType() { 
     583    return getReader().getNativeDataType(); 
     584  } 
     585 
    586586  /* @see IFormatHandler#setId(String) */ 
    587587  public void setId(String id) throws FormatException, IOException { 
  • branches/4.1/components/bio-formats/src/loci/formats/ImageWriter.java

    r5575 r5615  
    2424package loci.formats; 
    2525 
    26 import java.awt.Image; 
    2726import java.awt.image.ColorModel; 
    2827import java.io.IOException; 
     
    187186  } 
    188187 
    189   /* @see IFormatWriter#saveImage(Image, boolean) */ 
    190   public void saveImage(Image image, boolean last) 
     188  /* @see IFormatWriter#savePlane(Object, boolean) */ 
     189  public void savePlane(Object plane, boolean last) 
    191190    throws FormatException, IOException 
    192191  { 
    193     getWriter().saveImage(image, last); 
    194   } 
    195  
    196   /* @see IFormatWriter#saveImage(Image, int, boolean, boolean) */ 
    197   public void saveImage(Image image, int series, boolean lastInSeries, 
     192    getWriter().savePlane(plane, last); 
     193  } 
     194 
     195  /* @see IFormatWriter#savePlane(Object, int, boolean, boolean) */ 
     196  public void savePlane(Object plane, int series, boolean lastInSeries, 
    198197    boolean last) throws FormatException, IOException 
    199198  { 
    200     getWriter().saveImage(image, series, lastInSeries, last); 
     199    getWriter().savePlane(plane, series, lastInSeries, last); 
    201200  } 
    202201 
     
    204203  public void setInterleaved(boolean interleaved) { 
    205204    for (int i=0; i<writers.length; i++) writers[i].setInterleaved(interleaved); 
     205  } 
     206 
     207  /* @see IFormatWriter#isInterleaved() */ 
     208  public boolean isInterleaved() { 
     209    // NB: all writers should have the same interleaved status 
     210    return writers[0].isInterleaved(); 
    206211  } 
    207212 
     
    325330  } 
    326331 
     332  /* @see IFormatHandler#getNativeDataType() */ 
     333  public Class getNativeDataType() { 
     334    return getWriter().getNativeDataType(); 
     335  } 
     336 
    327337  /* @see IFormatHandler#setId(String) */ 
    328338  public void setId(String id) throws FormatException, IOException { 
  • branches/4.1/components/bio-formats/src/loci/formats/MetadataTools.java

    r5548 r5615  
    212212  } 
    213213 
     214  /** 
     215   * Returns a {@link loci.formats.ome.OMEXMLMetadata} object with the same 
     216   * contents as the given MetadataRetrieve, converting it if necessary. 
     217   */ 
    214218  public static IMetadata getOMEMetadata(MetadataRetrieve src) { 
    215219    // check if the metadata is already an OME-XML metadata object 
     
    226230   * If the given IMetadata is an instance of 
    227231   * {@link loci.formats.ome.OMEXMLMetadata}, the OriginalMetadata hashtable 
    228    * is returned.  Otherwise, returns null; 
     232   * is returned. Otherwise, returns null. 
    229233   */ 
    230234  public static Hashtable<String, String> getOriginalMetadata(IMetadata src) { 
  • branches/4.1/components/bio-formats/src/loci/formats/ReaderWrapper.java

    r5587 r5615  
    144144  // -- IFormatReader API methods -- 
    145145 
     146  public boolean isThisType(String name, boolean open) { 
     147    return reader.isThisType(name, open); 
     148  } 
     149 
    146150  public boolean isThisType(byte[] block) { 
    147151    return reader.isThisType(block); 
     
    152156  } 
    153157 
    154   public void setId(String id) throws FormatException, IOException { 
    155     reader.setId(id); 
    156   } 
    157  
    158158  public int getImageCount() { 
    159159    return reader.getImageCount(); 
     
    274274  } 
    275275 
    276   public Class getNativeDataType() { 
    277     return reader.getNativeDataType(); 
    278   } 
    279  
    280   public Object openData(int no, int x, int y, int w, int h) 
    281     throws FormatException, IOException 
    282   { 
    283     return reader.openData(no, x, y, w, h); 
     276  public Object openPlane(int no, int x, int y, int w, int h) 
     277    throws FormatException, IOException 
     278  { 
     279    return reader.openPlane(no, x, y, w, h); 
    284280  } 
    285281 
     
    290286  public void close(boolean fileOnly) throws IOException { 
    291287    reader.close(fileOnly); 
    292   } 
    293  
    294   public void close() throws IOException { 
    295     reader.close(); 
    296288  } 
    297289 
     
    441433  } 
    442434 
    443   public boolean isThisType(String name, boolean open) { 
    444     return reader.isThisType(name, open); 
    445   } 
    446  
    447435  public String getFormat() { 
    448436    return reader.getFormat(); 
     
    451439  public String[] getSuffixes() { 
    452440    return reader.getSuffixes(); 
     441  } 
     442 
     443  public Class getNativeDataType() { 
     444    return reader.getNativeDataType(); 
     445  } 
     446 
     447  public void setId(String id) throws FormatException, IOException { 
     448    reader.setId(id); 
     449  } 
     450 
     451  public void close() throws IOException { 
     452    reader.close(); 
    453453  } 
    454454 
  • branches/4.1/components/bio-formats/src/loci/formats/gui/AWTImageTools.java

    r5548 r5615  
    5757 
    5858import loci.common.DataTools; 
     59import loci.common.LogTools; 
    5960import loci.formats.FormatException; 
    6061import loci.formats.FormatTools; 
    6162import loci.formats.IFormatReader; 
    6263import loci.formats.ImageTools; 
     64import loci.formats.MetadataTools; 
     65import loci.formats.meta.MetadataRetrieve; 
    6366 
    6467/** 
     
    9497 
    9598  /** 
    96    * Creates an image from the given single-channel unsigned byte data. 
    97    * 
    98    * @deprecated Use {@link #makeImage(byte[], int, int, boolean)} instead. 
    99    */ 
    100   public static BufferedImage makeImage(byte[] data, int w, int h) { 
    101     return makeImage(data, w, h, false); 
    102   } 
    103  
    104   /** 
    10599   * Creates an image from the given single-channel byte data. 
    106100   * 
     
    118112 
    119113  /** 
    120    * Creates an image from the given single-channel unsigned short data. 
    121    * 
    122    * @deprecated Use {@link #makeImage(short[], int, int, boolean)} instead. 
    123    */ 
    124   public static BufferedImage makeImage(short[] data, int w, int h) { 
    125     return makeImage(data, w, h, false); 
    126   } 
    127  
    128   /** 
    129114   * Creates an image from the given single-channel short data. 
    130115   * 
     
    142127 
    143128  /** 
    144    * Creates an image from the given single-channel signed int data. 
    145    * 
    146    * @deprecated Use {@link Use #makeImage(int[], int, int, boolean)} instead. 
    147    */ 
    148   public static BufferedImage makeImage(int[] data, int w, int h) { 
    149     return makeImage(data, w, h, true); 
    150   } 
    151  
    152   /** 
    153129   * Creates an image from the given single-channel int data. 
    154130   * 
     
    188164 
    189165  // -- Image construction - from 1D (interleaved or banded) data arrays -- 
    190  
    191   /** 
    192    * Creates an image from the given unsigned byte data. 
    193    * 
    194    * @deprecated Use 
    195    *   {@link #makeImage(byte[], int, int, int, boolean, boolean)} instead. 
    196    */ 
    197   public static BufferedImage makeImage(byte[] data, 
    198     int w, int h, int c, boolean interleaved) 
    199   { 
    200     return makeImage(data, w, h, c, interleaved, false); 
    201   } 
    202166 
    203167  /** 
     
    233197 
    234198  /** 
    235    * Creates an image from the given unsigned short data. 
    236    * 
    237    * @deprecated Use 
    238    *   {@link #makeImage(short[], int, int, int, boolean, boolean)} instead. 
    239    */ 
    240   public static BufferedImage makeImage(short[] data, 
    241     int w, int h, int c, boolean interleaved) 
    242   { 
    243     return makeImage(data, w, h, c, interleaved, false); 
    244   } 
    245  
    246   /** 
    247199   * Creates an image from the given short data. 
    248200   * 
     
    276228 
    277229  /** 
    278    * Creates an image from the given signed int data. 
    279    * 
    280    * @deprecated Use 
    281    *   {@link #makeImage(int[], int, int, int, boolean, boolean)} instead. 
    282    */ 
    283   public static BufferedImage makeImage(int[] data, 
    284     int w, int h, int c, boolean interleaved) 
    285   { 
    286     return makeImage(data, w, h, c, interleaved, true); 
    287   } 
    288  
    289   /** 
    290230   * Creates an image from the given int data. 
    291231   * 
     
    361301 
    362302  /** 
    363    * Creates an image from the given unsigned byte data. 
    364    * 
    365    * @deprecated Use {@link #makeImage(byte[][], int, int, boolean)} instead. 
    366    */ 
    367   public static BufferedImage makeImage(byte[][] data, int w, int h) { 
    368     return makeImage(data, w, h, false); 
    369   } 
    370  
    371   /** 
    372303   * Creates an image from the given byte data. 
    373304   * 
     
    397328 
    398329  /** 
    399    * Creates an image from the given unsigned short data. 
    400    * 
    401    * @deprecated Use {@link #makeImage(short[][], int, int, boolean)} instead. 
    402    */ 
    403   public static BufferedImage makeImage(short[][] data, int w, int h) { 
    404     return makeImage(data, w, h, false); 
    405   } 
    406  
    407   /** 
    408330   * Creates an image from the given short data. 
    409331   * 
     
    433355 
    434356  /** 
    435    * Creates an image from the given signed int data. 
    436    * 
    437    * @deprecated Use {@link #makeImage(int[][], int, int, boolean)} instead. 
    438    */ 
    439   public static BufferedImage makeImage(int[][] data, int w, int h) { 
    440     return makeImage(data, w, h, true); 
    441   } 
    442  
    443   /** 
    444357   * Creates an image from the given int data. 
    445358   * 
     
    499412 
    500413  /** 
    501    * Creates an image from the given raw byte array, 
    502    * performing any necessary type conversions. 
    503    * 
    504    * @deprecated Use {@link #makeImage(byte[], int, int, int, 
    505    *    boolean, int, boolean, boolean, boolean)} instead. 
    506    */ 
    507   public static BufferedImage makeImage(byte[] data, int w, int h, int c, 
    508     boolean interleaved, int bpp, boolean little) 
    509   { 
    510     return makeImage(data, w, h, c, interleaved, bpp, false, little, bpp >= 4); 
     414   * Creates an image from the given raw byte array, obtaining the 
     415   * dimensional parameters from the specified metadata object. 
     416   * 
     417   * @param data Array containing image data. 
     418   * @param interleaved If set, the channels are assumed to be interleaved; 
     419   *   otherwise they are assumed to be sequential. 
     420   *   For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, 
     421   *   while "RRR...GGG...BBB..." is sequential. 
     422   * @param meta Metadata object containing dimensional parameters. 
     423   * @param series Relevant image series number of metadata object. 
     424   */ 
     425  public static BufferedImage makeImage(byte[] data, boolean interleaved, 
     426    MetadataRetrieve meta, int series) throws FormatException 
     427  { 
     428    MetadataTools.verifyMinimumPopulated(meta, series); 
     429    int width = meta.getPixelsSizeX(series, 0).intValue(); 
     430    int height = meta.getPixelsSizeY(series, 0).intValue(); 
     431    String pixelType = meta.getPixelsPixelType(series, 0); 
     432    int type = FormatTools.pixelTypeFromString(pixelType); 
     433    Integer nChannels = meta.getLogicalChannelSamplesPerPixel(series, 0); 
     434    if (nChannels == null) { 
     435      LogTools.warnDebug("SamplesPerPixel is null; it is assumed to be 1."); 
     436    } 
     437    int channels = nChannels == null ? 1 : nChannels.intValue(); 
     438    boolean littleEndian = !meta.getPixelsBigEndian(series, 0).booleanValue(); 
     439    return makeImage(data, width, height, channels, 
     440      interleaved, FormatTools.getBytesPerPixel(type), 
     441      FormatTools.isFloatingPoint(type), littleEndian, 
     442      FormatTools.isSigned(type)); 
    511443  } 
    512444 
     
    552484    } 
    553485    return null; 
    554   } 
    555  
    556   /** 
    557    * Creates an image from the given raw byte array, 
    558    * performing any necessary type conversions. 
    559    * 
    560    * @deprecated Use {@link #makeImage(byte[][], int, int, int, 
    561    *    boolean, boolean, boolean)} instead. 
    562    */ 
    563   public static BufferedImage makeImage(byte[][] data, 
    564     int w, int h, int bpp, boolean little) 
    565   { 
    566     return makeImage(data, w, h, bpp, false, little, false); 
    567486  } 
    568487 
     
    11761095  public static BufferedImage makeUnsigned(BufferedImage img) { 
    11771096    int pixelType = getPixelType(img); 
    1178     if (!FormatTools.isSigned(pixelType) || 
    1179       FormatTools.isFloatingPoint(pixelType)) 
    1180     { 
    1181       return img; 
    1182     } 
     1097    boolean signed = FormatTools.isSigned(pixelType); 
     1098    boolean fp = FormatTools.isFloatingPoint(pixelType); 
     1099    if (!signed || fp) return img; 
    11831100 
    11841101    int bpp = FormatTools.getBytesPerPixel(pixelType); 
    11851102 
    11861103    byte[][] pix = getPixelBytes(img, false); 
    1187     return makeImage(pix, img.getWidth(), img.getHeight(), bpp, false); 
     1104    return makeImage(pix, img.getWidth(), img.getHeight(), 
     1105      bpp, fp, false, false); 
    11881106  } 
    11891107 
     
    11981116 
    11991117    Object o = getPixels(image); 
     1118 
     1119    int pixelType = getPixelType(image); 
     1120    boolean signed = FormatTools.isSigned(pixelType); 
    12001121    if (o instanceof byte[][]) { 
    12011122      byte[][] pix = (byte[][]) o; 
    1202       for (int i=0; i<c; i++) results[i] = makeImage(pix[i], w, h); 
     1123      for (int i=0; i<c; i++) results[i] = makeImage(pix[i], w, h, signed); 
    12031124    } 
    12041125    else if (o instanceof short[][]) { 
    12051126      short[][] pix = (short[][]) o; 
    1206       for (int i=0; i<c; i++) results[i] = makeImage(pix[i], w, h); 
     1127      for (int i=0; i<c; i++) results[i] = makeImage(pix[i], w, h, signed); 
    12071128    } 
    12081129    else if (o instanceof int[][]) { 
    12091130      int[][] pix = (int[][]) o; 
    1210       for (int i=0; i<c; i++) results[i] = makeImage(pix[i], w, h); 
     1131      for (int i=0; i<c; i++) results[i] = makeImage(pix[i], w, h, signed); 
    12111132    } 
    12121133    else if (o instanceof float[][]) { 
     
    12631184    // compile results into a single array 
    12641185    int w = images[0].getWidth(), h = images[0].getHeight(); 
     1186    int pixelType = getPixelType(images[0]); 
     1187    boolean signed = FormatTools.isSigned(pixelType); 
    12651188    if (type == DataBuffer.TYPE_BYTE) { 
    12661189      byte[][] pix = new byte[c][]; 
     
    12711194      } 
    12721195      while (ndx < pix.length) pix[ndx++] = new byte[w * h]; // blank channel 
    1273       return makeImage(pix, w, h); 
    1274     } 
    1275     if (type == DataBuffer.TYPE_USHORT) { 
     1196      return makeImage(pix, w, h, signed); 
     1197    } 
     1198    if (type == DataBuffer.TYPE_USHORT || type == DataBuffer.TYPE_SHORT) { 
    12761199      short[][] pix = new short[c][]; 
    12771200      int ndx = 0; 
     
    12811204      } 
    12821205      while (ndx < pix.length) pix[ndx++] = new short[w * h]; // blank channel 
    1283       return makeImage(pix, w, h); 
     1206      return makeImage(pix, w, h, signed); 
    12841207    } 
    12851208    if (type == DataBuffer.TYPE_INT) { 
     
    12911214      } 
    12921215      while (ndx < pix.length) pix[ndx++] = new int[w * h]; // blank channel 
    1293       return makeImage(pix, w, h); 
     1216      return makeImage(pix, w, h, signed); 
    12941217    } 
    12951218    if (type == DataBuffer.TYPE_FLOAT) { 
     
    13251248    if (img == null) { 
    13261249      byte[][] data = new byte[1][width * height]; 
    1327       return makeImage(data, width, height); 
     1250      return makeImage(data, width, height, false); 
    13281251    } 
    13291252 
     
    13321255    if (needsPadding) { 
    13331256      Object pixels = getPixels(img); 
     1257      int pixelType = getPixelType(img); 
     1258      boolean signed = FormatTools.isSigned(pixelType); 
    13341259 
    13351260      if (pixels instanceof byte[][]) { 
     
    13401265            false, 1, img.getWidth(), width, height); 
    13411266        } 
    1342         return makeImage(newBytes, width, height); 
     1267        return makeImage(newBytes, width, height, signed); 
    13431268      } 
    13441269      else if (pixels instanceof short[][]) { 
     
    13491274            ImageTools.padImage(b[i], false, 1, img.getWidth(), width, height); 
    13501275        } 
    1351         return makeImage(newShorts, width, height); 
     1276        return makeImage(newShorts, width, height, signed); 
    13521277      } 
    13531278      else if (pixels instanceof int[][]) { 
     
    13581283            false, 1, img.getWidth(), width, height); 
    13591284        } 
    1360         return makeImage(newInts, width, height); 
     1285        return makeImage(newInts, width, height, signed); 
    13611286      } 
    13621287      else if (pixels instanceof float[][]) { 
     
    14021327  /** 
    14031328   * Perform autoscaling on the given BufferedImage; 
    1404    * map min to 0 and max to 255.  If the BufferedImage has 8 bit data, then 
    1405    * nothing happens. 
     1329   * map min to 0 and max to 255. 
     1330   * If the BufferedImage has 8 bit data, then nothing happens. 
    14061331   */ 
    14071332  public static BufferedImage autoscale(BufferedImage img, int min, int max) { 
    14081333    Object pixels = getPixels(img); 
     1334    int pixelType = getPixelType(img); 
     1335    boolean signed = FormatTools.isSigned(pixelType); 
    14091336 
    14101337    if (pixels instanceof byte[][]) return img; 
     
    14261353      } 
    14271354 
    1428       return makeImage(out, img.getWidth(), img.getHeight()); 
     1355      return makeImage(out, img.getWidth(), img.getHeight(), signed); 
    14291356    } 
    14301357    else if (pixels instanceof int[][]) { 
     
    14441371      } 
    14451372 
    1446       return makeImage(out, img.getWidth(), img.getHeight()); 
     1373      return makeImage(out, img.getWidth(), img.getHeight(), signed); 
    14471374    } 
    14481375    else if (pixels instanceof float[][]) { 
     
    14621389      } 
    14631390 
    1464       return makeImage(out, img.getWidth(), img.getHeight()); 
     1391      return makeImage(out, img.getWidth(), img.getHeight(), signed); 
    14651392    } 
    14661393    else if (pixels instanceof double[][]) { 
     
    14801407      } 
    14811408 
    1482       return makeImage(out, img.getWidth(), img.getHeight()); 
     1409      return makeImage(out, img.getWidth(), img.getHeight(), signed); 
    14831410    } 
    14841411    return img; 
     
    15621489    } 
    15631490 
     1491    int pixelType = getPixelType(source); 
     1492 
    15641493    BufferedImage result = null; 
    15651494    ColorModel sourceModel = source.getColorModel(); 
     
    15871516    } 
    15881517    else { 
     1518      if (FormatTools.isSigned(pixelType)) { 
     1519        source = makeUnsigned(source); 
     1520        sourceModel = null; 
     1521      } 
    15891522      Image scaled = 
    15901523        scaleAWT(source, width, height, Image.SCALE_AREA_AVERAGING); 
     
    17251658    byte[][] indices = getPixelBytes(img, le); 
    17261659    if (indices.length > 1) return img; 
    1727     if (getPixelType(img) == FormatTools.UINT8) { 
     1660 
     1661    int pixelType = getPixelType(img); 
     1662    boolean signed = FormatTools.isSigned(pixelType); 
     1663    if (pixelType == FormatTools.UINT8) { 
    17281664      IndexColorModel model = (IndexColorModel) img.getColorModel(); 
    17291665      byte[][] b = new byte[3][indices[0].length]; 
     
    17331669        b[2][i] = (byte) (model.getBlue(indices[0][i] & 0xff) & 0xff); 
    17341670      } 
    1735       return makeImage(b, img.getWidth(), img.getHeight()); 
    1736     } 
    1737     else if (getPixelType(img) == FormatTools.UINT16) { 
     1671      return makeImage(b, img.getWidth(), img.getHeight(), signed); 
     1672    } 
     1673    else if (pixelType == FormatTools.UINT16) { 
    17381674      Index16ColorModel model = (Index16ColorModel) img.getColorModel(); 
    17391675      short[][] s = new short[3][indices[0].length / 2]; 
     
    17441680        s[2][i] = (short) (model.getRed(ndx) & 0xffff); 
    17451681      } 
    1746       return makeImage(s, img.getWidth(), img.getHeight()); 
     1682      return makeImage(s, img.getWidth(), img.getHeight(), signed); 
    17471683    } 
    17481684    return null; 
  • branches/4.1/components/bio-formats/src/loci/formats/gui/BufferedImageReader.java

    r5587 r5615  
    3232 
    3333/** 
    34  * Utility methods for working with BufferedImage objects. 
     34 * A reader wrapper for reading image planes as BufferedImage objects. 
    3535 * 
    3636 * <dl><dt><b>Source code:</b></dt> 
     
    7575    if (BufferedImage.class.isAssignableFrom(dataType)) { 
    7676      // native data type is compatible with BufferedImage 
    77       return (BufferedImage) openData(no, x, y, w, h); 
     77      return (BufferedImage) openPlane(no, x, y, w, h); 
    7878    } 
    7979    else { 
  • branches/4.1/components/bio-formats/src/loci/formats/gui/DataConverter.java

    r5191 r5615  
    7979  // -- Fields -- 
    8080 
     81  // TODO - Use byte[] instead of BufferedImage for conversion pipeline. 
    8182  private FileStitcher reader = new FileStitcher(true); 
    8283  private DimensionSwapper swap = new DimensionSwapper(reader); 
    8384  private BufferedImageReader biReader = new BufferedImageReader(swap); 
    8485  private ImageWriter writer = new ImageWriter(); 
     86  private BufferedImageWriter biWriter = new BufferedImageWriter(writer); 
    8587  private JFileChooser rc, wc; 
    8688  private boolean shutdown, force = true; 
     
    631633 
    632634                  writer.setId(outFile); 
    633                   writer.saveImage(img, shutdown || filePlane == planesPerFile); 
     635                  biWriter.saveImage(img, 
     636                    shutdown || filePlane == planesPerFile); 
    634637                  if (shutdown) break; 
    635638                } 
  • branches/4.1/components/bio-formats/src/loci/formats/gui/ImageViewer.java

    r5523 r5615  
    103103 
    104104  /** Current format writer. */ 
    105   protected IFormatWriter myWriter; 
     105  protected BufferedImageWriter myWriter; 
    106106 
    107107  /** Reader for files on disk. */ 
     
    141141    fileReader = new ChannelMerger(new FileStitcher()); 
    142142    myReader = new BufferedImageReader(fileReader); 
    143     myWriter = fileWriter = new ImageWriter(); 
     143    fileWriter = new ImageWriter(); 
     144    myWriter = new BufferedImageWriter(fileWriter); 
    144145 
    145146    // NB: avoid dependencies on optional loci.ome.io package 
     
    743744 
    744745  /** 
    745    * Opens the given data source using the specified reader 
     746   * Opens from the given data source using the specified reader 
    746747   * in a separate thread. 
    747748   */ 
     
    760761 
    761762  /** 
    762    * Opens the given data source using the specified reader 
     763   * Saves to the given data destination using the specified writer 
    763764   * in a separate thread. 
    764765   */ 
     
    770771        } 
    771772        catch (IOException exc) { LogTools.trace(exc); } 
    772         myWriter = w; 
     773        myWriter = BufferedImageWriter.makeBufferedImageWriter(w); 
    773774        save(id); 
    774775      } 
  • branches/4.1/components/bio-formats/src/loci/formats/in/APNGReader.java

    r5587 r5615  
    100100    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); 
    101101 
    102     BufferedImage data = (BufferedImage) openData(no, x, y, w, h); 
     102    BufferedImage data = (BufferedImage) openPlane(no, x, y, w, h); 
    103103    byte[][] t = AWTImageTools.getPixelBytes(data, false); 
    104104 
     
    110110  } 
    111111 
    112   /* @see loci.formats.IFormatReader#getNativeDataType() */ 
    113   public Class getNativeDataType() { 
    114     return BufferedImage.class; 
    115   } 
    116  
    117   /* @see loci.formats.IFormatReader#openData(int, int, int, int, int int) */ 
    118   public Object openData(int no, int x, int y, int w, int h) 
     112  /* @see loci.formats.IFormatReader#openPlane(int, int, int, int, int int) */ 
     113  public Object openPlane(int no, int x, int y, int w, int h) 
    119114    throws FormatException, IOException 
    120115  { 
     
    183178    dis.close(); 
    184179    BufferedImage first = (BufferedImage) 
    185       openData(0, 0, 0, getSizeX(), getSizeY()); 
     180      openPlane(0, 0, 0, getSizeX(), getSizeY()); 
    186181 
    187182    // paste current image onto first image 
     
    202197      blocks = null; 
    203198    } 
     199  } 
     200 
     201  // -- IFormatHandler API methods -- 
     202 
     203  /* @see loci.formats.IFormatHandler#getNativeDataType() */ 
     204  public Class getNativeDataType() { 
     205    return BufferedImage.class; 
    204206  } 
    205207 
  • branches/4.1/components/bio-formats/src/loci/formats/in/AmiraReader.java

    r5517 r5615  
    2525 
    2626import java.io.IOException; 
    27  
    2827import java.util.ArrayList; 
    2928import java.util.Arrays; 
    3029import java.util.Map; 
    31  
    3230import java.util.regex.Matcher; 
    3331import java.util.regex.Pattern; 
    34  
    3532import java.util.zip.InflaterInputStream; 
    3633 
    3734import loci.common.DataTools; 
    3835import loci.common.RandomAccessInputStream; 
    39  
    4036import loci.formats.FormatException; 
    4137import loci.formats.FormatReader; 
    4238import loci.formats.FormatTools; 
    4339import loci.formats.MetadataTools; 
    44  
    4540import loci.formats.meta.FilterMetadata; 
    4641import loci.formats.meta.MetadataStore; 
    47  
    4842import loci.formats.tools.AmiraParameters; 
    4943 
  • branches/4.1/components/bio-formats/src/loci/formats/in/ImageIOReader.java

    r5587 r5615  
    7474    throws FormatException, IOException 
    7575  { 
    76     BufferedImage data = (BufferedImage) openData(no, x, y, w, h); 
     76    BufferedImage data = (BufferedImage) openPlane(no, x, y, w, h); 
    7777    byte[] t = AWTImageTools.getBytes(data, false); 
    7878    System.arraycopy(t, 0, buf, 0, (int) Math.min(t.length, buf.length)); 
     
    8080  } 
    8181 
    82   /* @see loci.formats.IFormatReader#getNativeDataType() */ 
    83   public Class getNativeDataType() { 
    84     return BufferedImage.class; 
    85   } 
    86  
    87   /* @see loci.formats.IFormatReader#openData(int, int, int, int, int int) */ 
    88   public Object openData(int no, int x, int y, int w, int h) 
     82  /* @see loci.formats.IFormatReader#openPlane(int, int, int, int, int int) */ 
     83  public Object openPlane(int no, int x, int y, int w, int h) 
    8984    throws FormatException, IOException 
    9085  { 
     
    9893    dis.close(); 
    9994    return b.getSubimage(x, y, w, h); 
     95  } 
     96 
     97  // -- IFormatHandler API methods -- 
     98 
     99  /* @see loci.formats.IFormatHandler#getNativeDataType() */ 
     100  public Class getNativeDataType() { 
     101    return BufferedImage.class; 
    100102  } 
    101103 
  • branches/4.1/components/bio-formats/src/loci/formats/in/IvisionReader.java

    r5596 r5615  
    207207    status("Looking for XML metadata"); 
    208208    boolean xmlFound = false; 
    209     while (!xmlFound && in.getFilePointer() < in.length()) { 
     209    while (!xmlFound && in.getFilePointer() < in.length() - 6) { 
    210210      int len = (int) Math.min(8192, in.length() - in.getFilePointer()); 
    211211      String check = in.readString(len); 
  • branches/4.1/components/bio-formats/src/loci/formats/in/LegacyQTReader.java

    r5587 r5615  
    3939import loci.formats.FormatTools; 
    4040import loci.formats.MetadataTools; 
    41 import loci.formats.MissingLibraryException; 
    4241import loci.formats.gui.AWTImageTools; 
    4342import loci.formats.gui.LegacyQTTools; 
     
    8887    throws FormatException, IOException 
    8988  { 
    90     BufferedImage data = (BufferedImage) openData(no, x, y, w, h); 
     89    BufferedImage data = (BufferedImage) openPlane(no, x, y, w, h); 
    9190    byte[] tmp = AWTImageTools.getBytes(data, false); 
    9291    System.arraycopy(tmp, 0, buf, 0, (int) Math.min(tmp.length, buf.length)); 
     
    9493  } 
    9594 
    96   /* @see loci.formats.IFormatReader#getNativeDataType() */ 
    97   public Class getNativeDataType() { 
    98     return BufferedImage.class; 
    99   } 
    100  
    101   /* @see loci.formats.IFormatReader#openData(int, int, int, int, int int) */ 
    102   public Object openData(int no, int x, int y, int w, int h) 
     95  /* @see loci.formats.IFormatReader#openPlane(int, int, int, int, int int) */ 
     96  public Object openPlane(int no, int x, int y, int w, int h) 
    10397    throws FormatException, IOException 
    10498  { 
     
    138132      image = null; 
    139133    } 
     134  } 
     135 
     136  // -- IFormatHandler API methods -- 
     137 
     138  /* @see loci.formats.IFormatHandler#getNativeDataType() */ 
     139  public Class getNativeDataType() { 
     140    return BufferedImage.class; 
    140141  } 
    141142 
  • branches/4.1/components/bio-formats/src/loci/formats/in/LiFlimReader.java

    r5517 r5615  
    2727import java.io.DataInputStream; 
    2828import java.io.FileInputStream; 
     29import java.io.IOException; 
    2930import java.io.InputStream; 
    3031import java.io.StringReader; 
    31 import java.io.IOException; 
    3232import java.util.Arrays; 
    3333import java.util.Hashtable; 
     
    4747import loci.formats.FormatTools; 
    4848import loci.formats.MetadataTools; 
    49 import loci.formats.codec.ZlibCodec; 
    5049import loci.formats.meta.FilterMetadata; 
    5150import loci.formats.meta.MetadataStore; 
  • branches/4.1/components/bio-formats/src/loci/formats/in/MIASReader.java

    r5594 r5615  
    4444import loci.formats.ImageTools; 
    4545import loci.formats.MetadataTools; 
    46 import loci.formats.in.MinimalTiffReader; 
    4746import loci.formats.meta.FilterMetadata; 
    4847import loci.formats.meta.MetadataStore; 
  • branches/4.1/components/bio-formats/src/loci/formats/in/MNGReader.java

    r5587 r5615  
    8888    throws FormatException, IOException 
    8989  { 
    90     BufferedImage data = (BufferedImage) openData(no, x, y, w, h); 
     90    BufferedImage data = (BufferedImage) openPlane(no, x, y, w, h); 
    9191    byte[] tmp = AWTImageTools.getBytes(data, true); 
    9292    System.arraycopy(tmp, 0, buf, 0, (int) Math.min(tmp.length, buf.length)); 
     
    9494  } 
    9595 
    96   /* @see loci.formats.IFormatReader#getNativeDataType() */ 
    97   public Class getNativeDataType() { 
    98     return BufferedImage.class; 
    99   } 
    100  
    101   /* @see loci.formats.IFormatReader#openData(int, int, int, int, int int) */ 
    102   public Object openData(int no, int x, int y, int w, int h) 
     96  /* @see loci.formats.IFormatReader#openPlane(int, int, int, int, int int) */ 
     97  public Object openPlane(int no, int x, int y, int w, int h) 
    10398    throws FormatException, IOException 
    10499  { 
     
    140135    super.close(fileOnly); 
    141136    if (!fileOnly) offsets = lengths = null; 
     137  } 
     138 
     139  // -- IFormatHandler API methods -- 
     140 
     141  /* @see loci.formats.IFormatHandler#getNativeDataType() */ 
     142  public Class getNativeDataType() { 
     143    return BufferedImage.class; 
    142144  } 
    143145 
  • branches/4.1/components/bio-formats/src/loci/formats/out/ImageIOWriter.java

    r5433 r5615  
    3434import loci.formats.FormatTools; 
    3535import loci.formats.FormatWriter; 
    36 import loci.formats.MetadataTools; 
    3736import loci.formats.gui.AWTImageTools; 
    3837import loci.formats.meta.MetadataRetrieve; 
     
    8180  { 
    8281    MetadataRetrieve meta = getMetadataRetrieve(); 
    83     MetadataTools.verifyMinimumPopulated(meta, series); 
    84     int width = meta.getPixelsSizeX(series, 0).intValue(); 
    85     int height = meta.getPixelsSizeY(series, 0).intValue(); 
    86     int type = 
    87       FormatTools.pixelTypeFromString(meta.getPixelsPixelType(series, 0)); 
    88     Integer nChannels = meta.getLogicalChannelSamplesPerPixel(series, 0); 
    89     if (nChannels == null) { 
    90       warn("SamplesPerPixel #0 is null.  It is assumed to be 1."); 
    91     } 
    92     int channels = nChannels == null ? 1 : nChannels.intValue(); 
    93     boolean littleEndian = !meta.getPixelsBigEndian(series, 0).booleanValue(); 
    94  
    95     BufferedImage image = AWTImageTools.makeImage(buf, width, height, channels, 
    96       interleaved, FormatTools.getBytesPerPixel(type), 
    97       FormatTools.isFloatingPoint(type), littleEndian, 
    98       FormatTools.isSigned(type)); 
    99     saveImage(image, series, lastInSeries, last); 
     82    BufferedImage image = AWTImageTools.makeImage(buf, 
     83      interleaved, meta, series); 
     84    savePlane(image, series, lastInSeries, last); 
    10085  } 
    10186 
    102   /* @see loci.formats.IFormatWriter#saveImage(Image, int, boolean, boolean) */ 
    103   public void saveImage(Image image, int series, boolean lastInSeries, 
     87  /* @see loci.formats.IFormatWriter#savePlane(Object, int, boolean, boolean) */ 
     88  public void savePlane(Object plane, int series, boolean lastInSeries, 
    10489    boolean last) throws FormatException, IOException 
    10590  { 
    106     BufferedImage img = AWTImageTools.makeBuffered(image, cm); 
     91    if (!(plane instanceof Image)) { 
     92      throw new IllegalArgumentException( 
     93        "Object to save must be a java.awt.Image"); 
     94    } 
     95 
     96    BufferedImage img = AWTImageTools.makeBuffered((Image) plane, cm); 
    10797    int type = AWTImageTools.getPixelType(img); 
    10898    int[] types = getPixelTypes(); 
     
    124114  // -- IFormatHandler API methods -- 
    125115 
     116  /* @see loci.formats.IFormatHandler#getNativeDataType() */ 
     117  public Class getNativeDataType() { 
     118    return Image.class; 
     119  } 
     120 
    126121  /* @see loci.formats.IFormatHandler#close() */ 
    127122  public void close() throws IOException { 
  • branches/4.1/components/bio-formats/src/loci/formats/out/LegacyQTWriter.java

    r5585 r5615  
    2626import java.awt.Image; 
    2727import java.awt.image.BufferedImage; 
    28 import java.io.File; 
    2928import java.io.IOException; 
    3029 
     
    3332import loci.common.ReflectedUniverse; 
    3433import loci.formats.FormatException; 
    35 import loci.formats.FormatTools; 
    3634import loci.formats.FormatWriter; 
    37 import loci.formats.MetadataTools; 
    38 import loci.formats.MissingLibraryException; 
    3935import loci.formats.gui.AWTImageTools; 
    4036import loci.formats.gui.LegacyQTTools; 
     
    124120    boolean last) throws FormatException, IOException 
    125121  { 
    126     MetadataRetrieve r = getMetadataRetrieve(); 
    127     MetadataTools.verifyMinimumPopulated(r, series); 
    128     int width = r.getPixelsSizeX(series, 0).intValue(); 
    129     int height = r.getPixelsSizeY(series, 0).intValue(); 
    130     Integer channels = r.getLogicalChannelSamplesPerPixel(series, 0); 
    131     if (channels == null) { 
    132       warn("SamplesPerPixel #0 is null.  It is assumed to be 1."); 
    133     } 
    134     int c = channels == null ? 1 : channels.intValue(); 
    135     int type = FormatTools.pixelTypeFromString(r.getPixelsPixelType(series, 0)); 
    136     int bpp = FormatTools.getBytesPerPixel(type); 
    137     boolean little = !r.getPixelsBigEndian(series, 0).booleanValue(); 
    138  
    139     BufferedImage img = AWTImageTools.makeImage(buf, width, height, c, 
    140       interleaved, bpp, FormatTools.isFloatingPoint(type), little, 
    141       FormatTools.isSigned(type)); 
    142     saveImage(img, series, lastInSeries, last); 
    143   } 
    144  
    145   /* @see loci.formats.IFormatWriter#saveImage(Image, int, boolean, boolean) */ 
    146   public void saveImage(Image image, int series, boolean lastInSeries, 
     122    MetadataRetrieve meta = getMetadataRetrieve(); 
     123    BufferedImage image = AWTImageTools.makeImage(buf, 
     124      interleaved, meta, series); 
     125    savePlane(image, series, lastInSeries, last); 
     126  } 
     127 
     128  /* @see loci.formats.IFormatWriter#savePlane(Image, int, boolean, boolean) */ 
     129  public void savePlane(Object plane, int series, boolean lastInSeries, 
    147130    boolean last) throws FormatException, IOException 
    148131  { 
     132    if (!(plane instanceof Image)) { 
     133      throw new IllegalArgumentException( 
     134        "Object to save must be a java.awt.Image"); 
     135    } 
     136 
    149137    if (tools == null || r == null) { 
    150138      tools = new LegacyQTTools(); 
     
    153141    tools.checkQTLibrary(); 
    154142 
     143    BufferedImage img = AWTImageTools.makeBuffered((Image) plane); 
     144 
    155145    if (!initialized) { 
    156146      initialized = true; 
     
    158148      try { 
    159149        r.exec("QTSession.open()"); 
    160         BufferedImage img = AWTImageTools.makeBuffered(image); 
    161150        width = img.getWidth(); 
    162151        height = img.getHeight(); 
     
    218207      int intsPerRow = ((Integer) r.getVar("intsPerRow")).intValue() / 4; 
    219208 
    220       byte[][] px = AWTImageTools.getBytes(AWTImageTools.makeBuffered(image)); 
     209      byte[][] px = AWTImageTools.getBytes(img); 
    221210 
    222211      int[] pixels = new int[px[0].length]; 
     
    307296  // -- IFormatHandler API methods -- 
    308297 
     298  /* @see loci.formats.IFormatHandler#getNativeDataType() */ 
     299  public Class getNativeDataType() { 
     300    return Image.class; 
     301  } 
     302 
    309303  /* @see loci.formats.IFormatHandler#close() */ 
    310304  public void close() throws IOException { 
  • branches/4.1/components/bio-formats/src/loci/formats/out/OMETiffWriter.java

    r5612 r5615  
    199199  public void setId(String id) throws FormatException, IOException { 
    200200    if (id.equals(currentId)) return; 
    201     if (new Location(id).exists()) { 
     201    Location file = new Location(id); 
     202    if (file.exists() && file.length() > 0) { 
    202203      // FIXME 
    203204      throw new FormatException( 
  • branches/4.1/components/bio-formats/src/loci/formats/out/TiffWriter.java

    r5612 r5615  
    2424package loci.formats.out; 
    2525 
    26 import java.awt.Image; 
    2726import java.io.IOException; 
    2827import java.util.Vector; 
     
    9392 
    9493  // -- TiffWriter API methods -- 
    95  
    96   /** 
    97    * Saves the given image to the specified (possibly already open) file. 
    98    * The IFD hashtable allows specification of TIFF parameters such as bit 
    99    * depth, compression and units.  If this image is the last one in the file, 
    100    * the last flag must be set. 
    101    */ 
    102   public void saveImage(Image image, IFD ifd, boolean last) { 
    103     // TODO 
    104   } 
    10594 
    10695  /** 
  • branches/4.1/components/bio-formats/src/loci/formats/tools/AmiraParameters.java

    r5471 r5615  
    2525 
    2626import java.io.IOException; 
    27  
    2827import java.util.ArrayList; 
    2928import java.util.Iterator; 
     
    3433 
    3534import loci.common.RandomAccessInputStream; 
    36  
    3735import loci.formats.FormatException; 
    3836 
  • branches/4.1/components/test-suite/src/loci/tests/testng/FormatReaderTest.java

    r5533 r5615  
    3636import java.io.File; 
    3737import java.io.FileWriter; 
     38import java.io.IOException; 
    3839import java.util.Arrays; 
    3940import java.util.LinkedList; 
     
    428429        // if CreationDate is before 1995, it's probably invalid 
    429430        String date = retrieve.getImageCreationDate(i); 
    430         if (DateTools.getTime(date, DateTools.ISO8601_FORMAT) < 
     431        if (date != null && DateTools.getTime(date, DateTools.ISO8601_FORMAT) < 
    431432          DateTools.getTime("1995-01-01T00:00:00", DateTools.ISO8601_FORMAT)) 
    432433        { 
     
    834835        int imageCount = reader.getImageCount(); 
    835836        totalPlanes += imageCount; 
    836         for (int j=0; j<imageCount; j++) reader.openImage(j); 
     837        try { 
     838          for (int j=0; j<imageCount; j++) reader.openImage(j); 
     839        } 
     840        catch (IOException e) { 
     841          LogTools.trace(e); 
     842        } 
    837843      } 
    838844      long t2 = System.currentTimeMillis(); 
     
    854860    catch (Throwable t) { 
    855861      try { 
     862        LogTools.trace(t); 
    856863        File f = new File(new Location(file).getParent(), ".bioformats"); 
    857864        BufferedWriter w = new BufferedWriter(new FileWriter(f, true)); 
    858         w.write("\"" + file + "\" test=false\n"); 
     865        w.write("\"" + new Location(file).getName() + "\" test=false\n"); 
    859866        w.close(); 
    860867      } 
  • branches/4.1/components/test-suite/src/loci/tests/testng/FormatWriterTest.java

    r5575 r5615  
    105105      reader.setId(id); 
    106106    } 
    107     catch (FormatException e) { } 
    108     catch (IOException e) { } 
     107    catch (FormatException e) { LogTools.trace(e); } 
     108    catch (IOException e) { LogTools.trace(e); } 
     109    config.setId(id); 
    109110  } 
    110111 
     
    168169    String msg = null; 
    169170    try { 
    170       config.setId(id); 
    171  
    172171      int type = reader.getPixelType(); 
    173172      if (!writer.isSupportedType(type)) { 
     
    176175        return; 
    177176      } 
     177 
     178      /* debug */ System.out.println("id = " + id); 
    178179 
    179180      String prefix = id.substring(id.lastIndexOf(File.separator) + 1, 
     
    190191      writer.close(); 
    191192      writer.setMetadataRetrieve((MetadataRetrieve) meta); 
     193      /* debug */ System.out.println("metadata says there are " + meta.getImageCount() + " series"); 
    192194 
    193195      // convert the input file 
Note: See TracChangeset for help on using the changeset viewer.