use of java.nio.DoubleBuffer in project robovm by robovm.
the class DoubleBufferTest method testHashCode.
public void testHashCode() {
buf.clear();
DoubleBuffer readonly = buf.asReadOnlyBuffer();
DoubleBuffer duplicate = buf.duplicate();
assertTrue(buf.hashCode() == readonly.hashCode());
assertTrue(buf.capacity() > 5);
duplicate.position(buf.capacity() / 2);
assertTrue(buf.hashCode() != duplicate.hashCode());
}
use of java.nio.DoubleBuffer in project robovm by robovm.
the class WrappedDoubleBufferTest method testWrappedDoubleuffer_IllegalArg.
/**
* @tests java.nio.CharBuffer#allocate(char[],int,int)
*
*/
public void testWrappedDoubleuffer_IllegalArg() {
double[] array = new double[20];
try {
DoubleBuffer.wrap(array, -1, 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
DoubleBuffer.wrap(array, 21, 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
DoubleBuffer.wrap(array, 0, -1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
DoubleBuffer.wrap(array, 0, 21);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
DoubleBuffer.wrap(array, Integer.MAX_VALUE, 1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
DoubleBuffer.wrap(array, 1, Integer.MAX_VALUE);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
DoubleBuffer.wrap((double[]) null, -1, 0);
//$NON-NLS-1$
fail("Should throw NPE");
} catch (NullPointerException e) {
}
DoubleBuffer buf = DoubleBuffer.wrap(array, 2, 16);
assertEquals(buf.position(), 2);
assertEquals(buf.limit(), 18);
assertEquals(buf.capacity(), 20);
}
use of java.nio.DoubleBuffer in project robovm by robovm.
the class ReadOnlyDoubleBufferTest method testPutDoubleBuffer.
public void testPutDoubleBuffer() {
DoubleBuffer other = DoubleBuffer.allocate(1);
try {
buf.put(other);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
try {
buf.put((DoubleBuffer) null);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
try {
buf.put(buf);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
}
use of java.nio.DoubleBuffer 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();
}
use of java.nio.DoubleBuffer 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;
}
Aggregations