Exemplo n.º 1
0
 /** Reads the pixel data from an image described by a FileInfo object. */
 Object readPixels(FileInfo fi) {
   Object pixels = null;
   try {
     InputStream is = createInputStream(fi);
     if (is == null) return null;
     ImageReader reader = new ImageReader(fi);
     pixels = reader.readPixels(is);
     minValue = reader.min;
     maxValue = reader.max;
     is.close();
   } catch (Exception e) {
     if (!Macro.MACRO_CANCELED.equals(e.getMessage())) IJ.handleException(e);
   }
   return pixels;
 }
Exemplo n.º 2
0
  public void run(String arg) {
    String ijDir = System.getProperty("ij.dir");
    if (!ijDir.endsWith("/")) ijDir += "/";
    if (arg == null || "".equals(arg)) {
      OpenDialog dialog = new OpenDialog("Which Fiji component", ijDir + "plugins", "");
      if (dialog.getDirectory() == null) return;
      arg = dialog.getDirectory() + dialog.getFileName();
    }
    if (arg.startsWith(ijDir)) arg = arg.substring(ijDir.length());

    final JFrame frame = new JFrame("Building " + arg + "...");
    Container panel = frame.getContentPane();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    JTextArea textArea = new JTextArea("Calling Fiji Build\n", 25, 80);
    textArea.setFont(new Font("Courier", Font.PLAIN, 12));
    textArea.setEditable(false);
    panel.add(new JScrollPane(textArea));
    final JButton okay = new JButton("okay");
    okay.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            frame.dispose();
          }
        });
    okay.setEnabled(false);
    okay.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(okay);
    frame.pack();
    frame.setLocationRelativeTo(null);
    okay.requestFocus();
    frame.setVisible(true);

    try {
      Fake fake = new Fake();
      fake.out = fake.err = new PrintStream(new JTextAreaOutputStream(textArea));
      Parser parser = fake.parse(new FileInputStream(ijDir + "/Fakefile"), new File(ijDir));
      final Rule all = parser.parseRules(Arrays.asList(arg.split("\\s+")));
      all.make();
      fake.out.println("Finished.");
      frame.setTitle("Built " + arg);
      okay.setEnabled(true);
    } catch (Exception e) {
      IJ.handleException(e);
    }
  }
Exemplo n.º 3
0
 /**
  * Open a file. If it's a directory, ask to open all images as a sequence in a stack or
  * individually.
  */
 public void openFile(File f) {
   if (IJ.debugMode) IJ.log("DragAndDrop.openFile: " + f);
   try {
     if (null == f) return;
     String path = f.getCanonicalPath();
     if (f.exists()) {
       if (f.isDirectory()) openDirectory(f, path);
       else {
         if (openAsVirtualStack && (path.endsWith(".tif") || path.endsWith(".TIF")))
           (new FileInfoVirtualStack()).run(path);
         else (new Opener()).openAndAddToRecent(path);
         OpenDialog.setLastDirectory(f.getParent() + File.separator);
         OpenDialog.setLastName(f.getName());
       }
     } else {
       IJ.log("File not found: " + path);
     }
   } catch (Throwable e) {
     if (!Macro.MACRO_CANCELED.equals(e.getMessage())) IJ.handleException(e);
   }
 }
Exemplo n.º 4
0
 @Override
 protected void log(final Throwable t) {
   IJ.handleException(t);
 }
Exemplo n.º 5
0
 /** Attemps to open a tiff file as a stack. Returns an ImagePlus object if successful. */
 public ImagePlus openTiffStack(FileInfo[] info) {
   if (info.length > 1 && !allSameSizeAndType(info)) return null;
   FileInfo fi = info[0];
   if (fi.nImages > 1) return new FileOpener(fi).open(false); // open contiguous images as stack
   else {
     ColorModel cm = createColorModel(fi);
     ImageStack stack = new ImageStack(fi.width, fi.height, cm);
     Object pixels = null;
     long skip = fi.getOffset();
     int imageSize = fi.width * fi.height * fi.getBytesPerPixel();
     if (info[0].fileType == FileInfo.GRAY12_UNSIGNED) {
       imageSize = (int) (fi.width * fi.height * 1.5);
       if ((imageSize & 1) == 1) imageSize++; // add 1 if odd
     }
     if (info[0].fileType == FileInfo.BITMAP) {
       int scan = (int) Math.ceil(fi.width / 8.0);
       imageSize = scan * fi.height;
     }
     long loc = 0L;
     int nChannels = 1;
     try {
       InputStream is = createInputStream(fi);
       ImageReader reader = new ImageReader(fi);
       IJ.resetEscape();
       for (int i = 0; i < info.length; i++) {
         nChannels = 1;
         Object[] channels = null;
         if (!silentMode) IJ.showStatus("Reading: " + (i + 1) + "/" + info.length);
         if (IJ.escapePressed()) {
           IJ.beep();
           IJ.showProgress(1.0);
           return null;
         }
         fi.stripOffsets = info[i].stripOffsets;
         fi.stripLengths = info[i].stripLengths;
         int bpp = info[i].getBytesPerPixel();
         if (info[i].samplesPerPixel > 1 && !(bpp == 3 || bpp == 4 || bpp == 6)) {
           nChannels = fi.samplesPerPixel;
           channels = new Object[nChannels];
           for (int c = 0; c < nChannels; c++) {
             pixels = reader.readPixels(is, c == 0 ? skip : 0L);
             channels[c] = pixels;
           }
         } else pixels = reader.readPixels(is, skip);
         if (pixels == null && channels == null) break;
         loc += imageSize * nChannels + skip;
         if (i < (info.length - 1)) {
           skip = info[i + 1].getOffset() - loc;
           if (info[i + 1].compression >= FileInfo.LZW) skip = 0;
           if (skip < 0L) {
             IJ.error("Opener", "Unexpected image offset");
             break;
           }
         }
         if (fi.fileType == FileInfo.RGB48) {
           Object[] pixels2 = (Object[]) pixels;
           stack.addSlice(null, pixels2[0]);
           stack.addSlice(null, pixels2[1]);
           stack.addSlice(null, pixels2[2]);
           isRGB48 = true;
         } else if (nChannels > 1) {
           for (int c = 0; c < nChannels; c++) {
             if (channels[c] != null) stack.addSlice(null, channels[c]);
           }
         } else stack.addSlice(null, pixels);
         IJ.showProgress(i, info.length);
       }
       is.close();
     } catch (Exception e) {
       IJ.handleException(e);
     } catch (OutOfMemoryError e) {
       IJ.outOfMemory(fi.fileName);
       stack.deleteLastSlice();
       stack.deleteLastSlice();
     }
     IJ.showProgress(1.0);
     if (stack.getSize() == 0) return null;
     if (fi.fileType == FileInfo.GRAY16_UNSIGNED
         || fi.fileType == FileInfo.GRAY12_UNSIGNED
         || fi.fileType == FileInfo.GRAY32_FLOAT
         || fi.fileType == FileInfo.RGB48) {
       ImageProcessor ip = stack.getProcessor(1);
       ip.resetMinAndMax();
       stack.update(ip);
     }
     // if (fi.whiteIsZero)
     //	new StackProcessor(stack, stack.getProcessor(1)).invert();
     ImagePlus imp = new ImagePlus(fi.fileName, stack);
     new FileOpener(fi).setCalibration(imp);
     imp.setFileInfo(fi);
     if (fi.info != null) imp.setProperty("Info", fi.info);
     if (fi.description != null && fi.description.contains("order=zct"))
       new HyperStackConverter().shuffle(imp, HyperStackConverter.ZCT);
     int stackSize = stack.getSize();
     if (nChannels > 1 && (stackSize % nChannels) == 0) {
       imp.setDimensions(nChannels, stackSize / nChannels, 1);
       imp = new CompositeImage(imp, IJ.COMPOSITE);
       imp.setOpenAsHyperStack(true);
     } else if (imp.getNChannels() > 1) imp = makeComposite(imp, fi);
     IJ.showProgress(1.0);
     return imp;
   }
 }