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;
}
Image filter code problem
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.
What example from the internet?
What filter isn't working?
Do you set w and h for the filter correctly?
Any screen shots of the errors?
What filter isn't working?
Do you set w and h for the filter correctly?
Any screen shots of the errors?
Width and height are set propperly. The emboss filter doesn't work:
[-0.5 0 0]
[ 0 1 0]
[ 0 0 0]
And there isn't any error, it's just not an emboss effect, just the image with a really tine hint of emboss and some random colour pixels in it, not like this:
[-0.5 0 0]
[ 0 1 0]
[ 0 0 0]
And there isn't any error, it's just not an emboss effect, just the image with a really tine hint of emboss and some random colour pixels in it, not like this:
That filter kernel you posted doesn't look like an emboss filter. Try using something like this:
[0 -1 -2]
[1 1 -1]
[2 1 0]
[0 -1 -2]
[1 1 -1]
[2 1 0]
For some reason everyone's filters look different, but that one doesn't give me an emboss efect either, I get this:
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement