private void SetLabLChValues(lcmsCIELab tLab) { lblMyR.Text = "R: " + rgbColor.R.ToString("F2") + "(" + (rgbColor.R / 255).ToString("F2") + ")"; lblMyG.Text = "G: " + rgbColor.G.ToString("F2") + "(" + (rgbColor.G / 255).ToString("F2") + ")"; lblMyB.Text = "B: " + rgbColor.B.ToString("F2") + "(" + (rgbColor.B / 255).ToString("F2") + ")"; lblL.Text = "L*: " + tLab.L.ToString("F2"); lbla.Text = "a*: " + tLab.a.ToString("F2"); lblb.Text = "b*: " + tLab.b.ToString("F2"); var tLCh = tLab.ToLCh(); var tXYZ = tLab.ToXYZ(pLab.WhitePoint); lbL.Text = "L: " + tLCh.L.ToString("F2"); lbC.Text = "C: " + tLCh.C.ToString("F2"); lbh.Text = "h: " + tLCh.h.ToString("F2"); lX.Text = "X: " + tXYZ.X.ToString("F2"); lY.Text = "Y: " + tXYZ.Y.ToString("F2"); lZ.Text = "Z: " + tXYZ.Z.ToString("F2"); if (currentLAB == null) { currentLAB = new lcmsCIELab(); } currentLAB.L = tLab.L; currentLAB.a = tLab.a; currentLAB.b = tLab.b; }
private void TestLabDBL() { pnlColor.BackColor = Color.FromArgb(tbRed.Value, tbGreen.Value, tbBlue.Value); lcmsCIELab labValues; double[] buffer = new double[3]; buffer[0] = rgbColor.R / 255; //In - Red Out - L (In - as input buffer) buffer[1] = rgbColor.G / 255; //In - Green Out - a (Out - as output buffer) buffer[2] = rgbColor.B / 255; //In - Blue Out - b var size = sizeof(double) * buffer.Length; IntPtr ptr = Marshal.AllocCoTaskMem(size); Marshal.Copy(buffer, 0, ptr, buffer.Length); //Copy the buffer to the pointer tRGBtoLabDBL.DoTransform(ptr, ptr, 1); Marshal.Copy(ptr, buffer, 0, buffer.Length); //Copy the transformed values in the pointer back to the buffer Marshal.FreeCoTaskMem(ptr); labValues = new lcmsCIELab(buffer[0], buffer[1], buffer[2]); SetLabLChValues(labValues); gbxConversion.Text = " RGB - LAB (double -> double)"; }
private void TestLab() { if (DontDoTestLab) { return; } pnlColor.BackColor = Color.FromArgb(tbRed.Value, tbGreen.Value, tbBlue.Value); double[] myLab = new double[3]; byte[] rgb = new byte[3]; //double rgb[0] = (Byte)tbRed.Value; //Red rgb[1] = (Byte)tbGreen.Value; //Green rgb[2] = (Byte)tbBlue.Value; //Blue IntPtr ptrIn = Marshal.AllocCoTaskMem(sizeof(byte) * rgb.Length); Marshal.Copy(rgb, 0, ptrIn, rgb.Length); IntPtr ptrOut = Marshal.AllocCoTaskMem(sizeof(double) * myLab.Length); tRGBtoLab.DoTransform(ptrIn, ptrOut, 1); Marshal.Copy(ptrOut, myLab, 0, myLab.Length); Marshal.FreeCoTaskMem(ptrIn); Marshal.FreeCoTaskMem(ptrOut); var labValues = new lcmsCIELab(myLab[0], myLab[1], myLab[2]); SetLabLChValues(labValues); gbxConversion.Text = " RGB - LAB (byte -> double)"; }
private void btnDeltaE2K_Click(object sender, EventArgs e) { var sLAB = txtLAB.Text.Split(); listLAB.Clear(); listLCH.Clear(); listXYZ.Clear(); listDE2K.Clear(); foreach (var item in sLAB) { if (!String.IsNullOrEmpty(item)) { listLAB.Add(Double.Parse(item)); } } var A = new lcmsCIELab(); var B = new lcmsCIELab(); if (listLAB.Count % 2 != 0) { txtLAB.Text = "Error!!! you have to enter an even number of LAB values."; return; } int half = listLAB.Count / 2; for (int i = 0; i < half; i += 3) { A.L = listLAB[i]; A.a = listLAB[i + 1]; A.b = listLAB[i + 2]; B.L = listLAB[half + i]; B.a = listLAB[half + i + 1]; B.b = listLAB[half + i + 2]; listDE2K.Add(A.DeltaECIE2000(B, 1, 1, 1)); } String sDE2K = ""; foreach (double item in listDE2K) { sDE2K += item + "\r\n"; } Clipboard.SetText(sDE2K); txtLAB.Text = sDE2K; }
private void btnLab_Click(object sender, EventArgs e) { var sLAB = txtLAB.Text.Split(); listLAB.Clear(); listLCH.Clear(); listXYZ.Clear(); foreach (var item in sLAB) { if (!String.IsNullOrEmpty(item)) { listLAB.Add(Double.Parse(item)); } } var A = new lcmsCIELab(); var B = new lcmsCIELCh(); var C = new lcmsCIEXYZ(); for (int i = 0; i < listLAB.Count; i += 3) { A.L = listLAB[i]; A.a = listLAB[i + 1]; A.b = listLAB[i + 2]; B.FromLab(A); C.FromLab(pLab.WhitePoint, A); listLCH.Add(B.L); listLCH.Add(B.C); listLCH.Add(B.h); listXYZ.Add(C.X); listXYZ.Add(C.Y); listXYZ.Add(C.Z); } listLAB.Clear(); }