Example usage for com.google.gwt.canvas.dom.client CanvasPixelArray set

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

Introduction

In this page you can find the example usage for com.google.gwt.canvas.dom.client 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:anagram.client.Lens.java

License:Apache License

public void draw(Context2d back, Context2d front) {
    front.drawImage(back.getCanvas(), 0, 0);

    if (!GWT.isScript()) {
        // in devmode this effect is slow so we disable it here
    } else {/*from ww  w .  jav  a2  s.c  o  m*/
        ImageData frontData = front.getImageData((int) (pos.x - radius), (int) (pos.y - radius), 2 * radius,
                2 * radius);
        CanvasPixelArray frontPixels = frontData.getData();
        ImageData backData = back.getImageData((int) (pos.x - radius), (int) (pos.y - radius), 2 * radius,
                2 * radius);
        CanvasPixelArray backPixels = backData.getData();
        int srcIdx, dstIdx;
        for (int i = lensArray.length - 1; i >= 0; i--) {
            dstIdx = 4 * lensArray[i][0];
            srcIdx = 4 * lensArray[i][1];
            frontPixels.set(dstIdx + 0, backPixels.get(srcIdx + 0));
            frontPixels.set(dstIdx + 1, backPixels.get(srcIdx + 1));
            frontPixels.set(dstIdx + 2, backPixels.get(srcIdx + 2));
        }
        front.putImageData(frontData, (int) (pos.x - radius), (int) (pos.y - radius));
    }

    front.setStrokeStyle(strokeStyle);
    front.beginPath();
    front.arc(pos.x, pos.y, radius, 0, Math.PI * 2, true);
    front.closePath();
    front.stroke();
}

From source file:com.emitrom.lienzo.client.core.image.AbstractConvolveImageFilter.java

License:Open Source License

@Override
public ImageData filter(ImageData source, boolean copy) {
    if (null == source) {
        return null;
    }/*ww  w  . j a v a2  s  .  c o m*/
    ImageData output = source.copy();

    final CanvasPixelArray srcd = source.getData();

    if (null == srcd) {
        return source;
    }
    final CanvasPixelArray dstd = output.getData();

    if (null == dstd) {
        return source;
    }
    int side = (int) (Math.sqrt(m_weights.length) + 0.5);

    int half = (int) (Math.floor(side / 2));

    int sw = source.getWidth();

    int sh = source.getHeight();

    int w = sw;

    int h = sh;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int sy = y;

            int sx = x;

            int dsto = (y * w + x) * 4;

            int r = 0, g = 0, b = 0;

            for (int cy = 0; cy < side; cy++) {
                for (int cx = 0; cx < side; cx++) {
                    int scy = sy + cy - half;

                    int scx = sx + cx - half;

                    if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
                        int srco = (scy * sw + scx) * 4;

                        double wt = m_weights[cy * side + cx];

                        r += srcd.get(srco + R_OFFSET) * wt;

                        g += srcd.get(srco + G_OFFSET) * wt;

                        b += srcd.get(srco + B_OFFSET) * wt;
                    }
                }
            }
            dstd.set(dsto + R_OFFSET, r);

            dstd.set(dsto + G_OFFSET, g);

            dstd.set(dsto + B_OFFSET, b);
        }
    }
    return output;
}

From source file:com.emitrom.lienzo.client.core.image.AverageGrayScaleImageDataFilter.java

License:Open Source License

@Override
public ImageData filter(ImageData source, boolean copy) {
    if (null == source) {
        return null;
    }// ww w .  j  ava2s .c o  m
    final int length = getLength(source);

    if (copy) {
        source = source.copy();
    }
    final CanvasPixelArray data = source.getData();

    if (null == data) {
        return source;
    }
    if (isNative()) {
        filter0(data, length);
    } else {
        for (int i = 0; i < length; i += PIXEL_SZ) {
            int v = (int) ((((double) (data.get(i + R_OFFSET) + data.get(i + G_OFFSET)
                    + data.get(i + B_OFFSET))) / 3.0) + 0.5);

            data.set(i + R_OFFSET, v);

            data.set(i + G_OFFSET, v);

            data.set(i + B_OFFSET, v);
        }
    }
    return source;
}

From source file:com.emitrom.lienzo.client.core.image.BrightnessImageDataFilter.java

License:Open Source License

@Override
public ImageData filter(ImageData source, boolean copy) {
    if (null == source) {
        return null;
    }//  w w  w .ja  v a2s  .  co  m
    final int length = getLength(source);

    if (copy) {
        source = source.copy();
    }
    final CanvasPixelArray data = source.getData();

    if (null == data) {
        return source;
    }
    if (isNative()) {

    } else {
        for (int i = 0; i < length; i += PIXEL_SZ) {
            int r = (int) Math.max(Math.min((data.get(i + R_OFFSET) + (m_brightness * 255) + 0.5), 255), 0);

            int g = (int) Math.max(Math.min((data.get(i + G_OFFSET) + (m_brightness * 255) + 0.5), 255), 0);

            int b = (int) Math.max(Math.min((data.get(i + B_OFFSET) + (m_brightness * 255) + 0.5), 255), 0);

            data.set(i + R_OFFSET, r);

            data.set(i + G_OFFSET, g);

            data.set(i + B_OFFSET, b);
        }
    }
    return source;
}

From source file:com.emitrom.lienzo.client.core.image.ChannelBrightnessImageDataFilter.java

License:Open Source License

@Override
public ImageData filter(ImageData source, boolean copy) {
    if (null == source) {
        return null;
    }//from  www. j  a v a 2s . co m
    final int length = getLength(source);

    if (copy) {
        source = source.copy();
    }
    final CanvasPixelArray data = source.getData();

    if (null == data) {
        return source;
    }
    if (isNative()) {
        filter0(data, length, m_r_brightness, m_g_brightness, m_b_brightness);
    } else {
        for (int i = 0; i < length; i += PIXEL_SZ) {
            int r = (int) Math.max(Math.min((data.get(i + R_OFFSET) + (m_r_brightness * 255) + 0.5), 255), 0);

            int g = (int) Math.max(Math.min((data.get(i + G_OFFSET) + (m_g_brightness * 255) + 0.5), 255), 0);

            int b = (int) Math.max(Math.min((data.get(i + B_OFFSET) + (m_b_brightness * 255) + 0.5), 255), 0);

            data.set(i + R_OFFSET, r);

            data.set(i + G_OFFSET, g);

            data.set(i + B_OFFSET, b);
        }
    }
    return source;
}

From source file:com.emitrom.lienzo.client.core.image.ColorLuminosityImageDataFilter.java

License:Open Source License

@Override
public ImageData filter(ImageData source, boolean copy) {
    if (null == source) {
        return null;
    }//from w  w  w.j  a  v  a2 s. com
    final int length = getLength(source);

    if (copy) {
        source = source.copy();
    }
    final CanvasPixelArray data = source.getData();

    if (null == data) {
        return source;
    }
    if (isNative()) {
        filter0(data, length, getR(), getG(), getB());
    } else {
        for (int i = 0; i < length; i += PIXEL_SZ) {
            double m = (((0.21 * data.get(i + R_OFFSET)) + (0.72 * data.get(i + G_OFFSET))
                    + (0.07 * data.get(i + B_OFFSET))) / 255.0);

            data.set(i + R_OFFSET, (int) ((getR() * m) + 0.5));

            data.set(i + G_OFFSET, (int) ((getG() * m) + 0.5));

            data.set(i + B_OFFSET, (int) ((getB() * m) + 0.5));
        }
    }
    return source;
}

From source file:com.emitrom.lienzo.client.core.image.LightnessGrayScaleImageDataFilter.java

License:Open Source License

@Override
public ImageData filter(ImageData source, boolean copy) {
    if (null == source) {
        return null;
    }/*from   www.j a  v  a 2s. c o m*/
    final int length = getLength(source);

    if (copy) {
        source = source.copy();
    }
    final CanvasPixelArray data = source.getData();

    if (null == data) {
        return source;
    }
    if (isNative()) {
        filter0(data, length);
    } else {
        for (int i = 0; i < length; i += PIXEL_SZ) {
            int r = data.get(i + R_OFFSET);

            int g = data.get(i + G_OFFSET);

            int b = data.get(i + B_OFFSET);

            int v = (int) ((((Math.max(Math.max(r, g), b) + Math.min(Math.min(r, g), b))) / 2.0) + 0.5);

            data.set(i + R_OFFSET, v);

            data.set(i + G_OFFSET, v);

            data.set(i + B_OFFSET, v);
        }
    }
    return source;
}

From source file:com.emitrom.lienzo.client.core.image.LuminosityGrayScaleImageDataFilter.java

License:Open Source License

@Override
public ImageData filter(ImageData source, boolean copy) {
    if (null == source) {
        return null;
    }/*from w ww  . j  av  a 2s  .  com*/
    final int length = getLength(source);

    if (copy) {
        source = source.copy();
    }
    final CanvasPixelArray data = source.getData();

    if (null == data) {
        return source;
    }
    if (isNative()) {
        filter0(data, length);
    } else {
        for (int i = 0; i < length; i += PIXEL_SZ) {
            int v = (int) (((0.21 * data.get(i + R_OFFSET)) + (0.72 * data.get(i + G_OFFSET))
                    + (0.07 * data.get(i + B_OFFSET))) + 0.5);

            data.set(i + R_OFFSET, v);

            data.set(i + G_OFFSET, v);

            data.set(i + B_OFFSET, v);
        }
    }
    return source;
}

From source file:com.emitrom.lienzo.client.core.image.RGBIgnoreAlphaImageDataFilter.java

License:Open Source License

/**
 * Returns an {@link ImageData} that is transformed based on the passed in RGB color, setting alpha to 255
 *//*  w  ww  .  ja va  2s .  c  om*/
@Override
public ImageData filter(ImageData source, boolean copy) {
    if (null == source) {
        return null;
    }
    final int length = getLength(source);

    if (copy) {
        source = source.copy();
    }
    final CanvasPixelArray data = source.getData();

    if (null == data) {
        return source;
    }
    if (isNative()) {
        filter0(data, length, getR(), getG(), getB());
    } else {
        for (int i = 0; i < length; i += PIXEL_SZ) {
            if (data.get(i + A_OFFSET) > 0) {
                data.set(i + R_OFFSET, getR());

                data.set(i + G_OFFSET, getG());

                data.set(i + B_OFFSET, getB());

                data.set(i + A_OFFSET, 255);
            }
        }
    }
    return source;
}

From source file:com.emitrom.lienzo.client.core.image.RGBImageDataFilter.java

License:Open Source License

/**
 * Return an {@link ImageData} that is transformed based on the passed in RGB color.
 */// w w w .  ja va2s  .  c o m
@Override
public ImageData filter(ImageData source, boolean copy) {
    if (null == source) {
        return null;
    }
    final int length = getLength(source);

    if (copy) {
        source = source.copy();
    }
    final CanvasPixelArray data = source.getData();

    if (null == data) {
        return source;
    }
    if (isNative()) {
        filter0(data, length, getR(), getG(), getB());
    } else {
        for (int i = 0; i < length; i += PIXEL_SZ) {
            data.set(i + R_OFFSET, getR());

            data.set(i + G_OFFSET, getG());

            data.set(i + B_OFFSET, getB());
        }
    }
    return source;
}