1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.rgb2hsv = void 0;
|
4 | var consts_1 = require("./consts");
|
5 |
|
6 | function 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 |
|
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 |
|
29 | var s = Math.round((max === 0 ? 0 : delta / max) * 100);
|
30 |
|
31 | var v = Math.round((max / consts_1.MAX_COLOR_RGB) * 100);
|
32 | return { h: h, s: s, v: v };
|
33 | }
|
34 | exports.rgb2hsv = rgb2hsv;
|
35 |
|
\ | No newline at end of file |