:) :
0. Any color can be presented as a 3D vector with coordinates (r, g, b)
1. For any w/b color is valid (r == g == b)
2. Any vector has a length
3. Any converted w/b vector has the same length to the original
4. Any pixel of an image has a color
See also[
^]
void convert(CImage* pcImage)
{
ASSERT(pcImage);
int iWidth(pcImage->GetWidth());
int iHeight(pcImage->GetHeight());
if (iWidth && iHeight) {
for (int i = 0; i < iWidth; i++) {
for (int j = 0; j < iHeight; j++) {
COLORREF clrOriginal(pcImage->GetPixel(i, j));
float fR(GET_R(clrOriginal));
float fG(GET_G(clrOriginal));
float fB(GET_B(clrOriginal));
float fWB = sqrt((fR * fR + fG * fG + fB * fB) /3);
pcImage->SetPixel(i, j, RGB(fWB, fWB, fWB));
}
}
}
}