To Change the Gamma of R, G,B values of a Pixel of the image

Posted: October 14, 2009 in C, C++, CUDA, Multimedia, Programming Tips, VC++
Tags: , , , , , , , ,

#define MAXVAL          255.0
#define GAMMACONSTANT   1
int SetGammaR(int iX, int iY, int iWidth, int iHeight, int iBPP, BYTE *pbySrc, double dbGammaR)
{
 double dbR = (double)(GetValueR(iX, iY, iWidth, iHeight, iBPP, pbySrc) / MAXVAL);
 dbR = pow (dbR, dbGammaR);
 dbR = dbR > GAMMACONSTANT ? dbR - GAMMACONSTANT : dbR;
 return((int) (dbR * MAXVAL));
}

int SetGammaG(int iX, int iY, int iWidth, int iHeight, int iBPP, BYTE *pbySrc, double dbGammaG)
{
 double dbG = (double)(GetValueG(iX, iY, iWidth, iHeight, iBPP, pbySrc) / MAXVAL);
 dbG = pow (dbG, dbGammaG);
 dbG = dbG > GAMMACONSTANT ? dbG - GAMMACONSTANT : dbG;
 return((int) (dbG * MAXVAL));
}

int SetGammaB(int iX, int iY, int iWidth, int iHeight, int iBPP, BYTE *pbySrc, double dbGammaB)
{
 double dbB = (double)(GetValueB(iX, iY, iWidth, iHeight, iBPP, pbySrc) / MAXVAL);
 dbB = pow (dbB, dbGammaB);
 dbB = dbB > GAMMACONSTANT ? dbB - GAMMACONSTANT : dbB;
 return((int) (dbB * MAXVAL));
}

iX                    -> x cordinate of the Pixel
iY                    -> y cordinate of the Pixel
iWidth           -> Width of the Image
iHeight          -> Height of the Image
pbySrc           -> Pointer to the Buffer where image is readed
iBpp               -> Bytes per pixel
dbGammaR  -> New Gamma value of Red Component of the Pixel
dbGammaG  -> New Gamma value of Green Component of the Pixel
dbGammaB  -> New Gamma value of Blue Component of the Pixel

The Gamma values should be in the range ie,  dbGammaR,  dbGammaG,  dbGammaB should be in 0.0 to 4.00
The default value is 1.0.

You can call these functions to the entire pixels of the image for the Gamma change of the image

NB: For the other functions given here, please refer the previous posts


														

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s