UNPKG

node-libpng

Version:

Unofficial bindings for node to libpng.

53 lines 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertPaletteToRGBA = exports.isColorPalette = exports.colorPalette = void 0; const rgb_1 = require("./rgb"); /** * Create a new color of type `ColorPalette`. * * @param index The value for the index on the palette. * * @return The color in palette representation. */ function colorPalette(index) { const color = [index]; Object.defineProperty(color, "index", { get() { return this[0]; } }); return color; } exports.colorPalette = colorPalette; /** * Checks if the given parameter is a color of type `ColorPalette`. * * @param color The input to check. * * @return `true` if `color` was of type `ColorPalette` and `false` otherwise. */ function isColorPalette(color) { if (typeof color !== "object" || !Array.isArray(color)) { return false; } if (color.length !== 1) { return false; } if (typeof color.index !== "number") { return false; } return true; } exports.isColorPalette = isColorPalette; /** * Converts a color of type `ColorPalette` to `ColorRGBA`. * * @param color The color to convert. * @param palette The palette of the image the color originated from. Used to lookup the color. * * @return The converted color in rgba format. */ function convertPaletteToRGBA(color, palette) { if (!palette.has(color.index)) { return; } return rgb_1.convertRGBToRGBA(palette.get(color.index)); } exports.convertPaletteToRGBA = convertPaletteToRGBA; //# sourceMappingURL=palette.js.map