Example usage for com.google.gwt.corp.gfx.client.canvas CanvasPixelArray set

List of usage examples for com.google.gwt.corp.gfx.client.canvas CanvasPixelArray set

Introduction

In this page you can find the example usage for com.google.gwt.corp.gfx.client.canvas CanvasPixelArray set.

Prototype

public final native void set(int i, int value) ;

Source Link

Document

Sets the data value at position i to the given value.

Usage

From source file:jake2.gwt.client.GwtWebGLRenderer.java

License:Open Source License

@Override
protected void GL_ResampleTexture(int[] in, int inwidth, int inheight, int[] out, int outwidth, int outheight) {

    if (canvas1.getWidth() < inwidth) {
        canvas1.setWidth(inwidth);// w  w w.j  av  a2  s  . c om
    }
    if (canvas1.getHeight() < inheight) {
        canvas1.setHeight(inheight);
    }

    CanvasRenderingContext2D inCtx = canvas1.getContext2D();
    ImageData data = inCtx.createImageData(inwidth, inheight);
    CanvasPixelArray pixels = data.getData();

    int len = inwidth * inheight;
    int p = 0;

    for (int i = 0; i < len; i++) {
        int abgr = in[i];
        pixels.set(p, (abgr & 255));
        pixels.set(p + 1, (abgr >> 8) & 255);
        pixels.set(p + 2, (abgr >> 16) & 255);
        pixels.set(p + 3, (abgr >> 24) & 255);
        p += 4;
    }
    inCtx.putImageData(data, 0, 0);

    if (canvas2.getWidth() < outwidth) {
        canvas2.setWidth(outwidth);
    }
    if (canvas2.getHeight() < outheight) {
        canvas2.setHeight(outheight);
    }

    CanvasRenderingContext2D outCtx = canvas2.getContext2D();
    outCtx.drawImage(canvas1, 0, 0, inwidth, inheight, 0, 0, outwidth, outheight);

    data = outCtx.getImageData(0, 0, outwidth, outheight);
    pixels = data.getData();

    len = outwidth * outheight;
    p = 0;

    for (int i = 0; i < len; i++) {
        int r = pixels.get(p) & 255;
        int g = pixels.get(p + 1) & 255;
        int b = pixels.get(p + 2) & 255;
        int a = pixels.get(p + 3) & 255;
        p += 4;
        out[i] = (a << 24) | (b << 16) | (g << 8) | r;
    }
}

From source file:jake2.gwt.client.GwtWebGLRenderer.java

License:Open Source License

protected void debugLightmap(IntBuffer lightmapBuffer, int w, int h, float scale) {
    CanvasElement canvas = (CanvasElement) Document.get().createElement("canvas");
    canvas.setWidth(w);//ww w  .j  a  va 2  s . co m
    canvas.setHeight(h);
    Document.get().getBody().appendChild(canvas);
    ImageData id = canvas.getContext2D().createImageData(w, h);
    CanvasPixelArray pd = id.getData();
    for (int i = 0; i < w * h; i++) {
        int abgr = lightmapBuffer.get(i);
        pd.set(i * 4, abgr & 255);
        pd.set(i * 4 + 1, abgr & 255);
        pd.set(i * 4 + 2, abgr & 255);
        pd.set(i * 4 + 3, abgr & 255);
    }
    canvas.getContext2D().putImageData(id, 0, 0);
}