Add the blend method to wesmage.
Also used the opportunity to better document the blend_surface function.
This commit is contained in:
parent
81636a48db
commit
6cdad25548
2 changed files with 56 additions and 1 deletions
|
@ -287,7 +287,29 @@ surface blur_alpha_surface(const surface &surf, int depth = 1, bool optimize=tru
|
|||
|
||||
/** 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);
|
||||
|
|
|
@ -153,6 +153,39 @@ REGISTER(brighten,
|
|||
"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)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue