Here you can find the source of RGBtoHSV(double r, double g, double b)
Parameter | Description |
---|---|
r | value is from 0 to 1 |
g | value is from 0 to 1 |
b | value is from 0 to 1 |
public static double[] RGBtoHSV(double r, double g, double b)
//package com.java2s; /*/*from ww w.ja v a 2s . co m*/ * ColorUtils.java * * Created by DFKI AV on 01.01.2012. * Copyright (c) 2011-2012 DFKI GmbH, Kaiserslautern. All rights reserved. * Use is subject to license terms. */ public class Main { /** * Calculates the HSV color value for a given RGB value. The return values * are h = [0,360], s = [0,1], v = [0,1]. If s == 0, then h = -1 (undefined) * * @param r value is from 0 to 1 * @param g value is from 0 to 1 * @param b value is from 0 to 1 * @return the calculated hsv value to return. */ public static double[] RGBtoHSV(double r, double g, double b) { double h, s, v; double min, max, delta; min = Math.min(Math.min(r, g), b); max = Math.max(Math.max(r, g), b); // V v = max; delta = max - min; // S if (max != 0) { s = delta / max; } else { s = 0; h = -1; return new double[] { h, s, v }; } // H if (r == max) { h = (g - b) / delta; // between yellow & magenta } else if (g == max) { h = 2 + (b - r) / delta; // between cyan & yellow } else { h = 4 + (r - g) / delta; // between magenta & cyan } h *= 60; // degrees if (h < 0) { h += 360; } return new double[] { h, s, v }; } }