Search in sources :

Example 11 with IntBuffer

use of java.nio.IntBuffer in project druid by druid-io.

the class IntListTest method testGetBaseList.

@Test
public void testGetBaseList() {
    int listSize = 2;
    IntList list = new IntList(listSize);
    int[] expectedArray = { 1, 2 };
    list.add(expectedArray[0]);
    list.add(expectedArray[1]);
    IntBuffer outputBuffer = list.getBaseList(0);
    Assert.assertEquals("Buffer size does not match", 2, outputBuffer.limit());
    int[] actualArray = new int[outputBuffer.capacity()];
    outputBuffer.get(actualArray);
    Assert.assertArrayEquals("Arrays are not matching", expectedArray, actualArray);
}
Also used : IntBuffer(java.nio.IntBuffer) Test(org.junit.Test)

Example 12 with IntBuffer

use of java.nio.IntBuffer in project druid by druid-io.

the class IntListTest method testNullCaseGetBaseList.

@Test
public void testNullCaseGetBaseList() {
    final int intSize = 2;
    IntList list = new IntList(intSize);
    list.set(2 * intSize, 100);
    IntBuffer outBuffer;
    outBuffer = list.getBaseList(0);
    Assert.assertNull("Should be Null", outBuffer);
}
Also used : IntBuffer(java.nio.IntBuffer) Test(org.junit.Test)

Example 13 with IntBuffer

use of java.nio.IntBuffer in project druid by druid-io.

the class IntList method getBaseList.

public IntBuffer getBaseList(int index) {
    final int[] array = baseLists.get(index);
    if (array == null) {
        return null;
    }
    final IntBuffer retVal = IntBuffer.wrap(array);
    if (index + 1 == baseListCount()) {
        retVal.limit(maxIndex - (index * allocateSize) + 1);
    }
    return retVal.asReadOnlyBuffer();
}
Also used : IntBuffer(java.nio.IntBuffer)

Example 14 with IntBuffer

use of java.nio.IntBuffer in project android_frameworks_base by ParanoidAndroid.

the class GLLogWrapper method doArrayElement.

private void doArrayElement(StringBuilder builder, boolean enabled, String name, PointerInfo pointer, int index) {
    if (!enabled) {
        return;
    }
    builder.append(" ");
    builder.append(name + ":{");
    if (pointer == null || pointer.mTempByteBuffer == null) {
        builder.append("undefined }");
        return;
    }
    if (pointer.mStride < 0) {
        builder.append("invalid stride");
        return;
    }
    int stride = pointer.getStride();
    ByteBuffer byteBuffer = pointer.mTempByteBuffer;
    int size = pointer.mSize;
    int type = pointer.mType;
    int sizeofType = pointer.sizeof(type);
    int byteOffset = stride * index;
    for (int i = 0; i < size; i++) {
        if (i > 0) {
            builder.append(", ");
        }
        switch(type) {
            case GL_BYTE:
                {
                    byte d = byteBuffer.get(byteOffset);
                    builder.append(Integer.toString(d));
                }
                break;
            case GL_UNSIGNED_BYTE:
                {
                    byte d = byteBuffer.get(byteOffset);
                    builder.append(Integer.toString(0xff & d));
                }
                break;
            case GL_SHORT:
                {
                    ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
                    short d = shortBuffer.get(byteOffset / 2);
                    builder.append(Integer.toString(d));
                }
                break;
            case GL_FIXED:
                {
                    IntBuffer intBuffer = byteBuffer.asIntBuffer();
                    int d = intBuffer.get(byteOffset / 4);
                    builder.append(Integer.toString(d));
                }
                break;
            case GL_FLOAT:
                {
                    FloatBuffer intBuffer = byteBuffer.asFloatBuffer();
                    float d = intBuffer.get(byteOffset / 4);
                    builder.append(Float.toString(d));
                }
                break;
            default:
                builder.append("?");
                break;
        }
        byteOffset += sizeofType;
    }
    builder.append("}");
}
Also used : IntBuffer(java.nio.IntBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 15 with IntBuffer

use of java.nio.IntBuffer in project gl-react-native by ProjectSeptemberInc.

the class GLCanvas method createSnapshot.

private Bitmap createSnapshot(int x, int y, int w, int h) {
    int[] bitmapBuffer = new int[w * h];
    int[] bitmapSource = new int[w * h];
    IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer);
    intBuffer.position(0);
    try {
        glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, intBuffer);
        int offset1, offset2;
        for (int i = 0; i < h; i++) {
            offset1 = i * w;
            offset2 = (h - i - 1) * w;
            for (int j = 0; j < w; j++) {
                int texturePixel = bitmapBuffer[offset1 + j];
                int blue = (texturePixel >> 16) & 0xff;
                int red = (texturePixel << 16) & 0x00ff0000;
                int pixel = (texturePixel & 0xff00ff00) | red | blue;
                bitmapSource[offset2 + j] = pixel;
            }
        }
    } catch (GLException e) {
        return null;
    }
    return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888);
}
Also used : IntBuffer(java.nio.IntBuffer) GLException(android.opengl.GLException)

Aggregations

IntBuffer (java.nio.IntBuffer)283 ByteBuffer (java.nio.ByteBuffer)95 FloatBuffer (java.nio.FloatBuffer)47 ShortBuffer (java.nio.ShortBuffer)36 Test (org.junit.Test)35 Bitmap (android.graphics.Bitmap)18 DoubleBuffer (java.nio.DoubleBuffer)18 IOException (java.io.IOException)14 BaseTest (org.apache.jena.atlas.junit.BaseTest)14 FileOutputStream (java.io.FileOutputStream)13 CharBuffer (java.nio.CharBuffer)11 LongBuffer (java.nio.LongBuffer)11 UTF8CodePointDecoder (org.antlr.v4.runtime.UTF8CodePointDecoder)11 ArrayList (java.util.ArrayList)10 File (java.io.File)9 Buffer (java.nio.Buffer)9 VertexBuffer (com.jme3.scene.VertexBuffer)7 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)6 BufferOverflowException (java.nio.BufferOverflowException)6 FileChannel (java.nio.channels.FileChannel)6