I'm facing a problem while trying to convert a colored image to grey scale image using C++. I think there's a problem in the use of function GetRGB().
Here is the source code and related header file.
void CCorner::RGBToGrayScale(CImage* pIn, CImage* pOut)
{
//
// INPUT:
// CImage* pIn: The input image with 24bit depth
//
// OUTPUT:
// CImage* pOut: The output image. It has ALREADY been initialized
// with the same dimension as the input image (pIN) and
// formatted to 8bit depth (256 gray levels).
//
int height = pIn->GetHeight();
int width = pIn->GetWidth();
int clrOriginal=pIn->GetColorType();
if (height && width){
for(int i=0;i<height;i++){
for(int j=0;j<width;j++){
byte *r,*g,*b;
r=NULL; g=NULL; b=NULL;
bool colors=pIn->GetRGB(i,j,r,g,b);
double newindex = 0.299**r+0.587**g+0.114**b;
pOut->SetIndex(i,j,newindex);
}
}
}
}
While GetRGB() is defined as
virtual BOOL GetRGB(int x, int y, byte* r, byte* g, byte* b)
{ return implementation->GetRGB(x, y, r, g, b); }
Thanks for helping!