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 * To change this template, choose Tools | Templates
20 * and open the template in the editor.
22 package org.apidesign.bck2brwsr.htmlpage;
24 import net.java.html.canvas.ImageData;
25 import org.apidesign.bck2brwsr.core.JavaScriptBody;
29 * @author Anton Epple <toni.epple@eppleton.de>
31 public class ImageDataWrapper implements ImageData {
33 private double width, height = -1;
34 private Object imageData;
37 public ImageDataWrapper(Object imageData) {
38 this.imageData = imageData;
41 private Data getData() {
43 data = new Data(getDataImpl(imageData));
48 @JavaScriptBody(args = {"imageData"}, body = "return imageData.data")
49 public native Object getDataImpl(Object imageData);
51 public double getWidth() {
53 width = getWidthImpl(imageData);
58 @JavaScriptBody(args = {"imageData"}, body = "return imagedata.width;")
59 private static native double getWidthImpl(Object imageData);
61 public double getHeight() {
63 height = getHeightImpl(imageData);
68 @JavaScriptBody(args = {"imageData"}, body = "return imagedata.height;")
69 private static native double getHeightImpl(Object imageData);
76 public int getR(double x, double y) {
77 double idx = (x + y * width) * 4;
78 return getData().get(idx);
82 public int getG(double x, double y) {
83 double idx = (x + y * width) * 4;
84 return getData().get(idx + 1);
88 public int getB(double x, double y) {
89 double idx = (x + y * width) * 4;
90 return getData().get(idx + 2);
94 public int getA(double x, double y) {
95 double idx = (x + y * width) * 4;
96 return getData().get(idx + 3);
100 public void setR(double x, double y, int value) {
101 double idx = (x + y * width) * 4;
102 getData().set(idx, value);
106 public void setG(double x, double y, int value) {
107 double idx = (x + y * width) * 4;
108 getData().set(idx + 1, value);
112 public void setB(double x, double y, int value) {
113 double idx = (x + y * width) * 4;
114 getData().set(idx + 2, value);
118 public void setA(double x, double y, int value) {
119 double idx = (x + y * width) * 4;
120 getData().set(idx + 3, value);
123 public static class Data {
127 public Data(Object data) {
131 public int get(double index) {
132 return getImpl(data, index);
135 public void set(double index, int value) {
136 setImpl(data, index, value);
139 @JavaScriptBody(args = {"data", "index", "value"}, body = "data[index]=value;")
140 private static native void setImpl(Object data, double index, int value);
142 @JavaScriptBody(args = {"imagedata", "index"}, body = "return data[index];")
143 private static native int getImpl(Object data, double index);