Friday, May 11, 2007

Posterize Filter effect

works well for byte pixels :
-------------------------------------
#define rint(x) (floor((x)+0.5f))
unsigned char CPosterizeImp::PosterizePixel(unsigned char u_value, int iLevels )
{
double dblValue;

dblValue = (float)u_value/255.0;
dblValue = rint(dblValue * (iLevels - 1.0)) / (iLevels - 1.0);

return (unsigned char)(dblValue * 255.0);
}

No comments: