// Single Convert ColorRef to RGB public static void ColorToRGB(UniColor color, out RGBDATA bits) { byte[] b; b = BitConverter.GetBytes(((Color)color).ToArgb()); bits.Red = b[2]; bits.Green = b[1]; bits.Blue = b[0]; }
public static UniColor BGRToColor(BGRDATA Bits) { var tibs = new RGBDATA(); tibs.Red = Bits.Red; tibs.Blue = Bits.Blue; tibs.Green = Bits.Green; return(RGBToColor(tibs)); }
// Single Convert ColorRef to RGB-reversed public static void ColorToBGR(UniColor color, out BGRDATA bits) { var tibs = new RGBDATA(); ColorToRGB(color, out tibs); bits.Blue = tibs.Blue; bits.Red = tibs.Red; bits.Green = tibs.Green; }
public static UniColor GetAverageColor(UniColor Color1, UniColor Color2) { var Bits = new RGBDATA[3]; float df; int e; float clr2 = Color2.Value; byte al = Color1.A; byte af = Color2.A; ColorToRGB(Color1, out Bits[0]); ColorToRGB(Color2, out Bits[1]); e = 0; if (Math.Round(clr2) != clr2) { df = Bits[0].Red * clr2; e = (int)Math.Round(df, 0); Bits[2].Red = (byte)(e & 0xFF); df = Bits[0].Green * clr2; e = (int)Math.Round(df, 0); Bits[2].Green = (byte)(e & 0xFF); df = Bits[0].Blue * clr2; e = (int)Math.Round(df, 0); Bits[2].Blue = (byte)(e & 0xFF); } else { df = (Bits[0].Red + (float)Bits[1].Red) / 2f; e = (int)Math.Round(df, 0); Bits[2].Red = (byte)(e & 0xFF); df = (Bits[0].Green + (float)Bits[1].Green) / 2f; e = (int)Math.Round(df, 0); Bits[2].Green = (byte)(e & 0xFF); df = (Bits[0].Blue + (float)Bits[1].Blue) / 2f; e = (int)Math.Round(df, 0); Bits[2].Blue = (byte)(e & 0xFF); } // Get the average alpha al = (byte)((al + af) / 2d); return(new UniColor(al, Bits[2].Red, Bits[2].Green, Bits[2].Blue)); }
public static UniColor SetTone(ref RGBDATA rgbData, float pPercent, UniColor Color = default) { float x; if (Color != default) { ColorToRGB(Color, out rgbData); } x = Max(rgbData.Red, rgbData.Green, rgbData.Blue); if (x == 0f) { rgbData.Red = 0; rgbData.Green = 0; rgbData.Blue = 0; return(UniColor.Empty); } rgbData.Red = (byte)(rgbData.Red / x * (255f * pPercent)); rgbData.Green = (byte)(rgbData.Green / x * (255f * pPercent)); rgbData.Blue = (byte)(rgbData.Blue / x * (255f * pPercent)); return(RGBToColor(rgbData)); }
// Single Convert RGB to ColorRef public static UniColor RGBToColor(RGBDATA bits) { return(Color.FromArgb(255, bits.Red, bits.Green, bits.Blue)); }