Description
| This takes a copy of the specified rectangle in a miniwindow, filters it according to the operation specified, and replaces the filtered version back in place.
Note that changes to miniwindows will not become visible until the output window is redrawn. This happens when new (visible) lines arrive from the MUD, or if you call WindowShow, or Redraw.
Parameters:
WindowName - the name of an existing miniwindow.
Left, Top, Right, Bottom - describes the rectangle to be filtered.
Operation - the filter operation. At present, one of:
1 - Apply colour noise
2 - Apply monochrome noise
3 - Blur (by comparing 2 pixels on each side)
4 - Sharpen
5 - Find edges
6 - Emboss
7 - Adjust Brightness (by adding Options to each pixel)
8 - Adjust Contrast
9 - Adjust Gamma
10 - Adjust Brightness for red channel only (by adding Options to each pixel)
11 - Adjust Contrast for red channel only
12 - Adjust Gamma for red channel only
13 - Adjust Brightness for green channel only (by adding Options to each pixel)
14 - Adjust Contrast for green channel only
15 - Adjust Gamma for green channel only
16 - Adjust Brightness for blue channel only (by adding Options to each pixel)
17 - Adjust Contrast for blue channel only
18 - Adjust Gamma for blue channel only
19 - Convert to grayscale - mix red/green/blue equally
20 - Convert to grayscale - mix 30% red + 59% green + 11% blue for normal perception
21 - Adjust Brightness (by multiplying Options by each pixel)
22 - Adjust Brightness for red channel only (by multiplying Options by each pixel)
23 - Adjust Brightness for green channel only (by multiplying Options by each pixel)
24 - Adjust Brightness for blue channel only (by multiplying Options by each pixel)
25 - Lesser Blur (by comparing 1 pixel on each side)
26 - Minor Blur (by comparing 1 pixel on each side, taking a smaller amount)
27 - Average - the entire rectangle is set to its average colour
Single channel operations - the modes which specify a single channel (10 to 18, 22 to 24) operate on that colour channel only (red, green or blue) leaving the others untouched. Thus by, say, increasing brightness on the red channel you add to the red pixels, but leave green and blue alone, making the image look redder. However decreasing brightness on the red channel would make the image look more cyan (as cyan is the complementary colour to red).
The complementary colours are:
red / cyan
green / magenta
blue / yellow
Options - filtering options.
For the Noise filter:
A number from about 0 to 255 indicating how much noise to add.
For the Blur, Sharpen, Find Edges and Emboss filters:
0 - both directions
1 - horizontal only
2 - vertical only
For the Brightness (additive) filter:
A number from -255 to +255 to indicate the amount to increase (or decrease) the value of each pixel - by adding. A negative number will make it darker, a positive number will make it brighter.
For the Brightness (multiplicative) filter:
A number which is multiplied by the value of each pixel. A number less than 1 will make it darker, a number greater than 1 will make it brighter. However black (zero) will remain black.
For the Contrast filter:
A number to indicate the amount to multiply by the value of each pixel. Zero will make the picture zero contrast, that is totally grey. If you use 1 the pixel will be normal contrast (as each pixel is multiplied by 1). A value between 0 and 1 will be lower contrast. A value above 1 will increase contrast. Negative numbers will have the effect of making the image look negative.
For the Gamma filter:
A number to indicate the amount of Gamma adjustment. Mathematically each pixel is raised to the power of this number. Thus, a gamma of 1 will result in no change. A gamma of 2 will darken the image somewhat. A gamma of 0.5 will lighten the image. A gamma of zero will make the image totally white.
The difference between gamma and brightness is that increasing brightness simply adds to the value of each pixel, so that black becomes gray, and bright pixel become clipped. Similarly, decreasing brightness means that white pixels become grey, and dark ones are clipped.
However because gamma is a power function, black stays black, and white stays white, with the biggest change in the mid range. A higher gamma value results in a darker image with more contrast. A lower gamma value (between 0 and 1) results in a lighter image with less contrast.
Warning - filtering is quite 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. In addition, most of the filtering operations (except noise) need to do a calculation on a "window" of adjoining pixels (2 on each side of each pixel), effectively multiplying the number of calculations by a further 5.
If possible, apply a filter once, and use the filtered image many times. As you can use miniwindows as image sources for other miniwindows, consider setting up a filtered image once, and then just copying it in when needed (eg. draw an elaborate background once, and then just copy in the result when needed).
See also FilterPixel which filters a single RGB code.
For more information, see:
http://www.gammon.com.au/mushclient/mw_images.htm
Note: Available in version 4.35 onwards.
|
Lua example
| -- Noise
WindowFilter (win, 0, 0, 0, 0, 1, 100) -- colour noise in whole window - level 100
WindowFilter (win, 0, 0, 0, 0, 1, 50) -- colour noise in whole window - level 50
WindowFilter (win, 0, 0, 0, 0, 2, 100) -- monochrome noise in whole window - level 100
-- Blurring
WindowFilter (win, 10, 10, 90, 90, 3, 0) -- blur both directions
WindowFilter (win, 10, 10, 90, 90, 3, 1) -- blur horizontal
WindowFilter (win, 10, 10, 90, 90, 3, 2) -- blur vertical
-- Sharpening
WindowFilter (win, 10, 10, 90, 90, 4, 0) -- sharpen in both directions
-- Edge detection
WindowFilter (win, 10, 10, 90, 90, 5, 0) -- edge detect
-- Emboss
WindowFilter (win, 10, 10, 90, 90, 6, 0) -- emboss
-- Brightness
WindowFilter (win, 10, 10, 90, 90, 7, -100) -- lower by 100
WindowFilter (win, 10, 10, 90, 90, 7, 100) -- raise by 100
WindowFilter (win, 10, 10, 90, 90, 21, 0.5) -- halve the brightness
WindowFilter (win, 10, 10, 90, 90, 21, 2) -- double the brightness
-- Contrast
WindowFilter (win, 10, 10, 90, 90, 8, 0.5) -- reduce
WindowFilter (win, 10, 10, 90, 90, 8, 2) -- increase
WindowFilter (win, 10, 10, 90, 90, 8, 10) -- increase a lot
WindowFilter (win, 10, 10, 90, 90, 8, -2) -- make negative
-- Gamma
WindowFilter (win, 10, 10, 90, 90, 9, 0.3) -- brighter, lower contrast
WindowFilter (win, 10, 10, 90, 90, 9, 1.5) -- darker, higher contrast
WindowFilter (win, 10, 10, 90, 90, 9, 5) -- very dark and contrasty
|