コード例 #1
0
ファイル: Converter.cs プロジェクト: BSU2015CG/LoburAU_7_New
        public static ColorLuv RGBtoLuv(int R, int G, int B)
        {
            double   X, Y, Z, L, u, v, _u, _v;
            double   Yn = 1.0, xn = 0.312713, yn = 0.329016, Un, Vn; //D65
            ColorXYZ xyz = RGBtoXYZ(R, G, B);

            X = xyz.X;
            Y = xyz.Y;
            Z = xyz.Z;

            if (X + 15 * Y + 3 * Z == 0)
            {
                return(new ColorLuv(0, 0, 0));
            }

            Un = 4 * xn / (-2 * xn + 12 * yn + 3);
            Vn = 9 * yn / (-2 * xn + 12 * yn + 3);
            _u = 4 * X / (X + 15 * Y + 3 * Z);
            _v = 9 * Y / (X + 15 * Y + 3 * Z);

            if (Y / Yn <= Math.Pow(6 / 29.0, 3))
            {
                L = Math.Pow(29 / 3.0, 3) * Y / Yn;
            }
            else
            {
                L = 116 * Math.Pow(Y / Yn, 1 / 3.0) - 16;
            }

            u = 13 * L * (_u - Un);
            v = 13 * L * (_v - Vn);

            return(new ColorLuv(L, u, v));
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: BSU2015CG/LoburAU_7_New
        private void refreshAll(ColorXYZ color)
        {
            trackBarX.Value  = X = Convert.ToInt32(color.X * 100.0);
            trackBarY_.Value = Y_ = Convert.ToInt32(color.Y * 100.0);
            trackBarZ.Value  = Z = Convert.ToInt32(color.Z * 100.0);
            ColorRGB rgb = Converter.XYZtoRGB(color.X, color.Y, color.Z);     //!!!

            R = trackBarR.Value = rgb.R;
            G = trackBarG.Value = rgb.G;
            B = trackBarB.Value = rgb.B;
            ColorCMYK cmyk = Converter.RGBtoCMYK(R, G, B);        //!!!!

            trackBarC.Value = C = Convert.ToInt32(cmyk.C);
            trackBarM.Value = M = Convert.ToInt32(cmyk.M);
            trackBarY.Value = Y = Convert.ToInt32(cmyk.Y);
            trackBarK.Value = K = Convert.ToInt32(cmyk.K);
            ColorHLS hls = Converter.RGBtoHLS(R, G, B);         //!!!!!

            trackBarH.Value = H = hls.H;
            trackBarL.Value = L = Convert.ToInt32(hls.L * 100.0);
            trackBarS.Value = S = Convert.ToInt32(hls.S * 100.0);
            ColorLuv luv = Converter.RGBtoLuv(R, G, B);           //!!!!

            trackBarL_.Value = L_ = Convert.ToInt32(luv.L);
            trackBarU.Value  = u = Convert.ToInt32(luv.u);
            trackBarV.Value  = v = Convert.ToInt32(luv.v);

            numericUpDownR.Value  = R;
            numericUpDownG.Value  = G;
            numericUpDownB.Value  = B;
            numericUpDownH.Value  = H;
            numericUpDownL.Value  = L;
            numericUpDownS.Value  = S;
            numericUpDownC.Value  = C;
            numericUpDownM.Value  = M;
            numericUpDownY.Value  = Y;
            numericUpDownK.Value  = K;
            numericUpDownL_.Value = L_;
            numericUpDownU.Value  = u;
            numericUpDownV.Value  = v;
            numericUpDownX.Value  = X;
            numericUpDownY_.Value = Y_;
            numericUpDownZ.Value  = Z;

            if (colorCut)
            {
                label14.Visible = true;

                if (cuttedComponents[0])
                {
                    numericUpDownR.BackColor = Color.Red;
                }
                else
                {
                    numericUpDownR.BackColor = Color.White;
                }
                if (cuttedComponents[1])
                {
                    numericUpDownG.BackColor = Color.Red;
                }
                else
                {
                    numericUpDownG.BackColor = Color.White;
                }
                if (cuttedComponents[2])
                {
                    numericUpDownB.BackColor = Color.Red;
                }
                else
                {
                    numericUpDownB.BackColor = Color.White;
                }

                colorCut = false;
            }
            else
            {
                label14.Visible = false;

                numericUpDownR.BackColor = Color.White;
                numericUpDownG.BackColor = Color.White;
                numericUpDownB.BackColor = Color.White;
            }

            currentColor = Color.FromArgb(R, G, B);
            panel1_Paint(null, null);
        }