List of usage examples for java.awt.image BufferedImage setRGB
public void setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)
From source file:MultiTextureTest.java
public Texture createLightMap() { int width = 128; int height = 128; BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); int[] rgbArray = new int[width * height]; int index, index2; int rgbInc = 256 / (width / 2 - 20); int rgbValue = 0; int k = width / 2 - 5; int i, j, rgb; rgb = 0xff;// w w w . j ava 2s . c o m rgbValue = rgb | (rgb << 8) | (rgb << 16) | (rgb << 24); for (i = width / 2 - 1, j = 0; j < 10; j++, i--) { rgbArray[i] = rgbValue; } for (; i > 8; i--, rgb -= rgbInc) { rgbValue = rgb | (rgb << 8) | (rgb << 16) | (rgb << 24); rgbArray[i] = rgbValue; } for (; i >= 0; i--) { rgbArray[i] = rgbValue; } for (i = 0; i < width / 2; i++) { rgbValue = rgbArray[i]; index = i; index2 = (width - i - 1); for (j = 0; j < height; j++) { rgbArray[index] = rgbArray[index2] = rgbValue; index += width; index2 += width; } } bimage.setRGB(0, 0, width, height, rgbArray, 0, width); ImageComponent2D grayImage = new ImageComponent2D(ImageComponent.FORMAT_RGB, bimage); lightTex = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, width, height); lightTex.setImage(0, grayImage); return lightTex; }
From source file:ResourceBundleSupport.java
/** * Creates a transparent image. These can be used for aligning menu items. * * @param width the width./*from w w w . ja va 2 s . co m*/ * @param height the height. * @return the created transparent image. */ private BufferedImage createTransparentImage(final int width, final int height) { final BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final int[] data = img.getRGB(0, 0, width, height, null, 0, width); Arrays.fill(data, 0x00000000); img.setRGB(0, 0, width, height, data, 0, width); return img; }
From source file:dk.dma.msinm.web.wms.WmsProxyServlet.java
/** * Masks out white colour// www .j a v a 2s.c o m * @param image the image to mask out * @return the resulting image */ private BufferedImage transformWhiteToTransparent(BufferedImage image) { BufferedImage dest = image; if (image.getType() != BufferedImage.TYPE_INT_ARGB) { dest = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = dest.createGraphics(); g2.drawImage(image, 0, 0, null); g2.dispose(); image.flush(); } // Mask out the white pixels final int width = image.getWidth(); int[] imgData = new int[width]; for (int y = 0; y < dest.getHeight(); y++) { // fetch a line of data from each image dest.getRGB(0, y, width, 1, imgData, 0, 1); // apply the mask for (int x = 0; x < width; x++) { for (Color col : MASKED_COLORS) { int colDist = Math.abs(col.getRed() - (imgData[x] >> 16 & 0x000000FF)) + Math.abs(col.getGreen() - (imgData[x] >> 8 & 0x000000FF)) + Math.abs(col.getBlue() - (imgData[x] & 0x000000FF)); if (colDist <= COLOR_DIST) { imgData[x] = 0x00FFFFFF & imgData[x]; } } } // replace the data dest.setRGB(0, y, width, 1, imgData, 0, 1); } return dest; }
From source file:org.niord.web.wms.WmsProxyServlet.java
/** * Masks out white colour//from w w w . j av a 2 s . c o m * @param image the image to mask out * @return the resulting image */ @SuppressWarnings("unused") private BufferedImage transformWhiteToTransparent(BufferedImage image) { BufferedImage dest = image; if (image.getType() != BufferedImage.TYPE_INT_ARGB) { dest = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = dest.createGraphics(); g2.drawImage(image, 0, 0, null); g2.dispose(); image.flush(); } // Mask out the white pixels final int width = image.getWidth(); int[] imgData = new int[width]; for (int y = 0; y < dest.getHeight(); y++) { // fetch a line of data from each image dest.getRGB(0, y, width, 1, imgData, 0, 1); // apply the mask for (int x = 0; x < width; x++) { for (Color col : MASKED_COLORS) { int colDist = Math.abs(col.getRed() - (imgData[x] >> 16 & 0x000000FF)) + Math.abs(col.getGreen() - (imgData[x] >> 8 & 0x000000FF)) + Math.abs(col.getBlue() - (imgData[x] & 0x000000FF)); if (colDist <= COLOR_DIST) { imgData[x] = 0x00FFFFFF & imgData[x]; } } } // replace the data dest.setRGB(0, y, width, 1, imgData, 0, 1); } return dest; }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
public void setBgrImageBrightness(float t) { if (baseBgrImage == null) { return;/*w w w.j a v a2s . co m*/ } int w = baseBgrImage.getWidth(); int h = baseBgrImage.getHeight(); int[] bgrData = baseBgrImage.getRGB(0, 0, w, h, null, 0, w); for (int i = 0; i < bgrData.length; i++) { int imc = bgrData[i]; int r = (int) (t * ((imc >> 16) & 0xff)); int g = (int) (t * ((imc >> 8) & 0xff)); int b = (int) (t * (imc & 0xff)); bgrData[i] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } BufferedImage bgrImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); bgrImage.setRGB(0, 0, w, h, bgrData, 0, w); ImageComponent2D bgrImageComponent = new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, bgrImage); bg.setImage(bgrImageComponent); }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
public void setBackgroundGradient(Color c0, Color c1, Color c2) { bgColor = new Color3f(c0.getColorComponents(null)); myFog.setColor(bgColor);// w ww . jav a 2 s. c om fireBgrColorChanged(); int r0 = c0.getRed(), r1 = c1.getRed(), r2 = c2.getRed(); int g0 = c0.getGreen(), g1 = c1.getGreen(), g2 = c2.getGreen(); int b0 = c0.getBlue(), b1 = c1.getBlue(), b2 = c2.getBlue(); int[] bgrData = new int[256 * 256]; int k = 0; for (int i = 0; i < 128; i++) { float t = i / 127.f; int r = (int) (t * r1 + (1 - t) * r0); int g = (int) (t * g1 + (1 - t) * g0); int b = (int) (t * b1 + (1 - t) * b0); int c = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); for (int j = 0; j < 256; j++, k++) { bgrData[k] = c; } } for (int i = 0; i < 128; i++) { float t = i / 127.f; int r = (int) (t * r2 + (1 - t) * r1); int g = (int) (t * g2 + (1 - t) * g1); int b = (int) (t * b2 + (1 - t) * b1); int c = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); for (int j = 0; j < 256; j++, k++) { bgrData[k] = c; } } BufferedImage bgrImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); bgrImage.setRGB(0, 0, 256, 256, bgrData, 0, 256); ImageComponent2D bgrImageComponent = new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, bgrImage); bg.setImage(bgrImageComponent); }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
private void initializeOnceCrosshairCursor() { if (crosshairCursor == null) { Toolkit toolkit = Toolkit.getDefaultToolkit(); BufferedImage crosshairCursorImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); int[] crosshairCursorRaster = new int[32 * 32]; for (int i = 0; i < crosshairCursorRaster.length; i++) { crosshairCursorRaster[i] = 0; }//from w ww. j a v a 2 s . c o m for (int i = 0; i < 14; i++) { crosshairCursorRaster[15 * 32 + i] = crosshairCursorRaster[15 * 32 + 31 - i] = 0xff888888; crosshairCursorRaster[15 + 32 * i] = crosshairCursorRaster[15 + 32 * (31 - i)] = 0xff888888; } crosshairCursorImage.setRGB(0, 0, 32, 32, crosshairCursorRaster, 0, 32); crosshairCursor = toolkit.createCustomCursor(crosshairCursorImage, new Point(15, 15), "crosshairCursor"); } }
From source file:gui.images.ImageHubExplorer.java
/** * This method calculates and sets the background landscape for the MDS data * visualization. The landscape is set according the the good/bad hubness * densities of different regions in the panel, based on the MDS projection * of the data. The landscape is then softened by applying some blurring. *//*from w w w . ja v a 2s . c om*/ public void setMDSBackground() { if (mdsBackgrounds[neighborhoodSize - 1] == null) { // Get the width and height of the panel. int width = mdsCollectionPanel.getWidth(); int height = mdsCollectionPanel.getHeight(); // Cell size. int step = 100; int steppedWidth = width / step; if (width % step != 0) { steppedWidth++; } int steppedHeight = height / step; if (height % step != 0) { steppedHeight++; } // Get the kNN sets for the appropriate neighborhood size. NeighborSetFinder nsf = getNSF().copy(); nsf.recalculateStatsForSmallerK(neighborhoodSize); int[] badHubness = nsf.getBadFrequencies(); int[] goodHubness = nsf.getGoodFrequencies(); int bucketX, bucketY; // Place all the projected data into the appropriate buckets in the // cell grid. // First initialize the buckets. ArrayList<Integer>[][] bucketedData = new ArrayList[steppedWidth][steppedHeight]; for (int i = 0; i < steppedWidth; i++) { for (int j = 0; j < steppedHeight; j++) { bucketedData[i][j] = new ArrayList<>(5); } } // Insert the data into the buckets. for (int i = 0; i < imageCoordinatesXY.length; i++) { bucketX = (int) (imageCoordinatesXY[i][0] / step); bucketY = (int) (imageCoordinatesXY[i][1] / step); if (bucketX >= bucketedData.length) { continue; } if (bucketY >= bucketedData[bucketX].length) { continue; } bucketedData[bucketX][bucketY].add(i); } int[] landscapeRaster = new int[width * height]; // The goodness of a pixel. int greennessValue; // Good and bad hubness contributions. double ghFactor; double bhFactor; // Weight of a contribution. double weight; // Kernel width. double sigma = 0.05; int pX; int pY; int pIndex; for (int i = 0; i < landscapeRaster.length; i++) { pX = i % width; pY = i / width; bucketX = (pX) / step; bucketY = (pY) / step; ghFactor = 0; bhFactor = 0; for (int j = 0; j < bucketedData[bucketX][bucketY].size(); j++) { pIndex = bucketedData[bucketX][bucketY].get(j); weight = Math.min(Math.exp( -sigma * ((imageCoordinatesXY[pIndex][0] - pX) * (imageCoordinatesXY[pIndex][0] - pX) + (imageCoordinatesXY[pIndex][1] - pY) * (imageCoordinatesXY[pIndex][1] - pY))), 1); ghFactor += weight * goodHubness[pIndex]; bhFactor += weight * badHubness[pIndex]; } if (ghFactor > 0 || bhFactor > 0) { greennessValue = (int) (255 * ((ghFactor) / (ghFactor + bhFactor))); landscapeRaster[i] = greennessValue << 8 | (255 - greennessValue) << 16; } else { landscapeRaster[i] = 0x809080; } } // Now perform several passes of box blur to soften the landscape. BoxBlur bb = new BoxBlur(18); bb.blurPixels(landscapeRaster, new int[landscapeRaster.length], new Dimension(width, height)); bb = new BoxBlur(9); bb.blurPixels(landscapeRaster, new int[landscapeRaster.length], new Dimension(width, height)); bb = new BoxBlur(17); bb.blurPixels(landscapeRaster, new int[landscapeRaster.length], new Dimension(width, height)); BufferedImage bckg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); bckg.setRGB(0, 0, width, height, landscapeRaster, 0, width); mdsBackgrounds[neighborhoodSize - 1] = bckg; mdsCollectionPanel.setBackgroundImage(bckg); // Refresh the display. mdsCollectionPanel.revalidate(); mdsCollectionPanel.repaint(); } else { // Load a landscape that was already calculated. mdsCollectionPanel.setBackgroundImage(mdsBackgrounds[neighborhoodSize - 1]); mdsCollectionPanel.revalidate(); mdsCollectionPanel.repaint(); } }