Available in the LEADTOOLS Imaging toolkit. |
RemapHue example for Visual Basic
' This example changes all green hues(and hues near green) to the hue of crNewColor
Private Function Increment(x As Integer) As Integer
Increment = (x + 1) Mod 256
End Function
Private Function Decrement(x As Integer) As Integer
Decrement = (x + 255) Mod 256
End Function
Private Function Add(x As Integer, y As Integer) As Integer
Add = (x + y) Mod 256
End Function
Private Sub Command1_Click()
Dim i As Integer
Dim nHueGreen As Integer
Dim nHueNewColor As Integer
Dim nHueChange As Integer
Dim crNewColor As OLE_COLOR
Dim iCount As Integer
For i = 0 To 255
LEAD1.MaskTable(i) = 0
LEAD1.HTable(i) = i
Next i
'Get the hue for green
nHueGreen = LEAD1.HSV_HfromRGB(RGB(0, 255, 0))
'Obtain new hue (crNewColor can be any color)
crNewColor = RGB(255, 255, 0)
nHueNewColor = LEAD1.HSV_HfromRGB(crNewColor)
nHueChange = nHueNewColor - nHueGreen
If (nHueChange < 0) Then
nHueChange = nHueChange + 256
End If
'Set values in uHueTable, uMaskTable
LEAD1.HTable(nHueGreen) = LEAD1.HTable(nHueGreen) + nHueChange
LEAD1.MaskTable(nHueGreen) = 1
'set the hues near green (+/- 5)
iCount = 0
i = Increment(nHueGreen)
While iCount < 5
LEAD1.HTable(i) = Add(LEAD1.HTable(i), nHueChange)
LEAD1.MaskTable(i) = 1
i = Increment(i)
iCount = iCount + 1
Wend
iCount = 0
i = Decrement(nHueGreen)
While iCount < 5
LEAD1.HTable(i) = Add(LEAD1.HTable(i), nHueChange)
LEAD1.MaskTable(i) = 1
i = Decrement(i)
iCount = iCount + 1
Wend
LEAD1.RemapHue True, True, False, False
End Sub