27 #define GETTEXT_DOMAIN "wesnoth-lib"
30 #define ERR_DP LOG_STREAM(err, log_display)
31 #define LOG_DP LOG_STREAM(info, log_display)
48 std::vector<modification *> & top_vector = top_pair->second;
51 top_vector.erase(top_vector.begin());
52 if ( top_vector.empty() )
61 for (
const map_type::value_type & pair :
priorities_)
62 count += pair.second.size();
83 std::map<std::string, mod_parser> mod_parsers;
96 if(split.size() != 2) {
97 ERR_DP <<
"error parsing image modifications: "
98 << encoded_mod <<
"\n";
105 if(mod_parsers.find(mod_type) == mod_parsers.end()) {
106 ERR_DP <<
"unknown image function in path: "
111 return (*mod_parsers[mod_type])(args);
117 :
message(message_stream.str())
160 if ( horiz_ && vert_ ) {
180 degrees_ - 360*(degrees_/360) :
181 degrees_ + 360*(1 + (-degrees_)/360);
183 switch ( normalized )
189 case 360:
return src;
232 SDL_Rect area = slice_;
260 std::stringstream sstr;
261 sstr <<
"~BLIT(): x-coordinate '"
262 <<
x_ <<
"' larger than destination image's width '"
263 << src->w <<
"' no blitting performed.\n";
269 std::stringstream sstr;
270 sstr <<
"~BLIT(): y-coordinate '"
271 <<
y_ <<
"' larger than destination image's height '"
272 << src->h <<
"' no blitting performed.\n";
277 if(surf_->w +
x_ > src->w) {
278 std::stringstream sstr;
279 sstr <<
"~BLIT(): offset and width '"
280 <<
x_ + surf_->w <<
"' larger than destination image's width '"
281 << src->w <<
"' no blitting performed.\n";
286 if(surf_->h +
y_ > src->h) {
287 std::stringstream sstr;
288 sstr <<
"~BLIT(): offset and height '"
289 <<
y_ + surf_->h <<
"' larger than destination image's height '"
290 << src->h <<
"' no blitting performed.\n";
320 if(src->w == mask_->w && src->h == mask_->h &&
x_ == 0 &&
y_ == 0)
344 if(src ==
nullptr) {
return nullptr; }
348 if(surf_->w != src->w || surf_->h != src->h)
362 std::pair<int,int> sz = calculate_size(src);
383 const int old_w = src->w;
384 const int old_h = src->h;
390 ERR_DP <<
"width of " << fn_ <<
" is negative - resetting to original width" << std::endl;
396 ERR_DP <<
"height of " << fn_ <<
" is negative - resetting to original height" << std::endl;
401 return std::make_pair(w, h);
406 const int old_w = src->w;
407 const int old_h = src->h;
408 long double w = get_w();
409 long double h = get_h();
413 ERR_DP <<
"width of SCALE_INTO is negative - resetting to original width" << std::endl;
419 ERR_DP <<
"height of SCALE_INTO is negative - resetting to original height" << std::endl;
424 long double ratio = std::min(w / old_w, h / old_h);
426 return std::make_pair(old_w * ratio, old_h * ratio);
451 (r_ != 0 || g_ != 0 ||
b_ != 0) ?
529 SDL_FillRect(ret,
nullptr, SDL_MapRGBA(ret->format,
color_.r,
color_.g,
548 struct parse_mod_registration
550 parse_mod_registration(
const char*
name, mod_parser parser)
552 mod_parsers[
name] = parser;
565 #define REGISTER_MOD_PARSER(type, args_var) \
566 static modification* parse_##type##_mod(const std::string&); \
567 static parse_mod_registration parse_##type##_mod_registration_aux(#type, &parse_##type##_mod); \
568 static modification* parse_##type##_mod(const std::string& args_var) \
575 if(params.size() < 2) {
576 ERR_DP <<
"too few arguments passed to the ~TC() function" << std::endl;
581 int side_n = lexical_cast_default<int>(params[0], -1);
584 ERR_DP <<
"invalid team (" << side_n
585 <<
") passed to the ~TC() function\n";
594 team_color = std::to_string(side_n);
596 ERR_DP <<
"bad things happen" << std::endl;
606 ERR_DP <<
"could not load TC info for '" << params[1]
608 <<
"bailing out from TC\n";
613 std::map<Uint32, Uint32> rc_map;
617 std::vector<Uint32>
const& old_color =
623 ERR_DP <<
"caught config::error while processing TC: "
626 <<
"bailing out from TC\n";
631 return new rc_modification(rc_map);
637 const std::vector<std::string> recolor_params =
utils::split(args,
'>');
639 if(recolor_params.size()>1){
643 std::map<Uint32, Uint32> rc_map;
647 std::vector<Uint32>
const& old_color =
654 <<
"caught config::error while processing color-range RC: "
658 <<
"bailing out from RC\n";
662 return new rc_modification(rc_map);
671 const std::vector<std::string> remap_params =
utils::split(args,
'>');
673 if(remap_params.size() < 2) {
674 ERR_DP <<
"not enough arguments passed to the ~PAL() function: "
682 std::map<Uint32, Uint32> rc_map;
683 std::vector<Uint32>
const& old_palette =
685 std::vector<Uint32>
const& new_palette =
688 for(
size_t i = 0;
i < old_palette.size() &&
i < new_palette.size(); ++
i) {
689 rc_map[old_palette[
i]] = new_palette[
i];
692 return new rc_modification(rc_map);
696 <<
"caught config::error while processing PAL function: "
700 <<
"bailing out from PAL\n";
709 bool horiz = (args.empty() || args.find(
"horiz") != std::string::npos);
710 bool vert = (args.find(
"vert") != std::string::npos);
712 return new fl_modification(horiz, vert);
719 const size_t s = slice_params.size();
723 return new rotate_modification();
726 return new rotate_modification(
727 lexical_cast_default<int>(slice_params[0]));
730 return new rotate_modification(
731 lexical_cast_default<int>(slice_params[0]),
732 lexical_cast_default<int>(slice_params[1]));
735 return new rotate_modification(
736 lexical_cast_default<int>(slice_params[0]),
737 lexical_cast_default<int>(slice_params[1]),
738 lexical_cast_default<int>(slice_params[2]));
747 return new gs_modification;
754 if (params.size() == 1) {
757 if (threshold < 0 || threshold > 255) {
758 ERR_DP <<
"~BW() argument out of range 0 - 255" << std::endl;
762 return new bw_modification(threshold);
766 ERR_DP <<
"unsupported argument in ~BW() function" << std::endl;
771 ERR_DP <<
"~BW() requires exactly one argument" << std::endl;
779 return new sepia_modification;
785 const std::vector<std::string>& params =
utils::split(args,
',');
787 switch (params.size()) {
792 return new negative_modification(-1,-1,-1);
797 if (threshold < -1 || threshold > 255) {
798 ERR_DP <<
"unsupported argument value in ~NEG() function" << std::endl;
802 return new negative_modification(threshold, threshold, threshold);
806 ERR_DP <<
"unsupported argument value in ~NEG() function" << std::endl;
815 if (thresholdRed < -1 || thresholdRed > 255 || thresholdGreen < -1 || thresholdGreen > 255 || thresholdBlue < -1 || thresholdBlue > 255) {
816 ERR_DP <<
"unsupported argument value in ~NEG() function" << std::endl;
820 return new negative_modification(thresholdRed, thresholdGreen, thresholdBlue);
824 ERR_DP <<
"unsupported argument value in ~NEG() function" << std::endl;
829 ERR_DP <<
"~NEG() requires 0, 1 or 3 arguments" << std::endl;
839 return new plot_alpha_modification;
845 return new wipe_alpha_modification;
851 const std::vector<std::string>& params =
utils::split(args,
',');
853 if(params.size() != 1) {
854 ERR_DP <<
"~ADJUST_ALPHA() requires exactly 1 arguments" << std::endl;
860 const size_t p100_pos = opacity_str.find(
'%');
862 if (p100_pos == std::string::npos) {
863 return new adjust_alpha_modification(lexical_cast_default<fixed_t> (opacity_str));
865 float opacity = lexical_cast_default<float>(opacity_str.substr(0,p100_pos)) / 100.0
f;
866 return new adjust_alpha_modification(static_cast<fixed_t> (255 * opacity));
873 std::vector<std::string>
const factors =
utils::split(args,
',');
874 const size_t s = factors.size();
877 ERR_DP <<
"no arguments passed to the ~CS() function" << std::endl;
881 int r = 0,
g = 0,
b = 0;
883 r = lexical_cast_default<int>(factors[0]);
886 g = lexical_cast_default<int>(factors[1]);
889 b = lexical_cast_default<int>(factors[2]);
892 return new cs_modification(r,
g,
b);
898 const std::vector<std::string>& params =
utils::split(args,
',');
900 if(params.size() != 4) {
901 ERR_DP <<
"~BLEND() requires exactly 4 arguments" << std::endl;
905 float opacity = 0.0f;
907 const std::string::size_type p100_pos = opacity_str.find(
'%');
909 if(p100_pos == std::string::npos)
910 opacity = lexical_cast_default<float>(opacity_str);
913 const std::string& parsed_field = opacity_str.substr(0, p100_pos);
914 opacity = lexical_cast_default<float>(parsed_field);
918 return new blend_modification(
919 lexical_cast_default<int>(params[0]),
920 lexical_cast_default<int>(params[1]),
921 lexical_cast_default<int>(params[2]),
929 const size_t s = slice_params.size();
931 if(s == 0 || (s == 1 && slice_params[0].empty())) {
932 ERR_DP <<
"no arguments passed to the ~CROP() function" << std::endl;
936 SDL_Rect slice_rect = { 0, 0, 0, 0 };
938 slice_rect.x = lexical_cast_default<Sint16, const std::string&>(slice_params[0]);
941 slice_rect.y = lexical_cast_default<Sint16, const std::string&>(slice_params[1]);
944 slice_rect.w = lexical_cast_default<Uint16, const std::string&>(slice_params[2]);
947 slice_rect.h = lexical_cast_default<Uint16, const std::string&>(slice_params[3]);
950 return new crop_modification(slice_rect);
956 message <<
" image not found: '" << img.
get_filename() <<
"'\n";
965 const size_t s = param.size();
967 if(s == 0 || (s == 1 && param[0].empty())){
968 ERR_DP <<
"no arguments passed to the ~BLIT() function" << std::endl;
975 x = lexical_cast_default<int>(param[1]);
976 y = lexical_cast_default<int>(param[2]);
980 ERR_DP <<
"negative position arguments in ~BLIT() function" << std::endl;
986 message <<
"~BLIT():";
987 if(!check_image(img, message))
991 return new blit_modification(surf, x,
y);
998 const size_t s = param.size();
1000 if(s == 0 || (s == 1 && param[0].empty())){
1001 ERR_DP <<
"no arguments passed to the ~MASK() function" << std::endl;
1008 x = lexical_cast_default<int>(param[1]);
1009 y = lexical_cast_default<int>(param[2]);
1012 if(x < 0 ||
y < 0) {
1013 ERR_DP <<
"negative position arguments in ~MASK() function" << std::endl;
1019 message <<
"~MASK():";
1020 if(!check_image(img, message))
1024 return new mask_modification(surf, x,
y);
1031 ERR_DP <<
"no arguments passed to the ~L() function" << std::endl;
1037 return new light_modification(surf);
1044 const size_t s = scale_params.size();
1046 if(s == 0 || (s == 1 && scale_params[0].empty())) {
1047 ERR_DP <<
"no arguments passed to the ~SCALE() function" << std::endl;
1053 w = lexical_cast_default<int, const std::string&>(scale_params[0]);
1056 h = lexical_cast_default<int, const std::string&>(scale_params[1]);
1059 return new scale_exact_modification(w,
h,
"SCALE",
false);
1065 const size_t s = scale_params.size();
1067 if(s == 0 || (s == 1 && scale_params[0].empty())) {
1068 ERR_DP <<
"no arguments passed to the ~SCALE_SHARP() function" << std::endl;
1074 w = lexical_cast_default<int, const std::string&>(scale_params[0]);
1077 h = lexical_cast_default<int, const std::string&>(scale_params[1]);
1080 return new scale_exact_modification(w,
h,
"SCALE_SHARP",
true);
1086 const size_t s = scale_params.size();
1088 if(s == 0 || (s == 1 && scale_params[0].empty())) {
1089 ERR_DP <<
"no arguments passed to the ~SCALE_INTO() function" << std::endl;
1095 w = lexical_cast_default<int, const std::string&>(scale_params[0]);
1098 h = lexical_cast_default<int, const std::string&>(scale_params[1]);
1101 return new scale_into_modification(w,
h,
"SCALE_INTO",
false);
1107 const size_t s = scale_params.size();
1109 if(s == 0 || (s == 1 && scale_params[0].empty())) {
1110 ERR_DP <<
"no arguments passed to the ~SCALE_INTO_SHARP() function" << std::endl;
1116 w = lexical_cast_default<int, const std::string&>(scale_params[0]);
1119 h = lexical_cast_default<int, const std::string&>(scale_params[1]);
1122 return new scale_into_modification(w,
h,
"SCALE_INTO_SHARP",
true);
1128 int z = lexical_cast_default<int, const std::string &>(args);
1133 return new xbrz_modification(z);
1141 const int depth = std::max<int>(0, lexical_cast_default<int>(args));
1143 return new bl_modification(
depth);
1149 const std::string::size_type p100_pos = args.find(
'%');
1151 if(p100_pos == std::string::npos)
1152 num = lexical_cast_default<float,const std::string&>(args);
1155 const std::string parsed_field = args.substr(0, p100_pos);
1156 num = lexical_cast_default<float,const std::string&>(parsed_field);
1160 return new o_modification(num);
1170 const int r = lexical_cast_default<int>(args);
1172 return new cs_modification(r,0,0);
1178 const int g = lexical_cast_default<int>(args);
1180 return new cs_modification(0,g,0);
1186 const int b = lexical_cast_default<int>(args);
1188 return new cs_modification(0,0,b);
1206 return new brighten_modification;
1212 return new darken_modification;
1218 int c[4] = { 0, 0, 0, SDL_ALPHA_OPAQUE };
1219 std::vector<std::string> factors =
utils::split(args,
',');
1221 for (
int i = 0; i < std::min<int>(factors.size(), 4); ++
i) {
1222 c[
i] = lexical_cast_default<int>(factors[
i]);
1225 return new background_modification(
create_color(c[0], c[1], c[2], c[3]));
1234 if (params.size() != 3 && params.size() != 4) {
1235 ERR_DP <<
"incorrect number of arguments in ~SWAP() function, they must be 3 or 4" << std::endl;
1239 channel redValue, greenValue, blueValue, alphaValue;
1241 if (params[0] ==
"red") {
1243 }
else if (params[0] ==
"green") {
1245 }
else if (params[0] ==
"blue") {
1247 }
else if (params[0] ==
"alpha") {
1250 ERR_DP <<
"unsupported argument value in ~SWAP() function: " << params[0] << std::endl;
1255 if (params[1] ==
"red") {
1257 }
else if (params[1] ==
"green") {
1259 }
else if (params[1] ==
"blue") {
1261 }
else if (params[1] ==
"alpha") {
1264 ERR_DP <<
"unsupported argument value in ~SWAP() function: " << params[0] << std::endl;
1268 if (params[2] ==
"red") {
1270 }
else if (params[2] ==
"green") {
1272 }
else if (params[2] ==
"blue") {
1274 }
else if (params[2] ==
"alpha") {
1277 ERR_DP <<
"unsupported argument value in ~SWAP() function: " << params[0] << std::endl;
1283 if (params.size() == 3) {
1287 if (params[3] ==
"red") {
1289 }
else if (params[3] ==
"green") {
1291 }
else if (params[3] ==
"blue") {
1293 }
else if (params[3] ==
"alpha") {
1296 ERR_DP <<
"unsupported argument value in ~SWAP() function: " << params[3] << std::endl;
1301 return new swap_modification(redValue, greenValue, blueValue, alphaValue);
surface rotate_any_surface(const surface &surf, float angle, int zoom, int offset, bool optimize)
Rotates a surface by any degrees.
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
surface flip_surface(const surface &surf, bool optimize)
GLint GLenum GLboolean normalized
tformula< unsigned > x_
The x coordinate of the rectangle.
surface rotate_180_surface(const surface &surf, bool optimize)
Rotates a surface 180 degrees.
surface create_neutral_surface(int w, int h)
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
GLint GLint GLsizei GLsizei GLsizei depth
SDL_Color create_color(const unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
const std::vector< Uint32 > & tc_info(const std::string &name)
const surface & get_mask() const
surface create_optimized_surface(const surface &surf)
A modified priority queue used to order image modifications.
bool file_exists() const
Tests whether the file the locater points at exists.
surface recolor_image(surface surf, const std::map< Uint32, Uint32 > &map_rgb, bool optimize)
Recolors a surface using a map with source and converted palette values.
surface rotate_90_surface(const surface &surf, bool clockwise, bool optimize)
Rotates a surface 90 degrees.
#define REGISTER_MOD_PARSER(type, args_var)
A macro for automatic modification parser registration.
surface negative_image(const surface &surf, const int thresholdR, const int thresholdG, const int thresholdB, bool optimize)
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
GLint GLint GLint GLint GLint GLint y
surface scale_surface(const surface &surf, int w, int h)
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
To lexical_cast(From value)
Lexical cast converts one type to another.
Definitions for the interface to Wesnoth Markup Language (WML).
const surface & get_surface() const
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
void push(modification *mod)
Adds mod to the queue (unless mod is nullptr).
void blit_surface(const surface &surf, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect)
Replacement for sdl_blit.
GLdouble GLdouble GLdouble b
STRIP_SPACES : strips leading and trailing blank spaces.
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
virtual std::pair< int, int > calculate_size(const surface &src) const
surface mask_surface(const surface &surf, const surface &mask, bool *empty_result, const std::string &filename)
Applies a mask on a surface.
surface wipe_alpha(const surface &surf, bool optimize)
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
static lg::log_domain log_display("display")
const surface & get_surface() const
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
GLubyte GLubyte GLubyte GLubyte w
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
surface swap_channels_image(const surface &surf, channel r, channel g, channel b, channel a, bool optimize)
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
surface adjust_surface_alpha(const surface &surf, fixed_t amount, bool optimize)
surface blend_surface(const surface &surf, const double amount, const Uint32 color, const bool optimize)
Blends a surface with a color.
virtual int priority() const
Specifies the priority of the modification.
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
surface light_surface(const surface &surf, const surface &lightmap, bool optimize)
Light surf using lightmap.
map_display and display: classes which take care of displaying the map and game-data on the screen...
Base abstract class for an image-path modification.
surface sepia_image(const surface &surf, bool optimize)
GLuint GLuint GLsizei count
surface flop_surface(const surface &surf, bool optimize)
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
static modification_queue decode(const std::string &)
Decodes modifications from a modification string.
const std::string & get_filename() const
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
surface adjust_surface_color(const surface &surf, int red, int green, int blue, bool optimize)
modification * top() const
Returns the top element in the queue .
static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
surface scale_surface_xbrz(const surface &surf, size_t z)
Scale a surface using xBRZ algorithm.
A color range definition is made of four reference RGB colors, used for calculating conversions from ...
float get_opacity() const
GLfloat GLfloat GLfloat GLfloat h
GLint GLint GLint GLint GLint x
tformula< unsigned > y_
The y coordinate of the rectangle.
GLdouble GLdouble GLdouble r
size_t size() const
Returns the number of elements in the queue.
surface blur_alpha_surface(const surface &surf, int depth, bool optimize)
Cross-fades a surface with alpha channel.
GLuint const GLchar * name
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
std::vector< std::string > parenthetical_split(std::string const &val, const char separator, std::string const &left, std::string const &right, const int flags)
Splits a string based either on a separator where text within parenthesis is protected from splitting...
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
Exception thrown by the operator() when an error occurs.
surface make_neutral_surface(const surface &surf)
const color_range & color_info(const std::string &name)
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
this module manages the cache of images.
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
Standard logging facilities (interface).
virtual std::pair< int, int > calculate_size(const surface &src) const
map_type priorities_
Map from a mod's priority() to the mods having that priority.
GLsizei GLenum GLuint GLuint GLsizei char * message
std::map< Uint32, Uint32 > recolor_range(const color_range &new_range, const std::vector< Uint32 > &old_rgb)
Converts a source palette using the specified color_range object.
const SDL_Color & get_color() const
surface alpha_to_greyscale(const surface &surf, bool optimize)
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
surface greyscale_image(const surface &surf, bool optimize)
texception(const std::stringstream &message_stream)
Constructor.
const std::vector< std::string > & get_team_colors()
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.
void pop()
Removes the top element from the queue.
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha)
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
Compatibility layer for using SDL 1.2 and 2.0.
surface scale_surface_sharp(const surface &surf, int w, int h, bool optimize)
Scale a surface using modified nearest neighbour algorithm.
const SDL_Rect & get_slice() const
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
Thrown when a lexical_cast fails.
GLsizei const GLcharARB ** string
virtual surface operator()(const surface &src) const
Applies the image-path modification on the specified surface.
surface cut_surface(const surface &surf, SDL_Rect const &r)
Cuts a rectangle from a surface.
#define ftofxp(x)
IN: float or int - OUT: fixed_t.
surface monochrome_image(const surface &surf, const int threshold, bool optimize)