/// <summary> /// Get the difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <param name="l">luma</param> /// <param name="c">chromaticity</param> /// <returns>The difference between Color1 and Color2</returns> public static double GetDeltaE_CMC(ColorLab Color1, ColorLab Color2, double l, double c) { if (Color1.ReferenceWhite.Name != WhitepointName.D65) { nLab1 = Converter.ToLab(Color1, nw); } if (Color2.ReferenceWhite.Name != WhitepointName.D65) { nLab2 = Converter.ToLab(Color2, nw); } var2 = Math.Sqrt(Math.Pow(nLab1.a, 2) + Math.Pow(nLab1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(nLab2.a, 2) + Math.Pow(nLab2.b, 2)); //C2 var4 = Math.Pow(nLab1.a - nLab2.a, 2) + Math.Pow(nLab1.b - nLab2.b, 2) - Math.Pow(var2 - var3, 2); var5 = (var4 < 0) ? 0 : Math.Sqrt(var4); //Delta H var6 = (nLab1.L < 16) ? 0.511 : (nLab1.L * 0.040975) / (1 + nLab1.L * 0.01765); //SL var7 = ((0.0638 * var2) / (1 + 0.0131 * var2)) + 0.638; //SC var8 = Math.Atan2(nLab1.b, nLab1.a); //H1 var8 = (var8 < 0) ? var8 + Pi2 : (var8 >= Pi2) ? var8 - Pi2 : var8; var9 = (var8 <= 6.0213859193804370403867331512857 && var8 >= 2.8623399732707005061548528603213) ? 0.56 + Math.Abs(0.2 * Math.Cos(var8 + 2.9321531433504736892318004910609)) : 0.36 + Math.Abs(0.4 * Math.Cos(var8 + 0.61086523819801535192329176897101)); //T var10 = Math.Sqrt(Math.Pow(var2, 4) / (Math.Pow(var2, 4) + 1900)); //F var11 = var7 * (var10 * var9 + 1 - var10); //SH return(Math.Sqrt(Math.Pow((nLab1.L - nLab2.L) / (l * var6), 2) + Math.Pow((var2 - var3) / (c * var7), 2) + Math.Pow(var5 / var11, 2))); }
/// <summary> /// Get the Hue difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The Hue difference between Color1 and Color2</returns> public static double GetDeltaH_CIE94(ColorLab Color1, ColorLab Color2) { var2 = Math.Sqrt(Math.Pow(Color1.a, 2) + Math.Pow(Color1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(Color2.a, 2) + Math.Pow(Color2.b, 2)); //C2 var1 = Math.Pow(Color1.a - Color2.a, 2) + Math.Pow(Color1.b - Color2.b, 2) - Math.Pow(var2 - var3, 2); return((var1 < 0) ? 0 : Math.Sqrt(var1)); }
public static System.Drawing.Color GetColour(ColorLab c1, ColorLab c2, double countup, int speed = 7, int fadespeed = 15) { speed = 21 - speed; double alpha_seed = countup * fadespeed; if (alpha_seed > 255) alpha_seed = 255; int alpha = (int)Math.Max(0, 255 - alpha_seed); double step = 1.0 / speed; double ratio = (countup - 1) * step; if (ratio > 1) ratio = 1; if (ratio < 0) ratio = 0; double ratio2 = 1 - ratio; double L = ((c1.L * ratio2) + (c2.L * ratio)); double a = ((c1.a * ratio2) + (c2.a * ratio)); double b = ((c1.b * ratio2) + (c2.b * ratio)); //Console.WriteLine("Lab = " + L.ToString() + "," + a.ToString() + "," + b.ToString()); ColorManagment.ColorConverter Converter = new ColorManagment.ColorConverter(); //create a new instance of a ColorConverter ColorLab lab = new ColorLab(L, a, b); //create new Lab color ColorRGB rgb = Converter.ToRGB(lab); //convert to rgb ColorHSV hsv = Converter.ToHSV(rgb); //conver to HSL //Console.WriteLine("hsl.l = " + hsv.V.ToString()); hsv.V *= alpha / 255.0; //darken rgb = Converter.ToRGB(hsv); //convert to rgb //Console.WriteLine("RGB + " + rgb.R.ToString() + "," + rgb.G.ToString() + "," + rgb.B.ToString()); return System.Drawing.Color.FromArgb(255, (int)(rgb.R * 255), (int)(rgb.G * 255), (int)(rgb.B * 255)); }
/// <summary> /// Get the difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The difference between Color1 and Color2</returns> public static double GetDeltaE_CIEDE2000(ColorLab Color1, ColorLab Color2) { var1 = (Color1.L + Color2.L) / 2d; //L_ var2 = Math.Sqrt(Math.Pow(Color1.a, 2) + Math.Pow(Color1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(Color2.a, 2) + Math.Pow(Color2.b, 2)); //C2 var4 = (var2 + var3) / 2d; //C_ var5 = (1 - Math.Sqrt((Math.Pow(var4, 7)) / (Math.Pow(var4, 7) + 6103515625))) / 2d; //G var6 = Color1.a * (1 + var5); //a1' var7 = Color2.a * (1 + var5); //a2' var8 = Math.Sqrt(Math.Pow(var6, 2) + Math.Pow(Color1.b, 2)); //C1' var9 = Math.Sqrt(Math.Pow(var7, 2) + Math.Pow(Color2.b, 2)); //C2' var10 = (var8 + var9) / 2d; //C'_ var11 = Math.Atan2(Color1.b, var6); //h1' var11 = (var11 < 0) ? var11 + Pi2 : (var11 >= Pi2) ? var11 - Pi2 : var11; var12 = Math.Atan2(Color2.b, var7); //h2' var12 = (var12 < 0) ? var12 + Pi2 : (var12 >= Pi2) ? var12 - Pi2 : var12; var13 = (Math.Abs(var11 - var12) > Math.PI) ? (var11 + var12 + Pi2) / 2d : (var11 + var12) / 2d; //H'_ var14 = 1 - 0.17 * Math.Cos(var13 - 0.5236) + 0.24 * Math.Cos(2 * var13) + 0.32 * Math.Cos(3 * var13 + 0.10472) - 0.2 * Math.Cos(4 * var13 - 1.0995574); //T var15 = var12 - var11; //Delta h' var15 = (Math.Abs(var15) > Math.PI && var12 <= var11) ? var15 + Pi2 : (Math.Abs(var15) > Math.PI && var12 > var11) ? var15 - Pi2 : var15; var16 = 2 * Math.Sqrt(var8 * var9) * Math.Sin(var15 / 2d); //Delta H' var17 = 1 + ((0.015 * Math.Pow(var1 - 50, 2)) / (Math.Sqrt(20 + Math.Pow(var1 - 50, 2)))); //SL var18 = 1 + 0.045 * var10; //SC var19 = 1 + 0.015 * var10 * var14; //SH var20 = 1.0471976 * Math.Exp(-Math.Pow((var13 - 4.799655) / 0.436332313, 2)); //Delta O var21 = 2 * Math.Sqrt(Math.Pow(var10, 7) / (Math.Pow(var10, 7) + 6103515625)); //RC var22 = -var21 *Math.Sin(2 *var20); //RT return(Math.Sqrt(Math.Pow((Color2.L - Color1.L) / var17, 2) + Math.Pow((var9 - var8) / var18, 2) + Math.Pow(var16 / var19, 2) + var22 * ((var9 - var8) / var18) * ((var16) / var19))); }
/// <summary> /// Get the Chroma difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The Chroma difference between Color1 and Color2</returns> public static double GetDeltaC_CMC(ColorLab Color1, ColorLab Color2) { if (Color1.ReferenceWhite.Name != WhitepointName.D65) nLab1 = Converter.ToLab(Color1, nw); if (Color2.ReferenceWhite.Name != WhitepointName.D65) nLab2 = Converter.ToLab(Color2, nw); var1 = Math.Sqrt(Math.Pow(nLab1.a, 2) + Math.Pow(nLab1.b, 2)); //C1 var2 = Math.Sqrt(Math.Pow(nLab2.a, 2) + Math.Pow(nLab2.b, 2)); //C2 return var1 - var2; }
/// <summary> /// Get the difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <param name="DiffMethod">The specific way to calculate the difference</param> /// <returns>The difference between Color1 and Color2</returns> public static double GetDeltaE_CIE94(ColorLab Color1, ColorLab Color2, CIE94DifferenceMethod DiffMethod) { var1 = (DiffMethod == CIE94DifferenceMethod.Textiles) ? 2 : 1; //SL var2 = Math.Sqrt(Math.Pow(Color1.a, 2) + Math.Pow(Color1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(Color2.a, 2) + Math.Pow(Color2.b, 2)); //C2 var4 = (DiffMethod == CIE94DifferenceMethod.GraphicArts) ? 0.045 : 0.048; //K1 var5 = (DiffMethod == CIE94DifferenceMethod.GraphicArts) ? 0.015 : 0.014; //K2 var6 = Math.Pow(Color1.a - Color2.a, 2) + Math.Pow(Color1.b - Color2.b, 2) - Math.Pow(var2 - var3, 2); //Delta H return(Math.Sqrt(Math.Pow((Color1.L - Color2.L) / var1, 2) + Math.Pow((var2 - var3) / (1 + var4 * var2), 2) + var6 / Math.Pow((1 + var5 * var2), 2))); }
/// <summary> /// Get the Chroma difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The Chroma difference between Color1 and Color2</returns> public static double GetDeltaC_CMC(ColorLab Color1, ColorLab Color2) { if (Color1.ReferenceWhite.Name != WhitepointName.D65) { nLab1 = Converter.ToLab(Color1, nw); } if (Color2.ReferenceWhite.Name != WhitepointName.D65) { nLab2 = Converter.ToLab(Color2, nw); } var1 = Math.Sqrt(Math.Pow(nLab1.a, 2) + Math.Pow(nLab1.b, 2)); //C1 var2 = Math.Sqrt(Math.Pow(nLab2.a, 2) + Math.Pow(nLab2.b, 2)); //C2 return(var1 - var2); }
public static System.Drawing.Color GetColour(ColorLab c1, ColorLab c2, double ratio) { double ratio2 = 1 - ratio; double L = ((c1.L * ratio2) + (c2.L * ratio)); double a = ((c1.a * ratio2) + (c2.a * ratio)); double b = ((c1.b * ratio2) + (c2.b * ratio)); double alpha = 255 * (1 - (ratio * ratio)); //Console.WriteLine("Lab = " + L.ToString() + "," + a.ToString() + "," + b.ToString()); ColorManagment.ColorConverter Converter = new ColorManagment.ColorConverter(); //create a new instance of a ColorConverter ColorLab lab = new ColorLab(L, a, b); //create new Lab color ColorRGB rgb = Converter.ToRGB(lab); //convert to rgb ColorHSV hsv = Converter.ToHSV(rgb); //conver to HSL //Console.WriteLine("hsl.l = " + hsv.V.ToString()); hsv.V *= alpha / 255.0; //darken rgb = Converter.ToRGB(hsv); //convert to rgb //Console.WriteLine("RGB + " + rgb.R.ToString() + "," + rgb.G.ToString() + "," + rgb.B.ToString()); if (ratio2 == 1.0) Animations.breatheTopPause = true; if (alpha < 0.02) return System.Drawing.Color.FromArgb(0, (int)(rgb.R * 255), (int)(rgb.G * 255), (int)(rgb.B * 255)); return System.Drawing.Color.FromArgb(255, (int)(rgb.R * 255), (int)(rgb.G * 255), (int)(rgb.B * 255)); }
/// <summary> /// Get the Chroma difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The Chroma difference between Color1 and Color2</returns> public static double GetDeltaC_CIE94(ColorLab Color1, ColorLab Color2) { var1 = Math.Sqrt(Math.Pow(Color1.a, 2) + Math.Pow(Color1.b, 2)); //C1 var2 = Math.Sqrt(Math.Pow(Color2.a, 2) + Math.Pow(Color2.b, 2)); //C2 return(var1 - var2); }
/// <summary> /// Get the difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <param name="DiffMethod">The specific way to calculate the difference</param> /// <returns>The difference between Color1 and Color2</returns> public static double GetDeltaE_CIE94(ColorLab Color1, ColorLab Color2, CIE94DifferenceMethod DiffMethod) { var1 = (DiffMethod == CIE94DifferenceMethod.Textiles) ? 2 : 1; //SL var2 = Math.Sqrt(Math.Pow(Color1.a, 2) + Math.Pow(Color1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(Color2.a, 2) + Math.Pow(Color2.b, 2)); //C2 var4 = (DiffMethod == CIE94DifferenceMethod.GraphicArts) ? 0.045 : 0.048; //K1 var5 = (DiffMethod == CIE94DifferenceMethod.GraphicArts) ? 0.015 : 0.014; //K2 var6 = Math.Pow(Color1.a - Color2.a, 2) + Math.Pow(Color1.b - Color2.b, 2) - Math.Pow(var2 - var3, 2);//Delta H return Math.Sqrt(Math.Pow((Color1.L - Color2.L) / var1, 2) + Math.Pow((var2 - var3) / (1 + var4 * var2), 2) + var6 / Math.Pow((1 + var5 * var2), 2)); }
private void Conversion(Color inColor) { Color inColor2 = inColor; if (inColor.IsICCcolor && !inColor.IsPCScolor) { inColor2 = Converter.ToICC(inColor); } if (inColor.Model != ColorModel.CIEXYZ) ColXYZ = Converter.ToXYZ(inColor2, XYZwp); if (inColor.Model != ColorModel.CIELab) ColLab = Converter.ToLab(inColor2, Labwp); if (inColor.Model != ColorModel.CIELuv) ColLuv = Converter.ToLuv(inColor2, Luvwp); if (inColor.Model != ColorModel.CIELCHab) ColLCHab = Converter.ToLCHab(inColor2, LCHabwp); if (inColor.Model != ColorModel.CIELCHuv) ColLCHuv = Converter.ToLCHuv(inColor2, LCHuvwp); if (inColor.Model != ColorModel.CIEYxy) ColYxy = Converter.ToYxy(inColor2, Yxywp); if (inColor.Model != ColorModel.LCH99) ColLCH99 = Converter.ToLCH99(inColor2); if (inColor.Model != ColorModel.LCH99b) ColLCH99b = Converter.ToLCH99b(inColor2); if (inColor.Model != ColorModel.LCH99c) ColLCH99c = Converter.ToLCH99c(inColor2); if (inColor.Model != ColorModel.LCH99d) ColLCH99d = Converter.ToLCH99d(inColor2); if (inColor.Model != ColorModel.DEF) ColDEF = Converter.ToDEF(inColor2); if (inColor.Model != ColorModel.Bef) ColBef = Converter.ToBef(inColor2); if (inColor.Model != ColorModel.BCH) ColBCH = Converter.ToBCH(inColor2); if (inColor.Model != ColorModel.RGB) { if (RGBSpace != RGBSpaceName.ICC) ColRGB = Converter.ToRGB(inColor2, RGBSpace); else ColRGB = (ColorRGB)Converter.ToICC(Converter.ToICC_PCS(inColor2, RGB_ICC), RGB_ICC); } if (inColor.Model != ColorModel.HSV) { if (HSVSpace != RGBSpaceName.ICC) ColHSV = Converter.ToHSV(inColor2, HSVSpace); else ColHSV = (ColorHSV)Converter.ToICC(Converter.ToICC_PCS(inColor2, HSV_ICC), HSV_ICC); } if (inColor.Model != ColorModel.HSL) { if (HSLSpace != RGBSpaceName.ICC) ColHSL = Converter.ToHSL(inColor2, HSLSpace); else ColHSL = (ColorHSL)Converter.ToICC(Converter.ToICC_PCS(inColor2, HSL_ICC), HSL_ICC); } if (inColor.Model != ColorModel.CMY && CMY_ICC != null) ColCMY = (ColorCMY)Converter.ToICC(Converter.ToICC_PCS(inColor2, CMY_ICC), CMY_ICC); if (inColor.Model != ColorModel.CMYK && CMYK_ICC != null) ColCMYK = (ColorCMYK)Converter.ToICC(Converter.ToICC_PCS(inColor2, CMYK_ICC), CMYK_ICC); if (inColor.Model != ColorModel.YCbCr) { if (YCbCrSpace != YCbCrSpaceName.ICC) ColYCbCr = Converter.ToYCbCr(inColor2, YCbCrSpace); else ColYCbCr = (ColorYCbCr)Converter.ToICC(Converter.ToICC_PCS(inColor2, YCbCr_ICC), YCbCr_ICC); } if (inColor.Model != ColorModel.Gray) { if (CMY_ICC != null) ColGray = (ColorGray)Converter.ToICC(Converter.ToICC_PCS(inColor2, Gray_ICC), Gray_ICC); else ColGray = Converter.ToGray(inColor2); } if (!IsXColor(inColor.Model) && XColor_ICC != null) ColX = (ColorX)Converter.ToICC(Converter.ToICC_PCS(inColor2, XColor_ICC), XColor_ICC); FillFields(); }
/// <summary> /// Get the Chroma difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The Chroma difference between Color1 and Color2</returns> public static double GetDeltaC_CIE94(ColorLab Color1, ColorLab Color2) { var1 = Math.Sqrt(Math.Pow(Color1.a, 2) + Math.Pow(Color1.b, 2)); //C1 var2 = Math.Sqrt(Math.Pow(Color2.a, 2) + Math.Pow(Color2.b, 2)); //C2 return var1 - var2; }
/// <summary> /// Get the Hue difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The Hue difference between Color1 and Color2</returns> public static double GetDeltaH_CMC(ColorLab Color1, ColorLab Color2) { if (Color1.ReferenceWhite.Name != WhitepointName.D65) nLab1 = Converter.ToLab(Color1, nw); if (Color2.ReferenceWhite.Name != WhitepointName.D65) nLab2 = Converter.ToLab(Color2, nw); var2 = Math.Sqrt(Math.Pow(nLab1.a, 2) + Math.Pow(nLab1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(nLab2.a, 2) + Math.Pow(nLab2.b, 2)); //C2 var1 = Math.Pow(nLab1.a - nLab2.a, 2) + Math.Pow(nLab1.b - nLab2.b, 2) - Math.Pow(var2 - var3, 2); return (var1 < 0) ? 0 : Math.Sqrt(var1); }
/// <summary> /// Get the Hue difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The Hue difference between Color1 and Color2</returns> public static double GetDeltaH_CIE94(ColorLab Color1, ColorLab Color2) { var2 = Math.Sqrt(Math.Pow(Color1.a, 2) + Math.Pow(Color1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(Color2.a, 2) + Math.Pow(Color2.b, 2)); //C2 var1 = Math.Pow(Color1.a - Color2.a, 2) + Math.Pow(Color1.b - Color2.b, 2) - Math.Pow(var2 - var3, 2); return (var1 < 0) ? 0 : Math.Sqrt(var1); }
/// <summary> /// Get the difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <param name="l">luma</param> /// <param name="c">chromaticity</param> /// <returns>The difference between Color1 and Color2</returns> public static double GetDeltaE_CMC(ColorLab Color1, ColorLab Color2, double l, double c) { if (Color1.ReferenceWhite.Name != WhitepointName.D65) nLab1 = Converter.ToLab(Color1, nw); if (Color2.ReferenceWhite.Name != WhitepointName.D65) nLab2 = Converter.ToLab(Color2, nw); var2 = Math.Sqrt(Math.Pow(nLab1.a, 2) + Math.Pow(nLab1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(nLab2.a, 2) + Math.Pow(nLab2.b, 2)); //C2 var4 = Math.Pow(nLab1.a - nLab2.a, 2) + Math.Pow(nLab1.b - nLab2.b, 2) - Math.Pow(var2 - var3, 2); var5 = (var4 < 0) ? 0 : Math.Sqrt(var4); //Delta H var6 = (nLab1.L < 16) ? 0.511 : (nLab1.L * 0.040975) / (1 + nLab1.L * 0.01765); //SL var7 = ((0.0638 * var2) / (1 + 0.0131 * var2)) + 0.638; //SC var8 = Math.Atan2(nLab1.b, nLab1.a); //H1 var8 = (var8 < 0) ? var8 + Pi2 : (var8 >= Pi2) ? var8 - Pi2 : var8; var9 = (var8 <= 6.0213859193804370403867331512857 && var8 >= 2.8623399732707005061548528603213) ? 0.56 + Math.Abs(0.2 * Math.Cos(var8 + 2.9321531433504736892318004910609)) : 0.36 + Math.Abs(0.4 * Math.Cos(var8 + 0.61086523819801535192329176897101)); //T var10 = Math.Sqrt(Math.Pow(var2, 4) / (Math.Pow(var2, 4) + 1900)); //F var11 = var7 * (var10 * var9 + 1 - var10); //SH return Math.Sqrt(Math.Pow((nLab1.L - nLab2.L) / (l * var6), 2) + Math.Pow((var2 - var3) / (c * var7), 2) + Math.Pow(var5 / var11, 2)); }
/// <summary> /// Get the difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The difference between Color1 and Color2</returns> public static double GetDeltaE_CIEDE2000(ColorLab Color1, ColorLab Color2) { var1 = (Color1.L + Color2.L) / 2d; //L_ var2 = Math.Sqrt(Math.Pow(Color1.a, 2) + Math.Pow(Color1.b, 2)); //C1 var3 = Math.Sqrt(Math.Pow(Color2.a, 2) + Math.Pow(Color2.b, 2)); //C2 var4 = (var2 + var3) / 2d; //C_ var5 = (1 - Math.Sqrt((Math.Pow(var4, 7)) / (Math.Pow(var4, 7) + 6103515625))) / 2d; //G var6 = Color1.a * (1 + var5); //a1' var7 = Color2.a * (1 + var5); //a2' var8 = Math.Sqrt(Math.Pow(var6, 2) + Math.Pow(Color1.b, 2)); //C1' var9 = Math.Sqrt(Math.Pow(var7, 2) + Math.Pow(Color2.b, 2)); //C2' var10 = (var8 + var9) / 2d; //C'_ var11 = Math.Atan2(Color1.b, var6); //h1' var11 = (var11 < 0) ? var11 + Pi2 : (var11 >= Pi2) ? var11 - Pi2 : var11; var12 = Math.Atan2(Color2.b, var7); //h2' var12 = (var12 < 0) ? var12 + Pi2 : (var12 >= Pi2) ? var12 - Pi2 : var12; var13 = (Math.Abs(var11 - var12) > Math.PI) ? (var11 + var12 + Pi2) / 2d : (var11 + var12) / 2d; //H'_ var14 = 1 - 0.17 * Math.Cos(var13 - 0.5236) + 0.24 * Math.Cos(2 * var13) + 0.32 * Math.Cos(3 * var13 + 0.10472) - 0.2 * Math.Cos(4 * var13 - 1.0995574); //T var15 = var12 - var11; //Delta h' var15 = (Math.Abs(var15) > Math.PI && var12 <= var11) ? var15 + Pi2 : (Math.Abs(var15) > Math.PI && var12 > var11) ? var15 - Pi2 : var15; var16 = 2 * Math.Sqrt(var8 * var9) * Math.Sin(var15 / 2d); //Delta H' var17 = 1 + ((0.015 * Math.Pow(var1 - 50, 2)) / (Math.Sqrt(20 + Math.Pow(var1 - 50, 2)))); //SL var18 = 1 + 0.045 * var10; //SC var19 = 1 + 0.015 * var10 * var14; //SH var20 = 1.0471976 * Math.Exp(-Math.Pow((var13 - 4.799655) / 0.436332313, 2)); //Delta O var21 = 2 * Math.Sqrt(Math.Pow(var10, 7) / (Math.Pow(var10, 7) + 6103515625)); //RC var22 = -var21 * Math.Sin(2 * var20); //RT return Math.Sqrt(Math.Pow((Color2.L - Color1.L) / var17, 2) + Math.Pow((var9 - var8) / var18, 2) + Math.Pow(var16 / var19, 2) + var22 * ((var9 - var8) / var18) * ((var16) / var19)); }
/// <summary> /// Get the difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The difference between Color1 and Color2</returns> public static double GetDeltaE_CIE76(ColorLab Color1, ColorLab Color2) { return(Math.Sqrt(Math.Pow(Color2.L - Color1.L, 2) + Math.Pow(Color2.a - Color1.a, 2) + Math.Pow(Color2.b - Color1.b, 2))); }
private static void DoAnimation() { //return; //WaveTimer.Enabled = false; if (centroids.Count == 0 || Form1.spellText != "") { //LogitechGSDK.LogiLedSetLighting(0, 0, 0); //WaveTimer.Enabled = true; if (Form1.spellText == "" && Form1.useLogitechColours && ((bw_Keysave != null && !bw_Keysave.IsBusy) || (bw_Breathe != null && !bw_Breathe.IsBusy) || (bw_Breathe == null && bw_Keysave == null)) && isAnimated) { //LogitechGSDK.LogiLedSetLighting(0, 0, 0); LogitechGSDK.LogiLedRestoreLighting(); } isAnimated = false; return; } else { isAnimated = true; //calculate the 2 end point colours into LAB space //System.Drawing.Color c1 = Form1.m_startColour; //System.Drawing.Color c2 = Form1.m_endColour; int fadespeed = Form1.m_fadespeed; int gradientspeed = Form1.m_gradientspeed; //ColorManagment.ColorConverter Converter = new ColorManagment.ColorConverter(); //create a new instance of a ColorConverter //ColorRGB rgb1 = new ColorRGB(RGBSpaceName.sRGB, c1.R , c1.G, c1.B ); //create an RGB color //ColorLab lab1 = Converter.ToLab(rgb1); //ColorRGB rgb2 = new ColorRGB(RGBSpaceName.sRGB, c2.R , c2.G, c2.B ); //create an RGB color //ColorLab lab2 = Converter.ToLab(rgb2); //bmp = new Bitmap(21, 6); ColorLab[,] lab1 = new ColorLab[21, 6]; ColorLab[,] lab2 = new ColorLab[21, 6]; for (int x = 0; x < 21; x++) for (int y = 0; y < 6; y++) { distances[x, y] = double.MaxValue; times[x, y] = int.MaxValue; } for (int i = 0; i < centroids.Count; i++) { centroid c = centroids[i]; for (int x = 0; x < 21; x++) for (int y = 0; y < 6; y++) { double distance = Math.Sqrt(((x - c.point.X) * (x - c.point.X) + (y - c.point.Y) * (y - c.point.Y))); distance = Math.Abs(distance) / (Form1.m_distanceFalloff / 2); if (Form1.m_Wave) { distance -= c.countup; distance = Math.Abs(distance); } if ((distance + c.countup) < (Math.Abs(distances[x, y] + times[x,y]))) { distances[x, y] = distance; lab1[x, y] = c.lab1; lab2[x, y] = c.lab2; if (c.countup / 20.0 < times[x, y]) times[x, y] = c.countup / 20.0; } } c.countup++; centroids[i] = c; } bool allBlack = true; try { //bmp = new Bitmap(21, 6); LockBitmap lockBitmap = new LockBitmap(bmp); lockBitmap.LockBits(); for (int x = 0; x < 21; x++) for (int y = 0; y < 6; y++) { double distance = distances[x, y]; System.Drawing.Color colour = System.Drawing.Color.White; if (Form1.m_Wave == true) colour = getColour(lab1[x, y], lab2[x, y], distance + times[x, y] + Math.Pow(distance, Form1.m_WaveSpeed), gradientspeed, fadespeed); else colour = getColour(lab1[x, y], lab2[x, y], distance + times[x, y], gradientspeed, fadespeed * 10); lockBitmap.SetPixel(x, y, colour); if (allBlack && (colour.R > 0 || colour.G > 0 || colour.B > 0)) allBlack = false; } lockBitmap.UnlockBits(); } catch { } finally { } byte[] b = Form1.getLEDGridFromBitmap(bmp); //((Form1)Application.OpenForms[0]).pic1.Image = bmp; //bmp.Save(@"C:\temp\heatmap.png"); Debug.WriteLine("set lighting at " + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString()); LogitechGSDK.LogiLedSetLightingFromBitmap(b); if (allBlack) { centroids.Clear(); } else if (!Form1.m_Wave) { for (int i = centroids.Count - 1; i >= 0; i--) { try { if (centroids[i].countup / 10 > 255 / fadespeed) centroids.RemoveAt(i); } catch { } } } // System.Threading.Thread.Sleep(Form1.m_AnimationSpeed); } //WaveTimer.Enabled = true; }
private void Convert_Button_Click(object sender, EventArgs e) { switch (((Button)sender).Name) { case "RGB_Button": try { if (RGBSpace != RGBSpaceName.ICC) ColRGB = new ColorRGB(RGBSpace, RGB[0], RGB[1], RGB[2]); else ColRGB = new ColorRGB(RGB_ICC, RGB[0], RGB[1], RGB[2]); Conversion(ColRGB); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "XYZ_Button": try { ColXYZ = new ColorXYZ(XYZwp, XYZ[0], XYZ[1], XYZ[2]); Conversion(ColXYZ); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "Lab_Button": try { ColLab = new ColorLab(Labwp, Lab[0], Lab[1], Lab[2]); Conversion(ColLab); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "Luv_Button": try { ColLuv = new ColorLuv(Luvwp, Luv[0], Luv[1], Luv[2]); Conversion(ColLuv); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "Yxy_Button": try { ColYxy = new ColorYxy(Yxywp, Yxy[0], Yxy[1], Yxy[2]); Conversion(ColYxy); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "LCHab_Button": try { ColLCHab = new ColorLCHab(LCHabwp, LCHab[0], LCHab[1], LCHab[2]); Conversion(ColLCHab); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "LCHuv_Button": try { ColLCHuv = new ColorLCHuv(LCHuvwp, LCHuv[0], LCHuv[1], LCHuv[2]); Conversion(ColLCHuv); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "LCH99_Button": try { ColLCH99 = new ColorLCH99(LCH99[0], LCH99[1], LCH99[2]); Conversion(ColLCH99); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "LCH99b_Button": try { ColLCH99b = new ColorLCH99b(LCH99b[0], LCH99b[1], LCH99b[2]); Conversion(ColLCH99b); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "LCH99c_Button": try { ColLCH99c = new ColorLCH99c(LCH99c[0], LCH99c[1], LCH99c[2]); Conversion(ColLCH99c); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "LCH99d_Button": try { ColLCH99d = new ColorLCH99d(LCH99d[0], LCH99d[1], LCH99d[2]); Conversion(ColLCH99d); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "HSV_Button": try { if (HSVSpace != RGBSpaceName.ICC) ColHSV = new ColorHSV(HSVSpace, HSV[0], HSV[1], HSV[2]); else ColHSV = new ColorHSV(HSV_ICC, HSV[0], HSV[1], HSV[2]); Conversion(ColHSV); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "HSL_Button": try { if (HSLSpace != RGBSpaceName.ICC) ColHSL = new ColorHSL(HSLSpace, HSL[0], HSL[1], HSL[2]); else ColHSL = new ColorHSL(HSL_ICC, HSL[0], HSL[1], HSL[2]); Conversion(ColHSL); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "CMY_Button": try { ColCMY = new ColorCMY(CMY_ICC, CMY[0], CMY[1], CMY[2]); Conversion(ColCMY); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "CMYK_Button": try { ColCMYK = new ColorCMYK(CMYK_ICC, CMYK[0], CMYK[1], CMYK[2], CMYK[3]); Conversion(ColCMYK); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "Gray_Button": try { if (Gray_ICC != null) ColGray = new ColorGray(Gray_ICC, Gray[0]); else ColGray = new ColorGray(Gray[0]); Conversion(ColGray); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "YCbCr_Button": try { if (YCbCrSpace == YCbCrSpaceName.ICC) ColYCbCr = new ColorYCbCr(YCbCr_ICC, YCbCr[0], YCbCr[1], YCbCr[2]); else ColYCbCr = new ColorYCbCr(YCbCrSpace, YCbCr[0], YCbCr[1], YCbCr[2]); Conversion(ColYCbCr); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "XColor_Button": try { ColX = new ColorX(XColor_ICC, XColor.Take(XColor_Channels).ToArray()); Conversion(ColX); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "DEF_Button": try { ColDEF = new ColorDEF(DEFwp, DEF[0], DEF[1], DEF[2]); Conversion(ColDEF); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "Bef_Button": try { ColBef = new ColorBef(Befwp, Bef[0], Bef[1], Bef[2]); Conversion(ColBef); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; case "BCH_Button": try { ColBCH = new ColorBCH(BCHwp, BCH[0], BCH[1], BCH[2]); Conversion(ColBCH); } catch (FormatException) { MessageBox.Show("Not a number!"); } catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); } break; } }
/// <summary> /// Get the difference between two colors /// </summary> /// <param name="Color1">First color</param> /// <param name="Color2">Second color</param> /// <returns>The difference between Color1 and Color2</returns> public static double GetDeltaE_CIE76(ColorLab Color1, ColorLab Color2) { return Math.Sqrt(Math.Pow(Color2.L - Color1.L, 2) + Math.Pow(Color2.a - Color1.a, 2) + Math.Pow(Color2.b - Color1.b, 2)); }