void io3d::CGraphics2D::grayscaleArea(int x1, int y1, int x2, int y2)
{
if (x1>x2)
{
switchElems<int>(x1,x2);
}
if (y1>y2)
{
switchElems<int>(y1,y2);
}
unsigned char c;
int next_line = -(x2-x1+1)+m_nNormYPitch;
WORD *pPixel = &m_pBackBuffer[x1+y1*m_nNormYPitch];
for (int y=y1; y<=y2; y++)
{
for (int x=x1; x<=x2; x++)
{
// Los pesos son 0.30, 0.59 y 0.11, pero realizo una aproximación
// Multiplico por 2, 4 y 1. Va incluido en el despl. el bajar G a 5 bits
// Debería dividir por 7, pero hacerlo por 8 es mucho más rápido (aunque se
// oscurece un poco la imagen).
c = ( (CR5(*pPixel)<<1) + (CG6(*pPixel)<<1) + CB5(*pPixel) ) >> 3;
*(pPixel++) = C565(c,c<<1,c);
}
// Reajuste para la siguiente línea
pPixel += next_line;
}
}