"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._withQuantumArray = exports._withDoubleArray = void 0;
const image_magick_1 = require("../../image-magick");
function _withDoubleArray(array, func) {
    const length = array.length * 8;
    if (length === 0)
        return func(0);
    const instance = image_magick_1.ImageMagick._api._malloc(length);
    try {
        const buffer = new ArrayBuffer(length);
        const doubleArray = new Float64Array(buffer);
        for (let i = 0; i < array.length; i++)
            doubleArray[i] = array[i];
        image_magick_1.ImageMagick._api.HEAPU8.set(new Int8Array(buffer), instance);
        return func(instance);
    }
    finally {
        image_magick_1.ImageMagick._api._free(instance);
    }
}
exports._withDoubleArray = _withDoubleArray;
function _withQuantumArray(array, func) {
    const length = array.length * 8;
    if (length === 0)
        return func(0);
    const instance = image_magick_1.ImageMagick._api._malloc(length);
    try {
        image_magick_1.ImageMagick._api.HEAPU8.set(array, instance);
        return func(instance);
    }
    finally {
        image_magick_1.ImageMagick._api._free(instance);
    }
}
exports._withQuantumArray = _withQuantumArray;
