public static final ByteBuffer getImageDataFromImage(BufferedImage bufferedImage) { WritableRaster wr; DataBuffer db; BufferedImage bi = new BufferedImage(128, 64, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); g.drawImage(bufferedImage, null, null); bufferedImage = bi; wr = bi.getRaster(); db = wr.getDataBuffer(); DataBufferInt dbi = (DataBufferInt) db; int[] data = dbi.getData(); ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length * 4); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); byteBuffer.asIntBuffer().put(data); byteBuffer.flip(); return byteBuffer; }
public void rgbFrame(boolean isPrerollFrame, int width, int height, IntBuffer rgb) { LOG.trace("RGB frame ({}x{}), preroll is {}", width, height, isPrerollFrame); final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); final int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); rgb.get(pixels, 0, width * height); try { exchanger.exchange(image); } catch (InterruptedException e) { throw new WebcamException("Exchange has been interrupted", e); } }
public static void convertScreenShot2(IntBuffer bgraBuf, BufferedImage out){ WritableRaster wr = out.getRaster(); DataBufferInt db = (DataBufferInt) wr.getDataBuffer(); int[] cpuArray = db.getData(); bgraBuf.clear(); bgraBuf.get(cpuArray); // int width = wr.getWidth(); // int height = wr.getHeight(); // // // flip the components the way AWT likes them // for (int y = 0; y < height / 2; y++){ // for (int x = 0; x < width; x++){ // int inPtr = (y * width + x); // int outPtr = ((height-y-1) * width + x); // int pixel = cpuArray[inPtr]; // cpuArray[inPtr] = cpuArray[outPtr]; // cpuArray[outPtr] = pixel; // } // } }
@Override public void rgbFrame(boolean preroll, int width, int height, IntBuffer rgb) { LOG.trace("New RGB frame"); if (t1 == -1 || t2 == -1) { t1 = System.currentTimeMillis(); t2 = System.currentTimeMillis(); } BufferedImage tmp = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); tmp.setAccelerationPriority(0); rgb.get(((DataBufferInt) tmp.getRaster().getDataBuffer()).getData(), 0, width * height); tmp.flush(); image = tmp; if (starting.compareAndSet(true, false)) { synchronized (this) { this.notifyAll(); } LOG.debug("GStreamer device ready"); } t1 = t2; t2 = System.currentTimeMillis(); fps = (4 * fps + 1000 / (t2 - t1 + 1)) / 5; }
int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
singleCursor = IntBuffer.wrap(dataIntBuf.getData()); cursors.add(singleCursor);
int[] data = imageBuffer.getData(); ByteBuffer byteBuffer = texData.getBuffers()[0]; byteBuffer.asIntBuffer().put(data);
int[] pixels = ((DataBufferInt) buffer).getData(); ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0);
int[] imageBuffer = dataBuffer.getData(); for (int srcLine = 0, dstLine = y; srcLine < height && dstLine < imageHeight; srcLine++, dstLine++) { try {
if (bImg.getType() == BufferedImage.TYPE_INT_RGB) { log.trace("makeMat: INT_RGB (%dx%d)", bImg.getWidth(), bImg.getHeight()); int[] data = ((DataBufferInt) bImg.getRaster().getDataBuffer()).getData(); ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 4); IntBuffer intBuffer = byteBuffer.asIntBuffer();
for (int i = 0; i < offsets.length; i++) { final int offset = offsets[i]; Arrays.fill(data.getData(i), offset, offset + size, n);
public static void main(String args[]) { System.setProperty("streamer.Element.debug", "true"); BufferedImageCanvas canvas = new BufferedImageCanvas(4, 4); Element renderer = new BufferedImagePixelsAdapter("renderer", canvas); byte[] pixels = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; int[] pixelsLE = new int[] {0x04030201, 0x08070605, 0x0c0b0a09, 0x100f0e0d, 0x04030201, 0x08070605, 0x0c0b0a09, 0x100f0e0d, 0x04030201, 0x08070605, 0x0c0b0a09, 0x100f0e0d, 0x04030201, 0x08070605, 0x0c0b0a09, 0x100f0e0d}; ByteBuffer buf = new ByteBuffer(pixels); buf.putMetadata(TARGET_X, 0); buf.putMetadata(TARGET_Y, 0); buf.putMetadata(WIDTH, 4); buf.putMetadata(HEIGHT, 4); buf.putMetadata(PIXEL_FORMAT, RGB888LE32); renderer.handleData(buf, null); String actualData = Arrays.toString(((DataBufferInt)canvas.getOfflineImage().getRaster().getDataBuffer()).getData()); String expectedData = Arrays.toString(pixelsLE); if (!actualData.equals(expectedData)) s_logger.error("Actual image: " + actualData + "\nExpected image: " + expectedData + "."); }
int[] data = ((DataBufferInt)canvas.getOfflineImage().getRaster().getDataBuffer()).getData(); System.arraycopy(pixelsBeforeCopy, 0, data, 0, pixelsBeforeCopy.length); data = ((DataBufferInt)canvas.getOfflineImage().getRaster().getDataBuffer()).getData(); String actualData = Arrays.toString(data); String expectedData = Arrays.toString(pixelsAfterCopy);
int[] imageBuffer = dataBuffer.getData();
break; case 32: int[] row32 = ((DataBufferInt) rowRaster.getDataBuffer()).getData(); read32bitChannel(c, channels, destRaster.getDataBuffer(), interleavedBands, bandOffset, pSourceCM, row32, pSource, pDest, pXSub, pYSub, header.width, header.height, pByteCounts, c * header.height, pCompression == PSD.COMPRESSION_RLE); break;
writePICTData( 0, 0, image.getWidth(), image.getHeight(), image.getColorModel(), ((DataBufferInt) buf).getData(), 0, image.getWidth() );
break; case 32: int[] row32 = ((DataBufferInt) rowRaster.getDataBuffer()).getData(); read32bitChannel(c, imageType.getNumBands(), raster.getDataBuffer(), interleavedBands, bandOffset, sourceCM, row32, area, area, xsub, ysub, width, height, byteCounts, 0, compression == PSD.COMPRESSION_RLE);
case DataBuffer.TYPE_INT: int[] rowDataInt = ((DataBufferInt) dataBuffer).getData(band);
int[] rowDataInt = ((DataBufferInt) rowRaster.getDataBuffer()).getData(); readRowInt(input, height, srcRegion, xSub, ySub, rowDataInt, destRaster, clippedRow, y); break;