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