UNPKG

897 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.rgb2hsv = void 0;
4var consts_1 = require("./consts");
5/** Converts RGB components to an HSV color. */
6function rgb2hsv(r, g, b) {
7 var h = NaN;
8 var max = Math.max(r, g, b);
9 var min = Math.min(r, g, b);
10 var delta = max - min;
11 // hue
12 if (delta === 0) {
13 h = 0;
14 }
15 else if (r === max) {
16 h = ((g - b) / delta) % 6;
17 }
18 else if (g === max) {
19 h = (b - r) / delta + 2;
20 }
21 else if (b === max) {
22 h = (r - g) / delta + 4;
23 }
24 h = Math.round(h * 60);
25 if (h < 0) {
26 h += 360;
27 }
28 // saturation
29 var s = Math.round((max === 0 ? 0 : delta / max) * 100);
30 // value
31 var v = Math.round((max / consts_1.MAX_COLOR_RGB) * 100);
32 return { h: h, s: s, v: v };
33}
34exports.rgb2hsv = rgb2hsv;
35//# sourceMappingURL=rgb2hsv.js.map
\No newline at end of file