private boolean showDialog() { String[] types = {"RAW", "JPEG", "ZLIB"}; GenericDialog gd = new GenericDialog("Generate Bricks"); gd.addChoice("FileType", types, filetype); gd.addNumericField("JPEG quality", jpeg_quality, 0); gd.addNumericField("Max file size (MB)", bdsizelimit, 0); int[] wlist = WindowManager.getIDList(); if (wlist == null) return false; String[] titles = new String[wlist.length]; for (int i = 0; i < wlist.length; i++) titles[i] = ""; int tnum = 0; for (int i = 0; i < wlist.length; i++) { ImagePlus imp = WindowManager.getImage(wlist[i]); if (imp != null) { titles[tnum] = imp.getTitle(); tnum++; } } gd.addChoice("Source image: ", titles, titles[0]); gd.showDialog(); if (gd.wasCanceled()) return false; filetype = types[gd.getNextChoiceIndex()]; jpeg_quality = (int) gd.getNextNumber(); if (jpeg_quality > 100) jpeg_quality = 100; if (jpeg_quality < 0) jpeg_quality = 0; bdsizelimit = (int) gd.getNextNumber(); int id = gd.getNextChoiceIndex(); lvImgTitle = new ArrayList<String>(); lvImgTitle.add(titles[id]); Prefs.set("filetype.string", filetype); Prefs.set("jpeg_quality.int", jpeg_quality); Prefs.set("bdsizelimit.int", bdsizelimit); return true; }
public void run(String arg) { imp = IJ.getImage(); int stackSize = imp.getStackSize(); if (imp == null) { IJ.noImage(); return; } // Make sure input image is a stack. if (stackSize == 1) { IJ.error("Z Project", "Stack required"); return; } // Check for inverting LUT. if (imp.getProcessor().isInvertedLut()) { if (!IJ.showMessageWithCancel("ZProjection", lutMessage)) return; } // Set default bounds. int channels = imp.getNChannels(); int frames = imp.getNFrames(); int slices = imp.getNSlices(); isHyperstack = imp.isHyperStack() || (ij.macro.Interpreter.isBatchMode() && ((frames > 1 && frames < stackSize) || (slices > 1 && slices < stackSize))); boolean simpleComposite = channels == stackSize; if (simpleComposite) isHyperstack = false; startSlice = 1; if (isHyperstack) { int nSlices = imp.getNSlices(); if (nSlices > 1) stopSlice = nSlices; else stopSlice = imp.getNFrames(); } else stopSlice = stackSize; // Build control dialog GenericDialog gd = buildControlDialog(startSlice, stopSlice); gd.showDialog(); if (gd.wasCanceled()) return; if (!imp.lock()) return; // exit if in use long tstart = System.currentTimeMillis(); setStartSlice((int) gd.getNextNumber()); setStopSlice((int) gd.getNextNumber()); method = gd.getNextChoiceIndex(); Prefs.set(METHOD_KEY, method); if (isHyperstack) { allTimeFrames = imp.getNFrames() > 1 && imp.getNSlices() > 1 ? gd.getNextBoolean() : false; doHyperStackProjection(allTimeFrames); } else if (imp.getType() == ImagePlus.COLOR_RGB) doRGBProjection(true); else doProjection(true); if (arg.equals("") && projImage != null) { long tstop = System.currentTimeMillis(); projImage.setCalibration(imp.getCalibration()); if (simpleComposite) IJ.run(projImage, "Grays", ""); projImage.show("ZProjector: " + IJ.d2s((tstop - tstart) / 1000.0, 2) + " seconds"); } imp.unlock(); IJ.register(ZProjector.class); return; }