RemapHue example for C++ 5.0 and later
//This example changes all green hues(and hues near green) to the hue of crNewColor
#define INCREMENT(x) ((x+1)%256)
#define DECREMENT(x) ((x+255)%256)
#define ADD(x,y) ((x+y)%256)
void CRemapHueDlg::OnRemapHue()
{
int i;
int nHueGreen;
int nHueNewColor;
int nHueChange;
OLE_COLOR crNewColor;
int iCount;
ILEADRasterProcess *pRasterProc=NULL;
CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&pRasterProc);
if (pRasterProc != NULL)
{
if((m_RasterView.GetRaster ().GetBitmapBits () == 16 && m_RasterView.GetRaster().GetIsGrayscale())
|| m_RasterView.GetRaster().GetBitmapBits() == 64 || m_RasterView.GetRaster().GetBitmapBits() == 48)
pRasterProc->RemapHueTablesSize = 65536;
else if(m_RasterView.GetRaster().GetBitmapBits() == 12)
pRasterProc->RemapHueTablesSize= 4096;
else
pRasterProc->RemapHueTablesSize = 256;
for (i=0; i< pRasterProc->RemapHueTablesSize; i++)
{
pRasterProc->PutMaskTable (i,0);
pRasterProc->PutHTable (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 = nHueNewColor - nHueGreen;
if (nHueChange < 0)
nHueChange = nHueChange + 256;
//Set values in uHueTable, uMaskTable
pRasterProc->PutHTable(nHueGreen, ADD(pRasterProc->GetHTable(nHueGreen), nHueChange) );
pRasterProc->PutMaskTable(nHueGreen, 1);
//set the hues near green (+/- 10)
iCount = 0;
i = INCREMENT(nHueGreen);
while (iCount < 10)
{
pRasterProc->PutHTable(i, ADD(pRasterProc->GetHTable(i), nHueChange) );
pRasterProc->PutMaskTable(i, 1);
i = INCREMENT(i);
iCount++;
}
iCount = 0;
i = DECREMENT(nHueGreen);
while (iCount < 10)
{
pRasterProc->PutHTable(i, ADD(pRasterProc->GetHTable(i), nHueChange));
pRasterProc->PutMaskTable(i, 1);
i = DECREMENT(i);
iCount = iCount + 1;
}
pRasterProc->RemapHue (m_RasterView.GetRaster(), TRUE, TRUE, FALSE, FALSE);
pRasterProc->Release();
}
}