FilterPixel
Script function

world.FilterPixel

DOC_scripting Read about scripting

Type

Method

Summary

Performs a filtering operation on one pixel

Prototype

long FilterPixel(long Pixel, short Operation, double Options);

DOC_data_types View list of data type meanings


Description

This applies the specified filtering operation to the pixel supplied (an RGB code).

This does largely the same thing as WindowFilter, except it operates on a single pixel (that is, a single RGB colour). This does the same operations (with the same codes as for WindowFilter) excepting the ones which require more than one pixel (like Blur, Sharpen, Find Edges, and Emboss).


Operation - the filter operation. At present, one of:

1 - Apply colour noise

2 - Apply monochrome noise

7 - Adjust Brightness (by adding Options to the pixel)

8 - Adjust Contrast

9 - Adjust Gamma

10 - Adjust Brightness for red channel only (by adding Options to the 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 the 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 the 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 the pixel)

22 - Adjust Brightness for red channel only (by multiplying Options by the pixel)

23 - Adjust Brightness for green channel only (by multiplying Options by the pixel)

24 - Adjust Brightness for blue channel only (by multiplying Options by the pixel)

27 - Average - the pixel's average colour (that is, itself)


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 value, 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 Brightness (additive) filter:

A number from -255 to +255 to indicate the amount to increase (or decrease) the value of the 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 the 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 the 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 the 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.


For more information, see:

http://www.gammon.com.au/mushclient/mw_images.htm



Lua example

-- Brightness

FilterPixel (0x445566, 7, -4) -- lower by 4 (gives 0x405162)
FilterPixel (0x445566, 7, 10) -- raise by 10 (gives 0x4e5f70)

FilterPixel (0x445566, 21, 0.5) -- halve the brightness (gives 0x222a33)
FilterPixel (0x445566, 21, 2) -- double the brightness (gives 0x88aacc)


-- Contrast

FilterPixel (0x445566, 8, 0.5) -- reduce (gives 0x626a73)
FilterPixel (0x445566, 8, 2) -- increase (gives 0x082a4c)


-- Gamma

FilterPixel (0x445566, 9, 0.3) -- brighter, lower contrast (gives 0xabb7c1)
FilterPixel (0x445566, 9, 1.5) -- darker, higher contrast (gives 0x233140)
FilterPixel (0x445566, 9, 5)   -- very dark and contrasty (gives 0x000102)



Return value

-1 : filter mode not in the list above.

Otherwise, the filtered pixel as an RGB code




See Also ...

Topics

DOC_scripting Scripting
DOC_utils Utilities

Functions

FNC_AddFont AddFont (Adds a custom font for use by MUSHclient)
FNC_Base64Decode Base64Decode (Takes a base-64 encoded string and decodes it.)
FNC_Base64Encode Base64Encode (Encodes a string using base-64 encoding.)
FNC_BlendPixel BlendPixel (Blends a single pixel with another, using a specified blending mode)
FNC_ChangeDir ChangeDir (Changes the MUSHclient working directory)
FNC_CreateGUID CreateGUID (Creates a GUID - Global Unique Identifier)
FNC_EditDistance EditDistance (Returns the Levenshtein Edit Distance between two words)
FNC_ErrorDesc ErrorDesc (Converts a MUSHclient script error code into an human-readable description)
FNC_ExportXML ExportXML (Exports a world item in XML format)
FNC_FixupEscapeSequences FixupEscapeSequences (Converts "escape sequences" like \t to their equivalent codes.)
FNC_FixupHTML FixupHTML (Fixes up text for writing as HTML)
FNC_FlashIcon FlashIcon (Flashes the MUSHclient icon on the Windows taskbar)
FNC_GenerateName GenerateName (Generates a random character name)
FNC_GetClipboard GetClipboard (Gets the clipboard contents)
FNC_GetScriptTime GetScriptTime (Returns the amount of time spent in script routines)
FNC_GetSoundStatus GetSoundStatus (Gets the status of a sound started by PlaySound)
FNC_GetUniqueID GetUniqueID (Creates a unique ID for general use, or for making Plugin IDs)
FNC_GetUniqueNumber GetUniqueNumber (Returns a unique number)
FNC_Hash Hash (Produces a hash (checksum) of a specified piece of text)
FNC_Help Help (Shows help for a script function, or a list of functions)
FNC_ImportXML ImportXML (Imports configuration data in XML format)
FNC_Metaphone Metaphone (Returns the metaphone code for the supplied word)
FNC_MoveMainWindow MoveMainWindow (Move and resize the main MUSHclient window)
FNC_MoveWorldWindow MoveWorldWindow (Move and resize a world window)
FNC_MoveWorldWindowX MoveWorldWindowX (Move and resize a specific world window)
FNC_MtRand MtRand (Returns pseudo-random number using the Mersenne Twister algorithm)
FNC_MtSrand MtSrand (Seed the Mersenne Twister pseudo-random number generator)
FNC_PlaySound PlaySound (Plays a sound using DirectSound)
FNC_ReadNamesFile ReadNamesFile (Loads in a file for generating character names)
FNC_Replace Replace (Replaces one substring with another)
FNC_SetBackgroundColour SetBackgroundColour (Sets a background colour for the output window)
FNC_SetBackgroundImage SetBackgroundImage (Sets a background image for the output window)
FNC_SetClipboard SetClipboard (Sets the clipboard contents)
FNC_SetForegroundImage SetForegroundImage (Sets a foreground image for the output window)
FNC_SetStatus SetStatus (Sets the status line text)
FNC_SetToolBarPosition SetToolBarPosition (Sets the position of the game toolbars on the screen.)
FNC_ShiftTabCompleteItem ShiftTabCompleteItem (Adds an item to the list shown for Shift+Tab completion)
FNC_Simulate Simulate (Simulate input from the MUD, for debugging purposes)
FNC_Sound Sound (Plays a sound)
FNC_StopSound StopSound (Stop playing a sound started by PlaySound)
FNC_StripANSI StripANSI (Strips ANSI colour sequences from a string)
FNC_Trace Trace (Trace mode property)
FNC_TraceOut TraceOut (Outputs the supplied message to the world Trace)
FNC_TranslateDebug TranslateDebug (Sends a debugging message to the localizing translator script)
FNC_TranslateGerman TranslateGerman (Translate German umluat sequences)
FNC_Transparency Transparency (Sets the transparency of the main MUSHclient window under Windows XP)
FNC_Trim Trim (Trims leading and trailing spaces from a string)
FNC_WindowFilter WindowFilter (Performs a filtering operation over part of the miniwindow.)

(Help topic: function=FilterPixel)

DOC_contents Documentation contents page