# HG changeset patch # User Anton Epple # Date 1369647101 -7200 # Node ID 9a6cf322f890ded09c74d540cc2f5fe5c391143c # Parent ab08a4271d5f589fe3dec71078a050e7d9771b8a RGBA values for ImageData diff -r ab08a4271d5f -r 9a6cf322f890 javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ImageDataWrapper.java --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ImageDataWrapper.java Mon May 27 11:26:55 2013 +0200 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ImageDataWrapper.java Mon May 27 11:31:41 2013 +0200 @@ -1,19 +1,19 @@ /** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach + * * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 2 of the License. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. + * You should have received a copy of the GNU General Public License along with + * this program. Look for COPYING file in the top folder. If not, see + * http://opensource.org/licenses/GPL-2.0. */ /* * To change this template, choose Tools | Templates @@ -28,34 +28,41 @@ * * @author Anton Epple */ -public class ImageDataWrapper implements ImageData{ +public class ImageDataWrapper implements ImageData { + private double width, height = -1; private Object imageData; private Data data; public ImageDataWrapper(Object imageData) { this.imageData = imageData; } - - public Data getData(){ - if (data == null){ + + private Data getData() { + if (data == null) { data = new Data(getDataImpl(imageData)); } return data; } - + @JavaScriptBody(args = {"imageData"}, body = "return imageData.data") public native Object getDataImpl(Object imageData); public double getWidth() { - return getWidthImpl(imageData); + if (width == -1) { + width = getWidthImpl(imageData); + } + return width; } @JavaScriptBody(args = {"imageData"}, body = "return imagedata.width;") private static native double getWidthImpl(Object imageData); public double getHeight() { - return getHeightImpl(imageData); + if (height == -1) { + height = getHeightImpl(imageData); + } + return height; } @JavaScriptBody(args = {"imageData"}, body = "return imagedata.height;") @@ -66,15 +73,52 @@ } @Override - public int getPixel(double x, double y) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + public int getR(double x, double y) { + double idx = (x + y * width) * 4; + return getData().get(idx); } @Override - public void setPixel(double x, double y, int value) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + public int getG(double x, double y) { + double idx = (x + y * width) * 4; + return getData().get(idx + 1); } + @Override + public int getB(double x, double y) { + double idx = (x + y * width) * 4; + return getData().get(idx + 2); + } + + @Override + public int getA(double x, double y) { + double idx = (x + y * width) * 4; + return getData().get(idx + 3); + } + + @Override + public void setR(double x, double y, int value) { + double idx = (x + y * width) * 4; + getData().set(idx, value); + } + + @Override + public void setG(double x, double y, int value) { + double idx = (x + y * width) * 4; + getData().set(idx + 1, value); + } + + @Override + public void setB(double x, double y, int value) { + double idx = (x + y * width) * 4; + getData().set(idx + 2, value); + } + + @Override + public void setA(double x, double y, int value) { + double idx = (x + y * width) * 4; + getData().set(idx + 3, value); + } public static class Data { @@ -84,18 +128,18 @@ this.data = data; } - public int get(int index) { + public int get(double index) { return getImpl(data, index); } - public void set(int index, int value) { + public void set(double index, int value) { setImpl(data, index, value); } @JavaScriptBody(args = {"data", "index", "value"}, body = "data[index]=value;") - private static native void setImpl(Object data, int index, int value); + private static native void setImpl(Object data, double index, int value); @JavaScriptBody(args = {"imagedata", "index"}, body = "return data[index];") - private static native int getImpl(Object data, int index); + private static native int getImpl(Object data, double index); } }