//
// ConvertToOmeTiff.java
//

import java.awt.image.BufferedImage;
import java.util.Hashtable;
import loci.formats.*;
import loci.formats.ome.OMEXMLMetadata;
import loci.formats.out.TiffWriter;

/** Converts the given files to OME-TIFF format. */
public class ConvertToOmeTiff {

  public static void main(String[] args) throws Exception {
    if (args.length == 0) {
      System.out.println("Usage: java ConvertToOmeTiff file1 file2 ...");
      return;
    }
    ImageReader reader = new ImageReader();
    TiffWriter writer = new TiffWriter();
    // record metadata to OME-XML format
    OMEXMLMetadata omexmlMeta = new OMEXMLMetadata();
    reader.setMetadataStore(omexmlMeta);
    for (int i=0; i<args.length; i++) {
      String id = args[i];
      String outId = id + ".tif";
      System.out.print("Converting " + id + " to " + outId + " ");
      reader.setId(id); 
      int imageCount = reader.getImageCount();
      // insert TiffData element into OME-XML
      // currently handles only single series (single Image, single Pixels)
      String xml = omexmlMeta.dumpXML();
      int pix = xml.indexOf("<Pixels ");
      int end = xml.indexOf("/>", pix);
      xml = xml.substring(0, end) +
        "><TiffData/></Pixels>" + xml.substring(end + 2);
      // write out image planes
      for (int j=0; j<imageCount; j++) {
        BufferedImage plane = reader.openImage(j);
        Hashtable ifd = null;
        if (j == 0) {
          // save OME-XML metadata to TIFF file's first IFD
          ifd = new Hashtable();
          TiffTools.putIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION, xml);
        }
        // write plane to output file
        writer.setId(outId);
        writer.saveImage(plane, ifd, j == imageCount - 1);
        System.out.print(".");
      }
      System.out.println(" [done]");
    }
  }

}

@@ -66,36 +66,8 @@
 ge;%0A
-import java.util.Hashtable;%0A
 impo
@@ -82,17 +82,27 @@
 formats.
-*
+ImageReader
 ;%0Aimport
@@ -159,16 +159,19 @@
 ats.out.
+OME
 TiffWrit
@@ -486,24 +486,27 @@
 ader();%0A    
+OME
 TiffWriter w
@@ -517,16 +517,19 @@
 r = new 
+OME
 TiffWrit
@@ -542,234 +542,171 @@
     
-// record metadata to OME-XML format%0A    OMEXMLMetadata omexmlMeta = new OMEXMLMetadata();%0A    reader.setMetadataStore(omexmlMeta);%0A    for (int i=0; i%3Cargs.length; i++) %7B%0A      String id = args%5Bi%5D;%0A      String outId = id + %22
+for (int i=0; i%3Cargs.length; i++) %7B%0A      String id = args%5Bi%5D;%0A      int dot = id.indexOf(%22.%22);%0A      String outId = (dot %3E= 0 ? id.substring(0, dot) : id) + %22.ome
 .tif
@@ -779,418 +779,286 @@
 %22);%0A
+%0A
       
-reader.setId(id); %0A      int imageCount = reader.getImageCount();%0A      // insert TiffData element into
+// record metadata to OME-XML format%0A      OMEXMLMetadata omexmlMeta = new
  OME
--
 XML
-%0A      // currently handles only single series (single Image, single Pixels)%0A      String xml = omexmlMeta.dumpXML();%0A      int pix = xml.indexOf(%22%3CPixels %22);%0A      int end = xml.indexOf(%22/%3E%22, pix);%0A      xml = xml.substring(0, end) +%0A        %22%3E%3CTiffData/%3E%3C/Pixels%3E%22 + xml.substring(end + 2
+Metadata();%0A      reader.setMetadataStore(omexmlMeta);%0A      reader.setId(id); %0A%0A      // configure OME-TIFF writer%0A      writer.setMetadataRetrieve(omexmlMeta);%0A      writer.setId(outId
 );%0A
+%0A
     
@@ -1085,16 +1085,63 @@
  planes%0A
+      int imageCount = reader.getImageCount();%0A
       fo
@@ -1228,235 +1228,8 @@
 j);%0A
-        Hashtable ifd = null;%0A        if (j == 0) %7B%0A          // save OME-XML metadata to TIFF file's first IFD%0A          ifd = new Hashtable();%0A          TiffTools.putIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION, xml);%0A        %7D%0A
     
@@ -1266,37 +1266,8 @@
 ile%0A
-        writer.setId(outId);%0A
     
@@ -1297,13 +1297,8 @@
 ane,
- ifd,
  j =
@@ -1351,24 +1351,68 @@
 %22);%0A      %7D%0A
+      writer.close();%0A      reader.close();%0A
       System

Update OME-TIFF conversion program to use most current API.