1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
void Blur(GTexture::Image *img) {
int i,j,index;
float red, green, blue;
float filter[3][3] = { {1.0,2.0,1.0},
{2.0,4.0f,2.0},
{1.0,2.0,1.0}};
float div = 16.0f;
int size = (img->width) * (img->height) * 4;
for(int a = 0; a < size ; a +=4) {
red = 0;
green = 0;
blue = 0;
for(j=0;j<3;j++)
for(i=0;i<3;i++)
{
index = ( a + ((j-1)*4) ) + (((i-1)*4)*img->height);
index = clamp<int>(index,0,size);
red += (float)img->data[index] * filter[j][i];
green += (float)img->data[index+1] * filter[j][i];
blue += (float)img->data[index+2] * filter[j][i];
}
red /= div;
green /= div;
blue /= div;
red = clamp<int>(red , 0 , 255);
green = clamp<int>(green , 0 , 255);
blue = clamp<int>(blue , 0 , 255);
img->data[a ] = (unsigned char)red;
img->data[a+1] = (unsigned char)green;
img->data[a+2] = (unsigned char)blue;
}
} |
Partager