Java HSV Color to HSB hsvToRGB(float p_181758_0_, float p_181758_1_, float p_181758_2_)

Here you can find the source of hsvToRGB(float p_181758_0_, float p_181758_1_, float p_181758_2_)

Description

hsv To RGB

License

Open Source License

Declaration

public static int hsvToRGB(float p_181758_0_, float p_181758_1_, float p_181758_2_) 

Method Source Code

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

public class Main {
    public static int hsvToRGB(float p_181758_0_, float p_181758_1_, float p_181758_2_) {
        int i = (int) (p_181758_0_ * 6.0F) % 6;
        float f = p_181758_0_ * 6.0F - (float) i;
        float f1 = p_181758_2_ * (1.0F - p_181758_1_);
        float f2 = p_181758_2_ * (1.0F - f * p_181758_1_);
        float f3 = p_181758_2_ * (1.0F - (1.0F - f) * p_181758_1_);
        float f4;
        float f5;
        float f6;

        switch (i) {
        case 0:/*from   w  w  w.  j a v  a 2  s . c o m*/
            f4 = p_181758_2_;
            f5 = f3;
            f6 = f1;
            break;

        case 1:
            f4 = f2;
            f5 = p_181758_2_;
            f6 = f1;
            break;

        case 2:
            f4 = f1;
            f5 = p_181758_2_;
            f6 = f3;
            break;

        case 3:
            f4 = f1;
            f5 = f2;
            f6 = p_181758_2_;
            break;

        case 4:
            f4 = f3;
            f5 = f1;
            f6 = p_181758_2_;
            break;

        case 5:
            f4 = p_181758_2_;
            f5 = f1;
            f6 = f2;
            break;

        default:
            throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was "
                    + p_181758_0_ + ", " + p_181758_1_ + ", " + p_181758_2_);
        }

        int j = clamp_int((int) (f4 * 255.0F), 0, 255);
        int k = clamp_int((int) (f5 * 255.0F), 0, 255);
        int l = clamp_int((int) (f6 * 255.0F), 0, 255);
        return j << 16 | k << 8 | l;
    }

    /**
     * Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and
     * third parameters.
     */
    public static int clamp_int(int num, int min, int max) {
        return num < min ? min : (num > max ? max : num);
    }
}

Related

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