RemapHue example for Delphi
// This example changes all green hues (and hues near green) to the hue of crNewColor
Function Increment (x: Integer): Integer;
begin
Result:= (x + 1) Mod 256;
End;
Function Decrement(x: Integer): Integer;
begin
Result:= (x + 255) Mod 256;
End;
Function Add(x: Integer; y: Integer): Integer;
begin
Result:= (x + y) Mod 256;
End;
var
i: Integer;
nHueGreen: Integer;
nHueNewColor: Integer;
nHueChange: Integer;
crNewColor: OLE_COLOR;
iCount: Integer;
RasterProc: LEADRasterProcess;
begin
RasterProc:= CreateComObject (CLASS_LEADRasterProcess) as LEADRasterProcess;
for i:= 0 to 255 do
begin
RasterProc.MaskTable [i]:= 0;
RasterProc.HTable [i]:= I;
end;
//Get the hue for green
nHueGreen:= RasterProc.HSV_HfromRGB (RGB(0, 255, 0));
//Obtain new hue (crNewColor can be any color)
crNewColor:= RGB(255, 255, 0);
nHueNewColor:= RasterProc.HSV_HfromRGB(crNewColor);
nHueChange:= nHueNewColor - nHueGreen;
if (nHueChange < 0) then
nHueChange:= nHueChange + 256;
//Set values in uHueTable, uMaskTable
RasterProc.HTable [nHueGreen]:= Add(RasterProc.HTable[nHueGreen], nHueChange);
RasterProc.MaskTable[nHueGreen]:= 1;
//set the hues near green (+/- 10)
iCount:= 0;
i:= Increment(nHueGreen);
While iCount < 10 do
begin
RasterProc.HTable[i]:= Add(RasterProc.HTable[i], nHueChange);
RasterProc.MaskTable [i]:= 1;
i:= Increment(i);
iCount:= iCount + 1;
end;
iCount:= 0;
i:= Decrement(nHueGreen);
While iCount < 10 do
begin
RasterProc.HTable [i]:= Add(RasterProc.HTable[i], nHueChange);
RasterProc.MaskTable[i]:= 1;
i:= Decrement(i);
iCount:= iCount + 1;
end;
RasterProc.RemapHue (LEADRasterView1.Raster, True, True, False, False);
end;