diff --git a/package.json b/package.json index d3ee1418..ab6bfcab 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/js/Aladin.js b/src/js/Aladin.js index 06ceedf4..d3130886 100644 --- a/src/js/Aladin.js +++ b/src/js/Aladin.js @@ -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); } /** diff --git a/src/js/View.js b/src/js/View.js index 39c2cf98..f20cb482 100644 --- a/src/js/View.js +++ b/src/js/View.js @@ -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)) {