TheDutchCoder / ColorConvert

A Sublime Text 2 plugin that converts CSS colors from hex to rgb and back
MIT License
55 stars 6 forks source link

begin with hex and convert three time, the hex value is not the original one #10

Closed feipigzi closed 10 years ago

feipigzi commented 10 years ago

f2f2f2 //from this one

V rgba(242, 242, 242, 1.0) V hsla(0.0, 0.0%, 94.9%, 1.0)
V

f1f1f1

TheDutchCoder commented 10 years ago

Yes this is due to the fact that hex/rgb is less accurate than hsla.

What I could do is store the 'original' value of the color and give that a higher precedence over the converted value. Or I could keep track of the unrounded hsla values and use those in my calculations.

Francisc commented 10 years ago

Yeah, this is a deal breaker for me. Please fix, I don't think enhancement is the proper tag for this.

Francisc commented 10 years ago

Wait, what do you mean HEX -> RGB conversion is less accurate?

TheDutchCoder commented 10 years ago

In CSS, rgb(a) only supports integers, whereas hsl(a) supports fractions, this can lead to some minor rounding differences.

On 16 March 2014 13:19, Francisc Romano notifications@github.com wrote:

Wait, what do you mean HEX -> RGB conversion is less accurate?

Reply to this email directly or view it on GitHubhttps://github.com/TheDutchCoder/ColorConvert/issues/10#issuecomment-37763366 .

jvanalst commented 10 years ago

Yah. This is a deal breaker for myself as well. Could part of the solution be to simply round the HSL to the nearest integer? I've never seen anyone use fractional HSL before.

jvanalst commented 10 years ago

Also the fact that it takes an HSL and converts it to an HSLA is mighty odd, behaviour wise. Reasonably harmless, but not what I would expect.

TheDutchCoder commented 10 years ago

I'm currently looking into this issue and it seems to have something to do with rounding numbers (RGB -> HSL can result in some major fractions).

E.g.: In the OP's example, the 94.9% is actually 94.901960784313715%.

I was preparing a system where all values were stored globally, so I'll pursue that in order to get everything accurate.

TheDutchCoder commented 10 years ago

I seem to have fixed the issue in my latest merge, this should get rid of the inaccuracies!