Closed maltebaer closed 4 years ago
Interesting question. https://github.com/d3/d3-color#color_brighter says “The behavior of this method [brighter] is dependent on the implementing color space.”
and indeed d3.lch(d3.rgb("#000")).brighter().hex() // "#2c2c2c"
There's no "official" definition of a brighten function, and as @Fil mentions, the behavior depends on the color space. In RGB, the effect on black follows the definiton: C' = C * Math.pow(1.42, k)
. This mostly corresponds to how the CSS brightness
filter works (C' = slope * C + intercept
); it, too, leaves black intact.
If you wanted more flexibility in applying transforms to colors (to obtain various brightness/contrast-type adjustments), the CSS Filter Effects Module may be a good start: In addition to a linear
multiplier, you can also apply a gamma
multiplier: C' = amplitude * Math.pow(C, exponent) + offset
.
Thanks for your answers.
Converting to HCL color space will work as desired, in my scenario.
What is the desired behaviour of brightening black colour? Right now it will return black.