use of net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeUint8ClampedArray in project htmlunit by HtmlUnit.
the class ImageData method getData.
/**
* Returns a {@link NativeUint8ClampedArray} representing a one-dimensional array containing
* the data in the RGBA order, with integer values between 0 and 255 (included).
* @return the {@code data} property
*/
@JsxGetter
public NativeUint8ClampedArray getData() {
if (data_ == null) {
final NativeArrayBuffer arrayBuffer = new NativeArrayBuffer(bytes_.length);
System.arraycopy(bytes_, 0, arrayBuffer.getBuffer(), 0, bytes_.length);
data_ = new NativeUint8ClampedArray(arrayBuffer, 0, bytes_.length);
data_.setParentScope(getParentScope());
data_.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), data_.getClassName()));
}
return data_;
}
use of net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeUint8ClampedArray in project htmlunit by HtmlUnit.
the class ImageData method jsConstructor.
/**
* JavaScript constructor.
* @param cx the current context
* @param args the arguments to the WebSocket constructor
* @param ctorObj the function object
* @param inNewExpr Is new or not
* @return the java object to allow JavaScript to access
*/
@JsxConstructor({ CHROME, EDGE, FF, FF_ESR })
public static Scriptable jsConstructor(final Context cx, final Object[] args, final Function ctorObj, final boolean inNewExpr) {
if (args.length < 2) {
throw Context.reportRuntimeError("ImageData ctor - too less arguments");
}
NativeUint8ClampedArray data = null;
final int width;
final int height;
if (args[0] instanceof NativeUint8ClampedArray) {
data = (NativeUint8ClampedArray) args[0];
if (data.getArrayLength() % 4 != 0) {
throw Context.reportRuntimeError("ImageData ctor - data length mod 4 not zero");
}
width = (int) ScriptRuntime.toInteger(args[1]);
if (args.length < 3) {
height = data.getArrayLength() / 4 / width;
if (data.getArrayLength() != 4 * width * height) {
throw Context.reportRuntimeError("ImageData ctor - width not correct");
}
} else {
height = (int) ScriptRuntime.toInteger(args[2]);
}
if (data.getArrayLength() != 4 * width * height) {
throw Context.reportRuntimeError("ImageData ctor - width/height not correct");
}
} else {
width = (int) ScriptRuntime.toInteger(args[0]);
height = (int) ScriptRuntime.toInteger(args[1]);
}
if (width < 0) {
throw Context.reportRuntimeError("ImageData ctor - width negative");
}
if (height < 0) {
throw Context.reportRuntimeError("ImageData ctor - height negative");
}
final ImageData result = new ImageData(null, 0, 0, width, height);
if (data != null) {
final byte[] bytes = data.getBuffer().getBuffer();
System.arraycopy(bytes, 0, result.bytes_, 0, Math.min(bytes.length, result.bytes_.length));
}
return result;
}
Aggregations