Java HSV Color to HSB hsvToRgb(float h, float s, float v, int[] rgb)

Here you can find the source of hsvToRgb(float h, float s, float v, int[] rgb)

Description

hsv To Rgb

License

Open Source License

Declaration

public static void hsvToRgb(float h, float s, float v, int[] rgb) 

Method Source Code

//package com.java2s;
/*/*  ww w . j  a va 2  s .  c  om*/
  ColorMapUtils.java
    
  (c) 2011-2013 Edward Swartz
    
  All rights reserved. This program and the accompanying materials
  are made available under the terms of the Eclipse Public License v1.0
  which accompanies this distribution, and is available at
  http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    public static void hsvToRgb(float h, float s, float v, int[] rgb) {
        float c = (Math.max(0f, Math.min(360f, v) / 256)) * Math.max(0f, Math.min(1f, s));
        float hprime = (Math.max(0f, Math.min(256f, h)) / 60);
        float x = c * (1 - Math.abs(hprime % 2 - 1));

        float fr, fg, fb;
        switch ((int) hprime) {
        case 0:
            fr = c;
            fg = x;
            fb = 0;
            break;
        case 1:
            fr = x;
            fg = c;
            fb = 0;
            break;
        case 2:
            fr = 0;
            fg = c;
            fb = x;
            break;
        case 3:
            fr = 0;
            fg = x;
            fb = c;
            break;
        case 4:
            fr = x;
            fg = 0;
            fb = c;
            break;
        case 5:
            fr = c;
            fg = 0;
            fb = x;
            break;
        default:
            fr = fg = fb = 0;
        }

        float m = (Math.max(0f, Math.min(256f, v)) / 256) - c;
        rgb[0] = (int) ((fr + m) * 255);
        rgb[1] = (int) ((fg + m) * 255);
        rgb[2] = (int) ((fb + m) * 255);
    }
}

Related

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