You'll probably find that this is because the HSL representation uses
different value ranges for its components than RGB. As far as I'm
aware, HSL can represent slightly fewer colours (in the context of RGB
media) than RGB. I think you will also find that most tools that allow
you to arbitrarily choose your representation will also exhibit this
lack of reflexivity; I think that Photoshop & the GIMP both also use
integers to represent HSL colours.

Clearly this isn't desired behaviour in your application, but I'm not
so sure if it really is s bug in MooTools. A limitation, perhaps. It
might be worthwhile producing a colour palette for your application,
and "snapping" all values to that palette. Perhaps only allow colours
in RGB whose values are multiples of 8 or something.

On Friday, January 22, 2010, woomla <[email protected]> wrote:
> Playing around with Color conversions, I've found out that conversion
> from RGB to HSB and back to RGB not yield in the same result. Should
> it not? Probably because the HSB values should be float. Anyhow, I've
> written this JSSpec test to easily see what's wrong.
>
>
>
>   describe('Color conversions vice-versa', {
>
>     'Conversion from RGB to HSB to RGB should not change': function ()
> {
>       var color = new Color([10, 11, 12], 'rgb');
>       value_of(new Color(color.hsb, 'hsb').rgb).should_be([10, 11,
> 12]);
>     },
>
>     'Conversion from HSB to RGB to HSB should not change': function ()
> {
>       var color = new Color([210, 17, 5], 'hsb');
>       value_of(new Color(color.rgb, 'rgb').hsb).should_be([210, 17,
> 5]);
>     },
>
>
>     'Conversion from RGB to HEX to RGB should not change': function ()
> {
>       var color = new Color([10, 11, 12], 'rgb');
>       value_of(new Color(color.hex).rgb).should_be([10, 11, 12]);
>     },
>
>     'Conversion from HEX to RGB to HEX should not change': function ()
> {
>       var color = new Color('0A0B0C');
>       value_of(new Color(color.rgb, 'rgb').hex).should_be('#0a0b0c');
>     },
>
>
>
>     'Conversion from HSB to HEX to HSB should not change': function ()
> {
>       var color = new Color([210, 17, 5], 'hsb');
>       value_of(new Color(color.hex).hsb).should_be([210, 17, 5]);
>     },
>
>     'Conversion from HEX to HSB to HEX should not change': function ()
> {
>       var color = new Color('0A0B0C');
>       value_of(new Color(color.hsb, 'hsb').hex).should_be('#0a0b0c');
>     }
>
>   });
>

-- 
http://barryvan.com.au/
[email protected]

Reply via email to