"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MagickImageCollection = void 0;
const image_magick_1 = require("./image-magick");
const magick_image_1 = require("./magick-image");
class MagickImageCollection extends Array {
    constructor() {
        super();
    }
    dispose() {
        let image = this.pop();
        while (image !== undefined) {
            image.dispose();
            image = this.pop();
        }
    }
    static create() {
        return Object.create(MagickImageCollection.prototype);
    }
    static _createFromImages(images, settings) {
        const collection = MagickImageCollection.create();
        let image = images;
        while (image !== 0) {
            const next = image_magick_1.ImageMagick._api._MagickImage_GetNext(image);
            image_magick_1.ImageMagick._api._MagickImage_SetNext(image, 0);
            collection.push(magick_image_1.MagickImage._createFromImage(image, settings));
            image = next;
        }
        return collection;
    }
    _use(func) {
        try {
            return func(this);
        }
        finally {
            this.dispose();
        }
    }
}
exports.MagickImageCollection = MagickImageCollection;
