//
// MakeLZW.java
//

import java.awt.image.BufferedImage;
import java.util.Hashtable;
import org.openmicroscopy.xml.OMENode;
import loci.formats.*;
import loci.formats.meta.MetadataStore;
import loci.formats.out.TiffWriter;

/** Converts the given image file to an LZW-compressed TIFF. */
public class MakeLZW {

  public static void main(String[] args) throws Exception {
    ImageReader reader = new ImageReader();
    MetadataStore omexmlMeta = MetadataTools.createOMEXMLMetadata();
    reader.setMetadataStore(omexmlMeta);
    TiffWriter writer = new TiffWriter();
    for (int i=0; i<args.length; i++) {
      String f = args[i];
      String nf = "lzw-" + f;
      System.out.print("Converting " + f + " to " + nf);
      reader.setId(f);
      writer.setId(nf);
      int blocks = reader.getImageCount();
      // CTR: FIXME: update this to be version-agnostic
      OMENode ome = (OMENode) omexmlMeta.getRoot();
      for (int b=0; b<blocks; b++) {
        System.out.print(".");
        BufferedImage img = reader.openImage(b);

        Hashtable ifd = new Hashtable();
        if (b == 0) {
          // preserve OME-XML block
          TiffTools.putIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION,
            ome.writeOME(false));
        }

        // save with LZW
        TiffTools.putIFDValue(ifd, TiffTools.COMPRESSION, TiffTools.LZW);
        TiffTools.putIFDValue(ifd, TiffTools.PREDICTOR, 2);

        // write file to disk
        writer.saveImage(img, ifd, b == blocks - 1);
      }
      System.out.println(" [done]");
    }
  }

}

@@ -92,38 +92,98 @@
 ort 
-org.openmicroscopy.xml.OMENode
+loci.formats.ImageReader;%0Aimport loci.formats.MetadataTools;%0Aimport loci.formats.TiffTools
 ;%0Aim
@@ -200,17 +200,37 @@
 formats.
-*
+meta.MetadataRetrieve
 ;%0Aimport
@@ -697,17 +697,22 @@
  String 
-f
+inFile
  = args%5B
@@ -728,18 +728,23 @@
  String 
-nf
+outFile
  = %22lzw-
@@ -747,17 +747,22 @@
 lzw-%22 + 
-f
+inFile
 ;%0A      
@@ -794,17 +794,22 @@
 ing %22 + 
-f
+inFile
  + %22 to 
@@ -812,18 +812,23 @@
  to %22 + 
-nf
+outFile
 );%0A     
@@ -841,17 +841,22 @@
 r.setId(
-f
+inFile
 );%0A     
@@ -873,10 +873,15 @@
 tId(
-nf
+outFile
 );%0A 
@@ -932,85 +932,61 @@
     
-// CTR: FIXME: update this to be version-agnostic%0A      OMENode ome = (OMENod
+String xml = MetadataTools.getOMEXML((MetadataRetriev
 e) o
@@ -998,17 +998,8 @@
 Meta
-.getRoot(
 );%0A 
@@ -1283,40 +1283,12 @@
 ION,
-%0A            ome.writeOME(false)
+ xml
 );%0A 

Update to version-agnostic OME-XML metadata store logic.