Class ColorUtils
- Namespace
- OmegaEngine.Foundation.Light
- Assembly
- OmegaEngine.Foundation.dll
Convert colors to different formats, interpolate, invert, ...
public static class ColorUtils
- Inheritance
-
objectColorUtils
Methods
DropAlpha(Color)
Removes the alpha channel from the color (setting it to full opacity).
[Pure]
public static Color DropAlpha(this Color color)
Parameters
colorColor
Returns
EqualsIgnoreAlpha(Color, Color)
Compares two colors ignoring the alpha channel and the name
[Pure]
public static bool EqualsIgnoreAlpha(this Color color1, Color color2)
Parameters
Returns
Interpolate(float, Color, Color)
Interpolates between two colors
[Pure]
public static Color Interpolate(float factor, Color color1, Color color2)
Parameters
factorfloatThe proportion of the two colors between 0 (only first color) and 1 (only second color)
color1ColorThe first color value
color2ColorThe second color value
Returns
InterpolateLinear(float, Color, Color)
Interpolates between two colors in linear space
[Pure]
public static Color InterpolateLinear(float factor, Color color1, Color color2)
Parameters
factorfloatThe proportion of the two colors between 0 (only first color) and 1 (only second color)
color1ColorThe first color value
color2ColorThe second color value
Returns
Remarks
Unlike Interpolate(float, Color, Color) this blends the light intensities the colors represent rather than their gamma-encoded byte values, so the midpoint is the physical average of the two.
LinearToSrgb(Color4)
Converts a color from linear space to sRGB (gamma) encoding, leaving the alpha channel untouched
[Pure]
public static Color4 LinearToSrgb(this Color4 color)
Parameters
colorColor4
Returns
- Color4
LinearToSrgb(float)
Converts a single color channel from linear space to sRGB (gamma) encoding
[Pure]
public static float LinearToSrgb(float value)
Parameters
valuefloatThe linear channel value, usually between 0 and 1
Returns
Remarks
Uses the exact piecewise IEC 61966-2-1 curve, not an approximate pow(value, 1/2.2)
Multiply(Color, float)
Multiplies a color's RGB channels with a scalar factor between 0 and 1, preserving the alpha channel
[Pure]
public static Color Multiply(this Color color, float factor)
Parameters
Returns
MultiplyLinear(Color, float)
Multiplies a color's RGB channels with a scalar factor between 0 and 1 in linear space, preserving the alpha channel
[Pure]
public static Color MultiplyLinear(this Color color, float factor)
Parameters
Returns
Remarks
Unlike Multiply(Color, float) this scales the light intensity the color represents rather than its gamma-encoded byte values, so a factor of 0.5 halves the actual brightness.
SrgbToLinear(Color4)
Converts a color from sRGB (gamma) encoding to linear space, leaving the alpha channel untouched
[Pure]
public static Color4 SrgbToLinear(this Color4 color)
Parameters
colorColor4
Returns
- Color4
SrgbToLinear(Color)
Converts an sRGB-encoded (i.e., as authored) Color to a linear-space SlimDX.Color4
[Pure]
public static Color4 SrgbToLinear(this Color color)
Parameters
colorColor
Returns
- Color4
Remarks
The result must never be converted back to an 8-bit Color: linear values crowd into the bottom of the byte range (sRGB 40 becomes linear 0.0212, i.e. byte 5), destroying precision in the darks. Linearize only at the boundary where the value is handed to the GPU as a float, SlimDX.Color4 or DWORD.
SrgbToLinear(float)
Converts a single color channel from sRGB (gamma) encoding to linear space
[Pure]
public static float SrgbToLinear(float value)
Parameters
valuefloatThe sRGB-encoded channel value, usually between 0 and 1
Returns
Remarks
Uses the exact piecewise IEC 61966-2-1 curve, not an approximate pow(value, 2.2)