unsigned short g_GammaLUT[65536];
void BuildTable(float fPrecompensation)
{
int i;
float f;
for (i = 0 ; i < 65536 ; i++)
{
f = (i + 0.5f)/16384 ; //归一化
f = (float) pow(f ,fPrecompensation);//预补偿(调用“求指数”函数)
unsigned short temp=(unsigned short) (f*16384 -0.5f);
if (temp>16383)
{
temp=16383;
}
if (temp<0)
{
temp=0;
}
g_GammaLUT[ i ] =temp; //反归一化
}
}
void GammaCorrection ( unsigned short *data,int Width,int Height,float fGamma)
{
BuildTable(1/fGamma) ;
unsigned short *temp=data;
for (int i=0;i<Width*Height;i++)
{
*temp=g_GammaLUT[*temp];
temp++;
}
}