ColourExtensionMethods
Extension methods for Eto.Drawing.Colour
Methods
public static Color Add(this Color colour, Color overlay)
Add two colours.
Parameters:
| colour (Color) | Base colour. |
| overlay (Color) | Overlay colour. |
Returns: Added colour.
There are four categories of special colour (Analysis, input, output, symbolic) which have four brighnesses in them (XxxxDark, Xxxx, XxxxLight, XxxxShine). This method will change those brightnesses depending on a level adjustment.
Parameters:
| colour (SpecialColour) | |
| level (int) |
public static Color Clip(this Color colour)
Clip the channels of a colour to the 0~1 range.
Parameters:
| colour (Color) | Colour to clip. |
Returns: Clipped colour.
public static Color Composite(this Color bottom, Color top)
Create a new colour which acts as the composite of a background and a foreground colour.
Parameters:
| bottom (Color) | Bottom colour. |
| top (Color) | Top colour. |
Returns: Composited colour.
Create a contrasting colour useful for foreground/background distinction. Contrast colours retain hue but will change luminance.
Parameters:
| colour (Color) | Base colour. |
| contrast (float = 0.8) | Contrast amount (0 to 1). |
Returns: Associated contrast colour.
Decrease the luminance of a colour.
Parameters:
| colour (Color) | Colour to start with. |
| factor (float) | Darkening factor. |
Returns: Darkened colour.
public static Color Desaturate(this Color colour, float amount, LuminanceMetric metric = LuminanceMetric.YCbCrGammaAdjusted)
Desaturate a colour by moving its channels to greyscale values.
Parameters:
| colour (Color) | Colour to desaturate. |
| amount (float) | Desaturation amount. 0=original colour, 1=pure grey. |
| metric (LuminanceMetric = LuminanceMetric.YCbCrGammaAdjusted) | Metric to use. |
Fade a colour to transparency.
Return a gamma-reverted version of this colour. By reverting the gamma, a gamma-adjusted colour is restored into standard sRGB space.
Parameters:
| colour (Color) | Colour to revert. |
| factor (float = 2.2) | Gamma exponent. |
Returns: Gamma reverted version.
Gamma
#Standard sRGB implementation of reverse gamma adjustment.
Gets the hue component (0~360) of a colour.
Parameters:
| colour (Color) |
Compute the luminance of a colour.
Parameters:
| colour (Color) | Colour |
| metric (LuminanceMetric) | Metric to use. |
Returns: Luminance of colour (0.0 to 1.0)
Compute the perceived luminance of a colour using non-linear HSP weighting.
Parameters:
| colour (Color) | Colour. |
Returns: Luminance of colour (0.0 to 1.0)
Gets the saturation component (0~1) of a colour, as defined by the HSB colour model.
Parameters:
| colour (Color) |
Create a negative colour. The alpha channel is not inverted.
Parameters:
| colour (Color) | Base colour. |
| maintainLuminance (bool) | If true, the inversion happens in HSL space, rather than RGB space. |
Returns: Negative colour.
Determines whether a colour qualifies as a dark one, meaning that it requires foreground objects to be of a bright colour.
Parameters:
| colour (Color) |
Increase the luminance of a colour.
Parameters:
| colour (Color) | Colour to start with. |
| factor (float) | Lightening factor. |
Returns: Lightened colour.
Create colour in between this colour and some target colour.
public static Color Multiply(this Color colour, Color overlay)
Multiply two colours. This has the effect of looking at the bottom colour through a piece of coloured glass.
Parameters:
| colour (Color) | Base colour. |
| overlay (Color) | Overlay colour. |
Returns: Multiplied colour.
Multiply a colour.
Parameters:
| colour (Color) | Base colour. |
| factor (float) | Multiplication factor. |
Returns: Multiplied colour.
public static Color MultiplyLinear(this Color colour, Color overlay)
Multiply two colours in LinearRGB. This has the effect of looking at the bottom colour through a piece of coloured glass.
Parameters:
| colour (Color) | Base colour. |
| overlay (Color) | Overlay colour. |
Returns: Multiplied colour.
Add a fixed value to all the channels in a colour.
Parameters:
| colour (Color) | Base colour. |
| amount (float) | Amount to add to each colour channel. |
Returns: Offsetted colour.
Add a fixed value to all the channels in a colour.
public static (Color back, Color fore) Palette(this ProcessState state)
Gets the pair of colours associated with the given process state.
Parameters:
| state (ProcessState) |
Pick a colour out of a palette which is the furthest away from other colours.
Parameters:
| palette (Color[]) | Palette to pick from. |
| colours (IEnumerable<Color>) | Palette to compare against. |
Returns: Colour in 'palette' which is the least like any colour in 'colours'.
public static Color Resolve(this SpecialColour colour, Color background, IconPalette palette = null)
Resolve a colour based on some context.
Parameters:
| colour (SpecialColour) | Colour to resolve. |
| background (Color) | Background. If fully transparent, the OS control background will be substituted. |
| palette (IconPalette = null) | Palette for resolving user-settable colours. If omitted, the standard Grasshopper palette will be substituted. |
Mapping function from colours to the gamma adjusted (exponent = 2.4) RGB cube.
Mapping function from colours to the gamma adjusted (exponent = 2.0) RGB cube.
Mapping function from colours to the sRGB cube.
Mapping function from colours to the HSL cylinder.
Mapping function from colours to the HSP* (perceived luminance) cylinder.
Mapping function from colours to the HSV cylinder.
Mapping function from colours to the Hsl sinusoidal space.
The projection space is a vertical half sine-wave revolved around the world Z axis. Bottom tip (black) resides at (0,0,-1) while the upper tip (white) can be found at (0,0,+1). The central axis from black to white contains all the greyscale values. Luminance is gamma adjusted and mapped along the vertical axis, hue is mapped around the vertical axis and saturation is mapped to an offset from the vertical axis. The offset is the product of the normalised saturation and the sine of the gamma-adjusted luminance.
public static Color Round(this Color colour)
Round a colour to 1/1000th accuracy in each channel.
Parameters:
| colour (Color) | Colour to round. |
Returns: Rounded colour.
Set the luminance of a colour. This method uses HSV luminance metric.
Parameters:
| colour (Color) | Colour to modify. |
| brightness (float) | New luminance (0.0~1.0 range). |
Returns: Modified colour.
Set the hue of a colour.
Parameters:
| colour (Color) | Colour to modify. |
| hue (float) | New hue (0~360 range). |
Returns: Modified colour.
Set the luminance of a colour. This method uses a custom metric and an iterative process.
Parameters:
| colour (Color) | Colour to modify. |
| luminance (float) | New luminance (0.0~1.0 range). |
| metric (LuminanceMetric) | specific metric to use. |
Returns: Modified colour.
Set the luminance of a colour.
Parameters:
| colour (ColorHSL) | Colour to modify. |
| luminance (float) | New luminance (0.0~1.0 range). |
| metric (LuminanceMetric) | specific metric to use. |
Returns: Modified colour.
Set the saturation of a colour. This method uses HSV saturation metric.
Parameters:
| colour (Color) | Colour to modify. |
| saturation (float) | New saturation (0.0~1.0 range). |
Returns: Modified colour.
Sinusoidal_Rgb
#Perform a reverse mapping from sinusoidal coordinates into sRGB coordinates. This conversion may be lossy if the coordinates reside outside the sinusoidal revolved volume.
Create a bitmap filled with this colour.
public static Color ToEto(this Color color)
Convert a GDI+ colour into an Eto colour.
Parameters:
| color (Color) | Color to convert. |
Returns: Eto colour.
public static Color ToGdi(this Color color)
Convert an eto colour into a GDI colour.
Parameters:
| color (Color) | Color to convert. |
Returns: Gdi colour.
Return the name of the colour space without any whitespace or funky characters
Parameters:
| space (Space) |
Return the name of the colour space without any whitespace or funky characters
Parameters:
| space (Space3) |
Return the official name of a colour space including funky characters and whitespace.
Parameters:
| space (Space) |
Return the official name of a colour space including funky characters and whitespace.
Parameters:
| space (Space3) |
Convert a colour so it will be displayed correctly in the UI. This involves optionally removing all alpha data as well as resolving special colours to their stand-in shades.
Parameters:
| colour (Color) | Colour to modify. |
| removeAlpha (bool = true) | If true, the alpha channel is stripped. |
Returns: Colour suitable for display in the UI.
Try to find the named colour in Eto.Drawing.Colors which matches this colour. The pure name is returned, without the 'Eto' or the 'Drawing' or the 'Colors'. This method is fairly slow.
Parameters:
| colour (Color) | Colour to test. |
| name (out string) | Name, if successful. |
Returns: True if a name was found.
Test whether a colour is one of the special colour codes.
Parameters:
| colour (Color) | Colour to test. |
Returns: Special colour identifier if any.
Gets a description suitable for use in the UI for a given special colour.
Parameters:
| colour (SpecialColour) |
Return a gamma-adjusted version of this colour. By adjusting the gamma, the colour is moved into a space where linear blending is more natural.
Parameters:
| colour (Color) | Colour to adjust. |
| factor (float = 2.2) | Gamma exponent. |
Returns: Gamma adjusted version.
Ungamma
#Apply a specific gamma function to a colour channel value.