Java HSV Color to HSB hsvToRgb(double[] hsv)

Here you can find the source of hsvToRgb(double[] hsv)

Description

Converts an HSV color value [0-1] to RGB [0-255].

License

Open Source License

Parameter

Parameter Description
v The value

Return

Array The RGB representation

Declaration

public static int[] hsvToRgb(double[] hsv) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w w w .  j a v a 2 s.c o  m
     * Converts an HSV color value [0-1] to RGB [0-255]. 
     *
     * @param   Number  h       The hue
     * @param   Number  s       The saturation
     * @param   Number  v       The value
     * @return  Array           The RGB representation
     */
    public static int[] hsvToRgb(double[] hsv) {
        double r = 0.0;
        double g = 0.0;
        double b = 0.0;

        double i = Math.floor(hsv[0] * 6.0);
        double f = hsv[0] * 6.0 - i;
        double p = hsv[2] * (1.0 - hsv[1]);
        double q = hsv[2] * (1.0 - f * hsv[1]);
        double t = hsv[2] * (1.0 - (1 - f) * hsv[1]);

        double c = i % 6;

        if (c == 0) {
            r = hsv[2];
            g = t;
            b = p;
        } else if (c == 1) {
            r = q;
            g = hsv[2];
            b = p;
        } else if (c == 2) {
            r = p;
            g = hsv[2];
            b = t;
        } else if (c == 3) {
            r = p;
            g = q;
            b = hsv[2];
        } else if (c == 4) {
            r = t;
            g = p;
            b = hsv[2];
        } else if (c == 5) {
            r = hsv[2];
            g = p;
            b = q;
        }

        return new int[] { (int) (r * 255.0), (int) (g * 255.0), (int) (b * 255.0) };
    }
}

Related

  1. hsv2rgb_hex(float h, float s, float v)
  2. hsva(double hue, double saturation, double value, double alpha)
  3. HSVToColor(float[] hsv)
  4. hsvToRgb(double hue, double saturation, double value)
  5. HSVtoRGB(double hue, double saturation, double value)
  6. HSVtoRGB(float h, float s, float v)
  7. HSVtoRGB(float h, float s, float v, float[] result)
  8. hsvToRgb(float h, float s, float v, int[] rgb)
  9. hsvToRGB(float hue, float saturation, float value)