#define BCHANNEL 0 #define GCHANNEL 1 #define RCHANNEL 2 unsigned char Clip(int iVal) { return ( iVal > 255 ? 255 : ( iVal < 0 ) ? 0 : iVal) ; } //Pixel Functions int GetValue(int iX, int iY, int iImageWidth, int iImageHeight, int iChannel, int iBPP, BYTE *pbySrc) { Clip(iX); Clip(iY); return pbySrc[iY * iImageWidth * iBPP + iX * iBPP + iChannel]; } int GetValueR(int iX, int iY, int iImageWidth, int iImageHeight, int iBPP, BYTE *pbySrc) { return GetValue(iX, iY, iImageWidth, iImageHeight, RCHANNEL, iBPP,pbySrc); } int GetValueG(int iX, int iY, int iImageWidth, int iImageHeight, int iBPP, BYTE *pbySrc) { return GetValue(iX, iY, iImageWidth, iImageHeight, GCHANNEL, iBPP, pbySrc); } int GetValueB(int iX, int iY, int iImageWidth, int iImageHeight, int iBPP, BYTE *pbySrc) { return GetValue(iX, iY, iImageWidth, iImageHeight, BCHANNEL, iBPP, pbySrc); }
Here the iX and iY values are the pixel positions
iImageWidth -> Width of the Image
iImageHeight -> Height of the Image
iBPP -> Bytes per pixel ie bitsperPixel/8. For eg. RGB 24 it is 3.
pbySrc -> Address of the Source buffer
Call the GetValueR() for Red value of a pixel, Call the GetValueG() for Green value of a pixel and Call the GetValueB() for Blue value of a pixel from your application.
NB: These functions are applicatoion for interlaced fromat or packed RGB formats and not for the planar formats