List of usage examples for java.awt.image ColorModel getComponents
public int[] getComponents(Object pixel, int[] components, int offset)
From source file:MainClass.java
public static void main(String[] args) throws Exception { byte ff = (byte) 0xff; byte[] r = { ff, 0, 0, ff, 0 }; byte[] g = { 0, ff, 0, ff, 0 }; byte[] b = { 0, 0, ff, ff, 0 }; ColorModel cm = new IndexColorModel(3, 5, r, g, b); Color[] colors = { new Color(255, 0, 0), new Color(0, 255, 0), new Color(0, 0, 255) }; for (int i = 0; i < colors.length; i++) { int rgb = colors[i].getRGB(); Object pixel = cm.getDataElements(rgb, null); System.out.println(colors[i] + " -> " + ((byte[]) pixel)[0]); }/*from w w w. ja va2 s.co m*/ for (byte i = 0; i < 5; i++) { int[] unnormalizedComponents = cm.getComponents(i, null, 0); System.out.print(i + " -> unnormalized components"); for (int j = 0; j < unnormalizedComponents.length; j++) System.out.print(" " + unnormalizedComponents[j]); System.out.println(); } }
From source file:Main.java
public static void main(String[] args) { byte ff = (byte) 0xff; byte[] r = { ff, 0, 0, ff, 0 }; byte[] g = { 0, ff, 0, ff, 0 }; byte[] b = { 0, 0, ff, ff, 0 }; ColorModel cm = new IndexColorModel(3, 5, r, g, b); Color[] colors = { new Color(255, 0, 0), new Color(0, 255, 0), new Color(0, 0, 255), new Color(64, 255, 64), new Color(255, 255, 0), new Color(0, 255, 255) }; for (int i = 0; i < colors.length; i++) { float[] normalizedComponents = colors[i].getComponents(null); int[] unnormalizedComponents = cm.getUnnormalizedComponents(normalizedComponents, 0, null, 0); int rgb = colors[i].getRGB(); Object pixel = cm.getDataElements(rgb, null); System.out.println(colors[i] + " -> " + ((byte[]) pixel)[0]); }//from w w w . j av a 2 s . c o m for (byte i = 0; i < 5; i++) { int[] unnormalizedComponents = cm.getComponents(i, null, 0); System.out.print(i + " -> unnormalized components"); for (int j = 0; j < unnormalizedComponents.length; j++) System.out.print(" " + unnormalizedComponents[j]); System.out.println(); } }
From source file:ComponentTest.java
public static void main(String[] args) { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, new int[] { 5, 6, 5 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); Color fifty = new Color(cs, new float[] { 1.0f, 1.0f, 1.0f }, 0); float[] components = fifty.getComponents(null); System.out.print("Original normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); System.out.println();//w w w.j av a2s .c om int[] unnormalized = cm.getUnnormalizedComponents(components, 0, null, 0); System.out.print("Original unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); Object pixel = cm.getDataElements(unnormalized, 0, (Object) null); System.out.print("Pixel samples: "); byte[] pixelBytes = (byte[]) pixel; for (int i = 0; i < 3; i++) System.out.print(pixelBytes[i] + " "); System.out.println(); unnormalized = cm.getComponents(pixel, null, 0); System.out.print("Derived unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); components = cm.getNormalizedComponents(unnormalized, 0, null, 0); System.out.print("Derived normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); System.out.println(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, new int[] { 5, 6, 5 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); Color fifty = new Color(cs, new float[] { 1.0f, 1.0f, 1.0f }, 0); float[] components = fifty.getComponents(null); System.out.print("Original normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); System.out.println();/*from w ww . ja va2 s . c om*/ int[] unnormalized = cm.getUnnormalizedComponents(components, 0, null, 0); System.out.print("Original unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); Object pixel = cm.getDataElements(unnormalized, 0, (Object) null); System.out.print("Pixel samples: "); byte[] pixelBytes = (byte[]) pixel; for (int i = 0; i < 3; i++) System.out.print(pixelBytes[i] + " "); System.out.println(); unnormalized = cm.getComponents(pixel, null, 0); System.out.print("Derived unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); components = cm.getNormalizedComponents(unnormalized, 0, null, 0); System.out.print("Derived normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); }
From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java
@Test public void testTransparentPaletteOpaqueOutput() throws Exception { String url = "wms?LAYERS=" + getLayerId(MockData.TASMANIA_DEM) + "&styles=demTranslucent&" + "FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1" + "&REQUEST=GetMap&SRS=EPSG%3A4326" + "&BBOX=145,-43,146,-41&WIDTH=100&HEIGHT=200&bgcolor=0xFF0000"; BufferedImage bi = getAsImage(url, "image/png"); ColorModel cm = bi.getColorModel(); assertTrue(cm instanceof IndexColorModel); assertEquals(Transparency.OPAQUE, cm.getTransparency()); // grab a pixel in the low left corner, should be red (BG color) int[] pixel = new int[1]; bi.getRaster().getPixel(4, 196, pixel); int[] color = new int[3]; cm.getComponents(pixel[0], color, 0); assertEquals(255, color[0]);/*from www . j a v a2s .c o m*/ assertEquals(0, color[1]); assertEquals(0, color[2]); // a pixel high enough to be solid, should be fully green bi.getRaster().getPixel(56, 49, pixel); cm.getComponents(pixel[0], color, 0); assertEquals(0, color[0]); assertEquals(255, color[1]); assertEquals(0, color[2]); }
From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java
@Test public void testTransparentPaletteTransparentOutput() throws Exception { String url = "wms?LAYERS=" + getLayerId(MockData.TASMANIA_DEM) + "&styles=demTranslucent&" + "FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1" + "&REQUEST=GetMap&SRS=EPSG%3A4326" + "&BBOX=145,-43,146,-41&WIDTH=100&HEIGHT=200&transparent=true"; BufferedImage bi = getAsImage(url, "image/png"); ColorModel cm = bi.getColorModel(); assertTrue(cm instanceof IndexColorModel); assertEquals(Transparency.TRANSLUCENT, cm.getTransparency()); // grab a pixel in the low left corner, should be transparent int[] pixel = new int[1]; bi.getRaster().getPixel(4, 196, pixel); int[] color = new int[4]; cm.getComponents(pixel[0], color, 0); assertEquals(0, color[3]);/*from ww w . j a v a 2 s .c om*/ // a pixel high enough to be solid, should be solid green bi.getRaster().getPixel(56, 49, pixel); cm.getComponents(pixel[0], color, 0); assertEquals(0, color[0]); assertEquals(255, color[1]); assertEquals(0, color[2]); assertEquals(255, color[3]); }
From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java
@Test public void testTransparentPaletteTransparentOutputPng8() throws Exception { String url = "wms?LAYERS=" + getLayerId(MockData.TASMANIA_DEM) + "&styles=demTranslucent&" + "FORMAT=image%2Fpng8&SERVICE=WMS&VERSION=1.1.1" + "&REQUEST=GetMap&SRS=EPSG%3A4326" + "&BBOX=145,-43,146,-41&WIDTH=100&HEIGHT=200&transparent=true"; BufferedImage bi = getAsImage(url, "image/png; mode=8bit"); ColorModel cm = bi.getColorModel(); assertTrue(cm instanceof IndexColorModel); assertEquals(Transparency.TRANSLUCENT, cm.getTransparency()); // grab a pixel in the low left corner, should be transparent int[] pixel = new int[1]; bi.getRaster().getPixel(4, 196, pixel); int[] color = new int[4]; cm.getComponents(pixel[0], color, 0); assertEquals(0, color[3]);/* w w w . j a v a 2 s. c om*/ // a pixel high enough to be solid, should be solid green bi.getRaster().getPixel(56, 49, pixel); cm.getComponents(pixel[0], color, 0); assertEquals(0, color[0]); assertEquals(255, color[1]); assertEquals(0, color[2]); assertEquals(255, color[3]); }