Search in sources :

Example 16 with LongBuffer

use of java.nio.LongBuffer in project robovm by robovm.

the class LongBufferTest method testDuplicate.

public void testDuplicate() {
    buf.clear();
    buf.mark();
    buf.position(buf.limit());
    // duplicate's contents should be the same as buf
    LongBuffer duplicate = buf.duplicate();
    assertNotSame(buf, duplicate);
    assertEquals(buf.position(), duplicate.position());
    assertEquals(buf.limit(), duplicate.limit());
    assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
    assertEquals(buf.isDirect(), duplicate.isDirect());
    assertEquals(buf.order(), duplicate.order());
    assertContentEquals(buf, duplicate);
    // duplicate's position, mark, and limit should be independent to buf
    duplicate.reset();
    assertEquals(duplicate.position(), 0);
    duplicate.clear();
    assertEquals(buf.position(), buf.limit());
    buf.reset();
    assertEquals(buf.position(), 0);
    // duplicate share the same content with buf
    if (!duplicate.isReadOnly()) {
        loadTestData1(buf);
        assertContentEquals(buf, duplicate);
        loadTestData2(duplicate);
        assertContentEquals(buf, duplicate);
    }
}
Also used : LongBuffer(java.nio.LongBuffer)

Example 17 with LongBuffer

use of java.nio.LongBuffer in project robovm by robovm.

the class GlobalValueTest method testPtr.

@Test
public void testPtr() {
    LongBuffer memoryAsLongBuffer = memory.order(ByteOrder.nativeOrder()).asLongBuffer();
    assertEquals(0, memoryAsLongBuffer.get(0));
    assertNull(ptrGetter());
    PointPtr ptr = new PointPtr();
    assertNull(ptr.get());
    Point p = new Point();
    ptr.set(p);
    ptrSetter(ptr);
    assertEquals(ptr.getHandle(), memoryAsLongBuffer.get(0));
    assertEquals(ptr, ptrGetter());
    assertEquals(ptr.get(), ptrGetter().get());
}
Also used : LongBuffer(java.nio.LongBuffer) Test(org.junit.Test)

Example 18 with LongBuffer

use of java.nio.LongBuffer in project libgdx by libgdx.

the class BufferUtilsTest method create.

@Override
public void create() {
    //Not emulated in gwt
    //ByteBuffer bytebuffer = BufferUtils.newUnsafeByteBuffer(1000 * 1000);
    //BufferUtils.disposeUnsafeByteBuffer(bytebuffer);
    ByteBuffer bb = BufferUtils.newByteBuffer(8);
    CharBuffer cb = BufferUtils.newCharBuffer(8);
    ShortBuffer sb = BufferUtils.newShortBuffer(8);
    IntBuffer ib = BufferUtils.newIntBuffer(8);
    LongBuffer lb = BufferUtils.newLongBuffer(8);
    FloatBuffer fb = BufferUtils.newFloatBuffer(8);
    DoubleBuffer db = BufferUtils.newDoubleBuffer(8);
    bb.position(4);
    BufferUtils.copy(new byte[] { 1, 2, 3, 4 }, 0, bb, 4);
    checkInt(bb.get(), 1);
    checkInt(bb.get(), 2);
    checkInt(bb.get(), 3);
    checkInt(bb.get(), 4);
    cb.position(4);
    BufferUtils.copy(new char[] { 1, 2, 3, 4 }, 0, cb, 4);
    checkInt(cb.get(), 1);
    checkInt(cb.get(), 2);
    checkInt(cb.get(), 3);
    checkInt(cb.get(), 4);
    cb.position(0);
    BufferUtils.copy(new char[] { 5, 6, 7, 8 }, 1, cb, 3);
    checkInt(cb.get(), 6);
    checkInt(cb.get(), 7);
    checkInt(cb.get(), 8);
    sb.position(4);
    BufferUtils.copy(new short[] { 1, 2, 3, 4 }, 0, sb, 4);
    checkInt(sb.get(), 1);
    checkInt(sb.get(), 2);
    checkInt(sb.get(), 3);
    checkInt(sb.get(), 4);
    sb.position(0);
    BufferUtils.copy(new short[] { 5, 6, 7, 8 }, 1, sb, 3);
    checkInt(sb.get(), 6);
    checkInt(sb.get(), 7);
    checkInt(sb.get(), 8);
    ib.position(4);
    BufferUtils.copy(new int[] { 1, 2, 3, 4 }, 0, ib, 4);
    checkInt(ib.get(), 1);
    checkInt(ib.get(), 2);
    checkInt(ib.get(), 3);
    checkInt(ib.get(), 4);
    ib.position(0);
    BufferUtils.copy(new int[] { 5, 6, 7, 8 }, 1, ib, 3);
    checkInt(ib.get(), 6);
    checkInt(ib.get(), 7);
    checkInt(ib.get(), 8);
    lb.position(4);
    BufferUtils.copy(new long[] { 1, 2, 3, 4 }, 0, lb, 4);
    checkInt(lb.get(), 1);
    checkInt(lb.get(), 2);
    checkInt(lb.get(), 3);
    checkInt(lb.get(), 4);
    lb.position(0);
    BufferUtils.copy(new long[] { 5, 6, 7, 8 }, 1, lb, 3);
    checkInt(lb.get(), 6);
    checkInt(lb.get(), 7);
    checkInt(lb.get(), 8);
    fb.position(4);
    BufferUtils.copy(new float[] { 1, 2, 3, 4 }, 0, fb, 4);
    checkFloat(fb.get(), 1);
    checkFloat(fb.get(), 2);
    checkFloat(fb.get(), 3);
    checkFloat(fb.get(), 4);
    fb.position(0);
    BufferUtils.copy(new float[] { 5, 6, 7, 8 }, 1, fb, 3);
    checkFloat(fb.get(), 6);
    checkFloat(fb.get(), 7);
    checkFloat(fb.get(), 8);
    if (Gdx.app.getType() != ApplicationType.WebGL) {
        // gwt throws: NYI: Numbers.doubleToRawLongBits
        db.position(4);
        BufferUtils.copy(new double[] { 1, 2, 3, 4 }, 0, db, 4);
        checkFloat(db.get(), 1);
        checkFloat(db.get(), 2);
        checkFloat(db.get(), 3);
        checkFloat(db.get(), 4);
        db.position(0);
        BufferUtils.copy(new double[] { 5, 6, 7, 8 }, 1, db, 3);
        checkFloat(db.get(), 6);
        checkFloat(db.get(), 7);
        checkFloat(db.get(), 8);
    }
    ByteBuffer bb2 = BufferUtils.newByteBuffer(4);
    bb.position(4);
    BufferUtils.copy(bb, bb2, 4);
    checkInt(bb2.get(), 1);
    checkInt(bb2.get(), 2);
    checkInt(bb2.get(), 3);
    checkInt(bb2.get(), 4);
    bench();
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) LongBuffer(java.nio.LongBuffer) IntBuffer(java.nio.IntBuffer) CharBuffer(java.nio.CharBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 19 with LongBuffer

use of java.nio.LongBuffer in project libgdx by libgdx.

the class BufferUtilsTest method benchLong.

private void benchLong() {
    LongBuffer lb = BufferUtils.newLongBuffer(1024 * 1024 / 8);
    long[] longs = new long[1024 * 1024 / 8];
    int len = longs.length;
    // relative put
    long start = TimeUtils.nanoTime();
    for (int j = 0; j < NUM_MB; j++) {
        lb.clear();
        for (int i = 0; i < len; i++) lb.put(longs[i]);
    }
    Gdx.app.log("BufferUtilsTest", "LongBuffer relative put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    // absolute put
    start = TimeUtils.nanoTime();
    for (int j = 0; j < NUM_MB; j++) {
        lb.clear();
        for (int i = 0; i < len; i++) lb.put(i, longs[i]);
    }
    Gdx.app.log("BufferUtilsTest", "LongBuffer absolute put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    // bulk put
    start = TimeUtils.nanoTime();
    for (int j = 0; j < NUM_MB; j++) {
        lb.clear();
        lb.put(longs);
    }
    Gdx.app.log("BufferUtilsTest", "LongBuffer bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    // JNI put
    start = TimeUtils.nanoTime();
    for (int j = 0; j < NUM_MB; j++) {
        lb.clear();
        BufferUtils.copy(longs, 0, lb, len);
    }
    Gdx.app.log("BufferUtilsTest", "LongBuffer native bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
}
Also used : LongBuffer(java.nio.LongBuffer)

Example 20 with LongBuffer

use of java.nio.LongBuffer in project bigbluebutton by bigbluebutton.

the class Frame method createIndexer.

/** Returns an {@link Indexer} for the <i>i</i>th image plane. */
public <I extends Indexer> I createIndexer(boolean direct, int i) {
    long[] sizes = { imageHeight, imageWidth, imageChannels };
    long[] strides = { imageStride, imageChannels, 1 };
    Buffer buffer = image[i];
    Object array = buffer.hasArray() ? buffer.array() : null;
    switch(imageDepth) {
        case DEPTH_UBYTE:
            return array != null ? (I) UByteIndexer.create((byte[]) array, sizes, strides) : direct ? (I) UByteIndexer.create((ByteBuffer) buffer, sizes, strides) : (I) UByteIndexer.create(new BytePointer((ByteBuffer) buffer), sizes, strides, false);
        case DEPTH_BYTE:
            return array != null ? (I) ByteIndexer.create((byte[]) array, sizes, strides) : direct ? (I) ByteIndexer.create((ByteBuffer) buffer, sizes, strides) : (I) ByteIndexer.create(new BytePointer((ByteBuffer) buffer), sizes, strides, false);
        case DEPTH_USHORT:
            return array != null ? (I) UShortIndexer.create((short[]) array, sizes, strides) : direct ? (I) UShortIndexer.create((ShortBuffer) buffer, sizes, strides) : (I) UShortIndexer.create(new ShortPointer((ShortBuffer) buffer), sizes, strides, false);
        case DEPTH_SHORT:
            return array != null ? (I) ShortIndexer.create((short[]) array, sizes, strides) : direct ? (I) ShortIndexer.create((ShortBuffer) buffer, sizes, strides) : (I) ShortIndexer.create(new ShortPointer((ShortBuffer) buffer), sizes, strides, false);
        case DEPTH_INT:
            return array != null ? (I) IntIndexer.create((int[]) array, sizes, strides) : direct ? (I) IntIndexer.create((IntBuffer) buffer, sizes, strides) : (I) IntIndexer.create(new IntPointer((IntBuffer) buffer), sizes, strides, false);
        case DEPTH_LONG:
            return array != null ? (I) LongIndexer.create((long[]) array, sizes, strides) : direct ? (I) LongIndexer.create((LongBuffer) buffer, sizes, strides) : (I) LongIndexer.create(new LongPointer((LongBuffer) buffer), sizes, strides, false);
        case DEPTH_FLOAT:
            return array != null ? (I) FloatIndexer.create((float[]) array, sizes, strides) : direct ? (I) FloatIndexer.create((FloatBuffer) buffer, sizes, strides) : (I) FloatIndexer.create(new FloatPointer((FloatBuffer) buffer), sizes, strides, false);
        case DEPTH_DOUBLE:
            return array != null ? (I) DoubleIndexer.create((double[]) array, sizes, strides) : direct ? (I) DoubleIndexer.create((DoubleBuffer) buffer, sizes, strides) : (I) DoubleIndexer.create(new DoublePointer((DoubleBuffer) buffer), sizes, strides, false);
        default:
            assert false;
    }
    return null;
}
Also used : FloatBuffer(java.nio.FloatBuffer) DoubleBuffer(java.nio.DoubleBuffer) ShortBuffer(java.nio.ShortBuffer) ByteBuffer(java.nio.ByteBuffer) IntBuffer(java.nio.IntBuffer) Buffer(java.nio.Buffer) LongBuffer(java.nio.LongBuffer) DoubleBuffer(java.nio.DoubleBuffer) LongBuffer(java.nio.LongBuffer) BytePointer(org.bytedeco.javacpp.BytePointer) DoublePointer(org.bytedeco.javacpp.DoublePointer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortPointer(org.bytedeco.javacpp.ShortPointer) LongPointer(org.bytedeco.javacpp.LongPointer) FloatPointer(org.bytedeco.javacpp.FloatPointer) IntBuffer(java.nio.IntBuffer) IntPointer(org.bytedeco.javacpp.IntPointer) ShortBuffer(java.nio.ShortBuffer)

Aggregations

LongBuffer (java.nio.LongBuffer)49 ByteBuffer (java.nio.ByteBuffer)16 DoubleBuffer (java.nio.DoubleBuffer)10 FloatBuffer (java.nio.FloatBuffer)10 IntBuffer (java.nio.IntBuffer)10 ShortBuffer (java.nio.ShortBuffer)10 CharBuffer (java.nio.CharBuffer)9 Test (org.junit.Test)7 BufferOverflowException (java.nio.BufferOverflowException)4 BufferUnderflowException (java.nio.BufferUnderflowException)3 Bitmap (android.graphics.Bitmap)2 InvalidMarkException (java.nio.InvalidMarkException)2 ByteSource (org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Buffer (java.nio.Buffer)1 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)1 BytePointer (org.bytedeco.javacpp.BytePointer)1 DoublePointer (org.bytedeco.javacpp.DoublePointer)1