Original Post
Hi, I tried to make some filter applying code, it compiles with no error but if I use a filter it does not look like the example from the internet, except for blurring.
SDL_Surface *applyfilter(double *filter,int w, int h, SDL_Surface *image)
{
SDL_Surface *ret=SDL_CreateRGBSurface(SDL_SWSURFACE,image->w,image->h,24,0,0,0,0);
SDL_LockSurface(ret);
for(int y=0;y<image->h;y++)
{
for(int x=0;x<image->w;x++)
{
int used=0,c=0,d=0;
double sumr=0,sumg=0,sumb=0;
for(int b=y-((h-1)/2);;b++)
{
for(int a=x-((w-1)/2);;a++)
{
if((a>0 && a<image->w)&&(b>0 && b<image->h))
{
used++;
Uint8 red,green,blue;
SDL_GetRGB(GetPixel(image,a,b),image->format,&red,&green,&blue);
sumr+=(int)(red)*filter[c+(d*w)];
sumg+=(int)(green)*filter[c+(d*w)];
sumb+=(int)(blue)*filter[c+(d*w)];
}
c++;
if(c==w)
break;
}
c=0;
d++;
if(d==h)
break;
}
sumr/=used/(w*h);
sumg/=used/(w*h);
sumb/=used/(w*h);
SetPixel(ret,x,y,(int)(sumr+0.5),(int)(sumg+0.5),(int)(sumb+0.5));
}
}
SDL_UnlockSurface(ret);
return ret;
}