import java.awt.*; import java.awt.event.*; import java.io.*; import ij.*; import ij.io.*; import ij.plugin.PlugIn; public class Open_ITEX implements PlugIn { public void run(String argv) { OpenDialog OD = new OpenDialog("open ITEX ...", argv); String D = OD.getDirectory(); if (D == null) return; String FN = OD.getFileName(); if (FN == null) return; ImagePlus IP = open(D, FN); if (IP != null) IP.show(); else IJ.showMessage("open ITEX ...", "failed."); } public static ImagePlus open(String D, String FN) { File F = new File(D, FN); try { FileInputStream FIS = new FileInputStream(F); byte[] H = new byte[64]; if (FIS.read(H) != 64) { IJ.showMessage("open ITEX ...", "header read error."); return null; } if ((H[12] != 0 && H[12] != 2 && H[12] != 3) || H[13] != 0) { IJ.showMessage("open ITEX ...", "unknown image type."); return null; } int L = ((int)H[2] & 255) + ((int)H[3] & 255) * 256; FileInfo FI = new FileInfo(); if (L != 0) { byte[] C = new byte[L]; if (FIS.read(C) != L) { IJ.showMessage("open ITEX ...", "comment read error."); return null; } int l = 0; while (l < L && C[l] != 0) ++l; if (l != 0) FI.info = new String(C, 0, l, "UTF-8"); } FI.directory = D; FI.fileName = FN; FI.width = ((int)H[4] & 255) + ((int)H[5] & 255) * 256; FI.height = ((int)H[6] & 255) + ((int)H[7] & 255) * 256; FI.offset = 64 + L; FI.fileFormat = FI.RAW; FI.intelByteOrder = true; FI.fileType = (H[12] == 3)?FileInfo.GRAY32_UNSIGNED: (H[12] == 2)?FileInfo.GRAY16_UNSIGNED:FileInfo.GRAY8; FI.nImages = 1; FI.gapBetweenImages = 0; FileOpener FO = new FileOpener(FI); ImagePlus IP = FO.open(false); IJ.showStatus(""); return IP; } catch(IOException e) { IJ.error("an error occured reading the file.\n" + e); IJ.showStatus(""); return null; } } } /* ImageJ/plugins/Input-Output/HandleExtraFileTypes.java : ... public class HandleExtraFileTypes extends ImagePlus implements PlugIn { ... private Object tryOpen(String directory, String name, String path) { ... ---------------- if (name.endsWith(".img") && buf[0]==73 && buf[1]==77) return tryPlugIn("Open_ITEX", path); ---------------- ... if (name.endsWith(".img") ...) { ... } ... ... ... */