+void
+apply_filter_to_surface(SDL_Surface* surface, int filter, Color color)
+{
+if(filter == HORIZONTAL_FLIP_FILTER)
+ {
+ SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
+ SDL_BlitSurface(surface, NULL, sur_copy, NULL);
+ SDL_SetAlpha(sur_copy,0,0);
+
+ SDL_Rect src, dst;
+ src.y = dst.y = 0;
+ src.w = dst.w = 1;
+ src.h = dst.h = sur_copy->h;
+ for(int x = 0; x < sur_copy->w; x++)
+ {
+ src.x = x; dst.x = sur_copy->w - x;
+ SDL_BlitSurface(sur_copy, &src, surface, &dst);
+ }
+
+ SDL_FreeSurface(sur_copy);
+ }
+else if(filter == MASK_FILTER)
+ {
+ SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
+
+ Uint8 r,g,b,a;
+
+ SDL_LockSurface(sur_copy);
+ for(int x = 0; x < sur_copy->w; x++)
+ for(int y = 0; y < sur_copy->h; y++)
+ {
+ SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a);
+ if(a != 0)
+ {
+ putpixel(sur_copy, x,y, color.map_rgba(sur_copy));
+ }
+ }
+ SDL_UnlockSurface(sur_copy);
+
+ SDL_BlitSurface(sur_copy, NULL, surface, NULL);
+ SDL_FreeSurface(sur_copy);
+ }
+}
+