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