Change ops to use ArrayBuffer instead of byteArray

This commit is contained in:
j433866 2019-04-01 10:54:46 +01:00
parent c2496fe63e
commit e44a22e143
18 changed files with 194 additions and 177 deletions

View file

@ -26,8 +26,8 @@ class SharpenImage extends Operation {
this.module = "Image";
this.description = "Sharpens an image (Unsharp mask)";
this.infoURL = "https://wikipedia.org/wiki/Unsharp_masking";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.presentType = "html";
this.args = [
{
@ -54,20 +54,20 @@ class SharpenImage extends Operation {
}
/**
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
*/
async run(input, args) {
const [radius, amount, threshold] = args;
if (!isImage(input)){
if (!isImage(new Uint8Array(input))){
throw new OperationError("Invalid file type.");
}
let image;
try {
image = await jimp.read(Buffer.from(input));
image = await jimp.read(input);
} catch (err) {
throw new OperationError(`Error loading image. (${err})`);
}
@ -140,7 +140,7 @@ class SharpenImage extends Operation {
} else {
imageBuffer = await image.getBufferAsync(jimp.AUTO);
}
return [...imageBuffer];
return imageBuffer.buffer;
} catch (err) {
throw new OperationError(`Error sharpening image. (${err})`);
}
@ -148,18 +148,19 @@ class SharpenImage extends Operation {
/**
* Displays the sharpened image using HTML for web apps
* @param {byteArray} data
* @param {ArrayBuffer} data
* @returns {html}
*/
present(data) {
if (!data.length) return "";
if (!data.byteLength) return "";
const dataArray = new Uint8Array(data);
const type = isImage(data);
const type = isImage(dataArray);
if (!type) {
throw new OperationError("Invalid image type.");
throw new OperationError("Invalid file type.");
}
return `<img src="data:${type};base64,${toBase64(data)}">`;
return `<img src="data:${type};base64,${toBase64(dataArray)}">`;
}
}