예제 #1
0
파일: Opener.java 프로젝트: kkkkxu/BioImage
 /** Opens the nth image of the specified TIFF stack. */
 public ImagePlus openTiff(String path, int n) {
   TiffDecoder td = new TiffDecoder(getDir(path), getName(path));
   if (IJ.debugMode) td.enableDebugging();
   FileInfo[] info = null;
   try {
     info = td.getTiffInfo();
   } catch (IOException e) {
     String msg = e.getMessage();
     if (msg == null || msg.equals("")) msg = "" + e;
     IJ.error("Open TIFF", msg);
     return null;
   }
   if (info == null) return null;
   FileInfo fi = info[0];
   if (info.length == 1 && fi.nImages > 1) {
     if (n < 1 || n > fi.nImages)
       throw new IllegalArgumentException("N out of 1-" + fi.nImages + " range");
     long size = fi.width * fi.height * fi.getBytesPerPixel();
     fi.longOffset = fi.getOffset() + (n - 1) * (size + fi.gapBetweenImages);
     fi.offset = 0;
     fi.nImages = 1;
   } else {
     if (n < 1 || n > info.length)
       throw new IllegalArgumentException("N out of 1-" + info.length + " range");
     fi.longOffset = info[n - 1].getOffset();
     fi.offset = 0;
     fi.stripOffsets = info[n - 1].stripOffsets;
     fi.stripLengths = info[n - 1].stripLengths;
   }
   FileOpener fo = new FileOpener(fi);
   return fo.open(false);
 }
예제 #2
0
파일: Opener.java 프로젝트: kkkkxu/BioImage
 /**
  * Attempts to open the specified inputStream as a TIFF, returning an ImagePlus object if
  * successful.
  */
 public ImagePlus openTiff(InputStream in, String name) {
   FileInfo[] info = null;
   try {
     TiffDecoder td = new TiffDecoder(in, name);
     if (IJ.debugMode) td.enableDebugging();
     info = td.getTiffInfo();
   } catch (FileNotFoundException e) {
     IJ.error("Open TIFF", "File not found: " + e.getMessage());
     return null;
   } catch (Exception e) {
     IJ.error("Open TIFF", "" + e);
     return null;
   }
   if (url != null && info != null && info.length == 1 && info[0].inputStream != null) {
     try {
       info[0].inputStream.close();
     } catch (IOException e) {
     }
     try {
       info[0].inputStream = new URL(url).openStream();
     } catch (Exception e) {
       IJ.error("Open TIFF", "" + e);
       return null;
     }
   }
   return openTiff2(info);
 }
예제 #3
0
파일: Opener.java 프로젝트: kkkkxu/BioImage
 /** Attempts to open the specified file as a tiff. Returns an ImagePlus object if successful. */
 public ImagePlus openTiff(String directory, String name) {
   TiffDecoder td = new TiffDecoder(directory, name);
   if (IJ.debugMode) td.enableDebugging();
   FileInfo[] info = null;
   try {
     info = td.getTiffInfo();
   } catch (IOException e) {
     String msg = e.getMessage();
     if (msg == null || msg.equals("")) msg = "" + e;
     IJ.error("Open TIFF", msg);
     return null;
   }
   if (info == null) return null;
   return openTiff2(info);
 }
예제 #4
0
파일: Opener.java 프로젝트: kkkkxu/BioImage
 /** Deserialize a byte array that was serialized using the FileSaver.serialize(). */
 public ImagePlus deserialize(byte[] bytes) {
   ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
   TiffDecoder decoder = new TiffDecoder(stream, "Untitled");
   if (IJ.debugMode) decoder.enableDebugging();
   FileInfo[] info = null;
   try {
     info = decoder.getTiffInfo();
   } catch (IOException e) {
     return null;
   }
   FileOpener opener = new FileOpener(info[0]);
   ImagePlus imp = opener.open(false);
   if (imp == null) return null;
   imp.setTitle(info[0].fileName);
   imp = makeComposite(imp, info[0]);
   return imp;
 }