void editColor() { Color c = background ? Toolbar.getBackgroundColor() : Toolbar.getForegroundColor(); ColorChooser cc = new ColorChooser((background ? "Background" : "Foreground") + " Color", c, false); c = cc.getColor(); if (background) Toolbar.setBackgroundColor(c); else Toolbar.setForegroundColor(c); }
public void refreshForeground() { // Boundary for Foreground Selection setColor(0x444444); drawRect(8, 266, (w * 2) + 4, (h * 2) + 4); setColor(0x999999); drawRect(9, 267, (w * 2) + 2, (h * 2) + 2); setRoi(10, 268, w * 2, h * 2); // Paints the Foreground Color setColor(Toolbar.getForegroundColor()); fill(); imp.updateAndDraw(); }
public void mousePressed(MouseEvent e) { // super.mousePressed(e); ImageProcessor ip = imp.getProcessor(); ip.setLineWidth(1); if (Toolbar.getToolId() == Toolbar.DROPPER) IJ.setTool(Toolbar.RECTANGLE); Rectangle flipperRect = new Rectangle(86, 268, 18, 18); Rectangle resetRect = new Rectangle(86, 294, 18, 18); Rectangle foreground1Rect = new Rectangle(9, 266, 45, 10); Rectangle foreground2Rect = new Rectangle(9, 276, 23, 25); Rectangle background1Rect = new Rectangle(33, 302, 45, 10); Rectangle background2Rect = new Rectangle(56, 277, 23, 25); int x = offScreenX(e.getX()); int y = offScreenY(e.getY()); long difference = System.currentTimeMillis() - mouseDownTime; boolean doubleClick = (difference <= 250); mouseDownTime = System.currentTimeMillis(); if (flipperRect.contains(x, y)) { Color c = Toolbar.getBackgroundColor(); Toolbar.setBackgroundColor(Toolbar.getForegroundColor()); Toolbar.setForegroundColor(c); } else if (resetRect.contains(x, y)) { Toolbar.setForegroundColor(new Color(0x000000)); Toolbar.setBackgroundColor(new Color(0xffffff)); } else if ((background1Rect.contains(x, y)) || (background2Rect.contains(x, y))) { background = true; if (doubleClick) editColor(); ((ColorGenerator) ip).refreshForeground(); ((ColorGenerator) ip).refreshBackground(); } else if ((foreground1Rect.contains(x, y)) || (foreground2Rect.contains(x, y))) { background = false; if (doubleClick) editColor(); ((ColorGenerator) ip).refreshBackground(); ((ColorGenerator) ip).refreshForeground(); } else { // IJ.log(" " + difference + " " + doubleClick); if (doubleClick) editColor(); else { setDrawingColor(offScreenX(e.getX()), offScreenY(e.getY()), background); } } if (ip instanceof ColorGenerator) { if (background) { ((ColorGenerator) ip).refreshForeground(); ((ColorGenerator) ip).refreshBackground(); } else { ((ColorGenerator) ip).refreshBackground(); ((ColorGenerator) ip).refreshForeground(); } } }
void apply(ImagePlus imp, ImageProcessor ip) { // this.setCursor(wait); // IJ.showStatus("Bandpassing slice "+previousSlice); java.awt.Color col; if (invert.getState()) col = Toolbar.getForegroundColor(); else col = Toolbar.getBackgroundColor(); ip.setColor(col); int fill = ip.BLACK; int keep = 0; if (bandPassH.getState() && bandPassS.getState() && bandPassB.getState()) { // PPP All pass for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue < minHue) || (hue > maxHue)) || ((sat < minSat) || (sat > maxSat)) || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (!bandPassH.getState() && !bandPassS.getState() && !bandPassB.getState()) { // SSS All stop for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue >= minHue) && (hue <= maxHue)) || ((sat >= minSat) && (sat <= maxSat)) || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (bandPassH.getState() && bandPassS.getState() && !bandPassB.getState()) { // PPS for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue < minHue) || (hue > maxHue)) || ((sat < minSat) || (sat > maxSat)) || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (!bandPassH.getState() && !bandPassS.getState() && bandPassB.getState()) { // SSP for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue >= minHue) && (hue <= maxHue)) || ((sat >= minSat) && (sat <= maxSat)) || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (bandPassH.getState() && !bandPassS.getState() && !bandPassB.getState()) { // PSS for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue < minHue) || (hue > maxHue)) || ((sat >= minSat) && (sat <= maxSat)) || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (!bandPassH.getState() && bandPassS.getState() && bandPassB.getState()) { // SPP for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue >= minHue) && (hue <= maxHue)) || ((sat < minSat) || (sat > maxSat)) || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (!bandPassH.getState() && bandPassS.getState() && !bandPassB.getState()) { // SPS for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue >= minHue) && (hue <= maxHue)) || ((sat < minSat) || (sat > maxSat)) || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (bandPassH.getState() && !bandPassS.getState() && bandPassB.getState()) { // PSP for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue < minHue) || (hue > maxHue)) || ((sat >= minSat) && (sat <= maxSat)) || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } ip.fill(fillMask); if (threshold.getState()) { ip.invert(); for (int j = 0; j < numPixels; j++) { if (fillMask[j] == fill) fillMask[j] = keep; else fillMask[j] = fill; } ip.fill(fillMask); ip.invert(); } }