<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: RGB to HSL and RGB to HSV color model conversion algorithms in JavaScript</title>
	<atom:link href="http://mjijackson.com/blog/2008/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://mjijackson.com/blog/2008/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Thu, 04 Dec 2008 19:02:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: TopC</title>
		<link>http://mjijackson.com/blog/2008/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-511</link>
		<dc:creator>TopC</dc:creator>
		<pubDate>Thu, 19 Jun 2008 21:20:01 +0000</pubDate>
		<guid isPermaLink="false">http://mjijackson.com/2008/02/10/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-511</guid>
		<description>&lt;p&gt;While trawling for an RGB to HSV solution I stumbled across your code. I've written colour modelling code before so knew what I was aiming for, I just wanted  a head start. Having put some code together I noticed one issue you might be interested in. The hsvToRgb() method needs to use &lt;code&gt;switch(i%6)&lt;/code&gt; otherwise  it'll go wrong when &lt;code&gt;h&lt;/code&gt; is 1. This modules is in wikipidia's formula but has gone astray in your code.&lt;/p&gt;

&lt;p&gt;I came up with a Colour class to supply the behaviour. I was going to include my code but it wouldn't fit so here's an extract. Adding 360 (6 in you case) prevents the hue from going negative...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Colour.prototype._rgbToHsv = function() {
    var r = this._red, g = this._green, b = this._blue;
    var max = this._value = Math.max(r, g, b);
    var min = Math.min(r, g, b);
    var d = max - min;
    this._saturation = (max == 0) ? 0 : d / max;
    switch(max){
        case min: this._hue = 0; break; // achromatic
        case r: this._hue = (60 * ((g - b) / d) + 360) % 360; break;
        case g: this._hue = 60 * ((b - r) / d) + 120; break;
        case b: this._hue = 60 * ((r - g) / d) + 240; break;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Cheers&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>While trawling for an RGB to HSV solution I stumbled across your code. I&#8217;ve written colour modelling code before so knew what I was aiming for, I just wanted  a head start. Having put some code together I noticed one issue you might be interested in. The hsvToRgb() method needs to use <code>switch(i%6)</code> otherwise  it&#8217;ll go wrong when <code>h</code> is 1. This modules is in wikipidia&#8217;s formula but has gone astray in your code.</p>

<p>I came up with a Colour class to supply the behaviour. I was going to include my code but it wouldn&#8217;t fit so here&#8217;s an extract. Adding 360 (6 in you case) prevents the hue from going negative&#8230;</p>

<pre><code>Colour.prototype._rgbToHsv = function() {
    var r = this._red, g = this._green, b = this._blue;
    var max = this._value = Math.max(r, g, b);
    var min = Math.min(r, g, b);
    var d = max - min;
    this._saturation = (max == 0) ? 0 : d / max;
    switch(max){
        case min: this._hue = 0; break; // achromatic
        case r: this._hue = (60 * ((g - b) / d) + 360) % 360; break;
        case g: this._hue = 60 * ((b - r) / d) + 120; break;
        case b: this._hue = 60 * ((r - g) / d) + 240; break;
    }
}
</code></pre>

<p>Cheers</p>]]></content:encoded>
	</item>
	<item>
		<title>By: unabacus</title>
		<link>http://mjijackson.com/blog/2008/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-499</link>
		<dc:creator>unabacus</dc:creator>
		<pubDate>Fri, 13 Jun 2008 22:41:42 +0000</pubDate>
		<guid isPermaLink="false">http://mjijackson.com/2008/02/10/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-499</guid>
		<description>&lt;p&gt;Hi, nice work...! i've spent ages searching for good straight-forward calculations that would help me produce my own "colour" code. Mainly because, as you've said, any code i have found has been hideous in either stature (huge), cleverness (complexity) or unexpected features (bugs).. up until now i had failed entirely to get hold of anything that suited my needs.. &lt;/p&gt;

&lt;p&gt;Thanks &lt;em&gt;a lot&lt;/em&gt;.. really appreciated.. if you have any stipulations for usage please let me know. I do however always mention sources with-in my creations if i have utilised anyone elses code.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi, nice work&#8230;! i&#8217;ve spent ages searching for good straight-forward calculations that would help me produce my own &#8220;colour&#8221; code. Mainly because, as you&#8217;ve said, any code i have found has been hideous in either stature (huge), cleverness (complexity) or unexpected features (bugs).. up until now i had failed entirely to get hold of anything that suited my needs.. </p>

<p>Thanks <em>a lot</em>.. really appreciated.. if you have any stipulations for usage please let me know. I do however always mention sources with-in my creations if i have utilised anyone elses code.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: mjijackson</title>
		<link>http://mjijackson.com/blog/2008/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-498</link>
		<dc:creator>mjijackson</dc:creator>
		<pubDate>Fri, 13 Jun 2008 22:28:30 +0000</pubDate>
		<guid isPermaLink="false">http://mjijackson.com/2008/02/10/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-498</guid>
		<description>&lt;p&gt;@Gyrobo: The color conversion algorithms are taken directly from the Wikipedia. In that source, the correct signs are&lt;/p&gt;

&lt;p&gt;&lt;code&gt;2 - (max + min)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This of course translates to&lt;/p&gt;

&lt;p&gt;&lt;code&gt;2 - max - min&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As far as your second comment is concerned, the function comment clearly states that the HSL values are returned on [0,1]. This makes sense because the inverse function (hslToRgb) likewise expects those values on the same interval.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Gyrobo: The color conversion algorithms are taken directly from the Wikipedia. In that source, the correct signs are</p>

<p><code>2 - (max + min)</code></p>

<p>This of course translates to</p>

<p><code>2 - max - min</code></p>

<p>As far as your second comment is concerned, the function comment clearly states that the HSL values are returned on [0,1]. This makes sense because the inverse function (hslToRgb) likewise expects those values on the same interval.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Gyrobo</title>
		<link>http://mjijackson.com/blog/2008/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-497</link>
		<dc:creator>Gyrobo</dc:creator>
		<pubDate>Fri, 13 Jun 2008 20:47:15 +0000</pubDate>
		<guid isPermaLink="false">http://mjijackson.com/2008/02/10/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-497</guid>
		<description>&lt;p&gt;Also, for rgbToHsl, shouldn't you include&lt;/p&gt;

&lt;p&gt;&lt;code&gt;h*=360;&lt;/code&gt;
&lt;code&gt;s*=100;&lt;/code&gt;
&lt;code&gt;l*=100;&lt;/code&gt;  &lt;/p&gt;

&lt;p&gt;before the return statement? Personally, I would also Math.round() each of those.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Also, for rgbToHsl, shouldn&#8217;t you include</p>

<p><code>h*=360;</code>
<code>s*=100;</code>
<code>l*=100;</code>  </p>

<p>before the return statement? Personally, I would also Math.round() each of those.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Gyrobo</title>
		<link>http://mjijackson.com/blog/2008/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-496</link>
		<dc:creator>Gyrobo</dc:creator>
		<pubDate>Fri, 13 Jun 2008 20:22:07 +0000</pubDate>
		<guid isPermaLink="false">http://mjijackson.com/2008/02/10/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-496</guid>
		<description>&lt;p&gt;In the rgbToHsl  line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;s = l &#62; 0.5 ? d / (2 - max - min) : d / (max (PLUS) min);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;(2 - max - min)&lt;/code&gt;  should be &lt;code&gt;(2 - max (PLUS) min)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;(The preview isn't showing plus signs, so I just wrote them in.)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>In the rgbToHsl  line</p>

<p><code>s = l &gt; 0.5 ? d / (2 - max - min) : d / (max (PLUS) min);</code></p>

<p>The <code>(2 - max - min)</code>  should be <code>(2 - max (PLUS) min)</code>.</p>

<p>(The preview isn&#8217;t showing plus signs, so I just wrote them in.)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Francesco</title>
		<link>http://mjijackson.com/blog/2008/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-475</link>
		<dc:creator>Francesco</dc:creator>
		<pubDate>Tue, 03 Jun 2008 17:27:37 +0000</pubDate>
		<guid isPermaLink="false">http://mjijackson.com/2008/02/10/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-475</guid>
		<description>&lt;p&gt;I really do appreciate your work, thank you very much for sharing.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I really do appreciate your work, thank you very much for sharing.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: mjijackson</title>
		<link>http://mjijackson.com/blog/2008/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-280</link>
		<dc:creator>mjijackson</dc:creator>
		<pubDate>Thu, 13 Mar 2008 00:55:29 +0000</pubDate>
		<guid isPermaLink="false">http://mjijackson.com/2008/02/10/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-280</guid>
		<description>&lt;p&gt;@emre: I'll have to check that out. Mostly, I just wanted to be able to manipulate colors for the web. Since [CSS3][1] will accept RGB, hex, and HSL, I figured I would stick with those for the present time.&lt;/p&gt;

&lt;p&gt;[1]: http://www.w3.org/TR/css3-color/ "CSS3 color module"&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@emre: I&#8217;ll have to check that out. Mostly, I just wanted to be able to manipulate colors for the web. Since [CSS3][1] will accept RGB, hex, and HSL, I figured I would stick with those for the present time.</p>

<p>[1]: <a href="http://www.w3.org/TR/css3-color/" rel="nofollow">http://www.w3.org/TR/css3-color/</a> &#8220;CSS3 color module&#8221;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: emre</title>
		<link>http://mjijackson.com/blog/2008/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-144</link>
		<dc:creator>emre</dc:creator>
		<pubDate>Wed, 13 Feb 2008 05:55:43 +0000</pubDate>
		<guid isPermaLink="false">http://mjijackson.com/2008/02/10/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript/#comment-144</guid>
		<description>&lt;p&gt;If you want to get serious, use the &lt;a href="http://en.wikipedia.org/wiki/Colorfulness" rel="nofollow"&gt;LCh color space&lt;/a&gt; instead. The HSL/HSB model does not have much physiological basis. Not important for casual use.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>If you want to get serious, use the <a href="http://en.wikipedia.org/wiki/Colorfulness" rel="nofollow">LCh color space</a> instead. The HSL/HSB model does not have much physiological basis. Not important for casual use.</p>]]></content:encoded>
	</item>
</channel>
</rss>
