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);
}
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;
}
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));
}
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;
}
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("}");
}
Aggregations