/**
 * Converts a color represented as an array of numbers (either RGB or RGBA) with 8-bit channel values (0-255)
 * into a normalized RGBA tuple with values in the range [0, 1].
 *
 * @param color - The input color as an array of numbers. It can be either:
 *   - [r, g, b]: An RGB color, where each channel is a number between 0 and 255.
 *   - [r, g, b, a]: An RGBA color, where each channel is a number between 0 and 255.
 *   - undefined
 * @returns A tuple [r, g, b, a] where each value is normalized to the range [0, 1] or undefined.
 */
export function toNormalizedColor(color) {
    return color
        ? [
            color[0] / 255,
            color[1] / 255,
            color[2] / 255,
            color.length === 3 ? 1 : color[3] / 255,
        ]
        : undefined;
}
/**
 * Converts a color represented as an array of numbers (either RGB or RGBA) with 8-bit channel values (0-255)
 * into a normalized RGBA tuple with values in the range [0, 1].
 *
 * @param color - The input color as an array of numbers. It can be either:
 *   - [r, g, b]: An RGB color, where each channel is a number between 0 and 255.
 *   - [r, g, b, a]: An RGBA color, where each channel is a number between 0 and 255.
 * @returns A tuple [r, g, b, a] where each value is normalized to the range [0, 1].
 */
export function toNormalizedRGBAColor(color) {
    return [
        color[0] / 255,
        color[1] / 255,
        color[2] / 255,
        color.length === 3 ? 1 : color[3] / 255,
    ];
}
/**
 * Converts a color represented as an array of numbers (either RGB or RGBA) with 8-bit channel values (0-255)
 * into a normalized RGB tuple with values in the range [0, 1].
 *
 * @param color - The input color as an array of numbers. It can be either:
 *   - [r, g, b]: An RGB color, where each channel is a number between 0 and 255.
 *   - [r, g, b, a]: An RGBA color, where each channel is a number between 0 and 255.
 * @returns A tuple [r, g, b] where each value is normalized to the range [0, 1].
 */
export function toNormalizedRGBColor(color) {
    return [color[0] / 255, color[1] / 255, color[2] / 255];
}
/**
 * Blends two color arrays together, following an additive blending pattern.
 * @param baseColor The underlying color.
 * @param addedColor The color to add on top. If this color has no opacity, the base color is fully overwritten
 * @returns The blended color as an RGBA array
 */
export function blendColors(baseColor, addedColor) {
    var _a, _b;
    const alpha1 = ((_a = baseColor[3]) !== null && _a !== void 0 ? _a : 255) / 255;
    const alpha2 = ((_b = addedColor[3]) !== null && _b !== void 0 ? _b : 255) / 255;
    const mixedAlpha = 1 - (1 - alpha2) * (1 - alpha1);
    if (mixedAlpha === 0)
        return [0, 0, 0, 0];
    const mixChannel = (channel) => {
        const channel1Res = addedColor[channel] * alpha2 +
            baseColor[channel] * alpha1 * (1 - alpha2);
        return Math.round(channel1Res / mixedAlpha);
    };
    return [mixChannel(0), mixChannel(1), mixChannel(2), mixedAlpha * 255];
}
/**
 * Converts a `Color` object to an array representation.
 *
 * @param color - The color value to convert, expected to be an iterable (e.g., TypedArray or array-like) representing a color.
 * @returns The color as an array of numbers, typed as either `RGBColor` or `RGBAColor`.
 */
export function toArrayColor(color) {
    return Array.from(color);
}
//# sourceMappingURL=Color.js.map