UNPKG

imagerot

Version:

A lightweight, cross-environment image library for applying unique effects via raw image buffers.

27 lines (26 loc) 708 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rgbToHsv = void 0; const rgbToHsv = (r, g, b) => { r /= 255, g /= 255, b /= 255; let max = Math.max(r, g, b), min = Math.min(r, g, b); let h = 0, v = max; let d = max - min; let s = max === 0 ? 0 : d / max; if (max !== min) { switch (max) { case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; } h /= 6; } return [h, s || 0, v || 0]; }; exports.rgbToHsv = rgbToHsv;