示例#1
0
        /// <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();
        }
示例#2
0
        /// <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();
        }
示例#3
0
文件: XYZ.cs 项目: ArTc0re/University
        /// <summary>
        /// transformatin CIE XYZ -> CIE L*a*b*
        /// source: http://en.wikipedia.org/wiki/CIELUV
        /// </summary>
        /// <author>Birthe Anne Wiegand</author>
        /// <returns>L*u*v* value</returns>
        public LUV asLUV(XYZ WP)
        {
            LUV temp = new LUV();

            float XXn = this.X / WP.X; // X / Xn
            float YYn = this.Y / WP.Y; // Y / Yn
            float ZZn = this.Z / WP.Z; // Z / Zn

            if (YYn <= 0.008856452)
            {
                temp.L = 903.2962963f * YYn;
            }
            else
            {
                temp.L = 116f * (float)Math.Pow(YYn, (1f / 3f)) - 16;
            }
            temp.U = 13f * temp.L * (ColorHelper.function_XYZ_to_LUV(this)[0] - ColorHelper.function_XYZ_to_LUV(WP)[0]);
            temp.V = 13f * temp.L * (ColorHelper.function_XYZ_to_LUV(this)[1] - ColorHelper.function_XYZ_to_LUV(WP)[1]);

            // to catch the otherwise occuring exception for (input.X + 15f * input.Y + 3f * input.Z) = 0
            // (ColorHelper.function_XYZ_to_LUV divides by zero if (input.X + 15f * input.Y + 3f * input.Z) = 0)
            // u* and v* are given the value 0 just for interface clarity as there is no information given about them.
            // (so 0 is as good as any other value, but does not imply anything wrong)
            if (float.IsNaN(temp.U)) temp.U = 0f;
            if (float.IsNaN(temp.V)) temp.V = 0f;

            return temp;
        }