示例#1
0
        static public CIELab[] Array_RGBtoCIELab(Color[] inputList)
        {
            CIELab[] outputList = new CIELab[inputList.Length];
            for (int i = 0; i < inputList.Length; i++)
            {
                outputList[i] = CIELab.RGB_to_CIELab(inputList[i]);
            }

            return(outputList);
        }
示例#2
0
        static public Color[] V5(Color[] llist, int ColorsCount)
        {
            List <RGB> RGB_AllColors = new List <RGB>();

            foreach (Color item in llist)
            {
                RGB_AllColors.Add(new RGB(item));
            }

            List <List <Color> > Result = new List <List <Color> >();
            List <RGB>           Part   = new List <RGB>();
            int maxLength      = 0;
            int emptyListCount = 0;

            RGB_AllColors.Sort(delegate(RGB left, RGB right)
                               { return(right.Hue.CompareTo(left.Hue)); });

            for (int i = 0; i < ColorsCount; i++)
            {
                if (i < 3)
                {
                    foreach (RGB item in RGB_AllColors)
                    {
                        if ((float)item.Hue >= (float)(120f * (float)i) && (float)item.Hue <= (float)(120f * (float)(i + 1)))
                        {
                            Part.Add(item);
                        }
                    }
                }

                if (Part.Count >= 2)
                {
                    Part = ColorPalette.DistrictByHue(Part, true);
                    Part.Sort(delegate(RGB left, RGB right)
                              { return(left.Hue.CompareTo(right.Hue)); });
                }

                if (maxLength < Part.Count)
                {
                    maxLength = Part.Count;
                }
                if (Part.Count == 0)
                {
                    emptyListCount += 1;
                }

                List <Color> temp = new List <Color>();
                foreach (RGB item in Part)
                {
                    temp.Add(item.Color);
                }

                Result.Add(temp.GetRange(0, temp.Count));
                Part.Clear();
            }

            if (emptyListCount != 0 && maxLength > 1)
            {
                double E_value    = 0d;
                double E_valueMax = 0d;
                int    GroupIndex = 0;

                while (emptyListCount != 0)
                {
                    Result.Sort(delegate(List <Color> left, List <Color> right)
                                { return(right.Count.CompareTo(left.Count)); });

                    E_value    = 0d;
                    E_valueMax = 0d;
                    GroupIndex = 0;

                    for (int i = 0; i < ColorsCount; i++)
                    {
                        if (Result[i].Count > 1)
                        {
                            Color  left      = ColorPalette.GetAverageColor(Result[i].GetRange(0, Result[i].Count / 2));
                            Color  right     = ColorPalette.GetAverageColor(Result[i].GetRange(Result[i].Count / 2, Result[i].Count / 2));
                            CIELab CIE_left  = CIELab.RGB_to_CIELab(left);
                            CIELab CIE_right = CIELab.RGB_to_CIELab(right);

                            E_value = CIELab.deltaE76(CIE_left, CIE_right);

                            if (E_value > E_valueMax)
                            {
                                GroupIndex = i;
                                E_valueMax = E_value;
                            }
                        }
                    }

                    maxLength = Result[GroupIndex].Count;
                    if (maxLength == 1)
                    {
                        break;
                    }

                    Result[ColorsCount - 1].AddRange(Result[GroupIndex].GetRange(0, maxLength / 2));
                    Result[GroupIndex].RemoveRange(0, maxLength / 2);
                    emptyListCount--;
                }
            }

            int index = Result.FindIndex(group => group.Count != 0);

            for (int i = 0; i < Result.Count; i++)
            {
                if (Result[i].Count == 0)
                {
                    Result[i] = Result[index];
                }
            }

            return(ColorPalette.GetAverageColors(Result).ToArray());
        }
        public void ConvertColor()
        {
            ChangeNeeded = false;
            switch (ConvertType)
            {
            case "RGB":
                TargetRGB = Color.FromArgb(Int32.Parse(RGB_R.Text), Int32.Parse(RGB_G.Text), Int32.Parse(RGB_B.Text));

                TargetXYZ    = CIELab.RGB_to_XYZ(TargetRGB);
                TargetCIELab = CIELab.RGB_to_CIELab(TargetRGB);
                TargetHSV    = HSV.RGB_to_HSV(TargetRGB);

                SetHSV();
                SetXYZ();
                SetCIELab();
                break;

            case "HSV":
                TargetHSV.H = Double.Parse(HSV_H.Text);
                TargetHSV.S = Double.Parse(HSV_S.Text);
                TargetHSV.V = Double.Parse(HSV_V.Text);

                TargetRGB    = HSV.HSV_to_RGB(TargetHSV);
                TargetXYZ    = CIELab.RGB_to_XYZ(TargetRGB);
                TargetCIELab = CIELab.RGB_to_CIELab(TargetRGB);

                SetRGB();
                SetXYZ();
                SetCIELab();
                break;

            case "XYZ":
                TargetXYZ[0] = Double.Parse(XYZ_X.Text) * 100d;
                TargetXYZ[1] = Double.Parse(XYZ_Y.Text) * 100d;
                TargetXYZ[2] = Double.Parse(XYZ_Z.Text) * 100d;

                TargetRGB    = CIELab.XYZ_to_RGB(TargetXYZ);
                TargetCIELab = CIELab.XYZ_to_CIELab(TargetXYZ);
                TargetHSV    = HSV.RGB_to_HSV(TargetRGB);

                SetRGB();
                SetHSV();
                SetCIELab();
                break;

            case "Lab":
                TargetCIELab.L = Double.Parse(Lab_L.Text);
                TargetCIELab.a = Double.Parse(Lab_a.Text);
                TargetCIELab.b = Double.Parse(Lab_b.Text);

                TargetRGB = CIELab.CIELab_to_RGB(TargetCIELab);
                TargetXYZ = CIELab.CIELab_to_XYZ(TargetCIELab);
                TargetHSV = HSV.RGB_to_HSV(TargetRGB);

                SetRGB();
                SetHSV();
                SetXYZ();
                break;
            }
            targetColor.BackColor = TargetRGB;
            ConvertType           = "";
            ChangeNeeded          = true;
        }