Search in sources :

Example 66 with IntBuffer

use of java.nio.IntBuffer in project Rajawali by Rajawali.

the class ScreenGrab method getPixelsFromBuffer.

/**
	 * Grabs the pixels from the buffer
	 * 
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 * @return
	 */
public static Bitmap getPixelsFromBuffer(int x, int y, int width, int height) {
    int[] b = new int[width * (y + height)];
    int[] bt = new int[width * height];
    IntBuffer ib = IntBuffer.wrap(b);
    ib.position(0);
    GLES20.glReadPixels(x, y, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ib);
    for (int i = 0, k = 0; i < height; i++, k++) {
        for (int j = 0; j < width; j++) {
            int pix = b[i * width + j];
            int pb = (pix >> 16) & 0xff;
            int pr = (pix << 16) & 0x00ff0000;
            int pix1 = (pix & 0xff00ff00) | pr | pb;
            bt[(height - k - 1) * width + j] = pix1;
        }
    }
    return Bitmap.createBitmap(bt, width, height, Bitmap.Config.ARGB_8888);
}
Also used : IntBuffer(java.nio.IntBuffer)

Example 67 with IntBuffer

use of java.nio.IntBuffer in project StickerCamera by Skykai521.

the class GPUImageView method capture.

/**
     * Capture the current image with the size as it is displayed and retrieve it as Bitmap.
     * @return current output as Bitmap
     * @throws InterruptedException
     */
public Bitmap capture() throws InterruptedException {
    final Semaphore waiter = new Semaphore(0);
    final int width = mGLSurfaceView.getMeasuredWidth();
    final int height = mGLSurfaceView.getMeasuredHeight();
    // Take picture on OpenGL thread
    final int[] pixelMirroredArray = new int[width * height];
    mGPUImage.runOnGLThread(new Runnable() {

        @Override
        public void run() {
            final IntBuffer pixelBuffer = IntBuffer.allocate(width * height);
            GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer);
            int[] pixelArray = pixelBuffer.array();
            // Convert upside down mirror-reversed image to right-side up normal image.
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    pixelMirroredArray[(height - i - 1) * width + j] = pixelArray[i * width + j];
                }
            }
            waiter.release();
        }
    });
    requestRender();
    waiter.acquire();
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.copyPixelsFromBuffer(IntBuffer.wrap(pixelMirroredArray));
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) IntBuffer(java.nio.IntBuffer) Semaphore(java.util.concurrent.Semaphore)

Example 68 with IntBuffer

use of java.nio.IntBuffer in project StickerCamera by Skykai521.

the class PixelBuffer method convertToBitmap.

private void convertToBitmap() {
    int[] iat = new int[mWidth * mHeight];
    IntBuffer ib = IntBuffer.allocate(mWidth * mHeight);
    mGL.glReadPixels(0, 0, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, ib);
    int[] ia = ib.array();
    // image.
    for (int i = 0; i < mHeight; i++) {
        for (int j = 0; j < mWidth; j++) {
            iat[(mHeight - i - 1) * mWidth + j] = ia[i * mWidth + j];
        }
    }
    mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
    mBitmap.copyPixelsFromBuffer(IntBuffer.wrap(iat));
}
Also used : IntBuffer(java.nio.IntBuffer)

Example 69 with IntBuffer

use of java.nio.IntBuffer in project robotium by RobotiumTech.

the class GLRenderWrapper method savePixels.

/**
	 * Extract the bitmap from OpenGL 
	 * 
	 * @param x the start column
	 * @param y the start line
	 * @param w the width of the bitmap
	 * @param h the height of the bitmap
	 * @param gl the current GL reference
	 */
private static Bitmap savePixels(int x, int y, int w, int h, GL10 gl) {
    int[] b = new int[w * (y + h)];
    int[] bt = new int[w * h];
    IntBuffer ib = IntBuffer.wrap(b);
    ib.position(0);
    gl.glReadPixels(x, 0, w, y + h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib);
    for (int i = 0, k = 0; i < h; i++, k++) {
        // and so, some correction need.
        for (int j = 0; j < w; j++) {
            int pix = b[i * w + j];
            int pb = (pix >> 16) & 0xff;
            int pr = (pix << 16) & 0x00ff0000;
            int pix1 = (pix & 0xff00ff00) | pr | pb;
            bt[(h - k - 1) * w + j] = pix1;
        }
    }
    Bitmap sb = Bitmap.createBitmap(bt, w, h, Bitmap.Config.ARGB_8888);
    return sb;
}
Also used : Bitmap(android.graphics.Bitmap) IntBuffer(java.nio.IntBuffer)

Example 70 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)

Aggregations

IntBuffer (java.nio.IntBuffer)286 ByteBuffer (java.nio.ByteBuffer)97 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