public BufferedImage getImageFromArray(int[] pixels, int width, int height) { BufferedImage tmpImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE); tmpImage.setRGB(0, 0, width, height, pixels, 0, width); return tmpImage; }
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); }
public UImage toUImage(ColorMapper colorMapper, HtmlColor backcolor, HtmlColor forecolor) { final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); if (backcolor == null) { backcolor = HtmlColorUtils.WHITE; } if (forecolor == null) { forecolor = HtmlColorUtils.BLACK; } final HtmlColorGradient gradient = new HtmlColorGradient(backcolor, forecolor, '\0'); for (int col = 0; col < width; col++) { for (int line = 0; line < height; line++) { final int localColor = color[line][col]; if (localColor == -1) { final double coef = 1.0 * grey[line][col] / (16 - 1); final Color c = gradient.getColor(colorMapper, coef); im.setRGB(col, line, c.getRGB()); } else { im.setRGB(col, line, localColor); } } } return new UImage(im); }
/** * 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)); }
@Test public void testNotBadCaching() throws IOException { T reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage one = reader.read(0); BufferedImage two = reader.read(0); assertNotSame("Multiple reads return same (mutable) image", one, two); one.setRGB(0, 0, Color.BLUE.getRGB()); two.setRGB(0, 0, Color.RED.getRGB()); assertTrue(one.getRGB(0, 0) != two.getRGB(0, 0)); reader.dispose(); }
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 static void managePattern(UParam param, Graphics2D g2d) { final UPattern pattern = param.getPattern(); if (pattern == UPattern.VERTICAL_STRIPE) { final BufferedImage bi = new BufferedImage(4, 4, BufferedImage.TYPE_INT_ARGB); final Rectangle r = new Rectangle(0, 0, 4, 4); final int rgb = ((HtmlColorSimple) param.getBackcolor()).getColor999().getRGB(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (i == 0 || i == 1) { bi.setRGB(i, j, rgb); final BufferedImage bi = new BufferedImage(4, 4, BufferedImage.TYPE_INT_ARGB); final Rectangle r = new Rectangle(0, 0, 4, 4); final int rgb = ((HtmlColorSimple) param.getBackcolor()).getColor999().getRGB(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (j == 0 || j == 1) { bi.setRGB(i, j, rgb); final BufferedImage bi = new BufferedImage(4, 4, BufferedImage.TYPE_INT_ARGB); final Rectangle r = new Rectangle(0, 0, 4, 4); final int rgb = ((HtmlColorSimple) param.getBackcolor()).getColor999().getRGB(); bi.setRGB(0, 1, rgb); bi.setRGB(1, 0, rgb); bi.setRGB(1, 1, rgb); bi.setRGB(1, 2, rgb); bi.setRGB(2, 1, rgb); g2d.setPaint(new TexturePaint(bi, r));
public BufferedImage toBufferedImage() { int[] transPixels = new int[pixels.length]; BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for (int i = 0; i < pixels.length; i++) { if (pixels[i] != 0) { transPixels[i] = pixels[i] | 0xff000000; } } img.setRGB(0, 0, width, height, transPixels, 0, width); return img; }
/** * 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; }
public UImage toUImage(ColorMapper colorMapper, HtmlColor backcolor, HtmlColor color) { if (backcolor == null) { backcolor = HtmlColorUtils.WHITE; } if (color == null) { color = HtmlColorUtils.BLACK; } // if (backcolor instanceof HtmlColorGradient) { // return special(colorMapper, (HtmlColorGradient) backcolor, color); // } final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); final HtmlColorGradient gradient = new HtmlColorGradient(backcolor, color, '\0'); for (int col = 0; col < width; col++) { for (int line = 0; line < height; line++) { final double coef = 1.0 * grey[line][col] / (grayLevel - 1); final Color c = gradient.getColor(colorMapper, coef); im.setRGB(col, line, c.getRGB()); } } return new UImage(im); }
/** * Transforms ByteBuffer into BufferedImage with specified width and height. */ private BufferedImage convertByteBufferToBufferedImage(ByteBuffer buffer, int width, int height) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int i = (x + width * y) * 4; int r = buffer.get(i) & 0xFF; int g = buffer.get(i + 1) & 0xFF; int b = buffer.get(i + 2) & 0xFF; image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b); } } return image; }
@Inject @Override public void toBufferedImage(BufferedImage img) { int width = getWidth(); int height = getHeight(); if (img.getWidth() != width || img.getHeight() != height) { throw new IllegalArgumentException("Image bounds do not match SpritePixels"); } int[] pixels = getPixels(); int[] transPixels = new int[pixels.length]; for (int i = 0; i < pixels.length; i++) { if (pixels[i] != 0) { transPixels[i] = pixels[i] | 0xff000000; } } img.setRGB(0, 0, width, height, transPixels, 0, width); }
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; image2.setRGB(i-lox, j-loy, rgb);
/** * Sets the color of pixel ({@code col}, {@code row}) to the given grayscale value. * * @param col the column index * @param row the row index * @param color the color (converts to grayscale if color is not a shade of gray) * @throws IllegalArgumentException unless both {@code 0 <= col < width} and {@code 0 <= row < height} * @throws IllegalArgumentException if {@code color} is {@code null} */ public void set(int col, int row, Color color) { validateColumnIndex(col); validateRowIndex(row); if (color == null) throw new IllegalArgumentException("color argument is null"); Color gray = toGray(color); image.setRGB(col, row, gray.getRGB()); }
public static void makeGray(BufferedImage img) { for (int x = 0; x < img.getWidth(); ++x) for (int y = 0; y < img.getHeight(); ++y) { int rgb = img.getRGB(x, y); int r = (rgb >> 16) & 0xFF; int g = (rgb >> 8) & 0xFF; int b = (rgb & 0xFF); int grayLevel = (r + g + b) / 3; int gray = (grayLevel << 16) + (grayLevel << 8) + grayLevel; img.setRGB(x, y, gray); } }