"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Rendering
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColorMap = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const core_common_1 = require("@itwin/core-common");
/** @internal */
class ColorMap extends core_bentley_1.IndexMap {
    _hasTransparency = false;
    constructor() { super(core_bentley_1.compareNumbers, 0xffff); }
    hasColor(color) { return -1 !== this.indexOf(color); }
    insert(color) {
        // The table should never contain a mix of opaque and translucent colors.
        if (this.isEmpty)
            this._hasTransparency = ColorMap.isTranslucent(color);
        else
            (0, core_bentley_1.assert)(ColorMap.isTranslucent(color) === this.hasTransparency);
        return super.insert(color);
    }
    get hasTransparency() { return this._hasTransparency; }
    get isUniform() { return 1 === this.length; }
    toColorIndex(index, indices) {
        index.reset();
        if (0 === this.length) {
            (0, core_bentley_1.assert)(false, "empty color map");
            return;
        }
        else if (1 === this.length) {
            index.initUniform(this._array[0].value);
        }
        else {
            const colors = new Uint32Array(this.length);
            for (const entry of this._array)
                colors[entry.index] = entry.value;
            index.initNonUniform(colors, indices, this.hasTransparency);
        }
    }
    static isTranslucent(tbgr) {
        return !core_common_1.ColorDef.isOpaque(tbgr);
    }
}
exports.ColorMap = ColorMap;
//# sourceMappingURL=ColorMap.js.map