Changeset 2682


Ignore:
Timestamp:
04/26/07 11:44:53 (13 years ago)
Author:
melissa
Message:
  • Converted OME uploader to use the IFormatWriter API; updated VisBio and ImageJ plugins as needed.
  • Added saveBytes(String, byte[], boolean) to IFormatWriter.
Location:
trunk/loci
Files:
1 added
3 deleted
13 edited

Legend:

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

    r2601 r2682  
    3737   */ 
    3838  void saveImage(String id, Image image, boolean last) 
     39    throws FormatException, IOException; 
     40 
     41  /** 
     42   * Saves the given byte array to the specified (possibly already open) file. 
     43   * If this is the last array to be written, the last flag must be set. 
     44   */ 
     45  void saveBytes(String id, byte[] bytes, boolean last) 
    3946    throws FormatException, IOException; 
    4047 
  • trunk/loci/formats/ImageWriter.java

    r2587 r2682  
    155155  // -- IFormatWriter API methods -- 
    156156 
     157  /* @see IFormatWriter#saveBytes(String, byte[], boolean) */ 
     158  public void saveBytes(String id, byte[] bytes, boolean last) 
     159    throws FormatException, IOException 
     160  { 
     161    getWriter(id).saveBytes(id, bytes, last);  
     162  } 
     163 
    157164  /* @see IFormatWriter#saveImage(String, Image, boolean) */ 
    158165  public void saveImage(String id, Image image, boolean last) 
  • trunk/loci/formats/ome/OMEXMLMetadataStore.java

    r2673 r2682  
    156156   * of 0 will be used. 
    157157   */ 
    158   public String getDescription(String description, Integer n) { 
     158  public String getDescription(Integer n) { 
    159159    int ndx = n == null ? 0 : n.intValue(); 
    160160    return getAttribute("Image", "Description", ndx); 
  • trunk/loci/formats/out/AVIWriter.java

    r2601 r2682  
    9191  // -- IFormatWriter API methods -- 
    9292 
    93   /** 
    94    * Saves the given image to the specified (possibly already open) file. 
    95    * If this image is the last one in the file, the last flag must be set. 
    96    */ 
     93  /* @see loci.formats.IFormatWriter#saveBytes(String, byte[], boolean) */ 
     94  public void saveBytes(String id, byte[] bytes, boolean last) 
     95    throws FormatException, IOException 
     96  { 
     97    throw new FormatException("Not implemented yet."); 
     98  } 
     99 
     100  /* @see loci.formats.IFormatWriter#saveImage(String, Image, boolean) */ 
    97101  public void saveImage(String id, Image image, boolean last) 
    98102    throws FormatException, IOException 
     
    527531  } 
    528532 
    529   /** Reports whether the writer can save multiple images to a single file. */ 
     533  /* @see loci.formats.IFormatWriter#canDoStacks(String) */  
    530534  public boolean canDoStacks(String id) { return true; } 
    531535 
  • trunk/loci/formats/out/EPSWriter.java

    r2569 r2682  
    4848  // -- IFormatWriter API methods -- 
    4949 
    50   /** 
    51    * Saves the given image to the specified (possibly already open) file. 
    52    * If this image is the last one in the file, the last flag must be set. 
    53    */ 
     50  /* @see loci.formats.IFormatWriter#saveBytes(String, byte[], boolean) */ 
     51  public void saveBytes(String id, byte[] bytes, boolean last) 
     52    throws FormatException, IOException 
     53  { 
     54    throw new FormatException("Not implemented yet."); 
     55  } 
     56 
     57  /* @see loci.formats.IFormatWriter#saveImage(String, Image, boolean) */  
    5458  public void saveImage(String id, Image image, boolean last) 
    5559    throws FormatException, IOException 
     
    151155  } 
    152156 
    153   /** Reports whether the writer can save multiple images to a single file. */ 
     157  /* @see loci.formats.IFormatWriter#canDoStacks(String) */  
    154158  public boolean canDoStacks(String id) { return false; } 
    155159 
  • trunk/loci/formats/out/ImageIOWriter.java

    r2569 r2682  
    6868  // -- IFormatWriter API methods -- 
    6969 
    70   /** 
    71    * Saves the given image to the specified (possibly already open) file. 
    72    * The last flag is ignored, since this writer produces single-image files. 
    73    */ 
     70  /* @see loci.formats.IFormatWriter#saveBytes(String, byte[], boolean) */ 
     71  public void saveBytes(String id, byte[] bytes, boolean last) 
     72    throws FormatException, IOException 
     73  { 
     74    throw new FormatException("Not implemented yet."); 
     75  } 
     76 
     77  /* @see loci.formats.IFormatWriter#saveImage(String, Image, boolean) */  
    7478  public void saveImage(String id, Image image, boolean last) 
    7579    throws FormatException, IOException 
     
    9296  } 
    9397 
    94   /** Reports whether the writer can save multiple images to a single file. */ 
     98  /* @see loci.formats.IFormatWriter#canDoStacks(String) */  
    9599  public boolean canDoStacks(String id) { return false; } 
    96100 
  • trunk/loci/formats/out/LegacyQTWriter.java

    r2569 r2682  
    106106  // -- IFormatWriter API methods -- 
    107107 
    108   /* @see loci.formats.IFormatWriter#save(String, Image, boolean) */ 
     108  /* @see loci.formats.IFormatWriter#saveBytes(String, byte[], boolean) */ 
     109  public void saveBytes(String id, byte[] bytes, boolean last) 
     110    throws FormatException, IOException 
     111  { 
     112    throw new FormatException("Not implemented yet."); 
     113  } 
     114 
     115  /* @see loci.formats.IFormatWriter#saveImage(String, Image, boolean) */ 
    109116  public void saveImage(String id, Image image, boolean last) 
    110117    throws FormatException, IOException 
  • trunk/loci/formats/out/QTWriter.java

    r2601 r2682  
    149149 
    150150  // -- IFormatWriter API methods -- 
     151 
     152  /* @see loci.formats.IFormatWriter#saveBytes(String, byte[], boolean) */ 
     153  public void saveBytes(String id, byte[] bytes, boolean last) 
     154    throws FormatException, IOException 
     155  { 
     156    throw new FormatException("Not implemented yet."); 
     157  } 
    151158 
    152159  /* @see loci.formats.IFormatWriter#saveImage(String, Image, boolean) */ 
  • trunk/loci/formats/out/TiffWriter.java

    r2601 r2682  
    107107  // -- IFormatWriter API methods -- 
    108108 
     109  /* @see loci.formats.IFormatWriter#saveBytes(String, byte[], boolean) */ 
     110  public void saveBytes(String id, byte[] bytes, boolean last) 
     111    throws FormatException, IOException 
     112  { 
     113    throw new FormatException("Not implemented yet."); 
     114  } 
     115 
    109116  /* @see loci.formats.IFormatWriter#save(String, Image, boolean) */ 
    110117  public void saveImage(String id, Image image, boolean last) 
  • trunk/loci/formats/using-bioformats.txt

    r2588 r2682  
    128128Following is a list of known oddities. 
    129129 
    130 o While the IFormatReader API provides methods to read a byte array or 
    131   BufferedImage, the IFormatWriter API only accepts a java.awt.Image. 
    132   For completeness, we should add a method to IFormatWriter that accepts an 
    133   array of bytes for writing.  The only reason for not doing so is that no 
    134   one has needed this feature (yet).  If you think this would be useful, 
    135   it can be added. 
    136  
    137130o IFormatWriter accepts Image objects, and not BufferedImages; yet all writers 
    138131  convert the Image to a BufferedImage.  You can still pass in a 
  • trunk/loci/plugins/Importer.java

    r2680 r2682  
    4040import java.util.*; 
    4141import javax.swing.Box; 
    42 import javax.swing.JFrame; 
    4342import loci.formats.*; 
    4443import loci.formats.ome.OMEReader; 
  • trunk/loci/plugins/LociUploader.java

    r2533 r2682  
    2727 
    2828import java.awt.TextField; 
    29 import java.util.Vector; 
    3029import ij.*; 
    3130import ij.gui.GenericDialog; 
     
    8685    try { 
    8786      IJ.showStatus("Starting upload..."); 
    88       OMEUploader ul = new OMEUploader(server, user, pass); 
     87      OMEWriter ul = new OMEWriter();  
     88      String id = server + "?user=" + user + "&password=" + pass;  
     89 
    8990      ImagePlus imp = WindowManager.getCurrentImage(); 
    9091      if (imp == null) { 
     
    9495      } 
    9596      ImageStack is = imp.getImageStack(); 
    96       Vector pixels = new Vector(); 
    9797      FileInfo fi = imp.getOriginalFileInfo(); 
    9898      OMEXMLMetadataStore store = new OMEXMLMetadataStore(); 
     
    133133          new Integer(FormatTools.UINT8), null, null, null, null); 
    134134      } 
     135      ul.setMetadataStore(store);  
    135136 
    136137      boolean little = !store.getBigEndian(null).booleanValue(); 
     
    140141        Object pix = is.getProcessor(i + 1).getPixels(); 
    141142 
     143        byte[] toUpload = null; 
     144 
    142145        if (pix instanceof byte[]) { 
    143           pixels.add((byte[]) pix); 
     146          toUpload = (byte[]) pix;  
    144147        } 
    145148        else if (pix instanceof short[]) { 
    146149          short[] s = (short[]) pix; 
    147           byte[] b = new byte[s.length * 2]; 
     150          toUpload = new byte[s.length * 2]; 
    148151          for (int j=0; j<s.length; j++) { 
    149             b[j*2] = little ? (byte) (s[j] & 0xff) :  
     152            toUpload[j*2] = little ? (byte) (s[j] & 0xff) :  
    150153              (byte) ((s[j] >>> 8) & 0xff); 
    151             b[j*2 + 1] = little ? (byte) ((s[j] >>> 8) & 0xff):  
     154            toUpload[j*2 + 1] = little ? (byte) ((s[j] >>> 8) & 0xff):  
    152155              (byte) (s[j] & 0xff);  
    153156          } 
    154           pixels.add(b); 
    155157        } 
    156158        else if (pix instanceof int[]) { 
     
    161163            int channels = store.getSizeC(null).intValue(); 
    162164            if (channels > 3) channels = 3; 
     165            toUpload = new byte[channels * rgb[0].length];  
    163166            for (int j=0; j<channels; j++) { 
    164               pixels.add(rgb[j]); 
     167              System.arraycopy(rgb[j], 0, toUpload, 0, rgb[j].length);  
    165168            } 
    166169          } 
    167170          else { 
    168171            int[] p = (int[]) pix; 
    169             byte[] b = new byte[4 * p.length]; 
     172            toUpload = new byte[4 * p.length]; 
    170173            for (int j=0; j<p.length; j++) { 
    171               b[j*4] = little ? (byte) (p[j] & 0xff) :  
     174              toUpload[j*4] = little ? (byte) (p[j] & 0xff) :  
    172175                (byte) ((p[j] >> 24) & 0xff);  
    173               b[j*4 + 1] = little ? (byte) ((p[j] >> 8) & 0xff) :  
     176              toUpload[j*4 + 1] = little ? (byte) ((p[j] >> 8) & 0xff) :  
    174177                (byte) ((p[j] >> 16) & 0xff);  
    175               b[j*4 + 2] = little ? (byte) ((p[j] >> 16) & 0xff) : 
     178              toUpload[j*4 + 2] = little ? (byte) ((p[j] >> 16) & 0xff) : 
    176179                (byte) ((p[j] >> 8) & 0xff);  
    177               b[j*4 + 3] = little ? (byte) ((p[j] >> 24) & 0xff) : 
     180              toUpload[j*4 + 3] = little ? (byte) ((p[j] >> 24) & 0xff) : 
    178181                (byte) (p[j] & 0xff);  
    179182            } 
     
    182185        else if (pix instanceof float[]) { 
    183186          float[] f = (float[]) pix; 
    184           byte[] b = new byte[f.length * 4]; 
     187          toUpload = new byte[f.length * 4]; 
    185188          for (int j=0; j<f.length; j++) { 
    186189            int k = Float.floatToIntBits(f[j]); 
    187             b[j*4] = little ? (byte) (k & 0xff) :  
     190            toUpload[j*4] = little ? (byte) (k & 0xff) :  
    188191              (byte) ((k >> 24) & 0xff);  
    189             b[j*4 + 1] = little ? (byte) ((k >> 8) & 0xff) :  
     192            toUpload[j*4 + 1] = little ? (byte) ((k >> 8) & 0xff) :  
    190193              (byte) ((k >> 16) & 0xff);  
    191             b[j*4 + 2] = little ? (byte) ((k >> 16) & 0xff) : 
     194            toUpload[j*4 + 2] = little ? (byte) ((k >> 16) & 0xff) : 
    192195              (byte) ((k >> 8) & 0xff);  
    193             b[j*4 + 3] = little ? (byte) ((k >> 24) & 0xff) : 
     196            toUpload[j*4 + 3] = little ? (byte) ((k >> 24) & 0xff) : 
    194197              (byte) (k & 0xff);  
    195198          } 
    196           pixels.add(b); 
    197         } 
    198       } 
    199  
    200       byte[][] planes = new byte[pixels.size()][]; 
    201       for (int i=0; i<pixels.size(); i++) { 
    202         planes[i] = (byte[]) pixels.get(i); 
     199        } 
     200       
     201        ul.saveBytes(id, toUpload, i == is.getSize() - 1);  
    203202      } 
    204203 
    205204      IJ.showStatus("Sending data to server..."); 
    206       ul.uploadPlanes(planes, 0, planes.length - 1, 1, store, true); 
    207       ul.logout(); 
     205      ul.close();  
    208206      IJ.showStatus("Upload finished."); 
    209207    } 
    210     catch (UploadException e) { 
     208    catch (Exception e) { 
    211209      IJ.error("Upload failed:\n" + e); 
    212210      e.printStackTrace(); 
  • trunk/loci/visbio/ome/ImageUploader.java

    r2499 r2682  
    2525 
    2626import java.util.*; 
     27import loci.formats.FormatTools; 
    2728import loci.formats.StatusEvent; 
    2829import loci.formats.StatusListener; 
    29 import loci.formats.ome.OMEUploader; 
    30 import loci.formats.ome.UploadException; 
     30import loci.formats.ome.OMEWriter; 
     31import loci.formats.ome.OMEXMLMetadataStore; 
    3132 
    3233/** 
     
    5657  { 
    5758    try {   
    58       OMEUploader ul = new OMEUploader(server, username, password); 
    59       String[] ids = data.getFilenames(); 
    60       ul.uploadFile(ids[0], true); 
     59      OMEWriter writer = new OMEWriter(); 
     60      OMEXMLMetadataStore store = new OMEXMLMetadataStore(); 
     61      store.setRoot(data.getOMENode()); 
     62      writer.setMetadataStore(store); 
     63   
     64      String id = server + "?user=" + username + "&password=" + password; 
     65 
     66      int numFiles = data.getFilenames().length; 
     67      int numImages = data.getImagesPerSource(); 
     68 
     69      for (int i=0; i<numFiles; i++) { 
     70        for (int j=0; j<numImages; j++) { 
     71          int[] coords = FormatTools.getZCTCoords(store.getDimensionOrder(null), 
     72            store.getSizeZ(null).intValue(), store.getSizeC(null).intValue(),  
     73            store.getSizeT(null).intValue(),  
     74            numImages*numFiles, numImages*i + j); 
     75          writer.saveImage(id,  
     76            data.getImage(new int[] {coords[0], coords[1], coords[2], j}),  
     77            (i == numFiles - 1) && (j == numImages - 1)); 
     78        } 
     79      } 
     80 
     81      writer.close(); 
    6182    } 
    62     catch (UploadException exc) { 
     83    catch (Exception exc) { 
    6384      notifyListeners(new StatusEvent(1, 1, 
    6485        "Error uploading (see error console for details)")); 
Note: See TracChangeset for help on using the changeset viewer.