🎨 Change implementation from Buffer to ArrayBuffer

This commit is contained in:
Xen0Xys
2024-05-30 15:34:01 +02:00
parent 27bc342d27
commit 9d978c780c
3 changed files with 18 additions and 9 deletions

View File

@@ -53,7 +53,6 @@
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.2.2",
"vite-plugin-wasm-pack": "^0.1.12",
"vitest": "^0.32.2",
"buffer": "^6.0.3"
"vitest": "^0.32.2"
}
}

View File

@@ -26,7 +26,6 @@
* Author: Thomas Boch[CDS], Matthieu Baumann[CDS]
*
*****************************************************************************/
import { Buffer } from "buffer";
import { version } from "./../../package.json";
import { View } from "./View.js";
@@ -2182,8 +2181,7 @@ aladin.on("positionChanged", ({ra, dec}) => {
};
Aladin.prototype.getViewImageBuffer = async function (withLogo) {
const viewDataURL = await this.view.getCanvasDataURL("image/png", null, null, withLogo);
return Buffer.from(viewDataURL.split(",")[1], "base64");
return await this.view.getCanvasBuffer("image/png", null, null, withLogo);
}
/**

View File

@@ -446,10 +446,7 @@ export let View = (function () {
this.catalogCanvas.style.cursor = cursor;
};
/**
* return dataURL string corresponding to the current view
*/
View.prototype.getCanvasDataURL = async function (imgType, width, height, withLogo=true) {
View.prototype.getCanvasContext = async function (imgType, width, height, withLogo=true) {
const loadImage = function (url) {
return new Promise((resolve, reject) => {
const image = new Image()
@@ -480,9 +477,24 @@ export let View = (function () {
ctx.drawImage(logo, offX, offY);
}
return c;
}
/**
* return dataURL string corresponding to the current view
*/
View.prototype.getCanvasDataURL = async function (imgType, width, height, withLogo=true) {
const c = await this.getCanvasContext(imgType, width, height, withLogo);
return c.toDataURL(imgType);
};
/**
* return ArrayBuffer corresponding to the current view
*/
View.prototype.getCanvasBuffer = async function (imgType, width, height, withLogo=true) {
const c = await this.getCanvasContext(imgType, width, height, withLogo);
return c.getContext('2d').getImageData(0, 0, c.width, c.height).data.buffer;
}
View.prototype.selectLayer = function (layer) {
if (!this.imageLayers.has(layer)) {