Code:
Public Shared Sub HLSToRGB(ByVal inputH As Short, ByVal inputS As Single, ByVal inputL As Single)
Dim rR As Single = 0
Dim rG As Single = 0
Dim rB As Single = 0
Dim Min As Single, Max As Single
inputH = inputH / 60
If inputS = 0 Then
Achromatic case:
rR = inputL
rG = inputL
rB = inputL
Else
Chromatic case:
If inputL <= 0.5 Then
Get Min value:
Min = inputL * (1 - inputS)
Else
Get Min value:
Min = inputL - inputS * (1 - inputL)
End If
Get the Max value:
Max = 2 * inputL - Min
Now depending on sector we can evaluate the h,l,s:
If (inputH < 1) Then
rR = Max
If (inputH < 0) Then
rG = Min
rB = rG - inputH * (Max - Min)
Else
rB = Min
rG = inputH * (Max - Min) + rB
End If
ElseIf (inputH < 3) Then
rG = Max
If (inputH < 2) Then
rB = Min
rR = rB - (inputH - 2) * (Max - Min)
Else
rR = Min
rB = (inputH - 2) * (Max - Min) + rR
End If
Else
rB = Max
If (inputH < 4) Then
rR = Min
rG = rR - (inputH - 4) * (Max - Min)
Else
rG = Min
rR = (inputH - 4) * (Max - Min) + rG
End If
End If
End If
AIvision.cR = rR * 255
AIvision.cG = rG * 255
AIvision.cB = rB * 255
all right... AIvision.cR = rR * 255 is overflowing because rR is getting over 1 when inputH is over around 340 (also depends on the other input values)... does anyone know why ? btw. this code is HSL to RGB converter... lol hope you are good at math.
AIvision class output values (RGB) cR, cG and rB are type of Byte. And after doing a bit more of researching I found out that cR got 288 and it should be between 0-255.
Anyway the overflowing happened e.g. with these input values:
346,8 ; 0,4464286 ; 0,4392157
Last edited by a moderator: