/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { double *vs = data.Vars; double *wp = data.OutWP; if (inColor[1] < Const.Delta) { outColor[0] = outColor[1] = outColor[2] = 0; } else { //yr vs[0] = inColor[1] / wp[1]; //uv' tmp vs[1] = 1 / (inColor[0] + 15d * inColor[1] + 3d * inColor[2]); //uv'r tmp vs[2] = 1d / (wp[0] + 15d * wp[1] + 3d * wp[2]); //L if (vs[0] > Const.Epsilon) { outColor[0] = 116d * Math.Pow(vs[0], Const.div1_3) - 16d; } else { outColor[0] = Const.Kappa * vs[0]; } //uv tmp vs[0] = 13d * outColor[0]; outColor[2] = vs[0] * ((9d * inColor[1] * vs[1]) - (9d * wp[1] * vs[2])); //v outColor[1] = vs[0] * ((4d * inColor[0] * vs[1]) - (4d * wp[0] * vs[2])); //u } }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { double *vs = data.Vars; double *wp = data.InWP; vs[0] = 1d / (wp[0] + 15d * wp[1] + 3d * wp[2]); vs[1] = 4d * wp[0] * vs[0]; //u'n vs[2] = 9d * wp[1] * vs[0]; //v'n const double f = 3d / 29d; const double g = f * f * f; if (inColor[0] <= Const.KapEps) { outColor[1] = wp[1] * inColor[0] * g; } else { vs[0] = (inColor[0] + 16d) * (1d / 116d); outColor[1] = wp[1] * vs[0] * vs[0] * vs[0]; } //TODO: if v(<0) and L(~0) are small, there is a problem because of a division with a very small number vs[5] = 13d * inColor[0]; if (vs[5] > Const.Delta) { vs[0] = 1 / vs[5]; vs[3] = (inColor[1] * vs[0]) + vs[1]; //u' vs[4] = (inColor[2] * vs[0]) + vs[2]; //v' vs[0] = 1d / (4d * vs[4]); outColor[0] = outColor[1] * ((9d * vs[3]) * vs[0]); outColor[2] = outColor[1] * ((12d - 3d * vs[3] - 20d * vs[4]) * vs[0]); } else { outColor[0] = outColor[2] = 0; } if (outColor[0] < 0) { outColor[0] = 0; } else if (outColor[0] > 1) { outColor[0] = 1; } if (outColor[2] < 0) { outColor[2] = 0; } else if (outColor[2] > 1) { outColor[2] = 1; } }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { double *vs = data.Vars; outColor[0] = Const.LCH99c_L1 * Math.Log(1 + Const.LCH99c_L2 * inColor[0]); //L vs[0] = Const.LCH99c_f * inColor[2]; //f outColor[1] = Math.Log(1 + Const.LCH99c_CG * Math.Sqrt(inColor[1] * inColor[1] + vs[0] * vs[0])) * Const.LCH99c_Cd; //C outColor[2] = Math.Atan2(vs[0], inColor[1]) * Const.Pi180_1; //H }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { double *vs = data.Vars; vs[0] = inColor[0] * Math.Sin(inColor[1]); outColor[0] = inColor[0] * Math.Sin(Const.Pi2 - inColor[1]); vs[1] = inColor[2] * Const.Pi180; outColor[1] = vs[0] * Math.Cos(vs[1]); outColor[2] = vs[0] * Math.Sin(vs[1]); }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { double *vs = data.Vars; outColor[0] = Const.LCH99b_L1 * Math.Log(1d + Const.LCH99b_L2 * inColor[0]); //L vs[1] = inColor[1] * Const.cos26 + inColor[2] * Const.sin26; //e vs[2] = Const.LCH99b_f * (-inColor[1] * Const.sin26 + inColor[2] * Const.cos26); //f outColor[1] = Math.Log(1d + Const.LCH99b_CG * Math.Sqrt(vs[1] * vs[1] + vs[2] * vs[2])) * Const.LCH99b_Cd; //C outColor[2] = (Math.Atan2(vs[2], vs[1]) * Const.Pi180_1) + Const.LCH99b_angle; //H }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { outColor[0] = Math.Sqrt(inColor[0] * inColor[0] + inColor[1] * inColor[1] + inColor[2] * inColor[2]); if (Math.Abs(outColor[0]) < Const.Delta) { outColor[1] = outColor[2] = 0; } else { outColor[1] = inColor[1] / outColor[0]; outColor[2] = inColor[2] / outColor[0]; } }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { if (inColor[2] < Const.Delta) { outColor[0] = outColor[1] = outColor[2] = 0; } else { double *vs = data.Vars; vs[0] = 1d / inColor[2]; outColor[1] = inColor[0]; outColor[0] = (inColor[1] * inColor[0]) * vs[0]; outColor[2] = ((1 - inColor[1] - inColor[2]) * inColor[0]) * vs[0]; } }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { const double div1_116 = 1 / 116d; const double div1_500 = 1 / 500d; const double div1_200 = 1 / 200d; const double div1_Kappa = 1 / Const.Kappa; double *vs = data.Vars; double *wp = data.InWP; vs[0] = (inColor[0] + 16d) * div1_116; //fy vs[1] = vs[0] + inColor[1] * div1_500; //fx vs[2] = vs[0] - inColor[2] * div1_200; //fz vs[3] = vs[1] * vs[1] * vs[1]; //fx^3 vs[4] = vs[2] * vs[2] * vs[2]; //fz^3 //Y if (inColor[0] > Const.KapEps) { vs[5] = (inColor[0] + 16d) * div1_116; outColor[1] = vs[5] * vs[5] * vs[5] * wp[1]; } else { outColor[1] = inColor[0] * div1_Kappa * wp[1]; } //X if (vs[3] > Const.Epsilon) { outColor[0] = vs[3] * wp[0]; } else { outColor[0] = ((116d * vs[1] - 16d) * div1_Kappa) * wp[0]; } //Z if (vs[4] > Const.Epsilon) { outColor[2] = vs[4] * wp[2]; } else { outColor[2] = ((116d * vs[2] - 16d) * div1_Kappa) * wp[2]; } }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { double *vs = data.Vars; outColor[1] = inColor[1] * inColor[0]; outColor[2] = inColor[2] * inColor[0]; vs[0] = inColor[0] * inColor[0] - outColor[1] * outColor[1] - outColor[2] * outColor[2]; if (vs[0] > 0) { outColor[0] = Math.Sqrt(vs[0]); } else { outColor[0] = 0; } }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { double *vs = data.Vars; //inColor[2]^2 vs[0] = inColor[2] * inColor[2]; //inColor[1]^2 vs[1] = inColor[1] * inColor[1]; //B outColor[0] = Math.Sqrt(inColor[0] * inColor[0] + vs[1] + vs[0]); //C if (Math.Abs(outColor[0]) < Const.Delta) { outColor[1] = 0; } else { outColor[1] = Math.Sqrt(inColor[1] * inColor[1] + vs[0]) / outColor[0]; if (inColor[2] < 0) { outColor[1] = Math.Asin(-outColor[1]); } else { outColor[1] = Math.Asin(outColor[1]); } } //H if (Math.Abs(inColor[1]) < Const.Delta) { outColor[2] = 0; } else { outColor[2] = inColor[1] / Math.Sqrt(vs[1] + vs[0]); if (inColor[2] < 0) { outColor[2] = Math.Acos(-outColor[2]) * Const.Pi180_1; } else { outColor[2] = Math.Acos(outColor[2]) * Const.Pi180_1; } } }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { const double div1_Cd = 1 / Const.LCH99c_Cd; const double div1_CG = 1 / Const.LCH99c_CG; const double div1_f = 1 / Const.LCH99c_f; const double div1_L1 = 1 / Const.LCH99c_L1; const double div1_L2 = 1 / Const.LCH99c_L2; double *vs = data.Vars; vs[0] = (Math.Exp(inColor[1] * div1_Cd) - 1) * div1_CG; //G vs[2] = inColor[2] * Const.Pi180; outColor[1] = vs[0] * Math.Cos(vs[2]); //e vs[1] = vs[0] * Math.Sin(vs[2]); //f outColor[2] = vs[1] * div1_f; outColor[0] = (Math.Exp(inColor[0] * div1_L1) - 1) * div1_L2; }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { const double div1_Cd = 1 / Const.LCH99b_Cd; const double div1_CG = 1 / Const.LCH99b_CG; const double div1_f = 1 / Const.LCH99b_f; const double div1_L1 = 1 / Const.LCH99b_L1; const double div1_L2 = 1 / Const.LCH99b_L2; double *vs = data.Vars; vs[0] = (Math.Exp(inColor[1] * div1_Cd) - 1) * div1_CG; //G vs[3] = (inColor[2] - Const.LCH99b_angle) * Const.Pi180; vs[1] = vs[0] * Math.Cos(vs[3]); //e vs[2] = (vs[0] * Math.Sin(vs[3])) * div1_f; //f outColor[1] = vs[1] * Const.cos26 - vs[2] * Const.sin26; outColor[2] = vs[1] * Const.sin26 + vs[2] * Const.cos26; outColor[0] = (Math.Exp(inColor[0] * div1_L1) - 1) * div1_L2; }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { double *vs = data.Vars; outColor[0] = inColor[1]; vs[0] = inColor[0] + inColor[1] + inColor[2]; if (Math.Abs(vs[0]) < Const.Delta) { outColor[1] = data.OutWPCr[0]; outColor[2] = data.OutWPCr[1]; } else { vs[0] = 1d / vs[0]; outColor[2] = inColor[1] * vs[0]; outColor[1] = inColor[0] * vs[0]; } }
/// <summary> /// Creates a new instance of the <see cref="ConversionCreator"/> class /// </summary> /// <param name="CMIL">The ILGenerator for the conversion method</param> /// <param name="data">The conversion data</param> /// <param name="inColor">The input color</param> /// <param name="outColor">The output color</param> protected ConversionCreator(ILGenerator CMIL, ConversionData data, Color inColor, Color outColor) : base(CMIL) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (inColor == null) { throw new ArgumentNullException(nameof(inColor)); } if (outColor == null) { throw new ArgumentNullException(nameof(outColor)); } Data = data; InColor = inColor; OutColor = outColor; }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { double *vs = data.Vars; //Max = vs[0] and Min = vs[1] UMath.MinMax_3(inColor, vs); if (Math.Round(vs[0], 6) == Math.Round(vs[1], 6)) { outColor[2] = vs[1]; outColor[0] = 0; } else { if (inColor[0] == vs[1]) { vs[2] = inColor[1] - inColor[2]; vs[3] = 3d; } else if (inColor[2] == vs[1]) { vs[2] = inColor[0] - inColor[1]; vs[3] = 1d; } else //inColor[0] == vs[1] (== min) { vs[2] = inColor[2] - inColor[0]; vs[3] = 5d; } outColor[0] = 60d * (vs[3] - vs[2] / (vs[0] - vs[1])); outColor[2] = vs[0]; } if (Math.Abs(vs[0]) < Const.Delta) { outColor[1] = 0; } else { outColor[1] = (vs[0] - vs[1]) / vs[0]; } }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { double *vs = data.Vars; //Max = vs[0] and Min = vs[1] UMath.MinMax_3(inColor, vs); vs[2] = vs[0] - vs[1]; vs[3] = vs[0] + vs[1]; outColor[2] = vs[3] * 0.5; if (Math.Round(vs[0], 6) == Math.Round(vs[1], 6)) { outColor[1] = outColor[0] = 0; } else { if (outColor[2] <= 0.5d) { outColor[1] = vs[2] / vs[3]; } else { outColor[1] = vs[2] / (2 - vs[2]); } if (inColor[0] == vs[0]) { outColor[0] = (inColor[1] - inColor[2]) / vs[2]; } else if (inColor[1] == vs[0]) { outColor[0] = 2d + (inColor[2] - inColor[0]) / vs[2]; } else { outColor[0] = 4d + (inColor[0] - inColor[1]) / vs[2]; } //inColor[2] == max outColor[0] *= 60d; } }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { const double div1_116 = 1 / 116d; double * vs = data.Vars; double * wp = data.OutWP; vs[0] = inColor[1] / wp[1]; if (vs[0] <= Const.Epsilon) { vs[0] = ((Const.Kappa * vs[0]) + 16d) * div1_116; } else { vs[0] = Math.Pow(vs[0], Const.div1_3); } vs[1] = inColor[0] / wp[0]; if (vs[1] <= Const.Epsilon) { vs[1] = ((Const.Kappa * vs[1]) + 16d) * div1_116; } else { vs[1] = Math.Pow(vs[1], Const.div1_3); } vs[2] = inColor[2] / wp[2]; if (vs[2] <= Const.Epsilon) { vs[2] = ((Const.Kappa * vs[2]) + 16d) * div1_116; } else { vs[2] = Math.Pow(vs[2], Const.div1_3); } outColor[0] = 116d * vs[0] - 16d; outColor[1] = 500d * (vs[1] - vs[0]); outColor[2] = 200d * (vs[0] - vs[2]); }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { if (Math.Abs(inColor[1]) < Const.Delta) { outColor[0] = inColor[2]; outColor[1] = inColor[2]; outColor[2] = inColor[2]; } else { const double div1_360 = 1d / 360d; double * vs = data.Vars; vs[0] = (inColor[0] * div1_360) * 6d; vs[1] = (int)vs[0]; //== Math.Floor vs[2] = inColor[2] * inColor[1]; vs[3] = vs[2] * (vs[0] - vs[1]); vs[4] = inColor[2] - vs[2]; vs[5] = inColor[2] - vs[3]; vs[6] = vs[4] + vs[3]; switch ((int)(vs[1] + 0.5)) //Since the value is always positive, this is the fastest way to round to an even number { case 6: case 0: outColor[0] = inColor[2]; outColor[1] = vs[6]; outColor[2] = vs[4]; break; case 1: outColor[0] = vs[5]; outColor[1] = inColor[2]; outColor[2] = vs[4]; break; case 2: outColor[0] = vs[4]; outColor[1] = inColor[2]; outColor[2] = vs[6]; break; case 3: outColor[0] = vs[4]; outColor[1] = vs[5]; outColor[2] = inColor[2]; break; case 4: outColor[0] = vs[6]; outColor[1] = vs[4]; outColor[2] = inColor[2]; break; default: outColor[0] = inColor[2]; outColor[1] = vs[4]; outColor[2] = vs[5]; break; } } }
/// <summary> /// Creates a new instance of the <see cref="ConversionCreator"/> class /// </summary> /// <param name="parent">The parent <see cref="ConversionCreator"/></param> /// /// <param name="isLast">States if the output color is the last color</param> /// <param name="inColor">The input color</param> /// <param name="outColor">The output color</param> protected ConversionCreator(ConversionCreator parent, Color inColor, Color outColor, bool isLast) : base(parent.ILG) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } if (inColor == null) { throw new ArgumentNullException(nameof(inColor)); } if (outColor == null) { throw new ArgumentNullException(nameof(outColor)); } Data = parent.Data; InColor = inColor; OutColor = outColor; base.IsFirstG = false; base.IsLastG = isLast; IsTempVar1 = !parent.IsTempVar1; }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { if (Math.Abs(inColor[1]) < Const.Delta) { outColor[0] = inColor[2]; outColor[1] = inColor[2]; outColor[2] = inColor[2]; } else { const double div1_60 = 1 / 60d; double * vs = data.Vars; if (inColor[2] < 0.5d) { vs[0] = inColor[2] * (1d + inColor[1]); } else { vs[0] = (inColor[2] + inColor[1]) - (inColor[1] * inColor[2]); } vs[1] = 2d * inColor[2] - vs[0]; if (inColor[0] > 360d) { inColor[0] -= 360d; } else if (inColor[0] < 0) { inColor[0] += 360d; } if (inColor[0] < 60d) { outColor[1] = vs[1] + (vs[0] - vs[1]) * inColor[0] * div1_60; } else if (inColor[0] < 180d) { outColor[1] = vs[0]; } else if (inColor[0] < 240d) { outColor[1] = vs[1] + (vs[0] - vs[1]) * (240d - inColor[0]) * div1_60; } else { outColor[1] = vs[1]; } vs[2] = inColor[0] - 120d; if (vs[2] > 360d) { vs[2] -= 360d; } else if (vs[2] < 0) { vs[2] += 360d; } if (vs[2] < 60d) { outColor[2] = vs[1] + (vs[0] - vs[1]) * vs[2] * div1_60; } else if (vs[2] < 180d) { outColor[2] = vs[0]; } else if (vs[2] < 240d) { outColor[2] = vs[1] + (vs[0] - vs[1]) * (240d - vs[2]) * div1_60; } else { outColor[2] = vs[1]; } vs[2] = inColor[0] + 120d; if (vs[2] > 360d) { vs[2] -= 360d; } else if (vs[2] < 0) { vs[2] += 360d; } if (vs[2] < 60d) { outColor[0] = vs[1] + (vs[0] - vs[1]) * vs[2] * div1_60; } else if (vs[2] < 180d) { outColor[0] = vs[0]; } else if (vs[2] < 240d) { outColor[0] = vs[1] + (vs[0] - vs[1]) * (240d - vs[2]) * div1_60; } else { outColor[0] = vs[1]; } } }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { outColor[0] = Math.Abs(inColor[0]); outColor[1] = inColor[1] * Math.Cos(inColor[2] * Const.Pi180); outColor[2] = inColor[1] * Math.Sin(inColor[2] * Const.Pi180); }
/// <summary> /// The conversion method /// </summary> /// <param name="inColor">The pointer to the input color values</param> /// <param name="outColor">The pointer to the output color values</param> /// <param name="data">The data that is used to perform the conversion</param> public static void Convert(double *inColor, double *outColor, ConversionData data) { outColor[0] = inColor[0]; outColor[1] = Math.Sqrt(inColor[1] * inColor[1] + inColor[2] * inColor[2]); outColor[2] = Math.Atan2(inColor[2], inColor[1]) * Const.Pi180_1; }
/// <summary> /// Creates a new instance of the <see cref="ConversionCreator"/> class /// </summary> /// <param name="CMIL">The ILGenerator for the conversion method</param> /// <param name="data">The conversion data</param> /// <param name="inColor">The input color</param> /// <param name="outColor">The output color</param> /// <param name="isLast">States if the output color is the last color</param> protected ConversionCreator(ILGenerator CMIL, ConversionData data, Color inColor, Color outColor, bool isLast) : this(CMIL, data, inColor, outColor) { base.IsLastG = isLast; }
/// <summary> /// Creates a new instance of the <see cref="ConversionCreator_Color"/> class /// </summary> /// <param name="CMIL">The ILGenerator for the conversion method</param> /// <param name="data">The conversion data</param> /// <param name="inColor">The input color</param> /// <param name="outColor">The output color</param> /// <param name="isLast">States if the output color is the last color</param> public ConversionCreator_Color(ILGenerator CMIL, ConversionData data, Color inColor, Color outColor, bool isLast) : base(CMIL, data, inColor, outColor, isLast) { }