import { fxaaPixels } from "../../PostProcessPass.js";
import { createProductionPostProcessOutput } from "./ProductionPostProcessTypes.js";
export class FXAAPass {
    options;
    name = "production-fxaa";
    enabled;
    lastResult = null;
    constructor(options = {}) {
        this.options = options;
        this.enabled = options.enabled ?? true;
    }
    apply(input) {
        const result = fxaaPixels(input.pixels, input.width, input.height, {
            edgeThreshold: this.enabled ? this.options.edgeThreshold ?? 0.08 : 1,
            subpixelBlend: this.enabled ? this.options.subpixelBlend ?? this.options.intensity ?? 0.68 : 0
        });
        this.lastResult = result;
        return createProductionPostProcessOutput(input, this.name, result.pixels, {
            edgePixels: countNonZero(result.edgeMask)
        }, ["FXAAPass applies the renderer FXAA pixel kernel and mutates image pixels, not only options metadata."]);
    }
    getLastResult() {
        return this.lastResult
            ? {
                ...this.lastResult,
                pixels: new Uint8Array(this.lastResult.pixels),
                edgeMask: new Uint8Array(this.lastResult.edgeMask)
            }
            : null;
    }
}
function countNonZero(values) {
    let count = 0;
    for (const value of values)
        if (value > 0)
            count += 1;
    return count;
}
//# sourceMappingURL=FXAAPass.js.map