Пример #1
0
        /// <summary>
        /// This method creates a VBO for the JND Ellipses for the selected Color with the values for McAdams Ellipses (0.055f)
        /// 
        /// The method first points to several directions with aequidistance angle and creates a line with points
        /// the points will taken to compute jnd until threshold is reached and breaks to take the next line
        /// </summary>
        /// <param name="color">the selected Color</param>
        /// <returns>returns a VBO with the Ellipse value</returns>
        /// <author>Markus Strobel, Justine Smyzek</author>
        private VBO createJNDEllipse(Yxy color)
        {
            int lines = 36;
            double degreeStep = 360d / lines;

            List<Vector2>[] linesArray = new List<Vector2>[lines];

            // generate lines to check
            for (int i = 0; i < lines; i++)
            {
                List<Vector2> linePoints = new List<Vector2>();

                double xOffSet = 0d;
                double yOffSet = 0d;

                // generate all vertices for each line
                for (double radius = 0.0001d; radius < 0.1d; radius += 0.0001d)
                {
                    xOffSet = radius * Math.Cos((i * degreeStep) * Math.PI / 180d);
                    yOffSet = radius * Math.Sin((i * degreeStep) * Math.PI / 180d);
                    linePoints.Add(new Vector2((float) (color.x + xOffSet), (float) (color.y + yOffSet)));
                }
                linesArray[i] = linePoints;
            }

            float jnd = 0.0055f; // value of McAdams Ellipsen

            List<Vector3> vertices = new List<Vector3>();
            List<int> indices = new List<int>();
            int ind = 0;

            // compute JND
            foreach(List<Vector2> line in linesArray)
            {
                foreach(Vector2 point in line)
                {
                    float result = 0f;
                    Yxy comp = new Yxy(point.X, point.Y);
                    result = ColorHelper.Chromatic_Difference(color.asXYZ(), comp.asXYZ());

                    if (result > jnd)
                    {
                        vertices.Add(new Vector3(point.X, point.Y, 0f));
                        indices.Add(ind++);
                        break;
                    }
                }
            }

            return LoadVBO(vertices.ToArray(), indices.ToArray());
        }
Пример #2
0
        /// <summary>
        /// mouse hover ofer the OpenGL Window will be handled here
        /// </summary>
        /// <author>Markus Strobel</author>
        private void glControl_MouseHover(object sender, System.EventArgs e)
        {
            // Get current mouse position within the glControl
            Point mousePos = glControl1.PointToClient(Cursor.Position);
            // get x,y relative to an origin in the bottom left
            float x = mousePos.X;
            float y = glControl1.Height - mousePos.Y;

            // normalize to 0..1
            x /= glControl1.Width;
            y /= glControl1.Height;

            if (radioButtonXYZView.Checked)
            {
                Yxy Yxy = new Yxy(x, y);
                hoveredXYZColor = Yxy.asXYZ();
                hoveredRGBColor = hoveredXYZColor.asRGB(); //FarbRechner.CIEXYZ_to_RGB(FarbRechner.CIEYxy_to_CIEXYZ(Yxy));

                x = (float)Math.Round((double)x, 2);
                y = (float)Math.Round((double)y, 2);

                // filter negative rgb values
                if (!(hoveredRGBColor.R < 0 || hoveredRGBColor.G < 0 || hoveredRGBColor.B < 0))
                {
                    try
                    {
                        // normalize
                        float maxV = Math.Max(hoveredRGBColor.R, Math.Max(hoveredRGBColor.G, hoveredRGBColor.B));
                        hoveredRGBColor.R /= maxV;
                        hoveredRGBColor.G /= maxV;
                        hoveredRGBColor.B /= maxV;

                        // gamma correction
                        hoveredRGBColor.R = ColorHelper.Reverse_Gamma_Correction(hoveredRGBColor.R);
                        hoveredRGBColor.G = ColorHelper.Reverse_Gamma_Correction(hoveredRGBColor.G);
                        hoveredRGBColor.B = ColorHelper.Reverse_Gamma_Correction(hoveredRGBColor.B);

                        panelColorPreview.BackColor = Color.FromArgb((int)(hoveredRGBColor.R * 255), (int)(hoveredRGBColor.G * 255), (int)(hoveredRGBColor.B * 255));
                        labelColorPreviewHex.Text = "#" + ((int)(hoveredRGBColor.R * 255)).ToString("X") + ((int)(hoveredRGBColor.G * 255)).ToString("X") + ((int)(hoveredRGBColor.B * 255)).ToString("X");
                    }
                    catch
                    {
                        labelColorPreviewHex.Text = "#000";
                        panelColorPreview.BackColor = Color.Black;
                    }
                }
                else
                {
                    labelColorPreviewHex.Text = "#000";
                    panelColorPreview.BackColor = Color.Black;
                }
                labelColPreviewXH.Text = "x: " + x.ToString();
                labelColPreviewYS.Text = "y: " + y.ToString();
            }
        }