Changeset 5590


Ignore:
Timestamp:
10/14/09 02:08:23 (10 years ago)
Author:
curtis
Message:

Progress toward removal of AWT from Bio-Formats writer logic:

  • Eliminate IFormatWriter.saveImage in favor of more general savePlane.
  • Lots of corresponding API cleanup.
  • Several utils classes still need updating.
  • OME Metadata Editor needs tweaking.
  • Readers and writers need testing.
Location:
trunk/components
Files:
2 added
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bf-ice/src/loci/ice/formats/IFormatWriterI.java

    r5490 r5590  
    2525 
    2626import Ice.Current; 
    27 import java.awt.Image; 
    2827import java.awt.image.ColorModel; 
    2928import java.io.IOException; 
     
    7271      exc.printStackTrace(); 
    7372    } 
    74   } 
    75  
    76   public void saveImage(Image image, boolean last, Current current) 
    77     throws FormatException, IOException 
    78   { 
    79     writer.saveImage(image, last); 
    80   } 
    81  
    82   public void saveImage(Image image, int series, boolean lastInSeries, 
    83     boolean last, Current current) throws FormatException, IOException 
    84   { 
    85     writer.saveImage(image, series, lastInSeries, last); 
    8673  } 
    8774 
  • trunk/components/bio-formats/src/loci/formats/ChannelFiller.java

    r5387 r5590  
    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); 
  • trunk/components/bio-formats/src/loci/formats/ChannelSeparator.java

    r5403 r5590  
    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} 
  • trunk/components/bio-formats/src/loci/formats/DimensionSwapper.java

    r5587 r5590  
    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 
  • trunk/components/bio-formats/src/loci/formats/FileStitcher.java

    r5587 r5590  
    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 { 
  • trunk/components/bio-formats/src/loci/formats/FormatHandler.java

    r5425 r5590  
    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 -- 
  • trunk/components/bio-formats/src/loci/formats/FormatReader.java

    r5587 r5590  
    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 { 
  • trunk/components/bio-formats/src/loci/formats/FormatWriter.java

    r5575 r5590  
    9090  } 
    9191 
    92   /* @see IFormatWriter#saveImage(Image, boolean) */ 
    93   public void saveImage(Image image, boolean last) 
     92  /* @see IFormatWriter#savePlane(Object, boolean) */ 
     93  public void savePlane(Object plane, boolean last) 
    9494    throws FormatException, IOException 
    9595  { 
    96     saveImage(image, 0, last, last); 
    97   } 
    98  
    99   /* @see IFormatWriter#saveImage(Image, int, boolean, boolean) */ 
    100   public void saveImage(Image image, int series, boolean lastInSeries, 
     96    savePlane(plane, 0, last, last); 
     97  } 
     98 
     99  /* @see IFormatWriter#savePlane(Image, int, boolean, boolean) */ 
     100  public void savePlane(Object plane, int series, boolean lastInSeries, 
    101101    boolean last) throws FormatException, IOException 
    102102  { 
    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(); 
    111     } 
    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); 
     103    // NB: Writers use byte arrays by default as the native type. 
     104    if (!(plane instanceof byte[])) { 
     105      throw new IllegalArgumentException("Object to save must be a byte[]"); 
     106    } 
     107    saveBytes((byte[]) plane, series, lastInSeries, last); 
    132108  } 
    133109 
     
    135111  public void setInterleaved(boolean interleaved) { 
    136112    this.interleaved = interleaved; 
     113  } 
     114 
     115  /* @see IFormatWriter#isInterleaved() */ 
     116  public boolean isInterleaved() { 
     117    return interleaved; 
    137118  } 
    138119 
  • trunk/components/bio-formats/src/loci/formats/IFormatHandler.java

    r4953 r5590  
    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; 
  • trunk/components/bio-formats/src/loci/formats/IFormatReader.java

    r5587 r5590  
    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 
  • trunk/components/bio-formats/src/loci/formats/IFormatWriter.java

    r5575 r5590  
    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. */ 
  • trunk/components/bio-formats/src/loci/formats/ImageReader.java

    r5587 r5590  
    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 { 
  • trunk/components/bio-formats/src/loci/formats/ImageWriter.java

    r5575 r5590  
    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 { 
  • trunk/components/bio-formats/src/loci/formats/ReaderWrapper.java

    r5587 r5590  
    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 
  • trunk/components/bio-formats/src/loci/formats/gui/AWTImageTools.java

    r5548 r5590  
    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, signed); 
    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; 
     
    17251652    byte[][] indices = getPixelBytes(img, le); 
    17261653    if (indices.length > 1) return img; 
    1727     if (getPixelType(img) == FormatTools.UINT8) { 
     1654 
     1655    int pixelType = getPixelType(img); 
     1656    boolean signed = FormatTools.isSigned(pixelType); 
     1657    if (pixelType == FormatTools.UINT8) { 
    17281658      IndexColorModel model = (IndexColorModel) img.getColorModel(); 
    17291659      byte[][] b = new byte[3][indices[0].length]; 
     
    17331663        b[2][i] = (byte) (model.getBlue(indices[0][i] & 0xff) & 0xff); 
    17341664      } 
    1735       return makeImage(b, img.getWidth(), img.getHeight()); 
    1736     } 
    1737     else if (getPixelType(img) == FormatTools.UINT16) { 
     1665      return makeImage(b, img.getWidth(), img.getHeight(), signed); 
     1666    } 
     1667    else if (pixelType == FormatTools.UINT16) { 
    17381668      Index16ColorModel model = (Index16ColorModel) img.getColorModel(); 
    17391669      short[][] s = new short[3][indices[0].length / 2]; 
     
    17441674        s[2][i] = (short) (model.getRed(ndx) & 0xffff); 
    17451675      } 
    1746       return makeImage(s, img.getWidth(), img.getHeight()); 
     1676      return makeImage(s, img.getWidth(), img.getHeight(), signed); 
    17471677    } 
    17481678    return null; 
  • trunk/components/bio-formats/src/loci/formats/gui/BufferedImageReader.java

    r5587 r5590  
    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 { 
  • trunk/components/bio-formats/src/loci/formats/gui/DataConverter.java

    r5191 r5590  
    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                } 
  • trunk/components/bio-formats/src/loci/formats/gui/ImageViewer.java

    r5523 r5590  
    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      } 
  • trunk/components/bio-formats/src/loci/formats/in/APNGReader.java

    r5587 r5590  
    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 
  • trunk/components/bio-formats/src/loci/formats/in/ImageIOReader.java

    r5587 r5590  
    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 
  • trunk/components/bio-formats/src/loci/formats/in/LegacyQTReader.java

    r5587 r5590  
    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, false); 
    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  { 
     
    138133      image = null; 
    139134    } 
     135  } 
     136 
     137  // -- IFormatHandler API methods -- 
     138 
     139  /* @see loci.formats.IFormatHandler#getNativeDataType() */ 
     140  public Class getNativeDataType() { 
     141    return BufferedImage.class; 
    140142  } 
    141143 
  • trunk/components/bio-formats/src/loci/formats/in/MNGReader.java

    r5587 r5590  
    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 
  • trunk/components/bio-formats/src/loci/formats/out/ImageIOWriter.java

    r5433 r5590  
    8181  { 
    8282    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); 
     83    BufferedImage image = AWTImageTools.makeImage(buf, 
     84      interleaved, meta, series); 
     85    savePlane(image, series, lastInSeries, last); 
    10086  } 
    10187 
    102   /* @see loci.formats.IFormatWriter#saveImage(Image, int, boolean, boolean) */ 
    103   public void saveImage(Image image, int series, boolean lastInSeries, 
     88  /* @see loci.formats.IFormatWriter#savePlane(Object, int, boolean, boolean) */ 
     89  public void savePlane(Object plane, int series, boolean lastInSeries, 
    10490    boolean last) throws FormatException, IOException 
    10591  { 
    106     BufferedImage img = AWTImageTools.makeBuffered(image, cm); 
     92    if (!(plane instanceof Image)) { 
     93      throw new IllegalArgumentException( 
     94        "Object to save must be a java.awt.Image"); 
     95    } 
     96 
     97    BufferedImage img = AWTImageTools.makeBuffered((Image) plane, cm); 
    10798    int type = AWTImageTools.getPixelType(img); 
    10899    int[] types = getPixelTypes(); 
     
    124115  // -- IFormatHandler API methods -- 
    125116 
     117  /* @see loci.formats.IFormatHandler#getNativeDataType() */ 
     118  public Class getNativeDataType() { 
     119    return Image.class; 
     120  } 
     121 
    126122  /* @see loci.formats.IFormatHandler#close() */ 
    127123  public void close() throws IOException { 
  • trunk/components/bio-formats/src/loci/formats/out/LegacyQTWriter.java

    r5585 r5590  
    124124    boolean last) throws FormatException, IOException 
    125125  { 
    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, 
     126    MetadataRetrieve meta = getMetadataRetrieve(); 
     127    BufferedImage image = AWTImageTools.makeImage(buf, 
     128      interleaved, meta, series); 
     129    savePlane(image, series, lastInSeries, last); 
     130  } 
     131 
     132  /* @see loci.formats.IFormatWriter#savePlane(Image, int, boolean, boolean) */ 
     133  public void savePlane(Object plane, int series, boolean lastInSeries, 
    147134    boolean last) throws FormatException, IOException 
    148135  { 
     136    if (!(plane instanceof Image)) { 
     137      throw new IllegalArgumentException( 
     138        "Object to save must be a java.awt.Image"); 
     139    } 
     140 
    149141    if (tools == null || r == null) { 
    150142      tools = new LegacyQTTools(); 
     
    153145    tools.checkQTLibrary(); 
    154146 
     147    BufferedImage img = AWTImageTools.makeBuffered((Image) plane); 
     148 
    155149    if (!initialized) { 
    156150      initialized = true; 
     
    158152      try { 
    159153        r.exec("QTSession.open()"); 
    160         BufferedImage img = AWTImageTools.makeBuffered(image); 
    161154        width = img.getWidth(); 
    162155        height = img.getHeight(); 
     
    218211      int intsPerRow = ((Integer) r.getVar("intsPerRow")).intValue() / 4; 
    219212 
    220       byte[][] px = AWTImageTools.getBytes(AWTImageTools.makeBuffered(image)); 
     213      byte[][] px = AWTImageTools.getBytes(img); 
    221214 
    222215      int[] pixels = new int[px[0].length]; 
     
    307300  // -- IFormatHandler API methods -- 
    308301 
     302  /* @see loci.formats.IFormatHandler#getNativeDataType() */ 
     303  public Class getNativeDataType() { 
     304    return Image.class; 
     305  } 
     306 
    309307  /* @see loci.formats.IFormatHandler#close() */ 
    310308  public void close() throws IOException { 
  • trunk/components/bio-formats/src/loci/formats/out/OMETiffWriter.java

    r5334 r5590  
    8686      // if programmer indicates which TiffData blocks map to which files using 
    8787      // UUID with FileName, we have all the information we need to write each 
    88       // plane to the correct file... assuming planes are fed to saveImage 
     88      // plane to the correct file... assuming planes are fed to saveBytes 
    8989      // according to the given dimension order 
    9090      // 
  • trunk/components/bio-formats/src/loci/formats/out/TiffWriter.java

    r5576 r5590  
    8080 
    8181  // -- TiffWriter API methods -- 
    82  
    83   /** 
    84    * Saves the given image to the specified (possibly already open) file. 
    85    * The IFD hashtable allows specification of TIFF parameters such as bit 
    86    * depth, compression and units.  If this image is the last one in the file, 
    87    * the last flag must be set. 
    88    */ 
    89   public void saveImage(Image image, IFD ifd, boolean last) { 
    90     // TODO 
    91   } 
    9282 
    9383  /** 
  • trunk/components/bio-formats/utils/MakeTestOmeTiff.java

    r5336 r5590  
    422422 
    423423    sb.setLength(0); 
     424    String schemaVersion = "2008-09"; 
     425    String schemaPrefix = "http://www.openmicroscopy.org/Schemas/OME/"; 
     426    String schemaPath = schemaPrefix + schemaVersion; 
    424427    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 
    425428      "<!-- Warning: this comment is an OME-XML metadata block, which " + 
     
    427430      "Please edit cautiously (if at all), and back up the original data " + 
    428431      "before doing so. For more information, see the OME-TIFF web site: " + 
    429       "http://loci.wisc.edu/ome/ome-tiff.html. --><OME " + 
    430       "xmlns=\"http://www.openmicroscopy.org/XMLschemas/OME/FC/ome.xsd\" " + 
     432      "http://loci.wisc.edu/ome/ome-tiff.html. -->\n" + 
     433      "<OME xmlns=\"" + schemaPath + "\" " + 
     434      "xmlns:bf=\"http://www.openmicroscopy.org/Schemas/BinaryFile/2008-09\" " + 
    431435      "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + 
    432436      "xsi:schemaLocation=\"" + 
    433       "http://www.openmicroscopy.org/XMLschemas/OME/FC/ome.xsd " + 
    434       "http://www.openmicroscopy.org/XMLschemas/OME/FC/ome.xsd\">"); 
     437      schemaPath + " " + schemaPath + "/ome.xsd\">"); 
    435438    for (int i=0; i<numImages; i++) { 
    436439      sb.append("<Image " + 
    437         "ID=\"openmicroscopy.org:Image:" + (i + 1) + "\" " + 
     440        "ID=\"Image:" + (i + 1) + "\" " + 
    438441        "Name=\"" + name + "\" " + 
    439         "DefaultPixels=\"openmicroscopy.org:Pixels:" + (i + 1) + "-1\">" + 
     442        "DefaultPixels=\"Pixels:" + (i + 1) + "\">" + 
    440443        "<CreationDate>" + creationDate + "</CreationDate>"); 
    441444      for (int p=0; p<numPixels[i]; p++) { 
    442445        sb.append("<Pixels " + 
    443           "ID=\"openmicroscopy.org:Pixels:" + (i + 1) + "-" + (p + 1) + "\" " + 
     446          "ID=\"Pixels:" + (i + 1) + "-" + (p + 1) + "\" " + 
    444447          "DimensionOrder=\"" + dimOrder[i][p] + "\" " + 
    445448          "PixelType=\"Uint8\" " + 
  • trunk/components/legacy/ome-editor/src/loci/ome/editor/MetadataPane.java

    r5334 r5590  
    479479        try { 
    480480          writer.setId(outId); 
    481           writer.saveImage(plane, ifd, i == imageCount - 1); 
     481          // CTR FIXME 
     482          //writer.saveImage(plane, ifd, i == imageCount - 1); 
    482483        } 
    483484        catch (Exception exc) { 
     
    536537      try { 
    537538        writer.setId(outId); 
    538         writer.saveImage(plane, ifd, i == imageCount - 1); 
     539        // CTR FIXME 
     540        //writer.saveImage(plane, ifd, i == imageCount - 1); 
    539541      } 
    540542      catch (Exception exc) { 
  • trunk/components/test-suite/src/loci/tests/testng/FormatWriterTest.java

    r5575 r5590  
    202202        for (int image=0; image<imageCount; image++) { 
    203203          boolean lastImage = image == imageCount - 1; 
    204           writer.saveImage(reader.openImage(image), series, 
     204          writer.saveBytes(reader.openBytes(image), series, 
    205205            lastImage, lastImage && lastSeries); 
    206206        } 
  • trunk/components/visbio/src/loci/visbio/data/ExportPane.java

    r5272 r5590  
    4242import loci.formats.FormatException; 
    4343import loci.formats.FormatTools; 
    44 import loci.formats.ImageWriter; 
     44import loci.formats.gui.AWTImageTools; 
     45import loci.formats.gui.BufferedImageWriter; 
    4546import loci.formats.out.TiffWriter; 
    4647import loci.formats.tiff.IFD; 
     
    116117 
    117118  /** Writer for saving images to disk. */ 
    118   private ImageWriter saver; 
     119  private BufferedImageWriter saver; 
    119120 
    120121  /** Data object from which exportable data will be derived. */ 
     
    142143    super("Export data"); 
    143144    this.bio = bio; 
    144     saver = new ImageWriter(); 
     145    saver = new BufferedImageWriter(); 
    145146 
    146147    // -- Page 1 -- 
     
    228229      public void run() { 
    229230        try { 
    230           TiffWriter tiffSaver = null; 
    231           if (format.equals("TIFF")) { 
    232             tiffSaver = (TiffWriter) saver.getWriter(TiffWriter.class); 
    233           } 
    234231          int count = 0; 
    235232          int max = 2 * numTotal; 
     
    270267              task.setStatus(count++, max, 
    271268                "Writing #" + (i + 1) + "/" + numTotal); 
    272               if (tiffSaver == null) { 
    273                 saver.setId(filename); 
    274                 saver.saveImage(image, true); 
    275               } 
    276               else { 
    277                 // save image to TIFF file 
    278                 IFD ifd = new IFD(); 
    279                 ifd.putIFDValue(IFD.SOFTWARE, 
    280                   VisBio.TITLE + " " + VisBio.VERSION); 
    281                 if (doLZW) { 
    282                   ifd.putIFDValue(IFD.COMPRESSION, TiffCompression.LZW); 
    283                   // do horizontal differencing 
    284                   ifd.putIFDValue(IFD.PREDICTOR, 2); 
    285                 } 
    286                 tiffSaver.setId(filename); 
    287                 tiffSaver.saveImage(image, ifd, true); 
    288               } 
     269              saver.setId(filename); 
     270              if (doLZW) saver.setCompression("LZW"); 
     271              saver.saveImage(AWTImageTools.makeBuffered(image), true); 
    289272            } 
    290273            else { 
     
    301284                  "Writing #" + img + "/" + numTotal); 
    302285                boolean last = j == lengths[excl] - 1; 
    303                 if (tiffSaver == null) { 
    304                   saver.setId(filename); 
    305                   saver.saveImage(image, last); 
    306                 } 
    307                 else { 
    308                   // save image to TIFF file 
    309                   IFD ifd = new IFD(); 
    310                   ifd.putIFDValue(IFD.SOFTWARE, 
    311                     VisBio.TITLE + " " + VisBio.VERSION); 
    312                   if (doLZW) { 
    313                     ifd.putIFDValue(IFD.COMPRESSION, TiffCompression.LZW); 
    314                     // do horizontal differencing 
    315                     ifd.putIFDValue(IFD.PREDICTOR, 2); 
    316                   } 
    317                   tiffSaver.setId(filename); 
    318                   tiffSaver.saveImage(image, ifd, last); 
    319                 } 
     286                saver.setId(filename); 
     287                if (doLZW) saver.setCompression("LZW"); 
     288                saver.saveImage(AWTImageTools.makeBuffered(image), last); 
    320289              } 
    321290            } 
  • trunk/components/visbio/src/loci/visbio/ome/ImageUploader.java

    r5093 r5590  
    3030import loci.formats.StatusEvent; 
    3131import loci.formats.StatusListener; 
     32import loci.formats.gui.BufferedImageWriter; 
    3233import loci.formats.meta.MetadataRetrieve; 
    3334import loci.formats.meta.MetadataStore; 
     
    6566    try { 
    6667      OMEWriter writer = new OMEWriter(); 
     68      BufferedImageWriter biWriter = new BufferedImageWriter(writer); 
    6769      MetadataStore store = MetadataTools.createOMEXMLMetadata(); 
    6870      store.setRoot(data.getOMEXMLRoot()); 
     
    9193        pos[1] = zct[0]; 
    9294        System.arraycopy(cPos, 0, pos, 2, cPos.length); 
    93         writer.saveImage(data.getImage(pos), i == total - 1); 
     95        biWriter.saveImage(data.getImage(pos), i == total - 1); 
    9496      } 
    9597 
  • trunk/components/visbio/src/loci/visbio/view/CaptureHandler.java

    r5093 r5590  
    3434 
    3535import loci.formats.FormatException; 
    36 import loci.formats.ImageWriter; 
     36import loci.formats.gui.BufferedImageWriter; 
    3737import loci.formats.gui.ExtensionFileFilter; 
    3838import loci.visbio.SystemManager; 
     
    162162    new Thread("VisBio-SnapshotThread-" + window.getName()) { 
    163163      public void run() { 
    164         ImageWriter writer = new ImageWriter(); 
     164        BufferedImageWriter writer = new BufferedImageWriter(); 
    165165        try { 
    166166          writer.setId(id); 
     
    253253        // step incrementally from position to position, grabbing images 
    254254        int count = 1; 
    255         ImageWriter writer = new ImageWriter(); 
     255        BufferedImageWriter writer = new BufferedImageWriter(); 
    256256        double[] mxStart = (double[]) pos.elementAt(0); 
    257257        for (int i=1; i<size; i++) { 
Note: See TracChangeset for help on using the changeset viewer.