import { BloomPass } from "./BloomPass.js";
import { ColorGradingPass } from "./ColorGradingPass.js";
import { FXAAPass } from "./FXAAPass.js";
import { createProductionPostProcessInput } from "./ProductionPostProcessTypes.js";
export class ProductionEffectComposer {
    options;
    enabled;
    passes;
    constructor(options = {}) {
        this.options = options;
        this.enabled = options.enabled ?? true;
        const intensity = options.intensity ?? 1;
        this.passes = [...(options.passes ?? [
                new ColorGradingPass({ intensity }),
                new BloomPass({ intensity: 0.32 * intensity, threshold: 0.62, radius: 2 }),
                new FXAAPass({ subpixelBlend: 0.65 })
            ])];
    }
    addPass(pass) {
        this.passes.push(pass);
        return this;
    }
    render(inputOrPixels, width, height, options = {}) {
        const input = inputOrPixels instanceof Uint8Array
            ? createProductionPostProcessInput(inputOrPixels, requireDimension(width, "width"), requireDimension(height, "height"), options)
            : inputOrPixels;
        if (!this.enabled) {
            return { ...input, passOutputs: [], totalChangedPixels: 0, diagnostics: ["ProductionEffectComposer disabled; source pixels returned unchanged."] };
        }
        const passOutputs = [];
        let current = input;
        for (const pass of this.passes) {
            if (!pass.enabled)
                continue;
            const output = pass.apply(current);
            passOutputs.push(output);
            current = output;
        }
        return {
            ...current,
            passOutputs,
            totalChangedPixels: passOutputs.reduce((sum, output) => sum + output.changedPixels, 0),
            diagnostics: passOutputs.flatMap((output) => output.diagnostics)
        };
    }
}
function requireDimension(value, label) {
    if (value === undefined || !Number.isInteger(value) || value <= 0) {
        throw new Error(`ProductionEffectComposer ${label} must be a positive integer when rendering raw pixels.`);
    }
    return value;
}
//# sourceMappingURL=ProductionEffectComposer.js.map