Skip to content

Commit

Permalink
2021.04.27 (1.53j26; Bug fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasband committed Apr 27, 2021
1 parent 8e97620 commit b553ff4
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 57 deletions.
4 changes: 1 addition & 3 deletions ij/IJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -2462,10 +2462,8 @@ public static String[] getLuts() {
return new String[0];
for (int i=0; i<lutsMenu.getItemCount(); i++) {
MenuItem menuItem = lutsMenu.getItem(i);
if (menuItem.getActionListeners().length == 0) // separator?
continue;
String label = menuItem.getLabel();
if (label.equals("Invert LUT") || label.equals("Apply LUT"))
if (label.equals("-") || label.equals("Invert LUT") || label.equals("Apply LUT"))
continue;
String command = (String)commands.get(label);
if (command==null || command.startsWith("ij.plugin.LutLoader"))
Expand Down
5 changes: 3 additions & 2 deletions ij/ImageJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class ImageJ extends Frame implements ActionListener,

/** Plugins should call IJ.getVersion() or IJ.getFullVersion() to get the version string. */
public static final String VERSION = "1.53j";
public static final String BUILD = "18";
public static final String BUILD = "26";
public static Color backgroundColor = new Color(237,237,237);
/** SansSerif, 12-point, plain font. */
public static final Font SansSerif12 = new Font("SansSerif", Font.PLAIN, 12);
Expand Down Expand Up @@ -734,7 +734,8 @@ else if (delta>0 && DEFAULT_PORT+delta<65536)
if (!noGUI && (ij==null || (ij!=null && !ij.isShowing()))) {
ij = new ImageJ(null, mode);
ij.exitWhenQuitting = true;
}
} else if (batchMode && noGUI)
Prefs.load(null, null);
int macros = 0;
for (int i=0; i<nArgs; i++) {
String arg = args[i];
Expand Down
4 changes: 4 additions & 0 deletions ij/Menus.java
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ void addJarErrorHeading(String jar) {

/** Returns the specified ImageJ menu (e.g., "File>New") or null if it is not found. */
public static Menu getImageJMenu(String menuPath) {
if (menus==null)
IJ.init();
if (menus==null)
return null;
if (menus.get(menuPath)!=null)
Expand Down Expand Up @@ -1333,6 +1335,8 @@ public static String getMacrosPath() {

/** Returns the hashtable that associates commands with plugins. */
public static Hashtable getCommands() {
if (pluginsTable==null)
IJ.init();
return pluginsTable;
}

Expand Down
46 changes: 24 additions & 22 deletions ij/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,29 +288,31 @@ public static boolean get(String key, boolean defaultValue) {
public static String load(Object ij, Applet applet) {
if (ImageJDir==null)
ImageJDir = System.getProperty("user.dir");
InputStream f = null;
try { // Look for IJ_Props.txt in ImageJ folder
f = new FileInputStream(ImageJDir+"/"+PROPS_NAME);
propertiesPath = ImageJDir+"/"+PROPS_NAME;
} catch (FileNotFoundException e) {
f = null;
}
if (f==null) {
// Look in ij.jar if not found in ImageJ folder
f = ij.getClass().getResourceAsStream("/"+PROPS_NAME);
}
if (applet!=null)
return loadAppletProps(f, applet);
if (f==null)
return PROPS_NAME+" not found in ij.jar or in "+ImageJDir;
f = new BufferedInputStream(f);
try {
props.load(f);
f.close();
} catch (IOException e) {
return("Error loading "+PROPS_NAME);
if (ij!=null) {
InputStream f = null;
try { // Look for IJ_Props.txt in ImageJ folder
f = new FileInputStream(ImageJDir+"/"+PROPS_NAME);
propertiesPath = ImageJDir+"/"+PROPS_NAME;
} catch (FileNotFoundException e) {
f = null;
}
if (f==null) {
// Look in ij.jar if not found in ImageJ folder
f = ij.getClass().getResourceAsStream("/"+PROPS_NAME);
}
if (applet!=null)
return loadAppletProps(f, applet);
if (f==null)
return PROPS_NAME+" not found in ij.jar or in "+ImageJDir;
f = new BufferedInputStream(f);
try {
props.load(f);
f.close();
} catch (IOException e) {
return("Error loading "+PROPS_NAME);
}
imagesURL = props.getProperty(IJ.isJava18()?"images.location":"images.location2");
}
imagesURL = props.getProperty(IJ.isJava18()?"images.location":"images.location2");
loadPreferences();
loadOptions();
guiScale = get(GUI_SCALE, 1.0);
Expand Down
13 changes: 11 additions & 2 deletions ij/gui/GenericDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -730,14 +730,23 @@ public void addMessage(String text, Font font, Color color) {
public void addTextAreas(String text1, String text2, int rows, int columns) {
if (textArea1!=null) return;
Panel panel = new Panel();
int scrollbars = TextArea.SCROLLBARS_NONE;
if (text1.endsWith("SCROLLBARS_BOTH")) {
scrollbars = TextArea.SCROLLBARS_BOTH;
text1 = text1.substring(0, text1.length()-15);
}
if (text1.endsWith("SCROLLBARS_VERTICAL_ONLY")) {
scrollbars = TextArea.SCROLLBARS_VERTICAL_ONLY;
text1 = text1.substring(0, text1.length()-24);
}
Font font = new Font("SansSerif", Font.PLAIN, (int)(14*Prefs.getGuiScale()));
textArea1 = new TextArea(text1,rows,columns,TextArea.SCROLLBARS_NONE);
textArea1 = new TextArea(text1,rows,columns,scrollbars);
if (IJ.isLinux()) textArea1.setBackground(Color.white);
textArea1.setFont(font);
textArea1.addTextListener(this);
panel.add(textArea1);
if (text2!=null) {
textArea2 = new TextArea(text2,rows,columns,TextArea.SCROLLBARS_NONE);
textArea2 = new TextArea(text2,rows,columns,scrollbars);
if (IJ.isLinux()) textArea2.setBackground(Color.white);
textArea2.setFont(font);
panel.add(textArea2);
Expand Down
7 changes: 5 additions & 2 deletions ij/plugin/FolderOpener.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FolderOpener implements PlugIn {
private static final int MAX_SEPARATE = 40;
private static final String DIR_KEY = "import.sequence.dir";
private static final String[] types = {"default", "16-bit", "32-bit", "RGB"};
private static String[] excludedTypes = {".txt", ".lut", ".roi", ".pty", ".hdr", ".java", ".ijm", ".py", ".js", ".bsh", ".xml"};
private static String[] excludedTypes = {".txt", ".lut", ".roi", ".pty", ".hdr", ".java", ".ijm", ".py", ".js", ".bsh", ".xml", ".rar"};
private static boolean staticSortFileNames = true;
private static boolean staticOpenAsVirtualStack;
private boolean convertToRGB;
Expand Down Expand Up @@ -422,7 +422,10 @@ else if (label2!=null && !label2.equals(""))
}
}
if (imp2.getStackSize()==1) {
imp2.setProperty("Label", list[0]);
int idx = this.start-1;
if (idx<0 || idx>=list.length)
idx = 0;
imp2.setProperty("Label", list[idx]);
if (info1!=null)
imp2.setProperty("Info", info1);
}
Expand Down
10 changes: 6 additions & 4 deletions ij/plugin/ImagesToStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ public void convertImagesToStack() {
gd.addChoice("Method:", methods, methods[staticMethod]);
}
gd.addStringField("Name:", name, 12);
gd.addStringField("Title Contains:", "", 12);
gd.addStringField("Title contains:", "", 12);
if (sizesDiffer)
gd.addCheckbox("Bicubic Interpolation", staticBicubic);
gd.addCheckbox("Use Titles as Labels", staticTitlesAsLabels);
gd.addCheckbox("Keep Source Images", staticKeep);
gd.addCheckbox("Bicubic interpolation", staticBicubic);
gd.addCheckbox("Use titles as labels", staticTitlesAsLabels);
gd.addCheckbox("Keep source images", staticKeep);
gd.showDialog();
if (gd.wasCanceled()) return;
if (sizesDiffer)
Expand Down Expand Up @@ -150,6 +150,8 @@ private ImagePlus convert(ImagePlus[] images, int count) {
if (ip.getMin()<min) min = ip.getMin();
if (ip.getMax()>max) max = ip.getMax();
String label = titlesAsLabels?images[i].getTitle():null;
if (label==null)
label = (String)images[i].getProperty("Label");
if (label!=null) {
String info = (String)images[i].getProperty("Info");
if (info!=null) label += "\n" + info;
Expand Down
116 changes: 96 additions & 20 deletions ij/plugin/RoiEnlarger.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
import ij.measure.Calibration;
import ij.plugin.filter.EDM;
import ij.plugin.filter.ThresholdToSelection;
import ij.plugin.frame.Recorder;
import java.awt.*;
import java.util.Vector;

/** This plugin, which enlarges or shrinks selections, implements the Edit/Selection/Enlarge command. */
public class RoiEnlarger implements PlugIn {
private static double defaultDistance = 15; // pixels
public class RoiEnlarger implements PlugIn, DialogListener {
private static final String DISTANCE_KEY = "enlarger.distance";
private static final String USE_PIXELS_KEY = "enlarger.pixels";
private double defaultDistance = Prefs.get(DISTANCE_KEY, 15); // pixels
private boolean defaultUsePixels = Prefs.get(USE_PIXELS_KEY, false);
private Calibration cal;
private Label unitsLabel;

public void run(String arg) {
ImagePlus imp = IJ.getImage();
Expand All @@ -21,42 +28,111 @@ public void run(String arg) {
if (!imp.okToDeleteRoi())
return;
double n = showDialog(imp, defaultDistance);
if (n==Double.NaN)
if (Double.isNaN(n))
return;
Prefs.set(DISTANCE_KEY, defaultDistance);
Prefs.set(USE_PIXELS_KEY, defaultUsePixels);
Roi roi2 = Math.abs(n)<256?enlarge255(roi,n):enlarge(roi,n);
if (roi2!=null) {
imp.setRoi(roi2);
Roi.setPreviousRoi(roi);
defaultDistance = n;
}
int pixels = (int)Math.round(n);
Recorder.recordCall("RoiEnlarger.enlarge(imp, "+pixels+");");
}


public static void enlarge(ImagePlus imp, int pixels) {
Roi roi = imp.getRoi();
if (roi==null || roi.isLine() || (roi instanceof PointRoi))
return;
Roi roi2 = Math.abs(pixels)<256?enlarge255(roi,pixels):enlarge(roi,pixels);
if (roi2!=null)
imp.setRoi(roi2);
}

public double showDialog(ImagePlus imp, double pixels) {
Calibration cal = imp.getCalibration();
cal = imp.getCalibration();
boolean scaled = cal.scaled();
boolean usePixels = false;
double n = pixels*cal.pixelWidth;
double pixelWidth = cal.pixelWidth;
boolean xyScaleDifferent = scaled && cal.pixelWidth != cal.pixelHeight;
boolean usePixels = defaultUsePixels;
double n = pixels;
int decimalPlaces = 0;
if (Math.floor(n)!=n)
decimalPlaces = 2;
if (scaled && !usePixels) {
n *= pixelWidth;
decimalPlaces = getDecimalPlaces(pixelWidth, n);
}
GenericDialog gd = new GenericDialog("Enlarge Selection");
gd.addNumericField("Enlarge by", n, decimalPlaces, 4, cal.getUnits());
gd.addNumericField("Enlarge by", n, decimalPlaces);
String units = scaled && !usePixels ? cal.getUnits()+" " : "pixels ";
gd.addToSameRow();
gd.addMessage(units.replace('\n', ' ')); //just in case of a newline character, which would make it a MultiLineLabel
unitsLabel = (Label)gd.getMessage();
if (scaled) {
gd.setInsets(0, 20, 0);
gd.setInsets(0, 20, 0); //top left bottom
gd.addCheckbox("Pixel units", usePixels);
}
gd.setInsets(10, 0, 0);
gd.addMessage("Enter negative number to shrink", null, Color.darkGray);
if (xyScaleDifferent) {
gd.setInsets(5, 0, 0);
gd.addMessage(" \n ", null, Color.RED);
}
gd.addDialogListener(this);
if (xyScaleDifferent && Macro.getOptions()==null)
updateWarning(gd); //in interactive mode only
gd.showDialog();
if (gd.wasCanceled())
return Double.NaN;
n = gd.getNextNumber();
if (scaled)
usePixels = gd.getNextBoolean();
pixels = usePixels?n:n/cal.pixelWidth;
pixels = usePixels ? n : n/pixelWidth;
defaultDistance = pixels;
defaultUsePixels = usePixels;
return pixels;
}


public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
Vector checkboxes = gd.getCheckboxes();
Checkbox usePixelsCbx = checkboxes == null ? null : (Checkbox)checkboxes.get(0);
double n = gd.getNextNumber();
boolean usePixels = cal.scaled() ? gd.getNextBoolean() : true; //getNextBoolean also needed for macro recorded
if (e != null && e.getSource() == usePixelsCbx) {
double pixelWidth = cal.pixelWidth;
int decimalPlaces = 0;
if (usePixels) {
n /= pixelWidth; //scaled to pixels
} else {
n *= pixelWidth; //pixels to scaled
decimalPlaces = getDecimalPlaces(pixelWidth, n);
}
TextField numberField = (TextField)gd.getNumericFields().get(0);
numberField.setText(IJ.d2s(n, decimalPlaces));
if (unitsLabel != null) unitsLabel.setText(usePixels ? "pixels" : cal.getUnits());
boolean xyScaleDifferent = cal.scaled() && cal.pixelWidth != cal.pixelHeight;
if (xyScaleDifferent && usePixelsCbx != null) updateWarning(gd);
}
return !gd.invalidNumber();
}

private void updateWarning(GenericDialog gd) {
Checkbox usePixelsCbx = (Checkbox)gd.getCheckboxes().get(0);
MultiLineLabel warningLabel = (MultiLineLabel)gd.getMessage();
boolean showWarning = !usePixelsCbx.getState(); //warn if not pixels units
warningLabel.setText(showWarning ? "WARNING: x & y scales differ\nConversion to pixels uses x scale" : " \n ");
}

//decimal places for displaying the scaled enlarge/shrink value
private static int getDecimalPlaces(double pixelWidth, double number) {
if (number == (int)number || pixelWidth == 1) return 0;
int decimalPlaces = (int)(-Math.log10(pixelWidth)+1.9);
if (decimalPlaces < 0) decimalPlaces = 0;
if (decimalPlaces >9) decimalPlaces = 9;
return decimalPlaces;
}

public static Roi enlarge(Roi roi, double pixels) {
if (pixels==0)
return roi;
Expand Down Expand Up @@ -86,14 +162,14 @@ public static Roi enlarge(Roi roi, double pixels) {
edm.setThreshold(0, n, ImageProcessor.NO_LUT_UPDATE);
roi2 = (new ThresholdToSelection()).convert(edm);
if (roi2==null)
return roi;
return roi;
roi2.copyAttributes(roi);
roi2.setLocation(bounds.x-n+xoffset, bounds.y-n+yoffset);
if (roi.getStroke()!=null)
roi2.setStroke(roi.getStroke());
return roi2;
}

private static Roi enlargeRectOrOval(Roi roi, int n) {
Rectangle bounds = roi.getBounds();
bounds.x -= n;
Expand All @@ -110,7 +186,7 @@ private static Roi enlargeRectOrOval(Roi roi, int n) {
roi2.copyAttributes(roi);
return roi2;
}

private static Roi shrink(Roi roi, int n) {
Rectangle bounds = roi.getBounds();
int width = bounds.width + 2;
Expand All @@ -120,7 +196,7 @@ private static Roi shrink(Roi roi, int n) {
ip.setColor(255);
ip.fill(roi);
roi.setLocation(bounds.x, bounds.y);
FloatProcessor edm = new EDM().makeFloatEDM (ip, 0, false);
FloatProcessor edm = new EDM().makeFloatEDM (ip, 0, false);
edm.setThreshold(n+1, Float.MAX_VALUE, ImageProcessor.NO_LUT_UPDATE);
Roi roi2 = (new ThresholdToSelection()).convert(edm);
if (roi2==null)
Expand All @@ -132,7 +208,7 @@ private static Roi shrink(Roi roi, int n) {
roi2.setLocation(bounds.x+bounds2.x-1, bounds.y+bounds2.y-1);
return roi2;
}

public static Roi enlarge255(Roi roi, double pixels) {
if (pixels==0)
return roi;
Expand Down Expand Up @@ -165,14 +241,14 @@ public static Roi enlarge255(Roi roi, double pixels) {
ip.setThreshold(0, n, ImageProcessor.NO_LUT_UPDATE);
roi2 = (new ThresholdToSelection()).convert(ip);
if (roi2==null)
return roi;
return roi;
roi2.copyAttributes(roi);
roi2.setLocation(bounds.x-n+xoffset, bounds.y-n+yoffset);
if (roi.getStroke()!=null)
roi2.setStroke(roi.getStroke());
return roi2;
}

private static Roi shrink255(Roi roi, int n) {
Rectangle bounds = roi.getBounds();
int width = bounds.width + 2;
Expand Down
Loading

0 comments on commit b553ff4

Please sign in to comment.