"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const ImageData_1 = require("../../../../../wrap/ImageData");
const _ids_1 = require("../../../../_ids");
class GetImageData extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['canvas', 'x', 'y', 'width', 'height', 'opt', 'any'],
            fo: ['image'],
        }, {
            input: {
                canvas: {
                    ref: true,
                },
            },
            output: {
                image: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_GET_IMAGE_DATA);
    }
    async f({ canvas, x, y, width, height, opt }, done, fail) {
        let imageData;
        try {
            imageData = await canvas.getImageData(x, y, width, height, opt);
        }
        catch (err) {
            if (err instanceof RangeError) {
                fail('out of memory');
                return;
            }
            fail(err.message);
            return;
        }
        const image = (0, ImageData_1.wrapImageData)(imageData, this.__system);
        done({
            image,
        });
    }
}
exports.default = GetImageData;
//# sourceMappingURL=index.js.map