Search in sources :

Example 1 with Uint8Array

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());
    });
}
Also used : Promise(im.actor.runtime.promise.Promise) HTTPError(im.actor.runtime.http.HTTPError) HTTPResponse(im.actor.runtime.http.HTTPResponse) JsHttpRequest(im.actor.runtime.js.http.JsHttpRequest) Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array)

Example 2 with Uint8Array

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));
    });
}
Also used : Promise(im.actor.runtime.promise.Promise) Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array) FilePart(im.actor.runtime.files.FilePart)

Example 3 with Uint8Array

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;
}
Also used : Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array)

Example 4 with Uint8Array

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);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array) HasArrayBufferView(java.nio.HasArrayBufferView) ByteBuffer(java.nio.ByteBuffer)

Example 5 with Uint8Array

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");
    }
}
Also used : Int32Array(com.google.gwt.typedarrays.shared.Int32Array) Uint16Array(com.google.gwt.typedarrays.shared.Uint16Array) Float32Array(com.google.gwt.typedarrays.shared.Float32Array) Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array)

Aggregations

Uint8Array (com.google.gwt.typedarrays.shared.Uint8Array)7 Promise (im.actor.runtime.promise.Promise)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 ArrayBuffer (com.google.gwt.typedarrays.shared.ArrayBuffer)1 Float32Array (com.google.gwt.typedarrays.shared.Float32Array)1 Int32Array (com.google.gwt.typedarrays.shared.Int32Array)1 Uint16Array (com.google.gwt.typedarrays.shared.Uint16Array)1 FilePart (im.actor.runtime.files.FilePart)1 HTTPError (im.actor.runtime.http.HTTPError)1 HTTPResponse (im.actor.runtime.http.HTTPResponse)1 JsHttpRequest (im.actor.runtime.js.http.JsHttpRequest)1 ConnectionEndpoint (im.actor.runtime.mtproto.ConnectionEndpoint)1 ByteBuffer (java.nio.ByteBuffer)1 HasArrayBufferView (java.nio.HasArrayBufferView)1