/** Creates a new instance of IDEJRManFramebufferImpl */ public IDEJRManFramebufferImpl(String name, BufferedImage image) { super("JRMan rendered: " + name, true, true, true, true); this.name = name; save.setEnabled(false); imagePanel.setImage(image); imagePanel.addToolbarAction(save); if (image.getType() == BufferedImage.TYPE_INT_ARGB || image.getType() == BufferedImage.TYPE_INT_ARGB_PRE) { imagePanel.setShowTransparencyPattern(true); } getRootPane().setDoubleBuffered(false); getContentPane().add(imagePanel); pack(); ImageResource images = ImageResource.getInstance(); // set the frame icon setFrameIcon(images.getJrMan()); // add this to the IDE desktop MainMenuEventHandlers.getInstance(null) .getIdeInstance() .getWorkspaceDesktop() .addInternalFrame(this, true); }
private void buildAccumulator(int r) { accImage = new BufferedImage(width, height, greyScale.getType()); Graphics2D g = accImage.createGraphics(); g.setColor(new Color(0, 0, 0, 0)); g.fillRect(0, 0, width, height); g.dispose(); int max = 0; double[] a = new double[1]; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { a[0] = acc[y * width + x][r - rmin] & 0xFF; accImage.getRaster().setPixel(x, y, a); } ImageIcon icon2 = new ImageIcon(accImage); lbl2.setIcon(icon2); }
public void sobel() { sobel = new BufferedImage(width, height, filtered.getType()); Graphics2D g = sobel.createGraphics(); g.setColor(new Color(0, 0, 0, 0)); g.fillRect(0, 0, width, height); g.dispose(); int[] tmp = new int[1]; sX = new double[height][width]; sY = new double[height][width]; double maxX = 0; double maxY = 0; for (int y = 1; y < height - 1; ++y) for (int x = 1; x < width - 1; ++x) { double Xvalue = 0; double Yvalue = 0; for (int j = -1; j <= 1; ++j) for (int i = -1; i <= 1; ++i) { Xvalue += GX[1 + j][1 + i] * filtered.getRaster().getPixel(x + i, y + j, tmp)[0]; Yvalue += GY[1 + j][1 + i] * filtered.getRaster().getPixel(x + i, y + j, tmp)[0]; } if (Xvalue > maxX) maxX = Xvalue; if (Yvalue > maxY) maxY = Yvalue; sX[y][x] = Xvalue; sY[y][x] = Yvalue; } for (int y = 1; y < height - 1; ++y) for (int x = 1; x < width - 1; ++x) { double[] a = {(Math.abs((sX[y][x] / maxX * 255)) + Math.abs((sY[y][x] / maxY) * 255))}; // if (a[0] > 0) binary[y][x] = 1; // if (a[0] <= 0) binary[y][x] = 0; sobel.getRaster().setPixel(x, y, a); } ImageIcon icon2 = new ImageIcon(sobel); lbl2.setIcon(icon2); }
/** * Loads PNG files and returns the result as an int[][]. The only PNG formats permitted are those * with up to 256 grays (including simple black and white) or indexed colors from an up to * 256-sized color table. Each integer value represents the gray level or the color table index * value of the pixel. The Y dimension is not flipped. */ public static int[][] loadPNGFile(InputStream str) throws IOException { // read the bytes into a byte array BufferedInputStream stream = new BufferedInputStream(str); ArrayList list = new ArrayList(); int count = 0; while (true) { byte[] buffer = new byte[16384 * 16]; int len = stream.read(buffer); if (len <= 0) // all done break; else if (len < buffer.length) { byte[] buf2 = new byte[len]; System.arraycopy(buffer, 0, buf2, 0, len); buffer = buf2; } count += len; list.add(buffer); } byte[] data = new byte[count]; int cur = 0; for (int i = 0; i < list.size(); i++) { byte[] b = (byte[]) (list.get(i)); System.arraycopy(b, 0, data, cur, b.length); cur += b.length; } // Next convert the byte array to a buffered image BufferedImage image = ((ToolkitImage) (new ImageIcon(data).getImage())).getBufferedImage(); // Is the color model something we can use? int type = image.getType(); if (type == BufferedImage.TYPE_BYTE_BINARY || type == BufferedImage.TYPE_BYTE_GRAY) { int w = image.getWidth(); int h = image.getHeight(); int[][] result = new int[w][h]; // obviously this could be done more efficiently for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) result[i][j] = (image.getRGB(i, j) & 0xFF); return result; } else if (type == BufferedImage.TYPE_BYTE_INDEXED) { Raster raster = image.getRaster(); if (raster.getTransferType() != DataBuffer.TYPE_BYTE) // uh oh throw new IOException("Input Stream must contain an image with byte data if indexed."); byte[] pixel = new byte[1]; int w = image.getWidth(); int h = image.getHeight(); int[][] result = new int[w][h]; // obviously this could be done more efficiently for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) { result[i][j] = ((byte[]) (raster.getDataElements(i, j, pixel)))[0]; if (result[i][j] < 0) result[i][j] += 256; } return result; } // else if (type == TYPE_USHORT_GRAY) // at present we don't handle shorts // { // } else throw new IOException( "Input Stream must contain a binary, byte-sized grayscale, or byte-sized indexed color scheme: " + image); }