Search in sources :

Example 6 with IntBuffer

use of java.nio.IntBuffer in project UltimateAndroid by cymcsg.

the class BitmapOutput method drawFrame.

@Override
public void drawFrame() {
    if (frameBuffer == null) {
        if (getWidth() != 0 && getHeight() != 0) {
            initFBO();
        } else {
            return;
        }
    }
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
    super.drawFrame();
    int[] pixels = new int[getWidth() * getHeight()];
    IntBuffer intBuffer = IntBuffer.wrap(pixels);
    intBuffer.position(0);
    GLES20.glReadPixels(0, 0, getWidth(), getHeight(), GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, intBuffer);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    for (int i = 0; i < pixels.length; i++) {
        //swap red and blue to translate back to bitmap rgb style
        pixels[i] = (pixels[i] & (0xFF00FF00)) | ((pixels[i] >> 16) & 0x000000FF) | ((pixels[i] << 16) & 0x00FF0000);
    }
    Bitmap image = Bitmap.createBitmap(pixels, getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    callback.bitmapCreated(image);
}
Also used : Bitmap(android.graphics.Bitmap) IntBuffer(java.nio.IntBuffer)

Example 7 with IntBuffer

use of java.nio.IntBuffer in project UltimateAndroid by cymcsg.

the class JPGFileEndpoint method drawFrame.

@Override
public void drawFrame() {
    if (frameBuffer == null) {
        if (getWidth() != 0 && getHeight() != 0) {
            initFBO();
        } else {
            return;
        }
    }
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
    super.drawFrame();
    int[] pixels = new int[getWidth() * getHeight()];
    IntBuffer intBuffer = IntBuffer.wrap(pixels);
    intBuffer.position(0);
    GLES20.glReadPixels(0, 0, getWidth(), getHeight(), GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, intBuffer);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    for (int i = 0; i < pixels.length; i++) {
        //swap red and blue to translate back to bitmap rgb style
        pixels[i] = (pixels[i] & (0xFF00FF00)) | ((pixels[i] >> 16) & 0x000000FF) | ((pixels[i] << 16) & 0x00FF0000);
    }
    Bitmap image = Bitmap.createBitmap(pixels, getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    String filePathName;
    if (increment) {
        filePathName = filePath + curNumber + ".jpg";
        curNumber++;
    } else {
        filePathName = filePath + ".jpg";
    }
    try {
        OutputStream out = new FileOutputStream(new File(filePathName));
        image.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
        if (storeToMedia) {
            String[] name = filePath.split("/");
            MediaStore.Images.Media.insertImage(context.getContentResolver(), filePathName, name[name.length - 1], "");
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Bitmap(android.graphics.Bitmap) IntBuffer(java.nio.IntBuffer) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

Example 8 with IntBuffer

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

the class IndexMergerTest method testDictIdSeeker.

@Test
public void testDictIdSeeker() throws Exception {
    IntBuffer dimConversions = ByteBuffer.allocateDirect(3 * Ints.BYTES).asIntBuffer();
    dimConversions.put(0);
    dimConversions.put(2);
    dimConversions.put(4);
    IndexMerger.IndexSeeker dictIdSeeker = new IndexMerger.IndexSeekerWithConversion((IntBuffer) dimConversions.asReadOnlyBuffer().rewind());
    Assert.assertEquals(0, dictIdSeeker.seek(0));
    Assert.assertEquals(-1, dictIdSeeker.seek(1));
    Assert.assertEquals(1, dictIdSeeker.seek(2));
    try {
        dictIdSeeker.seek(5);
        Assert.fail("Only support access in order");
    } catch (ISE ise) {
        Assert.assertTrue("Only support access in order", true);
    }
    Assert.assertEquals(-1, dictIdSeeker.seek(3));
    Assert.assertEquals(2, dictIdSeeker.seek(4));
    Assert.assertEquals(-1, dictIdSeeker.seek(5));
}
Also used : IntBuffer(java.nio.IntBuffer) ISE(io.druid.java.util.common.ISE) IncrementalIndexTest(io.druid.segment.data.IncrementalIndexTest) Test(org.junit.Test)

Example 9 with IntBuffer

use of java.nio.IntBuffer in project UltimateAndroid by cymcsg.

the class BitmapOutput method drawFrame.

@Override
public void drawFrame() {
    if (frameBuffer == null) {
        if (getWidth() != 0 && getHeight() != 0) {
            initFBO();
        } else {
            return;
        }
    }
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
    super.drawFrame();
    int[] pixels = new int[getWidth() * getHeight()];
    IntBuffer intBuffer = IntBuffer.wrap(pixels);
    intBuffer.position(0);
    GLES20.glReadPixels(0, 0, getWidth(), getHeight(), GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, intBuffer);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    for (int i = 0; i < pixels.length; i++) {
        //swap red and blue to translate back to bitmap rgb style
        pixels[i] = (pixels[i] & (0xFF00FF00)) | ((pixels[i] >> 16) & 0x000000FF) | ((pixels[i] << 16) & 0x00FF0000);
    }
    Bitmap image = Bitmap.createBitmap(pixels, getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    callback.bitmapCreated(image);
}
Also used : Bitmap(android.graphics.Bitmap) IntBuffer(java.nio.IntBuffer)

Example 10 with IntBuffer

use of java.nio.IntBuffer in project UltimateAndroid by cymcsg.

the class JPGFileEndpoint method drawFrame.

@Override
public void drawFrame() {
    if (frameBuffer == null) {
        if (getWidth() != 0 && getHeight() != 0) {
            initFBO();
        } else {
            return;
        }
    }
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
    super.drawFrame();
    int[] pixels = new int[getWidth() * getHeight()];
    IntBuffer intBuffer = IntBuffer.wrap(pixels);
    intBuffer.position(0);
    GLES20.glReadPixels(0, 0, getWidth(), getHeight(), GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, intBuffer);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    for (int i = 0; i < pixels.length; i++) {
        //swap red and blue to translate back to bitmap rgb style
        pixels[i] = (pixels[i] & (0xFF00FF00)) | ((pixels[i] >> 16) & 0x000000FF) | ((pixels[i] << 16) & 0x00FF0000);
    }
    Bitmap image = Bitmap.createBitmap(pixels, getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    String filePathName;
    if (increment) {
        filePathName = filePath + curNumber + ".jpg";
        curNumber++;
    } else {
        filePathName = filePath + ".jpg";
    }
    try {
        OutputStream out = new FileOutputStream(new File(filePathName));
        image.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
        if (storeToMedia) {
            String[] name = filePath.split("/");
            MediaStore.Images.Media.insertImage(context.getContentResolver(), filePathName, name[name.length - 1], "");
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Bitmap(android.graphics.Bitmap) IntBuffer(java.nio.IntBuffer) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

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