import ij.plugin.*; import ij.*; import ij.io.*; import ij.process.*; import java.io.*; /** This plugin opens images in the Isee/Unix (.ISE) format. modifited by arvonn tully from the IPLab_Reader source so that we can read ISee/Inovision Files Directly */ public class Isee_Reader extends ImagePlus implements PlugIn { boolean littleEndian; BufferedInputStream f; public void run(String arg) { if (arg ==""){ OpenDialog od = new OpenDialog("Open Isee...", arg); String directory = od.getDirectory(); String name = od.getFileName(); if (name==null) return; IJ.showStatus("Opening: " + directory + name); open(directory, name, arg); } if (arg!=""){ File theFile=new File(arg); //used to be theFile.getParent(); String directory = theFile.getParent()+'/'; String name = theFile.getName(); if (directory==null) return; open(directory, name, arg); } }//run void open(String directory, String name, String arg) { FileInfo fi = null; try { fi = getFileInfo(directory, name); } catch (IOException e) { String error = e.getMessage(); if (error==null || error.equals("")) error = ""+e; IJ.showMessage("Isee Reader failed because ", ""+error); return; } if (fi!=null) { FileOpener fo = new FileOpener(fi); ImagePlus imp = fo.open(false); if (imp==null) return; setStack(name, imp.getStack()); setCalibration(imp.getCalibration()); show(); } }//open FileInfo getFileInfo(String directory, String name) throws IOException { FileInfo fi = new FileInfo(); f = new BufferedInputStream(new FileInputStream(directory+name)); // we know that all isee files will be GRAY16_UNSIGNED fi.fileType = FileInfo.GRAY16_UNSIGNED; fi.fileFormat = fi.RAW; fi.fileName = name; fi.directory = directory; littleEndian = false; //Inovision file format is BigEndian fi.intelByteOrder = littleEndian; // we know that all isee images have a 512 byte offset // actually this is in the first four bytes int chomp = getInt();//first four bytes fi.offset = chomp; chomp = getInt();//second four bytes chomp = getInt();//third four bytes chomp = getInt();//fourth four bytes //fifth four bytes should be X resolution fi.width = getInt(); //sixth four bytes should be Y resolution fi.height = getInt(); f.close(); return fi; }//getFileInfo int getByte() throws IOException { int b = f.read(); if (b ==-1) throw new IOException("unexpected EOF"); return b; }//getByte final int getInt() throws IOException { int b0 = getByte(); int b1 = getByte(); int b2 = getByte(); int b3 = getByte(); if (littleEndian) return ((b3<<24) + (b2<<16) + (b1<<8) + b0); else return ((b0<<24) + (b1<<16) + (b2<<8) + b3); }//getInt }//Isee_Reader