import '../../../assert/js/assert.js';
import '../../../globals.js';
// Copyright 2023-2024, University of Colorado Boulder
/**
 * RenderProgram to unpremultiply the input color
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import Vector4 from '../../../dot/js/Vector4.js';
import { alpenglow, RenderColor, RenderColorSpaceConversion, RenderInstruction, RenderPremultiply } from '../imports.js';
export default class RenderUnpremultiply extends RenderColorSpaceConversion {
    constructor(program) {
        super(program, RenderColor.unpremultiply);
    }
    getName() {
        return 'RenderUnpremultiply';
    }
    withChildren(children) {
        assert && assert(children.length === 1);
        return new RenderUnpremultiply(children[0]);
    }
    writeInstructions(instructions) {
        this.program.writeInstructions(instructions);
        instructions.push(RenderInstructionUnpremultiply.INSTANCE);
    }
}
RenderPremultiply.prototype.inverse = RenderUnpremultiply;
RenderUnpremultiply.prototype.inverse = RenderPremultiply;
alpenglow.register('RenderUnpremultiply', RenderUnpremultiply);
const scratchVector = new Vector4(0, 0, 0, 0);
export class RenderInstructionUnpremultiply extends RenderInstruction {
    toString() {
        return 'RenderInstructionUnpremultiply()';
    }
    equals(other, areLocationsEqual) {
        return other instanceof RenderInstructionUnpremultiply;
    }
    execute(stack, context, executor) {
        stack.readTop(scratchVector);
        const alpha = scratchVector.w;
        if (alpha === 0) {
            stack.writeTop(Vector4.ZERO);
        }
        else {
            stack.writeTopValues(scratchVector.x / alpha, scratchVector.y / alpha, scratchVector.z / alpha, alpha);
        }
    }
    writeBinary(encoder, getOffset) {
        encoder.pushU32(RenderInstruction.UnpremultiplyCode);
    }
    getBinaryLength() {
        return 1;
    }
}
RenderInstructionUnpremultiply.INSTANCE = new RenderInstructionUnpremultiply();
//# sourceMappingURL=RenderUnpremultiply.js.map