ColourExtensionMethods

public static class ColourExtensionMethods
Extension methods for Eto.Drawing.Colour

Methods

public static Color Add(this Color colour, Color overlay)
Add two colours.
colour (Color)Base colour.
overlay (Color)Overlay colour.
Added colour.

AdjustLevel

#Example
public static SpecialColour AdjustLevel(this SpecialColour colour, int level)
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.
colour (SpecialColour)
level (int)
public static Color Clip(this Color colour)
Clip the channels of a colour to the 0~1 range.
colour (Color)Colour to clip.
Clipped colour.

Composite

#Example
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.
bottom (Color)Bottom colour.
top (Color)Top colour.
Composited colour.

Contrast

#Example
public static Color Contrast(this Color colour, float contrast = 0.8)
Create a contrasting colour useful for foreground/background distinction. Contrast colours retain hue but will change luminance.
colour (Color)Base colour.
contrast (float = 0.8)Contrast amount (0 to 1).
Associated contrast colour.

Darken

#Example
public static Color Darken(this Color colour, float factor)
Decrease the luminance of a colour.
colour (Color)Colour to start with.
factor (float)Darkening factor.
Darkened colour.

Desaturate

#Example
public static Color Desaturate(this Color colour, float amount, LuminanceMetric metric = LuminanceMetric.YCbCrGammaAdjusted)
Desaturate a colour by moving its channels to greyscale values.
colour (Color)Colour to desaturate.
amount (float)Desaturation amount. 0=original colour, 1=pure grey.
metric (LuminanceMetric = LuminanceMetric.YCbCrGammaAdjusted)Metric to use.
public static Color Fade(this Color colour, float t0, float t1, float t)
Fade a colour to transparency.
colour (Color)Base colour.
t0 (float)Value at which colour becomes completely transparent.
t1 (float)Value at which colour remains fixed.
t (float)Sampling value.
Faded colour.
public static Color Gamma(this Color colour, float factor = 2.2)
Return a gamma-reverted version of this colour. By reverting the gamma, a gamma-adjusted colour is restored into standard sRGB space.
colour (Color)Colour to revert.
factor (float = 2.2)Gamma exponent.
Gamma reverted version.

Gamma

#
public static float Gamma(float value, float factor)
Standard sRGB implementation of reverse gamma adjustment.
value (float)Value to adjust.
factor (float)Gamma exponent. Typical values range from 2.0 to 2.4, but values in between one and two may yield a weak gamma effect worth having.
Adjusted value.

GetHue

#Example
public static float GetHue(this Color colour)
Gets the hue component (0~360) of a colour.
colour (Color)

GetLuminance

#Example
public static float GetLuminance(this Color colour, LuminanceMetric metric)
Compute the luminance of a colour.
colour (Color)Colour
metric (LuminanceMetric)Metric to use.
Luminance of colour (0.0 to 1.0)

GetLuminance

#Example
public static float GetLuminance(this Color colour)
Compute the perceived luminance of a colour using non-linear HSP weighting.
colour (Color)Colour.
Luminance of colour (0.0 to 1.0)

GetSaturation

#Example
public static float GetSaturation(this Color colour)
Gets the saturation component (0~1) of a colour, as defined by the HSB colour model.
colour (Color)

Invert

#Example
public static Color Invert(this Color colour, bool maintainLuminance)
Create a negative colour. The alpha channel is not inverted.
colour (Color)Base colour.
maintainLuminance (bool)If true, the inversion happens in HSL space, rather than RGB space.
Negative colour.

IsDarkBackground

#Example
public static bool IsDarkBackground(this Color colour)
Determines whether a colour qualifies as a dark one, meaning that it requires foreground objects to be of a bright colour.
colour (Color)

Lighten

#Example
public static Color Lighten(this Color colour, float factor)
Increase the luminance of a colour.
colour (Color)Colour to start with.
factor (float)Lightening factor.
Lightened colour.

MoveTo

#Example
public static Color MoveTo(this Color colour, Color target, float factor, bool moveAlpha = true)
Create colour in between this colour and some target colour.
colour (Color)Base colour.
target (Color)Target colour.
factor (float)Motion factor.
moveAlpha (bool = true)If true, alpha channel will also be moved.
Moved colour.

Multiply

#Example
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.
colour (Color)Base colour.
overlay (Color)Overlay colour.
Multiplied colour.

Multiply

#Example
public static Color Multiply(this Color colour, float factor)
Multiply a colour.
colour (Color)Base colour.
factor (float)Multiplication factor.
Multiplied colour.

MultiplyLinear

#Example
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.
colour (Color)Base colour.
overlay (Color)Overlay colour.
Multiplied colour.

Offset

#Example
public static Color Offset(this Color colour, float amount)
Add a fixed value to all the channels in a colour.
colour (Color)Base colour.
amount (float)Amount to add to each colour channel.
Offsetted colour.

Offset

#Example
public static Color Offset(this Color colour, float amountRed, float amountGreen, float amountBlue)
Add a fixed value to all the channels in a colour.
colour (Color)Base colour.
amountRed (float)Amount to add to the red channel.
amountGreen (float)Amount to add to the green channel.
amountBlue (float)Amount to add to the blue channel.
Offsetted colour.

Palette

#Example
public static (Color back, Color fore) Palette(this ProcessState state)
Gets the pair of colours associated with the given process state.
state (ProcessState)

PickLeastAlike

#Example
public static Color PickLeastAlike(this Color[] palette, IEnumerable<Color> colours)
Pick a colour out of a palette which is the furthest away from other colours.
palette (Color[])Palette to pick from.
colours (IEnumerable<Color>)Palette to compare against.
Colour in 'palette' which is the least like any colour in 'colours'.

Resolve

#Example
public static Color Resolve(this SpecialColour colour, Color background, IconPalette palette = null)
Resolve a colour based on some context.
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.

Rgb_CubeGamma

#Example
public static void Rgb_CubeGamma(this Color colour, out double x, out double y, out double z)
Mapping function from colours to the gamma adjusted (exponent = 2.4) RGB cube.
colour (Color)Colour to map.
x (out double)X coordinate.
y (out double)Y coordinate.
z (out double)Z coordinate.

Rgb_CubeSquare

#Example
public static void Rgb_CubeSquare(this Color colour, out double x, out double y, out double z)
Mapping function from colours to the gamma adjusted (exponent = 2.0) RGB cube.
colour (Color)Colour to map.
x (out double)X coordinate.
y (out double)Y coordinate.
z (out double)Z coordinate.

Rgb_CubeStandard

#Example
public static void Rgb_CubeStandard(this Color colour, out double x, out double y, out double z)
Mapping function from colours to the sRGB cube.
colour (Color)Colour to map.
x (out double)X coordinate.
y (out double)Y coordinate.
z (out double)Z coordinate.

Rgb_CylinderHsl

#Example
public static void Rgb_CylinderHsl(this Color colour, out double x, out double y, out double z)
Mapping function from colours to the HSL cylinder.
colour (Color)Colour to map.
x (out double)X coordinate.
y (out double)Y coordinate.
z (out double)Z coordinate.

Rgb_CylinderHsp

#Example
public static void Rgb_CylinderHsp(this Color colour, out double x, out double y, out double z)
Mapping function from colours to the HSP* (perceived luminance) cylinder.
colour (Color)Colour to map.
x (out double)X coordinate.
y (out double)Y coordinate.
z (out double)Z coordinate.

Rgb_CylinderHsv

#Example
public static void Rgb_CylinderHsv(this Color colour, out double x, out double y, out double z)
Mapping function from colours to the HSV cylinder.
colour (Color)Colour to map.
x (out double)X coordinate.
y (out double)Y coordinate.
z (out double)Z coordinate.

Rgb_Sinusoidal

#Example
public static void Rgb_Sinusoidal(this Color colour, out double x, out double y, out double z)
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.

colour (Color)Colour to map.
x (out double)X coordinate.
y (out double)Y coordinate.
z (out double)Z coordinate.
public static Color Round(this Color colour)
Round a colour to 1/1000th accuracy in each channel.
colour (Color)Colour to round.
Rounded colour.

SetBrightness

#Example
public static Color SetBrightness(this Color colour, float brightness)
Set the luminance of a colour. This method uses HSV luminance metric.
colour (Color)Colour to modify.
brightness (float)New luminance (0.0~1.0 range).
Modified colour.

SetHue

#Example
public static Color SetHue(this Color colour, float hue)
Set the hue of a colour.
colour (Color)Colour to modify.
hue (float)New hue (0~360 range).
Modified colour.

SetLuminance

#Example
public static Color SetLuminance(this Color colour, float luminance, LuminanceMetric metric)
Set the luminance of a colour. This method uses a custom metric and an iterative process.
colour (Color)Colour to modify.
luminance (float)New luminance (0.0~1.0 range).
metric (LuminanceMetric)specific metric to use.
Modified colour.

SetLuminance

#Example
public static ColorHSL SetLuminance(this ColorHSL colour, float luminance, LuminanceMetric metric)
Set the luminance of a colour.
colour (ColorHSL)Colour to modify.
luminance (float)New luminance (0.0~1.0 range).
metric (LuminanceMetric)specific metric to use.
Modified colour.

SetSaturation

#Example
public static Color SetSaturation(this Color colour, float saturation)
Set the saturation of a colour. This method uses HSV saturation metric.
colour (Color)Colour to modify.
saturation (float)New saturation (0.0~1.0 range).
Modified colour.

Sinusoidal_Rgb

#
public static Color Sinusoidal_Rgb(double x, double y, double z)
Perform a reverse mapping from sinusoidal coordinates into sRGB coordinates. This conversion may be lossy if the coordinates reside outside the sinusoidal revolved volume.
x (double)
y (double)
z (double)

ToBitmap

#Example
public static Bitmap ToBitmap(this Color color, int width, int height)
Create a bitmap filled with this colour.
color (Color)Colour to fill.
width (int)Width of bitmap.
height (int)Height of bitmap.
Single colour bitmap.
public static Color ToEto(this Color color)
Convert a GDI+ colour into an Eto colour.
color (Color)Color to convert.
Eto colour.
public static Color ToEto(this SpecialColour colour)
Gets the actual ARGB colour which hints at a special colour.
colour (SpecialColour)
public static Color ToGdi(this Color color)
Convert an eto colour into a GDI colour.
color (Color)Color to convert.
Gdi colour.

ToName

#Example
public static string ToName(this Space space)
Return the name of the colour space without any whitespace or funky characters
space (Space)

ToName

#Example
public static string ToName(this Space3 space)
Return the name of the colour space without any whitespace or funky characters
space (Space3)

ToOfficialName

#Example
public static string ToOfficialName(this Space space)
Return the official name of a colour space including funky characters and whitespace.
space (Space)

ToOfficialName

#Example
public static string ToOfficialName(this Space3 space)
Return the official name of a colour space including funky characters and whitespace.
space (Space3)

ToUiColour

#Example
public static Color ToUiColour(this Color colour, bool removeAlpha = true)
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.
colour (Color)Colour to modify.
removeAlpha (bool = true)If true, the alpha channel is stripped.
Colour suitable for display in the UI.

TryMatchEtoColorName

#Example
public static bool TryMatchEtoColorName(this Color colour, out string name)
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.
colour (Color)Colour to test.
name (out string)Name, if successful.
True if a name was found.

TryParseSpecialColour

#Example
public static SpecialColour TryParseSpecialColour(this Color colour)
Test whether a colour is one of the special colour codes.
colour (Color)Colour to test.
Special colour identifier if any.

UiColour

#Example
public static Color UiColour(this SpecialColour colour)
Gets a stand-in colour for the given special colour.
colour (SpecialColour)

UiInfo

#Example
public static string UiInfo(this SpecialColour colour)
Gets a description suitable for use in the UI for a given special colour.
colour (SpecialColour)

UiName

#Example
public static string UiName(this SpecialColour colour)
Gets a name suitable for use in the UI for a given special colour.
colour (SpecialColour)

Ungamma

#Example
public static Color Ungamma(this Color colour, float factor = 2.2)
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.
colour (Color)Colour to adjust.
factor (float = 2.2)Gamma exponent.
Gamma adjusted version.

Ungamma

#
public static float Ungamma(float value, float factor)
Apply a specific gamma function to a colour channel value.
value (float)Value to adjust.
factor (float)Gamma exponent. Typical values range from 2.0 to 2.4, but values in between one and two may yield a weak gamma effect worth having.
Adjusted value.
public static Color WithA(this Color colour, float alpha)
Set the alpha channel of a colour.
colour (Color)Colour to modify.
alpha (float)New alpha value.
Modified colour.