Note that there are some explanatory texts on larger screens.

plurals
  1. POHSV / RGB color space conversion
    text
    copied!<p>I found this code in this forum but Im having doubts with the code. </p> <ol> <li><p>in this code snippet "int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;" why the complete answer is modulus by 6? (%6)</p></li> <li><p>why is " value = value * 255 " value is multiplied by 255? </p> <p>im reffering to this research paper (p-15 , p-16) and same algorithmic is discussed but I found these differences. </p> <p><a href="http://www.poynton.com/PDFs/coloureq.pdf" rel="nofollow">http://www.poynton.com/PDFs/coloureq.pdf</a></p> <pre><code>public static Color ColorFromHSV(double hue, double saturation, double value) { int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6; double f = hue / 60 - Math.Floor(hue / 60); value = value * 255; int v = Convert.ToInt32(value); int p = Convert.ToInt32(value * (1 - saturation)); int q = Convert.ToInt32(value * (1 - f * saturation)); int t = Convert.ToInt32(value * (1 - (1 - f) * saturation)); if (hi == 0) return Color.FromArgb(255, v, t, p); else if (hi == 1) return Color.FromArgb(255, q, v, p); else if (hi == 2) return Color.FromArgb(255, p, v, t); else if (hi == 3) return Color.FromArgb(255, p, q, v); else if (hi == 4) return Color.FromArgb(255, t, p, v); else return Color.FromArgb(255, v, p, q); } public void convertToHSV(Color color, out double hue, out double saturation, out double value) { int max = Math.Max(color.R, Math.Max(color.G, color.B)); int min = Math.Min(color.R, Math.Min(color.G, color.B)); hue = color.GetHue(); saturation = (max == 0) ? 0 : 1d - (1d * min / max); value = max / 255d; } </code></pre></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload