Does anyone know how to get HSL from linear RGB color (and not sRGB color)? I have seen many sRGB β HSL conversions, but nothing for linearRGB β HSL. Not sure if this is a fundamental transformation with slight changes, but I would appreciate any understanding that anyone might have about this.
Linear RGB does not match the linearization of sRGB (which takes [0.255] and makes it [0.1]). The linear conversion of RGB from / to sRGB is at http://en.wikipedia.org/wiki/SRGB . In VBA, this will be expressed (assuming linearized sRGB values ββ[0,1]):
Public Function sRGB_to_linearRGB(value As Double) If value < 0# Then sRGB_to_linearRGB = 0# Exit Function End If If value <= 0.04045 Then sRGB_to_linearRGB = value / 12.92 Exit Function End If If value <= 1# Then sRGB_to_linearRGB = ((value + 0.055) / 1.055) ^ 2.4 Exit Function End If sRGB_to_linearRGB = 1# End Function Public Function linearRGB_to_sRGB(value As Double) If value < 0# Then linearRGB_to_sRGB = 0# Exit Function End If If value <= 0.0031308 Then linearRGB_to_sRGB = value * 12.92 Exit Function End If If value < 1# Then linearRGB_to_sRGB = 1.055 * (value ^ (1# / 2.4)) - 0.055 Exit Function End If linearRGB_to_sRGB = 1# End Function
I tried to send values ββto the standard RGB_to_HSL routines in Linear RGB and return from HSL_to_RGB, but it does not work. Maybe because the current HSL β RGB algorithm takes gamma correction into account and linear RGB does not correct gamma - I donβt know for sure. I hardly saw any links that this can be done, with the exception of two:
I intend to:
- send from sRGB (e.g.
FF99FF ( R=255, G=153, B=255 )) to Linear RGB ( R=1.0, G=0.318546778125092, B=1.0 )- using the code above (for example, G = 153 will be obtained in linear RGB from
sRGB_to_linearRGB(153 / 255) )
- in HSL
- change / modulate saturation 350%
- send back from HSL-> Linear RGB-> sRGB, the result will be
FF19FF ( R=255, G=25, B=255 ).
Using available functions from .NET, such as .getHue from System.Drawing.Color , does not work in any sRGB space, except for 100% modulation of any HSL value, therefore, it is necessary to send linear RGB instead of sRGB.
source share