import '../../../assert/js/assert.js';
import '../../../globals.js';
// Copyright 2023-2024, University of Colorado Boulder
/**
 * RenderProgram to convert linear sRGB => sRGB
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import Vector4 from '../../../dot/js/Vector4.js';
import { alpenglow, RenderColor, RenderColorSpaceConversion, RenderInstruction, RenderSRGBToLinearSRGB } from '../imports.js';
export default class RenderLinearSRGBToSRGB extends RenderColorSpaceConversion {
    constructor(program) {
        super(program, RenderColor.linearToSRGB);
    }
    getName() {
        return 'RenderLinearSRGBToSRGB';
    }
    withChildren(children) {
        assert && assert(children.length === 1);
        return new RenderLinearSRGBToSRGB(children[0]);
    }
    writeInstructions(instructions) {
        this.program.writeInstructions(instructions);
        instructions.push(RenderInstructionLinearSRGBToSRGB.INSTANCE);
    }
}
RenderLinearSRGBToSRGB.prototype.inverse = RenderSRGBToLinearSRGB;
RenderSRGBToLinearSRGB.prototype.inverse = RenderLinearSRGBToSRGB;
alpenglow.register('RenderLinearSRGBToSRGB', RenderLinearSRGBToSRGB);
const scratchVector = new Vector4(0, 0, 0, 0);
export class RenderInstructionLinearSRGBToSRGB extends RenderInstruction {
    toString() {
        return 'RenderInstructionLinearSRGBToSRGB()';
    }
    equals(other, areLocationsEqual) {
        return other instanceof RenderInstructionLinearSRGBToSRGB;
    }
    execute(stack, context, executor) {
        // https://entropymine.com/imageworsener/srgbformula/ (a more precise formula for sRGB)
        // Linear to sRGB
        // 0 ≤ L ≤ 0.00313066844250063 : S = L×12.92
        // 0.00313066844250063 < L ≤ 1 : S = 1.055×L^1/2.4 − 0.055
        stack.readTop(scratchVector);
        stack.writeTopValues(scratchVector.x <= 0.00313066844250063 ? scratchVector.x * 12.92 : 1.055 * Math.pow(scratchVector.x, 1 / 2.4) - 0.055, scratchVector.y <= 0.00313066844250063 ? scratchVector.y * 12.92 : 1.055 * Math.pow(scratchVector.y, 1 / 2.4) - 0.055, scratchVector.z <= 0.00313066844250063 ? scratchVector.z * 12.92 : 1.055 * Math.pow(scratchVector.z, 1 / 2.4) - 0.055, scratchVector.w);
    }
    writeBinary(encoder, getOffset) {
        encoder.pushU32(RenderInstruction.LinearSRGBToSRGBCode);
    }
    getBinaryLength() {
        return 1;
    }
}
RenderInstructionLinearSRGBToSRGB.INSTANCE = new RenderInstructionLinearSRGBToSRGB();
//# sourceMappingURL=RenderLinearSRGBToSRGB.js.map