You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mix() returns wrong result for added colors. #1673
Interesting. I found that the problem is in alpha channel. Basically, an addition (or any other op) of two colors with alpha = 1 results in a color with alpha = 2, thus unexpected result when the result color passed to certain functions.
@seven-phases-max, I'm expecting mix(@a, @b, 25%) to return the same result as overlaying @a with 1/4th of its opacity over an original-opacity-@b in any image editor. I guess this goes inline with the discussion in #2291. Do I get this right?
Now, the spec coming from our designer says that #2274AC + 25% black should equal #195781. I've double-checked in Inkcape and GIMP, getting exactly the same results:
I.e. Less uses canonical rounding for non-integer color channel values when producing their hexadecimal representation while those graphics editors you mentioned seem to use floor for some reason. That's it. Note the rounding is not even a part of the mix function but the property of any rgb to hex conversion, e.g.:
@seven-phases-max, thanks for clearing this out – could've checked myself actually :) To be honest, I only noticed that the difference is so small at the very end of writing the comment.
I'm almost certain our designer has used Photoshop for the conversion. So maybe it's some kind of standard amond image editors? If it is so, would you consider adjusting LESS's color rounding algorhithm?
I admit it doesn't make sense to floor the values. But you do aim to mimic the behaviour of image editors, don't you?
Yeah, I wondered myself. I asked to test a few graphics products from Adobe and they actually seem to use 0.5 -> 0 rounding instead of 0.5 -> 1 (but not really floor, i.e. it's still 0.51 -> 1). I can't imagine any sensible reason they do this except some low-level algorithm/optimization compromise and/or backward-compatibility with 1960's.
Interesting.. 'round down' rounding. At least thats an even smaller change
from what we do - unless its accountancy rounding (where round up/down
flips depending on whether the number is odd/even) ?
I don't think this one should be reopened since it's about wrong result when mixing non-transparent colors and it's fixed (the fact that the error was in "alpha-compositing" code does not really matter). #2291 is about "alpha-compositing" algorithm itself and any hypothetical changes there won't affect the code example above. I kept #2291 open just in case someone comes up with ideas/rationale to use some another algo (but I guess it's most likely to be closed as time passes "due to inactivity" or so).
Please do if you feel this is important. Honestly I don't think this will be ever considered too seriously... Changing standard JavaScript round function there to some hand-written round-down method does not look like something that's worth 1/2^24 drift in a color value.
Activity
seven-phases-max commentedon Nov 22, 2013
Interesting. I found that the problem is in alpha channel. Basically, an addition (or any other op) of two colors with alpha = 1 results in a color with alpha = 2, thus unexpected result when the result color passed to certain functions.
lukeapage commentedon Nov 22, 2013
Great spot.
lukeapage commentedon Dec 22, 2013
@seven-phases-max assume this is now fixed?
seven-phases-max commentedon Dec 23, 2013
Yes, it is fixed.
tomek-he-him commentedon Feb 2, 2015
@seven-phases-max, I'm expecting
mix(@a, @b, 25%)to return the same result as overlaying@awith 1/4th of its opacity over an original-opacity-@bin any image editor. I guess this goes inline with the discussion in #2291. Do I get this right?Now, the spec coming from our designer says that
#2274AC+ 25% black should equal#195781. I've double-checked in Inkcape and GIMP, getting exactly the same results:And even so, less.js v2.3.1 returns
#1a5781:I know it's only one unit in one channel – but enough to be another color than that from the spec. It does make a difference in our case.
seven-phases-max commentedon Feb 2, 2015
@tomekwi
Let's see:
mix(black, #2274AC, 25%);->25% * black + 75% * #2274AC->75% * [34 167 129]->[25.5 87 129]andround(25.5)->26->0x1a.I.e. Less uses canonical rounding for non-integer color channel values when producing their hexadecimal representation while those graphics editors you mentioned seem to use
floorfor some reason. That's it. Note the rounding is not even a part of themixfunction but the property of anyrgbtohexconversion, e.g.:So I can't see any issue here or anything that should or may be fixed at all (at Less side ;)
tomek-he-him commentedon Feb 2, 2015
@seven-phases-max, thanks for clearing this out – could've checked myself actually :) To be honest, I only noticed that the difference is so small at the very end of writing the comment.
I'm almost certain our designer has used Photoshop for the conversion. So maybe it's some kind of standard amond image editors? If it is so, would you consider adjusting LESS's color rounding algorhithm?
I admit it doesn't make sense to floor the values. But you do aim to mimic the behaviour of image editors, don't you?
lukeapage commentedon Feb 2, 2015
Is there a reason gimp uses different rounding though? If every other tool
has a different rounding method, shouldnt we change?
lukeapage commentedon Feb 2, 2015
Reported before. Seems sass also floors.
#552
lukeapage commentedon Feb 2, 2015
Cant find any more info. I suspect flooring may have become the norm
because the first implementation cast a float to an int which floors right?
seven-phases-max commentedon Feb 3, 2015
@lukeapage
Yeah, I wondered myself. I asked to test a few graphics products from Adobe and they actually seem to use
0.5 -> 0rounding instead of0.5 -> 1(but not reallyfloor, i.e. it's still0.51 -> 1). I can't imagine any sensible reason they do this except some low-level algorithm/optimization compromise and/or backward-compatibility with 1960's.lukeapage commentedon Feb 3, 2015
Interesting.. 'round down' rounding. At least thats an even smaller change
from what we do - unless its accountancy rounding (where round up/down
flips depending on whether the number is odd/even) ?
tomek-he-him commentedon Feb 19, 2015
Should we reopen this issue? Merge into #2291?
Although to me #2291 seems to be a misunderstanding rather than a real problem.
seven-phases-max commentedon Feb 19, 2015
@tomekwi
I don't think this one should be reopened since it's about wrong result when mixing non-transparent colors and it's fixed (the fact that the error was in "alpha-compositing" code does not really matter). #2291 is about "alpha-compositing" algorithm itself and any hypothetical changes there won't affect the code example above. I kept #2291 open just in case someone comes up with ideas/rationale to use some another algo (but I guess it's most likely to be closed as time passes "due to inactivity" or so).
tomek-he-him commentedon Feb 19, 2015
I can make another issue out of this, if you consider changing the current rounding.
seven-phases-max commentedon Feb 19, 2015
Please do if you feel this is important. Honestly I don't think this will be ever considered too seriously... Changing standard JavaScript
roundfunction there to some hand-writtenround-downmethod does not look like something that's worth1/2^24drift in a color value.