Available in the LEADTOOLS Imaging toolkit. |
RemapHue example for C++ 4.0 and later
//This example changes all green hues(and hues near green) to the hue of crNewColor
// The example uses the following macros:
#define INCREMENT(x) ((x+1)%256)
#define DECREMENT(x) ((x+255)%256)
#define ADD(x,y) ((x+y)%256)
void CColorReplaceDlg::ChangeGreenHues(COLORREF crNewColor)
{
int i;
int nHueGreen, nHueNewColor, nHueChange;
int iCount;
//Initialize tables
for (i=0; i<256; i++)
{
m_Lead.SetMaskTable(i, 0);
m_Lead.SetHTable(i,i);
}
//Get the hue for green
nHueGreen = m_Lead.HSV_HfromRGB(RGB(0, 255, 0));
//Obtain new hue
nHueNewColor = m_Lead.HSV_HfromRGB(crNewColor);
nHueChange = nHueNewColor - nHueGreen;
if (nHueChange < 0)
nHueChange += 256;
//Set values in uHueTable, uMaskTable
m_Lead.SetHTable(nHueGreen, m_Lead.GetHTable(nHueGreen) + nHueChange);
m_Lead.SetMaskTable(nHueGreen, 1);
//set the hues near green (+/- 5)
iCount = 0;
i = INCREMENT(nHueGreen);
while (iCount < 5)
{
m_Lead.SetHTable(i, ADD(m_Lead.GetHTable(i), nHueChange) );
m_Lead.SetMaskTable(i, 1);
i = INCREMENT(i);
iCount++;
}
iCount = 0;
i = DECREMENT(nHueGreen);
while (iCount < 5)
{
m_Lead.SetHTable(i, ADD(m_Lead.GetHTable(i), nHueChange));
m_Lead.SetMaskTable(i,1);
i = DECREMENT(i);
iCount++;
}
m_Lead.RemapHue(TRUE, TRUE, FALSE, FALSE);
}