use of com.google.gwt.typedarrays.shared.Uint8Array in project actor-platform by actorapp.
the class JsHttpProvider method putMethod.
@Override
public Promise<HTTPResponse> putMethod(String url, byte[] contents) {
return new Promise<>(resolver -> {
JsHttpRequest request = JsHttpRequest.create();
request.open("PUT", url);
request.setRequestHeader("Content-Type", "application/octet-stream");
request.setOnLoadHandler(request1 -> {
if (request1.getReadyState() == 4) {
if (request1.getStatus() >= 200 && request1.getStatus() < 300) {
resolver.result(new HTTPResponse(request1.getStatus(), null));
} else {
resolver.error(new HTTPError(request1.getStatus()));
}
}
});
Uint8Array push = TypedArrays.createUint8Array(contents.length);
for (int i = 0; i < contents.length; i++) {
push.set(i, contents[i]);
}
request.send(push.buffer());
});
}
use of com.google.gwt.typedarrays.shared.Uint8Array in project actor-platform by actorapp.
the class JsFileInput method read.
@Override
public Promise<FilePart> read(int fileOffset, int len) {
return new Promise<>(resolver -> {
JsFileReader fileReader = JsFileReader.create();
fileReader.setOnLoaded(message -> {
Uint8Array array = TypedArrays.createUint8Array(message);
byte[] data = new byte[len];
for (int i = 0; i < len; i++) {
data[i] = (byte) (array.get(i));
}
resolver.result(new FilePart(fileOffset, len, data));
});
fileReader.readAsArrayBuffer(jsFile.slice(fileOffset, fileOffset + len));
});
}
use of com.google.gwt.typedarrays.shared.Uint8Array in project actor-platform by actorapp.
the class Conversion method convertBytes.
public static byte[] convertBytes(ArrayBuffer buffer) {
Uint8Array array = TypedArrays.createUint8Array(buffer);
byte[] res = new byte[array.length()];
for (int i = 0; i < res.length; i++) {
res[i] = (byte) (array.get(i));
}
return res;
}
use of com.google.gwt.typedarrays.shared.Uint8Array in project libgdx by libgdx.
the class GwtGL20 method glReadPixels.
@Override
public void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels) {
// verify request
if ((format != WebGLRenderingContext.RGBA) || (type != WebGLRenderingContext.UNSIGNED_BYTE)) {
throw new GdxRuntimeException("Only format RGBA and type UNSIGNED_BYTE are currently supported for glReadPixels(...). Create an issue when you need other formats.");
}
if (!(pixels instanceof ByteBuffer)) {
throw new GdxRuntimeException("Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...).");
}
// create new ArrayBufferView (4 bytes per pixel)
int size = 4 * width * height;
Uint8Array buffer = TypedArrays.createUint8Array(((HasArrayBufferView) pixels).getTypedArray().buffer(), 0, size);
// read bytes to ArrayBufferView
gl.readPixels(x, y, width, height, format, type, buffer);
}
use of com.google.gwt.typedarrays.shared.Uint8Array in project playn by threerings.
the class HtmlGLContext method tryBasicGLCalls.
private void tryBasicGLCalls() throws RuntimeException {
// test that our Float32 arrays work (a technique found in other WebGL checks)
Float32Array testFloat32Array = ArrayUtils.createFloat32Array(new float[] { 0.0f, 1.0f, 2.0f });
if (testFloat32Array.get(0) != 0.0f || testFloat32Array.get(1) != 1.0f || testFloat32Array.get(2) != 2.0f) {
throw new RuntimeException("Typed Float32Array check failed");
}
// test that our Int32 arrays work
Int32Array testInt32Array = ArrayUtils.createInt32Array(new int[] { 0, 1, 2 });
if (testInt32Array.get(0) != 0 || testInt32Array.get(1) != 1 || testInt32Array.get(2) != 2) {
throw new RuntimeException("Typed Int32Array check failed");
}
// test that our Uint16 arrays work
Uint16Array testUint16Array = ArrayUtils.createUint16Array(new int[] { 0, 1, 2 });
if (testUint16Array.get(0) != 0 || testUint16Array.get(1) != 1 || testUint16Array.get(2) != 2) {
throw new RuntimeException("Typed Uint16Array check failed");
}
// test that our Uint8 arrays work
Uint8Array testUint8Array = ArrayUtils.createUint8Array(new int[] { 0, 1, 2 });
if (testUint8Array.get(0) != 0 || testUint8Array.get(1) != 1 || testUint8Array.get(2) != 2) {
throw new RuntimeException("Typed Uint8Array check failed");
}
// Perform GL read back test where we paint rgba(1, 1, 1, 1) and then read back that data.
// (should be 100% opaque white).
bindFramebuffer();
clear(1, 1, 1, 1);
int err = glc.getError();
if (err != NO_ERROR) {
throw new RuntimeException("Read back GL test failed to clear color (error " + err + ")");
}
Uint8Array pixelData = TypedArrays.createUint8Array(4);
glc.readPixels(0, 0, 1, 1, RGBA, UNSIGNED_BYTE, pixelData);
if (pixelData.get(0) != 255 || pixelData.get(1) != 255 || pixelData.get(2) != 255) {
throw new RuntimeException("Read back GL test failed to read back correct color");
}
}
Aggregations