public static LongBuffer directCopy(LongBuffer b, ByteOrder order) { return directCopy((Buffer)b, order).asLongBuffer(); } public static ShortBuffer directCopy(ShortBuffer b, ByteOrder order) {
/** * Creates a direct buffer of the specified size (in elements) and type.. * @param size size of the buffer in elements * @param order byte order of the direct buffer * @param bufferClass type of the buffer. Must be one of IntBuffer.class, LongBuffer.class, ShortBuffer.class, ByteBuffer.class, DoubleBuffer.class, FloatBuffer.class * @return view on new direct buffer */ @SuppressWarnings("unchecked") public static <B extends Buffer> B directBuffer(int size, ByteOrder order, Class<B> bufferClass) { if (IntBuffer.class.isAssignableFrom(bufferClass)) return (B)directInts(size, order); if (LongBuffer.class.isAssignableFrom(bufferClass)) return (B)directLongs(size, order); if (ShortBuffer.class.isAssignableFrom(bufferClass)) return (B)directShorts(size, order); if (ByteBuffer.class.isAssignableFrom(bufferClass)) return (B)directBytes(size, order); if (DoubleBuffer.class.isAssignableFrom(bufferClass)) return (B)directDoubles(size, order); if (FloatBuffer.class.isAssignableFrom(bufferClass)) return (B)directFloats(size, order); if (CharBuffer.class.isAssignableFrom(bufferClass)) return (B)directChars(size, order); throw new UnsupportedOperationException("Cannot create direct buffers of type " + bufferClass.getName()); } /**
public static ByteBuffer directCopy(Buffer b, ByteOrder order) { ByteBuffer copy = ByteBuffer.allocateDirect((int)getSizeInBytes(b)).order(order == null ? ByteOrder.nativeOrder() : order); put(b, copy); return copy; }
int[] Texture = new int[1]; GL2 gl = (GL2)drawable.getGL(); buffer = NIOUtils.directFloats(bufferSize, ByteOrder.nativeOrder()); gl.glGenBuffers(1, VBO, 0); // Get A Valid Name gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBO[0]); // Bind The Buffer ByteBuffer texData = NIOUtils.directCopy(ByteBuffer.wrap(new byte[] { bMin1,bMin1,bMin1,bMin1, bMin1,bMin1,bMin1,bMin1, bMin1,bMin1,bMin1,bMin1, bMin1,bMin1,bMin1,bMin1,
/** * Bulk-copy all of the input buffer into the output buffer * @param input * @param output */ public static void put(Buffer input, Buffer output) { if (input instanceof ByteBuffer) put((ByteBuffer)input, output); else if (output instanceof ByteBuffer) put(input, (ByteBuffer)output); else if (input instanceof IntBuffer && output instanceof IntBuffer) ((IntBuffer)output).duplicate().put((IntBuffer)input); else if (input instanceof LongBuffer && output instanceof LongBuffer) ((LongBuffer)output).duplicate().put((LongBuffer)input); else if (input instanceof ShortBuffer && output instanceof ShortBuffer) ((ShortBuffer)output).duplicate().put((ShortBuffer)input); else if (input instanceof CharBuffer && output instanceof CharBuffer) ((CharBuffer)output).duplicate().put((CharBuffer)input); else if (input instanceof DoubleBuffer && output instanceof DoubleBuffer) ((DoubleBuffer)output).duplicate().put((DoubleBuffer)input); else if (input instanceof FloatBuffer && output instanceof FloatBuffer) ((FloatBuffer)output).duplicate().put((FloatBuffer)input); else throw new UnsupportedOperationException("Unhandled buffer type : " + input.getClass().getName()); }
public Buffer getData(BufferedImage image, Buffer optionalExistingOutput, boolean directBuffer, boolean allowDeoptimizingDirectRead, ByteOrder byteOrder) { int width = image.getWidth(), height = image.getHeight(); WritableRaster raster = checkWritableRaster(image); checkSinglePixelPackedSampleModel(raster); int length = width * height; short[] existingArray = getIndirectArray(optionalExistingOutput, length, short[].class); short[] array = (short[])raster.getDataElements(0, 0, width, height, existingArray); ShortBuffer output = null; if (optionalExistingOutput instanceof ShortBuffer) { output = (ShortBuffer)optionalExistingOutput; if (output.capacity() != length * 4) output = null; } if (output == null) output = NIOUtils.directShorts(length * 4, byteOrder); for (int i = 0; i < length; i++) { int offset = i * 4; short value = array[i]; output.put(offset, value); output.put(offset + 1, value); output.put(offset + 2, value); output.put(offset + 3, (short)0xffff); } return output; } },
IntBuffer results = NIOUtils.directInts(size, context.getByteOrder());
NIOUtils.put(ptr.getBuffer(), out);
public Buffer getData(BufferedImage image, Buffer optionalExistingOutput, boolean directBuffer, boolean allowDeoptimizingDirectRead, ByteOrder byteOrder) { int width = image.getWidth(), height = image.getHeight(); WritableRaster raster = checkWritableRaster(image); checkSinglePixelPackedSampleModel(raster); int length = width * height; short[] existingArray = getIndirectArray(optionalExistingOutput, length, short[].class); short[] array = (short[])raster.getDataElements(0, 0, width, height, existingArray); ShortBuffer output = null; if (optionalExistingOutput instanceof ShortBuffer) { output = (ShortBuffer)optionalExistingOutput; if (output.capacity() != length * 4) output = null; } if (output == null) output = NIOUtils.directShorts(length * 4, byteOrder); for (int i = 0; i < length; i++) { int offset = i * 4; short value = array[i]; output.put(offset, value); output.put(offset + 1, value); output.put(offset + 2, value); output.put(offset + 3, (short)0xffff); } return output; } },
public static ShortBuffer directCopy(ShortBuffer b, ByteOrder order) { return directCopy((Buffer)b, order).asShortBuffer(); } public static CharBuffer directCopy(CharBuffer b, ByteOrder order) {
NIOUtils.put(ptr.getBuffer(), out);
public static DoubleBuffer directCopy(DoubleBuffer b, ByteOrder order) { return directCopy((Buffer)b, order).asDoubleBuffer(); } public static FloatBuffer directCopy(FloatBuffer b, ByteOrder order) {
public static IntBuffer directCopy(IntBuffer b, ByteOrder order) { return directCopy((Buffer)b, order).asIntBuffer(); } public static LongBuffer directCopy(LongBuffer b, ByteOrder order) {
public static FloatBuffer directCopy(FloatBuffer b, ByteOrder order) { return directCopy((Buffer)b, order).asFloatBuffer(); } public static ByteBuffer directCopy(Buffer b, ByteOrder order) {
public static CharBuffer directCopy(CharBuffer b, ByteOrder order) { return directCopy((Buffer)b, order).asCharBuffer(); } public static DoubleBuffer directCopy(DoubleBuffer b, ByteOrder order) {
public Buffer getData(Image image, Buffer optionalExistingOutput, boolean directBuffer, boolean allowDeoptimizingDirectRead, ByteOrder byteOrder) { int[] intData = null; int width = image.getWidth(null), height = image.getHeight(null); PixelGrabber grabber = new PixelGrabber(image, 0, 0, width, height, true); try { grabber.grabPixels(); intData = (int[])grabber.getPixels(); } catch (InterruptedException ex) { throw new RuntimeException("Pixel read operation was interrupted", ex); } IntBuffer output = IntBuffer.wrap(intData); if (directBuffer) return NIOUtils.directCopy(output, byteOrder); else return output; } },
public Buffer getData(BufferedImage image, Buffer optionalExistingOutput, boolean directBuffer, boolean allowDeoptimizingDirectRead, ByteOrder byteOrder) { int width = image.getWidth(), height = image.getHeight(); WritableRaster raster = checkWritableRaster(image); checkSinglePixelPackedSampleModel(raster); byte[] existingArray = getIndirectArray(optionalExistingOutput, width * height, byte[].class); byte[] array; ByteBuffer output = null; if (!allowDeoptimizingDirectRead || isSubRaster(raster)) array = (byte[])raster.getDataElements(0, 0, width, height, existingArray); else { array = checkDataBuffer(raster, DataBufferByte.class).getData(); if (optionalExistingOutput instanceof ByteBuffer) { output = (ByteBuffer)optionalExistingOutput; if (output != null && output.capacity() == width * height) { if (!output.isDirect()) System.arraycopy(array, 0, output.array(), 0, width * height); else { output.duplicate().put(array); } } } } if (output == null) output = ByteBuffer.wrap(array); return directBuffer && !output.isDirect() ? NIOUtils.directCopy(output, byteOrder) : output; } },
public Buffer getData(BufferedImage image, Buffer optionalExistingOutput, boolean directBuffer, boolean allowDeoptimizingDirectRead, ByteOrder byteOrder) { int width = image.getWidth(), height = image.getHeight(); WritableRaster raster = checkWritableRaster(image); checkSinglePixelPackedSampleModel(raster); byte[] existingArray = getIndirectArray(optionalExistingOutput, width * height, byte[].class); byte[] array; ByteBuffer output = null; if (!allowDeoptimizingDirectRead || isSubRaster(raster)) array = (byte[])raster.getDataElements(0, 0, width, height, existingArray); else { array = checkDataBuffer(raster, DataBufferByte.class).getData(); if (optionalExistingOutput instanceof ByteBuffer) { output = (ByteBuffer)optionalExistingOutput; if (output != null && output.capacity() == width * height) { if (!output.isDirect()) System.arraycopy(array, 0, output.array(), 0, width * height); else { output.duplicate().put(array); } } } } if (output == null) output = ByteBuffer.wrap(array); return directBuffer && !output.isDirect() ? NIOUtils.directCopy(output, byteOrder) : output; } },
public Buffer getData(Image image, Buffer optionalExistingOutput, boolean directBuffer, boolean allowDeoptimizingDirectRead, ByteOrder byteOrder) { int[] intData = null; int width = image.getWidth(null), height = image.getHeight(null); PixelGrabber grabber = new PixelGrabber(image, 0, 0, width, height, true); try { grabber.grabPixels(); intData = (int[])grabber.getPixels(); } catch (InterruptedException ex) { throw new RuntimeException("Pixel read operation was interrupted", ex); } IntBuffer output = IntBuffer.wrap(intData); if (directBuffer) return NIOUtils.directCopy(output, byteOrder); else return output; } },
public Buffer getData(BufferedImage image, Buffer optionalExistingOutput, boolean directBuffer, boolean allowDeoptimizingDirectRead, ByteOrder byteOrder) { int width = image.getWidth(), height = image.getHeight(); WritableRaster raster = checkWritableRaster(image); checkSinglePixelPackedSampleModel(raster); short[] existingArray = getIndirectArray(optionalExistingOutput, width * height, short[].class); short[] array; ShortBuffer output = null; if (!allowDeoptimizingDirectRead || isSubRaster(raster)) array = (short[])raster.getDataElements(0, 0, width, height, existingArray); else { array = checkDataBuffer(raster, DataBufferShort.class).getData(); if (optionalExistingOutput instanceof ShortBuffer) { output = (ShortBuffer)optionalExistingOutput; if (output != null && output.capacity() == width * height) { if (!output.isDirect()) System.arraycopy(array, 0, output.array(), 0, width * height); else { output.duplicate().put(array); } } } } if (output == null) output = ShortBuffer.wrap(array); return directBuffer && !output.isDirect() ? NIOUtils.directCopy(output, byteOrder) : output; } },