protected void setDrawingColor(int ox, int oy, boolean setBackground) { // IJ.log("setDrawingColor: "+setBackground+this); int type = imp.getType(); int[] v = imp.getPixel(ox, oy); switch (type) { case ImagePlus.GRAY8: { if (setBackground) setBackgroundColor(getColor(v[0])); else setForegroundColor(getColor(v[0])); break; } case ImagePlus.GRAY16: case ImagePlus.GRAY32: { double min = imp.getProcessor().getMin(); double max = imp.getProcessor().getMax(); double value = (type == ImagePlus.GRAY32) ? Float.intBitsToFloat(v[0]) : v[0]; int index = (int) (255.0 * ((value - min) / (max - min))); if (index < 0) index = 0; if (index > 255) index = 255; if (setBackground) setBackgroundColor(getColor(index)); else setForegroundColor(getColor(index)); break; } case ImagePlus.COLOR_RGB: case ImagePlus.COLOR_256: { Color c = new Color(v[0], v[1], v[2]); if (setBackground) setBackgroundColor(c); else setForegroundColor(c); break; } } Color c; if (setBackground) c = Toolbar.getBackgroundColor(); else { c = Toolbar.getForegroundColor(); imp.setColor(c); } IJ.showStatus("(" + c.getRed() + ", " + c.getGreen() + ", " + c.getBlue() + ")"); }
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(); } }