void io3d::CGraphics2D::blurArea(int x1, int y1, int x2, int y2)
{
if (x1>x2)
{
switchElems<int>(x1,x2);
switchElems<int>(y1,y2);
}
if (y1>y2)
{
switchElems<int>(y1,y2);
}
int _x; // Píxel de la izquierda
int x_; // Píxel de la derecha
int _y; // Píxel de arriba
int y_; // Píxel de abajo
int r;
int g;
int b;
int next_line = -(x2-x1+1)+m_nNormYPitch;
int x;
WORD *pPixel = &m_pBackBuffer[x1+y1*m_nNormYPitch];
// Esquina superior izq.
_x = *pPixel;
x_ = *(pPixel+1);
_y = *(pPixel+1+m_nNormYPitch); // En diagonal abajo-dcha.
y_ = *(pPixel+m_nNormYPitch);
r = (CR5(_x)+CR5(x_)+CR5(_y)+CR5(y_))>>2;
g = (CG6(_x)+CG6(x_)+CG6(_y)+CG6(y_))>>2;
b = (CB5(_x)+CB5(x_)+CB5(_y)+CB5(y_))>>2;
*(pPixel++) = C565(r,g&0xFFFE,b);
// Centro primera fila
for (x=x1+1; x<x2; x++)
{
_x = *(pPixel-1);
x_ = *(pPixel+1);
_y = *pPixel;
y_ = *(pPixel+m_nNormYPitch);
r = (CR5(_x)+CR5(x_)+CR5(_y)+CR5(y_))>>2;
g = (CG6(_x)+CG6(x_)+CG6(_y)+CG6(y_))>>2;
b = (CB5(_x)+CB5(x_)+CB5(_y)+CB5(y_))>>2;
*(pPixel++) = C565(r,g&0xFFFE,b);
}
// Esquina superior dcha.
_x = *(pPixel-1);
x_ = *pPixel;
_y = *(pPixel-m_nNormYPitch);
y_ = *(pPixel-1+m_nNormYPitch); // En diagonal abajo-izq.
r = (CR5(_x)+CR5(x_)+CR5(_y)+CR5(y_))>>2;
g = (CG6(_x)+CG6(x_)+CG6(_y)+CG6(y_))>>2;
b = (CB5(_x)+CB5(x_)+CB5(_y)+CB5(y_))>>2;
*(pPixel++) = C565(r,g&0xFFFE,b);
// Parte central
for (int y=y1+1; y<y2; y++)
{
// Reajuste para la siguiente línea
pPixel += next_line;
// caso de x=x1
_x = *pPixel;
x_ = *(pPixel+1);
_y = *(pPixel-m_nNormYPitch);
y_ = *(pPixel+m_nNormYPitch);
r = (CR5(_x)+CR5(x_)+CR5(_y)+CR5(y_))>>2;
g = (CG6(_x)+CG6(x_)+CG6(_y)+CG6(y_))>>2;
b = (CB5(_x)+CB5(x_)+CB5(_y)+CB5(y_))>>2;
(*pPixel++) = C565(r,g&0xFFFE,b);
// Centro
for (int x=x1+1; x<x2; x++)
{
_x = *(pPixel-1);
x_ = *(pPixel+1);
_y = *(pPixel-m_nNormYPitch);
y_ = *(pPixel+m_nNormYPitch);
r = (CR5(_x)+CR5(x_)+CR5(_y)+CR5(y_))>>2;
g = (CG6(_x)+CG6(x_)+CG6(_y)+CG6(y_))>>2;
b = (CB5(_x)+CB5(x_)+CB5(_y)+CB5(y_))>>2;
*(pPixel++) = C565(r,g&0xFFFE,b); // Optimizará cambiar 0xFFFE por 0xFE ?
}
// caso de x=x2
_x = *(pPixel-1);
x_ = *pPixel;
_y = *(pPixel-m_nNormYPitch);
y_ = *(pPixel+m_nNormYPitch);
r = (CR5(_x)+CR5(x_)+CR5(_y)+CR5(y_))>>2;
g = (CG6(_x)+CG6(x_)+CG6(_y)+CG6(y_))>>2;
b = (CB5(_x)+CB5(x_)+CB5(_y)+CB5(y_))>>2;
*(pPixel++) = C565(r,g&0xFFFE,b);
}
// Reajuste para la siguiente línea
pPixel += next_line;
// Esquina inferior izq.
_x = *pPixel;
x_ = *(pPixel+1);
_y = *(pPixel-m_nNormYPitch);
y_ = *(pPixel+1-m_nNormYPitch); // En diagonal arriba-dcha
r = (CR5(_x)+CR5(x_)+CR5(_y)+CR5(y_))>>2;
g = (CG6(_x)+CG6(x_)+CG6(_y)+CG6(y_))>>2;
b = (CB5(_x)+CB5(x_)+CB5(_y)+CB5(y_))>>2;
*(pPixel++) = C565(r,g&0xFFFE,b);
// Centro última fila
for (x=x1+1; x<x2; x++)
{
_x = *(pPixel-1);
x_ = *(pPixel+1);
_y = *(pPixel-m_nNormYPitch);
y_ = *pPixel;
r = (CR5(_x)+CR5(x_)+CR5(_y)+CR5(y_))>>2;
g = (CG6(_x)+CG6(x_)+CG6(_y)+CG6(y_))>>2;
b = (CB5(_x)+CB5(x_)+CB5(_y)+CB5(y_))>>2;
*(pPixel++) = C565(r,g&0xFFFE,b);
}
// Esquina inferior dcha.
_x = *(pPixel-1);
x_ = *pPixel;
_y = *(pPixel-m_nNormYPitch);
y_ = *(pPixel-1-m_nNormYPitch); // En diagonal arriba-izq.
r = (CR5(_x)+CR5(x_)+CR5(_y)+CR5(y_))>>2;
g = (CG6(_x)+CG6(x_)+CG6(_y)+CG6(y_))>>2;
b = (CB5(_x)+CB5(x_)+CB5(_y)+CB5(y_))>>2;
*(pPixel++) = C565(r,g&0xFFFE,b);
}