// Generated file. To retain edits, remove this comment.
import { InterfaceTypes, runPipelineNode } from 'itk-wasm';
import path from 'path';
import { fileURLToPath } from 'url';
/**
 * Apply a smoothing anti-alias filter and subsample the input image.
 *
 * @param {Image} input - Input image
 * @param {DownsampleNodeOptions} options - options object
 *
 * @returns {Promise<DownsampleNodeResult>} - result object
 */
async function downsampleNode(input, options = { shrinkFactors: [2, 2], }) {
    const desiredOutputs = [
        { type: InterfaceTypes.Image },
    ];
    const inputs = [
        { type: InterfaceTypes.Image, data: input },
    ];
    const args = [];
    // Inputs
    const inputName = '0';
    args.push(inputName);
    // Outputs
    const downsampledName = '0';
    args.push(downsampledName);
    // Options
    args.push('--memory-io');
    if (options.shrinkFactors) {
        if (options.shrinkFactors.length < 2) {
            throw new Error('"shrink-factors" option must have a length > 2');
        }
        args.push('--shrink-factors');
        options.shrinkFactors.forEach((value) => {
            args.push(value.toString());
        });
    }
    if (options.cropRadius) {
        if (options.cropRadius.length < 2) {
            throw new Error('"crop-radius" option must have a length > 2');
        }
        args.push('--crop-radius');
        options.cropRadius.forEach((value) => {
            args.push(value.toString());
        });
    }
    const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', 'downsample');
    const { returnValue, stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs);
    if (returnValue !== 0 && stderr !== "") {
        throw new Error(stderr);
    }
    const result = {
        downsampled: outputs[0]?.data,
    };
    return result;
}
export default downsampleNode;
//# sourceMappingURL=downsample-node.js.map