36 typedef std::function<
void(
77 static std::map<std::string, tfilter>
filters;
84 filters.insert(filter);
100 #define REGISTER(name, description) \
101 tregister_filter register_filter_##name(std::make_pair( \
103 , tfilter(#name, #name description, std::bind(name, _1, _2))));
112 std::cerr <<
"Error: Arguments to scale »"
114 <<
"« are not compatible.\n";
115 throw texit(EXIT_FAILURE);
121 "|Scales the size of an image."
124 "|The width in pixel of the image after scaling."
127 "|The height in pixel of the image after scaling.")
136 std::cerr <<
"Error: Arguments to brighten »"
138 <<
"« are not compatible.\n";
140 throw texit(EXIT_FAILURE);
146 "|Brightens an image."
149 "|The amount the image should be brightened. The value of the every "
150 "color channel is multiplied by this value. Value less than zero "
151 "are set to zero. The alpha channel is not modified.")
154 blend(
surface& surf, const
std::
string& parameters)
158 const int count = sscanf(parameters.c_str(),
"%f,%x", &
amount, &
color);
161 std::cerr <<
"Error: Arguments to blend »"
163 <<
"« are not compatible.\n";
165 throw texit(EXIT_FAILURE);
171 "|Blends an image with another color."
174 "|The amount every pixel needs to be blended with its original value. "
176 "result = amount * color + (1 - amount) * original\n"
177 "The value needs to be in the range [0, 1]."
180 "|The color to blend with. The value should be given as 32-bit "
181 "hexadecimal value. The first fields should look like AARRGGBB, "
182 "where AA is the alpha channel, RR is the red channel, GG is the "
183 "green channel and BB is the blue channel. (Note the alpha channel "
192 std::cerr <<
"Error: Filter »"
194 <<
"« doesn't contain the expected separator »:«\n";
196 throw texit(EXIT_FAILURE);
201 if(itor == filters.end()) {
202 std::cerr <<
"Error: Filter »" << f[0] <<
"« is unknown.\n";
203 throw texit(EXIT_FAILURE);
206 itor->second.functor(surf, f[1]);
214 std::vector<std::string> elements(
utils::split(fmt,
'|'));
217 assert(elements.size() >= 2);
223 assert((elements.size() - 2) % 3 == 0);
225 for(
size_t i = 2;
i < elements.size();
i += 3) {
234 parameters.push_back(parameter);
238 std::vector<tfilter_description>
241 std::vector<tfilter_description>
result;
242 typedef std::pair<std::string, tfilter> thack;
243 for(
const thack& filter : filters) {
244 result.push_back(filter.second.description);
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
GLenum GLenum GLenum GLenum GLenum scale
#define REGISTER(name, description)
Register macro for a filter.
static std::map< std::string, tfilter > filters
The list of the available filters.
static void scale(surface &surf, const std::string ¶meters)
tfilter_description(const std::string &fmt)
Constructor.
std::string name
The name of the filter.
tfilter(const std::string &name__, const std::string &description__, const tfunctor &functor__)
surface scale_surface(const surface &surf, int w, int h)
STRIP_SPACES : strips leading and trailing blank spaces.
Helper structure to describe what a filter does.
tfilter_description description
Description of the filter.
surface blend_surface(const surface &surf, const double amount, const Uint32 color, const bool optimize)
Blends a surface with a color.
tfunctor functor
The functor to call for the filter.
Describes a filter parameter.
GLuint GLuint GLsizei count
const std::string ¶meters float amount
This exception when throw should terminate the application.
std::map< std::string, tfilter >::iterator itor
const std::string & parameters
surface brighten_image(const surface &surf, fixed_t amount, bool optimize)
Contains the definition of a filter.
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
GLuint const GLchar * name
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
std::vector< tfilter_description > filter_list()
Returns the list of available filters.
GLint GLint GLint GLint GLint GLint GLsizei width
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
std::function< void(surface &surf, const std::string ¶meters)> tfunctor
The functor to call for the filter.
void filter_apply(surface &surf, const std::string &filter)
GLsizei const GLcharARB ** string
std::string description
Description of the filter.
Helper structure to register a filter to the filters.
tregister_filter(const std::pair< std::string, tfilter > &filter)