Written by Nick Gammon - July 2008. Updated September 2010.
On this page:
See also:
Blending is a way of loading an image on top of an existing portion of a miniwindow (or all of it). You can specify two things when blending:
Before images can be blended to the miniwindow, the image must be "loaded". See Getting started with images - loading the image for how to do this.
WindowBlendImage function prototype:
long WindowBlendImage(BSTR Name, BSTR ImageId, long Left, long Top, long Right, long Bottom, short Mode, double Opacity, long SrcLeft, long SrcTop, long SrcRight, long SrcBottom);
This blends the specified image into the miniwindow, on top of the specified rectangle.
Value | Purpose | Lua symbol |
---|---|---|
1 | Normal | |
2 | Average | |
3 | Interpolate | |
4 | Dissolve | |
5 | Darken | |
6 | Multiply | |
7 | Colour Burn | |
8 | Linear Burn | |
9 | Inverse Colour Burn | |
10 | Subtract | |
11 | Lighten | |
12 | Screen | |
13 | Colour Dodge | |
14 | Linear Dodge | |
15 | Inverse Colour Dodge | |
16 | Add | |
17 | Overlay | |
18 | Soft Light | |
19 | Hard Light | |
20 | Vivid Light | |
21 | Linear Light | |
22 | Pin Light | |
23 | Hard Mix | |
24 | Difference | |
25 | Exclusion | |
26 | Reflect | |
27 | Glow | |
28 | Freeze | |
29 | Heat | |
30 | Negation | |
31 | Phoenix | |
32 | Stamp | |
33 | Xor | |
34 | And | |
35 | Or | |
36 | Red | |
37 | Green | |
38 | Blue | |
39 | Yellow | |
40 | Cyan | |
41 | Magenta | |
42 | Green limited by red | |
43 | Green limited by blue | |
44 | Green limited by average of red and blue | |
45 | Blue limited by red | |
46 | Blue limited by green | |
47 | Blue limited by average of red and green | |
48 | Red limited by green | |
49 | Red limited by blue | |
50 | Red limited by average of green and blue | |
51 | Red only | |
52 | Green only | |
53 | Blue only | |
54 | Discard red | |
55 | Discard green | |
56 | Discard blue | |
57 | All red | |
58 | All green | |
59 | All blue | |
60 | Hue mode | |
61 | Saturation mode | |
62 | Colour mode | |
63 | Luminance mode | |
64 | HSL |
When blending, whichever rectangle is smaller is the one used for the width and height of the operation (the destination rectangle or the source rectangle).
WindowBlendImage (win, "im", 0, 0, 0, 0, miniwin.blend_normal, 0.5) --normal mode at 50% opacity
Base image (in miniwindow) | Blend image (mentioned in WindowBlendImage) |
---|---|
![]() |
![]() |
Normal mode is a straight copy of each pixel from the blend to the base layer. If opacity is 100% then you will only see the blend image. The only point of using normal mode is if you have the opacity at less than 100%.
25% opacity
50% opacity
75% opacity
In these examples you can see how increasing the opacity makes more and more of the blended image appear on top of the base image. Note that the base "image" doesn't have to be literally a picture, it is whatever text, shapes or other graphics are in the destination rectangle in the miniwindow.
Some blend modes are commutative - that is, blending A on top of B is the same as B on top of A. The descriptions for the various modes will mention when a mode is commutative. Multiply mode is an example of a commutative mode, because the pixel values are multiplied together, and A x B is the same as B x A.
Blending images tends to be computation-expensive. For example, for a 600 x 600 pixel image, the program has to apply a calculation to 600 x 600 x 3 bytes (one for each of red, green and blue), which would be 1,080,000 calculations. There are more calculations needed if you specify an opacity other than 1, as it needs to merge the computed image back on top of the base image. Suggested techniques for keeping things moving quickly are:
Average mode is the same as normal mode with 50% opacity. Effectively, it is an average of both images.
This mode is commutative (base and blend layer can be swapped).
This is similar to average mode, but has better contrast. It uses a cosine calculation for its calculations and is likely to be slower than average mode.
This mode is commutative (base and blend layer can be swapped).
This randomly chooses pixels from the base layer or the blend layer, giving a rather strange speckled look. The number of pixels chosen is controlled by the opacity, at 100% opacity you would only see the blend layer. The example below shows dissolve mode at 50% opacity (an opacity parameter of 0.5):
I got some inspiration and formulae from the Pegtop.net - Blend Modes series of web pages. There is a lengthy description there of the various modes, along with some of the mathematics behind them.
I got quite a few of the C formulae from Photoshop Blend Mode Math web page.
Both of those pages have example images and examples of various blend modes in operation.
The examples on this page are taken from Fields of gold... by Spiralz, and Thanks to solea by jam343. These are licensed for royalty-free use under the Attribution 2.5 Generic License. They were obtained from the web site http://www.everystockphoto.com/.
Some ideas and descriptions were adapated from the Pegtop.net Blend Modes article.
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )