File: Test.java

package info (click to toggle)
natbraille 2.0rc3-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,924 kB
  • sloc: java: 31,266; xml: 7,747; sh: 165; haskell: 50; makefile: 34
file content (808 lines) | stat: -rw-r--r-- 23,440 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/**************************************************************************
/* This class implements various tests of the im4java-package.
/*
/* Copyright (c) 2009 by Bernhard Bablok (mail@bablokb.de)
/*
/* This program is free software; you can redistribute it and/or modify
/* it under the terms of the GNU Library General Public License as published
/* by  the Free Software Foundation; either version 2 of the License or
/* (at your option) any later version.
/*
/* This program is distributed in the hope that it will be useful, but
/* WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/* GNU Library General Public License for more details.
/*
/* You should have received a copy of the GNU Library General Public License
/* along with this program; see the file COPYING.LIB.  If not, write to
/* the Free Software Foundation Inc., 59 Temple Place - Suite 330,
/* Boston, MA  02111-1307 USA
/**************************************************************************/

package org.im4java.test;

import java.util.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.ImageIO;

import org.im4java.core.*;
import org.im4java.process.Pipe;
import org.im4java.process.ArrayListOutputConsumer;
import org.im4java.process.ProcessEvent;
import org.im4java.process.ProcessListener;
import org.im4java.utils.*;


/**
   This class implements various tests of the im4java-package.

   @version $Revision: 1.36 $
   @author  $Author: bablokb, Bruno Mascret (warnings) $
 */

public class  Test {

  //////////////////////////////////////////////////////////////////////////////

  /**
     Constructor.
   */

  public  Test() {
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Main-method. You can either pass the number(s) of the test or the
     string "all" for all tests.
   */

  public static void main(String[] args) {
    if (args.length == 0 || args[0].equals("help")) {
      System.err.
      println("usage: java org.im4java.test.Test all | help | nr [...]\n\n" +
          "Available tests:\n" +
					"\t 0: simple use of convert (BRAILLE)\n" +
          "\t 1: simple use of convert\n" +
          "\t 2: operation and sub-operations\n" +
          "\t 3: montage\n" +
          "\t 4: mixer\n" +
          "\t 5: mogrify\n" +
          "\t 6: identify\n" +
          "\t 7: composite\n" +
          "\t 8: info\n" +
          "\t 9: noise-filter\n" +
          "\t10: piping\n" +
          "\t11: dynamic operation\n" +
          "\t12: Reading BufferedImage\n" +
          "\t13: Writing BufferedImage\n" +
          "\t14: GraphicsMagick\n" +
          "\t15: jpegtran\n" +
          "\t16: asynchronous execution\n" +
          "\t17: ufraw-batch\n" +
          "\t18: exiftool\n" +
          "\t19: dcraw\n" +
          ""
      );
      System.exit(1);
    }
    try {
      Test test = new  Test();
      if (args[0].equals("all")) {
        test.testConvert();
        test.testOperation();
        test.testMontage();
        test.testMixer();
        test.testMogrify();
        test.testIdentify();
        test.testComposite();
        test.testInfo();
        test.testNoiseFilter();
        test.testPipe();
        test.testDynOp();
        test.testReadBufferedImage();
        test.testWriteBufferedImage();
        test.testGraphicsMagick();
        test.testJpegtran();
        test.testAsync();
        test.testUFRaw();
        test.testExiftool();
        test.testDCRaw();
      } else {
        for (int i=0; i<args.length; ++i) {
          int nr = Integer.parseInt(args[i]);
          switch (nr) {
						case 0:
              test.testConvertBr();
            case 1:
              test.testConvert();
              break;
            case 2:
              test.testOperation();
              break;
            case 3:
              test.testMontage();
              break;
            case 4:
              test.testMixer();
              break;
            case 5:
              test.testMogrify();
              break;
            case 6:
              test.testIdentify();
              break;
            case 7:
              test.testComposite();
              break;
            case 8:
              test.testInfo();
              break;
            case 9:
              test.testNoiseFilter();
              break;
            case 10:
              test.testPipe();
              break;
            case 11:
              test.testDynOp();
              break;
            case 12:
              test.testReadBufferedImage();
              break;
            case 13:
              test.testWriteBufferedImage();
              break;
            case 14:
              test.testGraphicsMagick();
              break;
            case 15:
              test.testJpegtran();
              break;
            case 16:
              test.testAsync();
              break;
            case 17:
              test.testUFRaw();
              break;
            case 18:
              test.testExiftool();
              break;
            case 19:
              test.testDCRaw();
              break;
            default:
              System.err.println("Test Nr " + nr + " not implemented yet!");
            break;
          }
        }
      }
    } catch (CommandException ce) {
      ce.printStackTrace();
      ArrayList<String> cmdError = ce.getErrorText();
      for (String line:cmdError) {
        System.err.println(line);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Basic test of convert.
   */

  public void testConvert() throws Exception {
    System.err.println(" 1. Testing convert ...");
    IMOperation op = new IMOperation();
    op.addImage().addImage();
    op.bordercolor("darkgray");
    op.border(10,10);
    op.appendHorizontally();
    op.addImage("x:");              // output: convert to screen

    String[] images = new String[] {
        "images/tulip1.jpg",
        "images/tulip 2.jpg"
    };

    ConvertCmd convert = new ConvertCmd();
    convert.run(op,(Object[]) images);
  }

public void testConvertBr() throws Exception {
    System.err.println(" 0. Brailel Testing convert ...");

    IMOperation op = new IMOperation();
    op.addImage("images/tulip1.jpg");
op.resize(40,768);
op.addImage("x:");
//op.addImage("myimage-small.brf");
ConvertCmd convert = new ConvertCmd();
convert.run(op,"images/tulip1.brf");
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test adding operations and suboperations.
   */

  public void testOperation() throws Exception {
    System.err.println(" 2. Testing operations and suboperations ...");
    IMOperation top = new IMOperation();

    // first (top) line
    top.addImage("images/rose1.jpg").addImage("images/rose2.jpg");
    top.appendHorizontally();

    // second (bottom) line
    IMOperation bottom = new IMOperation();
    bottom.addImage("images/tulip1.jpg").addImage("images/tulip2.jpg");
    bottom.appendHorizontally();

    // assemble lines
    IMOperation op = new IMOperation();
    op.addSubOperation(top);
    op.addSubOperation(bottom);
    op.appendVertically();

    op.addImage("x:");                      // output: convert to screen
    ConvertCmd convert = new ConvertCmd();
    convert.run(op);
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Basic test of montage.
   */

  public void testMontage() throws Exception {
    System.err.println(" 3. Testing montage ...");
    IMOperation all = new IMOperation();
    all.addImage("images/*.jpg");
    all.addImage("x:");              // output: convert to screen

    MontageCmd montage = new MontageCmd();
    montage.run(all);
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test using a channel-mixer.
   */

  public void testMixer() throws Exception {
    System.err.println(" 4. Testing channel-mixer ...");
    IMOperation mix = new IMOperation();

    // add image to operation and save in memory-register
    mix.addImage("images/tulip1.jpg");
    mix.write("mpr:orig");

    // convert to BW (special settings)
    mix.openOperation();
    mix.clone(0);
    mix.addOperation(new  ChannelMixer(0,0.12,0.78));
    mix.closeOperation();

    // convert to BW (emulate Ilford PANF film)
    mix.openOperation();
    mix.addImage("mpr:orig");
    mix.addOperation( ChannelMixer.ILFORD_PANF);
    mix.closeOperation();

    // append all images (same as p_append())
    mix.appendHorizontally();

    mix.addImage("x:");                       // output: convert to screen
    ConvertCmd convert = new ConvertCmd();
    convert.run(mix);
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Basic test of mogrify. Note that mogrify uses operators in prefix-notation!
   */

  public void testMogrify() throws Exception {
    System.err.println(" 5. Testing mogrify ...");
    IMOperation op = new IMOperation();
    op.resize(800);
    op.sigmoidalContrast(20d);
    op.addImage("images/firelily.jpg");

    MogrifyCmd mogrify = new MogrifyCmd();
    mogrify.run(op);

    IMOperation dis = new IMOperation();
    dis.addImage("images/firelily.jpg");
    DisplayCmd display = new DisplayCmd();
    display.run(dis);
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Basic test of identify.
   */

  public void testIdentify() throws Exception {
    System.err.println(" 6. Testing identify ...");
    IMOperation op = new IMOperation();
    // op.verbose();
    op.addImage(2);

    IdentifyCmd identify = new IdentifyCmd();
    System.out.println("   first run:");
    identify.run(op,"images/rose1.jpg","images/rose2.jpg");

    System.out.println("   second run:");
    ArrayListOutputConsumer output = new ArrayListOutputConsumer();
    identify.setOutputConsumer(output);
    identify.run(op,"images/tulip1.jpg","images/tulip2.jpg");
    ArrayList<String> cmdOutput = output.getOutput();
    for (String line:cmdOutput) {
      System.out.println(line);
    }
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Basic test of composite.   
     composite -blend {src_percent}x{dst_percent} overlay  bgnd  result
   */

  public void testComposite() throws Exception {
    System.err.println(" 7. Testing composite ...");
    IMOperation op = new IMOperation();
    op.blend(50);
    op.addImage(3);

    CompositeCmd composite = new CompositeCmd();
    composite.run(op,"images/rose1.jpg","images/rose2.jpg","x:");
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test image-information retrivial.
   */

  public void testInfo() throws Exception {
    System.err.println(" 8. Testing info ...");
    Info imageInfo = new Info("images/firelily.jpg");
    Enumeration<String> props = imageInfo.getPropertyNames();
    if (props == null) {
      return;
    }
    while (props.hasMoreElements()) {
      String prop=props.nextElement();
      System.out.println(prop+"="+imageInfo.getProperty(prop));
    }
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test the noise-filter. Note that the sample images are just too small
     to really see the effect.
   */

  public void testNoiseFilter() throws Exception {
    System.err.println(" 9. Testing noise-filter ...");
    IMOperation op = new IMOperation();

    // add image to operation
    op.addImage("images/spathiphyllum.jpg");

    // set up NoiseFilter.Edge
    IMOperation filterOp = new IMOperation();
    filterOp.despeckle();
    NoiseFilter.Edge noiseFilter = new NoiseFilter.Edge(filterOp,2.0);

    // use NoiseFilter.Edge
    op.openOperation();
    op.clone(0);
    op.addOperation(noiseFilter);
    op.closeOperation();

    // append all images (same as p_append())
    op.appendHorizontally();

    op.addImage("x:");                       // output: convert to screen
    ConvertCmd convert = new ConvertCmd();
    convert.run(op);
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test piping input and output to an IM command.
   */

  public void testPipe() throws Exception {
    System.err.println("10. Testing pipes ...");

    IMOperation op = new IMOperation();
    op.addImage("-");                   // read from stdin
    op.addImage("tif:-");               // write to stdout in tif-format

    // set up pipe(s): you can use one or two pipe objects
    FileInputStream fis = new FileInputStream("images/ipomoea.jpg");
    FileOutputStream fos = new FileOutputStream("images/ipomoea.tif");
    // Pipe pipe = new Pipe(fis,fos);
    Pipe pipeIn  = new Pipe(fis,null);
    Pipe pipeOut = new Pipe(null,fos);

    // set up command
    ConvertCmd convert = new ConvertCmd();
    convert.setInputProvider(pipeIn);
    convert.setOutputConsumer(pipeOut);
    convert.run(op);
    fis.close();
    fos.close();

    // show result
    DisplayCmd.show("images/ipomoea.tif");
  }

  ///////////////////////////////////////////////////////////////////////////////

  /**
   */

  private void testDynOp() throws Exception {
    System.err.println("11. Testing dynamic operations ...");

    IMOperation op = new IMOperation();
    // add image to operation
    op.addImage();

    // add -despeckle only if iso > 200
    op.openOperation();
    op.clone(0);
    op.addDynamicOperation(new DynamicOperation() {
      public Operation resolveOperation(Object... pImages)
      throws IM4JavaException {
        // we just care about the first image
        if (pImages.length>0) {

          // we use identify to query the iso-setting
          IMOperation iso = new IMOperation();
          iso.ping().format("%[EXIF:ISOSpeedRatings]\n");
          String img = (String) pImages[0];
          iso.addImage(img);
          IdentifyCmd identify = new IdentifyCmd();
          ArrayListOutputConsumer output = new ArrayListOutputConsumer();
          identify.setOutputConsumer(output);
          try {
            identify.run(iso);
          } catch (Exception e) {
            throw new IM4JavaException(e);
          }

          // now read the setting
          ArrayList<String> out = output.getOutput();
          int isoValue = Integer.parseInt(out.get(0));
          if (isoValue > 200) {
            IMOperation op = new IMOperation();
            op.despeckle();
            return op;
          } else {
            return null;
          }
        } else {
          return null;
        }
      }
    });
    op.closeOperation();
    op.appendHorizontally();

    // now run the command
    op.addImage();
    ConvertCmd convert = new ConvertCmd();
    convert.run(op,"images/firelily.jpg","x:");
    convert.run(op,"images/tulip1.jpg","x:");
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test image-conversion from BufferedImages.
   */

  public void testReadBufferedImage() throws Exception {
    System.err.println("12. Testing reading BufferedImages ...");

    IMOperation op = new IMOperation();
    op.addImage();                        // input
    op.blur(2.0).paint(10.0);
    op.addImage();                        // output


    // set up command
    ConvertCmd convert = new ConvertCmd();
    BufferedImage img = ImageIO.read(new File("images/tulip1.jpg"));
    convert.run(op,img,"images/buf2file.jpg");

    // show result
    DisplayCmd.show("images/buf2file.jpg");
    (new File("images/buf2file.jpg")).delete();
  }  

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test image-conversion to BufferedImages. Note that we need an
     OutputConsumer to pipe the result to the BufferedImage.
   */

  public void testWriteBufferedImage() throws Exception {
    System.err.println("13. Testing writing BufferedImages ...");

    IMOperation op = new IMOperation();
    op.addImage("images/tulip2.jpg");     // input
    op.blur(2.0).paint(10.0);
    op.addImage("png:-");                 // output: stdout


    // set up command
    ConvertCmd convert = new ConvertCmd();
    Stream2BufferedImage s2b = new Stream2BufferedImage();
    convert.setOutputConsumer(s2b);
    convert.run(op);

    // save result to disk
    BufferedImage img = s2b.getImage();
    ImageIO.write(img,"PNG",new File("images/tmpfile.png"));


    // show result
    DisplayCmd.show("images/tmpfile.png");
    (new File("images/tmpfile.png")).delete();
  }  

  //////////////////////////////////////////////////////////////////////////////

  /**
     Basic test of GraphicsMagick.
   */

  public void testGraphicsMagick() throws Exception {
    System.err.println("14. Testing GraphicsMagick's gm convert ...");
    IMOperation op = new IMOperation();
    op.addImage().addImage();
    op.bordercolor("darkgray");
    op.border(10,10);
    op.appendHorizontally();
    op.addImage("x:");              // output: convert to screen

    String[] images = new String[] {
        "images/rose1.jpg",
        "images/rose2.jpg"
    };

    ConvertCmd convert = new ConvertCmd(true);
    try {
      convert.run(op,(Object[]) images);
    } catch (CommandException ce) {
      // gm convert with x: as output always returns 1
    }
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test of jpegtran.
   */

  public void testJpegtran() throws Exception {
    System.err.println("15. Testing jpegtran ...");
    JPTOperation op = new JPTOperation();
    op.flip("horizontal");
    op.outfile(Operation.IMG_PLACEHOLDER);
    op.addImage();                            // input-filename

    JpegtranCmd jpegtran = new JpegtranCmd();
    jpegtran.run(op,"images/tulip2-flip.jpg","images/tulip2.jpg");

    DisplayCmd.show("images/tulip2-flip.jpg");
    (new File("images/tulip2-flip.jpg")).delete();
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test of asynchronous execution.
   */

  public void testAsync() throws Exception {
    System.err.println("16. Testing asynchronous execution ...");
    IMOperation op = new IMOperation();
    op.size(400,200);
    op.addImage("gradient:red","x:");

    ConvertCmd convert = new ConvertCmd();
    convert.setAsyncMode(true);

    // helper-class defined at the end of this file
    AsyncTestProcessListener pl = new AsyncTestProcessListener();
    convert.addProcessListener(pl);
    convert.run(op);

    // loop until the user finishes the operation
    for (int i=0; i<10; ++i) {
      System.err.println("sleeping for one second...");
      Thread.sleep(1000);
      if (!pl.isRunning()) {
	break;
      }
    }
    pl.destroy();
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test of ufraw-batch.
   */

  public void testUFRaw() throws Exception {
    System.err.println("17. Testing ufraw ...");
    String outfile="images/rawfile.tif";
    String infile=System.getProperty("im4java.testUFRaw.infile");
    if (infile == null) {
      System.err.println(
         "\nSkipping this test since input-file is not defined.\n" +
         "Set the system-property im4java.testUFRaw.infile to\n" +
         "your input-file for ufraw:\n" +
         "\tpass JAVA_OPTS=-Dim4java.testUFRaw.infile=... to \"make test\" or\n" +
         "\texport JAVA_OPTS=-Dim4java.testUFRaw.infile=...\n\n"
      );
      return;
    }

    UFRawOperation op = new UFRawOperation();
    op.exposure("auto");
    op.outType("tif");
    op.size(800);
    op.createId("no");
    op.overwrite();
    op.output(outfile);
    op.addImage(infile);                                 // input-filename

    UFRawCmd ufraw = new UFRawCmd(true);                 // use batch-mode
    ufraw.run(op);

    DisplayCmd.show(outfile);
    (new File(outfile)).delete();
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test of exiftool.
   */

  public void testExiftool() throws Exception {
    System.err.println("18. Testing exiftool ...");

    ETOperation op = new ETOperation();
    op.getTags("Filename","ImageWidth","ImageHeight","FNumber",
                                                           "ExposureTime","iso");
    op.addImage();

    // setup command and execute it (capture output)
    ArrayListOutputConsumer output = new ArrayListOutputConsumer();
    ExiftoolCmd et = new ExiftoolCmd();
    et.setOutputConsumer(output);
    et.run(op,"images/spathiphyllum.jpg");

    // dump output
    ArrayList<String> cmdOutput = output.getOutput();
    for (String line:cmdOutput) {
      System.out.println(line);
    }
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
     Test of dcraw.
   */

  public void testDCRaw() throws Exception {
    System.err.println("19. Testing dcraw ...");
    String outfile="images/rawfile.tif";
    String infile=System.getProperty("im4java.testDcraw.infile");
    if (infile == null) {
      System.err.println(
         "\nSkipping this test since input-file is not defined.\n" +
         "Set the system-property im4java.testDcraw.infile to\n" +
         "your input-file for dcraw:\n" +
         "\tpass JAVA_OPTS=-Dim4java.testDcraw.infile=... to \"make test\" or\n" +
         "\texport JAVA_OPTS=-Dim4java.testDcraw.infile=...\n\n"
      );
      return;
    }

    DCRAWOperation op = new DCRAWOperation();
    op.halfSize();
    op.createTIFF();
    op.write2stdout();
    op.addImage(infile);                                 // input-filename

    // create pipe for output
    FileOutputStream fos = new FileOutputStream(outfile);
    Pipe pipeOut = new Pipe(null,fos);

    // set up and run command
    DcrawCmd dcraw = new DcrawCmd();
    dcraw.setOutputConsumer(pipeOut);
    dcraw.run(op);
    fos.close();

    DisplayCmd.show(outfile);
    (new File(outfile)).delete();
  }

}

////////////////////////////////////////////////////////////////////////////////

/**
   Helper-class for method Test.asyncTest. A real-life application would do
   something more sensible like update a GUI.
*/

class AsyncTestProcessListener implements ProcessListener {
  private Process iProcess     = null;
  private boolean isTerminated = false;

  // save the started process
  public void processStarted(Process pProcess) {
    isTerminated=false;
    iProcess = pProcess;
  }

  // print return-code or stack-trace
  public void processTerminated(ProcessEvent pEvent) {
    synchronized(iProcess) {
      iProcess = null;
    }
    isTerminated = true;
    if (pEvent.getException() != null) {
      Exception e = pEvent.getException();
      System.err.println("Process terminated with: " + e.getMessage());
    } else {
      System.out.println("async process terminated with rc: " +
			 pEvent.getReturnCode());
    }
  }

  // check if thread is still running
  public boolean isRunning() {
    return !isTerminated;
  }

  // destroy running process (this will trigger an execption which
  // is passed to processTerminated())
  public void destroy() {
    try {
      synchronized(iProcess) {
	iProcess.destroy();
      }
    } catch (Exception e) {
    }
  }
}