List of usage examples for com.google.gwt.canvas.dom.client CanvasPixelArray get
public final native int get(int i) ;
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. j av a 2 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.java2 s. co 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; }//from w w w .j a v a 2 s . c om 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; }/*ww w .j av a2 s . c om*/ 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 va2 s. 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 ava 2 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 w ww . java 2 s .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 ww w. j a v a 2 s . 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) (((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 w w.ja va2 s. 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) { 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.googlecode.mgwt.image.client.ImageConverter.java
License:Apache License
public void convert(final ImageResource resource, String color, final ImageConverterCallback imageConverterCallback) { if (color == null) { throw new IllegalArgumentException(); }/*from w w w. j ava2 s .c o m*/ if (!color.startsWith("#")) { throw new IllegalArgumentException(); } color = maybeExpandColor(color); final int hexColor = Integer.parseInt(color.substring(1), 16); final int red = hexColor >> 16 & 0xFF; final int green = hexColor >> 8 & 0xFF; final int blue = hexColor & 0xFF; final int height = resource.getHeight(); final int width = resource.getWidth(); loadImage(resource.getSafeUri().asString(), width, height, new LoadImageCallback() { @Override public void onSuccess(ImageElement imageElement) { Canvas canvas = Canvas.createIfSupported(); canvas.getElement().setPropertyInt("height", height); canvas.getElement().setPropertyInt("width", width); Context2d context = canvas.getContext2d(); context.drawImage(imageElement, 0, 0); ImageData imageData = context.getImageData(0, 0, width, height); CanvasPixelArray canvasPixelArray = imageData.getData(); for (int i = 0; i < canvasPixelArray.getLength(); i += 4) { canvasPixelArray.set(i, red); canvasPixelArray.set(i + 1, green); canvasPixelArray.set(i + 2, blue); canvasPixelArray.set(i + 3, canvasPixelArray.get(i + 3)); } context.putImageData(imageData, 0, 0); imageConverterCallback.onSuccess(new ConvertedImageResource(canvas.toDataUrl("image/png"), resource.getWidth(), resource.getHeight())); } }); }