Java Code Examples for java.awt.image.IndexColorModel#getRGB()
The following examples show how to use
java.awt.image.IndexColorModel#getRGB() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShortHistogramTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 2
Source File: ShortHistogramTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 3
Source File: ShortHistogramTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 4
Source File: ShortHistogramTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 5
Source File: ShortHistogramTest.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 6
Source File: ShortHistogramTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 7
Source File: ShortHistogramTest.java From hottub with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 8
Source File: ShortHistogramTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 9
Source File: ShortHistogramTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 10
Source File: HeadlessIndexColorModel.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String args[]) { IndexColorModel cm = new IndexColorModel(8, 1, new byte[]{(byte) 128}, new byte[]{(byte) 128}, new byte[]{(byte) 128}); cm.getTransparency(); cm.getComponentSize(); cm.isAlphaPremultiplied(); cm.hasAlpha(); cm.isAlphaPremultiplied(); cm.getTransferType(); cm.getPixelSize(); cm.getComponentSize(); cm.getNumComponents(); cm.getNumColorComponents(); cm.getRed(20); cm.getGreen(20); cm.getBlue(20); cm.getAlpha(20); cm.getRGB(20); cm.isAlphaPremultiplied(); }
Example 11
Source File: ShortHistogramTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 12
Source File: ShortHistogramTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 13
Source File: ShortHistogramTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 14
Source File: ShortHistogramTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
protected BufferedImage createTestImage(int numColors) { IndexColorModel icm = createTestICM(numColors); int w = numColors * 10; int h = 20; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g = img.createGraphics(); for (int i = 0; i < numColors; i++) { int rgb = icm.getRGB(i); //System.out.printf("pixel %d, rgb %x\n", i, rgb); g.setColor(new Color(rgb)); g.fillRect(i * 10, 0, w - i * 10, h); } g.dispose(); return img; }
Example 15
Source File: PlotPanel.java From jtk with Apache License 2.0 | 5 votes |
/** * Determines if a specified color map has more than one color. * Note that we ignore any variation in alpha. */ private static boolean isMultiColor(ColorMapped cm) { ColorMap cmap = cm.getColorMap(); IndexColorModel icm = cmap.getColorModel(); int n = icm.getMapSize(); int rgb = icm.getRGB(0)&0x00ffffff; for (int i=1; i<n; ++i) if (rgb!=(icm.getRGB(i)&0x00ffffff)) return true; return false; }
Example 16
Source File: GifColorTable.java From pumpernickel with MIT License | 5 votes |
/** * Creates a color table from a <code>ColorIndexModel</code>. * * @param i * this needs to be a byte-based <code>ColorIndexModel</code>. */ public GifColorTable(IndexColorModel i) { this.icm = i; int size = i.getMapSize(); if (size == 0) throw new RuntimeException(); // if size is not an exact power // of 2, we must round it up to one... int realSize; if (size == 2) { realSize = 2; } else if (size <= 4) { realSize = 4; } else if (size <= 8) { realSize = 8; } else if (size <= 16) { realSize = 16; } else if (size <= 32) { realSize = 32; } else if (size <= 64) { realSize = 64; } else if (size <= 128) { realSize = 128; } else if (size <= 256) { realSize = 256; } else { throw new RuntimeException( "The number of colors in a GIF color table must be between 2 and 256."); } data = new byte[3 * realSize]; for (int a = 0; a < size; a++) { int rgb = i.getRGB(a); data[3 * a] = (byte) ((rgb >> 16) & 0xFF); data[3 * a + 1] = (byte) ((rgb >> 8) & 0xFF); data[3 * a + 2] = (byte) (rgb & 0xFF); } }
Example 17
Source File: BMPEncoder.java From jclic with GNU General Public License v2.0 | 5 votes |
/** * Writes the colour map resulting from the source <tt>IndexColorModel</tt>. * @param icm the source <tt>IndexColorModel</tt> * @param out the output to which the colour map will be written * @throws java.io.IOException if an error occurs */ public static void writeColorMap(IndexColorModel icm, net.sf.image4j.io.LittleEndianOutputStream out) throws IOException { int mapSize = icm.getMapSize(); for (int i = 0; i < mapSize; i++) { int rgb = icm.getRGB(i); int r = (rgb >> 16) & 0xFF; int g = (rgb >> 8) & 0xFF; int b = (rgb) &0xFF; out.writeByte(b); out.writeByte(g); out.writeByte(r); out.writeByte(0); } }
Example 18
Source File: ColorModelPatch.java From sis with Apache License 2.0 | 5 votes |
/** * Returns {@code true} if the given color models are equal. The {@link ColorModel} class * defines an {@code equals} method, but as of Java 6 that method does not compare every * attributes. For example it does not compare the color space and the transfer type, so * we have to compare them here. * * @param cm1 the first color model. * @param cm2 the second color model. * @return {@code true} if the two color models are equal. */ private static boolean equals(final ColorModel cm1, final ColorModel cm2) { if (cm1 == cm2) { return true; } if (cm1 != null && cm1.equals(cm2) && cm1.getClass().equals(cm2.getClass()) && cm1.getTransferType() == cm2.getTransferType() && Objects.equals(cm1.getColorSpace(), cm2.getColorSpace())) { if (cm1 instanceof IndexColorModel) { final IndexColorModel icm1 = (IndexColorModel) cm1; final IndexColorModel icm2 = (IndexColorModel) cm2; final int size = icm1.getMapSize(); if (icm2.getMapSize() == size && icm1.getTransparentPixel() == icm2.getTransparentPixel() && Objects.equals(icm1.getValidPixels(), icm2.getValidPixels())) { for (int i=0; i<size; i++) { if (icm1.getRGB(i) != icm2.getRGB(i)) { return false; } } } if (cm1 instanceof MultiBandsIndexColorModel) { final MultiBandsIndexColorModel micm1 = (MultiBandsIndexColorModel) cm1; final MultiBandsIndexColorModel micm2 = (MultiBandsIndexColorModel) cm2; if (micm1.numBands != micm2.numBands || micm1.visibleBand != micm2.visibleBand) { return false; } } } return true; } return false; }
Example 19
Source File: ExeCompiler.java From davmail with GNU General Public License v2.0 | 4 votes |
public BufferedImage getQuantizedImage(Image img) { // 32 bit ico file already loaded as BufferedImage if (img instanceof BufferedImage) { return (BufferedImage) img; } else { int width = img.getWidth(null); int height = img.getHeight(null); int[][] data = new int[width][height]; int[] pixelbuffer = new int[width * height]; PixelGrabber grabber = new PixelGrabber(img, 0, 0, width, height, pixelbuffer, 0, width); try { grabber.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); throw new RuntimeException("Can't load the image provided", e); } for (int i = 0; i < pixelbuffer.length; i++) { data[i % width][i / width] = pixelbuffer[i]; } int[][] savedata = new int[width][height]; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) savedata[x][y] = data[x][y]; int[] palette = net.charabia.util.codec.Quantize.quantizeImage(data, 255); byte[] cmap = new byte[256 * 4]; for (int i = 0; i < palette.length; i++) { // System.out.println(" i= " + (i)); cmap[(i * 4)] = (byte) ((palette[i] >> 16) & 0xFF); cmap[(i * 4) + 1] = (byte) ((palette[i] >> 8) & 0xFF); cmap[(i * 4) + 2] = (byte) (palette[i] & 0xFF); cmap[(i * 4) + 3] = (byte) 0xFF; } IndexColorModel colmodel = new IndexColorModel(8, palette.length, cmap, 0, true, 0); BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // // The normal manner of quantizing would be to run // result.setRGB(0,0, width, height, pixelbuffer, 0, width); // where result is a BufferedImage of // BufferedImage.TYPE_BYTE_INDEXED type. Unfortunately, I // couldn't make it work. So, here is a work-around that // should work similarly. // java.util.Hashtable set = new java.util.Hashtable(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int alpha = (savedata[x][y] >> 24) & 0xFF; if (alpha == 0) { result.setRGB(x, y, 0); // System.out.print("."); } else { int rgb = colmodel.getRGB(data[x][y]); rgb |= 0xFF000000; set.put(new Integer(rgb), new Integer(rgb)); result.setRGB(x, y, rgb); // System.out.print("*"); } } // System.out.println(""); } return result; } }