UNPKG

node-libpng

Version:

Unofficial bindings for node to libpng.

49 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertGrayScaleToRGBA = exports.isColorGrayScale = exports.colorGrayScale = void 0; const rgba_1 = require("./rgba"); /** * Create a new color of type `ColorGrayScale`. * * @param gray The value for the `gray` part of the color. * * @return The color in gray scale representation. */ function colorGrayScale(gray) { const color = [gray]; Object.defineProperty(color, "gray", { get() { return this[0]; } }); return color; } exports.colorGrayScale = colorGrayScale; /** * Checks if the given parameter is a color of type `ColorGrayScale`. * * @param color The input to check. * * @return `true` if `color` was of type `ColorGrayScale` and `false` otherwise. */ function isColorGrayScale(color) { if (typeof color !== "object" || !Array.isArray(color)) { return false; } if (color.length !== 1) { return false; } if (typeof color.gray !== "number") { return false; } return true; } exports.isColorGrayScale = isColorGrayScale; /** * Converts a color of type `ColorGrayScale` to `ColorRGBA`. * * @param color The color to convert. * * @return The converted color in rgba format. */ function convertGrayScaleToRGBA(grayScaleAlpha) { return rgba_1.colorRGBA(grayScaleAlpha.gray, grayScaleAlpha.gray, grayScaleAlpha.gray, 255); } exports.convertGrayScaleToRGBA = convertGrayScaleToRGBA; //# sourceMappingURL=gray-scale.js.map