有人知道从linearrgb颜色(而不是srgb颜色)获得hsl的方法吗?我见过很多srgb<->hsl转换,但是linearrgb<->hsl没有。不确定这是否是基本上相同的转换和细微的调整,但我很感激有人对此有任何见解。
线性RGB与线性化sRGB不同(取[0255]并使其成为[0,1])。从/到sRGB的线性RGB转换为
http://en.wikipedia.org/wiki/SRGB
. 在vba中,可以表示为(采用线性化的srgb值[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
我试过将线性的RGB值发送到标准的RGB-to-HSL例程,然后从HSL-to-RGB返回,但它不起作用。可能是因为当前的hsl<->rgb算法考虑了gamma校正,而线性rgb没有gamma校正-我不太清楚。我几乎看不到可以这样做的参考资料,除了两个:
-
参考
http://en.wikipedia.org/wiki/HSL_and_HSV#cite_note-9
(编号项目10)。
-
开放源代码上的引用
Grafx2项目@
http://code.google.com/p/grafx2/issues/detail?id=63#c22
其中,投稿人声明
他做过线性RGB<->HSL
转换并在.diff文件的注释附件中提供一些C代码
(我真的看不懂:()
我的目的是:
-
从sRGB发送(例如,
FF99FF
(
R=255, G=153, B=255
)
线性RGB(线性RGB)
R=1.0,
G=0.318546778125092, B=1.0
)
-
使用上面的代码(例如,
g=153可以用线性表示。
从RGB
sRGB_to_linearRGB(153 /
255)
)
-
到HSL
-
通过以下方式修改/调节饱和度
350%
-
从HSL发回->线性
rgb->sRGB,结果将是
FF19FF
(
R=255, G=25, B=255
)
使用.NET中的可用函数,例如
.getHue
从A
System.Drawing.Color
不能在任何高于任何HSL值100%调制的SRGB空间中工作,因此需要发送线性RGB而不是SRGB。