Class ColorUtil
- Namespace
- Vintagestory.API.MathTools
- Assembly
- VintagestoryAPI.dll
Many utility methods and fields for working with colors
public class ColorUtil
- Inheritance
-
ColorUtil
- Inherited Members
- Extension Methods
Fields
BlackArgb
Black opaque rgb color
public static readonly int BlackArgb
Field Value
BlackArgbDouble
White opaque color as normalized float values (0..1)
public static readonly double[] BlackArgbDouble
Field Value
- double[]
BlackArgbVec
Black opaque rgb color
public static readonly Vec4f BlackArgbVec
Field Value
BlackRgbVec
Black opaque rgb color
public static readonly Vec3f BlackRgbVec
Field Value
BrightBits
Amount of bits per block that are available to store the brightness value
public const int BrightBits = 5
Field Value
BrightMul
public const int BrightMul = 8
Field Value
BrightQuantities
public static int BrightQuantities
Field Value
ClearAlpha
~(255 << 24)
public const int ClearAlpha = 16777215
Field Value
HueBits
Amount of bits per block that are available to store the hue value
public const int HueBits = 6
Field Value
HueMul
public const int HueMul = 4
Field Value
HueQuantities
public static int HueQuantities
Field Value
OpaqueAlpha
255 << 24
public const int OpaqueAlpha = -16777216
Field Value
SatBits
Amount of bits per block that are available to store the saturation value
public const int SatBits = 3
Field Value
SatMul
public const int SatMul = 32
Field Value
SatQuantities
public static int SatQuantities
Field Value
WhiteAhsl
White opaque AHSV color
public static readonly int WhiteAhsl
Field Value
WhiteAhsvBytes
White opaque ahsv color as bytes (0..255)
public static readonly byte[] WhiteAhsvBytes
Field Value
- byte[]
WhiteArgb
White opaque argb color
public const int WhiteArgb = -1
Field Value
WhiteArgbBytes
White opaque argb color as bytes (0..255)
public static readonly byte[] WhiteArgbBytes
Field Value
- byte[]
WhiteArgbDouble
White opaque color as normalized float values (0..1)
public static readonly double[] WhiteArgbDouble
Field Value
- double[]
WhiteArgbFloat
White opaque color as normalized float values (0..1)
public static readonly float[] WhiteArgbFloat
Field Value
- float[]
WhiteArgbVec
White opaque color as normalized float values (0..1)
public static readonly Vec4f WhiteArgbVec
Field Value
WhiteRgbVec
White opaque color as normalized float values (0..1)
public static readonly Vec3f WhiteRgbVec
Field Value
Methods
ColorA(int)
Returns alpha value of given color
public static byte ColorA(int color)
Parameters
color
int
Returns
ColorAverage(int[], float[])
Averages several colors together in RGB space
public static int ColorAverage(int[] colors, float[] weights)
Parameters
Returns
ColorB(int)
Returns blue value of given color
public static byte ColorB(int color)
Parameters
color
int
Returns
ColorCombineHSV(int, int, int, int, int, int)
Combines two HSV colors by converting them to rgb then back to hsv. Uses the brightness as a weighting factor. Also leaves the brightness at the max of both hsv colors.
public static int[] ColorCombineHSV(int h1, int s1, int v1, int h2, int s2, int v2)
Parameters
Returns
- int[]
Combined HSV Color
ColorFromRgba(byte[])
public static int ColorFromRgba(byte[] channels)
Parameters
channels
byte[]
Returns
ColorFromRgba(double[])
public static int ColorFromRgba(double[] col)
Parameters
col
double[]
Returns
ColorFromRgba(int, int, int, int)
Care: the returned value is in true RGBA order, not BGRA as used for example by VS particle system. Therefore, depending on use, calling code may need to exchange the r and b parameters to see correct colors rendered in-game.
public static int ColorFromRgba(int r, int g, int b, int a)
Parameters
Returns
ColorFromRgba(Vec4f)
public static int ColorFromRgba(Vec4f colorRel)
Parameters
colorRel
Vec4f
Returns
ColorG(int)
Returns green value of given color
public static byte ColorG(int color)
Parameters
color
int
Returns
ColorMultiply(byte[], byte[])
Multiplies two colors together: c=(a*b)/255
public static byte[] ColorMultiply(byte[] color1, byte[] color2)
Parameters
Returns
- byte[]
ColorMultiply3(int, float)
Multiplies a float value to the rgb color channels, leaves alpha channel unchanged
public static int ColorMultiply3(int color, float multiplier)
Parameters
Returns
ColorMultiply3Clamped(int, float)
Multiplies a float value to the rgb color channels, leaves alpha channel unchanged. Makes sure the multiplied value stays within the 0..255 range
public static int ColorMultiply3Clamped(int color, float multiplier)
Parameters
Returns
ColorMultiply4(int, float)
Multiplies a float value to every color channel including the alpha component.
public static int ColorMultiply4(int color, float multiplier)
Parameters
Returns
ColorMultiply4(int, float, float, float, float)
Multiplies a float value to the rgb color channels
public static int ColorMultiply4(int color, float redMul, float greenMul, float blueMul, float alphaMul)
Parameters
Returns
ColorMultiplyEach(int, int)
Multiplies two colors together c=(a*b)/255
public static int ColorMultiplyEach(int color, int color2)
Parameters
Returns
ColorOver(int, int)
Overlays rgb1 on top of rgb2, based on their alpha values
public static int ColorOver(int rgb1, int rgb2)
Parameters
Returns
ColorOverlay(int, int, float)
Overlays rgb2 over rgb1 When c2weight = 0 resulting color is color1, when c2weight = 1 then resulting color is color2 Resulting color alpha value is 100% color1 alpha
public static int ColorOverlay(int rgb1, int rgb2, float c2weight)
Parameters
Returns
ColorR(int)
Returns red value of given color
public static byte ColorR(int color)
Parameters
color
int
Returns
ColorSubstractHSV(int, int, int, int, int, int)
Removes HSV2 from HSV1 by converting them to rgb then back to hsv. Uses the brightness as a weighting factor. Leaves brightness unchanged.
public static int[] ColorSubstractHSV(int h1, int s1, int v1, int h2, int s2, int v2)
Parameters
Returns
- int[]
ColorToString(int)
Returns human a readable string of given color
public static string ColorToString(int color)
Parameters
color
int
Returns
Doubles2Hex(double[])
public static string Doubles2Hex(double[] color)
Parameters
color
double[]
Returns
FromRGBADoubles(double[])
public static int FromRGBADoubles(double[] rgba)
Parameters
rgba
double[]
Returns
GetIncandescenceColorAsColor4f(int)
public static float[] GetIncandescenceColorAsColor4f(int temperature)
Parameters
temperature
int
Returns
- float[]
GrayscaleColor(byte)
Returns a fully opaque gray color with given brightness
public static int GrayscaleColor(byte brightness)
Parameters
brightness
byte
Returns
HSVa2RGBaBytes(byte[])
Converts given HSVA values into its respective RGBA Representation (all values in range of 0-255) R is the first byte in the resulting array
public static byte[] HSVa2RGBaBytes(byte[] hsva)
Parameters
hsva
byte[]
Returns
- byte[]
Hex2Doubles(string)
Parses a hex string as an rgb(a) color and returns an array of colors normalized fom 0..1 for use with Cairo. E.g. turns #FF0000 into double[1, 0, 0, 1] and #00FF00CC into double[0, 1, 0, 0.8]
public static double[] Hex2Doubles(string hex)
Parameters
hex
string
Returns
- double[]
Hex2Doubles(string, double)
public static double[] Hex2Doubles(string hex, double opacityRel)
Parameters
Returns
- double[]
Hex2Int(string)
Turn a string hex color (with #) into a single int
public static int Hex2Int(string hex)
Parameters
hex
string
Returns
Hsv2Rgb(int)
Converts given HSV value into it's respective RGB Representation (all values in range of 0-255) R is the most significant byte i.e. this is RGB
public static int Hsv2Rgb(int hsv)
Parameters
hsv
int
Returns
Hsv2RgbInts(int, int, int)
Converts given HSV values into its respective RGB representation (all values in range of 0-255) R is the first byte in the resulting array
public static int[] Hsv2RgbInts(int h, int s, int v)
Parameters
Returns
- int[]
HsvToRgb(int, int, int)
Converts given HSV values into it's respective RGB Representation (all values in range of 0-255) R is the most significant byte i.e. this is RGB
public static int HsvToRgb(int h, int s, int v)
Parameters
Returns
HsvToRgba(int, int, int)
Converts given HSB values into it's respective ARGB Representation (all values in range of 0-255, alpha always 255) R is the LEAST significant byte i.e. the result is BGR
public static int HsvToRgba(int h, int s, int v)
Parameters
Returns
HsvToRgba(int, int, int, int)
Converts given HSV values into its respective ARGB Representation (all values in range of 0-255) R is the LEAST significant byte i.e. the result is BGR
public static int HsvToRgba(int h, int s, int v, int a)
Parameters
Returns
Int2Hex(int)
Turn a color int into its string hex version, including preceeding #
public static string Int2Hex(int color)
Parameters
color
int
Returns
Int2HexBGR(int)
public static string Int2HexBGR(int color)
Parameters
color
int
Returns
Int2HexRgba(int)
Turn a color int into its string hex version, including preceeding #, including alpha channel
public static string Int2HexRgba(int color)
Parameters
color
int
Returns
ReverseColorBytes(byte[])
Reverses the RGB channels, but leaves alpha untouched. Basically turns RGBA into BGRA and vice versa
public static byte[] ReverseColorBytes(byte[] color)
Parameters
color
byte[]
Returns
- byte[]
ReverseColorBytes(int)
Reverses the RGB channels, but leaves alpha untouched. Basically turns RGBA into BGRA and vice versa
public static int ReverseColorBytes(int color)
Parameters
color
int
Returns
Rgb2HSv(int)
Converts given RGB value into it's respective HSV Representation (all values in range of 0-255) In the parameter, R is the most significant byte i.e. this is for RGB In the result, V is the LEAST significant byte
public static int Rgb2HSv(int rgb)
Parameters
rgb
int
Returns
Rgb2Hsv(float, float, float)
Converts given RGB values into it's respective HSV Representation (all values in range of 0-255) In the result, V is the MOST significant byte
public static int Rgb2Hsv(float r, float g, float b)
Parameters
Returns
RgbToHsvInts(int, int, int)
Converts given RGB values into it's respective HSV Representation (all values in range of 0-255)
public static int[] RgbToHsvInts(int r, int g, int b)
Parameters
Returns
- int[]
ToBGRABytes(int)
Splits up a 32bit int color into 4 1 byte components, in BGRA order (Alpha channel at the highest 8 bits)
public static byte[] ToBGRABytes(int color)
Parameters
color
int
Returns
- byte[]
ToRGBABytes(int)
Splits up a 32bit int color into 4 1 byte components, in RGBA order
public static byte[] ToRGBABytes(int color)
Parameters
color
int
Returns
- byte[]
ToRGBADoubles(int)
Returns a 4 element rgb double with values between 0..1
public static double[] ToRGBADoubles(int color)
Parameters
color
int
Returns
- double[]
ToRGBAFloats(int)
Returns a 4 element rgb float with values between 0..1
public static float[] ToRGBAFloats(int color)
Parameters
color
int
Returns
- float[]
ToRGBAVec4f(int)
public static Vec4f ToRGBAVec4f(int color)
Parameters
color
int
Returns
ToRGBAVec4f(int, ref Vec4f)
public static Vec4f ToRGBAVec4f(int color, ref Vec4f outVal)
Parameters
Returns
ToRGBVec3f(int, ref Vec3f)
Returns a 4 element rgb float with values between 0..1
public static Vec3f ToRGBVec3f(int color, ref Vec3f outVal)
Parameters
Returns
ToRgba(int, int, int, int)
Pack the 4 color components into a single ARGB 32bit int
public static int ToRgba(int a, int r, int g, int b)
Parameters
Returns
getIncandescenceColor(int)
public static int[] getIncandescenceColor(int temperature)
Parameters
temperature
int
Returns
- int[]