/** * {@collect.stats} Filters an IndexColorModel object by running each entry in its color tables * through the filterRGB function that RGBImageFilter subclasses must provide. Uses coordinates of * -1 to indicate that a color table entry is being filtered rather than an actual pixel value. * * @param icm the IndexColorModel object to be filtered * @exception NullPointerException if <code>icm</code> is null * @return a new IndexColorModel representing the filtered colors */ public IndexColorModel filterIndexColorModel(IndexColorModel icm) { int mapsize = icm.getMapSize(); byte r[] = new byte[mapsize]; byte g[] = new byte[mapsize]; byte b[] = new byte[mapsize]; byte a[] = new byte[mapsize]; icm.getReds(r); icm.getGreens(g); icm.getBlues(b); icm.getAlphas(a); int trans = icm.getTransparentPixel(); boolean needalpha = false; for (int i = 0; i < mapsize; i++) { int rgb = filterRGB(-1, -1, icm.getRGB(i)); a[i] = (byte) (rgb >> 24); if (a[i] != ((byte) 0xff) && i != trans) { needalpha = true; } r[i] = (byte) (rgb >> 16); g[i] = (byte) (rgb >> 8); b[i] = (byte) (rgb >> 0); } if (needalpha) { return new IndexColorModel(icm.getPixelSize(), mapsize, r, g, b, a); } else { return new IndexColorModel(icm.getPixelSize(), mapsize, r, g, b, trans); } }
void setHistogram(ImagePlus imp, int j) { ImageProcessor ip = imp.getProcessor(); ImageStatistics stats = ImageStatistics.getStatistics(ip, AREA + MODE, null); int maxCount2 = 0; histogram = stats.histogram; for (int i = 0; i < stats.nBins; i++) if ((histogram[i] > maxCount2) && (i != stats.mode)) maxCount2 = histogram[i]; hmax = stats.maxCount; if ((hmax > (maxCount2 * 1.5)) && (maxCount2 != 0)) { // GL 1.5 was 2 hmax = (int) (maxCount2 * 1.1); // GL 1.1 was 1.5 histogram[stats.mode] = hmax; } os = null; ColorModel cm = ip.getColorModel(); if (!(cm instanceof IndexColorModel)) return; IndexColorModel icm = (IndexColorModel) cm; int mapSize = icm.getMapSize(); if (mapSize != 256) return; byte[] r = new byte[256]; byte[] g = new byte[256]; byte[] b = new byte[256]; icm.getReds(r); icm.getGreens(g); icm.getBlues(b); hColors = new Color[256]; if (isRGB) { if (j == 0) { for (int i = 0; i < 256; i++) hColors[i] = new Color(i & 255, 0 & 255, 0 & 255); } else if (j == 1) { for (int i = 0; i < 256; i++) hColors[i] = new Color(0 & 255, i & 255, 0 & 255); } else if (j == 2) { for (int i = 0; i < 256; i++) hColors[i] = new Color(0 & 255, 0 & 255, i & 255); } } else { if (j == 0) { for (int i = 0; i < 256; i++) hColors[i] = new Color(r[i] & 255, g[i] & 255, b[i] & 255); } else if (j == 1) { for (int i = 0; i < 256; i++) // hColors[i] = new Color(127-i/2&255, 127+i/2&255, 127-i/2&255); hColors[i] = new Color(192 - i / 4 & 255, 192 + i / 4 & 255, 192 - i / 4 & 255); } else if (j == 2) { for (int i = 0; i < 256; i++) hColors[i] = new Color(i & 255, i & 255, 0 & 255); } } }