Jump to content
  • Advertisement
Sign in to follow this  
manhaeve

Image filter code problem

This topic is 3620 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}


Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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:

Share this post


Link to post
Share on other sites
For some reason everyone's filters look different, but that one doesn't give me an emboss efect either, I get this:

Share this post


Link to post
Share on other sites
Fixed it (mostly). The RGB values sometimes exceeded 255 or went below zero, I placed some limitation to it and now it gives some sweet effects, ty anyways.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!