RemapHue example for C++ Builder
// This example changes all green hues (and hues near green) to the hue of crNewColor
short Increment (short x)
{
return ((short)((x + 1) % 256));
}
short Decrement(short x)
{
return ((short)((x + 255) % 256));
}
short Add(short x, short y)
{
return ((short)((x + y) % 256));
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
short i;
short nHueGreen;
short nHueNewColor;
short nHueChange;
::OLE_COLOR crNewColor;
short iCount;
LEADRasterProcess* pRasterProc= NULL;
CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&pRasterProc);
for (i= 0; i < 256; i++)
{
pRasterProc->set_MaskTable (i, 0);
pRasterProc->set_HTable (i, i);
}
//Get the hue for green
nHueGreen= pRasterProc->HSV_HfromRGB (RGB(0, 255, 0));
//Obtain new hue (crNewColor can be any color)
crNewColor= RGB(255, 255, 0);
nHueNewColor= pRasterProc->HSV_HfromRGB(crNewColor);
nHueChange= (short)(nHueNewColor - nHueGreen);
if (nHueChange < 0)
nHueChange= (short)(nHueChange + 256);
//Set values in uHueTable, uMaskTable
pRasterProc->set_HTable (nHueGreen, Add(pRasterProc->get_HTable(nHueGreen), nHueChange));
pRasterProc->set_MaskTable(nHueGreen, 1);
//set the hues near green (+/- 10)
iCount= 0;
i= Increment(nHueGreen);
while (iCount < 10)
{
pRasterProc->set_HTable(i, Add(pRasterProc->get_HTable(i), nHueChange));
pRasterProc->set_MaskTable (i, 1);
i= Increment(i);
iCount= (short)(iCount + 1);
}
iCount= 0;
i= Decrement(nHueGreen);
while (iCount < 10)
{
pRasterProc->set_HTable (i, Add(pRasterProc->get_HTable(i), nHueChange));
pRasterProc->set_MaskTable(i, 1);
i= Decrement(i);
iCount= (short)(iCount + 1);
}
pRasterProc->RemapHue (LEADRasterView1->Raster, True, True, False, False);
pRasterProc-> Release( );
}