Author: mordante
Date: Sun Mar 25 17:23:28 2012
New Revision: 53662
URL: http://svn.gna.org/viewcvs/wesnoth?rev=53662&view=rev
Log:
Add the blend method to wesmage.
Also used the opportunity to better document the blend_surface function.
Modified:
trunk/src/sdl_utils.hpp
trunk/src/wesmage/filter.cpp
Modified: trunk/src/sdl_utils.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/sdl_utils.hpp?rev=53662&r1=53661&r2=53662&view=diff
==============================================================================
--- trunk/src/sdl_utils.hpp (original)
+++ trunk/src/sdl_utils.hpp Sun Mar 25 17:23:28 2012
@@ -287,7 +287,29 @@
/** Cuts a rectangle from a surface. */
surface cut_surface(const surface &surf, SDL_Rect const &r);
-surface blend_surface(const surface &surf, double amount, Uint32 color, bool
optimize=true);
+
+/**
+ * Blends a surface with a colour.
+ *
+ * Every pixel in the surface will be blended with the @p color given. The
+ * final colour of a pixel is amount * @p color + (1 - amount) * original.
+ *
+ * @param surf The surface to blend.
+ * @param amount The amount of the new colour is determined by
+ * @p color. Must be a number in the range
+ * [0, 1].
+ * @param color The colour to blend width, note its alpha
+ * channel is ignored.
+ * @param optimize Should the return surface be RLE optimized.
+ *
+ * @return The blended surface.
+ */
+surface blend_surface(
+ const surface &surf
+ , double amount
+ , Uint32 color
+ , bool optimize = true);
+
surface flip_surface(const surface &surf, bool optimize=true);
surface flop_surface(const surface &surf, bool optimize=true);
surface create_compatible_surface(const surface &surf, int width = -1, int
height = -1);
Modified: trunk/src/wesmage/filter.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/wesmage/filter.cpp?rev=53662&r1=53661&r2=53662&view=diff
==============================================================================
--- trunk/src/wesmage/filter.cpp (original)
+++ trunk/src/wesmage/filter.cpp Sun Mar 25 17:23:28 2012
@@ -153,6 +153,39 @@
"colour channel is multiplied by this value. Value less than
zero "
"are set to zero. The alpha channel is not modified.");
+static void
+blend(surface& surf, const std::string& parameters)
+{
+ float amount;
+ unsigned colour;
+ const int count = sscanf(parameters.c_str(), "%f,%x", &amount, &colour);
+
+ if(count != 2) {
+ std::cerr << "Error: Arguments to blend »"
+ << parameters
+ << "« are not compatible.\n";
+
+ throw texit(EXIT_FAILURE);
+ }
+
+ surf = blend_surface(surf, amount, colour);
+}
+REGISTER(blend,
+"|Blends an image with another colour."
+"|amount"
+ "|float"
+ "|The amount every pixel needs to be blended with its original value. "
+ "The formula is:\n"
+ "result = amount * colour + (1 - amount) * original\n"
+ "The value needs to be in the range [0, 1]."
+"|colour"
+ "|unsigned"
+ "|The colour to blend with. The value should be given as 32-bit "
+ "hexadecimal value. The first fields should look like AARRGGBB,
"
+ "where AA is the alpha channel, RR is the red channel, GG is
the "
+ "green channel and BB is the blue channel. (Note the alpha
channel "
+ "is ignored.");
+
void
filter_apply(surface& surf, const std::string& filter)
{
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits