import java.awt.*;
import java.io.*;
import ij.*;
import ij.plugin.*;
import ij.io.*;
import ij.process.*;

import quicktime.*;
import quicktime.io.*;
import quicktime.qd.*;
import quicktime.std.image.*;
import quicktime.app.image.*;


/**	Opens a quicktime recognisable file (PICT, MacPaint, GIF, JPEG, BMP, PNG, TGA, TIFF, ...)
	into a new window. Requires QuickTime for Java. Place QuickTime_Opener.class in the plugins
	folder and a command will be added to the Plug-Ins menu the next you start ImageJ. To add a
	command to File/Aquire, add a line something like "acquire10="Pict...",QuickTime_Opener"
	to ij.properties.
*/
public class QuickTime_Opener implements PlugIn {

	public void run(String arg) {
		try {
			QTSession.open();
			
			// prompt the user to select an image file
			QTFile imageFile = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);
			
			// import the image into QuickTime
			GraphicsImporter myGraphicsImporter = new GraphicsImporter (imageFile);
			
			//Create a GraphicsImporterDrawer which uses the GraphicsImporter to draw
			//this object produces pixels for the QTImageProducer
			GraphicsImporterDrawer myDrawer = new GraphicsImporterDrawer (myGraphicsImporter);
				
			//Create a java.awt.Image from the pixels supplied to it by the QTImageProducer
			QDRect r = myDrawer.getDisplayBounds();
			Dimension imageSize = new Dimension (r.getWidth(), r.getHeight());
			QTImageProducer qtProducer = new QTImageProducer (myDrawer, imageSize);
			Image img = Toolkit.getDefaultToolkit().createImage(qtProducer);
			
			new ImagePlus(imageFile.getName(), img).show();
				 		
	 		QTSession.close();
	 	}
		catch (Exception e) {
			QTSession.close();
			String msg = e.getMessage();
			if (msg.indexOf("-128")<0) // if not canceled by user
				IJ.error("Quicktime open failed: "+ msg);
		}
		catch (NoClassDefFoundError e) {
			IJ.error("QuickTime for Java required");
		}
	}

}







