RemapHue example for C++Builder
/*
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
*/
L_UINT Increment(L_UINT x)
{
return ((x + 1) % 256);
}
L_UINT Decrement(L_UINT x)
{
return ((x + 255) % 256);
}
L_UINT Add(int x, int y)
{
return ((x + y) % 256);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
L_INT i;
L_INT nHueGreen;
L_INT nHueNewColor;
L_INT nHueChange;
COLORREF crNewColor;
L_UINT uCount;
for (i= 0; i < 256; i ++ )
{
LEADImage1->MaskTable[i]= 0;
LEADImage1->HTable[i]= i;
}
//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)
nHueChange= nHueChange + 256;
//Set values in uHueTable, uMaskTable
LEADImage1->HTable[nHueGreen]= LEADImage1->HTable[nHueGreen] + (nHueChange);
LEADImage1->MaskTable[nHueGreen]= 1;
//set the hues near green (+/- 5)
uCount= 0;
i= Increment(nHueGreen);
while (uCount < 5)
{
LEADImage1->HTable[i]= Add(Integer(LEADImage1->HTable[i]), nHueChange);
LEADImage1->MaskTable[i]= 1;
i= Increment(i);
uCount++;
}
uCount= 0;
i= Decrement(nHueGreen);
while (uCount < 5)
{
LEADImage1->HTable[i]= Add(Integer(LEADImage1->HTable[i]), nHueChange);
LEADImage1->MaskTable[i]= 1;
i= Decrement(i);
uCount++;
}
LEADImage1->RemapHue( True, True, False, False ) ;
}