Search in sources :

Example 1 with ImageData

use of com.google.gwt.canvas.dom.client.ImageData in project playn by threerings.

the class HtmlCanvasImage method setRgb.

@Override
public void setRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) {
    Context2d ctx = canvas.canvas().getContext2d();
    ImageData imageData = ctx.createImageData(width, height);
    CanvasPixelArray pixelData = imageData.getData();
    int i = 0;
    int dst = offset;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int argb = rgbArray[dst + x];
            pixelData.set(i++, (argb >> 16) & 255);
            pixelData.set(i++, (argb >> 8) & 255);
            pixelData.set(i++, (argb) & 255);
            pixelData.set(i++, (argb >> 24) & 255);
        }
        dst += scanSize;
    }
    ctx.putImageData(imageData, startX, startY);
}
Also used : CanvasPixelArray(com.google.gwt.canvas.dom.client.CanvasPixelArray) Context2d(com.google.gwt.canvas.dom.client.Context2d) ImageData(com.google.gwt.canvas.dom.client.ImageData)

Example 2 with ImageData

use of com.google.gwt.canvas.dom.client.ImageData in project playn by threerings.

the class HtmlImage method getRgb.

@Override
public void getRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) {
    assert isReady() : "Cannot getRgb() a non-ready image";
    if (canvas == null) {
        canvas = img.getOwnerDocument().createCanvasElement();
        canvas.setHeight(img.getHeight());
        canvas.setWidth(img.getWidth());
        canvas.getContext2d().drawImage(img, 0, 0);
    // img.getOwnerDocument().getBody().appendChild(canvas);
    }
    Context2d ctx = canvas.getContext2d();
    ImageData imageData = ctx.getImageData(startX, startY, width, height);
    CanvasPixelArray pixelData = imageData.getData();
    int i = 0;
    int dst = offset;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int r = pixelData.get(i++);
            int g = pixelData.get(i++);
            int b = pixelData.get(i++);
            int a = pixelData.get(i++);
            rgbArray[dst + x] = a << 24 | r << 16 | g << 8 | b;
        }
        dst += scanSize;
    }
}
Also used : CanvasPixelArray(com.google.gwt.canvas.dom.client.CanvasPixelArray) Context2d(com.google.gwt.canvas.dom.client.Context2d) ImageData(com.google.gwt.canvas.dom.client.ImageData)

Aggregations

CanvasPixelArray (com.google.gwt.canvas.dom.client.CanvasPixelArray)2 Context2d (com.google.gwt.canvas.dom.client.Context2d)2 ImageData (com.google.gwt.canvas.dom.client.ImageData)2