RemapHue example for Delphi
{
This example considers that the image you are working with is 24 bpp.
This example changes all green hues(and hues near green) to the hue of crNewColor
}
Function Increment(x: L_UINT): L_UINT;
begin
Result:= (x + 1) Mod 256;
End;
Function Decrement(x: L_UINT): L_UINT;
begin
Result:= (x + 255) Mod 256;
End;
Function Add(x: L_UINT; y: L_UINT): L_UINT;
begin
Result:= (x + y) Mod 256;
End;
procedure TForm1.Button1Click(Sender: TObject);
var
i: L_INT;
nHueGreen: L_INT;
nHueNewColor: L_INT;
nHueChange: L_INT;
crNewColor: COLORREF;
uCount: L_UINT;
begin
LEADImage1.RemapHueTablesSize:= 256;
for i:= 0 To 255 do
begin
LEADImage1.MaskTable[i]:= 0;
LEADImage1.HTable[i]:= i;
end;
//Get the hue for green
nHueGreen:= LEADImage1.HSV_HfromRGB(RGB(0, 255, 0));
//Obtain new hue (crNewColor can be any color)
crNewColor:= RGB(255, 255, 0);
nHueNewColor:= LEADImage1.HSV_HfromRGB(crNewColor);
nHueChange:= nHueNewColor - nHueGreen;
if (nHueChange < 0) then
nHueChange:= nHueChange + 256;
//Set values in HTable, MaskTable
LEADImage1.HTable[nHueGreen]:= LEADImage1.HTable[nHueGreen] + L_UINT(nHueChange);
LEADImage1.MaskTable[nHueGreen]:= 1;
//set the hues near green (+/- 5)
uCount:= 0;
i:= Increment(nHueGreen);
while uCount < 5 do
begin
LEADImage1.HTable[i]:= Add(LEADImage1.HTable[i], nHueChange);
LEADImage1.MaskTable[i]:= 1;
i:= Increment(i);
uCount:= uCount + 1;
end;
uCount:= 0;
i:= Decrement(nHueGreen);
while uCount < 5 do
begin
LEADImage1.HTable[i]:= Add(Integer(LEADImage1.HTable[i]), nHueChange);
LEADImage1.MaskTable[i]:= 1;
i:= Decrement(i);
uCount:= uCount + 1;
end;
LEADImage1.RemapHue( True, True, False, False ) ;
end;