//import com.activated.jimi.*;
import com.sun.jimi.core.*;
import java.awt.*;
import java.util.*;

/**
 * A simple example program for reversing the
 * order of frames in a multi-frame image.
 */
public class SaveAnimator
{
 public static void main(String[] args)
 {
    String file0 = "c:/images/Animate/a.gif";
    String file1 = "c:/images/Animate/a1.gif";
    /*
  // print usage if wrong arguments are given
  if (args.length != 2) {
   System.err.println("Requires args: <src> <dest>");
   System.exit(1);
  }*/

  // vector to store loaded images in
  Vector images = new Vector();

  // read the images
  try {
        // create a JimiReader to read the image
        // series from
        JimiReader jr = Jimi.createJimiReader(file0);
        // enumerate the images in the series
        Enumeration e = jr.getImageEnumeration();
        // insert them into the vector in reverse
        while (e.hasMoreElements()) {
            Image i = (Image)e.nextElement();
            images.insertElementAt(e, 0);
        }
  }
  // catch exception if the source file
  // is malformed
  catch (JimiException e) {
   System.err.println("Error: " + e);
   System.exit(1);
  }

  // write the images back in reverse
  try {
        // create a JimiWriter for the output file
        JimiWriter jw = Jimi.createJimiWriter("a.gif");
        // pull the images out of the vector and
        // into an array
        Image[] series = new Image[images.size()];
        images.copyInto(series);
        // set the image array as the source for
        // the JimiWriter
        jw.setSource(series);
        // write the images!
        jw.putImage(file1);
  }
  // catch exception if the output file
  // can't be written to
  catch (JimiException e) {
   System.err.println("Error: " + e);
   System.exit(1);
  }
  // finished!
  System.exit(0);
 }
}

