Here you can find the source of hsvToRgb(double hue, double saturation, double value)
Parameter | Description |
---|---|
hue | double from 0-1 |
saturation | double from 0-1 |
value | double from 0-1 |
public static float hsvToRgb(double hue, double saturation, double value)
//package com.java2s; //License from project: Creative Commons License public class Main { /**/*from w ww. j a v a2 s.co m*/ * Convert a hue, saturation, and value to a float compatible with NIVision. * @param hue double from 0-1 * @param saturation double from 0-1 * @param value double from 0-1 * @return a float based on NIVision. */ public static float hsvToRgb(double hue, double saturation, double value) { int h = (int) (hue * 6); double f = hue * 6 - h; double p = value * (1 - saturation); double q = value * (1 - f * saturation); double t = value * (1 - (1 - f) * saturation); switch (h) { case 0: return getColor((int) (value * 256.0), (int) (t * 256.0), (int) (p * 256.0)); case 1: return getColor((int) (q * 256.0), (int) (value * 256.0), (int) (p * 256.0)); case 2: return getColor((int) (p * 256.0), (int) (value * 256.0), (int) (t * 256.0)); case 3: return getColor((int) (p * 256.0), (int) (q * 256.0), (int) (value * 256.0)); case 4: return getColor((int) (t * 256.0), (int) (p * 256.0), (int) (value * 256.0)); case 5: return getColor((int) (value * 256.0), (int) (p * 256.0), (int) (q * 256.0)); default: return getColor(0, 0, 0); } } /** * Takes a Red, Green, and Blue value and returns the appropriate float. Maybe * @param r Redness * @param g Greenness * @param b Blueness * @return A float */ public static float getColor(int r, int g, int b) { if (r < 0) { r = 0; } ; if (r > 0xFF) { r = 0xFF; } ; //Limit range for red if (g < 0) { g = 0; } ; if (g > 0xFF) { g = 0xFF; } ; //Limit range for blue if (b < 0) { b = 0; } ; if (b > 0xFF) { b = 0xFF; } ; //Limit range for green return (float) (0x00000000 + (((int) b) << 16) + (((int) g) << 8) + (((int) r))); } }