"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const ImageBitmap_1 = require("../../../../../wrap/ImageBitmap");
const _ids_1 = require("../../../../_ids");
class GrabFrame extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['camera', 'opt'],
            fo: ['image'],
            i: [],
            o: [],
        }, {
            input: {
                camera: {
                    ref: true,
                },
            },
            output: {
                image: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_GRAB_FRAME);
        this._err_flag = false;
        this.addListener('take_err', () => {
            if (this._err_flag) {
                this._err_flag = false;
                this._input.opt.pull();
            }
        });
    }
    async f({ camera, opt }, done, fail) {
        let _image;
        try {
            _image = await this._i.camera.grabFrame();
        }
        catch (err) {
            fail(err.message.toLowerCase());
            this._err_flag = true;
            return;
        }
        const image = (0, ImageBitmap_1.wrapImageBitmap)(_image, this.__system);
        done({ image });
    }
}
exports.default = GrabFrame;
//# sourceMappingURL=index.js.map