javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ImageDataWrapper.java
2 * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
3 * <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program. Look for COPYING file in the top folder. If not, see
16 * http://opensource.org/licenses/GPL-2.0.
19 package org.apidesign.bck2brwsr.htmlpage;
21 import net.java.html.canvas.ImageData;
22 import org.apidesign.bck2brwsr.core.JavaScriptBody;
26 * @author Anton Epple <toni.epple@eppleton.de>
28 public class ImageDataWrapper implements ImageData {
30 private double width, height = -1;
31 private Object imageData;
34 public ImageDataWrapper(Object imageData) {
35 this.imageData = imageData;
38 private Data getData() {
40 data = new Data(getDataImpl(imageData));
45 @JavaScriptBody(args = {"imageData"}, body = "return imageData.data")
46 public native Object getDataImpl(Object imageData);
48 public double getWidth() {
50 width = getWidthImpl(imageData);
55 @JavaScriptBody(args = {"imageData"}, body = "return imagedata.width;")
56 private static native int getWidthImpl(Object imageData);
58 public double getHeight() {
60 height = getHeightImpl(imageData);
65 @JavaScriptBody(args = {"imageData"}, body = "return imagedata.height;")
66 private static native int getHeightImpl(Object imageData);
73 public int getR(int x, int y) {
74 int idx = (x + y * (int)width) * 4;
75 return getData().get(idx);
79 public int getG(int x, int y) {
80 int idx = (x + y * (int)width) * 4;
81 return getData().get(idx + 1);
85 public int getB(int x, int y) {
86 int idx = (x + y * (int)width) * 4;
87 return getData().get(idx + 2);
91 public int getA(int x, int y) {
92 int idx = (x + y * (int)width) * 4;
93 return getData().get(idx + 3);
97 public void setR(int x, int y, int value) {
98 int idx = (x + y * (int)width) * 4;
99 getData().set(idx, value);
103 public void setG(int x, int y, int value) {
104 int idx = (x + y * (int)width) * 4;
105 getData().set(idx + 1, value);
109 public void setB(int x, int y, int value) {
110 int idx = (x + y * (int)width) * 4;
111 getData().set(idx + 2, value);
115 public void setA(int x, int y, int value) {
116 int idx = (x + y * (int)width) * 4;
117 getData().set(idx + 3, value);
120 private static class Data {
124 public Data(Object data) {
128 public int get(int index) {
129 return getImpl(data, index);
132 public void set(int index, int value) {
133 setImpl(data, index, value);
136 @JavaScriptBody(args = {"data", "index", "value"}, body = "data[index]=value;")
137 private static native void setImpl(Object data, int index, int value);
139 @JavaScriptBody(args = {"imagedata", "index"}, body = "return data[index];")
140 private static native int getImpl(Object data, int index);