Java HSV Color to HSB HSVToRGB(float... hsv)

Here you can find the source of HSVToRGB(float... hsv)

Description

HSV To RGB

License

Open Source License

Declaration

public static float[] HSVToRGB(float... hsv) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

public class Main {
    public static float[] HSVToRGB(float... hsv) {
        assert (hsv.length >= 3);
        float h = hsv[0];
        if (h < 0f)
            h += 1f;/*from  w w w .  j ava2 s  . c  o m*/
        float s = Math.min(Math.max(hsv[1], 0f), 1f);
        float v = Math.min(Math.max(hsv[2], 0f), 1f);

        float[] color = new float[4];
        int i;
        float f, p, q, t;
        if (s == 0f) {
            color[0] = v;
            color[1] = v;
            color[2] = v;
            return color;
        }

        h *= 6f;
        i = (int) Math.floor(h);
        f = h - i;
        p = v * (1 - s);
        q = v * (1 - s * f);
        t = v * (1 - s * (1 - f));
        switch (i) {
        case 0:
            color[0] = v;
            color[1] = t;
            color[2] = p;
            break;
        case 1:
            color[0] = q;
            color[1] = v;
            color[2] = p;
            break;
        case 2:
            color[0] = p;
            color[1] = v;
            color[2] = t;
            break;
        case 3:
            color[0] = p;
            color[1] = q;
            color[2] = v;
            break;
        case 4:
            color[0] = t;
            color[1] = p;
            color[2] = v;
            break;
        default:
            color[0] = v;
            color[1] = p;
            color[2] = q;
            break;
        }
        return color;
    }
}

Related

  1. HSVtoRGB(float h, float s, float v, float[] result)
  2. hsvToRgb(float h, float s, float v, int[] rgb)
  3. hsvToRGB(float hue, float saturation, float value)
  4. hsvToRgb(float hue, float saturation, float value)
  5. hsvToRGB(float p_181758_0_, float p_181758_1_, float p_181758_2_)
  6. HSVtoRGB(float[] hsv, float[] rgb)
  7. hsvToRgb(int hue, int saturation, int value)