From 03c70e3a06667e44fa7e6336233b641f5169c807 Mon Sep 17 00:00:00 2001 From: Ivan Hetman Date: Wed, 7 Oct 2020 12:21:02 +0300 Subject: [PATCH] Image data fix (#524) JS: add constructors for ImageData API --- .../java/org/teavm/jso/canvas/ImageData.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/jso/apis/src/main/java/org/teavm/jso/canvas/ImageData.java b/jso/apis/src/main/java/org/teavm/jso/canvas/ImageData.java index 08384baa8..bd4a68df3 100644 --- a/jso/apis/src/main/java/org/teavm/jso/canvas/ImageData.java +++ b/jso/apis/src/main/java/org/teavm/jso/canvas/ImageData.java @@ -15,20 +15,30 @@ */ package org.teavm.jso.canvas; +import org.teavm.jso.JSBody; import org.teavm.jso.JSObject; import org.teavm.jso.JSProperty; import org.teavm.jso.typedarrays.Uint8ClampedArray; -public interface ImageData extends JSObject { - @JSProperty - int getWidth(); +public abstract class ImageData implements JSObject { + private ImageData() { + } @JSProperty - int getHeight(); + public abstract int getWidth(); @JSProperty - Uint8ClampedArray getData(); + public abstract int getHeight(); @JSProperty - void setData(Uint8ClampedArray data); + public abstract Uint8ClampedArray getData(); + + @JSBody(params = { "array", "width" }, script = "return new ImageData(array, width);") + public static native ImageData create(Uint8ClampedArray array, int width); + + @JSBody(params = { "width", "height" }, script = "return new ImageData(width, height);") + public static native ImageData create(int width, int height); + + @JSBody(params = { "array", "width", "height" }, script = "return new ImageData(array, width, height);") + public static native ImageData create(Uint8ClampedArray array, int width, int height); }