`rgbToHsv` Converts an RGB color value to HSV *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1] *Returns:* { h, s, v } in [0,1]
179914
function rgbToHsv(r, g, b) {

    r = bound01(r, 255);
    g = bound01(g, 255);
    b = bound01(b, 255);

    var max = mathMax(r, g, b), min = mathMin(r, g, b);
    var h, s, v = max;

    var d = max - min;
    s = max === 0 ? 0 : d / max;

    if(max == min) {
        h = 0; // achromatic
    }
    else {
        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: h, s: s, v: v };
}
1086202
def rgb2hex(rgb):
    
    if len(rgb) > 3:
        rgb = rgb[:-1]
    return "#{0:02x}{1:02x}{2:02x}".format(*(int(v*255) for v in rgb))
957469
function HSVA_TO_RGBA() {
        var h = this.h();
        var s = this.s();
        var v = this.v();
        var a = this.a();
        var hi = Math.floor(h / 60);
        var f = h / 60 - hi;
        var p = v * (1 - s);
        var q = v * (1 - f * s);
        var t = v * (1 - (1 - f) * s);
        var rgba;

        switch (hi) {
            case 0:
                rgba = [v, t, p, a]; break;
            case 1:
                rgba = [q, v, p, a]; break;
            case 2:
                rgba = [p, v, t, a]; break;
            case 3:
                rgba = [p, q, v, a]; break;
            case 4:
                rgba = [t, p, v, a]; break;
            case 5:
                rgba = [v, p, q, a]; break;
            default:
                rgba = [0, 0, 0, a];
        }

        for (var i = rgba.length - 1; i--;) {
            rgba[i] *= 255;
        }

        return kolor.rgba(rgba);
    }
663503
public static function hsv2rgb( $hsv )
	{
		list( $h, $s, $v ) = $hsv;
		$rgb = array();
		$h	= $h / 60;
		$s	= $s / 100;
		$v	= $v / 100;
		if( $s == 0 )
		{
			$rgb[0]	= $v * 255;
			$rgb[1]	= $v * 255;
			$rgb[2]	= $v * 255;
		}
		else
		{
			$rgb_dec = array();
			$i	= floor( $h );
			$p	= $v * ( 1 - $s );
			$q	= $v * ( 1 - $s * ( $h - $i ) );
			$t	= $v * ( 1 - $s * ( 1 - ( $h - $i ) ) );
			switch( $i )
			{
				case 0:
				$rgb_dec[0]	= $v;
				$rgb_dec[1]	= $t;
				$rgb_dec[2]	= $p;
				break;
				case 1:
				$rgb_dec[0]	= $q;
				$rgb_dec[1]	= $v;
				$rgb_dec[2]	= $p;
				break;
				case 2:
				$rgb_dec[0]	= $p;
				$rgb_dec[1]	= $v;
				$rgb_dec[2]	= $t;
				break;
				case 3:
				$rgb_dec[0]	= $p;
				$rgb_dec[1]	= $q;
				$rgb_dec[2]	= $v;
				break;
				case 4:
				$rgb_dec[0]	= $t;
				$rgb_dec[1]	= $p;
				$rgb_dec[2]	= $v;
				break;
				case 5:
				$rgb_dec[0]	= $v;
				$rgb_dec[1]	= $p;
				$rgb_dec[2]	= $q;
				break;
				case 6:
				$rgb_dec[0]	= $v;
				$rgb_dec[1]	= $p;
				$rgb_dec[2]	= $q;
				break;
			}
			$rgb[0]	= round( $rgb_dec[0] * 255 );
			$rgb[1]	= round( $rgb_dec[1] * 255 );
			$rgb[2]	= round( $rgb_dec[2] * 255 );
		}
		return $rgb;
	}
1165974
public static void rgbToHsv_F32(Planar<GrayF32> rgb , Planar<GrayF32> hsv ) {
		GrayF32 R = rgb.getBand(0);
		GrayF32 G = rgb.getBand(1);
		GrayF32 B = rgb.getBand(2);

		GrayF32 H = hsv.getBand(0);
		GrayF32 S = hsv.getBand(1);
		GrayF32 V = hsv.getBand(2);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0,hsv.height,row->{
		for( int row = 0; row < hsv.height; row++ ) {
			int indexRgb = rgb.startIndex + row*rgb.stride;
			int indexHsv = hsv.startIndex + row*hsv.stride;
			int endRgb = indexRgb+hsv.width;

			for( ; indexRgb < endRgb; indexHsv++ , indexRgb++) {

				float r = R.data[indexRgb];
				float g = G.data[indexRgb];
				float b = B.data[indexRgb];

				float max = r > g ? ( r > b ? r : b) : ( g > b ? g : b );
				float min = r < g ? ( r < b ? r : b) : ( g < b ? g : b );

				float delta = max - min;

				V.data[indexHsv] = max;

				if( max != 0 )
					S.data[indexHsv] = delta / max;
				else {
					H.data[indexHsv] = Float.NaN;
					S.data[indexHsv] = 0;
					continue;
				}

				float h;
				if( r == max )
					h = ( g - b ) / delta;
				else if( g == max )
					h = 2 + ( b - r ) / delta;
				else
					h = 4 + ( r - g ) / delta;

				h *= d60_F32;
				if( h < 0 )
					h += PI2_F32;

				H.data[indexHsv] = h;
			}
		}
		//CONCURRENT_ABOVE });
	}
134843
def hex_to_hsv(color):
    
    color = normalize(color)
    color = color[1:]
    # color=tuple(ord(c)/255.0 for c in color.decode('hex'))
    color = (int(color[0:2], base=16) / 255.0, int(color[2:4],
                                                   base=16) / 255.0, int(color[4:6], base=16) / 255.0)
    return colorsys.rgb_to_hsv(*color)
1001480
def convertColor(value):
    
    s = value

    if s in colors:
        s = colors[s]

    rgbpMatch = rgbp.match(s)
    if rgbpMatch is not None:
        r = int(float(rgbpMatch.group(1)) * 255.0 / 100.0)
        g = int(float(rgbpMatch.group(2)) * 255.0 / 100.0)
        b = int(float(rgbpMatch.group(3)) * 255.0 / 100.0)
        s = '#%02x%02x%02x' % (r, g, b)
    else:
        rgbMatch = rgb.match(s)
        if rgbMatch is not None:
            r = int(rgbMatch.group(1))
            g = int(rgbMatch.group(2))
            b = int(rgbMatch.group(3))
            s = '#%02x%02x%02x' % (r, g, b)

    if s[0] == '#':
        s = s.lower()
        if len(s) == 7 and s[1] == s[2] and s[3] == s[4] and s[5] == s[6]:
            s = '#' + s[1] + s[3] + s[5]

    return s
279484
def hsl_to_rgb(self, h, s, l):
        

        h = h % 1.0
        s = min(max(s, 0.0), 1.0)
        l = min(max(l, 0.0), 1.0)

        if l <= 0.5:
            m2 = l*(s + 1.0)
        else:
            m2 = l + s - l*s
        m1 = l*2.0 - m2
        r = self._hue_to_rgb(m1, m2, h + 1.0/3.0)
        g = self._hue_to_rgb(m1, m2, h)
        b = self._hue_to_rgb(m1, m2, h - 1.0/3.0)

        # Apply gamma correction
        r **= self.gamma
        g **= self.gamma
        b **= self.gamma

        return (r, g, b)
616459
def from_hsv(cls, h, s, v):
        """"""
        rgb = colorsys.hsv_to_rgb(h, s, v)
        return cls.from_rgb(*(int(x * 255) for x in rgb))
943202
public static int[] RGBtoHSV (Color c) {
		return RGBtoHSV(c.r, c.g, c.b);
	}
364615
public static float[] getHSVArray(int r, int g, int b) {
        float[] hsv = new float[3];

        float rf = r / MAX;
        float gf = g / MAX;
        float bf = b / MAX;

        float minRGB = Math.min(rf, Math.min(gf, bf));
        float maxRGB = Math.max(rf, Math.max(gf, bf));

        float computedH = 0;
        float computedS = 0;
        float computedV = minRGB;

        // Black-gray-white
        if (minRGB != maxRGB) {
            // Colors other than black-gray-white:
            float d = (rf == minRGB) ? gf - bf : ((bf == minRGB) ? rf - gf : bf - rf);
            float h = (rf == minRGB) ? 3 : ((bf == minRGB) ? 1 : 5);
            computedH = 60 * (h - d / (maxRGB - minRGB));
            computedS = (maxRGB - minRGB) / maxRGB;
            computedV = maxRGB;
        }

        hsv[0] = computedH;
        hsv[1] = computedS;
        hsv[2] = computedV;
        return hsv;
    }
847659
public static Color HSVtoRGB (float h, float s, float v, Color targetColor) {
		if (h == 360) h = 359;
		int r, g, b;
		int i;
		float f, p, q, t;
		h = (float) Math.max(0.0, Math.min(360.0, h));
		s = (float) Math.max(0.0, Math.min(100.0, s));
		v = (float) Math.max(0.0, Math.min(100.0, v));
		s /= 100;
		v /= 100;
		h /= 60;
		i = MathUtils.floor(h);
		f = h - i;
		p = v * (1 - s);
		q = v * (1 - s * f);
		t = v * (1 - s * (1 - f));
		switch (i) {
			case 0:
				r = MathUtils.round(255 * v);
				g = MathUtils.round(255 * t);
				b = MathUtils.round(255 * p);
				break;
			case 1:
				r = MathUtils.round(255 * q);
				g = MathUtils.round(255 * v);
				b = MathUtils.round(255 * p);
				break;
			case 2:
				r = MathUtils.round(255 * p);
				g = MathUtils.round(255 * v);
				b = MathUtils.round(255 * t);
				break;
			case 3:
				r = MathUtils.round(255 * p);
				g = MathUtils.round(255 * q);
				b = MathUtils.round(255 * v);
				break;
			case 4:
				r = MathUtils.round(255 * t);
				g = MathUtils.round(255 * p);
				b = MathUtils.round(255 * v);
				break;
			default:
				r = MathUtils.round(255 * v);
				g = MathUtils.round(255 * p);
				b = MathUtils.round(255 * q);
		}

		targetColor.set(r / 255.0f, g / 255.0f, b / 255.0f, targetColor.a);
		return targetColor;
	}
1117470
def RGB_to_HSV(cobj, *args, **kwargs):
    
    var_R = cobj.rgb_r
    var_G = cobj.rgb_g
    var_B = cobj.rgb_b

    var_max = max(var_R, var_G, var_B)
    var_min = min(var_R, var_G, var_B)

    var_H = __RGB_to_Hue(var_R, var_G, var_B, var_min, var_max)

    if var_max == 0:
        var_S = 0
    else:
        var_S = 1.0 - (var_min / var_max)

    var_V = var_max

    return HSVColor(
        var_H, var_S, var_V)
77585
def rgb(self):
        
        coords = tuple(self.dimension_values(d, expanded=False)
                       for d in self.kdims)
        data = [self.dimension_values(d, flat=False)
                for d in self.vdims]

        hsv = self.hsv_to_rgb(*data[:3])
        if len(self.vdims) == 4:
            hsv += (data[3],)

        params = util.get_param_values(self)
        del params['vdims']
        return RGB(coords+hsv, bounds=self.bounds,
                   xdensity=self.xdensity, ydensity=self.ydensity,
                   **params)
938887
def hsv(h, s, v):
    """"""
    if 360 < h < 0:
        raise ValueError("h out of range: {}".format(h))
    if 1 < s < 0:
        raise ValueError("s out of range: {}".format(h))
    if 1 < v < 0:
        raise ValueError("v out of range: {}".format(h))
    c = v * s  # chroma
    h1 = h / 60
    x = c * (1 - abs(h1 % 2 - 1))
    if 0 <= h1 < 1:
        r1, g1, b1 = (c, x, 0)
    elif 1 <= h1 < 2:
        r1, g1, b1 = (x, c, 0)
    elif 2 <= h1 < 3:
        r1, g1, b1 = (0, c, x)
    elif 3 <= h1 < 4:
        r1, g1, b1 = (0, x, c)
    elif 4 <= h1 < 5:
        r1, g1, b1 = (x, 0, c)
    elif 5 <= h1 < 6:
        r1, g1, b1 = (c, 0, x)
    m = v - c
    r, g, b = r1 + m, g1 + m, b1 + m
    return int(r * 255), int(g * 255), int(b * 255)
385612
def Point2HexColor(a, lfrac, tfrac):
    

    [H,S,V] = [math.floor(360 * a), lfrac, tfrac]

    RGB = hsvToRGB(H, S, V)

    H = [hex(int(math.floor(255 * x))) for x in RGB]

    HEX = [a[a.find('x') + 1:] for a in H]
    HEX = ['0' + h if len(h) == 1 else h for h in HEX]

    return '#' + ''.join(HEX)
78471
def _hsla(h, s, l, a, **kwargs):
    
    res = colorsys.hls_to_rgb(float(h), float(l), float(s))
    return ColorValue([x * 255.0 for x in res] + [float(a)])