Search FAQ

WindowFilter

Script function

world.WindowFilter

Read about scripting

Type

Method

Summary

Performs a filtering operation over part of the miniwindow.

Prototype

long WindowFilter(BSTR WindowName, long Left, long Top, long Right, long Bottom, short Operation, double Options);

View list of data type meanings

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


Available in MUSHclient 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


Lua notes

You can use the following constants for the Operation argument:

miniwin.filter_noise = 1
miniwin.filter_monochrome_noise = 2
miniwin.filter_blur = 3
miniwin.filter_sharpen = 4
miniwin.filter_find_edges = 5
miniwin.filter_emboss = 6
miniwin.filter_brightness = 7
miniwin.filter_contrast = 8
miniwin.filter_gamma = 9
miniwin.filter_red_brightness = 10
miniwin.filter_red_contrast = 11
miniwin.filter_red_gamma = 12
miniwin.filter_green_brightness = 13
miniwin.filter_green_contrast = 14
miniwin.filter_green_gamma = 15
miniwin.filter_blue_brightness = 16
miniwin.filter_blue_contrast = 17
miniwin.filter_blue_gamma = 18
miniwin.filter_grayscale = 19
miniwin.filter_normal_grayscale = 20
miniwin.filter_brightness_multiply = 21
miniwin.filter_red_brightness_multiply = 22
miniwin.filter_green_brightness_multiply = 23
miniwin.filter_blue_brightness_multiply = 24
miniwin.filter_lesser_blur = 25
miniwin.filter_minor_blur = 26
miniwin.filter_average = 27


Return value

eNoSuchWindow - no such miniwindow

eUnknownOption - filter mode not in the list above

eOK - completed OK

View list of return code meanings

See Also ...

Topic

MiniWindows

Functions

(FilterPixel) Performs a filtering operation on one pixel
(GetDeviceCaps) Gets screen device capabilities
(SetCursor) Changes the shape of the mouse cursor
(TextRectangle) Specifies the size of the rectangle in which text is displayed in the output window.
(WindowAddHotspot) Adds a hotspot to a miniwindow
(WindowArc) Draws an arc in a miniwindow
(WindowBezier) Draws a Bézier curve in a miniwindow
(WindowBlendImage) Blends an image into a miniwindow, using a specified blending mode
(WindowCircleOp) Draws ellipses, filled rectangles, round rectangles, chords, pies in a miniwindow
(WindowCreate) Creates a miniwindow
(WindowCreateImage) Creates an image in a miniwindow
(WindowDelete) Deletes a miniwindow
(WindowDeleteAllHotspots) Deletes all hotspots from a miniwindow
(WindowDeleteHotspot) Deletes a hotspot from a miniwindow
(WindowDragHandler) Adds a drag handler to a miniwindow hotspot
(WindowDrawImage) Draws an image into a miniwindow
(WindowDrawImageAlpha) Draws an image into a miniwindow respecting the alpha channel
(WindowFont) Loads a font into a miniwindow
(WindowFontInfo) Returns information about a font
(WindowFontList) Lists all fonts loaded into a miniwindow
(WindowGetImageAlpha) Draws the alpha channel of an image into a miniwindow
(WindowGetPixel) Gets the colour of a single pixel in a miniwindow
(WindowGradient) Draws a gradient in a rectangle
(WindowHotspotInfo) Returns information about a hotspot
(WindowHotspotList) Lists all hotspots installed into a miniwindow
(WindowHotspotTooltip) Changes the tooltip text for a hotspot in a miniwindow
(WindowImageFromWindow) Creates an image from another miniwindow
(WindowImageInfo) Returns information about an image
(WindowImageList) Lists all images installed into a miniwindow
(WindowImageOp) Draws an ellipse, rectangle or round rectangle, filled with an image
(WindowInfo) Returns information about a miniwindow
(WindowLine) Draws a line in a miniwindow
(WindowList) Lists all miniwindows
(WindowLoadImage) Loads an image into a miniwindow from a disk file
(WindowMenu) Creates a pop-up menu inside a miniwindow
(WindowMergeImageAlpha) Merges an image into a miniwindow based on an alpha mask
(WindowMoveHotspot) Moves a hotspot in a miniwindow
(WindowPolygon) Draws a polygon in a miniwindow
(WindowPosition) Moves a miniwindow
(WindowRectOp) Draws a rectangle in a miniwindow
(WindowResize) Resizes a miniwindow
(WindowScrollwheelHandler) Adds a scroll-wheel handler to a miniwindow hotspot
(WindowSetPixel) Sets a single pixel in a miniwindow to the specified colour
(WindowSetZOrder) Sets the Z-Order for a miniwindow
(WindowShow) Shows or hides a miniwindow
(WindowText) Draws text into a miniwindow
(WindowTextWidth) Calculates the width of text in a miniwindow
(WindowTransformImage) Draws an image into a miniwindow with optional rotation, scaling, reflection and shearing
(WindowWrite) Writes the contents of a miniwindow to disk as a graphics file

(Help topic: function=WindowFilter)

Documentation contents page


Search ...

Enter a search string to find matching documentation.

Search for:   

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.