"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MagickReadSettings = void 0;
const image_magick_1 = require("../image-magick");
const magick_settings_1 = require("./magick-settings");
const magick_settings_2 = require("./magick-settings");
const string_1 = require("../internal/native/string");
class MagickReadSettings extends magick_settings_1.MagickSettings {
    constructor(partialSettings) {
        super();
        Object.assign(this, partialSettings);
    }
    static _createFrom(settings) {
        const result = new MagickReadSettings();
        result.format = settings.format;
        return result;
    }
    _use(func) {
        const settings = new magick_settings_2.NativeMagickSettings(this);
        try {
            const size = this.getSize();
            if (size !== '') {
                string_1._withString(size, sizePtr => {
                    image_magick_1.ImageMagick._api._MagickSettings_SetSize(settings._instance, sizePtr);
                });
            }
            return func(settings);
        }
        finally {
            settings.dispose();
        }
    }
    getSize() {
        if (this.width !== undefined && this.height !== undefined)
            return `${this.width}x${this.height}`;
        else if (this.width !== undefined)
            return `${this.width}x`;
        else if (this.height !== undefined)
            return `x${this.height}`;
        else
            return "";
    }
}
exports.MagickReadSettings = MagickReadSettings;
