Example usage for java.nio IntBuffer put

List of usage examples for java.nio IntBuffer put

Introduction

In this page you can find the example usage for java.nio IntBuffer put.

Prototype

public IntBuffer put(IntBuffer src) 

Source Link

Document

Writes all the remaining ints of the src int buffer to this buffer's current position, and increases both buffers' position by the number of ints copied.

Usage

From source file:Main.java

/**android methods*/

//Only for Android
public static IntBuffer makeFloatBuffer(int[] array) {
    final int integerSize = Integer.SIZE / 8;
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * integerSize);
    byteBuffer.order(ByteOrder.nativeOrder());
    IntBuffer intBuffer = byteBuffer.asIntBuffer();
    intBuffer.put(array);
    intBuffer.position(0);//from  w w w .  j a  v a 2s.co m
    return intBuffer;
}

From source file:Main.java

public static IntBuffer createIntBuffer(final int... data) {
    if (data == null) {
        return null;
    }//from w  ww.ja va  2s .  co  m
    final IntBuffer buff = createIntBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}

From source file:Main.java

public static IntBuffer arrayToIntBuffer(int[] inputArray) {
    IntBuffer iBuf = ByteBuffer.allocateDirect(inputArray.length * BYTES_PER_INT).order(ByteOrder.nativeOrder())
            .asIntBuffer();/*from w w  w .j  a  v a 2 s.  c  o  m*/
    iBuf.put(inputArray).position(0);
    return iBuf;
}

From source file:Main.java

public static IntBuffer createIndexBuffer(int[] indices) {
    IntBuffer indexBuffer;

    ByteBuffer bb = ByteBuffer.allocateDirect(indices.length * 4);
    bb.order(ByteOrder.nativeOrder());
    indexBuffer = bb.asIntBuffer();/*from  w  w  w. j a  va2  s  .c  o m*/
    indexBuffer.put(indices);
    indexBuffer.position(0);

    return indexBuffer;
}

From source file:Main.java

private static IntBuffer[] generateMipmaps(int[] rgb, int width, int height, int mipmaps) {
    if (rgb == null) {
        return null;
    } else {//from   www.  j a  v a2  s . c  o m
        ArrayList mipmapData = new ArrayList();
        IntBuffer buffer = newIntBuffer(width * height * 4);
        buffer.put(rgb).position(0);
        int level = 0;

        while (true) {
            mipmapData.add(buffer);

            if (width <= 0 || height <= 0 || level >= mipmaps) {
                return (IntBuffer[]) mipmapData.toArray(new IntBuffer[mipmapData.size()]);
            }

            IntBuffer newBuffer = newIntBuffer(width * height);
            scaleHalf(buffer, width, height, newBuffer, 0);
            buffer = newBuffer;
            ++level;
            width >>= 1;
            height >>= 1;
        }
    }
}

From source file:de.ailis.threedee.utils.BufferUtils.java

/**
 * Converts the specified integer buffer to native endian and returns this
 * new buffer. If buffer is already in correct endian format then it is
 * returned right away.//from  w  ww .j  a v a 2 s  .  c o m
 *
 * @param buffer
 *            The integer buffer to convert
 * @return The converted integer buffer or the source buffer if no
 *         conversion is needed
 */

public static IntBuffer convertToNativeEndian(final IntBuffer buffer) {
    if (buffer.order() == ByteOrder.nativeOrder())
        return buffer;

    final ByteBuffer bytes = ByteBuffer.allocateDirect(buffer.capacity());
    bytes.order(ByteOrder.nativeOrder());
    final IntBuffer ints = bytes.asIntBuffer();
    ints.put(buffer).rewind();
    return ints;
}

From source file:org.bimserver.utils.BinUtils.java

public static byte[] intToByteArray(int inInt) {
    byte[] bArray = new byte[4];
    ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
    IntBuffer lBuffer = bBuffer.asIntBuffer();
    lBuffer.put(inInt);
    return bArray;
}

From source file:Main.java

public static Buffer setupIntBuffer(IntBuffer preBuffer, int[] array) {

    if (preBuffer == null || preBuffer.capacity() < array.length) {
        preBuffer = createIntBuffer(array.length * 2);
    } else {/*w w  w  .j av a  2  s  . c o  m*/
        preBuffer.clear();
    }

    preBuffer.clear();
    preBuffer.put(array);
    preBuffer.position(0);

    return preBuffer;
}

From source file:org.jcodec.codecs.mjpeg.JpegDecoder.java

private static void lineToRgb(IntBuffer Y, IntBuffer Cb, IntBuffer Cr, IntBuffer rgb) {
    for (int i = 0; i < 8; i++) {
        Cb.position(Cb.position() - (i & 1));
        Cr.position(Cr.position() - (i & 1));
        int y = Y.get();
        int cb = Cb.get();
        int cr = Cr.get();
        rgb.put(ImageConvert.ycbcr_to_rgb24(y, cb, cr));
    }/*from  w  w  w . j ava 2s . c o m*/
}

From source file:Main.java

public static IntBuffer clone(final IntBuffer buf) {
    if (buf == null) {
        return null;
    }//  w  w w . java2s .c o m
    buf.rewind();

    final IntBuffer copy;
    if (buf.isDirect()) {
        copy = createIntBuffer(buf.limit());
    } else {
        copy = createIntBufferOnHeap(buf.limit());
    }
    copy.put(buf);

    return copy;
}