/// <summary> /// creating the PreviewLines for HSL Saturation /// </summary> /// <param name="selectedColor">the selected Color</param> /// <author>Justine Smyzek</author> private void createHSLPreviewLines(HSL selectedColor) { HSL hsl = new HSL(); Yxy yxy; GL.Color3(0.5f, 0.5f, 0.5f); hsl.H = selectedColor.H; hsl.S = 0; hsl.L = selectedColor.L; yxy = hsl.asRGB().asXYZ().asYxy(); Vector3 HSL_H0L = new Vector3(yxy.x, yxy.y, 0f); hsl.H = selectedColor.H; hsl.S = 1; hsl.L = selectedColor.L; yxy = hsl.asRGB().asXYZ().asYxy(); Vector3 HSL_H1L = new Vector3(yxy.x, yxy.y, 0f); Vector3[] vertices = { HSL_H0L, HSL_H1L }; int[] indices = new int[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { indices[i] = i; } hslPreviewLines = LoadVBO(vertices, indices); }
/// <summary> /// OpenGLForm constructor /// </summary> /// <author>Markus Strobel</author> public OpenGLForm() { InitializeComponent(); colorHelper = new ColorHelper(); container = new System.ComponentModel.Container(); tooltip = new System.Windows.Forms.ToolTip(container); selectedRGBColor = new RGB(); selectedHSLBaseSL = new HSL(1f, 1f, 0.5f); selectedHSLColor = new HSL(1f, 1f, 0.5f); // VBO inits ellipsesVBOs = new List<VBO>(); customRGB.Checked = true; // WP, RR, GG, BB set to default (lables etc) labelWPXValue.Text = Math.Round((double)ColorHelper.WP_default.X, 3).ToString(); labelWPYValue.Text = Math.Round((double)ColorHelper.WP_default.Y, 3).ToString(); labelWPZValue.Text = Math.Round((double)ColorHelper.WP_default.Z, 3).ToString(); labelRRXValue.Text = Math.Round((double)ColorHelper.RR_default.X, 3).ToString(); labelRRYValue.Text = Math.Round((double)ColorHelper.RR_default.Y, 3).ToString(); labelRRZValue.Text = Math.Round((double)ColorHelper.RR_default.Z, 3).ToString(); labelGGXValue.Text = Math.Round((double)ColorHelper.GG_default.X, 3).ToString(); labelGGYValue.Text = Math.Round((double)ColorHelper.GG_default.Y, 3).ToString(); labelGGZValue.Text = Math.Round((double)ColorHelper.GG_default.Z, 3).ToString(); labelBBXValue.Text = Math.Round((double)ColorHelper.BB_default.X, 3).ToString(); labelBBYValue.Text = Math.Round((double)ColorHelper.BB_default.Y, 3).ToString(); labelBBZValue.Text = Math.Round((double)ColorHelper.BB_default.Z, 3).ToString(); // initializes internal color values ResetColorValues(); //set RGB Slider lables to values (between 0 and 1) labelTabRGB_R.Text = "R: " + trackBarR.Value; labelTabRGB_G.Text = "G: " + trackBarG.Value; labelTabRGB_B.Text = "B: " + trackBarB.Value; //set HSL Slider lables to values labelTabHSL_H.Text = "H: " + (trackBarH.Value) + "°"; labelTabHSL_S.Text = "S: " + trackBarS.Value + "%"; labelTabHSL_L.Text = "L: " + trackBarL.Value + "%"; }
/// <summary> /// create HDL Polygon for Hue circulation /// </summary> /// <param name="selectedColor">the selected Color</param> /// <author>Justine Smyzek</author> private void createHSLPreviewCircle(HSL selectedColor) { HSL hsl = new HSL(); Yxy yxy; int j = 0; Vector3[] vertices = new Vector3[36]; GL.Color3(0.5f, 0.5f, 0.5f); for (int i = 0; i < 360; i += 10) { hsl.H = i; hsl.S = selectedColor.S; hsl.L = selectedColor.L; yxy = hsl.asRGB().asXYZ().asYxy(); Vector3 hsli = new Vector3(yxy.x, yxy.y, 0f); vertices[j] = hsli; j += 1; } int[] indices = new int[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { indices[i] = i; } hslPreviewCircle = LoadVBO(vertices, indices); }
/// <summary> /// Slidebar Event for HSL - allows to change the current selected point /// </summary> /// <author> Justine Smyzek</author> private void trackBarHSL_Scroll(object sender, EventArgs e) { TrackBar tb = sender as TrackBar; //calculate values HSL hsl_slide = new HSL(trackBarH.Value, trackBarS.Value / 100f, trackBarL.Value / 100f); RGB rgb_slide = hsl_slide.asRGB(); // here is a small computation error (like in trackbarRGB), TODO - fix to get and show the correct color from trackbarHSL // gamma correction //rgb_slide.R = ColorHelper.Apply_Gamma_Correction(rgb_slide.R); //rgb_slide.G = ColorHelper.Apply_Gamma_Correction(rgb_slide.G); //rgb_slide.B = ColorHelper.Apply_Gamma_Correction(rgb_slide.B); if (radioButtonXYZView.Checked) { //set new selected Color panelColorSelected.BackColor = Color.FromArgb((int)(rgb_slide.R * 255), (int)(rgb_slide.G * 255), (int)(rgb_slide.B * 255)); labelColorSelectedHex.Text = "#" + ((int)(rgb_slide.R * 255)).ToString("X") + ((int)(rgb_slide.G * 255)).ToString("X") + ((int)(rgb_slide.B * 255)).ToString("X"); //calculate yxy room Yxy yxy = rgb_slide.asXYZ().asYxy(); //control if Line prieview is wished - draw if (checkBoxHSL.Checked) { createHSLPreviewLines(hsl_slide); createHSLPreviewCircle(hsl_slide); showColorCircle = false; trackBarS.Enabled = false; checkBoxRGB.Enabled = false; trackBarS.Value = 100; } else { showColorCircle = true; trackBarS.Enabled = true; checkBoxRGB.Enabled = true; } //change labels of color labelTabHSL_H.Text = "H: " + trackBarH.Value + "°"; labelTabHSL_S.Text = "S: " + trackBarS.Value + "%"; labelTabHSL_L.Text = "L: " + trackBarL.Value + "%"; createSelectedColorCircleVBO(yxy.x, yxy.y, 0.01f, 36); // computes color circle position } //change also RBG scroll trackBarR.Value = (int)(rgb_slide.R * 255); trackBarG.Value = (int)(rgb_slide.G * 255); trackBarB.Value = (int)(rgb_slide.B * 255); labelTabRGB_R.Text = "R: " + rgb_slide.R; labelTabRGB_G.Text = "G: " + rgb_slide.G; labelTabRGB_B.Text = "B: " + rgb_slide.B; glControl1.Invalidate(); }
/// <summary> /// </summary> /// <author> Birthe Anne Wiegand</author> private void ResetColorValues() { // set color values to 0 RGBvalue = new RGB(); customRGBvalue = new customRGB(); sRGBvalue = new sRGB(); HSLvalue = new HSL(); HSVvalue = new HSV(); XYZvalue = new XYZ(); LUVvalue = new LUV(); LABvalue = new LAB(); UpdateBoxes(); }
/// <summary> /// this method is a quick n dirty modified HSLtoRGB for HSL Space computation /// </summary> /// <param name="hsl">the given hsl color</param> /// <returns>the resulting rgb color</returns> /// <author>Markus Strobel</author> public RGB HSLtoRGB(HSL hsl) { // quick n dirty modified version for -180° to 180° RGB rgb = new RGB(); float hue = hsl.H; while (hue < 0) { hue += 360; } float C = (1f - Math.Abs(2f * hsl.L - 1f)) * hsl.S; float X = C * (1f - Math.Abs(((hue / 60f) % 2f) - 1f)); float m = hsl.L - C / 2f; if (0f <= hsl.H && hsl.H < 60f) { rgb.R = C; rgb.G = X; rgb.B = 0; } else if (60f <= hsl.H && hsl.H < 120f) { rgb.R = X; rgb.G = C; rgb.B = 0; } else if (120f <= hsl.H && hsl.H <= 180f) { rgb.R = 0; rgb.G = C; rgb.B = X; } else if (-180f <= hsl.H && hsl.H < -120f) { rgb.R = 0; rgb.G = X; rgb.B = C; } else if (-120f <= hsl.H && hsl.H < -60f) { rgb.R = X; rgb.G = 0; rgb.B = C; } else if (-60f <= hsl.H && hsl.H < 0f) { rgb.R = C; rgb.G = 0; rgb.B = X; } rgb.R += m; rgb.G += m; rgb.B += m; return rgb; }
/// <summary> /// </summary> /// <author> Birthe Anne Wiegand</author> private void KonvertierenButton_Click(object sender, EventArgs e) { RadioButton checkedButton = this.tabFarbRechner.Controls.OfType<RadioButton>().FirstOrDefault(radioButton => radioButton.Checked); switch (checkedButton.Name) { case "customRGB": // parse input to internal customRGBvalue customRGBvalue.R = float.Parse(customRGB_R.Text, CultureInfo.InvariantCulture); customRGBvalue.G = float.Parse(customRGB_G.Text, CultureInfo.InvariantCulture); customRGBvalue.B = float.Parse(customRGB_B.Text, CultureInfo.InvariantCulture); // update other internal values XYZvalue = customRGBvalue.asXYZ(); RGBvalue = XYZvalue.asRGB(); sRGBvalue = RGBvalue.as_sRGB(); HSLvalue = RGBvalue.asHSL(); HSVvalue = RGBvalue.asHSV(); LUVvalue = XYZvalue.asLUV(); LABvalue = XYZvalue.asLAB(); break; case "sRGB": // parse input to internal customRGBvalue sRGBvalue.R = float.Parse(sRGB_R.Text, CultureInfo.InvariantCulture); sRGBvalue.G = float.Parse(sRGB_G.Text, CultureInfo.InvariantCulture); sRGBvalue.B = float.Parse(sRGB_B.Text, CultureInfo.InvariantCulture); // update other internal values RGBvalue = sRGBvalue.asRGB(); XYZvalue = RGBvalue.asXYZ(); customRGBvalue = XYZvalue.as_customRGB(); HSLvalue = RGBvalue.asHSL(); HSVvalue = RGBvalue.asHSV(); LUVvalue = XYZvalue.asLUV(); LABvalue = XYZvalue.asLAB(); break; case "HSL": // parse input to internal HSLvalue HSLvalue.H = float.Parse(HSL_H.Text, CultureInfo.InvariantCulture); HSLvalue.S = float.Parse(HSL_S.Text, CultureInfo.InvariantCulture); HSLvalue.L = float.Parse(HSL_L.Text, CultureInfo.InvariantCulture); // update other internal values RGBvalue = HSLvalue.asRGB(); XYZvalue = RGBvalue.asXYZ(); customRGBvalue = XYZvalue.as_customRGB(); sRGBvalue = RGBvalue.as_sRGB(); HSVvalue = RGBvalue.asHSV(); LUVvalue = XYZvalue.asLUV(); LABvalue = XYZvalue.asLAB(); break; case "HSV": // parse input to internal HSVvalue HSVvalue.H = float.Parse(HSV_H.Text, CultureInfo.InvariantCulture); HSVvalue.S = float.Parse(HSV_S.Text, CultureInfo.InvariantCulture); HSVvalue.V = float.Parse(HSV_V.Text, CultureInfo.InvariantCulture); // update other internal values RGBvalue = HSVvalue.asRGB(); XYZvalue = RGBvalue.asXYZ(); customRGBvalue = XYZvalue.as_customRGB(); sRGBvalue = RGBvalue.as_sRGB(); HSLvalue = RGBvalue.asHSL(); LUVvalue = XYZvalue.asLUV(); LABvalue = XYZvalue.asLAB(); break; case "XYZ": // parse input to internal HSVvalue XYZvalue.X = float.Parse(XYZ_X.Text, CultureInfo.InvariantCulture); XYZvalue.Y = float.Parse(XYZ_Y.Text, CultureInfo.InvariantCulture); XYZvalue.Z = float.Parse(XYZ_Z.Text, CultureInfo.InvariantCulture); // update other internal values RGBvalue = XYZvalue.asRGB(); customRGBvalue = XYZvalue.as_customRGB(); sRGBvalue = RGBvalue.as_sRGB(); HSLvalue = RGBvalue.asHSL(); HSVvalue = RGBvalue.asHSV(); LUVvalue = XYZvalue.asLUV(ColorHelper.WP_used); LABvalue = XYZvalue.asLAB(ColorHelper.WP_used); break; case "LUV": // parse input to internal LUVvalue LUVvalue.L = float.Parse(LUV_L.Text, CultureInfo.InvariantCulture); LUVvalue.U = float.Parse(LUV_U.Text, CultureInfo.InvariantCulture); LUVvalue.V = float.Parse(LUV_V.Text, CultureInfo.InvariantCulture); // update other internal values XYZvalue = LUVvalue.asXYZ(ColorHelper.WP_used); RGBvalue = XYZvalue.asRGB(); customRGBvalue = XYZvalue.as_customRGB(); sRGBvalue = RGBvalue.as_sRGB(); HSLvalue = RGBvalue.asHSL(); HSVvalue = RGBvalue.asHSV(); LABvalue = XYZvalue.asLAB(ColorHelper.WP_used); break; case "LAB": // parse input to internal LABvalue LABvalue.L = float.Parse(LAB_L.Text, CultureInfo.InvariantCulture); LABvalue.A = float.Parse(LAB_A.Text, CultureInfo.InvariantCulture); LABvalue.B = float.Parse(LAB_B.Text, CultureInfo.InvariantCulture); // update other internal values XYZvalue = LABvalue.asXYZ(ColorHelper.WP_used); RGBvalue = XYZvalue.asRGB(); customRGBvalue = XYZvalue.as_customRGB(); sRGBvalue = RGBvalue.as_sRGB(); HSLvalue = RGBvalue.asHSL(); HSVvalue = RGBvalue.asHSV(); LUVvalue = XYZvalue.asLUV(ColorHelper.WP_used); break; } UpdateBoxes(); }