"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../../Class/Functional");
const ImageBitmap_1 = require("../../../../../../wrap/ImageBitmap");
const _ids_1 = require("../../../../../_ids");
class ImageToBitmap extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['opt', 'image', 'rect'],
            o: ['bitmap'],
        }, {
            input: {
                image: {
                    ref: true,
                },
            },
            output: {
                bitmap: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_IMAGE_TO_BITMAP);
    }
    async f({ opt, rect, image }, done) {
        const { api: { media: { image: { createImageBitmap }, }, }, } = this.__system;
        const _image = await image.image();
        let _bitmap;
        try {
            _bitmap = await createImageBitmap(_image, rect, opt);
        }
        catch (err) {
            done(undefined, err.message);
            return;
        }
        const bitmap = (0, ImageBitmap_1.wrapImageBitmap)(_bitmap, this.__system);
        done({
            bitmap,
        });
    }
}
exports.default = ImageToBitmap;
//# sourceMappingURL=index.js.map