public void storeGreyscaleMapIntoAlpha(BufferedImage imageWithoutAlpha, BufferedImage greyscaleImage) { int width = imageWithoutAlpha.getWidth(); int height = imageWithoutAlpha.getHeight(); int[] imagePixels = imageWithoutAlpha.getRGB(0, 0, width, height, null, 0, width); int[] maskPixels = greyscaleImage.getRGB(0, 0, width, height, null, 0, width); for (int i = 0; i < imagePixels.length; i++) { int color = imagePixels[i] & 0x00ffffff; // Mask preexisting alpha int alpha = maskPixels[i] << 24; // Shift blue to alpha imagePixels[i] = color | alpha; } imageWithoutAlpha.setRGB(0, 0, width, height, imagePixels, 0, width); }
private void verifyBorderImage(BufferedImage border) throws Wrong9PatchException { int[] rgb = border.getRGB(0, 0, border.getWidth(), border.getHeight(), null, 0, border.getWidth()); for (int i = 0; i < rgb.length; i++) { if ((0xff000000 & rgb[i]) != 0) { if (rgb[i] != 0xff000000 && rgb[i] != 0xffff0000) { throw new Wrong9PatchException(); } } } } }
int height = term.height(); Image temp = capture.getScaledInstance(width, height, Image.SCALE_SMOOTH); BufferedImage scaled = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = scaled.createGraphics(); g2d.drawImage(temp, 0, 0, null); sb.append("\033[").append(y + 1).append(";1H"); for (int x = 0; x < width; x++) { Color pixel = new Color(scaled.getRGB(x, y)); int r = pixel.getRed(); int g = pixel.getGreen();
/** * Creates a new grayscale picture that is a deep copy of the argument picture. * * @param picture the picture to copy * @throws IllegalArgumentException if {@code picture} is {@code null} */ public GrayscalePicture(GrayscalePicture picture) { if (picture == null) throw new IllegalArgumentException("constructor argument is null"); width = picture.width(); height = picture.height(); image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); filename = picture.filename; isOriginUpperLeft = picture.isOriginUpperLeft; for (int col = 0; col < width(); col++) for (int row = 0; row < height(); row++) image.setRGB(col, row, picture.image.getRGB(col, row)); }
public void applyGrayscaleMaskToAlpha(BufferedImage image, BufferedImage mask) { int width = image.getWidth(); int height = image.getHeight(); int[] imagePixels = image.getRGB(0, 0, width, height, null, 0, width); int[] maskPixels = mask.getRGB(0, 0, width, height, null, 0, width); for (int i = 0; i < imagePixels.length; i++) { int color = imagePixels[i] & 0x00ffffff; // Mask preexisting alpha int alpha = maskPixels[i] << 24; // Shift blue to alpha imagePixels[i] = color | alpha; } image.setRGB(0, 0, width, height, imagePixels, 0, width); }
/** * This method returns the height represented by the specified pixel in the * given texture. The given texture should be a height-map. * * @param image * the height-map texture * @param x * pixel's X coordinate * @param y * pixel's Y coordinate * @return height represented by the given texture in the specified location */ private static int getHeight(BufferedImage image, int x, int y) { if (x < 0) { x = 0; } else if (x >= image.getWidth()) { x = image.getWidth() - 1; } if (y < 0) { y = 0; } else if (y >= image.getHeight()) { y = image.getHeight() - 1; } return image.getRGB(x, y) & 0xff; }
@Override public Vector4f calcColor(Biome biome) { float humidity = biome.getHumidity(); float temperature = biome.getTemperature(); float prod = temperature * humidity; int rgbValue = colorLut.getRGB((int) ((1.0 - temperature) * 255.0), (int) ((1.0 - prod) * 255.0)); Color c = new Color(rgbValue); return new Vector4f(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, 1.0f); } },
BufferedImage scaledImg = new BufferedImage(w, h, img.getType()); Graphics2D g2d = scaledImg.createGraphics(); g2d.drawImage(img, 0, 0, w, h, null); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { Color mycolor = new Color(scaledImg.getRGB(j, i)); int red = mycolor.getRed(); int green = mycolor.getGreen();
/** * Creates a new picture that is a deep copy of the argument picture. * * @param picture the picture to copy * @throws IllegalArgumentException if {@code picture} is {@code null} */ public Picture(Picture picture) { if (picture == null) throw new IllegalArgumentException("constructor argument is null"); width = picture.width(); height = picture.height(); image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); filename = picture.filename; isOriginUpperLeft = picture.isOriginUpperLeft; for (int col = 0; col < width(); col++) for (int row = 0; row < height(); row++) image.setRGB(col, row, picture.image.getRGB(col, row)); }
public BufferedImage processImage (BufferedImage image, int maxIterations) { int width = image.getWidth(); int height = image.getHeight(); BufferedImage processedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); int[] rgb = image.getRGB(0, 0, width, height, null, 0, width); Mask mask = new Mask(rgb); int iterations = 0; int lastPending = -1; while (mask.pendingSize > 0 && mask.pendingSize != lastPending && iterations < maxIterations) { lastPending = mask.pendingSize; executeIteration(rgb, mask, width, height); iterations++; } processedImage.setRGB(0, 0, width, height, rgb, 0, width); return processedImage; }
private static ByteBuffer readRgbModelFrom(BufferedImage image) { int w = image.getWidth(); int h = image.getHeight(); int[] pixels = new int[w * h]; image.getRGB(0, 0, w, h, pixels, 0, w); // use direct byte buffer to resolve heap errors here ByteBuffer rgbBytes = ByteBuffer.allocateDirect(w * h * BLOCK_SIZE); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { int index = r * w + c; int indexRgb = r * w * BLOCK_SIZE + c * BLOCK_SIZE; rgbBytes.put(indexRgb, (byte) ((pixels[index] >> 16) & 0xff)); rgbBytes.put(indexRgb + 1, (byte) ((pixels[index] >> 8) & 0xff)); rgbBytes.put(indexRgb + 2, (byte) (pixels[index] & 0xff)); rgbBytes.put(indexRgb + 3, (byte) ((pixels[index] >> 24) & 0xff)); } } return rgbBytes; }
@Override public Vector4f calcColor(Biome biome) { float humidity = biome.getHumidity(); float temperature = biome.getTemperature(); float prod = humidity * temperature; int rgbValue = foliageLut.getRGB((int) ((1.0 - temperature) * 255.0), (int) ((1.0 - prod) * 255.0)); Color c = new Color(rgbValue); return new Vector4f(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, 1.0f); } };
final int height2 = ruy - loy + 1; boolean border = false; final BufferedImage image2 = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_RGB); rgb = this.image.getRGB(i - 1, j); border = (rgb == bgcolor); rgbR += rgb >> 16 & 0xff; rgb = this.image.getRGB(i, j - 1); border = border || (rgb == bgcolor); rgbR += rgb >> 16 & 0xff; rgb = this.image.getRGB(i + 1, j); border = border || (rgb == bgcolor); rgbR += rgb >> 16 & 0xff; rgb = this.image.getRGB(i, j + 1); border = border || (rgb == bgcolor); rgbR += rgb >> 16 & 0xff; rgb = this.image.getRGB(i, j); image2.setRGB(i-lox, j-loy, rgb);
public BufferedImage processImage (BufferedImage image, int maxIterations) { int width = image.getWidth(); int height = image.getHeight(); BufferedImage processedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); int[] rgb = image.getRGB(0, 0, width, height, null, 0, width); Mask mask = new Mask(rgb); int iterations = 0; int lastPending = -1; while (mask.pendingSize > 0 && mask.pendingSize != lastPending && iterations < maxIterations) { lastPending = mask.pendingSize; executeIteration(rgb, mask, width, height); iterations++; } processedImage.setRGB(0, 0, width, height, rgb, 0, width); return processedImage; }
public void drawImage(BufferedImage image, double x, double y) { final int width = image.getWidth(); final int height = image.getHeight(); append("gsave", true); append(format(x) + " " + format(y) + " translate", true); append(format(width) + " " + format(height) + " scale", true); append("" + width + " " + height + " 8 [" + width + " 0 0 -" + height + " 0 " + height + "]", true); // append("" + width + " " + height + " 8 [0 0 0 0 0 0]"); append("{<", true); final StringBuilder sb = new StringBuilder(); for (int j = height - 1; j >= 0; j--) { for (int i = 0; i < width; i++) { final String hexString = getRgb(image.getRGB(i, j)); assert hexString.length() == 6; sb.append(hexString); } } append(sb.toString(), true); // append(">} image"); append(">} false 3 colorimage", true); ensureVisible(x + width, y + height); append("grestore", true); }
private static BufferedImage addTransparent(BufferedImage ico) { if (ico == null) { return null; } final BufferedImage transparentIcon = new BufferedImage(ico.getWidth(), ico.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE); for (int i = 0; i < ico.getWidth(); i++) { for (int j = 0; j < ico.getHeight(); j++) { final int col = ico.getRGB(i, j); if (col != ico.getRGB(0, 0)) { transparentIcon.setRGB(i, j, col); } } } return transparentIcon; }
/** * Converts BufferedImage to SWT/Image with alpha channel. */ protected Image swing2swt( Device device, BufferedImage img ) { PaletteData palette = new PaletteData( 0xFF0000, 0xFF00, 0xFF ); ImageData data = new ImageData( img.getWidth(), img.getHeight(), 32, palette ); for ( int y = 0; y < data.height; y++ ) { for ( int x = 0; x < data.width; x++ ) { int rgba = img.getRGB( x, y ); int rgb = palette.getPixel( new RGB( ( rgba >> 16 ) & 0xFF, ( rgba >> 8 ) & 0xFF, rgba & 0xFF ) ); int a = ( rgba >> 24 ) & 0xFF; data.setPixel( x, y, rgb ); data.setAlpha( x, y, a ); } } return new Image( device, data ); } }
/** * Returns the grayscale value of pixel ({@code col}, {@code row}) as a {@link java.awt.Color}. * * @param col the column index * @param row the row index * @return the grayscale value of pixel ({@code col}, {@code row}) * @throws IllegalArgumentException unless both {@code 0 <= col < width} and {@code 0 <= row < height} */ public Color get(int col, int row) { validateColumnIndex(col); validateRowIndex(row); Color color = new Color(image.getRGB(col, row)); return toGray(color); }