Changeset 2796


Ignore:
Timestamp:
05/18/07 10:27:16 (13 years ago)
Author:
curtis
Message:

Move testRead and testConvert into separate ConsoleTools class; eliminate
requirement for IFormatReaders and IFormatWriters themselves to implement them.

Location:
trunk/loci/formats
Files:
1 added
12 edited

Legend:

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

    r2786 r2796  
    142142  } 
    143143 
    144   public boolean testRead(String[] args) throws FormatException, IOException { 
    145     return FormatTools.testRead(this, args); 
    146   } 
    147  
    148144} 
  • trunk/loci/formats/ChannelSeparator.java

    r2786 r2796  
    171171  } 
    172172 
    173   public boolean testRead(String[] args) throws FormatException, IOException { 
    174     return FormatTools.testRead(this, args); 
    175   } 
    176  
    177173} 
  • trunk/loci/formats/FileStitcher.java

    r2786 r2796  
    622622  } 
    623623 
    624   /* @see IFormatReader#testRead(String[]) */ 
    625   public boolean testRead(String[] args) throws FormatException, IOException { 
    626     return FormatTools.testRead(this, args); 
    627   } 
    628  
    629624  // -- IFormatHandler API methods -- 
    630625 
  • trunk/loci/formats/FormatReader.java

    r2786 r2796  
    503503  } 
    504504 
    505   /* @see FormatReader#testRead(String[]) */ 
    506   public boolean testRead(String[] args) throws FormatException, IOException { 
    507     return FormatTools.testRead(this, args); 
    508   } 
    509  
    510505  // -- IFormatHandler API methods -- 
    511506 
  • trunk/loci/formats/FormatTools.java

    r2786 r2796  
    2525package loci.formats; 
    2626 
    27 import java.awt.Image; 
    28 import java.awt.image.BufferedImage; 
    29 import java.io.IOException; 
    30 import java.lang.reflect.Method; 
    31 import java.util.Arrays; 
    32 import java.util.Hashtable; 
    3327import java.util.StringTokenizer; 
    3428 
     
    108102 
    109103  private FormatTools() { } 
    110  
    111   // -- Utility methods - testing -- 
    112  
    113   /** 
    114    * A utility method for test reading a file from the command line, 
    115    * and displaying the results in a simple display. 
    116    */ 
    117   public static boolean testRead(IFormatReader reader, String[] args) 
    118     throws FormatException, IOException 
    119   { 
    120     String id = null; 
    121     boolean pixels = true; 
    122     boolean doMeta = true; 
    123     boolean thumbs = false; 
    124     boolean minmax = false; 
    125     boolean merge = false; 
    126     boolean stitch = false; 
    127     boolean separate = false; 
    128     boolean omexml = false; 
    129     boolean normalize = false; 
    130     boolean fastBlit = false; 
    131     int start = 0; 
    132     int end = Integer.MAX_VALUE; 
    133     int series = 0; 
    134     String map = null; 
    135     if (args != null) { 
    136       for (int i=0; i<args.length; i++) { 
    137         if (args[i].startsWith("-") && args.length > 1) { 
    138           if (args[i].equals("-nopix")) pixels = false; 
    139           else if (args[i].equals("-nometa")) doMeta = false; 
    140           else if (args[i].equals("-thumbs")) thumbs = true; 
    141           else if (args[i].equals("-minmax")) minmax = true; 
    142           else if (args[i].equals("-merge")) merge = true; 
    143           else if (args[i].equals("-stitch")) stitch = true; 
    144           else if (args[i].equals("-separate")) separate = true; 
    145           else if (args[i].equals("-omexml")) omexml = true; 
    146           else if (args[i].equals("-normalize")) normalize = true; 
    147           else if (args[i].equals("-fast")) fastBlit = true; 
    148           else if (args[i].equals("-debug")) FormatHandler.setDebug(true); 
    149           else if (args[i].equals("-level")) { 
    150             try { 
    151               FormatHandler.setDebugLevel(Integer.parseInt(args[++i])); 
    152             } 
    153             catch (NumberFormatException exc) { } 
    154           } 
    155           else if (args[i].equals("-range")) { 
    156             try { 
    157               start = Integer.parseInt(args[++i]); 
    158               end = Integer.parseInt(args[++i]); 
    159             } 
    160             catch (NumberFormatException exc) { } 
    161           } 
    162           else if (args[i].equals("-series")) { 
    163             try { 
    164               series = Integer.parseInt(args[++i]); 
    165             } 
    166             catch (NumberFormatException exc) { } 
    167           } 
    168           else if (args[i].equals("-map")) map = args[++i]; 
    169           else System.out.println("Ignoring unknown command flag: " + args[i]); 
    170         } 
    171         else { 
    172           if (id == null) id = args[i]; 
    173           else System.out.println("Ignoring unknown argument: " + args[i]); 
    174         } 
    175       } 
    176     } 
    177     if (FormatHandler.debug) { 
    178       System.out.println("Debugging at level " + FormatHandler.debugLevel); 
    179     } 
    180     if (id == null) { 
    181       String className = reader.getClass().getName(); 
    182       String format = reader.getFormat(); 
    183       String[] s = { 
    184         "To test read a file in " + format + " format, run:", 
    185         "  java " + className + " [-nopix] [-nometa] [-thumbs] [-minmax]", 
    186         "    [-merge] [-stitch] [-separate] [-omexml] [-normalize]", 
    187         "    [-fast] [-debug] [-range start end] [-series num] [-map id] file", 
    188         "", 
    189         "      file: the image file to read", 
    190         "    -nopix: read metadata only, not pixels", 
    191         "   -nometa: output only core metadata", 
    192         "   -thumbs: read thumbnails instead of normal pixels", 
    193         "   -minmax: compute min/max statistics", 
    194         "    -merge: combine separate channels into RGB image", 
    195         "   -stitch: stitch files with similar names", 
    196         " -separate: split RGB image into separate channels", 
    197         "   -omexml: populate OME-XML metadata", 
    198         "-normalize: normalize floating point images*", 
    199         "     -fast: paint RGB images as quickly as possible*", 
    200         "    -debug: turn on debugging output", 
    201         "    -range: specify range of planes to read (inclusive)", 
    202         "   -series: specify which image series to read", 
    203         "      -map: specify file on disk to which name should be mapped", 
    204         "", 
    205         "* = may result in loss of precision", 
    206         "" 
    207       }; 
    208       for (int i=0; i<s.length; i++) System.out.println(s[i]); 
    209       return false; 
    210     } 
    211     if (map != null) Location.mapId(id, map); 
    212     if (omexml) { 
    213       try { 
    214         // NB: avoid dependencies on optional loci.formats.ome package 
    215         Class c = Class.forName("loci.formats.ome.OMEXMLMetadataStore"); 
    216         MetadataStore ms = (MetadataStore) c.newInstance(); 
    217         reader.setMetadataStore(ms); 
    218       } 
    219       catch (Throwable t) { 
    220         // NB: error messages for missing OME-Java are printed later 
    221       } 
    222     } 
    223  
    224     // check file format 
    225     if (reader instanceof ImageReader) { 
    226       // determine format 
    227       ImageReader ir = (ImageReader) reader; 
    228       System.out.print("Checking file format "); 
    229       System.out.println("[" + ir.getFormat(id) + "]"); 
    230     } 
    231     else { 
    232       // verify format 
    233       System.out.print("Checking " + reader.getFormat() + " format "); 
    234       System.out.println(reader.isThisType(id) ? "[yes]" : "[no]"); 
    235     } 
    236  
    237     System.out.println("Initializing reader"); 
    238     if (stitch) { 
    239       reader = new FileStitcher(reader, true); 
    240       String pat = FilePattern.findPattern(new Location(id)); 
    241       if (pat != null) id = pat; 
    242     } 
    243     if (separate) reader = new ChannelSeparator(reader); 
    244     if (merge) reader = new ChannelMerger(reader); 
    245     MinMaxCalculator minMaxCalc = null; 
    246     if (minmax) reader = minMaxCalc = new MinMaxCalculator(reader); 
    247  
    248     StatusEchoer status = new StatusEchoer(); 
    249     reader.addStatusListener(status); 
    250  
    251     reader.close(); 
    252     reader.setNormalized(normalize); 
    253     reader.setMetadataFiltered(true); 
    254     reader.setMetadataCollected(doMeta); 
    255     long s1 = System.currentTimeMillis(); 
    256     reader.setId(id); 
    257     long e1 = System.currentTimeMillis(); 
    258     float sec1 = (e1 - s1) / 1000f; 
    259     System.out.println("Initialization took " + sec1 + "s"); 
    260  
    261     if (!normalize && reader.getPixelType() == FLOAT) { 
    262       throw new FormatException("Sorry, unnormalized floating point " + 
    263         "data is not supported. Please use the '-normalize' option."); 
    264     } 
    265  
    266     // read basic metadata 
    267     System.out.println(); 
    268     System.out.println("Reading core metadata"); 
    269     System.out.println(stitch ? 
    270       "File pattern = " + id : "Filename = " + reader.getCurrentFile()); 
    271     if (map != null) System.out.println("Mapped filename = " + map); 
    272     String[] used = reader.getUsedFiles(); 
    273     boolean usedValid = used != null && used.length > 0; 
    274     if (usedValid) { 
    275       for (int u=0; u<used.length; u++) { 
    276         if (used[u] == null) { 
    277           usedValid = false; 
    278           break; 
    279         } 
    280       } 
    281     } 
    282     if (!usedValid) { 
    283       System.out.println( 
    284         "************ Warning: invalid used files list ************"); 
    285     } 
    286     if (used == null) { 
    287       System.out.println("Used files = null"); 
    288     } 
    289     else if (used.length == 0) { 
    290       System.out.println("Used files = []"); 
    291     } 
    292     else if (used.length > 1) { 
    293       System.out.println("Used files:"); 
    294       for (int u=0; u<used.length; u++) System.out.println("\t" + used[u]); 
    295     } 
    296     else if (!id.equals(used[0])) { 
    297       System.out.println("Used files = [" + used[0] + "]"); 
    298     } 
    299     int seriesCount = reader.getSeriesCount(); 
    300     System.out.println("Series count = " + seriesCount); 
    301     for (int j=0; j<seriesCount; j++) { 
    302       reader.setSeries(j); 
    303  
    304       // read basic metadata for series #i 
    305       int imageCount = reader.getImageCount(); 
    306       boolean rgb = reader.isRGB(); 
    307       int sizeX = reader.getSizeX(); 
    308       int sizeY = reader.getSizeY(); 
    309       int sizeZ = reader.getSizeZ(); 
    310       int sizeC = reader.getSizeC(); 
    311       int sizeT = reader.getSizeT(); 
    312       int pixelType = reader.getPixelType(); 
    313       int effSizeC = reader.getEffectiveSizeC(); 
    314       int rgbChanCount = reader.getRGBChannelCount(); 
    315       int[] cLengths = reader.getChannelDimLengths(); 
    316       String[] cTypes = reader.getChannelDimTypes(); 
    317       int thumbSizeX = reader.getThumbSizeX(); 
    318       int thumbSizeY = reader.getThumbSizeY(); 
    319       boolean little = reader.isLittleEndian(); 
    320       String dimOrder = reader.getDimensionOrder(); 
    321       boolean orderCertain = reader.isOrderCertain(); 
    322       boolean interleaved = reader.isInterleaved(); 
    323  
    324       // output basic metadata for series #i 
    325       System.out.println("Series #" + j + ":"); 
    326       System.out.println("\tImage count = " + imageCount); 
    327       System.out.print("\tRGB = " + rgb + " (" + rgbChanCount + ")"); 
    328       if (merge) System.out.print(" (merged)"); 
    329       else if (separate) System.out.print(" (separated)"); 
    330       if (rgb != (rgbChanCount != 1)) { 
    331         System.out.println("\t************ Warning: RGB mismatch ************"); 
    332       } 
    333       System.out.println(); 
    334       System.out.println("\tInterleaved = " + interleaved); 
    335       System.out.println("\tWidth = " + sizeX); 
    336       System.out.println("\tHeight = " + sizeY); 
    337       System.out.println("\tSizeZ = " + sizeZ); 
    338       System.out.print("\tSizeC = " + sizeC); 
    339       if (sizeC != effSizeC) { 
    340         System.out.print(" (effectively " + effSizeC + ")"); 
    341       } 
    342       System.out.println(); 
    343       int cProduct = 1; 
    344       for (int i=0; i<cLengths.length; i++) { 
    345         System.out.println("\t\t#" + (i + 1) + " = " + 
    346           cTypes[i] + " (" + cLengths[i] + ")"); 
    347         cProduct *= cLengths[i]; 
    348       } 
    349       if (cLengths.length == 0 || cProduct != sizeC) { 
    350         System.out.println( 
    351           "\t************ Warning: C dimension mismatch ************"); 
    352       } 
    353       System.out.println("\tSizeT = " + sizeT); 
    354       if (imageCount != sizeZ * effSizeC * sizeT) { 
    355         System.out.println("\t************ Warning: ZCT mismatch ************"); 
    356       } 
    357       System.out.println("\tThumbnail size = " + 
    358         thumbSizeX + " x " + thumbSizeY); 
    359       System.out.println("\tEndianness = " + 
    360         (little ? "intel (little)" : "motorola (big)")); 
    361       System.out.println("\tDimension order = " + dimOrder + 
    362         (orderCertain ? " (certain)" : " (uncertain)")); 
    363       System.out.println("\tPixel type = " + getPixelTypeString(pixelType)); 
    364       if (doMeta) { 
    365         System.out.println("\t-----"); 
    366         int[] indices; 
    367         if (imageCount > 6) { 
    368           int q = imageCount / 2; 
    369           indices = new int[] { 
    370             0, q - 2, q - 1, q, q + 1, q + 2, imageCount - 1 
    371           }; 
    372         } 
    373         else if (imageCount > 2) { 
    374           indices = new int[] {0, imageCount / 2, imageCount - 1}; 
    375         } 
    376         else if (imageCount > 1) indices = new int[] {0, 1}; 
    377         else indices = new int[] {0}; 
    378         int[][] zct = new int[indices.length][]; 
    379         int[] indices2 = new int[indices.length]; 
    380         for (int i=0; i<indices.length; i++) { 
    381           zct[i] = reader.getZCTCoords(indices[i]); 
    382           indices2[i] = reader.getIndex(zct[i][0], zct[i][1], zct[i][2]); 
    383           System.out.print("\tPlane #" + indices[i] + " <=> Z " + zct[i][0] + 
    384             ", C " + zct[i][1] + ", T " + zct[i][2]); 
    385           if (indices[i] != indices2[i]) { 
    386             System.out.println(" [mismatch: " + indices2[i] + "]"); 
    387           } 
    388           else System.out.println(); 
    389         } 
    390       } 
    391     } 
    392     reader.setSeries(series); 
    393     String s = seriesCount > 1 ? (" series #" + series) : ""; 
    394     int pixelType = reader.getPixelType(); 
    395     int sizeC = reader.getSizeC(); 
    396  
    397     // get a priori min/max values 
    398     Double[] preGlobalMin = null, preGlobalMax = null; 
    399     Double[] preKnownMin = null, preKnownMax = null; 
    400     Double[] prePlaneMin = null, prePlaneMax = null; 
    401     boolean preIsMinMaxPop = false; 
    402     if (minmax) { 
    403       preGlobalMin = new Double[sizeC]; 
    404       preGlobalMax = new Double[sizeC]; 
    405       preKnownMin = new Double[sizeC]; 
    406       preKnownMax = new Double[sizeC]; 
    407       for (int c=0; c<sizeC; c++) { 
    408         preGlobalMin[c] = minMaxCalc.getChannelGlobalMinimum(c); 
    409         preGlobalMax[c] = minMaxCalc.getChannelGlobalMaximum(c); 
    410         preKnownMin[c] = minMaxCalc.getChannelKnownMinimum(c); 
    411         preKnownMax[c] = minMaxCalc.getChannelKnownMaximum(c); 
    412       } 
    413       prePlaneMin = minMaxCalc.getPlaneMinimum(0); 
    414       prePlaneMax = minMaxCalc.getPlaneMaximum(0); 
    415       preIsMinMaxPop = minMaxCalc.isMinMaxPopulated(); 
    416     } 
    417  
    418     // read pixels 
    419     if (pixels) { 
    420       System.out.println(); 
    421       System.out.print("Reading" + s + " pixel data "); 
    422       status.setVerbose(false); 
    423       int num = reader.getImageCount(); 
    424       if (start < 0) start = 0; 
    425       if (start >= num) start = num - 1; 
    426       if (end < 0) end = 0; 
    427       if (end >= num) end = num - 1; 
    428       if (end < start) end = start; 
    429  
    430       System.out.print("(" + start + "-" + end + ") "); 
    431       BufferedImage[] images = new BufferedImage[end - start + 1]; 
    432       long s2 = System.currentTimeMillis(); 
    433       boolean mismatch = false; 
    434       for (int i=start; i<=end; i++) { 
    435         status.setEchoNext(true); 
    436         if (!fastBlit) { 
    437           images[i - start] = thumbs ? 
    438             reader.openThumbImage(i) : reader.openImage(i); 
    439         } 
    440         else { 
    441           int x = reader.getSizeX(); 
    442           int y = reader.getSizeY(); 
    443           byte[] b = thumbs ? reader.openThumbBytes(i) : 
    444             reader.openBytes(i); 
    445           Object pix = DataTools.makeDataArray(b, 
    446             getBytesPerPixel(reader.getPixelType()), 
    447             reader.getPixelType() == FLOAT, 
    448             reader.isLittleEndian()); 
    449           images[i - start] = 
    450             ImageTools.makeImage(ImageTools.make24Bits(pix, x, y, 
    451               false, false), x, y); 
    452         } 
    453  
    454         // check for pixel type mismatch 
    455         int pixType = ImageTools.getPixelType(images[i - start]); 
    456         if (pixType != pixelType && !fastBlit) { 
    457           if (!mismatch) { 
    458             System.out.println(); 
    459             mismatch = true; 
    460           } 
    461           System.out.println("\tPlane #" + i + ": pixel type mismatch: " + 
    462             getPixelTypeString(pixType) + "/" + getPixelTypeString(pixelType)); 
    463         } 
    464         else { 
    465           mismatch = false; 
    466           System.out.print("."); 
    467         } 
    468       } 
    469       long e2 = System.currentTimeMillis(); 
    470       if (!mismatch) System.out.print(" "); 
    471       System.out.println("[done]"); 
    472  
    473       // output timing results 
    474       float sec2 = (e2 - s2) / 1000f; 
    475       float avg = (float) (e2 - s2) / images.length; 
    476       System.out.println(sec2 + "s elapsed (" + avg + "ms per image)"); 
    477  
    478       if (minmax) { 
    479         // get computed min/max values 
    480         Double[] globalMin = new Double[sizeC]; 
    481         Double[] globalMax = new Double[sizeC]; 
    482         Double[] knownMin = new Double[sizeC]; 
    483         Double[] knownMax = new Double[sizeC]; 
    484         for (int c=0; c<sizeC; c++) { 
    485           globalMin[c] = minMaxCalc.getChannelGlobalMinimum(c); 
    486           globalMax[c] = minMaxCalc.getChannelGlobalMaximum(c); 
    487           knownMin[c] = minMaxCalc.getChannelKnownMinimum(c); 
    488           knownMax[c] = minMaxCalc.getChannelKnownMaximum(c); 
    489         } 
    490         Double[] planeMin = minMaxCalc.getPlaneMinimum(0); 
    491         Double[] planeMax = minMaxCalc.getPlaneMaximum(0); 
    492         boolean isMinMaxPop = minMaxCalc.isMinMaxPopulated(); 
    493  
    494         // output min/max results 
    495         System.out.println(); 
    496         System.out.println("Min/max values:"); 
    497         for (int c=0; c<sizeC; c++) { 
    498           System.out.println("\tChannel " + c + ":"); 
    499           System.out.println("\t\tGlobal minimum = " + 
    500             globalMin[c] + " (initially " + preGlobalMin[c] + ")"); 
    501           System.out.println("\t\tGlobal maximum = " + 
    502             globalMax[c] + " (initially " + preGlobalMax[c] + ")"); 
    503           System.out.println("\t\tKnown minimum = " + 
    504             knownMin[c] + " (initially " + preKnownMin[c] + ")"); 
    505           System.out.println("\t\tKnown maximum = " + 
    506             knownMax[c] + " (initially " + preKnownMax[c] + ")"); 
    507         } 
    508         System.out.print("\tFirst plane minimum(s) ="); 
    509         if (planeMin == null) System.out.print(" none"); 
    510         else { 
    511           for (int subC=0; subC<planeMin.length; subC++) { 
    512             System.out.print(" " + planeMin[subC]); 
    513           } 
    514         } 
    515         System.out.print(" (initially"); 
    516         if (prePlaneMin == null) System.out.print(" none"); 
    517         else { 
    518           for (int subC=0; subC<prePlaneMin.length; subC++) { 
    519             System.out.print(" " + prePlaneMin[subC]); 
    520           } 
    521         } 
    522         System.out.println(")"); 
    523         System.out.print("\tFirst plane maximum(s) ="); 
    524         if (planeMax == null) System.out.print(" none"); 
    525         else { 
    526           for (int subC=0; subC<planeMax.length; subC++) { 
    527             System.out.print(" " + planeMax[subC]); 
    528           } 
    529         } 
    530         System.out.print(" (initially"); 
    531         if (prePlaneMax == null) System.out.print(" none"); 
    532         else { 
    533           for (int subC=0; subC<prePlaneMax.length; subC++) { 
    534             System.out.print(" " + prePlaneMax[subC]); 
    535           } 
    536         } 
    537         System.out.println(")"); 
    538         System.out.println("\tMin/max populated = " + 
    539           isMinMaxPop + " (initially " + preIsMinMaxPop + ")"); 
    540       } 
    541  
    542       // display pixels in image viewer 
    543       // NB: avoid dependencies on optional loci.formats.gui package 
    544       ReflectedUniverse r = new ReflectedUniverse(); 
    545       try { 
    546         r.exec("import loci.formats.gui.ImageViewer"); 
    547         r.exec("viewer = new ImageViewer()"); 
    548         r.setVar("reader", reader); 
    549         r.setVar("images", images); 
    550         r.setVar("true", true); 
    551         r.exec("viewer.setImages(reader, images)"); 
    552         r.exec("viewer.setVisible(true)"); 
    553       } 
    554       catch (ReflectException exc) { 
    555         throw new FormatException(exc); 
    556       } 
    557     } 
    558  
    559     // read format-specific metadata table 
    560     if (doMeta) { 
    561       System.out.println(); 
    562       System.out.println("Reading" + s + " metadata"); 
    563       Hashtable meta = reader.getMetadata(); 
    564       String[] keys = (String[]) meta.keySet().toArray(new String[0]); 
    565       Arrays.sort(keys); 
    566       for (int i=0; i<keys.length; i++) { 
    567         System.out.print(keys[i] + ": "); 
    568         System.out.println(reader.getMetadataValue(keys[i])); 
    569       } 
    570     } 
    571  
    572     // output OME-XML 
    573     if (omexml) { 
    574       System.out.println(); 
    575       System.out.println("Generating OME-XML"); 
    576       MetadataStore ms = reader.getMetadataStore(); 
    577  
    578       // NB: avoid dependencies on optional loci.formats.ome package 
    579       if (ms.getClass().getName().equals( 
    580         "loci.formats.ome.OMEXMLMetadataStore")) 
    581       { 
    582         try { 
    583           Method m = ms.getClass().getMethod("dumpXML", (Class[]) null); 
    584           String xml = (String) m.invoke(ms, (Object[]) null); 
    585           System.out.println(indentXML(xml)); 
    586         } 
    587         catch (Throwable t) { 
    588           System.out.println("Error generating OME-XML:"); 
    589           t.printStackTrace(); 
    590         } 
    591       } 
    592       else { 
    593         System.out.println("OME-Java library not found; no OME-XML available"); 
    594       } 
    595     } 
    596  
    597     return true; 
    598   } 
    599  
    600   /** A utility method for converting a file from the command line. */ 
    601   public static boolean testConvert(IFormatWriter writer, String[] args) 
    602     throws FormatException, IOException 
    603   { 
    604     String in = null, out = null; 
    605     if (args != null) { 
    606       for (int i=0; i<args.length; i++) { 
    607         if (args[i].startsWith("-") && args.length > 1) { 
    608           if (args[i].equals("-debug")) FormatHandler.setDebug(true); 
    609           else System.out.println("Ignoring unknown command flag: " + args[i]); 
    610         } 
    611         else { 
    612           if (in == null) in = args[i]; 
    613           else if (out == null) out = args[i]; 
    614           else System.out.println("Ignoring unknown argument: " + args[i]); 
    615         } 
    616       } 
    617     } 
    618     if (FormatHandler.debug) { 
    619       System.out.println("Debugging at level " + FormatHandler.debugLevel); 
    620     } 
    621     String className = writer.getClass().getName(); 
    622     if (in == null || out == null) { 
    623       System.out.println("To convert a file to " + writer.getFormat() + 
    624         " format, run:"); 
    625       System.out.println("  java " + className + " [-debug] in_file out_file"); 
    626       return false; 
    627     } 
    628  
    629     long start = System.currentTimeMillis(); 
    630     System.out.print(in + " "); 
    631     ImageReader reader = new ImageReader(); 
    632     reader.setId(in); 
    633     System.out.print("[" + reader.getFormat() + "] -> " + out + " "); 
    634     writer.setId(out); 
    635     System.out.print("[" + writer.getFormat() + "] "); 
    636     long mid = System.currentTimeMillis(); 
    637  
    638     int num = writer.canDoStacks() ? reader.getImageCount() : 1; 
    639     long read = 0, write = 0; 
    640     for (int i=0; i<num; i++) { 
    641       long s = System.currentTimeMillis(); 
    642       Image image = reader.openImage(i); 
    643       long m = System.currentTimeMillis(); 
    644       writer.saveImage(image, i == num - 1); 
    645       long e = System.currentTimeMillis(); 
    646       System.out.print("."); 
    647       read += m - s; 
    648       write += e - m; 
    649     } 
    650     long end = System.currentTimeMillis(); 
    651     System.out.println(" [done]"); 
    652  
    653     // output timing results 
    654     float sec = (end - start) / 1000f; 
    655     long initial = mid - start; 
    656     float readAvg = (float) read / num; 
    657     float writeAvg = (float) write / num; 
    658     System.out.println(sec + "s elapsed (" + 
    659       readAvg + "+" + writeAvg + "ms per image, " + initial + "ms overhead)"); 
    660  
    661     return true; 
    662   } 
    663104 
    664105  // -- Utility methods - dimensional positions -- 
     
    994435  } 
    995436 
    996   // -- Helper classes -- 
    997  
    998   /** Used by testRead to echo status messages to the console. */ 
    999   private static class StatusEchoer implements StatusListener { 
    1000     private boolean verbose = true; 
    1001     private boolean next = true; 
    1002  
    1003     public void setVerbose(boolean value) { verbose = value; } 
    1004     public void setEchoNext(boolean value) { next = value; } 
    1005  
    1006     public void statusUpdated(StatusEvent e) { 
    1007       if (verbose) System.out.println("\t" + e.getStatusMessage()); 
    1008       else if (next) { 
    1009         System.out.print(";"); 
    1010         next = false; 
    1011       } 
    1012     } 
    1013   } 
    1014  
    1015437} 
  • trunk/loci/formats/FormatWriter.java

    r2712 r2796  
    115115  } 
    116116 
    117   /* @see IFormatWriter#testConvert(String[]) */ 
    118   public boolean testConvert(String[] args) 
    119     throws FormatException, IOException 
    120   { 
    121     return FormatTools.testConvert(this, args); 
    122   } 
    123  
    124117  // -- IFormatHandler API methods -- 
    125118 
  • trunk/loci/formats/IFormatReader.java

    r2786 r2796  
    275275  Object getMetadataStoreRoot(); 
    276276 
    277   /** 
    278    * A utility method for test reading a file from the command line, 
    279    * and displaying the results in a simple display. 
    280    */ 
    281   boolean testRead(String[] args) throws FormatException, IOException; 
    282  
    283277  // -- Deprecated API methods -- 
    284278 
  • trunk/loci/formats/IFormatWriter.java

    r2712 r2796  
    7272  void setCompression(String compress) throws FormatException; 
    7373 
    74   /** A utility method for converting a file from the command line. */ 
    75   boolean testConvert(String[] args) throws FormatException, IOException; 
    76  
    7774  // -- Deprecated API methods -- 
    7875 
  • trunk/loci/formats/ImageReader.java

    r2786 r2796  
    448448  } 
    449449 
    450   /* @see IFormatReader#testRead(String[]) */ 
    451   public boolean testRead(String[] args) throws FormatException, IOException { 
    452     return FormatTools.testRead(this, args); 
    453   } 
    454  
    455450  // -- IFormatHandler API methods -- 
    456451 
     
    528523 
    529524  public static void main(String[] args) throws FormatException, IOException { 
    530     if (!new ImageReader().testRead(args)) System.exit(1); 
     525    if (!ConsoleTools.testRead(new ImageReader(), args)) System.exit(1); 
    531526  } 
    532527 
  • trunk/loci/formats/ImageWriter.java

    r2761 r2796  
    247247  } 
    248248 
    249   /* @see IFormatWriter#testConvert(String[]) */ 
    250   public boolean testConvert(String[] args) 
    251     throws FormatException, IOException 
    252   { 
    253     return FormatTools.testConvert(this, args); 
    254   } 
    255  
    256249  // -- IFormatHandler API methods -- 
    257250 
     
    328321 
    329322  public static void main(String[] args) throws FormatException, IOException { 
    330     if (!new ImageWriter().testConvert(args)) System.exit(1); 
     323    if (!ConsoleTools.testConvert(new ImageWriter(), args)) System.exit(1); 
    331324  } 
    332325 
  • trunk/loci/formats/ReaderWrapper.java

    r2786 r2796  
    262262  } 
    263263 
    264   public boolean testRead(String[] args) throws FormatException, IOException { 
    265     return reader.testRead(args); 
    266   } 
    267  
    268264  // -- IFormatHandler API methods -- 
    269265 
  • trunk/loci/formats/reader-guide.txt

    r2695 r2796  
    144144  the images in the file.  ImageReader can take additional parameters; a 
    145145  brief listing is provided for reference, but it is recommended that you 
    146   take a look at the contents of FormatReader.testRead to see exactly what 
     146  take a look at the contents of ConsoleTools.testRead to see exactly what 
    147147  each one does. 
    148148 
Note: See TracChangeset for help on using the changeset viewer.