>Chris,
>I'm trying to replace the colors on my image using
>IS3ColorReplaceImage, but not happen.
what happens?
>My image in memory is 8 bit grayscale, but the original file
>is 4 bit grayscale, so the palette is 256 colors but only 16
>is used.
are the pixel values 0..15 or 0..255 ?
>I would like to change 15% to black and 85% to white.
(put code inside <code> ... </code> tags - but use square brackets instead of < and >)
Code:
BYTE *pImage = GetImagePointer();
if(pImage==NULL) return(IS_ERR_BADPARAM);
UINT32 arrayColor[256];
memset(&arrayColor,0,sizeof(UINT32)*256);
ISrc(IS3FindColorsUsedIn8BitImage)(pImage,m_czPix.cx,m_czPix.cy,m_czPix.cx,arrayColor);
UINT32 unPixels=m_czPix.cx*m_czPix.cy;
double pBlack=0.0;
for(UINT32 i=0;i<16;i++)
{
pBlack+=((double)((double)arrayColor[i]/unPixels)*100.0);
if(pBlack>=15.0)
ISrc(IS3ColorReplaceImage)(pImage,m_czPix.cx,m_czPix.cy,m_czPix.cx,1,i,15,0,0);//15=white
else
ISrc(IS3ColorReplaceImage)(pImage,m_czPix.cx,m_czPix.cy,m_czPix.cx,1,i,0,0,0); //0=black
}
so, if the pixel is equal or brighter than 15% of the total pixels, you set it to white, else to black ?
a faster way might be:
Code:
BYTE *pImage = GetImagePointer();
if(pImage==NULL) return(IS_ERR_BADPARAM);
UINT32 arrayColor[256];
memset(&arrayColor,0,sizeof(UINT32)*256);
ISrc(IS3FindColorsUsedIn8BitImage)(pImage,m_czPix.cx,m_czPix.cy,m_czPix.cx,arrayColor);
UINT32 unPixels=m_czPix.cx*m_czPix.cy;
double pBlack=0.0;
BYTE lut[16];
BYTE *luts[1];
luts[0] = lut;
for(UINT32 i=0;i<16;i++)
{
pBlack+=((double)((double)arrayColor[i]/unPixels)*100.0);
if(pBlack>=15.0)
lut[i] = 15;
else
lut[i] = 0;
}
IS3ApplyLUTsToImage(pImage,m_czPix.cx,m_czPix.cy,1,m_czPix.cx,luts);
besides being probably 20 times faster, this way, you can look at the LUT in the debugger and see exactly how you are mapping the original colors to the new colors.